-
Notifications
You must be signed in to change notification settings - Fork 7
/
app.js
94 lines (78 loc) · 2.83 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
import 'dotenv/config';
import process from 'node:process';
import { URL } from 'node:url';
import sqlite3 from 'sqlite3';
import * as sqlite from 'sqlite';
import { GatewayIntentBits } from 'discord.js';
import { EClient, ECommandHandler, SQLiteProvider } from './lib/index.js';
// Make this independent of cwd
import { BotConfig } from './config/config.js';
import * as modules from './modules/index.js';
import { registerEvents } from './events/event.js';
if (process.getuid?.() === 0) {
console.warn('====================================');
console.warn('====================================');
console.warn('=====DO NOT RUN THE BOT AS ROOT=====');
console.warn('====================================');
console.warn('====================================');
}
class Client extends EClient {
constructor() {
super(
{
ownerIDs: process.env.BOT_OWNER?.split?.(',') ?? BotConfig.OWNERS,
config: { TOKEN: '', ...BotConfig }
},
{
// disableMentions: 'everyone',
allowedMentions: { parse: ['users', 'roles'] },
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.GuildModeration,
GatewayIntentBits.MessageContent,
// Intents.FLAGS.GUILD_INTEGRATIONS,
// Intents.FLAGS.GUILD_WEBHOOKS,
// Intents.FLAGS.GUILD_INVITES,
// Intents.FLAGS.GUILD_VOICE_STATES,
// Intents.FLAGS.GUILD_PRESENCES,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMessageReactions,
// Intents.FLAGS.GUILD_MESSAGE_TYPING,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.DirectMessageReactions,
// Intents.FLAGS.DIRECT_MESSAGE_TYPING
]
}
);
this.commandHandler = new ECommandHandler(this, {
prefix: process.env.BOT_PREFIX || BotConfig.PREFIX || ';',
path: new URL('commands', import.meta.url).pathname,
testGuild: process.env.TEST_GUILD,
enableSlashCommands: Boolean(Number(process.env?.ENABLE_SLASH_COMMANDS ?? BotConfig.ENABLE_SLASH_COMMANDS)),
});
}
}
const client = new Client();
// Load default path commands
await client.commandHandler.loadModules();
// Init DB
const db = await sqlite.open({
filename: new URL('./data/settings.sqlite3', import.meta.url).pathname,
driver: sqlite3.Database
});
// Load modules
await modules.init(client, db);
// Set provider
await client.setProvider(new SQLiteProvider(db));
console.log(`Loaded ${client.commandHandler.commands.size} commands`);
// Register EventEmitter events
await registerEvents(client);
await client.login(process.env.BOT_TOKEN || BotConfig.TOKEN).catch(err => {
console.error('Failed to log in', err);
process.exit(1);
});
// Just in case, I guess
process.on('unhandledRejection', (reason, promise) => {
console.log('Unhandled Rejection at:', promise, 'reason:', reason);
});