forked from Firepup650/FireBot
Improve cmd checking, add two new debug commands, and watch for gaining/losing ops
This commit is contained in:
parent
fdd490518c
commit
58060a5249
5 changed files with 61 additions and 5 deletions
2
bare.py
2
bare.py
|
@ -43,6 +43,8 @@ class bot:
|
||||||
markov: MarkovBot
|
markov: MarkovBot
|
||||||
autoMethod: str
|
autoMethod: str
|
||||||
dnsblMode: str
|
dnsblMode: str
|
||||||
|
statuses: dict[str, dict[str, str]]
|
||||||
|
ops: dict[str, bool]
|
||||||
|
|
||||||
def __init__(self, server: str): ...
|
def __init__(self, server: str): ...
|
||||||
|
|
||||||
|
|
1
bot.py
1
bot.py
|
@ -53,6 +53,7 @@ class bot(bare.bot):
|
||||||
)
|
)
|
||||||
self.queue: list[bbytes] = [] # pyright: ignore [reportInvalidTypeForm]
|
self.queue: list[bbytes] = [] # pyright: ignore [reportInvalidTypeForm]
|
||||||
self.statuses = {'firepup': {}}
|
self.statuses = {'firepup': {}}
|
||||||
|
self.ops = {}
|
||||||
self.sock = socket(AF_INET, SOCK_STREAM)
|
self.sock = socket(AF_INET, SOCK_STREAM)
|
||||||
self.current = "user"
|
self.current = "user"
|
||||||
self.threads = (
|
self.threads = (
|
||||||
|
|
24
commands.py
24
commands.py
|
@ -152,6 +152,26 @@ def debug(bot: bare.bot, chan: str, name: str, message: str) -> None:
|
||||||
bot.msg(f"[DEBUG] {dbg_out}", chan)
|
bot.msg(f"[DEBUG] {dbg_out}", chan)
|
||||||
|
|
||||||
|
|
||||||
|
def debugInternal(bot: bare.bot, chan: str, name: str, message: str) -> None:
|
||||||
|
things = dir(bot)
|
||||||
|
try:
|
||||||
|
thing = message.split(' ', 1)[1]
|
||||||
|
except IndexError:
|
||||||
|
bot.msg("You can't just ask me to lookup nothing.", chan)
|
||||||
|
return
|
||||||
|
if thing in things:
|
||||||
|
bot.msg(f"self.{thing} = {getattr(bot, thing)}", chan)
|
||||||
|
else:
|
||||||
|
bot.msg(f"I have nothing called \"{thing}\"", chan)
|
||||||
|
|
||||||
|
|
||||||
|
def debugEval(bot: bare.bot, chan: str, name: str, message: str) -> None:
|
||||||
|
try:
|
||||||
|
bot.msg(str(eval(message.split(' ', 1)[1])), chan)
|
||||||
|
except Exception as E:
|
||||||
|
bot.msg(f"Exception: {E}", chan)
|
||||||
|
|
||||||
|
|
||||||
def raw(bot: bare.bot, chan: str, name: str, message: str) -> None:
|
def raw(bot: bare.bot, chan: str, name: str, message: str) -> None:
|
||||||
bot.sendraw(message.split(" ", 1)[1])
|
bot.sendraw(message.split(" ", 1)[1])
|
||||||
|
|
||||||
|
@ -281,6 +301,8 @@ data: dict[str, dict[str, Any]] = {
|
||||||
"uptime": {"prefix": True, "aliases": []},
|
"uptime": {"prefix": True, "aliases": []},
|
||||||
"raw ": {"prefix": True, "aliases": ["cmd "], "check": checks.admin},
|
"raw ": {"prefix": True, "aliases": ["cmd "], "check": checks.admin},
|
||||||
"debug": {"prefix": True, "aliases": ["dbg", "d"], "check": checks.admin},
|
"debug": {"prefix": True, "aliases": ["dbg", "d"], "check": checks.admin},
|
||||||
|
"debugInternal": {"prefix": True, "aliases": ["dbgInt", "dI"], "check": checks.admin},
|
||||||
|
"debugEval": {"prefix": True, "aliases": ["dbgEval", "dE"], "check": checks.admin},
|
||||||
"8ball": {"prefix": True, "aliases": ["eightball", "8b"]},
|
"8ball": {"prefix": True, "aliases": ["eightball", "8b"]},
|
||||||
"join ": {"prefix": True, "aliases": [], "check": checks.admin},
|
"join ": {"prefix": True, "aliases": [], "check": checks.admin},
|
||||||
"quote": {"prefix": True, "aliases": ["q"]},
|
"quote": {"prefix": True, "aliases": ["q"]},
|
||||||
|
@ -314,6 +336,8 @@ call: dict[str, Callable[[bare.bot, str, str, str], None]] = {
|
||||||
"uptime": uptime,
|
"uptime": uptime,
|
||||||
"raw ": raw,
|
"raw ": raw,
|
||||||
"debug": debug,
|
"debug": debug,
|
||||||
|
"debugInternal": debugInternal,
|
||||||
|
"debugEval": debugEval,
|
||||||
"8ball": eball,
|
"8ball": eball,
|
||||||
"join ": join,
|
"join ": join,
|
||||||
"quote": quote,
|
"quote": quote,
|
||||||
|
|
16
config.py
16
config.py
|
@ -10,7 +10,7 @@ ipbl = DNSBLIpChecker()
|
||||||
hsbl = DNSBLDomainChecker()
|
hsbl = DNSBLDomainChecker()
|
||||||
|
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
__version__ = "v3.0.15"
|
__version__ = "v3.0.16"
|
||||||
npbase: str = (
|
npbase: str = (
|
||||||
"\[\x0303last\.fm\x03\] [A-Za-z0-9_[\]{}\\|\-^]{1,$MAX} (is listening|last listened) to: \x02.+ - .*\x02( \([0-9]+ plays\)( \[.*\])?)?" # pyright: ignore [reportInvalidStringEscapeSequence]
|
"\[\x0303last\.fm\x03\] [A-Za-z0-9_[\]{}\\|\-^]{1,$MAX} (is listening|last listened) to: \x02.+ - .*\x02( \([0-9]+ plays\)( \[.*\])?)?" # pyright: ignore [reportInvalidStringEscapeSequence]
|
||||||
)
|
)
|
||||||
|
@ -102,6 +102,20 @@ def decode_escapes(s: str) -> str:
|
||||||
return ESCAPE_SEQUENCE_RE.sub(decode_match, s)
|
return ESCAPE_SEQUENCE_RE.sub(decode_match, s)
|
||||||
|
|
||||||
|
|
||||||
|
def cmdFind(message: str, find: list, usePrefix: bool = True) -> bool:
|
||||||
|
cmd = None
|
||||||
|
try:
|
||||||
|
cmd = message.split(' ', 1)[0]
|
||||||
|
except IndexError: ...
|
||||||
|
if not cmd:
|
||||||
|
return False
|
||||||
|
if usePrefix:
|
||||||
|
return any(cmd == prefix + match for match in find)
|
||||||
|
else:
|
||||||
|
return any(cmd == match for match in find)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def mfind(message: str, find: list, usePrefix: bool = True) -> bool:
|
def mfind(message: str, find: list, usePrefix: bool = True) -> bool:
|
||||||
if usePrefix:
|
if usePrefix:
|
||||||
return any(message[: len(match) + 1] == prefix + match for match in find)
|
return any(message[: len(match) + 1] == prefix + match for match in find)
|
||||||
|
|
23
handlers.py
23
handlers.py
|
@ -103,7 +103,7 @@ def PRIVMSG(bot: bare.bot, msg: str) -> Union[tuple[None, None], tuple[str, str]
|
||||||
triggers = [cmd]
|
triggers = [cmd]
|
||||||
triggers.extend(cmds.data[cmd]["aliases"])
|
triggers.extend(cmds.data[cmd]["aliases"])
|
||||||
triggers = list(conf.sub(call, bot, chan, name).lower() for call in triggers)
|
triggers = list(conf.sub(call, bot, chan, name).lower() for call in triggers)
|
||||||
if conf.mfind(
|
if conf.cmdFind(
|
||||||
conf.sub(message, bot, chan, name).lower(),
|
conf.sub(message, bot, chan, name).lower(),
|
||||||
triggers,
|
triggers,
|
||||||
cmds.data[cmd]["prefix"],
|
cmds.data[cmd]["prefix"],
|
||||||
|
@ -124,7 +124,7 @@ def PRIVMSG(bot: bare.bot, msg: str) -> Union[tuple[None, None], tuple[str, str]
|
||||||
cmds.call[check](bot, chan, name, message)
|
cmds.call[check](bot, chan, name, message)
|
||||||
handled = True
|
handled = True
|
||||||
break
|
break
|
||||||
if not handled and conf.mfind(message, ["reload", "r"]):
|
if not handled and conf.cmdFind(message, ["reload", "r"]):
|
||||||
if checks.admin(bot, name, host, chan, "reload"):
|
if checks.admin(bot, name, host, chan, "reload"):
|
||||||
return "reload", chan
|
return "reload", chan
|
||||||
handled = True
|
handled = True
|
||||||
|
@ -194,7 +194,22 @@ def JOIN(bot: bare.bot, msg: str) -> tuple[None, None]:
|
||||||
|
|
||||||
|
|
||||||
def MODE(bot: bare.bot, msg: str) -> tuple[None, None]:
|
def MODE(bot: bare.bot, msg: str) -> tuple[None, None]:
|
||||||
pass
|
chan = msg.split("#", 1)[1].split(" ", 1)[0]
|
||||||
|
add = True if msg.split("#", 1)[1].split(" ", 2)[1][0] == "+" else False
|
||||||
|
modes = msg.split("#", 1)[1].split(" ", 2)[1][1:]
|
||||||
|
users = ""
|
||||||
|
try:
|
||||||
|
users = msg.split("#", 1)[1].split(" ", 2)[2].split()
|
||||||
|
except IndexError: ...
|
||||||
|
if len(modes) != len(users):
|
||||||
|
bot.log("Refusing to handle modes that do not have corresponding users.")
|
||||||
|
return None, None
|
||||||
|
for i in range(len(modes)):
|
||||||
|
if users[i] == bot.nick:
|
||||||
|
if modes[i] == "o":
|
||||||
|
bot.ops[chan] = add
|
||||||
|
bot.log(f"{'Got' if add else 'Lost'} ops in {chan}")
|
||||||
|
return None, None
|
||||||
|
|
||||||
|
|
||||||
def NULL(bot: bare.bot, msg: str) -> tuple[None, None]:
|
def NULL(bot: bare.bot, msg: str) -> tuple[None, None]:
|
||||||
|
@ -208,7 +223,7 @@ handles: dict[
|
||||||
"NICK": NICK,
|
"NICK": NICK,
|
||||||
"KICK": KICK,
|
"KICK": KICK,
|
||||||
"PART": PART,
|
"PART": PART,
|
||||||
"MODE": NULL,
|
"MODE": MODE,
|
||||||
"TOPIC": NULL,
|
"TOPIC": NULL,
|
||||||
"QUIT": QUIT,
|
"QUIT": QUIT,
|
||||||
"JOIN": JOIN,
|
"JOIN": JOIN,
|
||||||
|
|
Loading…
Reference in a new issue