Skip to content

Commit

Permalink
Merge pull request #24 from Antares-Network/development
Browse files Browse the repository at this point in the history
Update a few commands
  • Loading branch information
nathen418 authored Feb 9, 2021
2 parents a8b1a1c + a465a25 commit d085f61
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 0 deletions.
3 changes: 3 additions & 0 deletions actions/logToConsole.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@ module.exports = {
},
message: function (guild, message) {
console.log(`MESSAGE`.magenta, `[${guild.name}]`.green, `[${message.channel.name}]`.blue, `[${message.author.username}]`.yellow, `--`.grey, `${message.content}`.cyan)
},
dm: function (message) {
console.log(`DM`.blue, `[${message.author.username}]`.yellow, `--`.grey, `${message.content}`.cyan)
}
}
59 changes: 59 additions & 0 deletions commands/owner/update.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
const { Command } = require('discord.js-commando');
const gateModel = require('../../models/gate');
const guildModel = require('../../models/guild');
const logToConsole = require('../../actions/logToConsole');



module.exports = class UpdateCommand extends Command {
constructor(client) {
super(client, {
name: 'update',
group: 'owner',
memberName: 'update',
description: 'Update all the databases',
examples: ['update'],
guildOnly: true
});
}

//check to make sure the bot owner is the one running the show
hasPermission(msg) {
return this.client.isOwner(msg.author);
}


async run(message) {
//var init and gc
var totalUsers = 0;
var totalMessages = 0;
var totalOwners = [];

//get data from all the guilds
bot.guilds.cache.forEach(async guild => {
const doc = await guildModel.findOne({ GUILD_ID: guild.id }); //find the doc that has all the guild information in it
totalMessages += Number(doc.GUILD_MESSAGES);
totalOwners.push(guild.ownerID);
totalUsers += guild.memberCount
});

setTimeout(async () => {
await gateModel.findOneAndUpdate({ NAME: 'GATE' }, {
$set: {
GUILD_OWNER_ID: totalOwners,
TOTAL_MESSAGES: totalMessages,
TOTAL_SERVERS: bot.guilds.cache.size,
TOTAL_USERS: totalUsers
}
}, { new: true });
}, 5000);


try {
logToConsole.command(message.guild, message);
} catch (e) {
logToConsole.dm(message);

}
}
}

0 comments on commit d085f61

Please sign in to comment.