2022-02-05 15:59:45 +01:00
|
|
|
import * as Revolt from "@janderedev/revolt.js";
|
2021-10-08 23:36:46 +02:00
|
|
|
import { IMonkManager } from 'monk';
|
|
|
|
import logger from '../bot/logger';
|
2022-01-04 15:14:46 +01:00
|
|
|
import { adminBotLog } from "../bot/logging";
|
2021-10-08 23:36:46 +02:00
|
|
|
|
|
|
|
class AutomodClient extends Revolt.Client {
|
|
|
|
db: IMonkManager;
|
|
|
|
|
|
|
|
constructor(options: Partial<Revolt.ClientOptions> | undefined, monk: IMonkManager) {
|
|
|
|
super(options);
|
|
|
|
|
|
|
|
this.db = monk;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let login = (client: Revolt.Client): Promise<void> => new Promise((resolve, reject) => {
|
2021-12-05 15:18:12 +01:00
|
|
|
logger.info('Bot logging in...');
|
2021-10-08 23:36:46 +02:00
|
|
|
let env = process.env;
|
|
|
|
|
|
|
|
if (!env['BOT_TOKEN']) {
|
|
|
|
logger.error('Environment variable \'BOT_TOKEN\' not provided');
|
|
|
|
return reject('No bot token provided');
|
|
|
|
}
|
|
|
|
|
|
|
|
client.loginBot(env['BOT_TOKEN']);
|
|
|
|
|
|
|
|
client.once('ready', () => {
|
2022-01-03 15:44:19 +01:00
|
|
|
logger.done(`Bot logged in as ${client.user?.username}!`);
|
2022-01-04 15:14:46 +01:00
|
|
|
adminBotLog({ message: 'Bot logged in', type: 'INFO' });
|
2021-10-08 23:36:46 +02:00
|
|
|
resolve();
|
|
|
|
});
|
2022-04-30 15:57:37 +02:00
|
|
|
|
|
|
|
client.on('packet', packet => {
|
|
|
|
if (packet.type == 'InvalidSession' as any) {
|
|
|
|
logger.error('Authentication failed: ' + JSON.stringify(packet));
|
|
|
|
process.exit(99);
|
|
|
|
}
|
|
|
|
});
|
2021-10-08 23:36:46 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
export default AutomodClient;
|
|
|
|
export { login }
|