Example #1
0
    async def settings(self, ctx):
        """Shows the reminders role, channel, times, and timezone settings."""
        settings = self.guild_map[ctx.guild.id]
        channel_id, role_id, before, timezone, \
            website_allowed_patterns, website_disallowed_patterns = settings
        channel = ctx.guild.get_channel(channel_id)
        role = ctx.guild.get_role(role_id)
        if channel is None:
            raise RemindersCogError('No channel set for reminders')
        if role is None:
            raise RemindersCogError('No role set for reminders')
        if before is None:
            raise RemindersCogError('No reminder_times set for reminders')

        subscribed_websites_str = ", ".join(
            website for website, patterns in website_allowed_patterns.items()
            if patterns)

        before_str = ', '.join(str(before_mins) for before_mins in before)
        embed = discord_common.embed_success('Current reminder settings')
        embed.add_field(name='Channel', value=channel.mention)
        embed.add_field(name='Role', value=role.mention)
        embed.add_field(name='Before',
                        value=f'At {before_str} mins before contest')
        embed.add_field(name='Subscribed websites',
                        value=f'{subscribed_websites_str}')
        await ctx.send(embed=embed)
Example #2
0
 async def role(self, ctx, role: discord.Role):
     """Sets the reminder role to the given role.
     """
     if not role.mentionable:
         raise RemindersCogError(
             'The role for reminders must be mentionable')
     self.guild_map[ctx.guild.id].role_id = role.id
     await ctx.send(embed=discord_common.embed_success(
         f'Succesfully set the reminder role to {role.mention}'))
Example #3
0
 async def reset_judges_settings(self, ctx):
     """ Resets the judges settings to the default ones.
     """
     self.guild_map[ctx.guild.id].website_allowed_patterns = \
         _WEBSITE_ALLOWED_PATTERNS
     self.guild_map[ctx.guild.id].website_disallowed_patterns = \
         _WEBSITE_DISALLOWED_PATTERNS
     await ctx.send(embed=discord_common.embed_success(
         'Succesfully reset the judges settings to the default ones'))
Example #4
0
 async def off(self, ctx):
     """Unsubscribes you from contest reminders."""
     role = self._get_remind_role(ctx.guild)
     if role not in ctx.author.roles:
         embed = discord_common.embed_neutral(
             'You are not subscribed to contest reminders')
     else:
         await ctx.author.remove_roles(
             role, reason='User unsubscribed from contest reminders')
         embed = discord_common.embed_success(
             'Successfully unsubscribed from contest reminders')
     await ctx.send(embed=embed)
Example #5
0
 async def reset_judges_settings(self, ctx):
     """ Resets the judges settings to the default ones.
     """
     _, _, _, _, \
         default_allowed_patterns, default_disallowed_patterns = \
         get_default_guild_settings()
     self.guild_map[ctx.guild.id].website_allowed_patterns = \
         default_allowed_patterns
     self.guild_map[ctx.guild.id].website_disallowed_patterns = \
         default_disallowed_patterns
     await ctx.send(embed=discord_common.embed_success(
         'Succesfully reset the judges settings to the default ones'))
Example #6
0
 async def settz(self, ctx, timezone: str):
     """Sets the server's timezone to the given timezone.
     """
     if not (timezone in pytz.all_timezones):
         desc = ('The given timezone is invalid\n\n'
                 'Examples of valid timezones:\n\n')
         desc += '\n'.join(random.sample(pytz.all_timezones, 5))
         desc += '\n\nAll valid timezones can be found [here]'
         desc += f'({_PYTZ_TIMEZONES_GIST_URL})'
         raise RemindersCogError(desc)
     self.guild_map[ctx.guild.id].localtimezone = pytz.timezone(timezone)
     await ctx.send(embed=discord_common.embed_success(
         f'Succesfully set the server timezone to {timezone}'))
Example #7
0
 async def on(self, ctx):
     """Subscribes you to contest reminders.
     Use 't;remind settings' to see the current settings.
     """
     role = self._get_remind_role(ctx.guild)
     if role in ctx.author.roles:
         embed = discord_common.embed_neutral(
             'You are already subscribed to contest reminders')
     else:
         await ctx.author.add_roles(
             role, reason='User subscribed to contest reminders')
         embed = discord_common.embed_success(
             'Successfully subscribed to contest reminders')
     await ctx.send(embed=embed)
Example #8
0
    async def before(self, ctx, *reminder_times: int):
        """Sets a reminder `x` minutes before the contests
           for each `x` in `reminder_times`.

           e.g t;remind before 10 60 180
        """
        if not reminder_times or any(
                reminder_time <= 0 for reminder_time in reminder_times):
            raise RemindersCogError('Please provide valid `reminder_times`')
        reminder_times = list(reminder_times)
        reminder_times.sort(reverse=True)
        self.guild_map[ctx.guild.id].before = reminder_times
        await ctx.send(embed=discord_common.embed_success(
            'Succesfully set the reminder times to ' + f'{reminder_times}'))
Example #9
0
    async def here(self, ctx, role: discord.Role, *before: int):
        """Sets reminder channel to current channel,
        role to the given role, and reminder
        times to the given values in minutes.

        e.g t;remind here @Subscriber 10 60 180
        """
        if not role.mentionable:
            raise RemindersCogError(
                'The role for reminders must be mentionable')
        if not before or any(before_mins < 0 for before_mins in before):
            raise RemindersCogError('Please provide valid `before` values')
        before = list(before)
        before = sorted(before, reverse=True)
        self.guild_map[ctx.guild.id].role_id = role.id
        self.guild_map[ctx.guild.id].before = before
        self.guild_map[ctx.guild.id].channel_id = ctx.channel.id
        await ctx.send(embed=discord_common.embed_success(
            'Reminder settings saved successfully'))
Example #10
0
    async def unsubscribe(self, ctx, *websites: str):
        """Stop contest reminders from websites."""

        if all(website not in _SUPPORTED_WEBSITES for website in websites):
            supported_websites = ", ".join(_SUPPORTED_WEBSITES)
            embed = discord_common.embed_alert(
                f'None of these websites are supported for contest reminders.'
                f'\nSupported websites -\n {supported_websites}.')
        else:
            guild_id = ctx.guild.id
            unsubscribed, unsupported = self._set_guild_setting(
                guild_id, websites, defaultdict(list),
                defaultdict(lambda: ['']))
            unsubscribed_websites_str = ", ".join(unsubscribed)
            unsupported_websites_str = ", ".join(unsupported)
            success_str = f'Successfully unsubscribed from \
                    {unsubscribed_websites_str} for contest reminders.'

            success_str += f'\n{unsupported_websites_str} \
                {"are" if len(unsupported)>1 else "is"} \
                not supported.' if unsupported_websites_str else ""
            embed = discord_common.embed_success(success_str)
        await ctx.send(embed=embed)
Example #11
0
 async def clear(self, ctx):
     del self.guild_map[ctx.guild.id]
     await ctx.send(
         embed=discord_common.embed_success('Reminder settings cleared'))
Example #12
0
 async def here(self, ctx):
     """Sets reminder channel to current channel.
     """
     self.guild_map[ctx.guild.id].channel_id = ctx.channel.id
     await ctx.send(embed=discord_common.embed_success(
         f'Succesfully set the reminder channel to {ctx.channel.mention}'))