From b26bd4097f345764b8655dd88882460b98747777 Mon Sep 17 00:00:00 2001 From: Firepup Sixfifty Date: Thu, 9 Nov 2023 15:37:08 -0600 Subject: [PATCH] Formatting --- bare.py | 2 ++ handlers.py | 25 ++++++++----------------- logs.py | 5 ++++- overrides.py | 8 ++++---- 4 files changed, 18 insertions(+), 22 deletions(-) diff --git a/bare.py b/bare.py index fd4c9d4..642c59e 100644 --- a/bare.py +++ b/bare.py @@ -1,9 +1,11 @@ #!/usr/bin/python3 from socket import socket from overrides import bytes, bbytes + logs = ... re = ... from typing import NoReturn, Union + cmds = ... conf = ... sleep = ... diff --git a/handlers.py b/handlers.py index 8cc72f2..6067e37 100644 --- a/handlers.py +++ b/handlers.py @@ -7,6 +7,7 @@ from overrides import bytes, bbytes from importlib import reload import bare + def CTCP(bot: bare.bot, msg: str) -> bool: sender = msg.split("!", 1)[0][1:] kind = msg.split("\x01")[1].split(" ", 1)[0] @@ -39,6 +40,7 @@ def CTCP(bot: bare.bot, msg: str) -> bool: bot.log(f'Unknown CTCP "{kind}"', "WARN") return False + def PRIVMSG(bot: bare.bot, msg: str) -> Union[None, str]: # Format of ":[Nick]![ident]@[host|vhost] PRIVMSG [channel] :[message]” name = msg.split("!", 1)[0][1:] @@ -53,9 +55,7 @@ def PRIVMSG(bot: bare.bot, msg: str) -> Union[None, str]: name = Nname message = msg.split(">", 1)[1].strip() else: - message = ( - msg.split("PRIVMSG", 1)[1].split(":", 1)[1].strip() - ) + message = msg.split("PRIVMSG", 1)[1].split(":", 1)[1].strip() elif name == bot.nick: return # type: ignore else: @@ -82,10 +82,7 @@ def PRIVMSG(bot: bare.bot, msg: str) -> Union[None, str]: for cmd in cmds.data: triggers = [cmd] triggers.extend(cmds.data[cmd]["aliases"]) - triggers = list( - call.replace("$BOTNICK", bot.nick.lower()) - for call in triggers - ) + triggers = list(call.replace("$BOTNICK", bot.nick.lower()) for call in triggers) if conf.mfind( message.lower(), triggers, @@ -105,9 +102,7 @@ def PRIVMSG(bot: bare.bot, msg: str) -> Union[None, str]: if not handled: for check in cmds.checks: if re.search( - check.replace("$MAX", str(bot.nicklen)).replace( - "$BOTNICK", bot.nick - ), + check.replace("$MAX", str(bot.nicklen)).replace("$BOTNICK", bot.nick), message, ): cmds.call[check](bot, chan, name, message) @@ -138,15 +133,11 @@ def PRIVMSG(bot: bare.bot, msg: str) -> Union[None, str]: mm = open("mastermessages.txt", "r") q = mm.readlines() sel = conf.decode_escapes( - str(r.sample(q, 1)) - .strip("[]'") - .replace("\\n", "") - .strip('"') + str(r.sample(q, 1)).strip("[]'").replace("\\n", "").strip('"') ) bot.msg(f"[QUOTE] {sel}", chan) mm.close() return # type: ignore -handles = { - "PRIVMSG": PRIVMSG -} + +handles = {"PRIVMSG": PRIVMSG} diff --git a/logs.py b/logs.py index 947c0e5..e423ec9 100644 --- a/logs.py +++ b/logs.py @@ -5,7 +5,10 @@ from typing import Union def log( - message: str, origin: str = "Unknown", level: str = "LOG", time: Union[dt, str] = "now" + message: str, + origin: str = "Unknown", + level: str = "LOG", + time: Union[dt, str] = "now", ) -> None: if level in ["EXIT", "CRASH"]: stream = stderr diff --git a/overrides.py b/overrides.py index 35fa18e..b8e2786 100644 --- a/overrides.py +++ b/overrides.py @@ -28,14 +28,14 @@ class bytes(bbytes): errors: str = "strict", ) -> _T: if type(thing) == str: - cls.value = super().__new__(cls, thing, encoding, errors) # type: ignore + cls.value = super().__new__(cls, thing, encoding, errors) # type: ignore elif thing == None: - cls.value = super().__new__(cls) # type: ignore + cls.value = super().__new__(cls) # type: ignore elif thing != None: - cls.value = super().__new__(cls, thing) # type: ignore + cls.value = super().__new__(cls, thing) # type: ignore else: raise AttributeError("This shouldn't happen") - return cls.value # type: ignore + return cls.value # type: ignore @classmethod def lazy_decode(cls):