forked from Firepup650/FireBot
Formatting
This commit is contained in:
parent
2c10e267e5
commit
b26bd4097f
4 changed files with 18 additions and 22 deletions
2
bare.py
2
bare.py
|
@ -1,9 +1,11 @@
|
||||||
#!/usr/bin/python3
|
#!/usr/bin/python3
|
||||||
from socket import socket
|
from socket import socket
|
||||||
from overrides import bytes, bbytes
|
from overrides import bytes, bbytes
|
||||||
|
|
||||||
logs = ...
|
logs = ...
|
||||||
re = ...
|
re = ...
|
||||||
from typing import NoReturn, Union
|
from typing import NoReturn, Union
|
||||||
|
|
||||||
cmds = ...
|
cmds = ...
|
||||||
conf = ...
|
conf = ...
|
||||||
sleep = ...
|
sleep = ...
|
||||||
|
|
25
handlers.py
25
handlers.py
|
@ -7,6 +7,7 @@ from overrides import bytes, bbytes
|
||||||
from importlib import reload
|
from importlib import reload
|
||||||
import bare
|
import bare
|
||||||
|
|
||||||
|
|
||||||
def CTCP(bot: bare.bot, msg: str) -> bool:
|
def CTCP(bot: bare.bot, msg: str) -> bool:
|
||||||
sender = msg.split("!", 1)[0][1:]
|
sender = msg.split("!", 1)[0][1:]
|
||||||
kind = msg.split("\x01")[1].split(" ", 1)[0]
|
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")
|
bot.log(f'Unknown CTCP "{kind}"', "WARN")
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
|
||||||
def PRIVMSG(bot: bare.bot, msg: str) -> Union[None, str]:
|
def PRIVMSG(bot: bare.bot, msg: str) -> Union[None, 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:]
|
||||||
|
@ -53,9 +55,7 @@ def PRIVMSG(bot: bare.bot, msg: str) -> Union[None, str]:
|
||||||
name = Nname
|
name = Nname
|
||||||
message = msg.split(">", 1)[1].strip()
|
message = msg.split(">", 1)[1].strip()
|
||||||
else:
|
else:
|
||||||
message = (
|
message = msg.split("PRIVMSG", 1)[1].split(":", 1)[1].strip()
|
||||||
msg.split("PRIVMSG", 1)[1].split(":", 1)[1].strip()
|
|
||||||
)
|
|
||||||
elif name == bot.nick:
|
elif name == bot.nick:
|
||||||
return # type: ignore
|
return # type: ignore
|
||||||
else:
|
else:
|
||||||
|
@ -82,10 +82,7 @@ def PRIVMSG(bot: bare.bot, msg: str) -> Union[None, str]:
|
||||||
for cmd in cmds.data:
|
for cmd in cmds.data:
|
||||||
triggers = [cmd]
|
triggers = [cmd]
|
||||||
triggers.extend(cmds.data[cmd]["aliases"])
|
triggers.extend(cmds.data[cmd]["aliases"])
|
||||||
triggers = list(
|
triggers = list(call.replace("$BOTNICK", bot.nick.lower()) for call in triggers)
|
||||||
call.replace("$BOTNICK", bot.nick.lower())
|
|
||||||
for call in triggers
|
|
||||||
)
|
|
||||||
if conf.mfind(
|
if conf.mfind(
|
||||||
message.lower(),
|
message.lower(),
|
||||||
triggers,
|
triggers,
|
||||||
|
@ -105,9 +102,7 @@ def PRIVMSG(bot: bare.bot, msg: str) -> Union[None, str]:
|
||||||
if not handled:
|
if not handled:
|
||||||
for check in cmds.checks:
|
for check in cmds.checks:
|
||||||
if re.search(
|
if re.search(
|
||||||
check.replace("$MAX", str(bot.nicklen)).replace(
|
check.replace("$MAX", str(bot.nicklen)).replace("$BOTNICK", bot.nick),
|
||||||
"$BOTNICK", bot.nick
|
|
||||||
),
|
|
||||||
message,
|
message,
|
||||||
):
|
):
|
||||||
cmds.call[check](bot, chan, name, 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")
|
mm = open("mastermessages.txt", "r")
|
||||||
q = mm.readlines()
|
q = mm.readlines()
|
||||||
sel = conf.decode_escapes(
|
sel = conf.decode_escapes(
|
||||||
str(r.sample(q, 1))
|
str(r.sample(q, 1)).strip("[]'").replace("\\n", "").strip('"')
|
||||||
.strip("[]'")
|
|
||||||
.replace("\\n", "")
|
|
||||||
.strip('"')
|
|
||||||
)
|
)
|
||||||
bot.msg(f"[QUOTE] {sel}", chan)
|
bot.msg(f"[QUOTE] {sel}", chan)
|
||||||
mm.close()
|
mm.close()
|
||||||
return # type: ignore
|
return # type: ignore
|
||||||
|
|
||||||
handles = {
|
|
||||||
"PRIVMSG": PRIVMSG
|
handles = {"PRIVMSG": PRIVMSG}
|
||||||
}
|
|
||||||
|
|
5
logs.py
5
logs.py
|
@ -5,7 +5,10 @@ from typing import Union
|
||||||
|
|
||||||
|
|
||||||
def log(
|
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:
|
) -> None:
|
||||||
if level in ["EXIT", "CRASH"]:
|
if level in ["EXIT", "CRASH"]:
|
||||||
stream = stderr
|
stream = stderr
|
||||||
|
|
|
@ -28,14 +28,14 @@ class bytes(bbytes):
|
||||||
errors: str = "strict",
|
errors: str = "strict",
|
||||||
) -> _T:
|
) -> _T:
|
||||||
if type(thing) == str:
|
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:
|
elif thing == None:
|
||||||
cls.value = super().__new__(cls) # type: ignore
|
cls.value = super().__new__(cls) # type: ignore
|
||||||
elif thing != None:
|
elif thing != None:
|
||||||
cls.value = super().__new__(cls, thing) # type: ignore
|
cls.value = super().__new__(cls, thing) # type: ignore
|
||||||
else:
|
else:
|
||||||
raise AttributeError("This shouldn't happen")
|
raise AttributeError("This shouldn't happen")
|
||||||
return cls.value # type: ignore
|
return cls.value # type: ignore
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def lazy_decode(cls):
|
def lazy_decode(cls):
|
||||||
|
|
Loading…
Reference in a new issue