Skip to content

Commit 30f2bb8

Browse files
authored
Add files via upload
1 parent 8aad526 commit 30f2bb8

File tree

5 files changed

+2017
-0
lines changed

5 files changed

+2017
-0
lines changed

README.md

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Créer par `rh#6948`
2+
3+
## Step 1:
4+
- Configure le **config.js**
5+
6+
## Step 2:
7+
- Ouvre le terminal et éxecute "**npm install**"
8+
9+
## Step 3:
10+
- Lance en faisant **index.js**

config.js

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module.exports = {
2+
token: "ton token",
3+
prefix: "t!"
4+
}

index.js

+213
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
const Discord = require("discord.js");
2+
config = require("./config");
3+
Enmap = require("enmap");
4+
5+
const client = new Discord.Client({
6+
allowedMentions: {
7+
parse: ["roles", "users"],
8+
repliedUser: false,
9+
},
10+
partials: ['MESSAGE', 'CHANNEL'],
11+
intents: [
12+
Discord.Intents.FLAGS.GUILDS,
13+
Discord.Intents.FLAGS.GUILD_MEMBERS,
14+
Discord.Intents.FLAGS.GUILD_MESSAGES,
15+
],
16+
});
17+
18+
client.login(config.token)
19+
20+
client.settings = new Enmap({name: "settings"});
21+
22+
client.on("ready", () => {
23+
console.log(`${client.user.tag} est connecté!`);
24+
})
25+
26+
client.on("messageCreate", async (message) => {
27+
if(!message.guild || message.author.bot) return;
28+
29+
let args = message.content.slice(config.prefix.length).trim().split(" ");
30+
let cmd = args.shift()?.toLowerCase();
31+
32+
if(!message.content.startsWith(config.prefix) || !cmd || cmd.length == 0) return;
33+
34+
client.settings.ensure(message.guildId, {
35+
TicketSystem1: {
36+
channel: "",
37+
message: "",
38+
category: "",
39+
}
40+
})
41+
42+
if(cmd == "ping") {
43+
return message.reply(`\`🏓\` Pong! \`${client.ws.ping}ms\``)
44+
}
45+
if(cmd == "close") {
46+
let ticketUserId = client.settings.findKey(d => d.channelId == message.channelId);
47+
48+
if(!client.settings.has(ticketUserId)){
49+
return message.reply({
50+
content: `:x: Ce channel n'est pas un ticket.`
51+
})
52+
}
53+
client.settings.delete(ticketUserId);
54+
message.reply("Le ticket sera fermé d'ici 3 secondes");
55+
setTimeout(() => {
56+
message.channel.delete().catch(()=>{});
57+
}, 3000)
58+
}
59+
if(cmd == "setup") {
60+
let channel = message.mentions.channels.first() || message.guild.channels.cache.get(args[0]);
61+
if(!channel) return message.reply(":x: Merci de mentionné le channel ```Exemple: t!ticket #channel```");
62+
63+
let TicketEmbed = new Discord.MessageEmbed()
64+
.setColor("YELLOW")
65+
.setTitle("`🎟️` Créer un ticket")
66+
.setDescription("__Sélectionnez pour quoi vous avez besoin d'aide.__")
67+
.setFooter(message.guild.name, message.guild.iconURL({dynamic: true}));
68+
69+
let Menu = new Discord.MessageSelectMenu()
70+
.setCustomId("1ticket")
71+
.setPlaceholder("Clique ici pour ouvrir un ticket")
72+
.setMaxValues(1)
73+
.setMinValues(1)
74+
.addOptions([
75+
{
76+
label: "Aide générale".substr(0, 25),
77+
value: "gen_h".substr(0, 25),
78+
description: "Si vous avez une question sur notre projet".substr(0, 50),
79+
emoji: "🚀",
80+
},
81+
{
82+
label: "Aide pour payements".substr(0, 25),
83+
value: "order_h".substr(0, 25),
84+
description: "Si vous avez besoin d'aide pour commander un produit".substr(0, 70),
85+
emoji: "🪙",
86+
}
87+
])
88+
let row = new Discord.MessageActionRow().addComponents(Menu);
89+
90+
channel.send({
91+
embeds: [TicketEmbed],
92+
components: [row]
93+
}).then((msg) => {
94+
client.settings.set(message.guildId, channel.id, "TicketSystem1.channel")
95+
client.settings.set(message.guildId, msg.id, "TicketSystem1.message")
96+
client.settings.set(message.guildId, channel.parentId, "TicketSystem1.category")
97+
return message.reply("🔔 Mise en place terminé");
98+
}).catch((e) => {
99+
console.log(e);
100+
return message.reply("Un soucis a été rencontrer");
101+
})
102+
}
103+
})
104+
105+
client.on("interactionCreate", async (interaction) => {
106+
if(!interaction.isSelectMenu() || !interaction.guildId || interaction.message.author.id != client.user.id) return
107+
108+
client.settings.ensure(interaction.guildId, {
109+
TicketSystem1: {
110+
channel: "",
111+
message: "",
112+
category: "",
113+
}
114+
})
115+
116+
let data = client.settings.get(interaction.guildId)
117+
if(!data.TicketSystem1.channel || data.TicketSystem1.channel.length == 0) return
118+
119+
120+
if(interaction.channelId == data.TicketSystem1.channel && interaction.message.id == data.TicketSystem1.message) {
121+
switch(interaction.values[0]){
122+
case "gen_h": {
123+
let channel = await CreateTicket({
124+
OpeningMessage: "Création du ticket...",
125+
ClosedMessage: `Ticket ouvert juste ici: <#{channelId}>`,
126+
embeds: [ new Discord.MessageEmbed().setColor("GREEN").setTitle("Comment pourrais-je t'aider ?").setTimestamp()]
127+
}).catch(e=>{
128+
return console.log(e)
129+
})
130+
console.log(channel.name);
131+
} break;
132+
case "order_h": {
133+
let channel = await CreateTicket({
134+
OpeningMessage: "Création du ticket...",
135+
ClosedMessage: `Ticket ouvert juste ici: <#{channelId}>`,
136+
embeds: [ new Discord.MessageEmbed().setColor("ORANGE").setTitle("Comment pourrais-je t'aider ?").setTimestamp()]
137+
}).catch(e=>{
138+
return console.log(e)
139+
})
140+
console.log(channel.name);
141+
} break;
142+
}
143+
144+
async function CreateTicket(ticketdata) {
145+
return new Promise(async function(resolve, reject) {
146+
await interaction.reply({
147+
ephemeral: true,
148+
content: ticketdata.OpeningMessage
149+
})
150+
let { guild } = interaction.message;
151+
let category = guild.channels.cache.get(data.TicketSystem1.category);
152+
if(!category || category.type != "GUILD_CATEGORY") category = interaction.message.channel.parentId || null;
153+
let optionsData = {
154+
type: "GUILD_TEXT",
155+
topic: `${interaction.user.tag} | ${interaction.user.id}`,
156+
permissionOverwrites: [],
157+
}
158+
if(client.settings.has(interaction.user.id)){
159+
let TicketChannel = guild.channels.cache.get(client.settings.get(interaction.user.id, "channelId"))
160+
if(!TicketChannel) {
161+
client.settings.delete(interaction.user.id)
162+
} else {
163+
return interaction.editReply({
164+
ephemeral: true,
165+
content: `Tu as déjà un ticket ! : <#${TicketChannel.id}>`
166+
})
167+
}
168+
}
169+
optionsData.permissionOverwrites = [...guild.roles.cache.values()].sort((a, b) => b?.rawPosition - a.rawPosition).map(r => {
170+
let Obj = {}
171+
if(r.id){
172+
Obj.id = r.id;
173+
Obj.type = "role";
174+
Obj.deny = ["SEND_MESSAGES", "VIEW_CHANNEL", "EMBED_LINKS", "ADD_REACTIONS", "ATTACH_FILES"]
175+
Obj.allow = [];
176+
return Obj;
177+
} else {
178+
return false;
179+
}
180+
}).filter(Boolean);
181+
optionsData.permissionOverwrites.push({
182+
id: interaction.user.id,
183+
type: "member",
184+
allow: ["SEND_MESSAGES", "VIEW_CHANNEL", "EMBED_LINKS", "ADD_REACTIONS", "ATTACH_FILES"],
185+
deny: [],
186+
})
187+
while (optionsData.permissionOverwrites.length >= 99){
188+
optionsData.permissionOverwrites.shift();
189+
}
190+
if(category) optionsData.parent = category;
191+
guild.channels.create(`ticket-${interaction.user.username.split(" ").join("-")}`.substr(0, 32), optionsData).then(async channel => {
192+
await channel.send({
193+
content: `<@${interaction.user.id}>`,
194+
embeds: ticketdata.embeds
195+
}).catch(()=>{});
196+
client.settings.set(interaction.user.id, {
197+
userId: interaction.user.id,
198+
channelId: channel.id,
199+
})
200+
await interaction.editReply({
201+
ephemeral: true,
202+
content: ticketdata.ClosedMessage.replace("{channelId}", channel.id)
203+
}).catch(()=>{});
204+
resolve(channel);
205+
}).catch((e)=>{
206+
reject(e)
207+
});
208+
})
209+
210+
}
211+
212+
}
213+
})

0 commit comments

Comments
 (0)