diff options
Diffstat (limited to 'bot.py')
-rw-r--r-- | bot.py | 23 |
1 files changed, 18 insertions, 5 deletions
@@ -12,7 +12,7 @@ from collections import defaultdict as dd class Cupido(commands.Bot): - def __init__(self, *args, **kwargs): + def __init__(self, admin_channel, *args, **kwargs): super().__init__(*args, **kwargs) self.meta_channel = None self.lobby_channel = None @@ -23,6 +23,7 @@ class Cupido(commands.Bot): self.read_file() self.score_map = dd(lambda: 0) self.oldgroups = set() + self.admin_channel = admin_channel def read_file(self): try: @@ -60,10 +61,18 @@ class Cupido(commands.Bot): await answer(ctx, f'info: category created "{category}" ({category.id})') return category + async def create_voice_channel(self, ctx, name, category=None): + channel = await ctx.guild.create_voice_channel( + config.LOBBY_CHANNEL_NAME, + category=self.meta_channel, + ) + await channel.set_permissions(ctx.guild.default_role, **config.CHANNEL_PERMISSIONS) + return channel + async def create_lobby(self, ctx): - lobby = await ctx.guild.create_voice_channel( + lobby = await self.create_voice_channel( + ctx, config.LOBBY_CHANNEL_NAME, - topic=config.LOBBY_CHANNEL_TOPIC, category=self.meta_channel, ) await answer(ctx, f'info: voice channel created "{lobby}" ({lobby.id})') @@ -142,7 +151,7 @@ class Cupido(commands.Bot): await self.destroy_pair_channels(ctx, meta_channel) futures = [] for i in range(1, n + 1): - futures.append(ctx.guild.create_voice_channel(str(i), category=meta_channel)) + futures.append(self.create_voice_channel(ctx, str(i), category=meta_channel)) return await await_n(futures) async def get_channels(self, ctx): @@ -224,7 +233,11 @@ def main(): if token is None: print('error: no token was given') sys.exit(1) - bot = Cupido(activity=discord.Game(name=config.GAME_STATUS), command_prefix=config.COMMAND_PREFIX, case_insensitive=True) + admin_channel = getenv(config.ADMIN_CHANNEL_ENV_VAR) + if admin_channel is None: + print('error: no admin channel was given') + sys.exit(1) + bot = Cupido(int(admin_channel), activity=discord.Game(name=config.GAME_STATUS), command_prefix=config.COMMAND_PREFIX, case_insensitive=True) bot.remove_command('help') for cmd in bot_commands: bot.add_command(cmd) |