Invite Guard, Topic Parsing Changes

This commit is contained in:
Daniel Odendahl Jr
2017-08-03 22:08:52 +00:00
parent 128a87f40b
commit 104ab19bc5
9 changed files with 36 additions and 40 deletions
+9 -11
View File
@@ -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('<inviteguard>')) 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);
+4 -4
View File
@@ -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()
+4 -4
View File
@@ -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()
+4 -4
View File
@@ -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()
+2 -2
View File
@@ -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.');
+4 -4
View File
@@ -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()
@@ -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}`);
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "xiaobot",
"version": "28.3.0",
"version": "28.3.1",
"description": "Your personal server companion.",
"main": "Shard.js",
"scripts": {
+5 -7
View File
@@ -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}>.+</${setting}>`, 'gi');
if (!regex.test(topic)) return '';
const parsed = topic.match(regex)[0];