Add support for #sus on irc.tilde.chat

This commit is contained in:
Ultracoolguy 2020-11-15 21:35:34 -04:00
parent 932e51bae7
commit a55cb3cd55
1 changed files with 26 additions and 23 deletions

49
bot.py
View File

@ -5,40 +5,38 @@ from ircrobots import Bot as BaseBot
from ircrobots import Server as BaseServer
from ircrobots import ConnectionParams
SERVERS = [ ("freenode", "irc.freenode.net") ]
SERVERS = (dict([("freenode", "irc.freenode.net"),
("tildeverse", "irc.tilde.chat")]))
match_players = set()
# match_players = set()
match_players = {"freenode": set(), "tildeverse": set()}
botnick = "matchmaking-bot"
chan = "#among-sus"
def update_file():
file = open("playerlist.txt", "w")
def update_file(name):
file = open(f"playerlist-{name}.txt", "w")
file.seek(0)
file.truncate()
for player in match_players:
for player in match_players[name]:
file.write(player + '\n')
def read_file():
file = open("playerlist.txt", "r")
for player in file:
match_players.add(player[:-1]) #Remove newline
for name in SERVERS:
file = open(f"playerlist-{name}.txt", "r")
for player in file:
match_players[name].add(player[:-1]) #Remove newline
file.close()
class Server(BaseServer):
async def line_read(self, line: Line):
print(f"{self.name} < {line.format()}")
if line.command == "001":
print(f"connected to {self.isupport.network}")
await self.send(build("JOIN", [chan]))
elif "PRIVMSG" in line.command and chan in line.params[0]:
if "PRIVMSG" in line.command and self.params.autojoin[0] in line.params[0]:
chan = self.channels[line.params[0]].name
if line.params[1].startswith(".matchmake"):
channel = self.channels[line.params[0]]
ping = ""
for player in match_players:
for player in match_players[self.name]:
pfold = self.casefold(player)
if pfold in channel.users:
ping += f"{channel.users[pfold].nickname} "
@ -47,20 +45,21 @@ class Server(BaseServer):
elif line.params[1].startswith(".matchadd"):
if user in match_players:
user = line.source.split('!')[0]
if user in match_players[self.name]:
await self.send(build("PRIVMSG", [chan, "ERROR: player already in list."]))
else:
match_players.add(user)
update_file()
match_players[self.name].add(user)
update_file(self.name)
await self.send(build("PRIVMSG", [chan, "Added to the match list."]))
elif line.params[1].startswith(".matchdel"):
user = line.source.split('!')[0]
if user not in match_players:
if user not in match_players[self.name]:
await self.send(build("PRIVMSG", [chan, "ERROR: player isn't in list."]))
else:
match_players.remove(user)
update_file()
match_players[self.name].remove(user)
update_file(self.name)
await self.send(build("PRIVMSG", [chan, "Removed from match list."]))
elif line.params[1].startswith(".help"):
@ -80,8 +79,12 @@ class Bot(BaseBot):
async def main():
read_file()
bot = Bot()
for name, host in SERVERS:
for name, host in SERVERS.items():
params = ConnectionParams(botnick, host, 6697, True)
if name == "freenode":
params.autojoin = ["#among-sus"]
elif name == "tildeverse":
params.autojoin = ["#sus"]
await bot.add_server(name, params)
await bot.run()