Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add category ping to reports #9

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 30 additions & 1 deletion reports/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"emote_reactions": False,
"claim_reports": False,
"recieve_dms": [],
"category_roles": {},
}

# TODO Add reportdm command to disable dms on reports. To avoid annoyed members.
Expand Down Expand Up @@ -142,8 +143,14 @@ async def send_report_to_mods(self, ctx, embed, report_channel):
Sending to channel
"""
channel_report = self.bot.get_channel(report_channel)
if ctx.channel.category:
role_id = await self.config.guild(ctx.guild).category_roles.get_raw(str(ctx.channel.category.id), default=None)
ping = ctx.guild.get_role(role_id) if role_id else None
else:
ping = None

try:
await channel_report.send(embed=embed)
await channel_report.send(content=ping.mention if ping else None, embed=embed, allowed_mentions=discord.AllowedMentions(roles=True))
except discord.Forbidden:
self.log.warning("Unable to send message in {}".format(channel_report))
except discord.HTTPException as e:
Expand Down Expand Up @@ -281,6 +288,28 @@ async def emotes(self, ctx, toggle: Optional[bool]):
await self.config.guild(ctx.guild).emote_reactions.set(False)
return await ctx.send("The setting is now disabled")

@reportset.command()
async def ping(self, ctx, category: discord.CategoryChannel, role: discord.Role):
"""
Sets the role to be pinged when a report is sent in a category
"""
await self.config.guild(ctx.guild).category_roles.set_raw(str(category.id), value=role.id)
await ctx.send(f"Done. Set {role.mention} to be pinged when a report is sent in {category.name}")

@reportset.command()
async def removeping(self, ctx, category: discord.CategoryChannel):
"""
Removes the pinged role for a report in a specific category.
"""
data = await self.config.guild(ctx.guild).category_roles.get_raw(str(category.id), default=None)
if data is None:
await ctx.send(f"No ping role is set for {category.name}.")
return

await self.config.guild(ctx.guild).category_roles.clear_raw(str(category.id))
await ctx.send(f"Removed the ping role for reports in {category.name}.")


@commands.Cog.listener()
async def on_message(self, message):
"""
Expand Down