Skip to content

Commit

Permalink
Merge pull request #33 from muricans/mbot-testing
Browse files Browse the repository at this point in the history
7.5.4
  • Loading branch information
muricans authored Jun 8, 2019
2 parents 6fb68c5 + 3016c6b commit 83abc38
Show file tree
Hide file tree
Showing 12 changed files with 192 additions and 221 deletions.
6 changes: 5 additions & 1 deletion commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ const fs = require('fs');
const Discord = require('discord.js');
const mute = require('./commands/mod/mute');
const timer = require('./commands/util/timer');
const {
bot_owners_id,
} = require('./settings.json');

const cooldowns = new Discord.Collection();
module.exports.getCooldowns = (key) => {
Expand Down Expand Up @@ -193,7 +196,8 @@ module.exports.registerCommands = async (client, mbot) => {
return message.channel.send(`${message.author} Please add params! ${prefix}${comm.name} ${comm.usage}`);
}
}
if (message.author.id === "399121700429627393") {
const isOwner = bot_owners_id.find(id => id === message.author.id);
if (isOwner) {
try {
return comm.execute(message, args, client, prefix);
} catch (err) {
Expand Down
5 changes: 3 additions & 2 deletions commands/help.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,30 +59,31 @@ module.exports = {
.addField(prefix + 'help [command]', 'Returns a list of commands for this bot')
.addField(prefix + 'imgur [hash]', 'Returns a random image from imgur, or an image with the provided hash')
.addField(prefix + 'kick <user> [reason]', 'Kicks specified user')
.addField(prefix + 'leaderboard', 'Get up to 20 users with the most points')
.addField(prefix + 'meme', 'Returns a random meme')
.addField(prefix + 'modules <moduleName> <moduleOption> [setTo, ?name] [?setTo]', 'Use modules for your server. [Documentation](https://muricans.github.io/mbot/)')
.addField(prefix + `mute <user> <time?'min','hour'>`, `Keeps a player from chatting for specified time.`)
.addField(prefix + 'ping', 'Returns pong')
.setFooter(pageData);
sent.edit(embed);
break;
case 3:
embed = new Discord.RichEmbed()
.setTitle('Commands')
.addField(prefix + 'ping', 'Returns pong')
.addField(prefix + 'prefix <newPrefix>', 'Changes the bots prefix [admin only]')
.addField(prefix + 'points [user]', "Returns the designated user's (or your own) points")
.addField(prefix + 'qr <information>', 'Returns a QR code with the designated information')
.addField(prefix + 'random <subreddit> [time|search] [search]', 'Returns a random thread from a subreddit')
.addField(prefix + 'roulette <amount>', 'Returns win/loss and new total points')
.addField(prefix + 'roll [number]', 'Returns a random number between 1 and the chosen number')
.addField(prefix + 'suggest <suggestion>', 'Suggest a command or feature for the bot')
.addField(prefix + 'suggestions [clear]', 'Check the suggestions, (include <clear> [admin only] to clear the suggestions)')
.setFooter(pageData);
sent.edit(embed);
break;
case 4:
embed = new Discord.RichEmbed()
.setTitle('Commands')
.addField(prefix + 'suggestions [clear]', 'Check the suggestions, (include <clear> [admin only] to clear the suggestions)')
.addField(prefix + `timer <time?'min','hour'|cancel|list> [name]`, 'Set a timer for the bot to remind you on when it completes.')
.addField(prefix + 'unmute <user>', 'Unmute a muted user')
.addField(prefix + 'userinfo [user]', "Returns the designated user's info")
Expand Down
78 changes: 26 additions & 52 deletions commands/roulette/give.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
const sqlite = require('sqlite3').verbose();
const tls = require('../../tools');
const tools = new tls.Tools();

const db = new sqlite.Database('./mbot.db', (err) => {
if (err) {
console.error(err.message);
}
});

module.exports = {
name: 'give',
usage: '<user> <amount|all>',
Expand All @@ -16,56 +9,37 @@ module.exports = {
args: true,
minArgs: 2,
mod: true,
execute(message, args) {
async execute(message, args) {
if (message.mentions.users.first() === message.author) {
return message.reply('You cannot give points to yourself!');
}
if (!message.mentions.users.first()) {
return message.reply('That user does not exist!');
}
db.serialize(() => {
db.get("SELECT points points FROM users WHERE id = " + message.author.id.toString(), (err, row) => {
if (err) {
return message.reply('That user does not exist!');
}
const give = parseInt(args[1]);
if (args[1] === "all") {
const all = parseInt(row.points.toString());
//db.run('UPDATE users SET points = ? WHERE id = ?', 0, message.author.id.toString());
tools.setPoints(0, message.author.id.toString());
db.get("SELECT points points FROM users where id = " + message.mentions.users.first().id.toString(), (err, row2) => {
if (err) {
return console.log(err);
}
const mentCurrent = parseInt(row2.points.toString());
const mentNewCurrent = all + mentCurrent;
//db.run('UPDATE users SET points = ? WHERE id = ?', mentNewCurrent, message.mentions.users.first().id.toString());
tools.setPoints(mentNewCurrent, message.mentions.users.first().id.toString());
return message.reply('You sent all your points to ' + message.mentions.users.first() + '!');
});
return;
}
if (isNaN(give)) {
return message.reply('Please give a proper number!');
}
const current = parseInt(row.points.toString());
if (give > current) {
return message.reply("You don't have that many points! You have: " + current + " points.");
}
const newCurrent = current - give;
//db.run('UPDATE users SET points = ? WHERE id = ?', newCurrent, message.author.id.toString());
tools.setPoints(newCurrent, message.author.id.toString());
db.get("SELECT points points FROM users where id = " + message.mentions.users.first().id.toString(), (err, row2) => {
if (err) {
return console.log(err);
}
const mentCurrent = parseInt(row2.points.toString());
const mentNewCurrent = give + mentCurrent;
//db.run('UPDATE users SET points = ? WHERE id = ?', mentNewCurrent, message.mentions.users.first().id.toString());
tools.setPoints(mentNewCurrent, message.mentions.users.first().id.toString());
message.reply('You sent ' + give + ' points to ' + message.mentions.users.first() + '!');
});
});
});
const mention = message.mentions.users.first();
let current = await tools.getPoints(message.author.id);
const give = parseInt(args[1]);
let all = false;
if (args[1] === "all") {
all = true;
tools.setPoints(0, message.author.id);
}
if (!all && isNaN(give)) return message.channel.send('Please use numbers!');
let mentCurrent = await tools.getPoints(mention.id);
let msg;
if (all) {
mentCurrent = mentCurrent + current;
msg = `${message.author} You sent all your points to ${mention}!`;
current = 0;
} else {
if (give > current) return message.channel.send(`${message.author} You don't have that many points!`);
mentCurrent = mentCurrent + give;
msg = `${message.author} You sent ${give} points to ${mention}!`;
current = current - give;
}
tools.setPoints(mentCurrent, mention.id);
tools.setPoints(current, message.author.id);
tools.addCooldown(this.name, 3, message);
return message.channel.send(msg);
},
};
31 changes: 31 additions & 0 deletions commands/roulette/leaderboard.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const Discord = require('discord.js');
const sqlite = require('sqlite3').verbose();

const db = new sqlite.Database('./mbot.db', (err) => {
if (err) console.log(err.message);
});

module.exports = {
name: 'leaderboard',
description: 'Get up to 20 users with the most points',
async execute(message, args, client) {
leaderboard(message, client).then(leaders => message.channel.send(leaders));
},
};

function leaderboard(message, client) {
return new Promise((resolve) => {
db.all('SELECT points points, id id FROM users ORDER BY points DESC', (err, rows) => {
if (err) return console.log(err);
const embed = new Discord.RichEmbed().setTitle('Points Leaderboard');
if (!rows.length) return message.channel.send('No users found!');
rows.forEach(async (val, i, arr) => {
if (i < 20) {
const user = await client.fetchUser(arr[i].id);
embed.addField(`${i + 1}. ${user.username}`, arr[i].points, true);
}
});
resolve(embed);
});
});
}
43 changes: 14 additions & 29 deletions commands/roulette/points.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,23 @@
const sqlite = require('sqlite3').verbose();
const tls = require('../../tools');
const tools = new tls.Tools();

const db = new sqlite.Database('./mbot.db', (err) => {
if (err) {
console.error(err.message);
}
});

module.exports.cooldown = 0;

module.exports = {
name: 'points',
usage: '[user]',
description: `Returns the designated user's points`,
execute(message, args) {
db.serialize(() => {
if (args.length === 0) {
db.get('SELECT points points FROM users WHERE id = ' + message.author.id.toString(), (err, row) => {
if (err) {
return console.log(err);
}
return message.reply('You have ' + row.points.toString() + ' points!');
});
}
if (args.length > 0) {
tools.addCooldown(module.exports.name, 3, message);
db.get('SELECT points points FROM users WHERE id = ' + message.mentions.users.first().id.toString(), (err, row) => {
if (err) {
return message.reply('No such user exists!');
}
return message.reply(message.mentions.users.first().username + ' has ' + row.points.toString() + ' points!');
});
}
});
async execute(message, args) {
let current;
let msg;
const mention = message.mentions.users.first();
if (!args.length) {
current = await tools.getPoints(message.author.id);
msg = `You have ${current} points!`;
} else {
if (!mention) return message.channel.send('Could not find that user!');
current = await tools.getPoints(mention.id);
msg = `${mention.username} has ${current} points!`;
tools.addCooldown(this.name, 3, message);
}
return message.channel.send(msg);
},
};
62 changes: 22 additions & 40 deletions commands/roulette/roulette.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
const sqlite = require('sqlite3').verbose();
const tls = require('../../tools.js');
const tools = new tls.Tools();

const db = new sqlite.Database('./mbot.db', (err) => {
if (err) {
console.error(err.message);
}
});

module.exports = {
name: 'roulette',
usage: '<all|amount|percent>',
Expand All @@ -16,38 +9,27 @@ module.exports = {
args: true,
minArgs: 1,
mod: true,
execute(message, args, client) {
db.serialize(() => {
db.get("SELECT points points FROM users WHERE id = " + message.author.id.toString(), (err, row) => {
if (err) {
return console.log(err);
}
const current = parseInt(row.points.toString());
let num = parseInt(args[0]);
if (current === 0) {
tools.setPoints(10, message.author.id.toString());
return message.reply('You had 0 points, so I gave you +10 points!');
}
if (args[0] === "all") {
num = current;
return tools.roulette(num, current, message, client, true);
}
if (args[0].includes('%')) {
const per = (current * num) / 100;
const percentage = Math.round(per);
if (percentage > current) {
return message.reply("Sorry, you don't have that many points! Your current points: " + current);
}
return tools.roulette(percentage, current, message, client, false);
}
if (isNaN(num)) {
return message.reply('Your arguments are not a number or all! Please update them with such!');
}
if (num > current) {
return message.reply("Sorry, you don't have that many points! Your current points: " + current);
}
tools.roulette(num, current, message, client, false);
});
});
async execute(message, args, client) {
const current = await tools.getPoints(message.author.id);
const num = parseInt(args[0]);
if (current === 0) {
return message.channel.send(`${message.author} You don't have enough points!`);
}
if (args[0] === "all") {
return tools.roulette(current, current, message, client, true);
} else if (args[0].endsWith('%')) {
let percentage = tools.parsePercent(current * num);
console.log(percentage);
if (percentage > current) {
percentage = current;
}
return tools.roulette(percentage, current, message, client, false);
} else if (isNaN(num)) {
return message.channel.send('Please use numbers!');
} else if (num > current) {
return message.channel.send(`${message.author} You don't have enough points!`);
} else {
return tools.roulette(num, current, message, client, false);
}
},
};
30 changes: 7 additions & 23 deletions commands/roulette/set.js
Original file line number Diff line number Diff line change
@@ -1,38 +1,22 @@
const sqlite = require('sqlite3').verbose();
const tls = require('../../tools');
const tools = new tls.Tools();

const db = new sqlite.Database('./mbot.db', (err) => {
if (err) {
console.error(err.message);
}
});

module.exports = {
name: 'set',
usage: '<user> <amount>',
description: 'Sets the users points [dev only]',
args: true,
minArgs: 2,
owner: true,
execute(message, args, client) {
const weirdChamp = client.emojis.get("572690273247821824");
if (message.author.id != "399121700429627393") {
return message.channel.send(`${message.author} You don't have permission to use this command! ${weirdChamp}`);
}
execute(message, args) {
if (!message.mentions.users.first()) {
return message.reply('That user does not exist!');
}
db.serialize(() => {
db.get("SELECT points points FROM users WHERE id = " + message.mentions.users.first().id.toString(), () => {
const amnt = parseInt(args[1]);
if (isNaN(amnt)) {
return message.reply('Please use numbers!');
}
//db.run('UPDATE users SET points = ? WHERE id = ?', amnt, message.mentions.users.first().id.toString());
tools.setPoints(amnt, message.mentions.users.first().id.toString());
message.reply('You set ' + message.mentions.users.first() + ' points to ' + amnt + '!');
});
});
const amnt = parseInt(args[1]);
if (isNaN(amnt)) {
return message.channel.send('Please use numbers!');
}
tools.setPoints(amnt, message.mentions.users.first().id);
return message.channel.send(`${message.author} You set ${message.mentions.users.first()}'s points to ${amnt}!`);
},
};
2 changes: 2 additions & 0 deletions commands/util/timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ module.exports = {
send.push(`${id} (${shortId}) - ${timeLeft}`);
}
send = send.join('\n');
tools.addCooldown(this.name, 3, message);
if (send !== '') {
return message.channel.send('Timers:\n' + send).catch();
} else {
Expand Down Expand Up @@ -133,6 +134,7 @@ module.exports = {
}
require('../../logger').debug(wordNumbers);
tools.createTimer(message.author.id, mil, timerId, timerName.toLowerCase());
tools.addCooldown(this.name, 5, message);
return message.channel.send(`${message.author} Successfully created timer that will go off in ${out}\nName: ${timerName} (${timerId.substr(0, 6)})`);
},
};
Expand Down
Loading

0 comments on commit 83abc38

Please sign in to comment.