diff --git a/bot.py b/bot.py index abf8f23..60c8ad4 100644 --- a/bot.py +++ b/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) diff --git a/config.py b/config.py index 0370465..5ca2c0c 100644 --- a/config.py +++ b/config.py @@ -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"], }, diff --git a/handlers.py b/handlers.py index 81c83f2..a2f5262 100644 --- a/handlers.py +++ b/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, +}