diff --git a/XiaoBot.js b/XiaoBot.js index 7af4e93f..f48451ac 100644 --- a/XiaoBot.js +++ b/XiaoBot.js @@ -12,11 +12,9 @@ const client = new CommandoClient({ 'VOICE_STATE_UPDATE', 'FRIEND_ADD', 'FRIEND_REMOVE' - ], - messageCacheLifetime: 60, - messageSweepInterval: 60 + ] }); -const { carbon, dBots, dBotsOrg, parseTopic, parseTopicMsg } = require('./structures/Util'); +const { carbon, dBots, dBotsOrg, filterTopics, parseTopic } = require('./structures/Util'); client.registry .registerDefaultTypes() @@ -64,10 +62,10 @@ client.on('commandRun', command => ++command.uses); client.on('message', async msg => { if (!msg.guild || msg.author.bot) return; - const topic = msg.guild.defaultChannel.topic || ''; - if (!topic.toLowerCase().includes('')) return; + const channel = filterTopics(msg.guild.channels, 'inviteguard'); + if (!channel.size) return; const member = await msg.guild.fetchMember(msg.author); - if (member.hasPermission('ADMINISTRATOR')) return; + if (member.hasPermission('ADMINISTRATOR') || msg.author.id === msg.guild.ownerID) return; if (/discord(\.gg\/|app\.com\/invite\/|\.me\/)/gi.test(msg.content)) { if (msg.channel.permissionsFor(client.user).has('MANAGE_MESSAGES')) msg.delete(); msg.reply('Invites are prohibited from being posted here.'); @@ -75,9 +73,9 @@ client.on('message', async msg => { }); client.on('guildMemberAdd', member => { - const channel = parseTopic(member.guild.channels, 'memberlog', client.user).first(); + const channel = filterTopics(member.guild.channels, 'memberlog').first(); if (!channel) return; - const msg = parseTopicMsg(channel.topic, 'joinmessage') + const msg = parseTopic(channel.topic, 'joinmessage') .replace(/{{member}}/gi, member.user.username) .replace(/{{server}}/gi, member.guild.name) .replace(/{{mention}}/gi, member); @@ -85,9 +83,9 @@ client.on('guildMemberAdd', member => { }); client.on('guildMemberRemove', member => { - const channel = parseTopic(member.guild.channels, 'memberlog', client.user).first(); + const channel = filterTopics(member.guild.channels, 'memberlog').first(); if (!channel) return; - const msg = parseTopicMsg(channel.topic, 'leavemessage') + const msg = parseTopic(channel.topic, 'leavemessage') .replace(/{{member}}/gi, member.user.username) .replace(/{{server}}/gi, member.guild.name) .replace(/{{mention}}/gi, member); diff --git a/commands/moderation/ban.js b/commands/moderation/ban.js index ebafb0a3..548a0fce 100644 --- a/commands/moderation/ban.js +++ b/commands/moderation/ban.js @@ -1,7 +1,7 @@ const Command = require('../../structures/Command'); const { MessageEmbed } = require('discord.js'); const { stripIndents } = require('common-tags'); -const { parseTopic, parseTopicMsg } = require('../../structures/Util'); +const { filterTopics, parseTopic } = require('../../structures/Util'); module.exports = class BanCommand extends Command { constructor(client) { @@ -34,7 +34,7 @@ module.exports = class BanCommand extends Command { } async run(msg, args) { - const modlogs = parseTopic(msg.guild.channels, 'modlog', this.client.user).first(); + 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.bannable) return msg.say('This member is not bannable. Perhaps they have a higher role than me?'); @@ -48,7 +48,7 @@ module.exports = class BanCommand extends Command { }); if (!msgs.size || !['y', 'yes'].includes(msgs.first().content.toLowerCase())) return msg.say('Aborting.'); try { - const message = parseTopicMsg(modlogs.topic, 'modmessage') + const message = parseTopic(modlogs.topic, 'modmessage') .replace(/{{action}}/gi, 'banned') .replace(/{{moderator}}/gi, msg.author.tag) .replace(/{{server}}/gi, msg.guild.name); @@ -64,7 +64,7 @@ module.exports = class BanCommand extends Command { reason: `${msg.author.tag}: ${reason}` }); await msg.say(`Successfully banned ${member.user.tag}.`); - if (!modlogs || !modlogs.permissionsFor(this.client.user).has('SEND_MESSAGES')) { + if (!modlogs) { 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() diff --git a/commands/moderation/kick.js b/commands/moderation/kick.js index 070b301a..d9f2a49f 100644 --- a/commands/moderation/kick.js +++ b/commands/moderation/kick.js @@ -1,7 +1,7 @@ const Command = require('../../structures/Command'); const { MessageEmbed } = require('discord.js'); const { stripIndents } = require('common-tags'); -const { parseTopic, parseTopicMsg } = require('../../structures/Util'); +const { filterTopics, parseTopic } = require('../../structures/Util'); module.exports = class KickCommand extends Command { constructor(client) { @@ -34,7 +34,7 @@ module.exports = class KickCommand extends Command { } async run(msg, args) { - const modlogs = parseTopic(msg.guild.channels, 'modlog', this.client.user).first(); + 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.kickable) return msg.say('This member is not kickable. Perhaps they have a higher role than me?'); @@ -48,7 +48,7 @@ module.exports = class KickCommand extends Command { }); if (!msgs.size || !['y', 'yes'].includes(msgs.first().content.toLowerCase())) return msg.say('Aborting.'); try { - const message = parseTopicMsg(modlogs.topic, 'modmessage') + const message = parseTopic(modlogs.topic, 'modmessage') .replace(/{{action}}/gi, 'kicked') .replace(/{{moderator}}/gi, msg.author.tag) .replace(/{{server}}/gi, msg.guild.name); @@ -61,7 +61,7 @@ module.exports = class KickCommand extends Command { } 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')) { + if (!modlogs) { 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() diff --git a/commands/moderation/softban.js b/commands/moderation/softban.js index f63038af..9c67fa63 100644 --- a/commands/moderation/softban.js +++ b/commands/moderation/softban.js @@ -1,7 +1,7 @@ const Command = require('../../structures/Command'); const { MessageEmbed } = require('discord.js'); const { stripIndents } = require('common-tags'); -const { parseTopic, parseTopicMsg } = require('../../structures/Util'); +const { filterTopics, parseTopic } = require('../../structures/Util'); module.exports = class SoftbanCommand extends Command { constructor(client) { @@ -34,7 +34,7 @@ module.exports = class SoftbanCommand extends Command { } async run(msg, args) { - const modlogs = parseTopic(msg.guild.channels, 'modlog', this.client.user).first(); + 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.bannable) return msg.say('This member is not softbannable. Perhaps they have a higher role than me?'); @@ -48,7 +48,7 @@ module.exports = class SoftbanCommand extends Command { }); if (!msgs.size || !['y', 'yes'].includes(msgs.first().content.toLowerCase())) return msg.say('Aborting.'); try { - const message = parseTopicMsg(modlogs.topic, 'modmessage') + const message = parseTopic(modlogs.topic, 'modmessage') .replace(/{{action}}/gi, 'softbanned') .replace(/{{moderator}}/gi, msg.author.tag) .replace(/{{server}}/gi, msg.guild.name); @@ -65,7 +65,7 @@ module.exports = class SoftbanCommand extends Command { }); 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')) { + if (!modlogs) { 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() diff --git a/commands/moderation/unban.js b/commands/moderation/unban.js index 8b0349ca..846426b4 100644 --- a/commands/moderation/unban.js +++ b/commands/moderation/unban.js @@ -1,7 +1,7 @@ const Command = require('../../structures/Command'); const { MessageEmbed } = require('discord.js'); const { stripIndents } = require('common-tags'); -const { parseTopic } = require('../../structures/Util'); +const { filterTopics } = require('../../structures/Util'); module.exports = class UnbanCommand extends Command { constructor(client) { @@ -34,7 +34,7 @@ module.exports = class UnbanCommand extends Command { } async run(msg, args) { - const modlogs = parseTopic(msg.guild.channels, 'modlog', this.client.user).first(); + 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.'); diff --git a/commands/moderation/warn.js b/commands/moderation/warn.js index 1be75b0c..15405af8 100644 --- a/commands/moderation/warn.js +++ b/commands/moderation/warn.js @@ -1,7 +1,7 @@ const Command = require('../../structures/Command'); const { MessageEmbed } = require('discord.js'); const { stripIndents } = require('common-tags'); -const { parseTopic, parseTopicMsg } = require('../../structures/Util'); +const { filterTopics, parseTopic } = require('../../structures/Util'); module.exports = class WarnCommand extends Command { constructor(client) { @@ -33,7 +33,7 @@ module.exports = class WarnCommand extends Command { } async run(msg, args) { - const modlogs = parseTopic(msg.guild.channels, 'modlog', this.client.user).first(); + 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.kickable) return msg.say('This member is not warnable. Perhaps they have a higher role than me?'); @@ -47,7 +47,7 @@ module.exports = class WarnCommand extends Command { }); if (!msgs.size || !['y', 'yes'].includes(msgs.first().content.toLowerCase())) return msg.say('Aborting.'); try { - const message = parseTopicMsg(modlogs.topic, 'modmessage') + const message = parseTopic(modlogs.topic, 'modmessage') .replace(/{{action}}/gi, 'warned') .replace(/{{moderator}}/gi, msg.author.tag) .replace(/{{server}}/gi, msg.guild.name); @@ -59,7 +59,7 @@ module.exports = class WarnCommand extends Command { 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')) { + if (!modlogs) { 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() diff --git a/commands/random/portal-send.js b/commands/text-edit/portal-send.js similarity index 88% rename from commands/random/portal-send.js rename to commands/text-edit/portal-send.js index 39cc9121..6467af21 100644 --- a/commands/random/portal-send.js +++ b/commands/text-edit/portal-send.js @@ -1,11 +1,11 @@ const Command = require('../../structures/Command'); -const { parseTopic } = require('../../structures/Util'); +const { filterTopics } = require('../../structures/Util'); module.exports = class PortalSendCommand extends Command { constructor(client) { super(client, { name: 'portal-send', - group: 'random', + group: 'text-edit', memberName: 'portal-send', description: 'Send a message to a random channel that has a portal open.', guildOnly: true, @@ -27,7 +27,7 @@ module.exports = class PortalSendCommand extends Command { 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 = parseTopic(channels, 'portal', this.client.user).random(); + 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}`); diff --git a/package.json b/package.json index 9c2cedd7..b661b170 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "xiaobot", - "version": "28.3.0", + "version": "28.3.1", "description": "Your personal server companion.", "main": "Shard.js", "scripts": { diff --git a/structures/Util.js b/structures/Util.js index 177eb6eb..eca71729 100644 --- a/structures/Util.js +++ b/structures/Util.js @@ -41,17 +41,15 @@ class Util { .catch(err => console.error(`[DBOTSORG] Failed to post to Discord Bots Org. ${err}`)); } - static parseTopic(channels, setting, user) { - const channelList = channels.filter(c => { - const topic = c.topic || ''; - if (topic.includes(`<${setting}>`) && c.type === 'text' && c.permissionsFor(user).has('SEND_MESSAGES')) return true; // eslint-disable-line max-len + static filterTopics(channels, setting) { + return channels.filter(c => { + if (c.type !== 'text' || !c.topic) return false; + if (c.topic.includes(`<${setting}>`) && c.permissionsFor(c.client.user).has('SEND_MESSAGES')) return true; return false; }); - if (!channelList) return false; - return channelList; } - static parseTopicMsg(topic, setting) { + static parseTopic(topic, setting) { const regex = new RegExp(`<${setting}>.+`, 'gi'); if (!regex.test(topic)) return ''; const parsed = topic.match(regex)[0];