Type hints and corrections

This commit is contained in:
Firepup Sixfifty 2023-11-17 23:23:46 -06:00
parent 426011bf4e
commit 7c51c056b0
Signed by: Firepup650
GPG key ID: 7C92E2ABBBFAB9BA
4 changed files with 11 additions and 10 deletions

4
bot.py
View file

@ -217,11 +217,11 @@ class bot(bare.bot):
pass pass
if action in handlers.handles: if action in handlers.handles:
res, chan = handlers.handles[action](self, ircmsg) res, chan = handlers.handles[action](self, ircmsg)
if res == "reload": if res == "reload" and type(chan) == str:
reload(conf) reload(conf)
reload(cmds) reload(cmds)
reload(handlers) reload(handlers)
self.msg("Reloaded successfully", chan) # type: ignore self.msg("Reloaded successfully", chan)
else: else:
if ircmsg.startswith("PING "): if ircmsg.startswith("PING "):
self.ping(ircmsg) self.ping(ircmsg)

View file

@ -2,7 +2,7 @@ import random as r
import config as conf import config as conf
import re import re
import commands as cmds import commands as cmds
from typing import Union from typing import Union, Callable
from overrides import bytes, bbytes from overrides import bytes, bbytes
from importlib import reload from importlib import reload
import bare import bare
@ -41,7 +41,7 @@ def CTCP(bot: bare.bot, msg: str) -> bool:
return False 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]” # Format of ":[Nick]![ident]@[host|vhost] PRIVMSG [channel] :[message]”
name = msg.split("!", 1)[0][1:] name = msg.split("!", 1)[0][1:]
host = msg.split("@", 1)[1].split(" ", 1)[0] 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 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:] name = msg.split("!", 1)[0][1:]
if name == bot.nick: if name == bot.nick:
bot.nick = msg.split("NICK", 1)[1].split(":", 1)[1].strip() bot.nick = msg.split("NICK", 1)[1].split(":", 1)[1].strip()
return None, None 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(" ") important = msg.split("KICK", 1)[1].split(":", 1)[0].strip().split(" ")
channel = important[0] channel = important[0]
kicked = important[1] kicked = important[1]
@ -168,7 +168,7 @@ def KICK(bot: bare.bot, msg: str) -> tuple[Union[None, str], Union[None, str]]:
return None, None 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:] parted = msg.split("!", 1)[0][1:]
channel = msg.split("PART", 1)[1].split(":", 1)[0].strip() channel = msg.split("PART", 1)[1].split(":", 1)[0].strip()
if parted == bot.nick: 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 return None, None
handles = { handles: dict[str, Callable[[bare.bot, str], Union[tuple[None, None], tuple[str, str]]]] = {
"PRIVMSG": PRIVMSG, "PRIVMSG": PRIVMSG,
"NICK": NICK, "NICK": NICK,
"KICK": KICK, "KICK": KICK,

View file

@ -18,8 +18,10 @@ def log(
dtime = dt.now() dtime = dt.now()
elif type(time) == str: elif type(time) == str:
raise ValueError('Only "now" is an accepted string argument for time') raise ValueError('Only "now" is an accepted string argument for time')
elif type(time) == dt:
dtime = time
else: 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") time = dtime.strftime("%H:%M:%S")
if not "\n" in message: if not "\n" in message:
print(f"[{level}][{origin}][{time}] {message}", file=stream) print(f"[{level}][{origin}][{time}] {message}", file=stream)

View file

@ -6,7 +6,6 @@ _T = TypeVar("_T")
bbytes = bbytes bbytes = bbytes
class bytes(bbytes): class bytes(bbytes):
"""Local override of builtin bytes class to add "lazy_decode" """Local override of builtin bytes class to add "lazy_decode"