Add .remove admin command

This commit is contained in:
Rampoina 2022-01-20 19:48:29 +01:00
parent 7921f44058
commit d2f13337b0
2 changed files with 29 additions and 1 deletions

View File

@ -1,7 +1,8 @@
# SPDX-License-Identifier: MIT
[host]
server = chat.freenode.invalid
server = irc.freegamedev.net
nickname = matchmaking-bot
channels = #matchmaking-test
#Skipping ':' means using default port 1234
connections = tilde tildeverse.org foo foo.bar:6969
admins = {"#matchmaking-test: ["Rampoina","franzopow","emorrp1"], "#other": ["test"]}

27
bot.py
View File

@ -6,10 +6,12 @@ from ircrobots import Bot as BaseBot
from ircrobots import Server as BaseServer
from ircrobots import ConnectionParams
import pickle
import json
servers = []
match_players = {}
connections = {}
admins = {}
def update_file(name):
with open(f"playerlist-{name}.txt", "wb") as file:
@ -85,7 +87,22 @@ class Server(BaseServer):
await self.send(build("PRIVMSG", [chan, "ERROR: no players in " + game + " list."]))
else:
await self.send(build("PRIVMSG", [chan, game + " players: " + str(['_' + e for e in match_players[self.name + '-' + chan][game]])]))
elif line.params[1].startswith(".remove"):
channel = self.channels[line.params[0].lstrip("@")].name
if channel in admins[self.name]:
fadmins = admins[self.name][channel]
else:
fadmins = []
user = line.source.split('!')[0]
game = " ".join(line.params[1].split(" ")[1:]).lower()
if game not in match_players[self.name + '-' + chan]:
await self.send(build("PRIVMSG", [chan, "ERROR: game " + game + " not found"]))
if user not in fadmins:
await self.send(build("PRIVMSG", [chan, "ERROR: user " + user + " is not an admin"]))
if user in fadmins and game in match_players[self.name + '-' + chan]:
del match_players[self.name + '-' + chan][game]
await self.send(build("PRIVMSG", [chan, "Removed " + game]))
elif line.params[1].startswith(".del"):
user = line.source.split('!')[0]
if len(line.params[1].split(" ")) < 2:
@ -128,9 +145,19 @@ async def main():
elif not config[section]['channels']:
print(f"ERROR: You didn't define any channels in section {section}.")
exit(1)
elif not config[section]['admins']:
print(f"ERROR: You didn't define any admins in section {section}.")
exit(1)
server = config[section]['server']
nickname = config[section]['nickname']
channels = set(config[section]['channels'].split())
try:
admins[section] = json.loads(config[section]['admins'])
except Exception as e:
print(f"ERROR: Invalid admins in section {section}.")
print(e)
exit(1)
if config[section]['connections']:
if len(config[section]['connections'].split()) % 2 != 0: # If connections isn't even
print(f"ERROR: The section {section} has an invalid 'connections' defined.")