/[sudobot]/branches/2.x/src/cli.ts
ViewVC logotype

Contents of /branches/2.x/src/cli.ts

Parent Directory Parent Directory | Revision Log Revision Log


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

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26