-
Notifications
You must be signed in to change notification settings - Fork 6
/
index.js
183 lines (172 loc) · 6.31 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
const fs = require("node:fs");
const path = require("node:path");
const { Client, Collection, GatewayIntentBits, Events, EmbedBuilder } = require("discord.js");
const { token, widgets, logs_channel, links, dispenser_logs } = require("./config.json");
const client = new Client({ intents: ["Guilds", "GuildMessages", "GuildMembers", "MessageContent"], allowedMentions: { everyone: [false], roles: [false] } });
const Sequelize = require("sequelize");
const { byod, proxy } = require("./utils");
const level = new Sequelize("database", "user", "password", {
host: "localhost",
dialect: "sqlite",
logging: false,
storage: "levels.sqlite",
});
const Levels = level.define("levels", {
userID: {
type: Sequelize.INTEGER,
primaryKey: true,
},
level: {
type: Sequelize.INTEGER,
defaultValue: 1,
allowNull: false,
},
points: {
type: Sequelize.INTEGER,
defaultValue: 0,
allowNull: false,
},
lastMessage: {
type: Sequelize.INTEGER,
defaultValue: 0,
allowNull: false,
},
createdAt: {
type: Sequelize.DATE,
defaultValue: Sequelize.literal("CURRENT_TIMESTAMP"),
},
updatedAt: {
type: Sequelize.DATE,
defaultValue: Sequelize.literal("CURRENT_TIMESTAMP"),
},
});
const lnk = new Sequelize("database", "user", "password", {
host: "localhost",
dialect: "sqlite",
logging: false,
storage: "linkbot.sqlite",
});
const link = lnk.define("links", {
userID: {
type: Sequelize.INTEGER,
primaryKey: true,
},
number: {
type: Sequelize.INTEGER,
defaultValue: 0,
allowNull: false,
},
firstGen: {
type: Sequelize.INTEGER,
defaultValue: 0,
allowNull: false,
},
});
let stati = [`👨💻 Working on Selenite.`, `👀 Watching the Selenite Discord`, `🎮 Playing on Selenite`, `https://github.com/selenite-cc/`, `https://selenite.cc/`];
client.once(Events.ClientReady, () => {
Levels.sync();
setInterval(() => {
client.user.setActivity(stati[Math.round(Math.random() * (stati.length - 1))], { type: 4 });
}, 60000);
});
client.commands = new Collection();
const foldersPath = path.join(__dirname, "commands");
const commandFolders = fs.readdirSync(foldersPath);
for (const folder of commandFolders) {
const commandsPath = path.join(foldersPath, folder);
const commandFiles = fs.readdirSync(commandsPath).filter((file) => file.endsWith(".js"));
for (const file of commandFiles) {
const filePath = path.join(commandsPath, file);
const command = require(filePath);
if ("data" in command && "execute" in command) {
client.commands.set(command.data.name, command);
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
}
const eventsPath = path.join(__dirname, "events");
const eventFiles = fs.readdirSync(eventsPath).filter((file) => file.endsWith(".js"));
for (const file of eventFiles) {
const filePath = path.join(eventsPath, file);
const event = require(filePath);
if (event.once) {
client.once(event.name, (...args) => event.execute(...args));
} else {
client.on(event.name, (...args) => event.execute(...args));
}
}
client.login(token);
client.on("messageDelete", (message) => {
const logsChannel = client.channels.cache.get(logs_channel.toString());
const delEmbed = new EmbedBuilder();
delEmbed.setColor("#db3c30");
delEmbed.setTitle("🗑️ message deleted");
delEmbed.setDescription(`> **author:** <@${message.author.id}> \n> **channel:** <#${message.channel.id}> \n> **timestamp:** <t:${Math.floor(Date.now() / 1000)}:R> `);
if (message.content) {
delEmbed.addFields({ name: "message:", value: message.content });
}
// extra thing here to check if message has attachments
if (message.attachments.size > 0) {
const attachments = message.attachments.map((attachment) => attachment.url);
delEmbed.addFields({ name: "attached:", value: attachments.join("\n") });
}
logsChannel.send({ embeds: [delEmbed] });
});
client.on("messageUpdate", (oldm, newm) => {
const logsChannel = client.channels.cache.get(logs_channel.toString());
if (oldm !== newm) {
const ediEmbed = new EmbedBuilder();
ediEmbed.setColor("#e2e833");
ediEmbed.setTitle("✍️ message edited");
ediEmbed.setDescription(`> **author:** <@${oldm.author.id}> \n> **channel:** <#${oldm.channel.id}> \n> **timestamp:** <t:${Math.floor(Date.now() / 1000)}:R> `);
ediEmbed.addFields({ name: "before:", value: `${oldm}`, inline: true }, { name: "after:", value: `${newm}`, inline: true });
logsChannel.send({ embeds: [ediEmbed] });
}
});
client.on("interactionCreate", async (interaction) => {
if (interaction.isButton()) {
if (interaction.customId === "link") {
let [userData, firstGen] = await link.findOrCreate({
where: { userID: interaction.user.id },
defaults: { number: 0, firstGen: 0 },
});
if (userData.firstGen + 43200 < Math.floor(Date.now() / 1000)) {
await userData.update({ number: 0, firstGen: 0 }, { where: { userID: interaction.user.id } });
} else if (userData.number == 2) {
console.log(userData.number);
await interaction.reply({ content: `Please wait, you can generate 2 new links <t:${userData.firstGen + 43200}:R>.`, ephemeral: true });
return;
}
try {
let userLink = links[Math.floor(Math.random() * links.length)];
await interaction.user.send({ content: `**Please do not share links publically.**\nYour link is <${userLink}>` });
const dispenserLogs = client.channels.cache.get(dispenser_logs.toString());
dispenserLogs.send(`User ${interaction.user.id} - ${interaction.user.tag} generated a new link: <${userLink}>`);
if (userData.number == 0) {
await link.update({ number: 1, firstGen: Math.floor(Date.now() / 1000) }, { where: { userID: interaction.user.id } });
} else {
await link.update({ number: 2 }, { where: { userID: interaction.user.id } });
}
} catch (error) {
await interaction.reply({ content: `Please enable DMs.`, ephemeral: true });
const dispenserLogs = client.channels.cache.get(dispenser_logs.toString());
dispenserLogs.send(`User ${interaction.user.id} - ${interaction.user.tag} didn't enable dms :skull:`);
return;
}
}
if(interaction.customId.includes("byod")) {
byod(interaction);
}
if(interaction.customId.includes("proxy")) {
proxy(interaction);
}
} else if (interaction.isModalSubmit()) {
if(interaction.customId.includes("byod")) {
byod(interaction);
}
if(interaction.customId.includes("proxy")) {
proxy(interaction);
}
}
});