generated from CappeDiem/Discord.js-bot-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
155 lines (129 loc) · 5.38 KB
/
app.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
require('dotenv').config()
const prefix = require("./config.json").prefix;
const { Client, Intents, Collection } = require('discord.js')
const bot = require('./bot').bot;
const fs = require("fs")
const jsoning = require('jsoning')
bot.db = new jsoning('db.json')
bot.pterodactylkeys = new jsoning('pterodactylapis.json');
bot.commands = new Collection()
bot.modules = {}
const moduleFiles = fs.readdirSync('./modules/').filter(f => f.endsWith('.js'))
for (const file of moduleFiles) {
const props = require(`./modules/${file}`)
console.log(`${file} loaded`)
const trimmedFilename = file.replace(/\.js$/, '');
bot.modules[trimmedFilename] = props
}
const commandFiles = fs.readdirSync('./commands/').filter(f => f.endsWith('.js'))
for (const file of commandFiles) {
const props = require(`./commands/${file}`)
console.log(`${file} loaded`)
bot.commands.set(props.config.name, props)
}
const commandSubFolders = fs.readdirSync('./commands/').filter(f => !f.endsWith('.js'))
commandSubFolders.forEach(folder => {
const commandFiles = fs.readdirSync(`./commands/${folder}/`).filter(f => f.endsWith('.js'))
for (const file of commandFiles) {
const props = require(`./commands/${folder}/${file}`)
console.log(`${file} loaded from ${folder}`)
bot.commands.set(props.config.name, props)
}
});
// Load Event files from events folder
const eventFiles = fs.readdirSync('./events/').filter(f => f.endsWith('.js'))
for (const file of eventFiles) {
const event = require(`./events/${file}`)
if(event.once) {
bot.once(event.name, (...args) => event.execute(...args, bot))
} else {
bot.on(event.name, (...args) => event.execute(...args, bot))
}
}
//Command Manager
function parseUserId(arg) {
const mentionMatch = arg.match(/^<@!?(\d+)>$/);
if (mentionMatch) {
return mentionMatch[1];
}
if (/^\d+$/.test(arg)) {
return arg;
}
return null;
}
bot.on("messageCreate", async message => {
//Check if author is a bot
if(message.author.bot) return;
if (!message.author.bot) {
if (message.author.id == "254765343745114114") { //ty
message.react("<a:valentinehearts:1209247925977350214>");
} else if (message.author.id == "1176182260731490366") { //me
message.react("<a:gay:1209247930704203777>");
} else if (message.author.id == "195169523823935488") { //chris
message.react("<a:pepeeat:1209247927080587305>");
} else if (message.author.id == "692865328916594709") {
message.react("<a:purpleheart:1209252648130314240>"); //jess
} else {
message.react("👀");
}
setTimeout(async () => {
try {
const fetchedMessage = await message.fetch();
const botId = bot.user.id;
fetchedMessage.reactions.cache.forEach(async reaction => {
if (reaction.users.cache.has(botId)) {
await reaction.users.remove(botId);
}
});
} catch (error) {
console.error('Failed to remove reaction:', error);
}
}, 2 * 1000);
}
//get prefix from config and prepare message so it can be read as a command
let messageArray = message.content.split(" ")
let cmd = messageArray[0]
let args = messageArray.slice(1)
//Check for prefix
if(!cmd.startsWith(prefix)) return;
//Get the command from the commands collection and then if the command is found run the command file
const commandfile = bot.commands.get(cmd.slice(prefix.length));
if (commandfile) {
let commandArgs = {}
for (let i = 0; i < commandfile.config.cmdargs.length; i++) {
const argumentdata = commandfile.config.cmdargs[i];
if (!args[i] && argumentdata.required) {
return message.channel.send(`The argument ${argumentdata.name} (${argumentdata.type}) is required.`);
}
if (args[i]) {
if (argumentdata.type === 'string' && typeof args[i] === 'string') {
let parsedString = args.slice(i).join(" ");
commandArgs[argumentdata.name] = parsedString;
} else if (argumentdata.type === 'integer' && !isNaN(parseInt(args[i]))) {
const parsedInt = parseInt(args[i]);
commandArgs[argumentdata.name] = parsedInt;
} else if (argumentdata.type === 'userid') {
const userId = parseUserId(args[i]);
if (userId) {
commandArgs[argumentdata.name] = userId;
} else {
return message.channel.send(`The argument ${argumentdata.name} (${argumentdata.type}) must be a valid user ID or mention.`);
}
} else {
commandArgs[argumentdata.name] = args[i];
}
}
}
let userRnk = bot.modules.ranks.get(message.author.id)
console.log("userRnk",userRnk,commandfile.rnk)
if (userRnk >= commandfile.config.rnk) {
commandfile.run(bot, message, commandArgs);
} else {
message.channel.send('Insufficient permissions')
}
} else {
message.channel.send('No command was found.')
}
});
//Token
bot.login(process.env.TOKEN);