Skip to content

Commit

Permalink
[Def] [p]alert button
Browse files Browse the repository at this point in the history
  • Loading branch information
Twentysix26 committed Feb 22, 2023
1 parent f2308f0 commit c0ae0ec
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
2 changes: 1 addition & 1 deletion defender/abc.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ async def send_notification(self, destination: discord.abc.Messageable, descript
jump_to: discord.Message=None,
allow_everyone_ping=False, force_text_only=False, heat_key: str=None,
no_repeat_for: datetime.timedelta=None,
quick_action: QuickAction=None)->Optional[discord.Message]:
quick_action: QuickAction=None, view: discord.ui.View=None)->Optional[discord.Message]:
raise NotImplementedError()

@abstractmethod
Expand Down
11 changes: 5 additions & 6 deletions defender/commands/manualmodules.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
from ..enums import EmergencyMode
from ..abc import MixinMeta, CompositeMetaClass
from ..enums import EmergencyModules, Action, Rank
from redbot.core import commands, modlog
from ..core.menus import EmergencyView
from redbot.core import commands
from redbot.core.utils.chat_formatting import box
import discord
import asyncio
Expand Down Expand Up @@ -56,18 +57,16 @@ async def alert(self, ctx):
emergency_modules = await self.config.guild(guild).emergency_modules()

react_text = ""
emoji = None
if emergency_modules:
react_text = " React to this message or take some actions in this server to disable the emergency timer."
emoji = "⚠️"
react_text = " Press the button or take some actions in this server to disable the emergency timer."

await self.send_notification(guild,
f"An alert has been issued!{react_text}",
title=EMBED_TITLE,
fields=EMBED_FIELDS,
ping=True,
jump_to=ctx.message,
react=emoji)
view=EmergencyView(self))
await ctx.send("The staff has been notified. Please keep calm, I'm sure everything is fine. 🔥")

### Emergency mode
Expand Down Expand Up @@ -108,7 +107,7 @@ async def maybe_delete(message):
"Please stand by. ⚠️")

last_msg = await ctx.send(f"{ctx.author.mention} " + text.format(minutes))
await self.send_notification(guild, "⚠️ Seems like you're not around. I will automatically engage "
await self.send_notification(guild, "⚠️ Looks like you're not around. I will automatically engage "
f"emergency mode in {minutes} minutes if you don't show up.",
force_text_only=True)
while minutes != 0:
Expand Down
9 changes: 4 additions & 5 deletions defender/defender.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
from multiprocessing.pool import Pool
from zlib import crc32
from string import Template
from discord import ui
import datetime
import discord
import asyncio
Expand Down Expand Up @@ -520,7 +521,7 @@ async def send_notification(self, destination: discord.abc.Messageable, descript
ping=False, file: discord.File=None, react: str=None,
jump_to: discord.Message=None,
allow_everyone_ping=False, force_text_only=False, heat_key: str=None,
no_repeat_for: datetime.timedelta=None, quick_action: QuickAction=None)->Optional[discord.Message]:
no_repeat_for: datetime.timedelta=None, view: ui.View=None)->Optional[discord.Message]:
"""Sends a notification to the staff channel if a guild is passed. Embed preference is respected."""
if no_repeat_for:
if isinstance(destination, discord.Guild):
Expand Down Expand Up @@ -576,15 +577,13 @@ async def send_notification(self, destination: discord.abc.Messageable, descript

allowed_mentions = discord.AllowedMentions(roles=True, everyone=allow_everyone_ping)
msg = await destination.send(message_content, file=file, embed=embed,
allowed_mentions=allowed_mentions)
allowed_mentions=allowed_mentions, view=view)
if react:
await msg.add_reaction(react)

if quick_action and is_staff_notification:
self.quick_actions[guild.id][msg.id] = quick_action

return msg


def is_role_privileged(self, role: discord.Role, issuers_top_role: discord.Role=None):
if any((
role.permissions.manage_channels, role.permissions.manage_guild,
Expand Down

0 comments on commit c0ae0ec

Please sign in to comment.