Remove Stuff

This commit is contained in:
Daniel Odendahl Jr
2017-06-22 03:17:03 +00:00
parent 046a559342
commit 5e7a8d17ad
38 changed files with 40 additions and 704 deletions
+9 -61
View File
@@ -1,6 +1,6 @@
const { TOKEN, OWNER, PREFIX, INVITE } = process.env;
const path = require('path');
const CommandoClient = require('./structures/CommandoClient');
const { CommandoClient } = require('discord.js-commando');
const client = new CommandoClient({
commandPrefix: PREFIX,
owner: OWNER,
@@ -8,17 +8,14 @@ const client = new CommandoClient({
disableEveryone: true
});
const { carbon, dBots } = require('./structures/Stats');
const SequelizeProvider = require('./providers/Sequelize');
client.setProvider(new SequelizeProvider(client.database));
client.registry
.registerDefaultTypes()
.registerGroups([
['util', 'Utility'],
['user-info', 'User Info'],
['guild-info', 'Server Info'],
['moderation', 'Moderation'],
['settings', 'Server Settings'],
['random-res', 'Random Response'],
['random-img', 'Random Image'],
['image-edit', 'Image Manipulation'],
@@ -30,10 +27,11 @@ client.registry
['random', 'Random/Other'],
['roleplay', 'Roleplay']
])
.registerDefaultGroups()
.registerDefaultCommands({
help: false,
ping: false
ping: false,
prefix: false,
commandState: false
})
.registerCommandsIn(path.join(__dirname, 'commands'));
@@ -53,61 +51,16 @@ client.on('warn', console.warn);
client.on('commandError', (command, err) => console.error(command.name, err));
client.dispatcher.addInhibitor((msg) => {
if (msg.channel.type === 'dm') return false;
const role = msg.guild.settings.get('singleRole');
if (!msg.guild.roles.has(role) || msg.member.hasPermission('ADMINISTRATOR')) return false;
if (!msg.member.roles.has(role)) return 'single role';
else return false;
});
client.on('message', (msg) => {
if (msg.guild && !msg.channel.permissionsFor(client.user).has('SEND_MESSAGES')) return;
if (/(discord(\.gg\/|app\.com\/invite\/|\.me\/))/gi.test(msg.content)) {
if (!msg.guild || !msg.guild.settings.get('inviteGuard')) return;
if (msg.author.bot || msg.member.hasPermission('ADMINISTRATOR')) return;
if (!msg.channel.permissionsFor(client.user).has('MANAGE_MESSAGES')) {
msg.say('Could not delete invite, missing permissions.');
return;
}
msg.delete();
msg.reply('Invites are prohibited from being posted here.');
}
});
client.on('messageReactionAdd', (reaction, user) => {
if (reaction.emoji.name !== '⭐') return;
const msg = reaction.message;
const channel = msg.guild.channels.get(msg.guild.settings.get('starboard'));
if (!channel || !msg.channel.permissionsFor(client.user).has(['SEND_MESSAGES', 'MANAGE_MESSAGES'])) return;
if (user.id === msg.author.id) {
reaction.remove(user);
msg.reply('You cannot star your own messages, baka.');
return;
}
client.registry.resolveCommand('random:star').run(msg, { id: msg.id }, true);
});
client.on('guildMemberAdd', (member) => {
const role = member.guild.roles.get(member.guild.settings.get('joinRole'));
if (role && member.guild.me.hasPermission('MANAGE_ROLES')) member.addRole(role).catch(() => null);
const channel = member.guild.channels.get(member.guild.settings.get('memberLog'));
const channel = member.guild.channels.find('name', 'member-log');
if (!channel || !channel.permissionsFor(client.user).has('SEND_MESSAGES')) return;
const msg = member.guild.settings.get('joinMsg', 'Welcome <user>!')
.replace(/(<user>)/gi, member.user.username)
.replace(/(<server>)/gi, member.guild.name)
.replace(/(<mention>)/gi, member);
channel.send(msg);
channel.send(`Welcome ${member.username}!`);
});
client.on('guildMemberRemove', (member) => {
const channel = member.guild.channels.get(member.guild.settings.get('memberLog'));
const channel = member.guild.channels.find('name', 'member-log');
if (!channel || !channel.permissionsFor(client.user).has('SEND_MESSAGES')) return;
const msg = member.guild.settings.get('leaveMsg', 'Bye <user>...')
.replace(/(<user>)/gi, member.user.username)
.replace(/(<server>)/gi, member.guild.name)
.replace(/(<mention>)/gi, member);
channel.send(msg);
channel.send(`Bye ${member.username}...`);
});
client.on('guildCreate', async (guild) => {
@@ -126,11 +79,6 @@ client.on('guildDelete', async (guild) => {
dBots(count, client.user.id);
});
client.setTimeout(() => {
console.log(`[RESTART] Shard ${client.shard.id} Restarted.`);
process.exit(0);
}, 14400000);
client.login(TOKEN);
process.on('unhandledRejection', console.error);
-10
View File
@@ -1,10 +0,0 @@
[
"inviteGuard",
"modLog",
"memberLog",
"joinMsg",
"leaveMsg",
"singleRole",
"joinRole",
"starboard"
]
+1 -1
View File
@@ -15,7 +15,7 @@ module.exports = class YearsCommand extends Command {
description: 'Draws a user\'s avatar over Pokémon\'s "It\'s been 3000 years" meme.',
throttling: {
usages: 1,
duration: 15
duration: 30
},
clientPermissions: ['ATTACH_FILES'],
args: [
+1 -1
View File
@@ -15,7 +15,7 @@ module.exports = class BeautifulCommand extends Command {
description: 'Draws a user\'s avatar over Gravity Falls\' "Oh, this? This is beautiful." meme.',
throttling: {
usages: 1,
duration: 15
duration: 30
},
clientPermissions: ['ATTACH_FILES'],
args: [
+1 -1
View File
@@ -15,7 +15,7 @@ module.exports = class BobRossCommand extends Command {
description: 'Draws a user\'s avatar over Bob Ross\' canvas.',
throttling: {
usages: 1,
duration: 15
duration: 30
},
clientPermissions: ['ATTACH_FILES'],
args: [
+1 -1
View File
@@ -18,7 +18,7 @@ module.exports = class CardCommand extends Command {
guildOnly: true,
throttling: {
usages: 1,
duration: 15
duration: 30
},
clientPermissions: ['ATTACH_FILES'],
args: [
+1 -1
View File
@@ -14,7 +14,7 @@ module.exports = class ChallengerCommand extends Command {
description: 'Draws a user\'s avatar over Super Smash Bros.\'s "Challenger Approaching" screen.',
throttling: {
usages: 1,
duration: 15
duration: 30
},
clientPermissions: ['ATTACH_FILES'],
args: [
+1 -1
View File
@@ -14,7 +14,7 @@ module.exports = class DexterCommand extends Command {
description: 'Draws a user\'s avatar over Dexter from Pokémon\'s screen.',
throttling: {
usages: 1,
duration: 15
duration: 30
},
clientPermissions: ['ATTACH_FILES'],
args: [
+1 -1
View File
@@ -12,7 +12,7 @@ module.exports = class GreyscaleCommand extends Command {
description: 'Draws a user\'s avatar in greyscale.',
throttling: {
usages: 1,
duration: 15
duration: 30
},
clientPermissions: ['ATTACH_FILES'],
args: [
+1 -1
View File
@@ -11,7 +11,7 @@ module.exports = class InvertCommand extends Command {
description: 'Draws a user\'s avatar inverted.',
throttling: {
usages: 1,
duration: 15
duration: 30
},
clientPermissions: ['ATTACH_FILES'],
args: [
+1 -1
View File
@@ -15,7 +15,7 @@ module.exports = class RIPCommand extends Command {
description: 'Draws a user\'s avatar over a gravestone.',
throttling: {
usages: 1,
duration: 15
duration: 30
},
clientPermissions: ['ATTACH_FILES'],
args: [
+1 -1
View File
@@ -14,7 +14,7 @@ module.exports = class SimbaCommand extends Command {
description: 'Draws a user\'s avatar over Simba from The Lion King\'s reflection.',
throttling: {
usages: 1,
duration: 15
duration: 30
},
clientPermissions: ['ATTACH_FILES'],
args: [
+1 -1
View File
@@ -14,7 +14,7 @@ module.exports = class SteamCardCommand extends Command {
description: 'Draws a user\'s avatar over a Steam card.',
throttling: {
usages: 1,
duration: 15
duration: 30
},
clientPermissions: ['ATTACH_FILES'],
args: [
+1 -1
View File
@@ -14,7 +14,7 @@ module.exports = class TriggeredCommand extends Command {
description: 'Draws a user\'s avatar over a Triggered meme.',
throttling: {
usages: 1,
duration: 15
duration: 30
},
clientPermissions: ['ATTACH_FILES'],
args: [
+1 -1
View File
@@ -14,7 +14,7 @@ module.exports = class WantedCommand extends Command {
description: 'Draws a user\'s avatar over a wanted poster.',
throttling: {
usages: 1,
duration: 15
duration: 30
},
clientPermissions: ['ATTACH_FILES'],
args: [
+1 -1
View File
@@ -33,7 +33,7 @@ module.exports = class BanCommand extends Command {
}
async run(msg, args) {
const modlogs = msg.guild.channels.get(msg.guild.settings.get('modLog'));
const modlogs = msg.guild.channels.find('name', 'mod-log');
const { member, reason } = args;
if (!member.bannable) return msg.say('This member is not bannable. Perhaps they have a higher role than me?');
await msg.say(`Are you sure you want to ban ${member.user.tag} (${member.id})?`);
+1 -1
View File
@@ -33,7 +33,7 @@ module.exports = class KickCommand extends Command {
}
async run(msg, args) {
const modlogs = msg.guild.channels.get(msg.guild.settings.get('modLog'));
const modlogs = msg.guild.channels.find('name', 'mod-log');
const { member, reason } = args;
if (!member.kickable) return msg.say('This member is not kickable. Perhaps they have a higher role than me?');
await msg.say(`Are you sure you want to kick ${member.user.tag} (${member.id})?`);
+1 -1
View File
@@ -33,7 +33,7 @@ module.exports = class SoftbanCommand extends Command {
}
async run(msg, args) {
const modlogs = msg.guild.channels.get(msg.guild.settings.get('modLog'));
const modlogs = msg.guild.channels.find('name', 'mod-log');
const { member, reason } = args;
if (!member.bannable) return msg.say('This member is not bannable. Perhaps they have a higher role than me?');
await msg.say(`Are you sure you want to softban ${member.user.tag} (${member.id})?`);
+1 -1
View File
@@ -33,7 +33,7 @@ module.exports = class UnbanCommand extends Command {
}
async run(msg, args) {
const modlogs = msg.guild.channels.get(msg.guild.settings.get('modLog'));
const modlogs = msg.guild.channels.find('name', 'mod-log');
const { id, reason } = args;
const bans = await msg.guild.fetchBans();
if (!bans.has(id)) return msg.say('This ID is not in the Guild Banlist.');
+1 -1
View File
@@ -32,7 +32,7 @@ module.exports = class WarnCommand extends Command {
}
async run(msg, args) {
const modlogs = msg.guild.channels.get(msg.guild.settings.get('modLog'));
const modlogs = msg.guild.channels.find('name', 'mod-log');
const { member, reason } = args;
await msg.say(`Are you sure you want to warn ${member.user.tag} (${member.id})?`);
const msgs = await msg.channel.awaitMessages((res) => res.author.id === msg.author.id, {
-51
View File
@@ -1,51 +0,0 @@
const Command = require('../../structures/Command');
const { RichEmbed } = require('discord.js');
const { stripIndents } = require('common-tags');
const moment = require('moment');
module.exports = class StarCommand extends Command {
constructor(client) {
super(client, {
name: 'star',
group: 'random',
memberName: 'star',
description: 'Stars a message, sending it to the starboard.',
args: [
{
key: 'id',
prompt: 'What is the ID of the message you wish to star?',
type: 'string'
}
]
});
this.starred = [];
}
async run(msg, args, reaction) {
const { id } = args;
const channel = msg.guild.channels.get(msg.guild.settings.get('starboard'));
if (!channel || this.starred.includes(id)) return null;
const message = await msg.channel.fetchMessage(id);
if (!reaction && msg.author.id === message.author.id) return msg.reply('You cannot star your own messages.');
this.starred.push(id);
if (!channel.permissionsFor(this.client.user).has('SEND_MESSAGES')) {
return msg.say('Could not send the message to the starboard.');
} else if (channel.permissionsFor(this.client.user).has('EMBED_LINKS')) {
const embed = new RichEmbed()
.setColor(0xFFFF00)
.setAuthor(message.author.tag, message.author.displayAvatarURL)
.setDescription(message.content)
.setImage(message.attachments.first() ? message.attachments.first().url : null)
.setFooter(moment(message.createdTimestamp).format('MMMM Do YYYY h:mm:ss A'));
return channel.send({ embed });
} else {
return msg.say(stripIndents`
**Author:** ${message.author.tag}
**Content:** ${message.content}
**Date:** ${moment(message.createdTimestamp).format('MMMM Do YYYY h:mm:ss A')}
${message.attachments.first() ? `**Image:** ${message.attachments.first().url}` : ''}
`);
}
}
};
-32
View File
@@ -1,32 +0,0 @@
const Command = require('../../structures/Command');
const settings = require('../../assets/json/clear-setting');
module.exports = class ClearSettingCommand extends Command {
constructor(client) {
super(client, {
name: 'clear-setting',
group: 'settings',
memberName: 'clear-setting',
description: 'Removes a custom setting from your server.',
guildOnly: true,
userPermissions: ['ADMINISTRATOR'],
args: [
{
key: 'setting',
prompt: 'What setting do you want to clear?',
type: 'string',
validate: (setting) => {
if (settings.includes(setting)) return true;
else return `Please enter one of the following: ${settings.join(', ')}`;
}
}
]
});
}
run(msg, args) {
const { setting } = args;
msg.guild.settings.remove(setting);
return msg.say(`${setting} has been removed from your server settings.`);
}
};
-19
View File
@@ -1,19 +0,0 @@
const Command = require('../../structures/Command');
module.exports = class InviteGuardCommand extends Command {
constructor(client) {
super(client, {
name: 'invite-guard',
group: 'settings',
memberName: 'invite-guard',
description: 'Turns on auto-deletion of invites.',
guildOnly: true,
userPermissions: ['ADMINISTRATOR']
});
}
run(msg) {
msg.guild.settings.set('inviteGuard', true);
return msg.say('Invite Guard is now active.');
}
};
-27
View File
@@ -1,27 +0,0 @@
const Command = require('../../structures/Command');
module.exports = class JoinRoleCommand extends Command {
constructor(client) {
super(client, {
name: 'join-role',
group: 'settings',
memberName: 'join-role',
description: 'Sets a role that new members are automatically joined to.',
guildOnly: true,
userPermissions: ['ADMINISTRATOR'],
args: [
{
key: 'role',
prompt: 'What role should new members be joined to?',
type: 'role'
}
]
});
}
run(msg, args) {
const { role } = args;
msg.guild.settings.set('joinRole', role.id);
return msg.say(`Join Role set to ${role.name}.`);
}
};
-27
View File
@@ -1,27 +0,0 @@
const Command = require('../../structures/Command');
module.exports = class MemberLogCommand extends Command {
constructor(client) {
super(client, {
name: 'member-channel',
group: 'settings',
memberName: 'member-channel',
description: 'Sets a channel for member join/leave logs to be sent.',
guildOnly: true,
userPermissions: ['ADMINISTRATOR'],
args: [
{
key: 'channel',
prompt: 'What is the channel you want to send logs to?',
type: 'channel'
}
]
});
}
run(msg, args) {
const { channel } = args;
msg.guild.settings.set('memberLog', channel.id);
return msg.say(`Member Log channel set to ${channel.name}.`);
}
};
-47
View File
@@ -1,47 +0,0 @@
const Command = require('../../structures/Command');
module.exports = class MemberMsgCommand extends Command {
constructor(client) {
super(client, {
name: 'member-message',
aliases: ['member-msg'],
group: 'settings',
memberName: 'member-message',
description: 'Sets the message for either join/leave logs to use.',
details: '**Placeholders:** <user>: Username, <server>: Server Name, <mention>: A Mention of the User',
guildOnly: true,
userPermissions: ['ADMINISTRATOR'],
args: [
{
key: 'type',
prompt: 'Which message would you like to change? Please enter either `joinMsg` or `leaveMsg`.',
type: 'string',
validate: (type) => {
if (['joinMsg', 'leaveMsg'].includes(type)) return true;
else return 'Please enter either `joinMsg` or `leaveMsg`.';
}
},
{
key: 'message',
prompt: 'What should be sent to the channel? Use <user>, <server>, and <mention> as placeholders.',
type: 'string',
validate: (message) => {
if (message.length < 150) return true;
else return 'Invalid Message. Message must be under 150 characters.';
}
}
]
});
}
run(msg, args) {
const { type, message } = args;
if (type === 'joinMsg') {
msg.guild.settings.set('joinMsg', message);
return msg.say(`Join Message set to "${message}".`);
} else {
msg.guild.settings.set('leaveMsg', message);
return msg.say(`Leave Message set to "${message}".`);
}
}
};
-27
View File
@@ -1,27 +0,0 @@
const Command = require('../../structures/Command');
module.exports = class ModChannelCommand extends Command {
constructor(client) {
super(client, {
name: 'mod-channel',
group: 'settings',
memberName: 'mod-channel',
description: 'Sets a channel for mod logs to be sent.',
guildOnly: true,
userPermissions: ['ADMINISTRATOR'],
args: [
{
key: 'channel',
prompt: 'What is the channel you want to send logs to?',
type: 'channel'
}
]
});
}
run(msg, args) {
const { channel } = args;
msg.guild.settings.set('modLog', channel.id);
return msg.say(`Mod Log channel set to ${channel.name}.`);
}
};
-33
View File
@@ -1,33 +0,0 @@
const Command = require('../../structures/Command');
const { stripIndents } = require('common-tags');
module.exports = class SettingListCommand extends Command {
constructor(client) {
super(client, {
name: 'setting-list',
group: 'settings',
memberName: 'setting-list',
description: 'Shows a list of current guild settings.',
guildOnly: true
});
}
run(msg) {
const modLog = msg.guild.channels.get(msg.guild.settings.get('modLog'));
const memberLog = msg.guild.channels.get(msg.guild.settings.get('memberLog'));
const singleRole = msg.guild.roles.get(msg.guild.settings.get('singleRole'));
const joinRole = msg.guild.roles.get(msg.guild.settings.get('joinRole'));
const starboard = msg.guild.channels.get(msg.guild.settings.get('starboard'));
return msg.say(stripIndents`
**Prefix:** ${msg.guild.commandPrefix}
**Invite Guard:** ${msg.guild.settings.get('inviteGuard', false)}
**Mod Channel:** ${modLog ? modLog.name : 'None'}
**Starboard:** ${starboard ? starboard.name : 'None'}
**Join Role:** ${joinRole ? joinRole.name : 'None'}
**Member Channel:** ${memberLog ? memberLog.name : 'None'}
**Join Message:** ${msg.guild.settings.get('joinMsg', 'Welcome <user>! (Default)')}
**Leave Message:** ${msg.guild.settings.get('leaveMsg', 'Bye <user>... (Default)')}
**Single Role:** ${singleRole ? singleRole.name : 'None'}
`);
}
};
-27
View File
@@ -1,27 +0,0 @@
const Command = require('../../structures/Command');
module.exports = class SingleRoleCommand extends Command {
constructor(client) {
super(client, {
name: 'single-role',
group: 'settings',
memberName: 'single-role',
description: 'Sets a single role that is able to use commands.',
guildOnly: true,
userPermissions: ['ADMINISTRATOR'],
args: [
{
key: 'role',
prompt: 'What role should be able to use commands?',
type: 'role'
}
]
});
}
run(msg, args) {
const { role } = args;
msg.guild.settings.set('singleRole', role.id);
return msg.say(`Single role mode has been enabled with the role ${role.name}.`);
}
};
-27
View File
@@ -1,27 +0,0 @@
const Command = require('../../structures/Command');
module.exports = class StarboardCommand extends Command {
constructor(client) {
super(client, {
name: 'starboard',
group: 'settings',
memberName: 'starboard',
description: 'Sets a channel for the starboard.',
guildOnly: true,
userPermissions: ['ADMINISTRATOR'],
args: [
{
key: 'channel',
prompt: 'What is the channel you want to set as the starboard?',
type: 'channel'
}
]
});
}
run(msg, args) {
const { channel } = args;
msg.guild.settings.set('starboard', channel.id);
return msg.say(`Starboard set to ${channel.name}.`);
}
};
+2 -7
View File
@@ -20,14 +20,13 @@
<li>Minecraft Achievement Generation!</li>
<li>Meme Generation!</li>
<li>Pokémon Fusion!</li>
<li>Moderation Commands including Ban/Kick/Softban/Unban/Warn, Lockdown, and Prune, with Customizable Logging!</li>
<li>Moderation Commands including Ban/Kick/Softban/Unban/Warn, Lockdown, and Prune, with Logging!</li>
<li>Currency and Temperature Conversion!</li>
<li>Math Calculator!</li>
<li>Cleverbot!</li>
<li>Tons of Secret Easter Eggs to discover!</li>
<li>Horoscopes!</li>
<li>LMGTFY Link Generation!</li>
<li>Starboard!</li>
<li>Strawpoll Generation!</li>
<li>Events that Happened today in history!</li>
<li>Would you rather questions!</li>
@@ -64,11 +63,7 @@
<li>Translate Text to almost 100 languages!</li>
<li>Binary, Morse, Pirate, and Temmie Translators!</li>
<li>Cowsay, Embed, Reverse, Upside Down, and Zalgo Text!</li>
<li>Customizable Prefix!</li>
<li>Protect your server against Invite Advertising!</li>
<li>Add a role to a user on join!</li>
<li>Member Join/Leave Logging to a Customizable Channel, with a Customizable Message!</li>
<li>Optional "Single Role Mode" where only one role can use the bot's commands!</li>
<li>Member Join/Leave Logging!</li>
<li>And so so so much more!</li>
</ol>
</div>
+2 -2
View File
@@ -12,8 +12,8 @@
<div class="xiaobox2">
<h2>Notes</h2>
<ol>
<li>Moderation commands require a channel set with x;modchannel to send Ban/Kick/Softban/Unban/Warn logs.</li>
<li>To use member join/leave logging, set a channel with x;memberchannel. A custom message can be set with x;membermsg.</li>
<li>Moderation commands require a channel named mod-log to send Ban/Kick/Softban/Unban/Warn logs.</li>
<li>To use member join/leave logging, create a channel named member-log.</li>
<li>Use x;help to view a command list</li>
<li>Visit my <a href="https://discord.gg/fqQF8mc">home server</a> for more support, or for updates, or if you just want to hang out.</li>
</ol>
+4 -9
View File
@@ -17,14 +17,13 @@
<li>Minecraft Achievement Generation!</li>
<li>Meme Generation!</li>
<li>Pokémon Fusion!</li>
<li>Moderation Commands including Ban/Kick/Softban/Unban/Warn, Lockdown, and Prune, with Customizable Logging!</li>
<li>Moderation Commands including Ban/Kick/Softban/Unban/Warn, Lockdown, and Prune, with Logging!</li>
<li>Currency and Temperature Conversion!</li>
<li>Math Calculator!</li>
<li>Cleverbot!</li>
<li>Tons of Secret Easter Eggs to discover!</li>
<li>Horoscopes!</li>
<li>LMGTFY Link Generation!</li>
<li>Starboard!</li>
<li>Strawpoll Generation!</li>
<li>Events that Happened today in history!</li>
<li>Would you rather questions!</li>
@@ -61,18 +60,14 @@
<li>Translate Text to almost 100 languages!</li>
<li>Binary, Morse, Pirate, and Temmie Translators!</li>
<li>Cowsay, Embed, Reverse, Upside Down, and Zalgo Text!</li>
<li>Customizable Prefix!</li>
<li>Protect your server against Invite Advertising!</li>
<li>Add a role to a user on join!</li>
<li>Member Join/Leave Logging to a Customizable Channel, with a Customizable Message!</li>
<li>Optional "Single Role Mode" where only one role can use the bot's commands!</li>
<li>Member Join/Leave Logging!</li>
<li>And so so so much more!</li>
</ul>
</ol>
<h2>Notes</h2>
<ol>
<li>Moderation commands require a channel set with x;modchannel to send Ban/Kick/Softban/Unban/Warn logs.</li>
<li>To use member join/leave logging, set a channel with x;memberchannel. A custom message can be set with x;membermsg.</li>
<li>Moderation commands require a channel named mod-log to send Ban/Kick/Softban/Unban/Warn logs.</li>
<li>To use member join/leave logging, create a channel named member-log.</li>
<li>Use x;help to view a command list</li>
<li>Visit my <a href="https://discord.gg/fqQF8mc">home server</a> for more support, or for updates, or if you just want to hang out.</li>
</ol>
+1 -5
View File
@@ -1,6 +1,6 @@
{
"name": "xiaobot",
"version": "24.0.0",
"version": "25.0.0",
"description": "Your personal server companion.",
"main": "Shard.js",
"scripts": {
@@ -20,8 +20,6 @@
"discord-bot",
"discord-js",
"discord-js-commando",
"postgres",
"postgresql",
"cleverbot"
],
"author": "dragonfire535 <danielbodendahl@gmail.com>",
@@ -45,8 +43,6 @@
"mathjs": "^3.13.3",
"moment": "^2.18.1",
"moment-duration-format": "^1.3.0",
"pg": "^6.2.4",
"sequelize": "^4.1.0",
"snekfetch": "^3.1.11",
"tsubaki": "^1.1.1",
"xml2js": "^0.4.17",
-239
View File
@@ -1,239 +0,0 @@
const { SettingProvider } = require('discord.js-commando');
const Sequelize = require('sequelize');
/**
* Uses an PostgreSQL database to store settings with guilds
* @extends {SettingProvider}
*/
class SequelizeProvider extends SettingProvider {
/**
* @external PostgreSQLDatabase
* @see {@link https://www.npmjs.com/package/sequelize}
*/
/**
* @param {SQLDatabase} db - Database for the provider
*/
constructor(db) {
super();
/**
* Database that will be used for storing/retrieving settings
* @type {SQLDatabase}
*/
this.db = db;
/**
* Client that the provider is for (set once the client is ready)
* @name SequelizeProvider#client
* @type {CommandoClient}
* @readonly
*/
Object.defineProperty(this, 'client', { value: null, writable: true });
/**
* Settings cached in memory, mapped by guild ID (or 'global')
* @type {Map}
* @private
*/
this.settings = new Map();
/**
* Listeners on the Client, mapped by the event name
* @type {Map}
* @private
*/
this.listeners = new Map();
/**
* Sequelize Model Object
* @type {SequelizeModel}
* @private
*/
this.model = this.db.define('settings', {
guild: {
type: Sequelize.STRING,
allowNull: false,
unique: true,
primaryKey: true
},
settings: { type: Sequelize.TEXT }
});
/**
* @external SequelizeModel
* @see {@link http://docs.sequelizejs.com/en/latest/api/model/}
*/
}
async init(client) {
this.client = client;
await this.db.sync();
// Load all settings
const rows = await this.model.findAll();
for (const row of rows) {
let settings;
try {
settings = JSON.parse(row.dataValues.settings);
} catch (err) {
client.emit('warn', `SequelizeProvider couldn't parse the settings stored for guild ${row.dataValues.guild}.`); // eslint-disable-line max-len
continue;
}
const guild = row.dataValues.guild !== '0' ? row.dataValues.guild : 'global';
this.settings.set(guild, settings);
if (guild !== 'global' && !client.guilds.has(row.dataValues.guild)) continue;
this.setupGuild(guild, settings);
}
// Listen for changes
this.listeners
.set('commandPrefixChange', (guild, prefix) => this.set(guild, 'prefix', prefix))
.set('commandStatusChange', (guild, command, enabled) => this.set(guild, `cmd-${command.name}`, enabled))
.set('groupStatusChange', (guild, group, enabled) => this.set(guild, `grp-${group.id}`, enabled))
.set('guildCreate', (guild) => {
const settings = this.settings.get(guild.id);
if (!settings) return;
this.setupGuild(guild.id, settings);
})
.set('commandRegister', (command) => {
for (const [guild, settings] of this.settings) {
if (guild !== 'global' && !client.guilds.has(guild)) continue;
this.setupGuildCommand(client.guilds.get(guild), command, settings);
}
})
.set('groupRegister', (group) => {
for (const [guild, settings] of this.settings) {
if (guild !== 'global' && !client.guilds.has(guild)) continue;
this.setupGuildGroup(client.guilds.get(guild), group, settings);
}
});
for (const [event, listener] of this.listeners) client.on(event, listener);
}
destroy() {
// Remove all listeners from the client
for (const [event, listener] of this.listeners) this.client.removeListener(event, listener);
this.listeners.clear();
}
get(guild, key, defVal) {
const settings = this.settings.get(this.constructor.getGuildID(guild));
return settings ? typeof settings[key] !== 'undefined' ? settings[key] : defVal : defVal;
}
async set(guild, key, val) {
guild = this.constructor.getGuildID(guild);
let settings = this.settings.get(guild);
if (!settings) {
settings = {};
this.settings.set(guild, settings);
}
settings[key] = val;
await this.model.upsert(
{ guild: guild !== 'global' ? guild : '0', settings: JSON.stringify(settings) },
{ where: { guild: guild !== 'global' ? guild : '0' } }
);
if (guild === 'global') this.updateOtherShards(key, val);
return val;
}
async remove(guild, key) {
guild = this.constructor.getGuildID(guild);
const settings = this.settings.get(guild);
if (!settings || typeof settings[key] === 'undefined') return undefined;
const val = settings[key];
settings[key] = undefined;
await this.model.upsert(
{ guild: guild !== 'global' ? guild : '0', settings: JSON.stringify(settings) },
{ where: { guild: guild !== 'global' ? guild : '0' } }
);
if (guild === 'global') this.updateOtherShards(key, undefined);
return val;
}
async clear(guild) {
guild = this.constructor.getGuildID(guild);
if (!this.settings.has(guild)) return;
this.settings.delete(guild);
await this.model.destroy({ where: { guild: guild !== 'global' ? guild : '0' } });
}
/**
* Loads all settings for a guild
* @param {string} guild - Guild ID to load the settings of (or 'global')
* @param {Object} settings - Settings to load
* @private
*/
setupGuild(guild, settings) {
if (typeof guild !== 'string') throw new TypeError('The guild must be a guild ID or "global".');
guild = this.client.guilds.get(guild) || null;
// Load the command prefix
if (typeof settings.prefix !== 'undefined') {
if (guild) guild._commandPrefix = settings.prefix;
else this.client._commandPrefix = settings.prefix;
}
// Load all command/group statuses
for (const command of this.client.registry.commands.values()) this.setupGuildCommand(guild, command, settings);
for (const group of this.client.registry.groups.values()) this.setupGuildGroup(guild, group, settings);
}
/**
* Sets up a command's status in a guild from the guild's settings
* @param {?Guild} guild - Guild to set the status in
* @param {Command} command - Command to set the status of
* @param {Object} settings - Settings of the guild
* @private
*/
setupGuildCommand(guild, command, settings) {
if (typeof settings[`cmd-${command.name}`] === 'undefined') return;
if (guild) {
if (!guild._commandsEnabled) guild._commandsEnabled = {};
guild._commandsEnabled[command.name] = settings[`cmd-${command.name}`];
} else {
command._globalEnabled = settings[`cmd-${command.name}`];
}
}
/**
* Sets up a group's status in a guild from the guild's settings
* @param {?Guild} guild - Guild to set the status in
* @param {CommandGroup} group - Group to set the status of
* @param {Object} settings - Settings of the guild
* @private
*/
setupGuildGroup(guild, group, settings) {
if (typeof settings[`grp-${group.id}`] === 'undefined') return;
if (guild) {
if (!guild._groupsEnabled) guild._groupsEnabled = {};
guild._groupsEnabled[group.id] = settings[`grp-${group.id}`];
} else {
group._globalEnabled = settings[`grp-${group.id}`];
}
}
/**
* Updates a global setting on all other shards if using the {@link ShardingManager}.
* @param {string} key - Key of the setting to update
* @param {*} val - Value of the setting
* @private
*/
updateOtherShards(key, val) {
if (!this.client.shard) return;
key = JSON.stringify(key);
val = typeof val !== 'undefined' ? JSON.stringify(val) : 'undefined';
this.client.shard.broadcastEval(`
if(this.shard.id !== ${this.client.shard.id} && this.provider && this.provider.settings) {
this.provider.settings.global[${key}] = ${val};
}
`);
}
}
module.exports = SequelizeProvider;
+4
View File
@@ -8,6 +8,10 @@ class XiaoCommand extends Command {
this.nsfw = info.nsfw;
this.clientPermissions = info.clientPermissions;
this.userPermissions = info.userPermissions;
this.throttling = {
usages: 1,
duration: 2
};
}
hasPermission(msg) {
-13
View File
@@ -1,13 +0,0 @@
const { Client } = require('discord.js-commando');
const Database = require('./PostgreSQL');
class CommandoClient extends Client {
constructor(options) {
super(options);
this.database = Database.db;
Database.start();
}
}
module.exports = CommandoClient;
-23
View File
@@ -1,23 +0,0 @@
const Sequelize = require('sequelize');
const { DATABASE_URL } = process.env;
const database = new Sequelize(DATABASE_URL, { logging: false });
class Database {
static get db() {
return database;
}
static start() {
database.authenticate()
.then(() => console.log('[DATABASE] Connection has been established successfully.'))
.then(() => console.log('[DATABASE] Synchronizing...'))
.then(() => database.sync()
.then(() => console.log('[DATABASE] Synchronizing complete!'))
.catch((err) => console.error(`[DATABASE] Error synchronizing: ${err}`))
)
.then(() => console.log('[DATABASE] Ready!'))
.catch((err) => console.error(`[DATABASE] Unable to connect: ${err}`));
}
}
module.exports = Database;