-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
161 lines (128 loc) · 4.44 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
// Import necessary modules
const { Client, Intents, GatewayIntentBits } = require('discord.js');
const mongoose = require('mongoose');
const config = require('./config');
const GuildSettings = require('./models/settings');
const Command = require('./models/Command');
const Dashboard = require('./dashboard/dashboard');
const fs = require('fs');
const path = require('path');
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.MessageContent,
GatewayIntentBits.GuildMembers,
],
});
mongoose.connect(config.mongodbUrl, {
useNewUrlParser: true,
useUnifiedTopology: true,
});
client.config = config;
client.commands = new Map();
const loadCommands = require('./functions/commandloader');
client.once('ready', async () => {
try {
console.log('Bot is ready!');
console.log('Fetching members...');
await loadCommands(client, './commands');
console.log('Commands loaded successfully.');
client.user.setActivity(
'https://github.com/hotsu0p/chaotic',
{ type: 'WATCHING' },
);
Dashboard(client);
console.log('Dashboard initialized.');
} catch (error) {
console.error('Error during client ready:', error);
}
});
/* const { exec } = require('child_process');
const { EmbedBuilder } = require('discord.js');
const pythonScriptPath = './monitor.py';
const userTag = 'hotsu0p';
const command = `python ${pythonScriptPath} ${userTag} `;
const childProcess = exec(command, (error, stdout, stderr) => {
if (error) {
console.error(`Error executing Python script: ${error.message}`);
return;
}
});
const */customCommandsModel = require('./models/CustomCommands');
client.on('messageCreate', async (message) => {
if (message.guild) {
const guildId = message.guild.id;
const messageContent = message.content;
const command = await customCommandsModel.findOne({ guildId, trigger: messageContent });
if (command) {
message.channel.send(command.content);
} else {
return;
}
}
});
client.on('guildMemberRemove', async (member) => {
try {
const guildId = member.guild.id;
const guildSettings = await GuildSettings.findOne({ guildId });
const footer = guildSettings.footer;
if (!guildSettings || !guildSettings.leaveChannel) {
console.error(`Leave channel not configured for guild ID ${guildId}`);
return;
}
const leaveChannel = member.guild.channels.cache.get(guildSettings.leaveChannel);
if (!leaveChannel) {
console.error(`Leave channel not found for guild ID ${guildId} with ID ${guildSettings.leaveChannel}`);
return;
}
const embed = new EmbedBuilder()
.setFooter({ text: `${footer}`,})
.setDescription(`Goodbye, ${member.user.tag}! We'll miss you.`);
// Send a farewell message to the leave channel
leaveChannel.send({ embeds: [embed.toJSON()], });
} catch (error) {
console.error('Error handling guildMemberRemove event:', error);
}
});
client.on('messageCreate', async (message) => {
try {
let storedSettings = await GuildSettings.findOne({
guildID: message.guild.id,
});
if (!storedSettings) {
const newSettings = new GuildSettings({
guildID: message.guild.id,
});
await newSettings.save();
storedSettings = newSettings;
}
if (!message.content.startsWith(storedSettings.prefix)) return;
const args = message.content.slice(storedSettings.prefix.length).trim().split(/ +/g);
const guild = message.guild
const commandName = args.shift().toLowerCase();
let command = client.commands.get(commandName);
// If the command was not found by name, try to find it by alias
if (!command) {
for (const [name, cmd] of client.commands.entries()) {
if (cmd.aliases && cmd.aliases.includes(commandName)) {
command = cmd;
break;
}
}
}
if (command) {
if (typeof command.execute === 'function') {
command.execute(message, args, guild);
} else {
console.error(`Command ${command.name} is missing the execute method.`);
}
}
} catch (error) {
console.error('Error during message event:', error);
}
});
const prefix = '!'; // Change this to your desired command prefix
client.on('error', console.error);
client.on('warn', console.warn);
client.login(config.token);