Move all handlers out of bot.py into handlers.py, minor config update
This commit is contained in:
parent
9bf199bb48
commit
cc4a4d0e1f
3 changed files with 30 additions and 9 deletions
10
bot.py
10
bot.py
|
@ -90,7 +90,7 @@ class bot(bare.bot):
|
|||
for subchan in chans:
|
||||
self.join(subchan, origin)
|
||||
return
|
||||
if chan.startswith("0") or (chan == "#main" and lock):
|
||||
if chan.startswith("0") or (chan == "#main" and lock and self.server != "replirc"):
|
||||
if origin != "null":
|
||||
self.msg(f"Refusing to join channel {chan} (protected)", origin)
|
||||
return
|
||||
|
@ -213,17 +213,13 @@ class bot(bare.bot):
|
|||
action = ircmsg.split(" ", 2)[1].strip()
|
||||
except IndexError:
|
||||
pass
|
||||
if action == "PRIVMSG":
|
||||
res, chan = handlers.PRIVMSG(self, ircmsg)
|
||||
if action in handlers.handles:
|
||||
res, chan = handlers.handles[action](self, ircmsg)
|
||||
if res == "reload":
|
||||
reload(conf)
|
||||
reload(cmds)
|
||||
reload(handlers)
|
||||
self.msg("Reloaded successfully", chan) # type: ignore
|
||||
elif action == "NICK":
|
||||
name = ircmsg.split("!", 1)[0][1:]
|
||||
if name == self.nick:
|
||||
self.nick = ircmsg.split("NICK", 1)[1].split(":", 1)[1].strip()
|
||||
else:
|
||||
if ircmsg.startswith("PING "):
|
||||
self.ping(ircmsg)
|
||||
|
|
|
@ -15,7 +15,7 @@ servers: dict[str, dict[str, Any]] = {
|
|||
"port": 6601,
|
||||
"interval": 200,
|
||||
"pass": env["ircnow_pass"],
|
||||
"channels": {"#random": 0, "#dice": 0, "#offtopic": 0},
|
||||
"channels": {"#random": 0, "#dice": 0, "#offtopic": 0, "#main/replirc": 0},
|
||||
"admins": [],
|
||||
"hosts": ["9pfs.repl.co"],
|
||||
},
|
||||
|
|
27
handlers.py
27
handlers.py
|
@ -151,5 +151,30 @@ def PRIVMSG(bot: bare.bot, msg: str) -> tuple[Union[None, str], Union[None, str]
|
|||
mm.close()
|
||||
return None, None
|
||||
|
||||
def NICK(bot: bare.bot, msg: str) -> tuple[Union[None, str], Union[None, str]]:
|
||||
name = msg.split("!", 1)[0][1:]
|
||||
if name == bot.nick:
|
||||
bot.nick = msg.split("NICK", 1)[1].split(":", 1)[1].strip()
|
||||
return None, None
|
||||
|
||||
handles = {"PRIVMSG": PRIVMSG}
|
||||
def KICK(bot: bare.bot, msg: str) -> tuple[Union[None, str], Union[None, str]]:
|
||||
important = msg.split("KICK", 1)[1].split(":", 1)[0].strip().split(" ")
|
||||
channel = important[0]
|
||||
kicked = important[1]
|
||||
if kicked == bot.nick:
|
||||
bot.channels.pop(channel, None)
|
||||
return None, None
|
||||
|
||||
def PART(bot: bare.bot, msg: str) -> tuple[Union[None, str], Union[None, str]]:
|
||||
parted = msg.split("!", 1)[0][1:]
|
||||
channel = msg.split("PART", 1)[1].split(":", 1)[0].strip()
|
||||
if parted == bot.nick:
|
||||
bot.channels.pop(channel, None)
|
||||
return None, None
|
||||
|
||||
handles = {
|
||||
"PRIVMSG": PRIVMSG,
|
||||
"NICK": NICK,
|
||||
"KICK": KICK,
|
||||
"PART": PART,
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue