Add thread option to autoreact
This commit is contained in:
parent
31df95809f
commit
1fc0aec8f6
2 changed files with 51 additions and 28 deletions
|
@ -181,6 +181,11 @@ class Jarvis(Snake):
|
||||||
if autoreact:
|
if autoreact:
|
||||||
for reaction in autoreact.reactions:
|
for reaction in autoreact.reactions:
|
||||||
await message.add_reaction(reaction)
|
await message.add_reaction(reaction)
|
||||||
|
if autoreact.thread:
|
||||||
|
name = message.content
|
||||||
|
if len(name) > 100:
|
||||||
|
name = name[:97] + "..."
|
||||||
|
await message.create_thread(name=message.content, reason="Autoreact")
|
||||||
|
|
||||||
async def checks(self, message: Message) -> None:
|
async def checks(self, message: Message) -> None:
|
||||||
"""Other message checks."""
|
"""Other message checks."""
|
||||||
|
|
|
@ -26,7 +26,7 @@ class AutoReactCog(Scale):
|
||||||
self.custom_emote = re.compile(r"^<:\w+:(\d+)>$")
|
self.custom_emote = re.compile(r"^<:\w+:(\d+)>$")
|
||||||
|
|
||||||
async def create_autoreact(
|
async def create_autoreact(
|
||||||
self, ctx: InteractionContext, channel: GuildText
|
self, ctx: InteractionContext, channel: GuildText, thread: bool
|
||||||
) -> Tuple[bool, Optional[str]]:
|
) -> Tuple[bool, Optional[str]]:
|
||||||
"""
|
"""
|
||||||
Create an autoreact monitor on a channel.
|
Create an autoreact monitor on a channel.
|
||||||
|
@ -34,6 +34,7 @@ class AutoReactCog(Scale):
|
||||||
Args:
|
Args:
|
||||||
ctx: Interaction context of command
|
ctx: Interaction context of command
|
||||||
channel: Channel to monitor
|
channel: Channel to monitor
|
||||||
|
thread: Create a thread
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
Tuple of success? and error message
|
Tuple of success? and error message
|
||||||
|
@ -42,12 +43,13 @@ class AutoReactCog(Scale):
|
||||||
if exists:
|
if exists:
|
||||||
return False, f"Autoreact already exists for {channel.mention}."
|
return False, f"Autoreact already exists for {channel.mention}."
|
||||||
|
|
||||||
_ = Autoreact(
|
await Autoreact(
|
||||||
guild=ctx.guild.id,
|
guild=ctx.guild.id,
|
||||||
channel=channel.id,
|
channel=channel.id,
|
||||||
reactions=[],
|
reactions=[],
|
||||||
|
thread=thread,
|
||||||
admin=ctx.author.id,
|
admin=ctx.author.id,
|
||||||
).save()
|
).commit()
|
||||||
|
|
||||||
return True, None
|
return True, None
|
||||||
|
|
||||||
|
@ -62,7 +64,11 @@ class AutoReactCog(Scale):
|
||||||
Returns:
|
Returns:
|
||||||
Success?
|
Success?
|
||||||
"""
|
"""
|
||||||
return Autoreact.objects(guild=ctx.guild.id, channel=channel.id).delete() is not None
|
ar = await Autoreact.find_one(q(guild=ctx.guild.id, channel=channel.id))
|
||||||
|
if ar:
|
||||||
|
await ar.delete()
|
||||||
|
return True
|
||||||
|
return False
|
||||||
|
|
||||||
@slash_command(
|
@slash_command(
|
||||||
name="autoreact",
|
name="autoreact",
|
||||||
|
@ -76,11 +82,17 @@ class AutoReactCog(Scale):
|
||||||
required=True,
|
required=True,
|
||||||
)
|
)
|
||||||
@slash_option(
|
@slash_option(
|
||||||
name="emote", description="Emote to add", opt_type=OptionTypes.STRING, required=True
|
name="thread", description="Create a thread?", opt_type=OptionTypes.BOOLEAN, required=False
|
||||||
|
)
|
||||||
|
@slash_option(
|
||||||
|
name="emote", description="Emote to add", opt_type=OptionTypes.STRING, required=False
|
||||||
)
|
)
|
||||||
@check(admin_or_permissions(Permissions.MANAGE_GUILD))
|
@check(admin_or_permissions(Permissions.MANAGE_GUILD))
|
||||||
async def _autoreact_add(self, ctx: InteractionContext, channel: GuildText, emote: str) -> None:
|
async def _autoreact_add(
|
||||||
|
self, ctx: InteractionContext, channel: GuildText, thread: bool = True, emote: str = None
|
||||||
|
) -> None:
|
||||||
await ctx.defer()
|
await ctx.defer()
|
||||||
|
if emote:
|
||||||
custom_emoji = self.custom_emote.match(emote)
|
custom_emoji = self.custom_emote.match(emote)
|
||||||
standard_emoji = emote in emoji_list
|
standard_emoji = emote in emoji_list
|
||||||
if not custom_emoji and not standard_emoji:
|
if not custom_emoji and not standard_emoji:
|
||||||
|
@ -91,28 +103,34 @@ class AutoReactCog(Scale):
|
||||||
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, ctx.guild.emojis):
|
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)
|
await ctx.send("Please use a custom emote from this server.", ephemeral=True)
|
||||||
return
|
return
|
||||||
autoreact = await Autoreact.find_one(q(guild=ctx.guild.id, channel=channel.id))
|
autoreact = await Autoreact.find_one(q(guild=ctx.guild.id, channel=channel.id))
|
||||||
if not autoreact:
|
if not autoreact:
|
||||||
self.create_autoreact(ctx, channel)
|
await self.create_autoreact(ctx, channel, thread)
|
||||||
autoreact = await Autoreact.find_one(q(guild=ctx.guild.id, channel=channel.id))
|
autoreact = await Autoreact.find_one(q(guild=ctx.guild.id, channel=channel.id))
|
||||||
if 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.",
|
||||||
ephemeral=True,
|
ephemeral=True,
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
if len(autoreact.reactions) >= 5:
|
if emote and len(autoreact.reactions) >= 5:
|
||||||
await ctx.send(
|
await ctx.send(
|
||||||
"Max number of reactions hit. Remove a different one to add this one",
|
"Max number of reactions hit. Remove a different one to add this one",
|
||||||
ephemeral=True,
|
ephemeral=True,
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
if emote:
|
||||||
autoreact.reactions.append(emote)
|
autoreact.reactions.append(emote)
|
||||||
autoreact.save()
|
autoreact.thread = thread
|
||||||
await ctx.send(f"Added {emote} to {channel.mention} autoreact.")
|
await autoreact.commit()
|
||||||
|
message = ""
|
||||||
|
if emote:
|
||||||
|
message += f" Added {emote} to {channel.mention} autoreact."
|
||||||
|
message += f" Set autoreact thread creation to {thread} in {channel.mention}"
|
||||||
|
await ctx.send(message)
|
||||||
|
|
||||||
@slash_command(
|
@slash_command(
|
||||||
name="autoreact",
|
name="autoreact",
|
||||||
|
@ -143,7 +161,7 @@ class AutoReactCog(Scale):
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
if emote.lower() == "all":
|
if emote.lower() == "all":
|
||||||
self.delete_autoreact(ctx, channel)
|
await self.delete_autoreact(ctx, channel)
|
||||||
await ctx.send(f"Autoreact removed from {channel.mention}")
|
await ctx.send(f"Autoreact removed from {channel.mention}")
|
||||||
elif emote not in autoreact.reactions:
|
elif emote not in autoreact.reactions:
|
||||||
await ctx.send(
|
await ctx.send(
|
||||||
|
@ -153,9 +171,9 @@ class AutoReactCog(Scale):
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
autoreact.reactions.remove(emote)
|
autoreact.reactions.remove(emote)
|
||||||
autoreact.save()
|
await autoreact.commit()
|
||||||
if len(autoreact.reactions) == 0:
|
if len(autoreact.reactions) == 0 and not autoreact.thread:
|
||||||
self.delete_autoreact(ctx, channel)
|
await self.delete_autoreact(ctx, channel)
|
||||||
await ctx.send(f"Removed {emote} from {channel.mention} autoreact.")
|
await ctx.send(f"Removed {emote} from {channel.mention} autoreact.")
|
||||||
|
|
||||||
@slash_command(
|
@slash_command(
|
||||||
|
|
Loading…
Add table
Reference in a new issue