diff --git a/bot.py b/bot.py index d9a3a23..7140d56 100644 --- a/bot.py +++ b/bot.py @@ -217,11 +217,11 @@ class bot(bare.bot): pass if action in handlers.handles: res, chan = handlers.handles[action](self, ircmsg) - if res == "reload": + if res == "reload" and type(chan) == str: reload(conf) reload(cmds) reload(handlers) - self.msg("Reloaded successfully", chan) # type: ignore + self.msg("Reloaded successfully", chan) else: if ircmsg.startswith("PING "): self.ping(ircmsg) diff --git a/handlers.py b/handlers.py index 940720a..ac66783 100644 --- a/handlers.py +++ b/handlers.py @@ -2,7 +2,7 @@ import random as r import config as conf import re import commands as cmds -from typing import Union +from typing import Union, Callable from overrides import bytes, bbytes from importlib import reload import bare @@ -41,7 +41,7 @@ def CTCP(bot: bare.bot, msg: str) -> bool: return False -def PRIVMSG(bot: bare.bot, msg: str) -> tuple[Union[None, str], Union[None, str]]: +def PRIVMSG(bot: bare.bot, msg: str) -> Union[tuple[None, None], tuple[str, str]]: # Format of ":[Nick]![ident]@[host|vhost] PRIVMSG [channel] :[message]” name = msg.split("!", 1)[0][1:] host = msg.split("@", 1)[1].split(" ", 1)[0] @@ -152,14 +152,14 @@ def PRIVMSG(bot: bare.bot, msg: str) -> tuple[Union[None, str], Union[None, str] return None, None -def NICK(bot: bare.bot, msg: str) -> tuple[Union[None, str], Union[None, str]]: +def NICK(bot: bare.bot, msg: str) -> tuple[None, None]: name = msg.split("!", 1)[0][1:] if name == bot.nick: bot.nick = msg.split("NICK", 1)[1].split(":", 1)[1].strip() return None, None -def KICK(bot: bare.bot, msg: str) -> tuple[Union[None, str], Union[None, str]]: +def KICK(bot: bare.bot, msg: str) -> tuple[None, None]: important = msg.split("KICK", 1)[1].split(":", 1)[0].strip().split(" ") channel = important[0] kicked = important[1] @@ -168,7 +168,7 @@ def KICK(bot: bare.bot, msg: str) -> tuple[Union[None, str], Union[None, str]]: return None, None -def PART(bot: bare.bot, msg: str) -> tuple[Union[None, str], Union[None, str]]: +def PART(bot: bare.bot, msg: str) -> tuple[None, None]: parted = msg.split("!", 1)[0][1:] channel = msg.split("PART", 1)[1].split(":", 1)[0].strip() if parted == bot.nick: @@ -176,7 +176,7 @@ def PART(bot: bare.bot, msg: str) -> tuple[Union[None, str], Union[None, str]]: return None, None -handles = { +handles: dict[str, Callable[[bare.bot, str], Union[tuple[None, None], tuple[str, str]]]] = { "PRIVMSG": PRIVMSG, "NICK": NICK, "KICK": KICK, diff --git a/logs.py b/logs.py index 5b16435..7a39402 100644 --- a/logs.py +++ b/logs.py @@ -18,8 +18,10 @@ def log( dtime = dt.now() elif type(time) == str: raise ValueError('Only "now" is an accepted string argument for time') + elif type(time) == dt: + dtime = time else: - dtime = time # type: dt #type: ignore + raise ValueError("time must either be a string or a dt object") time = dtime.strftime("%H:%M:%S") if not "\n" in message: print(f"[{level}][{origin}][{time}] {message}", file=stream) diff --git a/overrides.py b/overrides.py index b463c01..2f8c810 100644 --- a/overrides.py +++ b/overrides.py @@ -6,7 +6,6 @@ _T = TypeVar("_T") bbytes = bbytes - class bytes(bbytes): """Local override of builtin bytes class to add "lazy_decode"