diff --git a/XiaoBot.js b/XiaoBot.js index b605236e..7af5466f 100644 --- a/XiaoBot.js +++ b/XiaoBot.js @@ -12,7 +12,7 @@ const client = new Client({ messageSweepInterval: 120 }); const SequelizeProvider = require('./providers/Sequelize'); -const { postStats, filterTopics, parseTopic } = require('./structures/Util'); +const { postStats } = require('./structures/Util'); client.registry .registerDefaultTypes() @@ -57,28 +57,6 @@ client.on('warn', console.warn); client.on('commandError', (command, err) => console.error(command.name, err)); -client.on('guildMemberAdd', member => { - if (!member) return; - const channel = filterTopics(member.guild.channels, 'memberlog').first(); - if (!channel) return; - const msg = parseTopic(channel.topic, 'joinmessage') - .replace(/{{member}}/gi, member.user.username) - .replace(/{{server}}/gi, member.guild.name) - .replace(/{{mention}}/gi, member); - channel.send(msg || `Welcome ${member.user.username}!`); -}); - -client.on('guildMemberRemove', member => { - if (!member) return; - const channel = filterTopics(member.guild.channels, 'memberlog').first(); - if (!channel) return; - const msg = parseTopic(channel.topic, 'leavemessage') - .replace(/{{member}}/gi, member.user.username) - .replace(/{{server}}/gi, member.guild.name) - .replace(/{{mention}}/gi, member); - channel.send(msg || `Bye ${member.user.username}...`); -}); - client.on('guildCreate', async guild => { console.log(`[GUILD] I have joined ${guild.name}! (${guild.id})`); const guilds = await client.shard.fetchClientValues('guilds.size'); diff --git a/commands/moderation/ban.js b/commands/moderation/ban.js index 47f29c92..4ef9e9ce 100644 --- a/commands/moderation/ban.js +++ b/commands/moderation/ban.js @@ -1,7 +1,5 @@ const Command = require('../../structures/Command'); -const { MessageEmbed } = require('discord.js'); const { stripIndents } = require('common-tags'); -const { filterTopics } = require('../../structures/Util'); module.exports = class BanCommand extends Command { constructor(client) { @@ -10,7 +8,7 @@ module.exports = class BanCommand extends Command { aliases: ['banne'], group: 'moderation', memberName: 'ban', - description: 'Bans a user and logs the ban to the mod logs.', + description: 'Bans a user.', guildOnly: true, clientPermissions: ['BAN_MEMBERS'], userPermissions: ['BAN_MEMBERS'], @@ -34,7 +32,6 @@ module.exports = class BanCommand extends Command { } async run(msg, args) { - const modlogs = filterTopics(msg.guild.channels, 'modlog').first(); const { member, reason } = args; if (member.id === msg.author.id) return msg.say('I don\'t think you want to ban yourself...'); if (member.id === msg.guild.ownerID) return msg.say('Don\'t you think that might be betraying your leader?'); @@ -60,27 +57,6 @@ module.exports = class BanCommand extends Command { days: 7, reason: `${msg.author.tag}: ${reason}` }); - await msg.say(`Successfully banned ${member.user.tag}.`); - if (!modlogs || !modlogs.permissionsFor(this.client.user).has('SEND_MESSAGES')) { - return msg.say('Could not log the ban to the mod logs.'); - } else if (modlogs.permissionsFor(this.client.user).has('EMBED_LINKS')) { - const embed = new MessageEmbed() - .setAuthor(msg.author.tag, msg.author.displayAvatarURL()) - .setColor(0xFF0000) - .setTimestamp() - .setDescription(stripIndents` - **Member:** ${member.user.tag} (${member.id}) - **Action:** Ban - **Reason:** ${reason} - `); - return modlogs.send({ embed }); - } else { - return modlogs.send(stripIndents` - **Member:** ${member.user.tag} (${member.id}) - **Action:** Ban - **Reason:** ${reason} - **Moderator:** ${msg.author.tag} - `); - } + return msg.say(`Successfully banned ${member.user.tag}.`); } }; diff --git a/commands/moderation/hackban.js b/commands/moderation/hackban.js index cc0c0e97..ef0f95fa 100644 --- a/commands/moderation/hackban.js +++ b/commands/moderation/hackban.js @@ -1,7 +1,4 @@ const Command = require('../../structures/Command'); -const { MessageEmbed } = require('discord.js'); -const { stripIndents } = require('common-tags'); -const { filterTopics } = require('../../structures/Util'); module.exports = class HackbanCommand extends Command { constructor(client) { @@ -10,7 +7,7 @@ module.exports = class HackbanCommand extends Command { aliases: ['hackbanne'], group: 'moderation', memberName: 'hackban', - description: 'Bans a user who doesn\'t have to be in the server and logs the ban to the mod logs.', + description: 'Bans a user who doesn\'t have to be in the server.', guildOnly: true, clientPermissions: ['BAN_MEMBERS'], userPermissions: ['ADMINISTRATOR'], @@ -34,7 +31,6 @@ module.exports = class HackbanCommand extends Command { } async run(msg, args) { - const modlogs = filterTopics(msg.guild.channels, 'modlog').first(); const { id, reason } = args; if (id === msg.author.id) return msg.say('I don\'t think you want to ban yourself...'); if (id === msg.guild.ownerID) return msg.say('Don\'t you think that might be betraying your leader?'); @@ -44,7 +40,7 @@ module.exports = class HackbanCommand extends Command { } catch (err) { return msg.say('Could not resolve user.'); } - await msg.say(`Are you sure you want to ban ${user.tag} (${user.id})?`); + await msg.say(`Are you sure you want to hackban ${user.tag} (${user.id})?`); const msgs = await msg.channel.awaitMessages(res => res.author.id === msg.author.id, { max: 1, time: 30000 @@ -56,29 +52,8 @@ module.exports = class HackbanCommand extends Command { reason: `${msg.author.tag}: ${reason}` }); } catch (err) { - return msg.say(`Could not ban the user: \`${err.message}\``); - } - await msg.say(`Successfully banned ${user.tag}.`); - if (!modlogs || !modlogs.permissionsFor(this.client.user).has('SEND_MESSAGES')) { - return msg.say('Could not log the ban to the mod logs.'); - } else if (modlogs.permissionsFor(this.client.user).has('EMBED_LINKS')) { - const embed = new MessageEmbed() - .setAuthor(msg.author.tag, msg.author.displayAvatarURL()) - .setColor(0xA90000) - .setTimestamp() - .setDescription(stripIndents` - **Member:** ${user.tag} (${user.id}) - **Action:** Hackban - **Reason:** ${reason} - `); - return modlogs.send({ embed }); - } else { - return modlogs.send(stripIndents` - **Member:** ${user.tag} (${user.id}) - **Action:** Hackban - **Reason:** ${reason} - **Moderator:** ${msg.author.tag} - `); + return msg.say(`Could not hackban the user: \`${err.message}\``); } + return msg.say(`Successfully hackbanned ${user.tag}.`); } }; diff --git a/commands/moderation/kick.js b/commands/moderation/kick.js index 2edcc5be..c1620f00 100644 --- a/commands/moderation/kick.js +++ b/commands/moderation/kick.js @@ -1,7 +1,5 @@ const Command = require('../../structures/Command'); -const { MessageEmbed } = require('discord.js'); const { stripIndents } = require('common-tags'); -const { filterTopics } = require('../../structures/Util'); module.exports = class KickCommand extends Command { constructor(client) { @@ -10,7 +8,7 @@ module.exports = class KickCommand extends Command { aliases: ['kickke'], group: 'moderation', memberName: 'kick', - description: 'Kicks a user and logs the kick to the mod logs.', + description: 'Kicks a user.', guildOnly: true, clientPermissions: ['KICK_MEMBERS'], userPermissions: ['KICK_MEMBERS'], @@ -34,7 +32,6 @@ module.exports = class KickCommand extends Command { } async run(msg, args) { - const modlogs = filterTopics(msg.guild.channels, 'modlog').first(); const { member, reason } = args; if (member.id === msg.author.id) return msg.say('I don\'t think you want to kick yourself...'); if (member.id === msg.guild.ownerID) return msg.say('Don\'t you think that might be betraying your leader?'); @@ -57,27 +54,6 @@ module.exports = class KickCommand extends Command { await msg.say('Failed to send DM.'); } await member.kick(`${msg.author.tag}: ${reason}`); - await msg.say(`Successfully kicked ${member.user.tag}.`); - if (!modlogs || !modlogs.permissionsFor(this.client.user).has('SEND_MESSAGES')) { - return msg.say('Could not log the kick to the mod logs.'); - } else if (modlogs.permissionsFor(this.client.user).has('EMBED_LINKS')) { - const embed = new MessageEmbed() - .setAuthor(msg.author.tag, msg.author.displayAvatarURL()) - .setColor(0xFFA500) - .setTimestamp() - .setDescription(stripIndents` - **Member:** ${member.user.tag} (${member.id}) - **Action:** Kick - **Reason:** ${reason} - `); - return modlogs.send({ embed }); - } else { - return modlogs.send(stripIndents` - **Member:** ${member.user.tag} (${member.id}) - **Action:** Kick - **Reason:** ${reason} - **Moderator:** ${msg.author.tag} - `); - } + return msg.say(`Successfully kicked ${member.user.tag}.`); } }; diff --git a/commands/moderation/softban.js b/commands/moderation/softban.js index bffe6c65..21371f5b 100644 --- a/commands/moderation/softban.js +++ b/commands/moderation/softban.js @@ -1,7 +1,5 @@ const Command = require('../../structures/Command'); -const { MessageEmbed } = require('discord.js'); const { stripIndents } = require('common-tags'); -const { filterTopics } = require('../../structures/Util'); module.exports = class SoftbanCommand extends Command { constructor(client) { @@ -10,7 +8,7 @@ module.exports = class SoftbanCommand extends Command { aliases: ['softbanne'], group: 'moderation', memberName: 'softban', - description: 'Kicks a user and deletes their messages, and logs the softban to the mod logs.', + description: 'Kicks a user and deletes their messages.', guildOnly: true, clientPermissions: ['BAN_MEMBERS'], userPermissions: ['KICK_MEMBERS'], @@ -34,7 +32,6 @@ module.exports = class SoftbanCommand extends Command { } async run(msg, args) { - const modlogs = filterTopics(msg.guild.channels, 'modlog').first(); const { member, reason } = args; if (member.id === msg.author.id) return msg.say('I don\'t think you want to softban yourself...'); if (member.id === msg.guild.ownerID) return msg.say('Don\'t you think that might be betraying your leader?'); @@ -61,27 +58,6 @@ module.exports = class SoftbanCommand extends Command { reason: `${msg.author.tag}: ${reason} (Softban)` }); await msg.guild.unban(member.user, 'Softban'); - await msg.say(`Successfully softbanned ${member.user.tag}.`); - if (!modlogs || !modlogs.permissionsFor(this.client.user).has('SEND_MESSAGES')) { - return msg.say('Could not log the softban to the mod logs.'); - } else if (modlogs.permissionsFor(this.client.user).has('EMBED_LINKS')) { - const embed = new MessageEmbed() - .setAuthor(msg.author.tag, msg.author.displayAvatarURL()) - .setColor(0xFF4500) - .setTimestamp() - .setDescription(stripIndents` - **Member:** ${member.user.tag} (${member.id}) - **Action:** Softban - **Reason:** ${reason} - `); - return modlogs.send({ embed }); - } else { - return modlogs.send(stripIndents` - **Member:** ${member.user.tag} (${member.id}) - **Action:** Softban - **Reason:** ${reason} - **Moderator:** ${msg.author.tag} - `); - } + return msg.say(`Successfully softbanned ${member.user.tag}.`); } }; diff --git a/commands/moderation/unban.js b/commands/moderation/unban.js index 9b3e35b8..00183a65 100644 --- a/commands/moderation/unban.js +++ b/commands/moderation/unban.js @@ -1,7 +1,5 @@ const Command = require('../../structures/Command'); -const { MessageEmbed } = require('discord.js'); const { stripIndents } = require('common-tags'); -const { filterTopics } = require('../../structures/Util'); module.exports = class UnbanCommand extends Command { constructor(client) { @@ -10,7 +8,7 @@ module.exports = class UnbanCommand extends Command { aliases: ['unbanne'], group: 'moderation', memberName: 'unban', - description: 'Unbans a user and logs the unban to the mod logs.', + description: 'Unbans a user.', guildOnly: true, clientPermissions: ['BAN_MEMBERS'], userPermissions: ['BAN_MEMBERS'], @@ -34,7 +32,6 @@ module.exports = class UnbanCommand extends Command { } async run(msg, args) { - const modlogs = filterTopics(msg.guild.channels, 'modlog').first(); 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.'); @@ -46,27 +43,6 @@ module.exports = class UnbanCommand extends Command { }); if (!msgs.size || !['y', 'yes'].includes(msgs.first().content.toLowerCase())) return msg.say('Aborting.'); await msg.guild.unban(member, `${msg.author.tag}: ${reason}`); - await msg.say(`Successfully unbanned ${member.tag}.`); - if (!modlogs || !modlogs.permissionsFor(this.client.user).has('SEND_MESSAGES')) { - return msg.say('Could not log the unban to the mod logs.'); - } else if (modlogs.permissionsFor(this.client.user).has('EMBED_LINKS')) { - const embed = new MessageEmbed() - .setAuthor(msg.author.tag, msg.author.displayAvatarURL()) - .setColor(0x00AE86) - .setTimestamp() - .setDescription(stripIndents` - **Member:** ${member.tag} (${member.id}) - **Action:** Unban - **Reason:** ${reason} - `); - return modlogs.send({ embed }); - } else { - return modlogs.send(stripIndents` - **Member:** ${member.tag} (${member.id}) - **Action:** Unban - **Reason:** ${reason} - **Moderator:** ${msg.author.tag} - `); - } + return msg.say(`Successfully unbanned ${member.tag}.`); } }; diff --git a/commands/moderation/warn.js b/commands/moderation/warn.js deleted file mode 100644 index da5cab16..00000000 --- a/commands/moderation/warn.js +++ /dev/null @@ -1,81 +0,0 @@ -const Command = require('../../structures/Command'); -const { MessageEmbed } = require('discord.js'); -const { stripIndents } = require('common-tags'); -const { filterTopics } = require('../../structures/Util'); - -module.exports = class WarnCommand extends Command { - constructor(client) { - super(client, { - name: 'warn', - aliases: ['warnne'], - group: 'moderation', - memberName: 'warn', - description: 'Warns a user and logs the warn to the mod logs.', - guildOnly: true, - userPermissions: ['KICK_MEMBERS'], - args: [ - { - key: 'member', - prompt: 'What member do you want to warn?', - type: 'member' - }, - { - key: 'reason', - prompt: 'What do you want to set the reason as?', - type: 'string', - validate: reason => { - if (reason.length < 140) return true; - return 'Please keep the reason under 140 characters.'; - } - } - ] - }); - } - - async run(msg, args) { - const modlogs = filterTopics(msg.guild.channels, 'modlog').first(); - const { member, reason } = args; - if (member.id === msg.author.id) return msg.say('I don\'t think you want to warn yourself...'); - if (member.id === msg.guild.ownerID) return msg.say('Don\'t you think that might be betraying your leader?'); - if (!member.kickable) return msg.say('This member is not warnable. Perhaps they have a higher role than me?'); - if (member.highestRole.calculatedPosition > msg.member.highestRole.calculatedPosition - 1) { - return msg.say('Your roles are too low to warn this member.'); - } - 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, { - max: 1, - time: 30000 - }); - if (!msgs.size || !['y', 'yes'].includes(msgs.first().content.toLowerCase())) return msg.say('Aborting.'); - try { - await member.send(stripIndents` - You were warned in ${msg.guild.name} by ${msg.author.tag}! - **Reason:** ${reason} - `); - } catch (err) { - await msg.say('Failed to send DM.'); - } - await msg.say(`Successfully warned ${member.user.tag}.`); - if (!modlogs || !modlogs.permissionsFor(this.client.user).has('SEND_MESSAGES')) { - return msg.say('Could not log the warn to the mod logs.'); - } else if (modlogs.permissionsFor(this.client.user).has('EMBED_LINKS')) { - const embed = new MessageEmbed() - .setAuthor(msg.author.tag, msg.author.displayAvatarURL()) - .setColor(0xFFFF00) - .setTimestamp() - .setDescription(stripIndents` - **Member:** ${member.user.tag} (${member.id}) - **Action:** Warn - **Reason:** ${reason} - `); - return modlogs.send({ embed }); - } else { - return modlogs.send(stripIndents` - **Member:** ${member.user.tag} (${member.id}) - **Action:** Warn - **Reason:** ${reason} - **Moderator:** ${msg.author.tag} - `); - } - } -}; diff --git a/commands/text-edit/portal-send.js b/commands/text-edit/portal-send.js deleted file mode 100644 index cbe0e77c..00000000 --- a/commands/text-edit/portal-send.js +++ /dev/null @@ -1,39 +0,0 @@ -const Command = require('../../structures/Command'); -const { filterTopics } = require('../../structures/Util'); - -module.exports = class PortalSendCommand extends Command { - constructor(client) { - super(client, { - name: 'portal-send', - group: 'text-edit', - memberName: 'portal-send', - description: 'Send a message to a random channel that has a portal open.', - guildOnly: true, - args: [ - { - key: 'message', - prompt: 'What message do you want to send?', - type: 'string', - validate: message => { - if (message.length > 1500) return 'Message must be under 1500 characters.'; - if (!/discord(\.gg|app\.com\/invite|\.me)\//gi.test(message)) return true; - return 'Please do not send invites.'; - } - } - ] - }); - } - - async run(msg, args) { - const { message } = args; - const channels = this.client.channels.filter(c => c.type === 'text' && c.guild.id !== msg.guild.id); - const channel = filterTopics(channels, 'portal').random(); - if (!channel) return msg.say('Aww... No channel has an open portal...'); - try { - await channel.send(`**${msg.author.tag} (${msg.guild.name}):** ${message}`); - return msg.say(`Message sent to **${channel.guild.name}**!`); - } catch (err) { - return msg.say('Failed to send message...'); - } - } -}; diff --git a/commands/util/setting-help.js b/commands/util/setting-help.js deleted file mode 100644 index 6962b9d8..00000000 --- a/commands/util/setting-help.js +++ /dev/null @@ -1,28 +0,0 @@ -const Command = require('../../structures/Command'); -const { stripIndents } = require('common-tags'); - -module.exports = class SettingHelpCommand extends Command { - constructor(client) { - super(client, { - name: 'setting-help', - group: 'util', - memberName: 'setting-help', - description: 'View help on how to set up settings.', - guarded: true - }); - } - - run(msg) { - return msg.say(stripIndents` - __**Settings**__ - **Mod Log Channel:** Place \`\` in a channel's topic. - **Portal Channel:** Place \`\` in a channel's topic. - **Member Log Channel:** Place \`\` in a channel's topic. - **Custom Join Message:** Place \`message\` in the Member Log's topic. - **Custom Leave Message:** Place \`message\` in the Member Log's topic. - - __**Placeholders**__ - **Join/Leave Message:** \`{{member}}\`, \`{{server}}\`, \`{{mention}}\` - `); - } -}; diff --git a/package.json b/package.json index f6fe5fb7..abb8a708 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "37.5.5", + "version": "38.0.0", "description": "Your personal server companion.", "main": "Shard.js", "scripts": { diff --git a/structures/Util.js b/structures/Util.js index 9a4c88aa..1e370669 100644 --- a/structures/Util.js +++ b/structures/Util.js @@ -19,35 +19,6 @@ class Util { .catch(err => console.error(`[DBOTSORG] Failed to post to Discord Bots Org. ${err}`)); } - static filterTopics(channels, setting) { - return channels.filter(c => { - try { - if (c.type !== 'text' || !c.topic || !c.permissionsFor(c.client.user).has('SEND_MESSAGES')) return false; - return c.topic.includes(`<${setting}>`); - } catch (err) { - console.error(stripIndents` - ${err.name}: ${err.message} - Guild memberCount: ${c.guild.memberCount} - GuildMemberStore size: ${c.guild.members.size} - permissionsFor ClientUser: ${c.permissionsFor(c.client.user)} - GuildMember for ClientUser: ${c.guild.me} - Guild available: ${c.guild.available} - Guild ID: ${c.guild.id} - Channel ID: ${c.id} - `); - return false; - } - }); - } - - static parseTopic(topic, setting) { - const regex = new RegExp(`<${setting}>.+`, 'gi'); - if (!regex.test(topic)) return ''; - const parsed = topic.match(regex)[0]; - const word = `<${setting}>`; - return parsed.slice(word.length, parsed.length - (word.length + 1)); - } - static wait(time) { return promisify(setTimeout)(time); }