Skip to content

Commit

Permalink
feat(console): Use chalk for colors
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco Crespi committed Mar 26, 2020
1 parent 00edc32 commit 6a6135a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 20 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"amqplib": "0.5.5",
"axios": "0.19.2",
"bufferutil": "4.0.1",
"chalk": "3.0.0",
"chart.js": "2.9.3",
"chartjs-node": "1.7.1",
"chartjs-plugin-datalabels": "0.7.0",
Expand Down
29 changes: 17 additions & 12 deletions src/bot.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { configureScope, init } from '@sentry/node';
import chalk from 'chalk';

import { IMClient } from './client';

Expand Down Expand Up @@ -39,9 +40,13 @@ process.on('unhandledRejection', (reason: any, p: any) => {
});

const main = async () => {
console.log('-------------------------------------');
console.log(`This is shard ${shardId}/${shardCount} of ${type} instance ${instance}`);
console.log('-------------------------------------');
console.log(chalk.green('-------------------------------------'));
console.log(
chalk.green(
`This is shard ${chalk.blue(`${shardId}/${shardCount}`)} of ${chalk.blue(type)} instance ${chalk.blue(instance)}`
)
);
console.log(chalk.green('-------------------------------------'));

const client = new IMClient({
version: pkg.version,
Expand All @@ -54,21 +59,21 @@ const main = async () => {
config
});

console.log('-------------------------------------');
console.log('Starting bot...');
console.log('-------------------------------------');
console.log(chalk.green('-------------------------------------'));
console.log(chalk.green('Starting bot...'));
console.log(chalk.green('-------------------------------------'));

await client.init();

console.log('-------------------------------------');
console.log('Waiting for start ticket...');
console.log('-------------------------------------');
console.log(chalk.green('-------------------------------------'));
console.log(chalk.green('Waiting for start ticket...'));
console.log(chalk.green('-------------------------------------'));

await client.waitForStartupTicket();

console.log('-------------------------------------');
console.log('Connecting to discord...');
console.log('-------------------------------------');
console.log(chalk.green('-------------------------------------'));
console.log(chalk.green('Connecting to discord...'));
console.log(chalk.green('-------------------------------------'));
await client.connect();
};

Expand Down
8 changes: 4 additions & 4 deletions src/client.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import chalk from 'chalk';
import { Client, Embed, Guild, Member, Message, TextChannel } from 'eris';
import i18n from 'i18n';
import moment, { Moment } from 'moment';
Expand Down Expand Up @@ -246,7 +247,7 @@ export class IMClient extends Client {
public async waitForStartupTicket() {
const start = process.uptime();
const interval = setInterval(
() => console.log(`Waiting for ticket since ${Math.floor(process.uptime() - start)} seconds...`),
() => console.log(`Waiting for ticket since ${chalk.blue(Math.floor(process.uptime() - start))} seconds...`),
10000
);
await this.service.rabbitmq.waitForStartupTicket();
Expand All @@ -268,8 +269,7 @@ export class IMClient extends Client {
const set = await this.db.getBotSettings(this.user.id);
this.settings = set ? set.value : { ...botDefaultSettings };

console.log(`Client ready! Serving ${this.guilds.size} guilds.`);
console.log(`This is the ${this.type} version of the bot.`);
console.log(chalk.green(`Client ready! Serving ${chalk.blue(this.guilds.size)} guilds.`));

// Init all caches
await Promise.all(Object.values(this.cache).map((c) => c.init()));
Expand Down Expand Up @@ -367,7 +367,7 @@ export class IMClient extends Client {
public serviceStartupDone(service: IMService) {
this.startingServices = this.startingServices.filter((s) => s !== service);
if (this.startingServices.length === 0) {
console.log(`All services ready, returning start ticket`);
console.log(chalk.green(`All services ready`));
this.rabbitmq.endStartup().catch((err) => console.error(err));
}
}
Expand Down
3 changes: 2 additions & 1 deletion src/framework/services/Scheduler.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { captureException, withScope } from '@sentry/node';
import chalk from 'chalk';
import { Guild } from 'eris';
import moment from 'moment';

Expand Down Expand Up @@ -85,7 +86,7 @@ export class SchedulerService extends IMService {
private async scheduleScheduledActions() {
let actions = await this.client.db.getScheduledActionsForGuilds(this.client.guilds.map((g) => g.id));
actions = actions.filter((a) => a.date !== null);
console.log(`Scheduling ${actions.length} actions from db`);
console.log(`Scheduling ${chalk.blue(actions.length)} actions from db`);
actions.forEach((action) => this.createTimer(action));
}

Expand Down
7 changes: 4 additions & 3 deletions src/invites/services/Tracking.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import chalk from 'chalk';
import { AnyChannel, Guild, GuildAuditLog, GuildChannel, Invite, Member, Role, TextChannel } from 'eris';
import i18n from 'i18n';
import moment from 'moment';
Expand Down Expand Up @@ -81,17 +82,17 @@ export class TrackingService extends IMService {
console.error(err);
}

console.log('Updated invite count for ' + guild.name);
console.log(`Updated invite count for ${chalk.blue(guild.name)}`);
}

this.pendingGuilds.delete(guild.id);
if (this.pendingGuilds.size % 50 === 0) {
console.log(`Pending: ${this.pendingGuilds.size}/${this.initialPendingGuilds}`);
console.log(`Pending: ${chalk.blue(`${this.pendingGuilds.size}/${this.initialPendingGuilds}`)}`);
await this.client.rabbitmq.sendStatusToManager();
}

if (this.pendingGuilds.size === 0) {
console.log(`\x1b[32mLoaded all pending guilds!\x1b[0m`);
console.log(chalk.green(`Loaded all pending guilds!`));
this.startupDone();
}

Expand Down

0 comments on commit 6a6135a

Please sign in to comment.