Skip to content

Commit 1794413

Browse files
committed
Let admin close tickets, implement kill tickets, allow add teammates
1 parent 8ffaf62 commit 1794413

File tree

1 file changed

+55
-20
lines changed

1 file changed

+55
-20
lines changed

modules/genius/genius.py

Lines changed: 55 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
from dis_snek.http_requests.channels import ChannelRequests
1717

1818
from storage.genius import Genius
19-
from utils.config import GUILD, PARTICIPANT_ROLE, MAX_TICKETS
19+
from utils.config import GUILD, PARTICIPANT_ROLE, MAX_TICKETS, ADMIN_ROLE
2020
from utils.embeds import GENIUS_BAR
2121

2222

@@ -83,6 +83,33 @@ async def genius_kill(self, ctx):
8383
await ctx.send("Tickets cleared")
8484
self.bot.storage.save()
8585

86+
@slash_command(
87+
name="add",
88+
description="Invite your teammate to this ticket")
89+
@slash_option(
90+
"user",
91+
"Teammate that you want to add",
92+
OptionTypes.USER,
93+
required=True
94+
)
95+
async def add(self, ctx, user):
96+
catId = ctx.channel.parent_id
97+
if catId not in self.genius.occupied.values():
98+
await ctx.send("You can only use this command in ticket channels!", ephemeral=True)
99+
return
100+
101+
channel = await self.bot.get_channel(catId)
102+
await channel.edit_permission(
103+
PermissionOverwrite(
104+
id=user.id,
105+
type=1,
106+
allow="1024",
107+
deny="0"
108+
)
109+
)
110+
111+
await ctx.send(f"{user.mention} has been added to this support ticket!")
112+
86113

87114
async def setup_channel(self, channel):
88115
await channel.purge()
@@ -165,34 +192,41 @@ async def get_out_queueu(self, ctx: InteractionContext):
165192
@component_callback("closeTicket")
166193
async def close_ticket(self, ctx: InteractionContext):
167194
author_id = str(ctx.author.id)
168-
169-
if author_id not in self.genius.occupied:
195+
if await ctx.author.has_role(ADMIN_ROLE):
196+
for key, value in self.genius.occupied.items():
197+
if value == ctx.channel.parent_id:
198+
await self.delete_channels(value)
199+
del self.genius.occupied[key]
200+
break
201+
202+
elif author_id not in self.genius.occupied:
170203
await ctx.send("You did not create this ticket!", ephemeral=True)
171-
172-
cat = self.genius.occupied[author_id]
173-
if cat != ctx.channel.parent_id: # shouldnt happen
174204
return
205+
else:
206+
cat = self.genius.occupied[author_id]
207+
await self.delete_channels(cat)
208+
209+
if cat != ctx.channel.parent_id: # shouldnt happen
210+
return
211+
self.genius.close_ticket(author_id)
175212

213+
if len(self.genius.queue) > 0: #no-one in queue
214+
userId = self.genius.dequeue()
215+
await self.create_ticket(userId)
216+
217+
self.bot.storage.save()
218+
await self.update_queue()
219+
220+
221+
async def delete_channels(self, catId):
176222
guild = await self.bot.get_guild(GUILD)
177-
cat = await guild.get_channel(cat)
223+
cat = await guild.get_channel(catId)
178224
channels = cat.channels
179225

180226
for i in channels:
181227
await guild.delete_channel(i.id)
182228
await guild.delete_channel(cat)
183229

184-
self.genius.close_ticket(author_id)
185-
186-
if len(self.genius.queue) == 0: #no-one in queue
187-
self.bot.storage.save()
188-
await self.update_queue()
189-
return
190-
191-
userId = self.genius.dequeue()
192-
await self.create_ticket(userId)
193-
self.bot.storage.save()
194-
await self.update_queue()
195-
196230

197231
async def create_ticket(self, userId):
198232
userName = (await self.bot.get_user(userId)).display_name
@@ -226,10 +260,11 @@ async def create_ticket(self, userId):
226260
custom_id="closeTicket"
227261
)
228262

229-
await tc.send(
263+
msg = await tc.send(
230264
f"Hey <@{userId}>! Welcome to your support channel! Please explain your issue here and someone will help you shortly. Alternatively, join your assigned vc.", # This text was definitely not stolen ;)
231265
components=[button3]
232266
)
267+
await msg.pin()
233268

234269
self.genius.new_ticket(userId, cat.id)
235270

0 commit comments

Comments
 (0)