community-relations/src/commands/stats.ts

37 lines
1.4 KiB
TypeScript
Raw Normal View History

2020-07-21 04:12:56 -04:00
import { Message } from 'eris';
import { Client, Command, RichEmbed } from '../class';
export default class Stats extends Command {
constructor(client: Client) {
super(client);
this.name = 'stats';
this.description = 'Provides system statistics.';
this.usage = `${this.client.config.prefix}stats`;
this.permissions = 0;
this.guildOnly = false;
this.enabled = true;
}
public async run(message: Message) {
try {
const messages = await this.client.db.Stat.findOne({ name: 'messages' });
const commands = await this.client.db.Stat.findOne({ name: 'commands' });
const pages = await this.client.db.Stat.findOne({ name: 'pages' });
const requests = await this.client.db.Stat.findOne({ name: 'requests' });
const embed = new RichEmbed();
embed.setTitle('Statistics');
embed.setThumbnail(this.client.user.avatarURL);
embed.addField('Messages Seen', `${messages.value}`, true);
2020-07-21 04:18:38 -04:00
embed.addField('Commands Executed', `${commands.value}`, true);
2020-07-21 04:12:56 -04:00
embed.addField('HTTP Requests Served', `${requests.value}`, true);
embed.addField('Pages Sent', `${pages.value}`, true);
embed.setFooter(this.client.user.username, this.client.user.avatarURL);
embed.setTimestamp();
return message.channel.createMessage({ embed });
} catch (err) {
return this.client.util.handleError(err, message, this);
}
}
}