Support for raw commands at varying stages on first connection, unfinished twitch server connection (closes #3 on h's nest git server)

This commit is contained in:
Firepup Sixfifty 2024-04-20 02:47:00 -05:00
parent 58f67591ac
commit b6c58e66fc
Signed by: Firepup650
GPG key ID: 7C92E2ABBBFAB9BA
3 changed files with 42 additions and 2 deletions

View file

@ -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): ...

27
bot.py
View file

@ -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 = {}

View file

@ -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"]