-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
213 lines (192 loc) · 8.72 KB
/
index.js
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
const Discord = require("discord.js");
config = require("./config");
Enmap = require("enmap");
const client = new Discord.Client({
allowedMentions: {
parse: ["roles", "users"],
repliedUser: false,
},
partials: ['MESSAGE', 'CHANNEL'],
intents: [
Discord.Intents.FLAGS.GUILDS,
Discord.Intents.FLAGS.GUILD_MEMBERS,
Discord.Intents.FLAGS.GUILD_MESSAGES,
],
});
client.login(config.token)
client.settings = new Enmap({name: "settings"});
client.on("ready", () => {
console.log(`${client.user.tag} est connecté!`);
})
client.on("messageCreate", async (message) => {
if(!message.guild || message.author.bot) return;
let args = message.content.slice(config.prefix.length).trim().split(" ");
let cmd = args.shift()?.toLowerCase();
if(!message.content.startsWith(config.prefix) || !cmd || cmd.length == 0) return;
client.settings.ensure(message.guildId, {
TicketSystem1: {
channel: "",
message: "",
category: "",
}
})
if(cmd == "ping") {
return message.reply(`\`🏓\` Pong! \`${client.ws.ping}ms\``)
}
if(cmd == "close") {
let ticketUserId = client.settings.findKey(d => d.channelId == message.channelId);
if(!client.settings.has(ticketUserId)){
return message.reply({
content: `:x: Ce channel n'est pas un ticket.`
})
}
client.settings.delete(ticketUserId);
message.reply("Le ticket sera fermé d'ici 3 secondes");
setTimeout(() => {
message.channel.delete().catch(()=>{});
}, 3000)
}
if(cmd == "setup") {
let channel = message.mentions.channels.first() || message.guild.channels.cache.get(args[0]);
if(!channel) return message.reply(":x: Merci de mentionné le channel ```Exemple: t!ticket #channel```");
let TicketEmbed = new Discord.MessageEmbed()
.setColor("YELLOW")
.setTitle("`🎟️` Créer un ticket")
.setDescription("__Sélectionnez pour quoi vous avez besoin d'aide.__")
.setFooter(message.guild.name, message.guild.iconURL({dynamic: true}));
let Menu = new Discord.MessageSelectMenu()
.setCustomId("1ticket")
.setPlaceholder("Clique ici pour ouvrir un ticket")
.setMaxValues(1)
.setMinValues(1)
.addOptions([
{
label: "Aide générale".substr(0, 25),
value: "gen_h".substr(0, 25),
description: "Si vous avez une question sur notre projet".substr(0, 50),
emoji: "🚀",
},
{
label: "Aide pour payements".substr(0, 25),
value: "order_h".substr(0, 25),
description: "Si vous avez besoin d'aide pour commander un produit".substr(0, 70),
emoji: "🪙",
}
])
let row = new Discord.MessageActionRow().addComponents(Menu);
channel.send({
embeds: [TicketEmbed],
components: [row]
}).then((msg) => {
client.settings.set(message.guildId, channel.id, "TicketSystem1.channel")
client.settings.set(message.guildId, msg.id, "TicketSystem1.message")
client.settings.set(message.guildId, channel.parentId, "TicketSystem1.category")
return message.reply("🔔 Mise en place terminé");
}).catch((e) => {
console.log(e);
return message.reply("Un soucis a été rencontrer");
})
}
})
client.on("interactionCreate", async (interaction) => {
if(!interaction.isSelectMenu() || !interaction.guildId || interaction.message.author.id != client.user.id) return
client.settings.ensure(interaction.guildId, {
TicketSystem1: {
channel: "",
message: "",
category: "",
}
})
let data = client.settings.get(interaction.guildId)
if(!data.TicketSystem1.channel || data.TicketSystem1.channel.length == 0) return
if(interaction.channelId == data.TicketSystem1.channel && interaction.message.id == data.TicketSystem1.message) {
switch(interaction.values[0]){
case "gen_h": {
let channel = await CreateTicket({
OpeningMessage: "Création du ticket...",
ClosedMessage: `Ticket ouvert juste ici: <#{channelId}>`,
embeds: [ new Discord.MessageEmbed().setColor("GREEN").setTitle("Comment pourrais-je t'aider ?").setTimestamp()]
}).catch(e=>{
return console.log(e)
})
console.log(channel.name);
} break;
case "order_h": {
let channel = await CreateTicket({
OpeningMessage: "Création du ticket...",
ClosedMessage: `Ticket ouvert juste ici: <#{channelId}>`,
embeds: [ new Discord.MessageEmbed().setColor("ORANGE").setTitle("Comment pourrais-je t'aider ?").setTimestamp()]
}).catch(e=>{
return console.log(e)
})
console.log(channel.name);
} break;
}
async function CreateTicket(ticketdata) {
return new Promise(async function(resolve, reject) {
await interaction.reply({
ephemeral: true,
content: ticketdata.OpeningMessage
})
let { guild } = interaction.message;
let category = guild.channels.cache.get(data.TicketSystem1.category);
if(!category || category.type != "GUILD_CATEGORY") category = interaction.message.channel.parentId || null;
let optionsData = {
type: "GUILD_TEXT",
topic: `${interaction.user.tag} | ${interaction.user.id}`,
permissionOverwrites: [],
}
if(client.settings.has(interaction.user.id)){
let TicketChannel = guild.channels.cache.get(client.settings.get(interaction.user.id, "channelId"))
if(!TicketChannel) {
client.settings.delete(interaction.user.id)
} else {
return interaction.editReply({
ephemeral: true,
content: `Tu as déjà un ticket ! : <#${TicketChannel.id}>`
})
}
}
optionsData.permissionOverwrites = [...guild.roles.cache.values()].sort((a, b) => b?.rawPosition - a.rawPosition).map(r => {
let Obj = {}
if(r.id){
Obj.id = r.id;
Obj.type = "role";
Obj.deny = ["SEND_MESSAGES", "VIEW_CHANNEL", "EMBED_LINKS", "ADD_REACTIONS", "ATTACH_FILES"]
Obj.allow = [];
return Obj;
} else {
return false;
}
}).filter(Boolean);
optionsData.permissionOverwrites.push({
id: interaction.user.id,
type: "member",
allow: ["SEND_MESSAGES", "VIEW_CHANNEL", "EMBED_LINKS", "ADD_REACTIONS", "ATTACH_FILES"],
deny: [],
})
while (optionsData.permissionOverwrites.length >= 99){
optionsData.permissionOverwrites.shift();
}
if(category) optionsData.parent = category;
guild.channels.create(`ticket-${interaction.user.username.split(" ").join("-")}`.substr(0, 32), optionsData).then(async channel => {
await channel.send({
content: `<@${interaction.user.id}>`,
embeds: ticketdata.embeds
}).catch(()=>{});
client.settings.set(interaction.user.id, {
userId: interaction.user.id,
channelId: channel.id,
})
await interaction.editReply({
ephemeral: true,
content: ticketdata.ClosedMessage.replace("{channelId}", channel.id)
}).catch(()=>{});
resolve(channel);
}).catch((e)=>{
reject(e)
});
})
}
}
})