Fix autoreact delete bug
This commit is contained in:
parent
006ca87dc0
commit
4343b67abd
1 changed files with 58 additions and 17 deletions
|
@ -40,7 +40,9 @@ class AutoReactCog(Extension):
|
|||
Returns:
|
||||
Tuple of success? and error message
|
||||
"""
|
||||
exists = await Autoreact.find_one(Autoreact.guild == ctx.guild.id, Autoreact.channel == channel.id)
|
||||
exists = await Autoreact.find_one(
|
||||
Autoreact.guild == ctx.guild.id, Autoreact.channel == channel.id
|
||||
)
|
||||
if exists:
|
||||
return False, f"Autoreact already exists for {channel.mention}."
|
||||
|
||||
|
@ -54,7 +56,9 @@ class AutoReactCog(Extension):
|
|||
|
||||
return True, None
|
||||
|
||||
async def delete_autoreact(self, ctx: InteractionContext, channel: GuildText) -> bool:
|
||||
async def delete_autoreact(
|
||||
self, ctx: InteractionContext, channel: GuildText
|
||||
) -> bool:
|
||||
"""
|
||||
Remove an autoreact monitor on a channel.
|
||||
|
||||
|
@ -65,7 +69,9 @@ class AutoReactCog(Extension):
|
|||
Returns:
|
||||
Success?
|
||||
"""
|
||||
ar = await Autoreact.find_one(Autoreact.guild == ctx.guild.id, Autoreact.channel == channel.id)
|
||||
ar = await Autoreact.find_one(
|
||||
Autoreact.guild == ctx.guild.id, Autoreact.channel == channel.id
|
||||
)
|
||||
if ar:
|
||||
await ar.delete()
|
||||
return True
|
||||
|
@ -83,11 +89,25 @@ class AutoReactCog(Extension):
|
|||
opt_type=OptionType.CHANNEL,
|
||||
required=True,
|
||||
)
|
||||
@slash_option(name="thread", description="Create a thread?", opt_type=OptionType.BOOLEAN, required=False)
|
||||
@slash_option(name="emote", description="Emote to add", opt_type=OptionType.STRING, required=False)
|
||||
@slash_option(
|
||||
name="thread",
|
||||
description="Create a thread?",
|
||||
opt_type=OptionType.BOOLEAN,
|
||||
required=False,
|
||||
)
|
||||
@slash_option(
|
||||
name="emote",
|
||||
description="Emote to add",
|
||||
opt_type=OptionType.STRING,
|
||||
required=False,
|
||||
)
|
||||
@check(admin_or_permissions(Permissions.MANAGE_GUILD))
|
||||
async def _autoreact_add(
|
||||
self, ctx: InteractionContext, channel: GuildText, thread: bool = True, emote: str = None
|
||||
self,
|
||||
ctx: InteractionContext,
|
||||
channel: GuildText,
|
||||
thread: bool = True,
|
||||
emote: str = None,
|
||||
) -> None:
|
||||
await ctx.defer()
|
||||
if emote:
|
||||
|
@ -101,13 +121,22 @@ class AutoReactCog(Extension):
|
|||
return
|
||||
if custom_emoji:
|
||||
emoji_id = int(custom_emoji.group(1))
|
||||
if not find(lambda x: x.id == emoji_id, await ctx.guild.fetch_all_custom_emojis()):
|
||||
await ctx.send("Please use a custom emote from this server.", ephemeral=True)
|
||||
if not find(
|
||||
lambda x: x.id == emoji_id,
|
||||
await ctx.guild.fetch_all_custom_emojis(),
|
||||
):
|
||||
await ctx.send(
|
||||
"Please use a custom emote from this server.", ephemeral=True
|
||||
)
|
||||
return
|
||||
autoreact = await Autoreact.find_one(Autoreact.guild == ctx.guild.id, Autoreact.channel == channel.id)
|
||||
autoreact = await Autoreact.find_one(
|
||||
Autoreact.guild == ctx.guild.id, Autoreact.channel == channel.id
|
||||
)
|
||||
if not autoreact:
|
||||
await self.create_autoreact(ctx, channel, thread)
|
||||
autoreact = await Autoreact.find_one(Autoreact.guild == ctx.guild.id, Autoreact.channel == channel.id)
|
||||
autoreact = await Autoreact.find_one(
|
||||
Autoreact.guild == ctx.guild.id, Autoreact.channel == channel.id
|
||||
)
|
||||
if emote and emote in autoreact.reactions:
|
||||
await ctx.send(
|
||||
f"Emote already added to {channel.mention} autoreactions.",
|
||||
|
@ -147,8 +176,12 @@ class AutoReactCog(Extension):
|
|||
required=True,
|
||||
)
|
||||
@check(admin_or_permissions(Permissions.MANAGE_GUILD))
|
||||
async def _autoreact_remove(self, ctx: InteractionContext, channel: GuildText, emote: str) -> None:
|
||||
autoreact = await Autoreact.find_one(Autoreact.guild == ctx.guild.id, Autoreact.channel == channel.id)
|
||||
async def _autoreact_remove(
|
||||
self, ctx: InteractionContext, channel: GuildText, emote: str
|
||||
) -> None:
|
||||
autoreact = await Autoreact.find_one(
|
||||
Autoreact.guild == ctx.guild.id, Autoreact.channel == channel.id
|
||||
)
|
||||
if not autoreact:
|
||||
await ctx.send(
|
||||
f"Please create autoreact first with /autoreact add {channel.mention} {emote}",
|
||||
|
@ -182,8 +215,10 @@ class AutoReactCog(Extension):
|
|||
required=True,
|
||||
)
|
||||
@check(admin_or_permissions(Permissions.MANAGE_GUILD))
|
||||
async def _autoreact_delete(self, ctx: InteractionContext, channel: GuildText) -> None:
|
||||
result = self.delete_autoreact(ctx, channel)
|
||||
async def _autoreact_delete(
|
||||
self, ctx: InteractionContext, channel: GuildText
|
||||
) -> None:
|
||||
result = await self.delete_autoreact(ctx, channel)
|
||||
if not result:
|
||||
await ctx.send(f"No autoreact found in {channel.mention}", ephemeral=True)
|
||||
else:
|
||||
|
@ -199,8 +234,12 @@ class AutoReactCog(Extension):
|
|||
opt_type=OptionType.CHANNEL,
|
||||
required=True,
|
||||
)
|
||||
async def _autoreact_list(self, ctx: InteractionContext, channel: GuildText) -> None:
|
||||
exists = await Autoreact.find_one(Autoreact.guild == ctx.guild.id, Autoreact.channel == channel.id)
|
||||
async def _autoreact_list(
|
||||
self, ctx: InteractionContext, channel: GuildText
|
||||
) -> None:
|
||||
exists = await Autoreact.find_one(
|
||||
Autoreact.guild == ctx.guild.id, Autoreact.channel == channel.id
|
||||
)
|
||||
if not exists:
|
||||
await ctx.send(
|
||||
f"Please create autoreact first with /autoreact add {channel.mention} <emote>",
|
||||
|
@ -209,7 +248,9 @@ class AutoReactCog(Extension):
|
|||
return
|
||||
message = ""
|
||||
if len(exists.reactions) > 0:
|
||||
message = f"Current active autoreacts on {channel.mention}:\n" + "\n".join(exists.reactions)
|
||||
message = f"Current active autoreacts on {channel.mention}:\n" + "\n".join(
|
||||
exists.reactions
|
||||
)
|
||||
else:
|
||||
message = f"No reactions set on {channel.mention}"
|
||||
await ctx.send(message)
|
||||
|
|
Loading…
Add table
Reference in a new issue