Create cog disabling API (#4043)

* create cog disbale base

* Because defaults...

* lol

* announcer needs to respect this

* defaultdict mishap

* Allow None as guild

- Mostly for interop with with ctx.guild

* a whitespace issue

* Apparently, I broke this too

* Apply suggestions from code review

Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com>

* This can probably be more optimized later, but since this is a cached value, it's not a large issue

* Report tunnel closing

* mod too

* whitespace issue

* Fix Artifact of prior method naming

* these 3 places should have the check if i understood it correctly

* Announce the closed tunnels

* tunnel oversight

* Make the player stop at next track

* added where draper said to put it

* Apply suggestions from code review

Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com>

Co-authored-by: jack1142 <6032823+jack1142@users.noreply.github.com>
Co-authored-by: Drapersniper <27962761+drapersniper@users.noreply.github.com>
This commit is contained in:
Michael H
2020-07-28 14:52:36 -04:00
committed by GitHub
parent 97379afe6d
commit 1d80fe9aec
18 changed files with 329 additions and 5 deletions

View File

@@ -293,10 +293,11 @@ class Reports(commands.Cog):
pass
@commands.Cog.listener()
async def on_raw_reaction_add(self, payload):
async def on_raw_reaction_add(self, payload: discord.RawReactionActionEvent):
"""
oh dear....
"""
if not str(payload.emoji) == "\N{NEGATIVE SQUARED CROSS MARK}":
return
@@ -314,13 +315,35 @@ class Reports(commands.Cog):
@commands.Cog.listener()
async def on_message(self, message: discord.Message):
to_remove = []
for k, v in self.tunnel_store.items():
topic = _("Re: ticket# {1} in {0.name}").format(*k)
guild, ticket_number = k
if await self.bot.cog_disabled_in_guild(self, guild):
to_remove.append(k)
continue
topic = _("Re: ticket# {ticket_number} in {guild.name}").format(
ticket_number=ticket_number, guild=guild
)
# Tunnels won't forward unintended messages, this is safe
msgs = await v["tun"].communicate(message=message, topic=topic)
if msgs:
self.tunnel_store[k]["msgs"] = msgs
for key in to_remove:
if tun := self.tunnel_store.pop(key, None):
guild, ticket = key
await tun["tun"].close_because_disabled(
_(
"Correspondence about ticket# {ticket_number} in "
"{guild.name} has been ended due "
"to reports being disabled in that server."
).format(ticket_number=ticket, guild=guild)
)
@commands.guild_only()
@checks.mod_or_permissions(manage_roles=True)
@report.command(name="interact")