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