From c524513a9d7da39bd8a7684d34e1d6b7851dbf23 Mon Sep 17 00:00:00 2001 From: NatrixAeria Date: Tue, 20 Oct 2020 07:37:29 +0200 Subject: Notify members after a specified amount of time --- bot.py | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) (limited to 'bot.py') diff --git a/bot.py b/bot.py index 22ebbe6..16a34a6 100644 --- a/bot.py +++ b/bot.py @@ -16,6 +16,7 @@ class Cupido(commands.Bot): super().__init__(*args, **kwargs) self.meta_channel = None self.lobby_channel = None + self.notify_channel = None self.pair_channels = [] self.task = None self.reaction_map = {} @@ -82,6 +83,37 @@ class Cupido(commands.Bot): await answer(ctx, f'info: voice channel created "{lobby}" ({lobby.id})') return lobby + async def create_notify_channel(self, ctx): + channel = await ctx.guild.create_text_channel( + config.NOTIFY_CHANNEL_NAME, + category=self.meta_channel, + topic=config.NOTIFY_CHANNEL_TOPIC, + overwrites={ + self.user: discord.PermissionOverwrite( + add_reactions=True, + send_messages=True, + mention_everyone=True, + manage_roles=True, + manage_permissions=True, + manage_messages=True, + manage_channels=True, + read_messages=True, + read_message_history=True, + embed_links=True, + ), + ctx.guild.default_role: discord.PermissionOverwrite( + add_reactions=False, + send_messages=False, + send_tts_messages=False, + embed_links=False, + attach_files=False, + mention_everyone=False, + ), + } + ) + await answer(ctx, f'info: text channel created "{channel}" ({channel.id})') + return channel + def get_meta_channel(self, ctx): return self.meta_channel or discord.utils.get(ctx.guild.categories, name=config.CATEGORY_CHANNEL_NAME) @@ -93,6 +125,14 @@ class Cupido(commands.Bot): category=meta_channel )) + def get_notify_channel(self, ctx, meta_channel): + return (self.notify_channel + or discord.utils.get( + ctx.guild.text_channels, + name=config.NOTIFY_CHANNEL_NAME, + category=meta_channel + )) + def get_pair_channels_no_cache(self, ctx, meta_channel): return sorted((channel for channel in ctx.guild.voice_channels if channel.category == meta_channel @@ -157,7 +197,8 @@ class Cupido(commands.Bot): futures = [] for i in range(1, n + 1): futures.append(self.create_voice_channel(ctx, str(i), category=meta_channel)) - return await await_n(futures) + channels = await await_n(futures) + return channels async def get_channels(self, ctx, msg=True): meta_channel = self.get_meta_channel(ctx) @@ -246,6 +287,16 @@ class Cupido(commands.Bot): embed = discord.Embed(title=title, type="rich", description=text, colour=color) await (await channel).send(embed=embed) + async def print_scoreboard(self, ctx, target): + text = config.SCOREBOARD_TEXT + scores = [i for i in self.score_map.items()] + scores = sorted(scores, reverse=True, key=lambda i: i[1]) + for n, (member, score) in enumerate(scores): + if score > 0: + text += f'\n {n+1}. {self.get_username(member)} hat {score} Punkt{"" if score == 1 else "e"}' + embed = discord.Embed(title=config.SCOREBOARD_TITLE, type="rich", description=text, colour=discord.Colour.purple()) + await target.send(embed=embed) + def main(): token = getenv(config.TOKEN_ENV_VAR) -- cgit v1.2.3-54-g00ecf