-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
155 lines (131 loc) · 4.87 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
const { Client, Collection, GatewayIntentBits, Partials, ChannelType } = require('discord.js');
const config = require('./config.json');
const fs = require("fs");
const lol = require("./util/lol_functions.js");
const index2 = require('./index2.js');
const logger = require('./util/logger');
const dns = require('node:dns');
dns.setDefaultResultOrder('ipv4first');
logger.log("Starting...");
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
],
partials: [
Partials.Message,
Partials.Channel,
Partials.Reaction
]
});
// -------------- LOL -----------------
client.lol = lol;
client.lol.setup(client);
// -------------- Commandes -----------------
client.commands = new Collection();
client.context_menu = new Collection();
client.buttons = new Collection();
client.groups = new Collection();
client.timers = new Collection();
client.listeners = new Collection();
client.amonglegends = new Collection();
client.owners = config["owner"];
const ListenerFiles = fs.readdirSync('./listeners').filter(file => file.endsWith('.js'));
for (const file of ListenerFiles) {
const listener = require(`./listeners/${file}`);
client.listeners.set(listener.name, listener);
}
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
const contextFiles = fs.readdirSync('./context-menu').filter(file => file.endsWith('.js'));
for (const file of contextFiles) {
const context = require(`./context-menu/${file}`);
client.context_menu.set(context.name, context);
}
const buttonFiles = fs.readdirSync('./buttons').filter(file => file.endsWith('.js'));
for (const file of buttonFiles) {
const button = require(`./buttons/${file}`);
client.buttons.set(button.name, button);
}
const TimersFiles = fs.readdirSync('./timers').filter(file => file.endsWith('.js'));
for (const file of TimersFiles) {
const timer = require(`./timers/${file}`);
client.timers.set(timer.name, timer);
}
client.commands.forEach((item) => {
if (!client.groups.has(item.group)) {
const a = {
name: item.group,
commands: new Collection()
};
client.groups.set(item.group, a);
}
client.groups.get(item.group).commands.set(item.name, item);
});
client.isOwner = function (user) {
return client.owners.includes(user.id);
};
// -------------- Utils -----------------
if (!String.prototype.format) {
String.prototype.format = function () {
const args = arguments;
return this.replace(/{(\d+)}/g, function (match, number) {
return typeof args[number] !== 'undefined'
? args[number]
: match;
});
};
}
// -------------- Events -----------------
client.listeners.forEach((item) => {
client.on(item.type, async (args1, args2, args3, args4) => {
item.run(client, args1, args2, args3, args4);
});
});
// -------------- Functions -----------------
/**
* Check if the command can be run
* @function canRunCommande
* @param {*} message message send by the user
* @param {*} commande commande to run
* @param {*} interaction interaction send by the user
* @return {Boolean} return true if the command can be run
*/
client.canRunCommande = function (message, commande, interaction = undefined) {
if (interaction === undefined) {
//if(commande.commande_channel === true && !message.channel.name.toLowerCase().includes("commande")) return false
if (!checkpermission(message, commande.owner, commande.permission)) { return "perm"; }
if (commande.place === "dm" && message.channel.type !== ChannelType.DM) { return false; }
if (commande.place === "guild" && message.channel.type !== ChannelType.GuildText) { return false; }
return true;
}
//if(commande.commande_channel === true && !interaction.channel.name.toLowerCase().includes("commande")) return false;
if (!checkpermission(interaction, commande.owner, commande.permission)) { return "perm"; }
return true;
};
/**
* Check if the user has the given permission
* @function checkpermission
* @param {*} message message send by the user
* @param {*} perm permission to check
* @returns {Boolean} return true if the user has the permission
*/
function checkpermission(message, owner, perm) {
const id = message.author !== undefined ? message.author.id : message.user.id;
if (client.owners.includes(id)) {
return true;
}
if (owner === true) {
return false;
}
if (perm === undefined) {
return true;
}
return message?.member?.permissions?.has(perm) ?? false;
}
// -------------- Index2 -----------------
index2.main(client);
// -------------- Login -----------------
client.login(process.env.DISCORD_TOKEN);