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