async def check_in_list(self, ctx: commands.Context, page: int = None): """!kazhelp description: | Check your list of check-ins. The result is always PMed to you. Moderators can query any user's checkins with {{!checkin query}} instead. parameters: - name: page type: number optional: true description: The page number to access, if a user has more than 1 page of badges. default: last page (most recent) examples: - command: .checkin list description: List all your check-ins (last page if multiple pages). - command: .checkin list 4 description: List the 4th page of check-ins. """ try: db_records = self.c.query_check_ins(member=ctx.message.author) paginator = Pagination(db_records, self.ITEMS_PER_PAGE, align_end=True) if page is not None: paginator.page = max(0, min(paginator.total_pages - 1, page - 1)) await self.send_check_in_list(ctx.message.author, paginator, ctx.message.author) except orm.exc.NoResultFound: await self.bot.say("{} You haven't checked in yet!".format( ctx.message.author.mention))
async def quote_list(self, ctx: commands.Context, user: str, page: int = None): """ Retrieve a list of quotes. Reply is always PMed. Arguments: * user: Required. The user to find a quote for. See `.help quote` for valid formats. * page: Optional. The page number to access, if there are more than 1 pages of notes. Default: last page. Examples: .quote list @JaneDoe - List all quotes by JaneDoe (page 1 if multiple pages).. .quote list @JaneDoe 4 - List the 4th page of quotes by JaneDoe. """ logger.info("quote list: {}".format(message_log_str(ctx.message))) db_user = c.query_user(self.server, user) db_records = c.query_author_quotes(db_user) paginator = Pagination(db_records, self.QUOTES_PER_PAGE, align_end=True) if page is not None: paginator.page = max(0, min(paginator.total_pages - 1, page - 1)) await self.send_quotes_list(ctx.message.author, paginator, db_user, ctx.message.server)
async def quote_list(self, ctx: commands.Context, user: str, page: int = None): """!kazhelp description: Retrieve a list of quotes. Always PMed. parameters: - name: user type: "@user" description: > The user to find a quote for. Should be an @mention or a discord ID. - name: page type: number optional: true default: last page (most recent) description: The page number to show, if there are more than 1 page of quotes. examples: - command: .quote list @JaneDoe#0921 description: List all quotes by JaneDoe. - command: .quote list @JaneDoe#0921 4 description: List the 4th page of quotes by JaneDoe. """ db_user = c.query_user(self.server, user) if len(db_user.quotes) == 0: logger.warning("User has no quotes.") await self.bot.say("Sorry, {} has no quotes!".format(db_user.name)) return paginator = Pagination(db_user.quotes, self.QUOTES_PER_PAGE, align_end=True) if page is not None: paginator.page = max(0, min(paginator.total_pages - 1, page - 1)) await self.send_quotes_list(ctx.message.author, paginator, db_user)
async def removed(self, ctx, user: str, page: int = None): """!kazhelp description: Show all removed notes, optionally filtered by user. parameters: - name: user type: "@user" description: The user to filter by, or `all`. See {{!notes}} for user format. - name: page optional: true default: last page (latest notes) type: number description: The page number to show, if there are more than 1 page of notes. """ if user != 'all': db_user = await c.query_user(self.bot, user) db_group = c.query_user_group(db_user) db_records = c.query_user_records(db_group, removed=True) else: db_user = None db_group = None db_records = c.query_user_records(None, removed=True) records_pages = Pagination(db_records, self.NOTES_PAGE_SIZE, True) if page is not None: records_pages.page = max(1, min(records_pages.total_pages, page)) await self.show_record_page(ctx.message.channel, records=records_pages, user=db_user, group=db_group, title='*** Removed Records')
async def watches(self, ctx, page: int = None): """!kazhelp description: Show all watches currently in effect (i.e. all `watch`, `int` and `warn` records that are not expired). details: | 10 notes are shown per page. This is partly due to Discord message length limits, and partly to avoid too large a data dump in a single request. parameters: - name: page optional: true default: last page (latest notes) type: number description: The page number to show, if there are more than 1 page of notes. """ watch_types = (RecordType.watch, RecordType.int, RecordType.warn) db_records = c.query_unexpired_records(types=watch_types) records_pages = Pagination(db_records, self.NOTES_PAGE_SIZE, True) if page is not None: records_pages.page = max(1, min(records_pages.total_pages, page)) - 1 await self.show_record_page(ctx.message.channel, records=records_pages, user=None, title='Active Watches')
async def send_quotes_list(self, dest: discord.Channel, quotes: Pagination, user: model.User): title = "Quotes by {}".format(user.name) footer_text = "Page {:d}/{:d}".format(quotes.page + 1, quotes.total_pages) es = EmbedSplitter(title=title, color=self.EMBED_COLOR, auto_truncate=True) es.set_footer(text=footer_text) start_index, end_index = quotes.get_page_indices() for i, quote in enumerate(quotes.get_page_records()): # Format strings for this quote f_name = "#{:d}".format(start_index + i + 1) f_message = self.format_quote(quote, show_saved=False) + '\n\\_\\_\\_' es.add_field(name=f_name, value=f_message, inline=False) await self.send_message(dest, embed=es)
async def badges(self, ctx: commands.Context, user: MemberConverter2, page: int = None): """!kazhelp brief: Check a user's badges. description: | Check a user's badges. TIP: If you want to give a badge, leave a properly formatted message in {{badge_channel}}. See the top of the {{%BadgeManager}} page (web manual) or `.help BadgeManager` (in-bot help) for more information. parameters: - name: user type: "@mention" description: The user to check (as an @mention or a Discord ID). - name: page type: number optional: true description: The page number to access, if a user has more than 1 page of badges. default: last page (most recent) examples: - command: .badges @JaneDoe description: List all of JaneDoe's badges (most recent, if there are multiple pages). - command: .badges @JaneDoe 4 description: List the 4th page of JaneDoe's badges. """ user = user # type: discord.Member # for IDE type checking try: db_records = self.c.query_badges(member=user) paginator = Pagination(db_records, self.ITEMS_PER_PAGE, align_end=True) if page is not None: paginator.page = max(0, min(paginator.total_pages - 1, page - 1)) await self.show_badges(ctx.message.channel, paginator, user) except database.NoResultFound: await self.bot.say("{} hasn't gotten any badges yet!".format( user.mention))
async def send_quotes_list(self, dest: discord.Channel, quotes: Pagination, user: model.User, server: discord.Server): title = "Quotes by {}".format(user.name) footer_text = "Page {:d}/{:d}".format(quotes.page + 1, quotes.total_pages) base_len = len(title) + len(footer_text) em = discord.Embed(title=title, color=self.EMBED_COLOR) start_index, end_index = quotes.get_page_indices() total_fields = 0 total_len = base_len for i, quote in enumerate(quotes.get_page_records()): # Format strings for this quote f_name = "#{:d}".format(start_index + i + 1) f_message = self.format_quote(quote, show_saved=False) + '\n\\_\\_\\_' cur_len = len(f_name) + len(f_message) # check lengths and number of fields too_many_fields = total_fields + 1 > Limits.EMBED_FIELD_NUM embed_too_long = total_len + cur_len > int( 0.95 * Limits.EMBED_TOTAL) # if we can't fit this quote in this embed, send it and start a new one if too_many_fields or embed_too_long: await self.bot.send_message(dest, embed=em) em = discord.Embed(title=title, color=self.EMBED_COLOR) total_len = base_len total_fields = 0 # add the field for the current quote em.add_field(name=f_name, value=f_message, inline=False) # end of iteration updates total_len += cur_len em.set_footer(text=footer_text) await self.bot.send_message(dest, embed=em)
async def notes(self, ctx, user: str, page: int = None): """!kazhelp description: "Access a user's moderation logs." details: | 10 notes are shown per page. This is partly due to Discord message length limits, and partly to avoid too large a data dump in a single request. parameters: - name: user type: "@user" description: "The user for whom to retrieve moderation notes. This can be an `@mention`, a Discord ID (numerical only), or a KazTron ID (starts with `*`)." - name: page optional: true default: last page (latest notes) type: number description: "The page number to show, if there are more than 1 page of notes." examples: - command: .notes @User#1234 - command: .notes 330178495568436157 3 """ db_user = await c.query_user(self.bot, user) db_group = c.query_user_group(db_user) db_records = c.query_user_records(db_group) db_joins = c.query_user_joins(db_group) if db_joins: db_records = self.merge_records_joins(db_records, db_joins) records_pages = Pagination(db_records, self.NOTES_PAGE_SIZE, align_end=True) if page is not None: records_pages.page = max( 0, min(records_pages.total_pages - 1, page - 1)) await self.show_record_page(ctx.message.channel, records=records_pages, user=db_user, group=db_group, title='Moderation Record')
async def check_in_query(self, ctx: commands.Context, user: MemberConverter2, page: int = None): """!kazhelp description: | Query a user's list of check-ins. This is the moderator's version of {{!checkin list}}. parameters: - name: user type: "@mention" description: The user to check (as an @mention or a Discord ID). - name: page type: number optional: true description: The page number to access, if a user has more than 1 page of badges. default: last page (most recent) examples: - command: .checkin query @JaneDoe description: List all check-ins by JaneDoe (last page if multiple pages). - command: .checkin query @JaneDoe 4 description: List the 4th page of check-ins by JaneDoe. """ member = user # type: discord.Member # just for type checking try: db_records = self.c.query_check_ins(member=member) paginator = Pagination(db_records, self.ITEMS_PER_PAGE, align_end=True) if page is not None: paginator.page = max(0, min(paginator.total_pages - 1, page - 1)) await self.send_check_in_list(ctx.message.channel, paginator, member) except orm.exc.NoResultFound: await self.bot.say("{} has not checked in yet.".format( member.mention))
async def temps(self, ctx, page: int = None): """!kazhelp description: Show all tempbans currently in effect (i.e. non-expired `temp` records). details: | 10 notes are shown per page. This is partly due to Discord message length limits, and partly to avoid too large a data dump in a single request. parameters: - name: page optional: true default: last page (latest notes) type: number description: The page number to show, if there are more than 1 page of notes. """ db_records = c.query_unexpired_records(types=RecordType.temp) records_pages = Pagination(db_records, self.NOTES_PAGE_SIZE, True) if page is not None: records_pages.page = max(1, min(records_pages.total_pages, page)) - 1 await self.show_record_page(ctx.message.channel, records=records_pages, user=None, title='Active Temporary Bans (Mutes)')