-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
203 lines (170 loc) · 5.84 KB
/
Copy pathindex.js
File metadata and controls
203 lines (170 loc) · 5.84 KB
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
const keepAlive = require(`./public/server.js`);
const Discord = require(`discord.js`);
// PACKAGES FOR THE BOT
const fs = require(`fs`);
const FreshDB = require(`fresh.db`);
const emoji = require(`emoji-log`);
const config = { prefix: `~` };
const timer = require(`@calipsa/timer`);
const { Webhook, MessageBuilder } = require(`discord-webhook-node`);
// CUSTOM OBJECTS AND PROMISES
const hook = new Webhook(process.env.WEBHOOK);
let db = new FreshDB();
const client = new Discord.Client();
client.commands = new Discord.Collection();
// DATE
let date_ob = new Date();
let date = ("0" + date_ob.getDate()).slice(-2);
let month = ("0" + (date_ob.getMonth() + 1)).slice(-2);
let year = date_ob.getFullYear();
let hours = date_ob.getHours();
if (hours > 4) {
hours = hours - 4;
} else if (hours < 4) {
hours = hours + 12;
hours = hours - 4;
}
let minutes = date_ob.getMinutes();
let seconds = date_ob.getSeconds();
const time =
year + "-" + month + "-" + date + " " + hours + ":" + minutes + ":" + seconds;
/*
The following code is under MIT license and should be treated like so. Refer to legal information for more about the MIT license
*/
/*
Bot`s code, and everything DiscordJS related
*/
// COMMAND HANDLER
const loadCommands = (dir = `./commands/`) => {
let totalTime = 0;
fs.readdirSync(dir).forEach((dirs) => {
const commands = fs
.readdirSync(`${dir}/${dirs}/`)
.filter((files) => files.endsWith(`.js`));
for (const file of commands) {
let end = timer();
const getFileName = require(`${dir}/${dirs}/${file}`);
client.commands.set(getFileName.help.name, getFileName);
let duration = end();
duration = duration * 1000;
duration = Math.round(duration);
duration = duration / 1000;
let partialTime = duration;
totalTime = partialTime + totalTime;
console.emoji(`✅ `, ` : ${getFileName.help.name} --- ${duration} ms`);
}
});
totalTime = totalTime * 1000;
totalTime = Math.round(totalTime);
totalTime = totalTime / 1000;
console.emoji(`🌍 `, ` : ${totalTime} ms`);
};
loadCommands();
// BOT - ON READY
client.on(`ready`, async () => {
console.log(`Logged in as ${client.user.tag}! ${time} - UTC(-4)`);
client.user.setActivity(`~lang fr/en/es`);
});
// BOT - ON MESSAGE
client.on(`message`, async (msg) => {
if (!msg.content.startsWith(config.prefix)) return;
let prefix = config.prefix;
let messageArray = msg.content.split(` `);
let args = messageArray.slice(1);
// LANGUAGE MICRO PROGRAM
if (msg.content.startsWith(`~lang`)) {
let end2 = timer();
if (
!msg.guild.member(msg.author).hasPermission(`ADMINISTRATOR`) &&
msg.author.id !== `370367253205745667`
) {
msg.channel.send(
`The required permission to change this setting is Administrator.`
);
return;
}
if (args[0] === `en`) {
db.set(msg.guild.id, `en`);
msg.channel.send(
`The chosen language is **english**. Thank you for using MCINFO !`
);
} else if (args[0] === `es`) {
db.set(msg.guild.id, `es`);
msg.channel.send(
`El idioma elegido es el español. ¡Gracias por usar MCINFO!`
);
} else if (args[0] === `fr`) {
db.set(msg.guild.id, `fr`);
msg.channel.send(
`La langue choisie est Français ! Merci d'utiliser MCINFO!`
);
} else {
msg.channel.send(
`Please choose a valid language. The default language is **en**`
);
db.set(msg.guild.id, `en`);
return;
}
let duration2 = end2();
duration2 = duration2 * 1000;
duration2 = Math.round(duration2);
duration2 = duration2 + 1;
duration2 = duration2 / 1000;
console.log(`~lang-` + args[0] + ` ` + duration2 + ` ` + `ms`);
}
// CHECK IF SERVER HAS ASSIGNED LANGUAGE
if (!db.get(`${msg.guild.id}`)) {
msg.channel.send(
`Choose your language by doing **~lang en**` +
`\n` +
`Choissisez votre language en envoyant **~lang fr**` +
`\n` +
`Elija su idioma haciendo **~lang es**`
);
}
// GET THE REQUESTED COMMAND WITH REQUESTED LANGUAGE
let command = `${messageArray[0]}-${db.get(`${msg.guild.id}`)}`;
// TIME CALCULATING FOR DEBUGGING
let end1 = timer();
let commandFile = client.commands.get(command.slice(prefix.length));
if (commandFile) {
commandFile.run(client, msg, args);
let duration1 = end1();
let consoleDuration = `${duration1}`;
duration1 = duration1 * 1000;
duration1 = Math.round(duration1);
duration1 = duration1 + 1;
duration1 = duration1 / 1000;
console.log(command + ` ` + duration1 + ` ms`);
}
});
// BOT - ON JOIN SERVER
client.on(`guildCreate`, (guild) => {
const IMAGE_URL = `https://emojipedia-us.s3.dualstack.us-west-1.amazonaws.com/thumbs/240/twitter/259/new-button_1f195.png`;
hook.setUsername(`New Server !`);
hook.setAvatar(IMAGE_URL);
const newServerEmbed = new MessageBuilder()
.setTitle(`New Server Joined !`)
.addField(`New server`, `${guild.name} - ${guild.id}`)
.addField(`Information`, `${guild.memberCount} members `)
.setColor(`#00b0f4`)
.setTimestamp();
hook.send(newServerEmbed);
setTimeout(function () {
const channel = guild.channels.cache.find(
(channel) =>
channel.type === `text` &&
channel.permissionsFor(guild.me).has(`SEND_MESSAGES`)
);
channel.send(
`Hey ! Thanks for adding me on your server ! Choose your language by doing **~lang en**` +
`\n` +
`Salut ! Merci de m'avoir ajouté sur votre serveur ! Choissisez votre language en envoyant **~lang fr** (pour français) !` +
`\n` +
`¡Hola! ¡Gracias por agregarme a su servidor! ¡Elija su idioma enviando **~lang es** (para español)` + `\n` + `Aide/Help/Ayuda : **https://discord.gg/dtbHZPz**`
);
console.log(`New server joined !`);
}, 3000);
});
keepAlive();
client.login(process.env.TOKEN);