Skip to content

Commit 91f8330

Browse files
committed
Update main.py
1 parent 6cc9d29 commit 91f8330

File tree

1 file changed

+31
-30
lines changed

1 file changed

+31
-30
lines changed

main.py

Lines changed: 31 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -57,37 +57,45 @@ async def cancel(self, interaction: discord.Interaction, button: discord.ui.Butt
5757
self.value = False
5858
self.stop()
5959

60+
async def lock_thread(interaction: discord.Interaction, reason:str=None):
61+
em = discord.Embed(title="🔒 Locked!", description=f"Reason: {reason}" if reason else None, timestamp=datetime.datetime.now(), color=discord.Color.green())
62+
em.set_footer(text=f'Locked by {interaction.user.name}', icon_url=interaction.user.avatar.url)
63+
await interaction.followup.send(embed=em)
64+
await interaction.channel.edit(name=
65+
'[🔒] ' + interaction.channel.name,
66+
locked=True,
67+
archived=True,
68+
reason=reason if reason else None)
69+
70+
async def unlock_thread(interaction: discord.Interaction, thread: discord.Thread, reason:str=None):
71+
await interaction.followup.send(embed=discord.Embed(title="🔓 Unlocked!", description=f"Reason: {reason}" if reason else None, color=discord.Color.green()))
72+
await thread.edit(name=thread.name.replace('[🔒] ', ''), locked=False, archived=False, reason=reason or None)
73+
embed=discord.Embed(
74+
title="This thread has been unlocked!",
75+
description=f"Reason: {reason}" if reason else None,
76+
timestamp=datetime.datetime.now(),
77+
color=discord.Color.green()
78+
)
79+
embed.set_footer(text=f"Unlocked by {interaction.user.name}", icon_url=interaction.user.avatar.url)
80+
await thread.send(embed=embed)
6081

6182

6283
@tree.command(name='lock', description='Locks the thread')
6384
@app_commands.describe(reason='The reason for locking the thread')
6485
async def lock(interaction: discord.Interaction, reason:str=None):
86+
await interaction.response.defer(ephemeral=False)
6587
if not isinstance(interaction.channel, discord.Thread):
6688
await interaction.response.send_message(embed=discord.Embed(title='❌ This command can only be used in threads.', color=discord.Color.red()), ephemeral=True)
6789
return
68-
await interaction.response.defer(ephemeral=False)
6990
view = Confirm()
7091
if interaction.user == interaction.channel.owner or interaction.permissions.manage_threads:
71-
em = discord.Embed(title="🔒 Locked!", description=f"Reason: {reason}" if reason else None, timestamp=datetime.datetime.utcnow(), footer=f"Locked by {interaction.user}", avatar_url=interaction.user.avatar.url,color=discord.Color.green())
72-
await interaction.followup.send(embed=em)
73-
await interaction.channel.edit(name=
74-
'[🔒] ' + interaction.channel.name,
75-
locked=True,
76-
archived=True,
77-
reason=reason if reason else None)
92+
await lock_thread(interaction, reason)
7893
else:
79-
await interaction.followup.send(f'<@{interaction.channel.owner_id}>',embed=discord.Embed(title='Do you want to lock this thread?', color=discord.Color.green()), view=view)
94+
await interaction.followup.send(f'<@{interaction.channel.owner_id}>',embed=discord.Embed(title='Do you want to lock this thread?', color=discord.Color.green(), avatar_url=interaction.user.avatar.url).set_footer(f'{interaction.user.name} is requesting to lock this thread.'), view=view)
8095

81-
# Wait for the View to stop listening for input...
8296
await view.wait()
8397
if view.value:
84-
em = discord.Embed(title="🔒 Locked!", description=f"Reason: {reason}" if reason else None, timestamp=datetime.datetime.utcnow(), color=discord.Color.green())
85-
await interaction.followup.send(embed=em)
86-
await interaction.channel.edit(name=
87-
'[🔒] ' + interaction.channel.name,
88-
locked=True,
89-
archived=True,
90-
reason=reason if reason else None)
98+
await lock_thread(interaction, reason)
9199
else:
92100
await interaction.followup.send(embed=discord.Embed(title="❌ Cancelled", color=discord.Color.red()))
93101

@@ -103,25 +111,18 @@ async def unlock(interaction: discord.Interaction, thread: str=None, reason:str=
103111
if not thread:
104112
await interaction.followup.send(embed=discord.Embed(title='❌ Failed', description='Please either use this command in a thread and/or specify the thread ID/link.', color=discord.Color.red()), ephemeral=True)
105113
return
106-
if re.match(r'(https?:\/\/)?(ptb\.|canary\.)?discord(app)?\.(com|net)\/channels\/([0-9]+)\/([0-9]+)', thread):
107-
thread = await bot.fetch_channel(int(re.match(r'(https?:\/\/)?(ptb\.|canary\.)?discord(app)?\.(com|net)\/channels\/([0-9]+)\/([0-9]+)', thread).group(6)))
108-
elif thread.isdigit():
114+
if str(thread).isdigit():
109115
thread = await interaction.guild.fetch_channel(int(thread))
116+
elif re.match(r'(https?:\/\/)?(ptb\.|canary\.)?discord(app)?\.(com|net)\/channels\/([0-9]+)\/([0-9]+)', thread):
117+
thread = await bot.fetch_channel(int(re.match(r'(https?:\/\/)?(ptb\.|canary\.)?discord(app)?\.(com|net)\/channels\/([0-9]+)\/([0-9]+)', thread).group(6)))
118+
110119
if not isinstance(thread, discord.Thread):
111120
await interaction.followup.send(embed=discord.Embed(title='❌ Failed', description='Not a thread!', color=discord.Color.red()), ephemeral=True)
112121
return
113122
if not thread.locked and not thread.archived:
114123
await interaction.followup.send(embed=discord.Embed(title="❌ This thread is already unlocked!", color=discord.Color.red(), ephemeral=True))
115124
return
116-
await interaction.followup.send(embed=discord.Embed(title="🔓 Unlocked!", description=f"Reason: {reason}" if reason else None, color=discord.Color.green()))
117-
await thread.edit(name=thread.name.replace('[🔒] ', ''), locked=False, archived=False, reason=reason or None)
118-
await thread.send(embed=discord.Embed(
119-
title="This thread has been unlocked!",
120-
description=f"Reason: {reason}" if reason else None,
121-
timestamp=datetime.datetime.utcnow(),
122-
footer=f"Unlocked by {interaction.user.name}",
123-
color=discord.Color.green()
124-
))
125+
await unlock_thread(interaction, thread, reason)
125126

126127
# create the modal for partnering
127128
class PartnerModal(discord.ui.Modal, title='Partner with us!'):
@@ -130,7 +131,7 @@ class PartnerModal(discord.ui.Modal, title='Partner with us!'):
130131
app_link = discord.ui.TextInput(label='App Link(s)', placeholder='Your app link(s)', required=True)
131132

132133
async def on_submit(self, interaction: discord.Interaction):
133-
embed=discord.Embed(title='New Partner Application!', description=f'{interaction.user.mention} has submitted an application!', timestamp=datetime.datetime.utcnow(), color=discord.Color.green())
134+
embed=discord.Embed(title='New Partner Application!', description=f'{interaction.user.mention} has submitted an application!', timestamp=datetime.datetime.now(), color=discord.Color.green())
134135
embed.add_field(name='App Name(s)', value=self.app_name.value, inline=False)
135136
embed.add_field(name='App Description(s)', value=self.app_desc.value, inline=False)
136137
embed.add_field(name='App Link(s)', value=self.app_link.value, inline=False)

0 commit comments

Comments
 (0)