-
Notifications
You must be signed in to change notification settings - Fork 5
/
index.js
331 lines (295 loc) · 13.9 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
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
// |**** ⚠️ ALL COPYRIGHTS GOSE TO DEF(http://discord.com/users/933856726770413578) ⚠️ ****|
// |**** ⚠️ ALL COPYRIGHTS GOSE TO DEF(http://discord.com/users/933856726770413578) ⚠️ ****|
// |**** ⚠️ ALL COPYRIGHTS GOSE TO DEF(http://discord.com/users/933856726770413578) ⚠️ ****|
// did you see casperMusic? chack out: https://discord.gg/ws9jA2cR5s
/**
⚠️ stop right there ⚠️
did you know you are stealing my project when you remove the copyright?
you can just contact me http://discord.com/users/933856726770413578 for publish it
or if you are using it for your server know the no one will see the copyrights only you in the project
so why you are removing it?, be nice and just leave it
|**** ⚠️ ALL COPYRIGHTS GOSE TO DEF(http://discord.com/users/933856726770413578) ⚠️ ****|
|**** ⚠️ ALL COPYRIGHTS GOSE TO DEF(http://discord.com/users/933856726770413578) ⚠️ ****|
|**** ⚠️ ALL COPYRIGHTS GOSE TO DEF(http://discord.com/users/933856726770413578) ⚠️ ****|
*/
// imports
const Discord = require("discord.js");
const modals = require("discord-modals");
const ora = require("ora");
const chalk = require("chalk");
const db = require("quick.db");
const fs = require("node:fs");
// constructors
const data = new db.table("suggestion_def")
const client = new Discord.Client({
intents: 32767
});
modals(client);
// ready event and slash commands reg
client.on("ready", () => {
let _ = ora("Processing Clients...").start();
setTimeout(() => _.color = "yellow", 430)
setTimeout(() => _.succeed("Client has logged in as "+chalk.red.bold(client.user.username)),1200)
let commands = [
{name:"set-suggestion-channel",description:"set the suggestions channel",type:1},
{name:"remove-suggestion-channel",description:"remove the suggestions channel",type:1},
{name:"send-suggestion",description:"send a suggestion to suggestions channel",type:1},
{name:"get-user-suggestions",description:"get suggestions of any user",type:1,options:[
{name:"user",description:"the user you will get the suggestion from",required:true,type:6}
]},
];
client.application.commands.set(commands)
}).login(fs.readFileSync(__dirname+"/token.txt", {encoding:"utf-8"}));
// interactionDetected event
client.on("interactionCreate", async(interaction) => {
// some condetions
if (interaction.isButton()) return await buttons(interaction);
if (
!interaction.isCommand()
||
!interaction.guild?.id
||
!interaction.user
||
interaction.channel.type == "DM"
||
!interaction.guild.me.permissionsIn(interaction.channel)
.has(Discord.Permissions.FLAGS.SEND_MESSAGES)
)
return;
if (interaction.commandName == "set-suggestion-channel") {
if (!interaction.member.permissions.has(Discord.Permissions.FLAGS.MANAGE_GUILD))
return interaction.reply(
{content:"you need some permissions to allow you using **`"+interaction.commandName+"`** command.",ephemeral:true}
)
let channel = interaction.channelId;
let value = {channel:channel}
let key = "SuggestionsChannel_"+interaction.guild?.id;
data.set(key, value)
interaction.reply(
{content:"<#"+channel+"> has set as suggestion channel on **"+interaction.guild?.name+"**.",ephemeral:true}
)
}
else if (interaction.commandName == "remove-suggestion-channel") {
if (!interaction.member.permissions.has(Discord.Permissions.FLAGS.MANAGE_GUILD))
return interaction.reply(
{content:"you need some permissions to allow you using **`"+interaction.commandName+"`** command.",ephemeral:true}
)
let key = "SuggestionsChannel_"+interaction.guild?.id;
data.delete(key)
interaction.reply(
{content:"suggestion channel has been rested.",ephemeral:true}
)
}
else if (interaction.commandName == "get-user-suggestions") {
let userInfos = interaction.options.getUser("user",true);
let userKey = "Suggestions_"+interaction.guild.id+"_"+userInfos.id.toString()+".sugs";
let udata = data.fetch(userKey);
if (udata == null) return interaction.reply(
{content:"<@"+userInfos.id+"> has no suggestion on **"+interaction.guild?.name+"**.",ephemeral:true}
)
else {
let calSugs = await udata.map((message, index) => `${index + 1}. [go to suggestion message](${message.url})\n\`\`\`\n${message.content}\`\`\``).join("\n\n");
interaction.reply(
{content:calSugs,ephemeral:true}
)
}
}
else if (interaction.commandName == "send-suggestion") {
const modal = new modals.Modal()
.setCustomId('send')
.setTitle('type you suggestion down blow:')
.addComponents(
new modals.TextInputComponent()
.setCustomId('input')
.setLabel('Some text Here')
.setStyle('LONG')
.setMinLength(3)
.setMaxLength(1024)
.setPlaceholder('write the suggestion here!.')
.setRequired(true)
);
let modalData = await modals.showModal(modal, {
client: client,
interaction: interaction
});
modalData;
}
});
// respond for modals
client.on('modalSubmit', async (modal) => {
if (modal.customId == 'send') {
let key = "SuggestionsChannel_"+modal.guild?.id;
let res = modal.getTextInputValue('input');
let value = data.fetch(key)?.channel
let channel = client.channels.cache.get(value);
if (!channel) return modal.reply(
{content:'Soory! i can not find the suggestion channel in this server',ephemeral:true}
);
modal.reply(
{content:'Done! your suggestion has been send successfully, you suggestion:```\n'+res+'```',ephemeral:true}
);
channel.send({
embeds: [
{author:{
name: modal.user.username,
iconURL: modal.user.avatarURL({dynamic:true})
},color:0x2c2f33,timestamp: new Date(),footer:{
iconURL: modal.guild?.iconURL({dynamic:true}),
text: modal.guild?.name
},description:res,fields:[
{name:"👍 Up votes:",value:"```\n0```",inline:true},
{name:"👎 Down votes:",value:"```\n0```",inline:true},
]}
],
components: [
new Discord.MessageActionRow()
.addComponents(
new Discord.MessageButton()
.setCustomId("up")
.setStyle("DANGER")
.setLabel("👍 Up"),
new Discord.MessageButton()
.setCustomId("down")
.setStyle("DANGER")
.setLabel("👎 Down"),
new Discord.MessageButton()
.setCustomId("info")
.setStyle("SECONDARY")
.setLabel("❓ How Voted"),
)
]
}).then(async message => {
let dataConstructor = {url:message.url.toString(),content:res}
let userKey = "Suggestions_"+modal.guild?.id+"_"+modal.user.id.toString()+".sugs";
let udata = data.fetch(userKey)
let value = {voters: [],votersInfo: []}
let key = message.id.toString()
if (udata == null) await data.set(userKey, [dataConstructor]);
else await data.push(userKey, dataConstructor)
data.set(key, value);
});
}
});
// message event
client.on("messageCreate", (msg) => {
if (msg.author.bot) return;
if (!msg.guild?.id) return;
let key = "SuggestionsChannel_"+msg.guild?.id;
let guild = msg.guild
let channel = msg.channel;
let msgAuthor = msg.author;
let rawEContent = msg["content"]
let data2 = data.fetch(key);
if (data2 == null) return;
if (msg.channelId !== data2.channel) return;
if (msg.deletable) msg.delete();
channel.send({
embeds: [
{author:{
name: msgAuthor.username,
iconURL: msgAuthor.avatarURL({dynamic:true})
},color:0x2c2f33,timestamp: new Date(),footer:{
iconURL: guild.iconURL({dynamic:true}),
text: guild.name
},description:rawEContent,fields:[
{name:"👍 Up votes:",value:"```\n0```",inline:true},
{name:"👎 Down votes:",value:"```\n0```",inline:true},
]}
],
components: [
new Discord.MessageActionRow()
.addComponents(
new Discord.MessageButton()
.setCustomId("up")
.setStyle("DANGER")
.setLabel("👍 Up"),
new Discord.MessageButton()
.setCustomId("down")
.setStyle("DANGER")
.setLabel("👎 Down"),
new Discord.MessageButton()
.setCustomId("info")
.setStyle("SECONDARY")
.setLabel("❓ How Voted"),
)
]
}).then(async message => {
let dataConstructor = {url:message.url.toString(),content:rawEContent}
let userKey = "Suggestions_"+msg.guild.id+"_"+msg.author.id.toString()+".sugs";
let udata = data.fetch(userKey)
let value = {voters: [],votersInfo: []}
let key = message.id.toString()
if (udata == null) await data.set(userKey, [dataConstructor]);
else await data.push(userKey, dataConstructor)
data.set(key, value);
});
})
/**
*
* @param {Discord.ButtonInteraction} interaction
*/
async function buttons(interaction) {
await interaction.deferUpdate().catch(() => {})
switch (interaction.customId) {
case "up": {
let message = interaction.message;
let embed = message.embeds[0];
let dater = `${new Date().getFullYear()}/${new Date().getMonth()}/${new Date().getDay()} ${new Date().getHours()}:${new Date().getMinutes()}:${new Date().getSeconds()}`
let key = message.id.toString()+".voters";
let ke2 = message.id.toString()+".votersInfo";
let value = {user:interaction.user,date: dater}
let newNumber = Number(embed.fields[0].value.split("```\n")[1].split("```")[0]) + 1;
let voter = data.fetch(message.id.toString()).voters;
if (voter.includes(interaction.user.id)) return interaction.followUp({content:"you has voted for this suggestion befor.", ephemeral:true});
let editedEmbed = {author:embed.author,color:embed.color,timestamp: embed.timestamp,footer:embed.footer,
description:embed.description,fields:[
{name:"👍 Up votes:",value:`\`\`\`\n${newNumber}\`\`\``,inline:true},
embed.fields[1],
]}
await data.push(key, interaction.user.id);
await data.push(ke2, value)
message.edit({components: message.components,embeds: [editedEmbed]})
}
break;
case "down": {
let message = interaction.message;
let embed = message.embeds[0];
let dater = `${new Date().getFullYear()}/${new Date().getMonth()}/${new Date().getDay()} ${new Date().getHours()}:${new Date().getMinutes()}:${new Date().getSeconds()}`
let key = message.id.toString()+".voters";
let ke2 = message.id.toString()+".votersInfo";
let value = {user:interaction.user,date: dater}
let newNumber = Number(embed.fields[1].value.split("```\n")[1].split("```")[0]) + 1;
let voter = data.fetch(message.id.toString()).voters;
if (voter.includes(interaction.user.id)) return interaction.followUp({content:"you has voted for this suggestion befor.", ephemeral:true});
let editedEmbed = {author:embed.author,color:embed.color,timestamp: embed.timestamp,footer:embed.footer,
description:embed.description,fields:[
embed.fields[0],
{name:"👎 Down votes:",value:`\`\`\`\n${newNumber}\`\`\``,inline:true},
]}
await data.push(key, interaction.user.id);
await data.push(ke2, value)
message.edit({components: message.components,embeds: [editedEmbed]})
}
break;
case "info": {
let voters = data.fetch(interaction.message.id.toString()).votersInfo;
let raws = voters.map((voter, index) => `${index + 1}. ${voter.user.username} - ${voter.date}`).join("\n")
if (voters == []) return interaction.followUp({content:"there is no voters", ephemeral:true});
interaction.followUp({content:raws, ephemeral:true});
}
break;
default:
break;
}
}
/**
⚠️ stop right there ⚠️
did you know you are stealing my project when you remove the copyright?
you can just contact me http://discord.com/users/933856726770413578 for publish it
or if you are using it for your server know the no one will see the copyrights only you in the project
so why you are removing it?, be nice and just leave it
|**** ⚠️ ALL COPYRIGHTS GOSE TO DEF(http://discord.com/users/933856726770413578) ⚠️ ****|
|**** ⚠️ ALL COPYRIGHTS GOSE TO DEF(http://discord.com/users/933856726770413578) ⚠️ ****|
|**** ⚠️ ALL COPYRIGHTS GOSE TO DEF(http://discord.com/users/933856726770413578) ⚠️ ****|
*/