mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-20 09:56:05 -05:00
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:
@@ -40,6 +40,8 @@ class Announcer:
|
||||
self.active = False
|
||||
|
||||
async def _get_announce_channel(self, guild: discord.Guild) -> Optional[discord.TextChannel]:
|
||||
if await self.ctx.bot.cog_disabled_in_guild_raw("Admin", guild.id):
|
||||
return
|
||||
channel_id = await self.config.guild(guild).announce_channel()
|
||||
return guild.get_channel(channel_id)
|
||||
|
||||
|
||||
@@ -326,6 +326,11 @@ class Alias(commands.Cog):
|
||||
|
||||
@commands.Cog.listener()
|
||||
async def on_message_without_command(self, message: discord.Message):
|
||||
|
||||
if message.guild is not None:
|
||||
if await self.bot.cog_disabled_in_guild(self, message.guild):
|
||||
return
|
||||
|
||||
try:
|
||||
prefix = await self.get_prefix(message)
|
||||
except ValueError:
|
||||
|
||||
@@ -25,6 +25,13 @@ class AudioEvents(MixinMeta, metaclass=CompositeMetaClass):
|
||||
):
|
||||
if not (track and guild):
|
||||
return
|
||||
|
||||
if await self.bot.cog_disabled_in_guild(self, guild):
|
||||
player = lavalink.get_player(guild.id)
|
||||
await player.stop()
|
||||
await player.disconnect()
|
||||
return
|
||||
|
||||
track_identifier = track.track_identifier
|
||||
if self.playlist_api is not None:
|
||||
daily_cache = self._daily_playlist_cache.setdefault(
|
||||
|
||||
@@ -178,6 +178,8 @@ class DpyEvents(MixinMeta, metaclass=CompositeMetaClass):
|
||||
async def on_voice_state_update(
|
||||
self, member: discord.Member, before: discord.VoiceState, after: discord.VoiceState
|
||||
) -> None:
|
||||
if await self.bot.cog_disabled_in_guild(self, member.guild):
|
||||
return
|
||||
await self.cog_ready_event.wait()
|
||||
if after.channel != before.channel:
|
||||
try:
|
||||
|
||||
@@ -19,7 +19,13 @@ class LavalinkEvents(MixinMeta, metaclass=CompositeMetaClass):
|
||||
current_track = player.current
|
||||
current_channel = player.channel
|
||||
guild = self.rgetattr(current_channel, "guild", None)
|
||||
if await self.bot.cog_disabled_in_guild(self, guild):
|
||||
await player.stop()
|
||||
await player.disconnect()
|
||||
return
|
||||
guild_id = self.rgetattr(guild, "id", None)
|
||||
if not guild:
|
||||
return
|
||||
current_requester = self.rgetattr(current_track, "requester", None)
|
||||
current_stream = self.rgetattr(current_track, "is_stream", None)
|
||||
current_length = self.rgetattr(current_track, "length", None)
|
||||
|
||||
@@ -20,6 +20,8 @@ class PlayerTasks(MixinMeta, metaclass=CompositeMetaClass):
|
||||
while True:
|
||||
async for p in AsyncIter(lavalink.all_players()):
|
||||
server = p.channel.guild
|
||||
if await self.bot.cog_disabled_in_guild(self, server):
|
||||
continue
|
||||
|
||||
if [self.bot.user] == p.channel.members:
|
||||
stop_times.setdefault(server.id, time.time())
|
||||
|
||||
@@ -516,6 +516,9 @@ class CustomCommands(commands.Cog):
|
||||
if len(message.content) < 2 or is_private or not user_allowed or message.author.bot:
|
||||
return
|
||||
|
||||
if await self.bot.cog_disabled_in_guild(self, message.guild):
|
||||
return
|
||||
|
||||
ctx = await self.bot.get_context(message)
|
||||
|
||||
if ctx.prefix is None:
|
||||
|
||||
@@ -369,6 +369,10 @@ class Filter(commands.Cog):
|
||||
async def on_message(self, message: discord.Message):
|
||||
if isinstance(message.channel, discord.abc.PrivateChannel):
|
||||
return
|
||||
|
||||
if await self.bot.cog_disabled_in_guild(self, message.guild):
|
||||
return
|
||||
|
||||
author = message.author
|
||||
valid_user = isinstance(author, discord.Member) and not author.bot
|
||||
if not valid_user:
|
||||
@@ -395,6 +399,11 @@ class Filter(commands.Cog):
|
||||
await self.maybe_filter_name(member)
|
||||
|
||||
async def maybe_filter_name(self, member: discord.Member):
|
||||
|
||||
guild = member.guild
|
||||
if (not guild) or await self.bot.cog_disabled_in_guild(self, guild):
|
||||
return
|
||||
|
||||
if not member.guild.me.guild_permissions.manage_nicknames:
|
||||
return # No permissions to manage nicknames, so can't do anything
|
||||
if member.top_role >= member.guild.me.top_role:
|
||||
|
||||
@@ -79,6 +79,10 @@ class Events(MixinMeta):
|
||||
author = message.author
|
||||
if message.guild is None or self.bot.user == author:
|
||||
return
|
||||
|
||||
if await self.bot.cog_disabled_in_guild(self, message.guild):
|
||||
return
|
||||
|
||||
valid_user = isinstance(author, discord.Member) and not author.bot
|
||||
if not valid_user:
|
||||
return
|
||||
@@ -110,6 +114,9 @@ class Events(MixinMeta):
|
||||
@commands.Cog.listener()
|
||||
async def on_member_update(self, before: discord.Member, after: discord.Member):
|
||||
if before.nick != after.nick and after.nick is not None:
|
||||
guild = after.guild
|
||||
if (not guild) or await self.bot.cog_disabled_in_guild(self, guild):
|
||||
return
|
||||
async with self.config.member(before).past_nicks() as nick_list:
|
||||
while None in nick_list: # clean out null entries from a bug
|
||||
nick_list.remove(None)
|
||||
|
||||
@@ -142,6 +142,9 @@ class KickBanMixin(MixinMeta):
|
||||
if not guild.me.guild_permissions.ban_members:
|
||||
continue
|
||||
|
||||
if await self.bot.cog_disabled_in_guild(self, guild):
|
||||
continue
|
||||
|
||||
async with self.config.guild(guild).current_tempbans() as guild_tempbans:
|
||||
for uid in guild_tempbans.copy():
|
||||
unban_time = datetime.utcfromtimestamp(
|
||||
|
||||
@@ -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")
|
||||
|
||||
@@ -702,6 +702,8 @@ class Streams(commands.Cog):
|
||||
continue
|
||||
for message in stream._messages_cache:
|
||||
with contextlib.suppress(Exception):
|
||||
if await self.bot.cog_disabled_in_guild(self, message.guild):
|
||||
continue
|
||||
autodelete = await self.config.guild(message.guild).autodelete()
|
||||
if autodelete:
|
||||
await message.delete()
|
||||
@@ -714,6 +716,8 @@ class Streams(commands.Cog):
|
||||
channel = self.bot.get_channel(channel_id)
|
||||
if not channel:
|
||||
continue
|
||||
if await self.bot.cog_disabled_in_guild(self, channel.guild):
|
||||
continue
|
||||
ignore_reruns = await self.config.guild(channel.guild).ignore_reruns()
|
||||
if ignore_reruns and is_rerun:
|
||||
continue
|
||||
|
||||
Reference in New Issue
Block a user