async def me(self, ctx, arg: str = None): settings = cf_common.user_db.get_reminder_settings(ctx.guild.id) if settings is None: raise ContestCogError( 'To use this command, reminder settings must be set by an admin' ) _, role_id, _ = settings role = ctx.guild.get_role(int(role_id)) if role is None: raise ContestCogError( 'The role set for reminders is no longer available') if arg is None: if role in ctx.author.roles: await ctx.send(embed=discord_common.embed_neutral( 'You are already subscribed to contest reminders')) return await ctx.author.add_roles( role, reason='User subscribed to contest reminders') await ctx.send(embed=discord_common.embed_success( 'Successfully subscribed to contest reminders')) elif arg == 'not': if role not in ctx.author.roles: await ctx.send(embed=discord_common.embed_neutral( 'You are not subscribed to contest reminders')) return await ctx.author.remove_roles( role, reason='User unsubscribed from contest reminders') await ctx.send(embed=discord_common.embed_success( 'Successfully unsubscribed from contest reminders'))
async def _generic_remind(self, ctx, action, role_name, what): roles = [role for role in ctx.guild.roles if role.name == role_name] if not roles: raise HandleCogError( f'Role `{role_name}` not present in the server') role = roles[0] if action == 'give': if role in ctx.author.roles: await ctx.send(embed=discord_common.embed_neutral( f'You are already subscribed to {what} reminders')) return await ctx.author.add_roles( role, reason=f'User subscribed to {what} reminders') await ctx.send(embed=discord_common.embed_success( f'Successfully subscribed to {what} reminders')) elif action == 'remove': if role not in ctx.author.roles: await ctx.send(embed=discord_common.embed_neutral( f'You are not subscribed to {what} reminders')) return await ctx.author.remove_roles( role, reason=f'User unsubscribed from {what} reminders') await ctx.send(embed=discord_common.embed_success( f'Successfully unsubscribed from {what} reminders')) else: raise HandleCogError(f'Invalid action {action}')
async def settings(self, ctx): """Shows the role, channel and before time settings.""" settings = cf_common.user_db.get_reminder_settings(ctx.guild.id) if settings is None: await ctx.send( embed=discord_common.embed_neutral('Reminder not set')) return channel_id, role_id, before = settings channel_id, role_id, before = int(channel_id), int( role_id), json.loads(before) channel, role = ctx.guild.get_channel(channel_id), ctx.guild.get_role( role_id) if channel is None: raise ContestCogError( 'The channel set for reminders is no longer available') if role is None: raise ContestCogError( 'The role set for reminders is no longer available') 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') await ctx.send(embed=embed)
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)
async def _send_contest_list(self, ctx, contests, *, title, empty_msg): if contests is None: raise ContestCogError('Contest list not present') if len(contests) == 0: await ctx.send(embed=discord_common.embed_neutral(empty_msg)) return pages = self._make_contest_pages(contests, title) paginator.paginate(self.bot, ctx.channel, pages, wait_time=_CONTEST_PAGINATE_WAIT_TIME, set_pagenum_footers=True)
async def on(self, ctx): """Subscribes you to contest reminders. Use ';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)
async def unmagic_all(self, ctx): """Updates handles of all users that have changed handles (typically new year's magic)""" to_fix = await self._needs_fixing( ctx, cf_common.user_db.get_handles_for_guild(ctx.guild.id)) embed = discord_common.embed_neutral(f'Users to fix: {len(to_fix)}') await ctx.send(embed=embed) summary_embed = await self._fix(ctx, to_fix) await ctx.send(embed=summary_embed)