Shorten command names and add .list command

This commit is contained in:
Rampoina 2021-07-12 12:34:50 +02:00
parent 64ac0d5798
commit cb10c69427
1 changed files with 15 additions and 4 deletions

19
bot.py
View File

@ -27,9 +27,10 @@ def read_file(name):
class Server(BaseServer):
async def line_read(self, line: Line):
print("Line Params: ", line.params)
if "PRIVMSG" in line.command and any(channel in line.params[0] for channel in self.params.autojoin):
chan = self.channels[line.params[0]].name
if line.params[1].startswith(".matchmake"):
if line.params[1].startswith(".match"):
channel = self.channels[line.params[0]]
if len(line.params[1].split(" ")) < 2:
await self.send(build("PRIVMSG", [chan, "ERROR: game not specified"]))
@ -55,7 +56,7 @@ class Server(BaseServer):
else:
self.send(build("PRIVMSG", [chan, f"Connect using nc {address} 1234"]))
elif line.params[1].startswith(".matchadd"):
elif line.params[1].startswith(".add"):
user = line.source.split('!')[0]
if len(line.params[1].split(" ")) < 2:
await self.send(build("PRIVMSG", [chan, "ERROR: game not specified"]))
@ -70,7 +71,17 @@ class Server(BaseServer):
update_file(self.name + '-' + chan)
await self.send(build("PRIVMSG", [chan, "Added " + user + " to the " + game + " match list."]))
elif line.params[1].startswith(".matchdel"):
elif line.params[1].startswith(".list"):
user = line.source.split('!')[0]
if len(line.params[1].split(" ")) < 2:
await self.send(build("PRIVMSG", [user, "list: " + str(match_players[self.name + '-' + chan])]))
else:
game = " ".join(line.params[1].split(" ")[1:]).lower()
if game not in match_players[self.name + '-' + chan]:
await self.send(build("PRIVMSG", [user, "ERROR: no players in " + game + " list."]))
else:
await self.send(build("PRIVMSG", [user, game + " players: " + str(match_players[self.name + '-' + chan][game])]))
elif line.params[1].startswith(".del"):
user = line.source.split('!')[0]
if len(line.params[1].split(" ")) < 2:
await self.send(build("PRIVMSG", [chan, "ERROR: game not specified"]))
@ -89,7 +100,7 @@ class Server(BaseServer):
await self.send(build("PRIVMSG", [chan, "Removed " + user + " from the " + game + " match list."]))
elif line.params[1].startswith(".help"):
await self.send(build("PRIVMSG", [chan, " .matchadd game: Add to list; .matchdel game: Remove from list; .matchmake game: Ping everyone on list"]))
await self.send(build("PRIVMSG", [chan, " .add game: Add to list; .del game: Remove from list; .match game: Ping everyone on list"]))
async def line_send(self, line: Line):
print(f"{self.name} > {line.format()}")