|
16 | 16 | from dis_snek.http_requests.channels import ChannelRequests |
17 | 17 |
|
18 | 18 | 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 |
20 | 20 | from utils.embeds import GENIUS_BAR |
21 | 21 |
|
22 | 22 |
|
@@ -83,6 +83,33 @@ async def genius_kill(self, ctx): |
83 | 83 | await ctx.send("Tickets cleared") |
84 | 84 | self.bot.storage.save() |
85 | 85 |
|
| 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 | + |
86 | 113 |
|
87 | 114 | async def setup_channel(self, channel): |
88 | 115 | await channel.purge() |
@@ -165,34 +192,41 @@ async def get_out_queueu(self, ctx: InteractionContext): |
165 | 192 | @component_callback("closeTicket") |
166 | 193 | async def close_ticket(self, ctx: InteractionContext): |
167 | 194 | 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: |
170 | 203 | 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 |
174 | 204 | 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) |
175 | 212 |
|
| 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): |
176 | 222 | guild = await self.bot.get_guild(GUILD) |
177 | | - cat = await guild.get_channel(cat) |
| 223 | + cat = await guild.get_channel(catId) |
178 | 224 | channels = cat.channels |
179 | 225 |
|
180 | 226 | for i in channels: |
181 | 227 | await guild.delete_channel(i.id) |
182 | 228 | await guild.delete_channel(cat) |
183 | 229 |
|
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 | | - |
196 | 230 |
|
197 | 231 | async def create_ticket(self, userId): |
198 | 232 | userName = (await self.bot.get_user(userId)).display_name |
@@ -226,10 +260,11 @@ async def create_ticket(self, userId): |
226 | 260 | custom_id="closeTicket" |
227 | 261 | ) |
228 | 262 |
|
229 | | - await tc.send( |
| 263 | + msg = await tc.send( |
230 | 264 | 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 ;) |
231 | 265 | components=[button3] |
232 | 266 | ) |
| 267 | + await msg.pin() |
233 | 268 |
|
234 | 269 | self.genius.new_ticket(userId, cat.id) |
235 | 270 |
|
|
0 commit comments