Don't ping the user .match ing, fixes #1

This commit is contained in:
Rampoina 2022-02-15 16:13:43 +01:00
parent 5f945f33a5
commit 9962c1e019
1 changed files with 24 additions and 16 deletions

40
bot.py
View File

@ -40,26 +40,34 @@ class Server(BaseServer):
else:
game = " ".join(line.params[1].split(" ")[1:]).lower()
ping = ""
user = line.source.split('!')[0]
if game not in match_players[self.name + '-' + chan]:
await self.send(build("PRIVMSG", [chan, "ERROR: no players in "+ game]))
else:
for player in match_players[self.name + '-' + chan][game]:
pfold = self.casefold(player)
if pfold in channel.users:
ping += f"{channel.users[pfold].nickname} "
else:
ping += f"{player} "
matches = match_players[self.name + '-' + chan][game]
others = list(set(matches) - set([user])) # don't ping the user who .matched
if len(others) > 0:
for player in others:
pfold = self.casefold(player)
if pfold in channel.users:
ping += f"{channel.users[pfold].nickname} "
else:
ping += f"{player} "
await self.send(build("PRIVMSG", [chan, "Anyone ready for " + game + f" : {ping} ?"]))
if connections[self.name]:
for connection,address in connections[self.name].items():
if connection in line.params[1]:
if ':' in address:
realaddress = address.split(':')[0]
port = address.split(':')[1]
self.send(build("PRIVMSG", [chan, f"Connect using nc {realaddress} {port}"]))
else:
self.send(build("PRIVMSG", [chan, f"Connect using nc {address} 1234"]))
else:
await self.send(build("PRIVMSG", [chan, user + ": you're the only one who plays this game :("]))
await self.send(build("PRIVMSG", [chan, "Anyone ready for " + game + f" : {ping} ?"]))
if connections[self.name]:
for connection,address in connections[self.name].items():
if connection in line.params[1]:
if ':' in address:
realaddress = address.split(':')[0]
port = address.split(':')[1]
self.send(build("PRIVMSG", [chan, f"Connect using nc {realaddress} {port}"]))
else:
self.send(build("PRIVMSG", [chan, f"Connect using nc {address} 1234"]))
elif line.params[1].startswith(".add"):
user = line.source.split('!')[0]