1 |
rakin |
77 |
#!/usr/bin/ts-node |
2 |
|
|
|
3 |
rakin |
344 |
import { registerCLICommands } from './utils/registry'; |
4 |
rakin |
77 |
import DiscordClient from './client/Client'; |
5 |
|
|
import { Intents } from 'discord.js'; |
6 |
|
|
import { config } from 'dotenv'; |
7 |
|
|
import { existsSync } from 'fs'; |
8 |
|
|
import path from 'path'; |
9 |
|
|
import { yellow } from './utils/util'; |
10 |
|
|
|
11 |
|
|
if (existsSync(path.join(__dirname, '../.env'))) { |
12 |
|
|
config(); |
13 |
|
|
} |
14 |
|
|
else { |
15 |
|
|
process.env.ENV = 'prod'; |
16 |
|
|
} |
17 |
|
|
|
18 |
|
|
if (process.argv.includes('--prod')) { |
19 |
|
|
console.warn(yellow('WARNING: Forcing production mode (--prod option passed)')); |
20 |
|
|
process.env.ENV = 'prod'; |
21 |
|
|
} |
22 |
|
|
|
23 |
|
|
if (process.argv.includes('--dev')) { |
24 |
|
|
console.warn(yellow('WARNING: Forcing development mode (--dev option passed)')); |
25 |
|
|
process.env.ENV = 'dev'; |
26 |
|
|
} |
27 |
|
|
|
28 |
|
|
const client = new DiscordClient({ |
29 |
|
|
partials: ["CHANNEL"], |
30 |
|
|
intents: [ |
31 |
|
|
Intents.FLAGS.GUILDS, |
32 |
|
|
Intents.FLAGS.GUILD_MESSAGES, |
33 |
|
|
Intents.FLAGS.DIRECT_MESSAGES, |
34 |
|
|
Intents.FLAGS.DIRECT_MESSAGE_TYPING, |
35 |
|
|
Intents.FLAGS.GUILD_PRESENCES, |
36 |
|
|
Intents.FLAGS.GUILD_MEMBERS, |
37 |
|
|
Intents.FLAGS.GUILD_BANS, |
38 |
|
|
Intents.FLAGS.GUILD_MESSAGE_REACTIONS, |
39 |
|
|
Intents.FLAGS.GUILD_EMOJIS_AND_STICKERS, |
40 |
|
|
] |
41 |
|
|
}, path.resolve(__dirname, '..')); |
42 |
|
|
|
43 |
|
|
client.on('ready', async () => { |
44 |
|
|
console.log('The system has logged into discord.'); |
45 |
|
|
await registerCLICommands(client, '../cli-commands'); |
46 |
|
|
|
47 |
|
|
const { argv, exit } = process; |
48 |
|
|
|
49 |
|
|
argv.shift(); |
50 |
|
|
argv.shift(); |
51 |
|
|
|
52 |
|
|
if (!argv[0]) { |
53 |
|
|
console.log('No command provided.'); |
54 |
|
|
exit(-1); |
55 |
|
|
} |
56 |
|
|
|
57 |
|
|
const commandName = argv.shift(); |
58 |
|
|
const command = client.cliCommands.get(commandName!); |
59 |
|
|
|
60 |
|
|
if (!command) { |
61 |
|
|
console.log(`${commandName}: command not found`); |
62 |
|
|
exit(-1); |
63 |
|
|
} |
64 |
|
|
|
65 |
|
|
const options = argv.filter(a => a[0] === '-'); |
66 |
|
|
const args = argv.filter(a => a[0] !== '-'); |
67 |
|
|
|
68 |
|
|
if (command!.requiredArgs > args.length) { |
69 |
|
|
console.log(`${commandName}: expected at least ${command!.requiredArgs} arguments`); |
70 |
|
|
exit(-1); |
71 |
|
|
} |
72 |
|
|
|
73 |
|
|
if (command!.requiredOptions > options.length) { |
74 |
|
|
console.log(`${commandName}: expected at least ${command!.requiredOptions} options`); |
75 |
|
|
exit(-1); |
76 |
|
|
} |
77 |
|
|
|
78 |
|
|
await command!.run(client, argv, args, options); |
79 |
|
|
}); |
80 |
|
|
|
81 |
|
|
client.login(process.env.TOKEN); |