From b6c58e66fce5ed83f58d070a00bd4a318f11d621 Mon Sep 17 00:00:00 2001 From: Firepup Sixfifty Date: Sat, 20 Apr 2024 02:47:00 -0500 Subject: [PATCH] Support for raw commands at varying stages on first connection, unfinished twitch server connection (closes #3 on h's nest git server) --- bare.py | 3 +++ bot.py | 27 ++++++++++++++++++++++++++- config.py | 14 +++++++++++++- 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/bare.py b/bare.py index 3dfbae9..c48c599 100644 --- a/bare.py +++ b/bare.py @@ -36,6 +36,9 @@ class bot: ignores: list[str] threads: list[str] lastfmLink: LastFMNetwork + onIdntCmds: list[str] + onJoinCmds: list[str] + onStrtCmds: list[str] def __init__(self, server: str): ... diff --git a/bot.py b/bot.py index 012f381..1ec602c 100644 --- a/bot.py +++ b/bot.py @@ -45,19 +45,36 @@ class bot(bare.bot): if "interval" in conf.servers[server] else 50 ) - self.nick = "FireBot" + self.nick = conf.servers[server]["nick"] if "nick" in conf.servers[server] else "FireBot" self.queue: list[bbytes] = [] # pyright: ignore [reportInvalidTypeForm] self.sock = socket(AF_INET, SOCK_STREAM) self.current = "user" self.threads = ( conf.servers[server]["threads"] if "threads" in conf.servers[server] else [] ) + self.onIdntCmds = ( + conf.servers[server]["onIdntCmds"] if "onIdntCmds" in conf.servers[server] else [] + ) + self.onJoinCmds = ( + conf.servers[server]["onJoinCmds"] if "onJoinCmds" in conf.servers[server] else [] + ) + self.onStrtCmds = ( + conf.servers[server]["onStrtCmds"] if "onStrtCmds" in conf.servers[server] else [] + ) self.lastfmLink = conf.lastfmLink self.log(f"Start init for {self.server}") def connect(self) -> None: self.log(f"Joining {self.server}...") self.sock.connect((self.address, self.port)) + self.send("\n") # Just for sanity + if self.onStrtCmds: + for cmd in self.onStrtCmds: + self.send(cmd + "\n") + if "serverPass" in conf.servers[self.server]: + self.send( + f"PASS {conf.servers[self.server]['serverPass']}\n" + ) self.send(f"USER {self.nick} {self.nick} {self.nick} {self.nick}\n") self.send(f"NICK {self.nick}\n") ircmsg = "" @@ -124,6 +141,8 @@ class bot(bare.bot): print(bytes(ircmsg).lazy_decode()) if ircmsg.startswith("PING "): self.ping(ircmsg) + elif ircmsg.startswith("ERROR "): + self.exit("Lost connection to the server while joining a channel") elif len(ircmsg.split("\x01")) == 3: handlers.CTCP(self, ircmsg) elif code == 403: @@ -230,8 +249,14 @@ class bot(bare.bot): f"IDENTIFY FireBot {conf.servers[self.server]['pass']}", "NickServ" ) sleep(0.5) + if self.onIdntCmds: + for cmd in self.onIdntCmds: + self.send(cmd + "\n") for chan in self.channels: self.join(chan, "null", False) + if self.onJoinCmds: + for cmd in self.onJoinCmds: + self.send(cmd + "\n") tMgr = None if self.threads: tdict = {} diff --git a/config.py b/config.py index 2351bfd..401ef60 100644 --- a/config.py +++ b/config.py @@ -6,7 +6,7 @@ from typing import Optional, Any import bare, pylast load_dotenv() -__version__ = "v3.0.4" +__version__ = "v3.0.5-dev" npbase: str = ( "\[\x0303last\.fm\x03\] [A-Za-z0-9_[\]{}\\|\-^]{1,$MAX} (is listening|last listened) to: \x02.+ - .*\x02( \([0-9]+ plays\)( \[.*\])?)?" # pyright: ignore [reportInvalidStringEscapeSequence] ) @@ -54,6 +54,18 @@ servers: dict[str, dict[str, Any]] = { "169.254.253.107", "2600-6c5a-637f-1a85-0000-0000-0000-6667.inf6.spectrum.com", ], + "onIdntCmds": [ + "OPER e e" + ], + }, + "twitch": { + "nick": "fireschatbot", + "address": "irc.chat.twitch.tv", + "serverPass": env["twitch_pass"], + "channels": { + "#firepup650": 0, + }, + "admins": ["firepup650"], }, } admin_hosts: list[str] = ["firepup.firepi", "47.221.227.180"]