-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.js
295 lines (267 loc) · 11.5 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
require('dotenv').config()
const { Client, GatewayIntentBits, REST, Routes, ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder, ActivityType, ModalBuilder, TextInputBuilder, TextInputStyle } = require('discord.js');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
],
});
const fs = require('node:fs');
const commands = [];
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require("./commands/" + file);
commands.push(command.data.toJSON());
}
const rest = new REST({ version: '10' }).setToken(process.env.TOKEN);
(async () => {
try {
const data = await rest.put(
Routes.applicationGuildCommands(process.env.CLIENT_ID, process.env.GUILD_ID),
{ body: commands },
);
} catch (error) {
console.error(error);
}
})();
client.on("ready", () => {
client.user.setPresence({
activities: [{ name: "with proxies", type: ActivityType.Playing }],
status: "online"
});
})
client.on('interactionCreate', async interaction => {
if (interaction.isChatInputCommand()) {
if (interaction.commandName == "panel") {
var row = new ActionRowBuilder()
row.addComponents(
new ButtonBuilder()
.setCustomId("link")
.setLabel("Get Link")
.setStyle(ButtonStyle.Primary),
)
var panelEmbed = new EmbedBuilder()
.setColor(0x004953)
.setTitle("Cog Dispenser")
.setDescription("Click the button below to get a new proxy link")
.setFooter({ text: "Made by Nebelung", iconURL: "https://avatars.githubusercontent.com/u/81875430" })
await interaction.reply({ embeds: [ panelEmbed ], components: [ row ] })
} else if (interaction.commandName == "admin") {
var row = new ActionRowBuilder()
row.addComponents(
new ButtonBuilder()
.setCustomId("links")
.setLabel("Links")
.setStyle(ButtonStyle.Primary),
new ButtonBuilder()
.setCustomId("add")
.setLabel("Add")
.setStyle(ButtonStyle.Success),
new ButtonBuilder()
.setCustomId("remove")
.setLabel("Remove")
.setStyle(ButtonStyle.Danger),
new ButtonBuilder()
.setCustomId("reset")
.setLabel("Reset Limit")
.setStyle(ButtonStyle.Secondary),
)
var panelEmbed = new EmbedBuilder()
.setColor(0x004953)
.setTitle("Admin Panel")
.setDescription("Admin commands for the proxy bot")
.setFooter({ text: "Made by Nebelung", iconURL: "https://avatars.githubusercontent.com/u/81875430" })
await interaction.reply({ embeds: [ panelEmbed ], components: [ row ] })
}
} else if (interaction.isButton()) {
if (interaction.customId == "link") {
var allLinks = JSON.parse(fs.readFileSync("data/links.json"));
var allRequested = JSON.parse(fs.readFileSync("data/requested.json"))[interaction.user.id]
if (allRequested) {
allLinks = allLinks.filter(item => !allRequested.includes(item))
}
var randomLink = allLinks[Math.floor(Math.random() * allLinks.length)];
if (!randomLink) {
return interaction.reply({ content: "No Proxies Available", ephemeral: true })
}
var users = JSON.parse(fs.readFileSync("data/users.json"));
if (users[interaction.user.id] && users[interaction.user.id] == 3) {
return interaction.reply({ content: "You can no longer receive sites until the bot is reset", ephemeral: true })
}
var remaining = String(remaining = 3 - Number(users[interaction.user.id] || 0) - 1)
interaction.deferUpdate()
var proxyEmbed = new EmbedBuilder()
.setColor(0x004953)
.setTitle("Cog Dispenser")
.setDescription("Enjoy your new link")
.addFields(
{ name: "URL", value: randomLink },
{ name: "Remaining", value: remaining },
{ name: "Notice", value: "If the link is blocked click the report button below" }
)
.setFooter({ text: "Made by Nebelung", iconURL: "https://avatars.githubusercontent.com/u/81875430" })
var row = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setURL(randomLink)
.setLabel("Open")
.setStyle(ButtonStyle.Link),
new ButtonBuilder()
.setCustomId("report")
.setLabel("Report")
.setStyle(ButtonStyle.Danger)
)
client.users.cache.get(interaction.user.id).send({embeds: [ proxyEmbed ], components: [ row ]})
var newUsers = users;
if (!users[interaction.user.id]) {
newUsers[interaction.user.id] = 1;
} else {
newUsers[interaction.user.id] = newUsers[interaction.user.id] + 1;
}
fs.writeFileSync("data/users.json", JSON.stringify(newUsers, null, 2));
var newRequested = JSON.parse(fs.readFileSync("data/requested.json"));
if (!newRequested[interaction.user.id]) {
newRequested[interaction.user.id] = []
}
newRequested[interaction.user.id].push(randomLink)
fs.writeFileSync("data/requested.json", JSON.stringify(newRequested, null, 2));
} else if (interaction.customId == "report") {
var reportModule = new ModalBuilder()
.setCustomId("reportModule")
.setTitle("Report");
var reportReason = new TextInputBuilder()
.setCustomId("reportReason")
.setLabel("Reason")
.setStyle(TextInputStyle.Paragraph)
.setMaxLength(500)
.setRequired(true)
var firstRow = new ActionRowBuilder().addComponents(reportReason);
reportModule.addComponents(firstRow);
await interaction.showModal(reportModule);
} else if (interaction.customId == "reset") {
fs.writeFileSync("data/users.json", "{}");
return interaction.reply({ content: "Reset bot for all users", ephemeral: true })
} else if (interaction.customId == "closeReport") {
var closeReportModule = new ModalBuilder()
.setCustomId("closeReportModule")
.setTitle("Report");
var closeReportReason = new TextInputBuilder()
.setCustomId("closeReportReason")
.setLabel("Reason")
.setStyle(TextInputStyle.Paragraph)
.setPlaceholder('How was this resolved?')
.setMaxLength(500)
.setRequired(true)
var firstRow = new ActionRowBuilder().addComponents(closeReportReason);
closeReportModule.addComponents(firstRow);
await interaction.showModal(closeReportModule);
} else if (interaction.customId == "add") {
var addModule = new ModalBuilder()
.setCustomId("addModule")
.setTitle("Add Link");
var linkURL = new TextInputBuilder()
.setCustomId("linkURL")
.setLabel("URL")
.setStyle(TextInputStyle.Short)
.setMaxLength(500)
.setRequired(true)
var firstRow = new ActionRowBuilder().addComponents(linkURL);
addModule.addComponents(firstRow);
await interaction.showModal(addModule);
} else if (interaction.customId == "remove") {
var removeModule = new ModalBuilder()
.setCustomId("removeModule")
.setTitle("Remove Link");
var linkURL = new TextInputBuilder()
.setCustomId("linkURL")
.setLabel("URL")
.setStyle(TextInputStyle.Short)
.setMaxLength(500)
.setRequired(true)
var firstRow = new ActionRowBuilder().addComponents(linkURL);
removeModule.addComponents(firstRow);
await interaction.showModal(removeModule);
} else if (interaction.customId == "links") {
var allLinks = JSON.parse(fs.readFileSync("data/links.json"));
if (allLinks == []) {
allLinks = "No Links Available"
} else {
allLinks = allLinks.join("\n")
}
var linksEmbed = new EmbedBuilder()
.setColor(0x004953)
.setTitle("Links")
.setDescription("Every link in the database!\n```\n" + allLinks + "\n```")
.setFooter({ text: "Made by Nebelung", iconURL: "https://avatars.githubusercontent.com/u/81875430" })
return interaction.reply({ embeds: [ linksEmbed ], ephemeral: true })
}
} else if (interaction.isModalSubmit()) {
if (interaction.customId == "reportModule") {
var reportEmbed = new EmbedBuilder()
.setColor(0x004953)
.setTitle("Proxy Report")
.setDescription("A link has been reported by a user")
.addFields(
{ name: "URL", value: interaction.message.embeds[0].data.fields[0].value },
{ name: "Reason", value: interaction.fields.getTextInputValue("reportReason") },
{ name: "User", value: "<@" + interaction.user.id + ">" }
)
.setFooter({ text: "Made by Nebelung", iconURL: "https://avatars.githubusercontent.com/u/81875430" })
var row = new ActionRowBuilder()
.addComponents(
new ButtonBuilder()
.setCustomId("closeReport")
.setLabel("Close")
.setStyle(ButtonStyle.Danger),
)
client.guilds.cache.get(process.env.GUILD_ID).client.channels.cache.get(process.env.REPORTS_ID).send({ embeds: [ reportEmbed ], components: [ row ] })
return interaction.reply({ content: "Your report has been submitted", ephemeral: true })
} else if (interaction.customId == "closeReportModule") {
var user = interaction.message.embeds[0].data.fields[2].value.replace("<", "").replace(">", "").replace("@", "")
client.users.fetch(user, false).then((user) => {
var closedReportEmbed = new EmbedBuilder()
.setColor(0x004953)
.setTitle("Closed Report")
.setDescription("A reported link by you has been resolved")
.addFields(
{ name: "URL", value: interaction.message.embeds[0].data.fields[0].value },
{ name: "Reason", value: interaction.message.embeds[0].data.fields[1].value },
{ name: "Response", value: interaction.fields.getTextInputValue("closeReportReason") },
{ name: "Closed By", value: "<@" + interaction.user.id + ">" }
)
.setFooter({ text: "Made by Nebelung", iconURL: "https://avatars.githubusercontent.com/u/81875430" })
user.send({ embeds: [ closedReportEmbed ] })
})
interaction.message.delete()
return interaction.reply({content: "Closed and sent response to user", ephemeral: true})
} else if (interaction.customId == "addModule") {
var newLinks = JSON.parse(fs.readFileSync("data/links.json"));
newLinks.push(interaction.fields.getTextInputValue("linkURL"))
fs.writeFileSync("data/links.json", JSON.stringify(newLinks, null, 2));
return interaction.reply({content: interaction.fields.getTextInputValue("linkURL") + " was successfully added", ephemeral: true})
} else if (interaction.customId == "removeModule") {
var newLinks = JSON.parse(fs.readFileSync("data/links.json"));
if (newLinks.includes(interaction.fields.getTextInputValue("linkURL"))) {
newLinks = newLinks.filter(link => link !== interaction.fields.getTextInputValue("linkURL"))
fs.writeFileSync("data/links.json", JSON.stringify(newLinks, null, 2));
return interaction.reply({content: interaction.fields.getTextInputValue("linkURL") + " was successfully removed", ephemeral: true})
} else {
return interaction.reply({content: interaction.fields.getTextInputValue("linkURL") + " was not found in the database. Click the Links button for a list of all links", ephemeral: true})
}
}
} else if (interaction.isUserContextMenuCommand()) {
if (interaction.commandName == "Reset") {
if (!interaction.targetUser.bot) {
var newUsers = JSON.parse(fs.readFileSync("data/users.json"));
newUsers[interaction.targetUser.id] = 0
fs.writeFileSync("data/users.json", JSON.stringify(newUsers, null, 2));
return interaction.reply({content: "Reset bot limit for <@" + interaction.targetUser.id + ">", ephemeral: true})
} else {
return interaction.reply({content: "Cannot reset a bot", ephemeral: true})
}
}
}
});
client.login(process.env.TOKEN);