Skip to content

Commit

Permalink
Fixed bugs with latest commit (unreferenced variables and so forth)
Browse files Browse the repository at this point in the history
Also renamed some commands for usability and updated their aliases
  • Loading branch information
Nos78 committed Apr 13, 2019
1 parent 44addd6 commit bf6546b
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 33 deletions.
4 changes: 2 additions & 2 deletions bot.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ client.on('message', async message => {
if (!cmd) return;

// Some commands are not meant to be executed inside DMs
if (command.guildOnly && message.channel.type !== 'text') {
if (cmd.guildOnly && message.channel.type !== 'text') {
return message.reply('I cannot execute that command inside a direct message!');
}

Expand Down Expand Up @@ -144,7 +144,7 @@ client.on('message', async message => {

if (now < expirationTime) {
const timeLeft = (expirationTime - now) / 1000;
return message.reply(`please wait ${timeLeft.toFixed(1)} more second(s) before reusing the \`${command.name}\` command.`);
return message.reply(`please wait ${timeLeft.toFixed(1)} more second(s) before reusing the \`${cmd.name}\` command.`);
}
}
timestamps.set(message.author.id, now);
Expand Down
12 changes: 12 additions & 0 deletions commands/botowner.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const library = require('../library');

module.exports = {
name: 'botowner',
description: `Returns the ID of my owner on this server`,
cooldown: 30,
args: false,
guildOnly: true,
execute(message, args) {
message.channel.send(`According to my records, my current owner for this server is ${library.Admin.owner(message.guild.id, message.client)}`);
},
};
2 changes: 1 addition & 1 deletion commands/datahelp.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const { prefix } = require('../config.json');

module.exports = {
name: 'help',
name: 'datahelp',
description: 'List all of my commands or info about a specific command.',
aliases: ['commands'],
usage: '[command name]',
Expand Down
5 changes: 3 additions & 2 deletions commands/isadmin.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,12 @@ module.exports = {
description: `Are you an admin of this server? This command will let you know!`,
cooldown: 30,
args: false,
guildOnly: true,
execute(message, args) {
let admin = "is not";
if(library.Admin.isAdmin(message.sender.id, message.guild.id, message.client)) {
if(library.Admin.isAdmin(message.author.id, message.guild.id, message.client)) {
admin = "is"
}
message.channel.send(`According to my records, ${message.sender} ${admin} recorded as an admin of ${message.guild.name}.`);
message.channel.send(`According to my records, ${message.author} ${admin} recorded as an admin of ${message.guild.name}.`);
},
};
1 change: 1 addition & 0 deletions commands/isowner.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = {
description: `Are you my owner? This command will let you know!`,
cooldown: 30,
args: false,
guildOnly: true,
execute(message, args) {
let owner = "is not";
if(library.Admin.isOwner(message.author.id, message.guild.id, message.client)) {
Expand Down
1 change: 1 addition & 0 deletions commands/owner.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ module.exports = {
cooldown: 30,
args: false,
description: `Indicates who I consider to be my owner on this server.`,
guildOnly: true,
execute(message, args) {
message.channel.send(`According to my records, the current owner of ${message.guild.name} is ${library.Admin.owner(message.guild.id, message.client)}`);
},
Expand Down
4 changes: 2 additions & 2 deletions commands/ping.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ module.exports = {
description: 'Calculates the ping between sending a message and editing it, calculating round-trip latency! The second ping is the averge latency between the bot and the web-socket (one way).',
cooldown: 5,
args: false,
execute(message, args) {
async execute(message, args) {
// Calculates ping between sending a message and editing it, giving a nice round-trip latency.
// The second ping is an average latency between the bot and the websocket server (one-way, not round-trip)
const m = await message.channel.send("Ping?");
m.edit(`Pong! ${sender} Latency is ${m.createdTimestamp - message.createdTimestamp}ms. API Latency is ${Math.round(bot.ping)}ms`);
m.edit(`Pong! ${message.author} Latency is ${m.createdTimestamp - message.createdTimestamp}ms. API Latency is ${Math.round(message.client.ping)}ms`);
},
};
17 changes: 10 additions & 7 deletions commands/power.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
const Discord = require('discord.js');
const db = require('../db');
const config = require('../config.json');
const library = require('../library');

module.exports = {
name: 'power',
Expand All @@ -8,6 +10,7 @@ module.exports = {
args: false,
usage: '<number>',
cooldown: 30,
guildOnly: true,
execute(message, args) {
var score = [];
db.scores.findByNameAndGuild(message.author.id, message.guild.id)
Expand Down Expand Up @@ -51,7 +54,7 @@ module.exports = {
// notify the user it was successful
message.channel.send({embed: {
color: config.powerColor,
description: `Thank you, ${sender}, ${member.displayName} total power is set to ${library.Format.numberWithCommas(score.totalpower)}`
description: `Thank you, ${message.author}, ${member.displayName} total power is set to ${library.Format.numberWithCommas(score.totalpower)}`
}});
})
} else {
Expand All @@ -60,7 +63,7 @@ module.exports = {
// notify the user it was successful
message.channel.send({embed: {
color: config.powerColor,
description: `Thank you, ${sender}, ${member.displayName} total power is set to ${library.Format.numberWithCommas(score.totalpower)}`
description: `Thank you, ${message.author}, ${member.displayName} total power is set to ${library.Format.numberWithCommas(score.totalpower)}`
}});
})
}
Expand All @@ -81,7 +84,7 @@ module.exports = {
// notify the user it was successful
message.channel.send({embed: {
color: config.powerColor,
description: `Thank you, ${sender}, your total power is set to ${library.Format.numberWithCommas(score.totalpower)}`
description: `Thank you, ${message.author}, your total power is set to ${library.Format.numberWithCommas(score.totalpower)}`
}});
})
} else {
Expand All @@ -90,7 +93,7 @@ module.exports = {
// notify the user it was successful
message.channel.send({embed: {
color: config.powerColor,
description: `Thank you, ${sender}, your total power is set to ${library.Format.numberWithCommas(score.totalpower)}`
description: `Thank you, ${message.author}, your total power is set to ${library.Format.numberWithCommas(score.totalpower)}`
}});
})
}
Expand All @@ -112,7 +115,7 @@ module.exports = {
} else {
message.channel.send({embed: {
color: config.powerColor,
description: `${sender}, please use \`!pd abc\`, where abc is a number or an actual person!}`
description: `${message.author}, please use \`!pd abc\`, where abc is a number or an actual person!}`
}});
}
}
Expand All @@ -123,12 +126,12 @@ module.exports = {
.then(top10 => {
const embed = new Discord.RichEmbed()
.setTitle("Power Leaderboard")
.setAuthor(bot.user.username, bot.user.avatarURL)
.setAuthor(message.client.user.username, message.client.user.avatarURL)
.setDescription("Our top 10 power leaders!")
.setColor(config.powerColor);
var c = 1;
for(const data of top10) {
embed.addField(`${c}. ${bot.guilds.get(guildID).members.get(data.uid).displayName}`, `${library.Format.numberWithCommas(data.totalpower)}`);
embed.addField(`${c}. ${message.client.guilds.get(message.guild.id).members.get(data.uid).displayName}`, `${library.Format.numberWithCommas(data.totalpower)}`);
c++;
}
embed.addField(`${config.password} Your personal total power is`, `${library.Format.numberWithCommas(score.totalpower)}`)
Expand Down
21 changes: 12 additions & 9 deletions commands/pd.js → commands/powerdestroyed.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
const Discord = require('discord.js');
const db = require('../db');
const config = require('../config.json');
const library = require('../library');

module.exports = {
name: 'pd',
name: 'powerdestroyed',
description: 'See the power destoyed top 10, or set your own power destroyed score.',
aliases: ['powerdestroyed'],
aliases: ['pd'],
args: false,
usage: '<number>',
cooldown: 30,
guildOnly: true,
execute(message, args) {
var score = [];
db.scores.findByNameAndGuild(message.author.id, message.guild.id)
Expand Down Expand Up @@ -51,7 +54,7 @@ module.exports = {
// notify the user it was successful
message.channel.send({embed: {
color: config.powerDestroyedColor,
description: `Thank you, ${sender}, ${member.displayName} power destroyed is set to ${library.Format.numberWithCommas(score.power_destroyed)}`
description: `Thank you, ${message.author}, ${member.displayName} power destroyed is set to ${library.Format.numberWithCommas(score.power_destroyed)}`
}});
})
} else {
Expand All @@ -60,7 +63,7 @@ module.exports = {
// notify the user it was successful
message.channel.send({embed: {
color: config.powerDestroyedColor,
description: `Thank you, ${sender}, ${member.displayName} power destroyed is set to ${library.Format.numberWithCommas(score.power_destroyed)}`
description: `Thank you, ${message.author}, ${member.displayName} power destroyed is set to ${library.Format.numberWithCommas(score.power_destroyed)}`
}});
})
}
Expand All @@ -81,7 +84,7 @@ module.exports = {
// notify the user it was successful
message.channel.send({embed: {
color: config.powerDestroyedColor,
description: `Thank you, ${sender}, your power destroyed is set to ${library.Format.numberWithCommas(score.power_destroyed)}`
description: `Thank you, ${message.author}, your power destroyed is set to ${library.Format.numberWithCommas(score.power_destroyed)}`
}});
})
} else {
Expand All @@ -90,7 +93,7 @@ module.exports = {
// notify the user it was successful
message.channel.send({embed: {
color: config.powerDestroyedColor,
description: `Thank you, ${sender}, your power destroyed is set to ${library.Format.numberWithCommas(score.power_destroyed)}`
description: `Thank you, ${message.author}, your power destroyed is set to ${library.Format.numberWithCommas(score.power_destroyed)}`
}});
})
}
Expand All @@ -112,7 +115,7 @@ module.exports = {
} else {
message.channel.send({embed: {
color: config.powerDestroyedColor,
description: `${sender}, please use \`!pd abc\`, where abc is a number or an actual person!}`
description: `${message.author}, please use \`!pd abc\`, where abc is a number or an actual person!}`
}});
}
}
Expand All @@ -123,12 +126,12 @@ module.exports = {
.then(top10 => {
const embed = new Discord.RichEmbed()
.setTitle("Power Destroyed Leaderboard")
.setAuthor(bot.user.username, bot.user.avatarURL)
.setAuthor(message.client.user.username, message.client.user.avatarURL)
.setDescription("Our top 10 power destroyed leaders!")
.setColor(config.powerDestroyedColor);
var c = 1;
for(const data of top10) {
embed.addField(`${c}. ${bot.guilds.get(guildID).members.get(data.uid).displayName}`, `${library.Format.numberWithCommas(data.power_destroyed)}`);
embed.addField(`${c}. ${message.client.guilds.get(message.guild.id).members.get(data.uid).displayName}`, `${library.Format.numberWithCommas(data.power_destroyed)}`);
c++;
}
embed.addField(`Your personal power destroyed is`, `${library.Format.numberWithCommas(score.power_destroyed)}`)
Expand Down
21 changes: 12 additions & 9 deletions commands/rr.js → commands/resourcesraided.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
const Discord = require('discord.js');
const db = require('../db');
const config = require('../config.json');
const library = require('../library');

module.exports = {
name: 'rr',
name: 'resourcesraided',
description: 'See the resources raided top 10, or set your own resources raided score.',
aliases: ['resourcesraided'],
aliases: ['rr'],
args: false,
usage: '<number>',
cooldown: 30,
guildOnly: true,
execute(message, args) {
var score = [];
db.scores.findByNameAndGuild(message.author.id, message.guild.id)
Expand Down Expand Up @@ -51,7 +54,7 @@ module.exports = {
// notify the user it was successful
message.channel.send({embed: {
color: config.resourcesRaidedColor,
description: `Thank you, ${sender}, ${member.displayName} resources raided is set to ${library.Format.numberWithCommas(score.resources_raided)}`
description: `Thank you, ${message.author}, ${member.displayName} resources raided is set to ${library.Format.numberWithCommas(score.resources_raided)}`
}});
})
} else {
Expand All @@ -60,7 +63,7 @@ module.exports = {
// notify the user it was successful
message.channel.send({embed: {
color: config.resourcesRaidedColor,
description: `Thank you, ${sender}, ${member.displayName} resources raided is set to ${library.Format.numberWithCommas(score.resources_raided)}`
description: `Thank you, ${message.author}, ${member.displayName} resources raided is set to ${library.Format.numberWithCommas(score.resources_raided)}`
}});
})
}
Expand All @@ -81,7 +84,7 @@ module.exports = {
// notify the user it was successful
message.channel.send({embed: {
color: config.resourcesRaidedColor,
description: `Thank you, ${sender}, your resources raided is set to ${library.Format.numberWithCommas(core.resources_raided)}`
description: `Thank you, ${message.author}, your resources raided is set to ${library.Format.numberWithCommas(core.resources_raided)}`
}});
})
} else {
Expand All @@ -90,7 +93,7 @@ module.exports = {
// notify the user it was successful
message.channel.send({embed: {
color: 3447003,
description: `Thank you, ${sender}, your resources raided is set to ${library.Format.numberWithCommas(score.resources_raided)}`
description: `Thank you, ${message.author}, your resources raided is set to ${library.Format.numberWithCommas(score.resources_raided)}`
}});
})
}
Expand All @@ -112,7 +115,7 @@ module.exports = {
} else {
message.channel.send({embed: {
color: config.resourcesRaidedColor,
description: `${sender}, please use \`!pd abc\`, where abc is a number or an actual person!}`
description: `${message.author}, please use \`!pd abc\`, where abc is a number or an actual person!}`
}});
}
}
Expand All @@ -123,12 +126,12 @@ module.exports = {
.then(top10 => {
const embed = new Discord.RichEmbed()
.setTitle("Resources Raided Leaderboard")
.setAuthor(bot.user.username, bot.user.avatarURL)
.setAuthor(message.client.user.username, message.client.user.avatarURL)
.setDescription("Our top 10 resources raided leaders!")
.setColor(config.resourcesRaidedColor);
var c = 1;
for(const data of top10) {
embed.addField(`${c}. ${bot.guilds.get(guildID).members.get(data.uid).displayName}`, `${library.Format.numberWithCommas(data.resources_raided)}`);
embed.addField(`${c}. ${message.client.guilds.get(message.guild.id).members.get(data.uid).displayName}`, `${library.Format.numberWithCommas(data.resources_raided)}`);
c++;
}
embed.addField(`Your personal resources raided is`, `${library.Format.numberWithCommas(score.resources_raided)}`)
Expand Down
2 changes: 1 addition & 1 deletion commands/uptime.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ module.exports = {
let minutes = Math.floor(totalSeconds / 60);
let seconds = totalSeconds % 60;
let uptime = `${days} days, ${hours} hours, ${minutes} minutes and ${seconds} seconds`;
message.channel.send(`${sender}, I have been active for ${uptime}`);
message.channel.send(`${message.author}, I have been active for ${uptime}`);
},
};

0 comments on commit bf6546b

Please sign in to comment.