|
11 | 11 | from discord.ext.commands import BucketType, Cog, Context, command, group, has_any_role
|
12 | 12 | from discord.utils import escape_markdown
|
13 | 13 | from pydis_core.site_api import ResponseCodeError
|
| 14 | +from pydis_core.utils.channel import get_or_fetch_channel |
14 | 15 | from pydis_core.utils.members import get_or_fetch_member
|
15 | 16 | from pydis_core.utils.paste_service import PasteFile, PasteTooLongError, PasteUploadError, send_to_paste_service
|
16 | 17 |
|
@@ -602,6 +603,37 @@ async def _set_rules_command_help(self) -> None:
|
602 | 603 |
|
603 | 604 | self.rules.help = help_string
|
604 | 605 |
|
| 606 | + async def _send_rules_alert(self, ctx: Context, requested_rules: list[int]) -> None: |
| 607 | + """Send an alert to the Rule Alerts thread when a non-staff member uses the rules command.""" |
| 608 | + rules_thread = await get_or_fetch_channel(self.bot, constants.Channels.rule_alerts) |
| 609 | + |
| 610 | + if rules_thread is None: |
| 611 | + log.error("Failed to find the rules alert thread channel.") |
| 612 | + return |
| 613 | + |
| 614 | + rule_desc = None |
| 615 | + |
| 616 | + if len(requested_rules) == 1: |
| 617 | + rule_desc = f"Rule **{requested_rules[0]}** was requested by {ctx.author.mention} in {ctx.channel.mention}." |
| 618 | + elif len(requested_rules) > 1: |
| 619 | + rule_desc = ( |
| 620 | + f"Rules **{', '.join(map(str, requested_rules))}** were requested " |
| 621 | + f"by {ctx.author.mention} in {ctx.channel.mention}." |
| 622 | + ) |
| 623 | + |
| 624 | + warning_embed = Embed( |
| 625 | + title="Rules Command Alert", |
| 626 | + description=rule_desc, |
| 627 | + color=Colour.red(), |
| 628 | + url=ctx.message.jump_url |
| 629 | + ) |
| 630 | + |
| 631 | + warning_embed.set_footer(text="Warnings are sent for invocations from non-staff members.") |
| 632 | + |
| 633 | + warning_embed.set_author(name=f"{ctx.author} ({ctx.author.id})", icon_url=ctx.author.display_avatar.url) |
| 634 | + |
| 635 | + await rules_thread.send(embed=warning_embed) |
| 636 | + |
605 | 637 | @command(aliases=("rule",))
|
606 | 638 | async def rules(self, ctx: Context, *, args: str | None) -> set[int] | None:
|
607 | 639 | """
|
@@ -651,10 +683,16 @@ async def rules(self, ctx: Context, *, args: str | None) -> set[int] | None:
|
651 | 683 | final_rule_numbers = {keyword_to_rule_number[keyword] for keyword in keywords}
|
652 | 684 | final_rule_numbers.update(rule_numbers)
|
653 | 685 |
|
654 |
| - for rule_number in sorted(final_rule_numbers): |
| 686 | + sorted_rules = sorted(final_rule_numbers) |
| 687 | + |
| 688 | + for rule_number in sorted_rules: |
655 | 689 | self.bot.stats.incr(f"rule_uses.{rule_number}")
|
656 | 690 | final_rules.append(f"**{rule_number}.** {full_rules[rule_number - 1][0]}")
|
657 | 691 |
|
| 692 | + if constants.Roles.helpers not in {role.id for role in ctx.author.roles}: |
| 693 | + # If the user is not a helper, send an alert to the rules thread. |
| 694 | + await self._send_rules_alert(ctx, final_rule_numbers) |
| 695 | + |
658 | 696 | await LinePaginator.paginate(final_rules, ctx, rules_embed, max_lines=3)
|
659 | 697 |
|
660 | 698 | return final_rule_numbers
|
|
0 commit comments