add basic logging
This commit is contained in:
parent
648fe39fe6
commit
e718827432
2 changed files with 44 additions and 0 deletions
42
src/bot/logging.ts
Normal file
42
src/bot/logging.ts
Normal file
|
@ -0,0 +1,42 @@
|
|||
import { ColorResolvable, MessageEmbed, WebhookClient } from "discord.js";
|
||||
import logger from "./logger";
|
||||
import { client as bot } from '../index'
|
||||
|
||||
let client: WebhookClient|undefined;
|
||||
|
||||
if (process.env.LOG_WEBHOOK) {
|
||||
try {
|
||||
client = new WebhookClient({ url: process.env.LOG_WEBHOOK });
|
||||
} catch(e) {
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
|
||||
async function adminBotLog(data: { message: string, type: 'INFO'|'WARN'|'ERROR' }) {
|
||||
logger.info(`[${data.type}] Admin log: ${data.message}`);
|
||||
try {
|
||||
let color: ColorResolvable = '#ffffff';
|
||||
switch(data.type) {
|
||||
case 'INFO': color = '#00ff73'; break;
|
||||
case 'WARN': color = '#ffc823'; break;
|
||||
case 'ERROR': color = '#ff4208'; break;
|
||||
}
|
||||
|
||||
let embed = new MessageEmbed()
|
||||
.setDescription(data.message)
|
||||
.setColor(color);
|
||||
|
||||
await client?.send({
|
||||
embeds: [ embed ],
|
||||
username: bot.user?.username,
|
||||
avatarURL: bot.user?.generateAvatarURL({ size: 128 })
|
||||
});
|
||||
} catch(e) {
|
||||
logger.error(`Failed to log: ${e}`);
|
||||
}
|
||||
}
|
||||
|
||||
export {
|
||||
client,
|
||||
adminBotLog,
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
import * as Revolt from "@janderedev/revolt.js";
|
||||
import { IMonkManager } from 'monk';
|
||||
import logger from '../bot/logger';
|
||||
import { adminBotLog } from "../bot/logging";
|
||||
|
||||
class AutomodClient extends Revolt.Client {
|
||||
db: IMonkManager;
|
||||
|
@ -25,6 +26,7 @@ let login = (client: Revolt.Client): Promise<void> => new Promise((resolve, reje
|
|||
|
||||
client.once('ready', () => {
|
||||
logger.done(`Bot logged in as ${client.user?.username}!`);
|
||||
adminBotLog({ message: 'Bot logged in', type: 'INFO' });
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in a new issue