Skip to content

Commit

Permalink
Merge PR #97 from TheBastionBot/dev
Browse files Browse the repository at this point in the history
Bastion Bot v6.6.2
  • Loading branch information
iamtraction committed Jan 27, 2018
2 parents bcc7c20 + 0ec2198 commit 3cbb1c4
Show file tree
Hide file tree
Showing 20 changed files with 266 additions and 162 deletions.
10 changes: 4 additions & 6 deletions changes.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
{
"date": "January 24, 2018",
"date": "January 27, 2018",
"fixed": [
"Fixed crashes when Cleverbot API didn't returned any response.",
"Fixed Bastion not stopping the typing event.",
"Fixed `claim` not working for uncached guild members."
"Fixed `claim` crashes when there was no Patreon API key."
],
"improved": [
"You can now give Bastion Currencies without having to mention them; just use their IDs. Yeah, less annoying.",
"If there's no one in the voice channel, Bastion will automatically pause the music.",
"Are you a Patreon creator and hosting Bastion yourself? The `patrons` command will now show your patrons and not the patrons of the Bastion bot project.",
"`clearWarn`, `deafen`, `kick`, `mute`, `nickname`, `removeAllRoles`, `softBan`, `textMute`, `textUnMute`, `unDeafen`, `unMute` and `warn` commands can be used with the ID of the user. No need to mention them anymore.",
"Under-the-hood improvements"
],
"added": [],
Expand Down
65 changes: 39 additions & 26 deletions functions/getPatrons.js
Original file line number Diff line number Diff line change
@@ -1,45 +1,58 @@
const request = require('request-promise-native');
const patreon = require('../settings/credentials.json').patreon;

module.exports = (campaignID) => {
module.exports = () => {
return new Promise(async (resolve, reject) => {
try {
let options = {
headers: {
'Authorization': `Bearer ${patreon ? patreon.creatorAccessToken : undefined}`
},
uri: `https://www.patreon.com/api/oauth2/api/campaigns/${campaignID}/pledges`,
uri: 'https://www.patreon.com/api/oauth2/api/current_user/campaigns',
json: true
};

let response = await request(options);

let data = response.data;
let included = response.included;

let pledges = data.filter(data => data.type === 'pledge');
let users = included.filter(inc => inc.type === 'user');

let patrons = pledges.map(pledge => {
let id = pledge.relationships.patron.data.id;
let user = users.filter(user => user.id === pledge.relationships.patron.data.id)[0];

return {
id: id,
full_name: user.attributes.full_name,
vanity: user.attributes.vanity,
email: user.attributes.email,
discord_id: user.attributes.social_connections.discord.user_id,
amount_cents: pledge.attributes.amount_cents,
created_at: pledge.attributes.created_at,
declined_since: pledge.attributes.declined_since,
patron_pays_fees: pledge.attributes.patron_pays_fees,
pledge_cap_cents: pledge.attributes.pledge_cap_cents,
image_url: user.attributes.image_url
if (response && response.data && response.data.length) {
options = {
headers: {
'Authorization': `Bearer ${patreon ? patreon.creatorAccessToken : undefined}`
},
uri: `https://www.patreon.com/api/oauth2/api/campaigns/${response.data[0].id}/pledges`,
json: true
};
});
response = await request(options);

resolve(patrons);
let data = response.data;
let included = response.included;

let pledges = data.filter(data => data.type === 'pledge');
let users = included.filter(inc => inc.type === 'user');

let patrons = pledges.map(pledge => {
let id = pledge.relationships.patron.data.id;
let user = users.filter(user => user.id === pledge.relationships.patron.data.id)[0];

return {
id: id,
full_name: user.attributes.full_name,
vanity: user.attributes.vanity,
email: user.attributes.email,
discord_id: user.attributes.social_connections.discord.user_id,
amount_cents: pledge.attributes.amount_cents,
created_at: pledge.attributes.created_at,
declined_since: pledge.attributes.declined_since,
patron_pays_fees: pledge.attributes.patron_pays_fees,
pledge_cap_cents: pledge.attributes.pledge_cap_cents,
image_url: user.attributes.image_url
};
});

resolve(patrons);
}

reject('Not a Patreon Creator.');
}
catch (e) {
reject(e);
Expand Down
2 changes: 1 addition & 1 deletion handlers/commandHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ module.exports = async message => {
if (message.client.shard) {
message.client.log.console(`${COLOR.green('[SHARD]:')} ${message.client.shard.id}`);
}
message.client.log.console(`${COLOR.green('[SERVER]:')} ${message.guild} ${COLOR.cyan(`<#${message.guild.id}>`)}`);
message.client.log.console(`${COLOR.green('[SERVER]:')} ${message.guild} ${COLOR.cyan(message.guild.id)}`);
message.client.log.console(`${COLOR.green('[CHANNEL]:')} #${message.channel.name} ${COLOR.cyan(message.channel)}`);
message.client.log.console(`${COLOR.green('[USER]:')} ${message.author.tag} ${COLOR.cyan(`${message.author}`)}`);

Expand Down
2 changes: 1 addition & 1 deletion locales/en/modules.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@
"emojiInfo": "Shows information of a specifed emoji of your Discord server.",
"inRole": "Shows members that have a specifed role in your Discord server.",
"level": "Shows the current level of the specified user's account.",
"patrons": "Shows the list of people who continuously supports the development of the Bastion Bot project, by being my patron, on [Patreon](https://patreon.com/snkrsnkampa).",
"patrons": "Shows the list of people who continuously supports the development of the Bastion Bot project, by being my patron, on [Patreon](https://patreon.com/snkrsnkampa). But if you're hosting Bastion yourself, and you're a Patreon creator, it will show the list of your Patrons.",
"ping": "Shows the response time and average WebSocket ping of Bastion.",
"profile": "Shows Bastion user profile of a specified user of your Discord server.",
"roleID": "Shows the ID of a specified role of your Discord server.",
Expand Down
2 changes: 1 addition & 1 deletion modules/administration/createEmoji.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

exports.exec = async (Bastion, message, args) => {
try {
if (!args.url || !/^(https?:\/\/)((([-a-z0-9]{1,})?(-?)+[-a-z0-9]{1,})(\.))+([a-z]{1,63})\/((([a-z0-9._\-~#%])+\/)+)?([a-z0-9._\-~#%]+)\.(jpg|jpeg|gif|png|bmp)$/i.test(args.url) || !args.name) {
if (!args.url || !/^(https?:\/\/)((([-a-z0-9]{1,})?(-?)+[-a-z0-9]{1,})(\.))+([a-z]{1,63})\/((([a-z0-9._\-~#%])+\/)+)?([a-z0-9._\-~#%]+)\.(jpg|jpeg|gif|png)$/i.test(args.url) || !args.name) {
/**
* The command was ran with invalid parameters.
* @fires commandUsage
Expand Down
14 changes: 11 additions & 3 deletions modules/info/patrons.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,33 @@

exports.exec = async (Bastion, message, args) => {
try {
let patrons = await Bastion.functions.getPatrons(754397);
let patrons = await Bastion.functions.getPatrons();
patrons = patrons.map(patron => patron.full_name);

let noOfPages = patrons.length / 50;
let i = (args.page > 0 && args.page < noOfPages + 1) ? args.page : 1;
i = i - 1;

let description;
if (Bastion.user.id === '267035345537728512') {
description = 'These are the awesome people who continuously support the development of the Bastion bot project, by being my patron, on [Patreon](https://patreon.com/snkrsnkampa).\nIf you want to support the development of Bastion too, [be my Patron](https://patreon.com/bePatron?c=754397)';
}
else {
description = 'These are the awesome people who continuously support us, by being our patron, on Patreon.';
}

message.channel.send({
embed: {
color: 16345172,
description: 'These are the awesome people who continuously support the development of the Bastion Bot project by being my patron on [Patreon](https://patreon.com/snkrsnkampa).',
description: description,
fields: [
{
name: 'Patrons',
value: patrons.slice(i * 50, (i * 50) + 50).join(', ')
}
],
footer: {
text: `Page: ${i + 1} of ${noOfPages > parseInt(noOfPages) ? parseInt(noOfPages) + 1 : parseInt(noOfPages)} • https://patreon.com/snkrsnkampa`
text: `Page: ${i + 1} of ${noOfPages > parseInt(noOfPages) ? parseInt(noOfPages) + 1 : parseInt(noOfPages)}`
}
}
}).catch(e => {
Expand Down
27 changes: 17 additions & 10 deletions modules/moderation/clearWarn.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@

exports.exec = async (Bastion, message, args) => {
try {
let user = message.mentions.users.first();
let user;
if (message.mentions.users.size) {
user = message.mentions.users.first();
}
else if (args.id) {
user = await Bastion.fetchUser(args.id);
}
if (!user) {
/**
* The command was ran with invalid parameters.
Expand All @@ -18,10 +24,7 @@ exports.exec = async (Bastion, message, args) => {
let member = await message.guild.fetchMember(user.id);
if (message.author.id !== message.guild.ownerID && message.member.highestRole.comparePositionTo(member.highestRole) <= 0) return Bastion.log.info(Bastion.strings.error(message.guild.language, 'lowerRole', true));

let reason = args.slice(1).join(' ');
if (reason.length < 1) {
reason = 'No given reason';
}
args.reason = args.reason.join(' ');

if (!message.guild.warns) {
/**
Expand All @@ -42,7 +45,7 @@ exports.exec = async (Bastion, message, args) => {
message.channel.send({
embed: {
color: Bastion.colors.GREEN,
description: `${message.author.tag} cleared the warnings for ${user.tag} with reason **${reason}**`
description: `${message.author.tag} cleared the warnings for ${user.tag} with reason **${args.reason}**`
}
}).catch(e => {
Bastion.log.error(e);
Expand All @@ -52,7 +55,7 @@ exports.exec = async (Bastion, message, args) => {
* Logs moderation events if it is enabled
* @fires moderationLog
*/
Bastion.emit('moderationLog', message.guild, message.author, this.help.name, user, reason);
Bastion.emit('moderationLog', message.guild, message.author, this.help.name, user, args.reason);
}
catch (e) {
Bastion.log.error(e);
Expand All @@ -61,14 +64,18 @@ exports.exec = async (Bastion, message, args) => {

exports.config = {
aliases: [ 'warnClear' ],
enabled: true
enabled: true,
argsDefinitions: [
{ name: 'id', type: String, defaultOption: true },
{ name: 'reason', alias: 'r', type: String, multiple: true, defaultValue: [ 'No reason given.' ] }
]
};

exports.help = {
name: 'clearWarn',
botPermission: '',
userTextPermission: 'KICK_MEMBERS',
userVoicePermission: '',
usage: 'clearWarn @user-mention [Reason]',
example: [ 'clearWarn @user#0001 Reason for clearing the warning.' ]
usage: 'clearWarn <@USER_MENTION | USER_ID> -r [Reason]',
example: [ 'clearWarn @user#001 -r Apologized', 'clearWarn 167147569575323761 -r Forgiven' ]
};
27 changes: 17 additions & 10 deletions modules/moderation/deafen.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@

exports.exec = async (Bastion, message, args) => {
try {
let user = message.mentions.users.first();
let user;
if (message.mentions.users.size) {
user = message.mentions.users.first();
}
else if (args.id) {
user = await Bastion.fetchUser(args.id);
}
if (!user) {
/**
* The command was ran with invalid parameters.
Expand All @@ -20,15 +26,12 @@ exports.exec = async (Bastion, message, args) => {

await member.setDeaf(true);

let reason = args.slice(1).join(' ');
if (reason.length < 1) {
reason = 'No reason given';
}
args.reason = args.reason.join(' ');

message.channel.send({
embed: {
color: Bastion.colors.ORANGE,
description: `${message.author.tag} deafened ${user.tag} with reason **${reason}**`
description: `${message.author.tag} deafened ${user.tag} with reason **${args.reason}**`
}
}).catch(e => {
Bastion.log.error(e);
Expand All @@ -38,7 +41,7 @@ exports.exec = async (Bastion, message, args) => {
* Logs moderation events if it is enabled
* @fires moderationLog
*/
Bastion.emit('moderationLog', message.guild, message.author, this.help.name, user, reason);
Bastion.emit('moderationLog', message.guild, message.author, this.help.name, user, args.reason);
}
catch (e) {
Bastion.log.error(e);
Expand All @@ -47,14 +50,18 @@ exports.exec = async (Bastion, message, args) => {

exports.config = {
aliases: [ 'deaf' ],
enabled: true
enabled: true,
argsDefinitions: [
{ name: 'id', type: String, defaultOption: true },
{ name: 'reason', alias: 'r', type: String, multiple: true, defaultValue: [ 'No reason given.' ] }
]
};

exports.help = {
name: 'deafen',
botPermission: 'DEAFEN_MEMBERS',
userTextPermission: 'DEAFEN_MEMBERS',
userVoicePermission: '',
usage: 'deafen @user-mention [Reason]',
example: [ 'deafen @user#0001 Reason for the deafening.' ]
usage: 'deafen <@USER_MENTION | USER_ID> -r [Reason]',
example: [ 'deafen @user#001 -r Shouting like crazy', 'deafen 167147569575323761 -r Profanity' ]
};
31 changes: 19 additions & 12 deletions modules/moderation/kick.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@

exports.exec = async (Bastion, message, args) => {
try {
let user = message.mentions.users.first();
let user;
if (message.mentions.users.size) {
user = message.mentions.users.first();
}
else if (args.id) {
user = await Bastion.fetchUser(args.id);
}
if (!user) {
/**
* The command was ran with invalid parameters.
Expand All @@ -26,17 +32,14 @@ exports.exec = async (Bastion, message, args) => {
return Bastion.emit('error', Bastion.strings.error(message.guild.language, 'forbidden'), Bastion.strings.error(message.guild.language, 'noPermission', true, 'kick', user), message.channel);
}

let reason = args.slice(1).join(' ');
if (reason.length < 1) {
reason = 'No given reason';
}
await member.kick(args.reason);

await member.kick(reason);
args.reason = args.reason.join(' ');

message.channel.send({
embed: {
color: Bastion.colors.RED,
description: `${message.author.tag} kicked ${user.tag} with reason **${reason}**`,
description: `${message.author.tag} kicked ${user.tag} with reason **${args.reason}**`,
footer: {
text: `ID ${user.id}`
}
Expand All @@ -49,12 +52,12 @@ exports.exec = async (Bastion, message, args) => {
* Logs moderation events if it is enabled
* @fires moderationLog
*/
Bastion.emit('moderationLog', message.guild, message.author, this.help.name, member, reason);
Bastion.emit('moderationLog', message.guild, message.author, this.help.name, member, args.reason);

member.send({
embed: {
color: Bastion.colors.RED,
description: `${message.author.tag} kicked you from **${message.guild.name}** server with reason **${reason}**`
description: `${message.author.tag} kicked you from **${message.guild.name}** server with reason **${args.reason}**`
}
}).catch(e => {
Bastion.log.error(e);
Expand All @@ -67,14 +70,18 @@ exports.exec = async (Bastion, message, args) => {

exports.config = {
aliases: [ 'k' ],
enabled: true
enabled: true,
argsDefinitions: [
{ name: 'id', type: String, defaultOption: true },
{ name: 'reason', alias: 'r', type: String, multiple: true, defaultValue: [ 'No reason given.' ] }
]
};

exports.help = {
name: 'kick',
botPermission: 'KICK_MEMBERS',
userTextPermission: 'KICK_MEMBERS',
userVoicePermission: '',
usage: 'kick @user-mention [Reason]',
example: [ 'kick @user#0001 Reason for the kick.' ]
usage: 'kick <@USER_MENTION | USER_ID> -r [Reason]',
example: [ 'kick @user#001 -r Being rude to everyone.', 'kick 167147569575323761 -r Spamming' ]
};
Loading

0 comments on commit 3cbb1c4

Please sign in to comment.