Haha-Yes/commands/utility/ping.js

40 lines
1.3 KiB
JavaScript
Raw Normal View History

2018-10-09 16:31:23 +02:00
const { oneLine } = require('common-tags');
const { Command } = require('discord.js-commando');
2018-11-28 01:35:26 +01:00
const SelfReloadJSON = require('self-reload-json');
2018-12-05 00:52:21 +01:00
2018-10-09 16:31:23 +02:00
module.exports = class PingCommand extends Command {
constructor(client) {
super(client, {
name: 'ping',
group: 'util',
memberName: 'ping',
description: 'Checks the bot\'s ping to the Discord server.',
throttling: {
usages: 5,
duration: 10
}
});
}
2018-11-28 01:35:26 +01:00
async run(message) {
2018-12-06 23:01:40 +01:00
let blacklistJson = new SelfReloadJSON('./json/blacklist.json');
2018-11-28 01:35:26 +01:00
if(blacklistJson[message.author.id])
return blacklist(blacklistJson[message.author.id] , message)
if(!message.editable) {
const pingMsg = await message.say('Pinging...');
2018-10-09 16:31:23 +02:00
return pingMsg.edit(oneLine`
2018-11-28 01:35:26 +01:00
${message.channel.type !== 'dm' ? `${message.author},` : ''}
<:ping:499226870047571978> Pong! The message round-trip took **${pingMsg.createdTimestamp - message.createdTimestamp}**ms.
2018-10-09 16:31:23 +02:00
${this.client.ping ? `The heartbeat ping is **${Math.round(this.client.ping)}**ms.` : ''}
`);
} else {
2018-11-28 01:35:26 +01:00
await message.edit('Pinging...');
return message.edit(oneLine`
Pong! The message round-trip took **${message.editedTimestamp - message.createdTimestamp}**ms.
2018-10-09 16:31:23 +02:00
${this.client.ping ? `The heartbeat ping is **${Math.round(this.client.ping)}**ms.` : ''}
`);
}
}
};