This repository was archived by the owner on Jul 3, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathticket.py
More file actions
390 lines (344 loc) · 20.6 KB
/
ticket.py
File metadata and controls
390 lines (344 loc) · 20.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
import discord
from discord.ext import commands
from discord.ext.commands import cooldown, BucketType
import json
import asyncio
class Tickets(commands.Cog):
def __init__(self, client):
self.client = client
@commands.Cog.listener()
async def on_ready(self):
print("Tickets are ready!")
@commands.command(aliases = ['createticket', 'ticketnew','ticket'])
@cooldown(1, 10, BucketType.user)
async def new(self, ctx, *, reason = None):
em = discord.Embed(title = "Confirm New Ticket", color = 0x0098d2)
#em.add_field(name = "Reason:", value = "We don't want people to spam!")
em.add_field(name = "Next Step:", value = "Type `confirm` in the chat to confirm this ticket!")
em.set_author(name = ctx.author.name, icon_url = ctx.author.avatar_url)
em.set_footer(text = "Be nice with the support Team")
msg = await ctx.send(embed = em)
def msg_check(m):
return m.author == ctx.author and m.channel == ctx.channel
try:
msg = await self.client.wait_for('message', timeout = 15.0, check= msg_check)
except:
em = discord.Embed(title = " New Ticket Failed!", color = 0x0098d2)
em.add_field(name = "Reason:", value = "You took too long!")
em.add_field(name = "Cooldown", value = "1 minute more!")
em.set_author(name = ctx.author.name, icon_url = ctx.author.avatar_url)
await ctx.send(embed = em)
else:
if msg.content != "confirm":
em = discord.Embed(title = "New Ticket Failed!", color = 0x0098d2)
em.add_field(name = "Reason:", value = "You did not want to create one!")
em.add_field(name = "Cooldown", value = "1 minute more!")
em.set_author(name = ctx.author.name, icon_url = ctx.author.avatar_url)
await ctx.send(embed = em)
else:
channelname = "ticket-{}".format(ctx.author.name)
for _channel in ctx.guild.channels:
if _channel.name == channelname:
return await ctx.channel.send(f"You already have a ticket! Please contact staff in {_channel.mention}!")
warning = f"""{ctx.author.mention} it is always good to provide a reason for your inquiry with the Support Staff\nNext time try `[p]new <reason>`
"""
tickets = await self.get_tickets()
guild = ctx.guild
author = ctx.author
# Logic
if str(ctx.guild.id) not in tickets or tickets[str(ctx.guild.id)]["ticketrole"] ==[]:
em = discord.Embed(title = "<:Red_Cross:988360177017311263> New Failed",color = 0x0098d2)
em.add_field(name = "Reason:", value = "Tickets are not setup!")
em.add_field(name ="Usage:", value = "Usage for an admin:\n```diff\n+ [p] addticketrole <@role> [reason]\n- [p] new [reason]\n```")
await ctx.send(embed = em)
return
# Getting the role made!
ticketrole = tickets[str(ctx.guild.id)]["ticketrole"]
helper_role=[]
#role_id = int(ticketrole)
# Setting up the Channel
channel = await ctx.guild.create_text_channel(f'ticket-{ctx.author.name}')
# Creating the embed
em = discord.Embed(title = f"<:sucess:935052640449077248> New ticket", color = 0x1a1110)
em.add_field(name = "Description:", value = "Staff will be with your shortly")
em.add_field(name = "Member:", value = f"{ctx.author.mention}")
em.add_field(name = "Reason:", value = f"`{reason}`")
em.set_footer(text="Recommended setting up all the stuff")
# Perms
# Make sure the author can type!
await channel.set_permissions(ctx.author, read_messages = True, send_messages = True)
# Make sure everyone else should not be able to see anything, cause it should be private
await channel.set_permissions(ctx.guild.default_role, read_messages = False, send_messages = False)
for xx in ticketrole:
x=ctx.guild.get_role(int(xx))
await channel.set_permissions(x, read_messages = True, send_messages = True)
staff=[]
for x in ticketrole:
staff.append(f'<@&{x}>')
staff=''.join(staff)
# Sending the embed
await channel.send(content=staff,embed = em)
if reason == None:
await channel.send(warning)
await ctx.send(f"Created the ticket for {ctx.author.mention} , Check {channel.mention}")
# send the mod log
try:
channelId = int(tickets[str(ctx.guild.id)]["ticketchannel"])
for channel_ in ctx.guild.channels:
if channel_.id == channelId:
em = discord.Embed(title = "<:sucess:935052640449077248> Ticket Opened!", color = 0x0098d2)
em.add_field(name = "Member:", value = f"{ctx.author.mention}")
em.add_field(name ="Reason:", value = f"`{reason}`")
em.add_field(name= "Channel / Access Point", value = f'{channel.mention}')
em.set_author(name = ctx.author.name, icon_url = ctx.author.avatar_url)
await channel_.send(embed = em)
break
except:
pass
@new.error
async def new_error(self, ctx, error):
if isinstance(error, commands.CommandOnCooldown):
em = discord.Embed(title = "<:Red_Cross:988360177017311263> New Error", color = 0x0098d2)
em.add_field(name = "Reason:", value = "If your trying to spam the server then get off!")
em.add_field(name = "Try again in:", value = "`{:.2f}s`".format(error.retry_after))
em.set_footer(text="Lots of Spam can lead to a ban")
em.set_author(name = ctx.author.name, icon_url = ctx.author.avatar_url)
await ctx.send(embed = em)
if isinstance(error, commands.BotMissingPermissions):
em = discord.Embed(title = f'<:Red_Cross:988360177017311263> {ctx.command.name} Failed!', color = discord.Color.random(), description = "<:Coder_Hammer:826315685142462474> Guys huh we created uhhhhhhhhh yeahhhhhh")
em.add_field(name = 'Reason', value = 'I don\'t have the perms to do that-')
em.add_field(name = 'What to do:', value = "Give me perms when?")
em.set_footer(text = "-_-", icon_url = ctx.author.avatar_url)
await ctx.send(embed = em)
@commands.command(aliases = ['setticketrole', 'ticketrole'])
@commands.has_permissions(manage_guild = True)
async def addticketrole(self, ctx, role : discord.Role = None, *,reason = None):
if role == None:
await ctx.send("You need to provide a valid role!")
return
tickets = await self.get_tickets()
em = discord.Embed(title= "<:sucess:935052640449077248> Added ticketrole", color = 0x0098d2)
em.set_author(name = ctx.author.name, icon_url = ctx.author.avatar_url)
guild = ctx.guild
author = ctx.author
if str(ctx.guild.id) not in tickets:
em.add_field(name = "Switch:", value = f"`None` <➡️940608259075764265> {role.mention}")
tickets[str(guild.id)] = {}
tickets[str(guild.id)]["ticketrole"]=[]
tickets[str(guild.id)]["ticketrole"].append(int(role.id))
else:
role_id = tickets[str(guild.id)]["ticketrole"]
tickets[str(guild.id)]["ticketrole"].append(int(role.id))
em.add_field(name = "Role:", value = f"{role.mention}")
em.add_field(name = "Features:", value = "Users can now type `[p] new <reason>`")
em.add_field(name = "Reason:", value = f"`{reason}`")
em.set_footer(text="Recommended setting up all the stuff")
await ctx.send(embed = em)
# send the mod log
try:
channelId = int(tickets[str(ctx.guild.id)]["ticketchannel"])
for channel_ in ctx.guild.channels:
if channel_.id == channelId:
em = discord.Embed(title = "<:sucess:935052640449077248> Ticket Role Set!", color = 0x0098d2)
em.add_field(name = "Staff Member:", value = f"{ctx.author.mention}")
em.add_field(name ="Reason:", value = f"`{reason}`")
em.add_field(name= "Ticket Role", value = f'{role.mention}')
em.set_author(name = ctx.author.name, icon_url = ctx.author.avatar_url)
em.set_thumbnail(url = ctx.author.avatar_url)
await channel_.send(embed = em)
break
except:
pass
# Updating the database
with open("data.json", "w") as f:
json.dump(tickets, f)
@commands.command(aliases = ['remticketrole', 'ticketroleremove'])
@commands.has_permissions(manage_guild = True)
async def removeticketrole(self, ctx, role : discord.Role = None, *,reason = None):
if role == None:
await ctx.send("You need to provide a valid role!")
return
tickets = await self.get_tickets()
guild = ctx.guild
author = ctx.author
if str(ctx.guild.id) not in tickets:
return await ctx.send(embed=discord.Embed(title="Failed",description="No record for this guild , setup tickets"))
else:
if role.id in tickets[str(guild.id)]["ticketrole"]:
try:
em = discord.Embed(title= "<:sucess:935052640449077248> Removed ticketrole", color = 0x0098d2)
em.set_author(name = ctx.author.name, icon_url = ctx.author.avatar_url)
tickets[str(guild.id)]["ticketrole"].remove(role.id)
# Updating the database
with open("data.json", "w") as f:
json.dump(tickets, f)
em.add_field(name = "Role:", value = f"{role.mention}")
em.add_field(name = "Now:", value = f"People having {role} as their topmost role can't see tickets any more")
em.add_field(name = "Reason:", value = f"`{reason}`")
em.set_footer(text="Recommended setting up all the stuff")
await ctx.send(embed = em)
except Exception as e:
await ctx.send(e)
@addticketrole.error
async def addticketrole_error(self, ctx, error):
if isinstance(error, commands.MissingPermissions):
em = discord.Embed(title = "<:Red_Cross:988360177017311263> Ticket Error", color = 0x0098d2)
em.add_field(name = "Reason:", value = "You don't have the perms dont try to control me duh!")
em.add_field(name = "Perms:", value = "`Manage Server permission missing!`")
em.set_author(name = ctx.author.name, icon_url = ctx.author.avatar_url)
em.set_footer(text="Recommended setting up all the stuff")
await ctx.send(embed = em)
if isinstance(error, commands.BadArgument):
em = discord.Embed(title= "<:Red_Cross:988360177017311263> Ticket Error", color = 0x0098d2)
em.add_field(name ="Reason:", value = f"{ctx.author.mention}, you need to provide a valid role!")
em.add_field(name = "Usage:", value = '```diff\n+ [p] addticketrole <@role> [reason]\n- [p] addticketrole bruh\n```')
em.set_author(name = ctx.author.name, icon_url = ctx.author.avatar_url)
em.set_footer(text = "Read the docs, heheboi!")
await ctx.send(embed = em)
if isinstance(error, commands.BotMissingPermissions):
em = discord.Embed(title = f'<:Red_Cross:988360177017311263> {ctx.command.name} Failed!', color = discord.Color.random(), description = "<:Coder_Hammer:826315685142462474> Ladies and gentlemen we got ||...||")
em.add_field(name = 'Reason', value = 'I don\'t have the perms to do that-')
em.add_field(name = 'What to do:', value = "Give me perms when?")
em.set_footer(text = "-_-", icon_url = ctx.author.avatar_url)
await ctx.send(embed = em)
@commands.command(aliases = ['addticketlogs', 'atl', 'stl'])
@commands.has_permissions(manage_guild = True)
async def setticketlogs(self, ctx, channel : discord.TextChannel = None, *, reason = None):
if channel is None:
await ctx.send("You need to provide a valid channel!")
em = discord.Embed(title ="<:sucess:935052640449077248> Ticket Logs Set", color = 0x0098d2)
em.add_field(name = "Staff Member:", value = f"{ctx.author.mention}")
em.add_field(name = "Channel:", value = f"{channel.mention}")
em.add_field(name = "Reason:", value = f"`{reason}`", inline = False)
em.set_author(name = ctx.author.name, icon_url = ctx.author.avatar_url)
em.set_footer(text = "Invite me with [p] invite ;)")
await ctx.send(embed = em)
tickets = await self.get_tickets()
guild = ctx.guild
if str(ctx.guild.id) not in tickets:
tickets[str(guild.id)] = {}
tickets[str(guild.id)]["ticketchannel"] = int(channel.id)
else:
tickets[str(guild.id)]["ticketchannel"] = int(channel.id)
with open("data.json", "w") as f:
json.dump(tickets, f)
@setticketlogs.error
async def setticketlogs_error(self,ctx, error):
if isinstance(error, commands.MissingPermissions):
em = discord.Embed(title = '<:Red_Cross:988360177017311263> Setticketlogs Failed', color = 0x0098d2)
em.add_field(name = "Reason:", value = "`Manage Server permission is missing!`")
em.set_thumbnail(url = ctx.author.avatar_url)
em.set_footer(text="Smh, imagine thinking you have the perms!")
em.set_author(name = ctx.author.name, icon_url = ctx.author.avatar_url)
await ctx.send(embed = em)
if isinstance(error, commands.BadArgument):
em = discord.Embed(title = '<:Red_Cross:988360177017311263> Setticketlogs Failed', color = 0x0098d2)
em.add_field(name = "Reason:", value = "Mention a channel properly, like {}".format(ctx.channel.mention))
em.add_field(name= "Usage:", value = "```diff\n+ [p] setticketlogs #ticket-logs better ticket logs\n- [p] setticketlogs SniperXi199#2209 setting a member as logs\n```")
em.set_thumbnail(url = ctx.author.avatar_url)
em.set_footer(text="Smh, imagine being that bad!")
em.set_author(name = ctx.author.name, icon_url = ctx.author.avatar_url)
await ctx.send(embed = em)
if isinstance(error, commands.BotMissingPermissions):
em = discord.Embed(title = f'<:Red_Cross:988360177017311263> {ctx.command.name} Failed!', color = discord.Color.random(), description = "<:Coder_Hammer:826315685142462474> Ladies and gentlemen we got ||...||")
em.add_field(name = 'Reason', value = 'I don\'t have the perms to do that-')
em.add_field(name = 'What to do:', value = "Give me perms when?")
em.set_footer(text = "-_-", icon_url = ctx.author.avatar_url)
await ctx.send(embed = em)
@commands.command(aliases = ['closeticket', "ticketclose"])
@commands.has_permissions(manage_channels = True)
async def close(self, ctx, *, reason = None):
channel = ctx.channel
name = channel.name
tickets = await self.get_tickets()
if name.startswith("ticket-"):
# send mod log
channelId = int(tickets[str(ctx.guild.id)]["ticketchannel"])
print(channelId)
for ticketChannel in ctx.guild.channels:
# find channel
if ticketChannel.id == channelId:
em = discord.Embed(title = "<:Red_Cross:988360177017311263> Ticket Closed!", color = 0x0098d2)
em.add_field(name = "Staff Member:", value = f"{ctx.author.mention}")
em.add_field(name ="Reason:", value = f"`{reason}`")
# get the name of member
ticket, name = name.split("-")
em.add_field(name = "Inquirer:", value = f"{name}")
em.set_thumbnail(url = ctx.author.avatar_url)
await ticketChannel.send(embed = em)
break
messageEmbed = discord.Embed(title = "<:sucess:935052640449077248> Ticket Will Close!", color = 0x0098d2,
description = "This ticket will close in ten seconds. Thanks for your time!")
seconds = 10
messageEmbed.add_field(name= "Time remaining:", value = f"`{seconds}`")
messageEmbed.add_field(name = "Staff Member:", value = f"{ctx.author.mention}")
messageEmbed.add_field(name = "Reason:", value = f"`{reason}`")
messageEmbed.add_field(name = "Mod Logs:", value = "Sending logs in 5 seconds!")
messageEmbed.set_footer(text = "Wanna invite me eh? `[p] invite`)")
await ctx.send(embed = messageEmbed)
# sleep and delete channel
await asyncio.sleep(10)
# now delete the channel
await channel.delete()
else:
em = discord.Embed(title = "<:Red_Cross:988360177017311263> Closing Failed!", color= 0x0098d2)
em.add_field(name = "Reason:", value = f'This channel ({ctx.channel.mention}) is not a ticket channel!')
em.add_field(name = "Try again later!", value = "Only a channel which has been a ticket can be closed!")
em.set_footer(text="Recommended setting up all the stuff")
em.set_author(name = ctx.author.name, icon_url = ctx.author.avatar_url)
await ctx.send(embed = em)
@close.error
async def close_error(self, ctx, error):
if isinstance(error, commands.MissingPermissions):
em = discord.Embed(title = '<:Red_Cross:988360177017311263> Close Failed', color = 0x0098d2)
em.add_field(name = "Reason:", value = "`Manage Channels permission is missing!`")
em.set_thumbnail(url = ctx.author.avatar_url)
em.set_footer(text="Smh, imagine thinking you have the perms!")
await ctx.send(embed = em)
if isinstance(error, commands.BotMissingPermissions):
em = discord.Embed(title = f'<:Red_Cross:988360177017311263> {ctx.command.name} Failed!', color = discord.Color.random(), description = "<:Coder_Hammer:826315685142462474> Ladies and gentlemen we got ||...||")
em.add_field(name = 'Reason', value = 'I don\'t have the perms to do that-')
em.add_field(name = 'What to do:', value = "Give me perms when?")
em.set_footer(text = "-_-", icon_url = ctx.author.avatar_url)
await ctx.send(embed = em)
async def get_tickets(self):
with open("data.json", "r") as f:
data = json.load(f)
return data
"""
@param guild : discord.Guild object!
"""
async def get_logs(self, guild):
guild_id = guild.id
tickets = await self.get_tickets()
if str(guild_id) not in tickets:
return False
return int(tickets[str(guild.id)]["ticketchannel"])
"""
@param guild : discord.Guild object!
"""
async def get_role(self, guild):
guild_id = guild.id
tickets = await self.get_tickets()
if str(guild_id) not in tickets:
return False
return int(tickets[str(guild_id)]["ticketrole"])
"""
@param guild : discord.Guild object!
@param ticketrole : discord.Role object
@param ticketchannel : discord.Channel object
"""
async def open_guild(self, guild, ticketrole : discord.Role, ticketchannel: discord.TextChannel):
tickets = await self.get_tickets()
if not str(guild.id) in tickets:
tickets[str(guild.id)] = {}
tickets[str(guild.id)]["ticketchannel"] = int(ticketchannel.id)
tickets[str(guild.id)]["ticketrole"] = int(ticketrole.id)
else:
tickets[str(guild.id)]["ticketchannel"] = int(ticketchannel.id)
tickets[str(guild.id)]["ticketrole"] = int(ticketrole.id)
with open("data.json", "w") as f:
json.dump(tickets, f)
return [self.get_logs(guild), self.get_role(guild)]
def setup(client):
client.add_cog(Tickets(client))