2019-03-31 19:17:50 +02:00
|
|
|
const { Listener } = require('discord-akairo');
|
2020-04-01 04:36:17 +02:00
|
|
|
const { dailyStats } = require('../../config.json');
|
2020-05-30 17:48:52 +02:00
|
|
|
let serverID = require('../../json/serverID.json');
|
2020-04-01 04:36:17 +02:00
|
|
|
let report = [];
|
|
|
|
let time = new Date();
|
2019-03-31 19:17:50 +02:00
|
|
|
|
|
|
|
class commandStartedListener extends Listener {
|
|
|
|
constructor() {
|
|
|
|
super('commandStarted', {
|
|
|
|
emitter: 'commandHandler',
|
|
|
|
event: 'commandStarted'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-04-01 04:36:17 +02:00
|
|
|
async exec(message, command) {
|
2019-03-31 17:31:47 +02:00
|
|
|
//This is for april fools
|
2020-04-01 04:36:17 +02:00
|
|
|
let today = new Date(), lastUpdate;
|
2020-05-30 17:48:52 +02:00
|
|
|
|
2019-03-31 17:31:47 +02:00
|
|
|
let dd = today.getDate();
|
|
|
|
let mm = today.getMonth() + 1; //January is 0!
|
2020-04-01 04:36:17 +02:00
|
|
|
|
2019-03-31 17:31:47 +02:00
|
|
|
if (dd < 10) {
|
|
|
|
dd = '0' + dd;
|
2020-05-30 17:48:52 +02:00
|
|
|
}
|
2019-03-31 17:31:47 +02:00
|
|
|
if (mm < 10) {
|
|
|
|
mm = '0' + mm;
|
2020-05-30 17:48:52 +02:00
|
|
|
}
|
2020-04-01 04:36:17 +02:00
|
|
|
let curDate = dd + '.' + mm;
|
2019-03-31 17:31:47 +02:00
|
|
|
//Only execute when its april first
|
2020-05-03 22:41:54 +02:00
|
|
|
if (curDate === '01.04' && !serverID.includes(message.guild.id)) {
|
2019-03-31 17:31:47 +02:00
|
|
|
let count = Math.random() * 100;
|
2019-04-01 00:06:34 +02:00
|
|
|
if (count < 10) {
|
2020-03-02 16:06:15 +01:00
|
|
|
serverID.push(message.guild.id);
|
2020-04-01 03:13:45 +02:00
|
|
|
|
|
|
|
const channel = this.client.channels.resolve('694715943372193803'); // Too lazy to make entry for it
|
|
|
|
channel.send(`${message.guild.name} (${message.guild.id}) got april fool triggered! hueheheh owned`);
|
|
|
|
|
2019-03-31 20:41:19 +02:00
|
|
|
this.client.user.setActivity('people buy haha yes gold™', { type: 'WATCHING' });
|
2020-03-02 14:40:09 +01:00
|
|
|
let Embed = this.client.util.embed()
|
2020-03-22 21:54:19 +01:00
|
|
|
.setColor(message.member ? message.member.displayHexColor : 'NAVY')
|
2020-03-02 14:40:09 +01:00
|
|
|
.setTitle('Haha yes **gold**')
|
2021-03-31 18:32:51 +02:00
|
|
|
.setDescription('To further utilize this command, please visit https://gold.namejeff.xyz/')
|
2020-03-02 14:40:09 +01:00
|
|
|
.attachFiles(['./asset/img/gold.png'])
|
|
|
|
.setImage('attachment://gold.png')
|
|
|
|
.setFooter('This is an april fool\'s joke, no command will EVER be behind a paywall');
|
|
|
|
|
2020-04-01 04:36:17 +02:00
|
|
|
message.channel.send(Embed);
|
2019-03-31 17:31:47 +02:00
|
|
|
}
|
2019-03-31 19:17:50 +02:00
|
|
|
}
|
2020-04-01 04:36:17 +02:00
|
|
|
|
|
|
|
if (dailyStats) {
|
2020-05-03 22:41:54 +02:00
|
|
|
if (command.category.id === 'owner') return; // Don't count owner command
|
2020-04-01 04:36:17 +02:00
|
|
|
let obj = {
|
|
|
|
command: command.id
|
|
|
|
};
|
2020-05-30 17:48:52 +02:00
|
|
|
|
2020-09-04 18:47:39 +02:00
|
|
|
if (message.guild) obj.guild = message.guild.id;
|
|
|
|
|
2020-04-01 04:36:17 +02:00
|
|
|
report.push(obj);
|
2020-05-30 17:48:52 +02:00
|
|
|
|
2020-04-01 04:36:17 +02:00
|
|
|
let uniqueGuild = [];
|
|
|
|
let commands = {};
|
2020-04-02 19:12:46 +02:00
|
|
|
let executedCommands = 0;
|
2020-05-30 17:48:52 +02:00
|
|
|
|
2020-04-01 04:36:17 +02:00
|
|
|
report.forEach(e => {
|
|
|
|
if (!uniqueGuild.includes(e.guild)) {
|
|
|
|
uniqueGuild.push(e.guild);
|
|
|
|
}
|
2020-05-30 17:48:52 +02:00
|
|
|
|
2020-04-01 04:36:17 +02:00
|
|
|
if (!commands[e.command]) {
|
|
|
|
commands[e.command] = 1;
|
|
|
|
} else {
|
|
|
|
commands[e.command] = commands[e.command] + 1;
|
|
|
|
}
|
2020-04-02 19:12:46 +02:00
|
|
|
|
|
|
|
executedCommands++;
|
2020-05-30 17:48:52 +02:00
|
|
|
|
2020-04-01 04:36:17 +02:00
|
|
|
});
|
2020-05-30 17:48:52 +02:00
|
|
|
|
2020-04-01 04:36:17 +02:00
|
|
|
if ( !lastUpdate || ( today.getTime() - lastUpdate.getTime() ) > 30000 ) {
|
|
|
|
// Set the last time we checked, and then check if the date has changed.
|
|
|
|
lastUpdate = today;
|
|
|
|
if ( time.getDate() !== today.getDate() ) {
|
|
|
|
// If the date has changed, set the date to the new date, and refresh stuff.
|
|
|
|
time = today;
|
2020-05-30 17:48:52 +02:00
|
|
|
|
2020-04-01 04:36:17 +02:00
|
|
|
let arr = Object.values(commands);
|
|
|
|
let max = Math.max(...arr);
|
|
|
|
let min = Math.min(...arr);
|
2020-05-30 17:48:52 +02:00
|
|
|
|
2020-04-01 04:36:17 +02:00
|
|
|
let Embed = this.client.util.embed()
|
|
|
|
.setColor('GREEN')
|
|
|
|
.setTitle('Daily usage report!')
|
|
|
|
.addField('Number of unique guild', uniqueGuild.length)
|
2020-05-30 17:48:52 +02:00
|
|
|
.addField('Number of command executed', executedCommands, true)
|
2020-07-11 01:25:19 +02:00
|
|
|
.addField('Last used command', command.id, true)
|
2020-04-01 04:36:17 +02:00
|
|
|
.addField('Most used command', `${getKeyByValue(commands, max)} (${max} times)`, true )
|
|
|
|
.addField('Least used command', `${getKeyByValue(commands, min)} (${min} times)`, true)
|
|
|
|
.setFooter(`Bot usage as of ${today}`);
|
2020-05-30 17:48:52 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
2020-04-02 19:12:46 +02:00
|
|
|
const channel = this.client.channels.resolve(dailyStats);
|
2020-04-01 04:36:17 +02:00
|
|
|
channel.send(Embed);
|
2020-04-02 19:12:46 +02:00
|
|
|
|
2020-04-01 04:36:17 +02:00
|
|
|
uniqueGuild = [];
|
|
|
|
commands = {};
|
|
|
|
report = [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getKeyByValue(object, value) {
|
|
|
|
return Object.keys(object).find(key => object[key] === value);
|
|
|
|
}
|
|
|
|
|
2019-03-31 19:17:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-05-30 17:48:52 +02:00
|
|
|
module.exports = commandStartedListener;
|