Skip to content

Commit

Permalink
More changes
Browse files Browse the repository at this point in the history
  • Loading branch information
boomermath committed Oct 7, 2021
1 parent 5e2fd1f commit f519378
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 51 deletions.
86 changes: 42 additions & 44 deletions lib/util/Console.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,46 @@ import { Console } from "console";
import { inspect } from "util";

export default class BopConsole extends Console {
constructor() {
super(process.stdout, process.stderr);
}

get timestamp(): string {
return new Date().toLocaleTimeString();
}

public log(message: unknown): void {
this.write(message, ["inverse"]);
}

public success(message: unknown): void {
this.write(message, ["bgGreen", "bold"]);
}

public error(message: unknown): void {
this.write(message, ["red", "underline"]);
}

public info(message: unknown): void {
this.write(message, ["bgBlue", "dim"]);
}

private write(message: unknown, colors: string[], type?: string): void {
const flattened = this._flatten(message);
const colorsTemplate = colors.join(".");
super[type === "error" ? "error" : "log"](
chalk`{${colorsTemplate} ${flattened} | ${this.timestamp}}`
);
}

private _flatten(message: unknown): string {
if (message instanceof Error) {
return message.stack ?? message.name;
} else if (Array.isArray(message)) {
return message.every((entry) => typeof entry === "string")
? message.join("\n")
: message.map((e) => inspect(e)).join("\n");
} else if (typeof message === "object") {
return inspect(message);
}
return String(message);
}
constructor() {
super(process.stdout, process.stderr);
}

get timestamp(): string {
return new Date().toLocaleTimeString();
}

public log(message: unknown): void {
this.write(message, ["inverse"]);
}

public success(message: unknown): void {
this.write(message, ["bgGreen", "bold"]);
}

public error(message: unknown): void {
this.write(message, ["red", "underline"]);
}

public info(message: unknown): void {
this.write(message, ["bgBlue", "dim"]);
}

private write(message: unknown, colors: string[], type?: string): void {
const flattened = this._flatten(message);
const colorsTemplate = colors.join(".");
super[type === "error" ? "error" : "log"](
chalk`{${colorsTemplate} ${flattened} | ${this.timestamp}}`
);
}

private _flatten(message: unknown): string {
if (Array.isArray(message)) {
return message.every((entry) => typeof entry === "string")
? message.join("\n")
: message.map((e) => inspect(e)).join("\n");
} else if (typeof message === "object") {
return inspect(message);
}
return String(message);
}
}
12 changes: 6 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions src/commands/clear.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import { Message } from "discord.js";
import BopClient from "../../lib/Client";
import { Command } from "../../lib/Modules";
import { Notification } from "../../lib/util/Embeds";

export default class extends Command {
public constructor(client: BopClient, directory: string) {
super(client, directory, {
name: "clear",
description: "Leave the voice channel.",
aliases: ["c", "clean", "clearqueue", "cq"],
cooldown: 1,
});
}

public async main(message: Message): Promise<void> {
const queue = this.client.player.getQueue(message.guild!);
queue.clear();
message.channel.send({ embeds: [new Notification("Queue cleared!")] });
}
}
2 changes: 1 addition & 1 deletion src/events/player/error.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default class BotDisconnectEvent extends Event {
this.client.console.error(error);

if (error.message.includes("403")) return;

this.client.player.deleteQueue(queue.guild);

queue.metadata?.channel.send({
Expand Down

0 comments on commit f519378

Please sign in to comment.