forked from Firepup650/FireBot
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:
parent
58f67591ac
commit
b6c58e66fc
3 changed files with 42 additions and 2 deletions
3
bare.py
3
bare.py
|
@ -36,6 +36,9 @@ class bot:
|
||||||
ignores: list[str]
|
ignores: list[str]
|
||||||
threads: list[str]
|
threads: list[str]
|
||||||
lastfmLink: LastFMNetwork
|
lastfmLink: LastFMNetwork
|
||||||
|
onIdntCmds: list[str]
|
||||||
|
onJoinCmds: list[str]
|
||||||
|
onStrtCmds: list[str]
|
||||||
|
|
||||||
def __init__(self, server: str): ...
|
def __init__(self, server: str): ...
|
||||||
|
|
||||||
|
|
27
bot.py
27
bot.py
|
@ -45,19 +45,36 @@ class bot(bare.bot):
|
||||||
if "interval" in conf.servers[server]
|
if "interval" in conf.servers[server]
|
||||||
else 50
|
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.queue: list[bbytes] = [] # pyright: ignore [reportInvalidTypeForm]
|
||||||
self.sock = socket(AF_INET, SOCK_STREAM)
|
self.sock = socket(AF_INET, SOCK_STREAM)
|
||||||
self.current = "user"
|
self.current = "user"
|
||||||
self.threads = (
|
self.threads = (
|
||||||
conf.servers[server]["threads"] if "threads" in conf.servers[server] else []
|
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.lastfmLink = conf.lastfmLink
|
||||||
self.log(f"Start init for {self.server}")
|
self.log(f"Start init for {self.server}")
|
||||||
|
|
||||||
def connect(self) -> None:
|
def connect(self) -> None:
|
||||||
self.log(f"Joining {self.server}...")
|
self.log(f"Joining {self.server}...")
|
||||||
self.sock.connect((self.address, self.port))
|
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"USER {self.nick} {self.nick} {self.nick} {self.nick}\n")
|
||||||
self.send(f"NICK {self.nick}\n")
|
self.send(f"NICK {self.nick}\n")
|
||||||
ircmsg = ""
|
ircmsg = ""
|
||||||
|
@ -124,6 +141,8 @@ class bot(bare.bot):
|
||||||
print(bytes(ircmsg).lazy_decode())
|
print(bytes(ircmsg).lazy_decode())
|
||||||
if ircmsg.startswith("PING "):
|
if ircmsg.startswith("PING "):
|
||||||
self.ping(ircmsg)
|
self.ping(ircmsg)
|
||||||
|
elif ircmsg.startswith("ERROR "):
|
||||||
|
self.exit("Lost connection to the server while joining a channel")
|
||||||
elif len(ircmsg.split("\x01")) == 3:
|
elif len(ircmsg.split("\x01")) == 3:
|
||||||
handlers.CTCP(self, ircmsg)
|
handlers.CTCP(self, ircmsg)
|
||||||
elif code == 403:
|
elif code == 403:
|
||||||
|
@ -230,8 +249,14 @@ class bot(bare.bot):
|
||||||
f"IDENTIFY FireBot {conf.servers[self.server]['pass']}", "NickServ"
|
f"IDENTIFY FireBot {conf.servers[self.server]['pass']}", "NickServ"
|
||||||
)
|
)
|
||||||
sleep(0.5)
|
sleep(0.5)
|
||||||
|
if self.onIdntCmds:
|
||||||
|
for cmd in self.onIdntCmds:
|
||||||
|
self.send(cmd + "\n")
|
||||||
for chan in self.channels:
|
for chan in self.channels:
|
||||||
self.join(chan, "null", False)
|
self.join(chan, "null", False)
|
||||||
|
if self.onJoinCmds:
|
||||||
|
for cmd in self.onJoinCmds:
|
||||||
|
self.send(cmd + "\n")
|
||||||
tMgr = None
|
tMgr = None
|
||||||
if self.threads:
|
if self.threads:
|
||||||
tdict = {}
|
tdict = {}
|
||||||
|
|
14
config.py
14
config.py
|
@ -6,7 +6,7 @@ from typing import Optional, Any
|
||||||
import bare, pylast
|
import bare, pylast
|
||||||
|
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
__version__ = "v3.0.4"
|
__version__ = "v3.0.5-dev"
|
||||||
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]
|
||||||
)
|
)
|
||||||
|
@ -54,6 +54,18 @@ servers: dict[str, dict[str, Any]] = {
|
||||||
"169.254.253.107",
|
"169.254.253.107",
|
||||||
"2600-6c5a-637f-1a85-0000-0000-0000-6667.inf6.spectrum.com",
|
"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"]
|
admin_hosts: list[str] = ["firepup.firepi", "47.221.227.180"]
|
||||||
|
|
Loading…
Reference in a new issue