aboutsummaryrefslogtreecommitdiff
path: root/src/lib/utils/Logger.ts
diff options
context:
space:
mode:
authorTymanWasTaken <tyman@tyman.tech>2021-05-16 20:30:34 -0400
committerTymanWasTaken <tyman@tyman.tech>2021-05-16 20:30:34 -0400
commit372718e567e060cead16dde5d6d190666b4dd575 (patch)
tree1fad29305b6277838833a7e8ae4381136212f301 /src/lib/utils/Logger.ts
parent1db014860c3cf6070bb29f75b6a8cf08070e5b9a (diff)
downloadtanzanite-372718e567e060cead16dde5d6d190666b4dd575.tar.gz
tanzanite-372718e567e060cead16dde5d6d190666b4dd575.tar.bz2
tanzanite-372718e567e060cead16dde5d6d190666b4dd575.zip
add colored logging and improved logging code, fix a few moderation command issues, add more logging, and make ban check run every 30s not 60s
Diffstat (limited to 'src/lib/utils/Logger.ts')
-rw-r--r--src/lib/utils/Logger.ts44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/lib/utils/Logger.ts b/src/lib/utils/Logger.ts
new file mode 100644
index 0000000..455ba36
--- /dev/null
+++ b/src/lib/utils/Logger.ts
@@ -0,0 +1,44 @@
+import { TextChannel } from 'discord.js';
+import { BotClient } from '../extensions/BotClient';
+import chalk from 'chalk';
+
+export class Logger {
+ private client: BotClient;
+ public constructor(client: BotClient) {
+ this.client = client;
+ }
+ private stripColor(text: string): string {
+ return text.replace(
+ // eslint-disable-next-line no-control-regex
+ /[\u001b\u009b][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nqry=><]/g,
+ ''
+ );
+ }
+ public getChannel(channel: 'log' | 'error' | 'dm'): Promise<TextChannel> {
+ return this.client.channels.fetch(
+ this.client.config.channels[channel]
+ ) as Promise<TextChannel>;
+ }
+ public async log(message: string, sendChannel = false): Promise<void> {
+ console.log(chalk`{bgCyan LOG} ` + message);
+ if (sendChannel) {
+ const channel = await this.getChannel('log');
+ await channel.send('[LOG] ' + this.stripColor(message));
+ }
+ }
+ public async verbose(message: string, sendChannel = false): Promise<void> {
+ if (!this.client.config.verbose) return;
+ console.log(chalk`{bgMagenta VERBOSE} ` + message);
+ if (sendChannel) {
+ const channel = await this.getChannel('log');
+ await channel.send('[VERBOSE] ' + this.stripColor(message));
+ }
+ }
+ public async error(message: string, sendChannel = false): Promise<void> {
+ console.log(chalk`{bgRed ERROR} ` + message);
+ if (sendChannel) {
+ const channel = await this.getChannel('error');
+ await channel.send('[ERROR] ' + this.stripColor(message));
+ }
+ }
+}