Skip to content

Commit

Permalink
added bot log toggles to the settings table, added moderator only cha…
Browse files Browse the repository at this point in the history
…nnels
  • Loading branch information
sabattle committed Aug 30, 2020
1 parent 2d516a0 commit 5f6f0c5
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 2 deletions.
60 changes: 60 additions & 0 deletions src/commands/admin/setmodchannels.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
const Command = require('../Command.js');
const { MessageEmbed } = require('discord.js');
const { success } = require('../../utils/emojis.json');
const { oneLine, stripIndent } = require('common-tags');

module.exports = class SetModChannelsCommand extends Command {
constructor(client) {
super(client, {
name: 'setmodchannels',
aliases: ['setmodcs', 'setmcs', 'smcs'],
usage: 'setmodchannels <channel mentions/IDs>',
description: oneLine`
Sets the moderator only text channels for your server.
Only \`${client.utils.capitalize(client.types.MOD)}\` type commands will work in these channels,
and Calypso will only respond to members with permission to use those commands.
Provide no channels to clear the current \`mod channels\`.
`,
type: client.types.ADMIN,
userPermissions: ['MANAGE_GUILD'],
examples: ['setmodchannels #general #memes #off-topic']
});
}
run(message, args) {
const modChannelIds = message.client.db.settings.selectModChannelIds.pluck().get(message.guild.id);
let oldModChannels = [];
if (modChannelIds) {
for (const channel of modChannelIds.split(' ')) {
oldModChannels.push(message.guild.channels.cache.get(channel));
}
oldModChannels = oldModChannels.join(' ');
}
if (oldModChannels.length === 0) oldModChannels = '`None`';
const embed = new MessageEmbed()
.setTitle('Settings: `Mod Channels`')
.setThumbnail(message.guild.iconURL({ dynamic: true }))
.setDescription(`The \`mod channels\` were successfully updated. ${success}`)
.setFooter(message.member.displayName, message.author.displayAvatarURL({ dynamic: true }))
.setTimestamp()
.setColor(message.guild.me.displayHexColor);

// Clear if no args provided
if (args.length === 0) {
message.client.db.settings.updateModChannelIds.run(null, message.guild.id);
return message.channel.send(embed.addField('Channels', `${oldModChannels} ➔ \`None\``));
}

let channels = [];
for (const arg of args) {
const channel = this.getChannelFromMention(message, arg) || message.guild.channels.cache.get(arg);
if (channel && channel.type === 'text' && channel.viewable) channels.push(channel);
else return this.sendErrorMessage(message, 0, stripIndent`
Please mention only accessible text channels or provide only valid text channel IDs
`);
}
channels = [...new Set(channels)];
const channelIds = channels.map(c => c.id).join(' '); // Only keep unique IDs
message.client.db.settings.updateModChannelIds.run(channelIds, message.guild.id);
message.channel.send(embed.addField('Channels', `${oldModChannels}${channels.join(' ')}`));
}
};
10 changes: 10 additions & 0 deletions src/commands/admin/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,14 @@ module.exports = class SettingsCommand extends Command {
const welcomeChannel = message.guild.channels.cache.get(row.welcome_channel_id) || '`None`';
const leaveChannel = message.guild.channels.cache.get(row.leave_channel_id) || '`None`';
const crownChannel = message.guild.channels.cache.get(row.crown_channel_id) || '`None`';
let modChannels = [];
if (row.mod_channel_ids) {
for (const channel of row.mod_channel_ids.split(' ')) {
modChannels.push(message.guild.channels.cache.get(channel));
}
modChannels = modChannels.join(' ');
}
if (modChannels.length === 0) modChannels = '`None`';
const adminRole = message.guild.roles.cache.get(row.admin_role_id) || '`None`';
const modRole = message.guild.roles.cache.get(row.mod_role_id) || '`None`';
const muteRole = message.guild.roles.cache.get(row.mute_role_id) || '`None`';
Expand Down Expand Up @@ -83,6 +91,7 @@ module.exports = class SettingsCommand extends Command {
.addField('Auto Role', autoRole, true)
.addField('Auto Kick', autoKick, true)
.addField('Random Color', randomColor, true)
.addField('Mod Channels', modChannels)
);
case 'verif':
case 'verification':
Expand Down Expand Up @@ -181,6 +190,7 @@ module.exports = class SettingsCommand extends Command {
**Auto Role:** ${autoRole}
**Auto Kick:** ${autoKick}
**Random Color:** ${randomColor}
**Mod Channels:** ${modChannels}
`)
// Verification Settings
.addField('__**Verification**__', stripIndent`
Expand Down
7 changes: 7 additions & 0 deletions src/commands/fun/say.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ module.exports = class SayCommand extends Command {
Please mention an accessible text channel or provide a valid text channel ID
`);

// Get mod channels
let modChannelIds = message.client.db.settings.selectModChannelIds.pluck().get(message.guild.id) || [];
if (typeof(modChannelIds) === 'string') modChannelIds = modChannelIds.split(' ');
if (modChannelIds.includes(channel.id)) return this.sendErrorMessage(message, 0, stripIndent`
Provided channel is moderator only, please mention an accessible text channel or provide a valid text channel ID
`);

if (!args[0]) return this.sendErrorMessage(message, 0, 'Please provide a message for me to say');

// Check channel permissions
Expand Down
2 changes: 1 addition & 1 deletion src/commands/info/botinfo.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = class BotInfoCommand extends Command {
Version :: ${pkg.version}
Library :: Discord.js v12.2.0
Environment :: Node.js v12.16.3
Database :: SQlite
Database :: SQLite
`;
const embed = new MessageEmbed()
.setTitle('Calypso\'s Bot Information')
Expand Down
20 changes: 19 additions & 1 deletion src/events/message.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,29 @@ module.exports = (client, message) => {

if (prefixRegex.test(message.content)) {

// Get mod channels
let modChannelIds = message.client.db.settings.selectModChannelIds.pluck().get(message.guild.id) || [];
if (typeof(modChannelIds) === 'string') modChannelIds = modChannelIds.split(' ');

const [, match] = message.content.match(prefixRegex);
const args = message.content.slice(match.length).trim().split(/ +/g);
const cmd = args.shift().toLowerCase();
let command = client.commands.get(cmd) || client.aliases.get(cmd); // If command not found, check aliases
if (command && !disabledCommands.includes(command.name)) {

// Check if mod channel
if (modChannelIds.includes(message.channel.id)) {
if (
command.type != client.types.MOD || (command.type == client.types.MOD &&
message.channel.permissionsFor(message.author).missing(command.userPermissions) != 0)
) {
// Update points with messagePoints value
if (pointTracking)
client.db.users.updatePoints.run({ points: messagePoints }, message.author.id, message.guild.id);
return; // Return early so Calypso doesn't respond
}
}

// Check permissions
const permission = command.checkPermissions(message);
if (permission) {
Expand All @@ -36,7 +53,8 @@ module.exports = (client, message) => {
}
} else if (
(message.content === `<@${client.user.id}>` || message.content === `<@!${client.user.id}>`) &&
message.channel.permissionsFor(message.guild.me).has(['SEND_MESSAGES', 'EMBED_LINKS'])
message.channel.permissionsFor(message.guild.me).has(['SEND_MESSAGES', 'EMBED_LINKS']) &&
!modChannelIds.includes(message.channel.id)
) {
const embed = new MessageEmbed()
.setTitle('Hi, I\'m Calypso. Need help?')
Expand Down
15 changes: 15 additions & 0 deletions src/utils/db.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ db.prepare(`
modlog_channel_id TEXT,
botlog_channel_id TEXT,
verification_channel_id TEXT,
mod_channel_ids TEXT,
welcome_channel_id TEXT,
leave_channel_id TEXT,
crown_channel_id TEXT,
Expand All @@ -32,6 +33,10 @@ db.prepare(`
auto_role_id TEXT,
verification_role_id TEXT,
crown_role_id TEXT,
log_message_delete INTEGER DEFAULT 0 NOT NULL,
log_message_edit INTEGER DEFAULT 0 NOT NULL,
log_role_change INTEGER DEFAULT 0 NOT NULL,
log_name_change INTEGER DEFAULT 0 NOT NULL,
random_color INTEGER DEFAULT 0 NOT NULL,
auto_kick INTEGER,
point_tracking INTEGER DEFAULT 1 NOT NULL,
Expand Down Expand Up @@ -99,12 +104,17 @@ const settings = {
FROM settings
WHERE guild_id = ?;
`),
selectModChannelIds: db.prepare('SELECT mod_channel_ids FROM settings WHERE guild_id = ?;'),
selectWelcomeMessages: db.prepare('SELECT welcome_channel_id, welcome_message FROM settings WHERE guild_id = ?;'),
selectLeaveMessages: db.prepare('SELECT leave_channel_id, leave_message FROM settings WHERE guild_id = ?;'),
selectAdminRoleId: db.prepare('SELECT admin_role_id FROM settings WHERE guild_id = ?;'),
selectModRoleId: db.prepare('SELECT mod_role_id FROM settings WHERE guild_id = ?;'),
selectMuteRoleId: db.prepare('SELECT mute_role_id FROM settings WHERE guild_id = ?;'),
selectAutoRoleId: db.prepare('SELECT auto_role_id FROM settings WHERE guild_id = ?;'),
selectLogMessageDelete: db.prepare('SELECT log_message_delete FROM settings WHERE guild_id = ?;'),
selectLogMessageEdit: db.prepare('SELECT log_message_edit FROM settings WHERE guild_id = ?;'),
selectLogRoleChange: db.prepare('SELECT log_role_change FROM settings WHERE guild_id = ?;'),
selectLogNameChange: db.prepare('SELECT log_name_change FROM settings WHERE guild_id = ?;'),
selectRandomColor: db.prepare('SELECT random_color FROM settings WHERE guild_id = ?;'),
selectAutoKick: db.prepare('SELECT auto_kick FROM settings WHERE guild_id = ?;'),
selectPoints: db.prepare(`
Expand All @@ -126,6 +136,7 @@ const settings = {
updateModlogChannelId: db.prepare('UPDATE settings SET modlog_channel_id = ? WHERE guild_id = ?;'),
updateBotlogChannelId: db.prepare('UPDATE settings SET botlog_channel_id = ? WHERE guild_id = ?;'),
updateVerificationChannelId: db.prepare('UPDATE settings SET verification_channel_id = ? WHERE guild_id = ?;'),
updateModChannelIds: db.prepare('UPDATE settings SET mod_channel_ids = ? WHERE guild_id = ?;'),
updateWelcomeChannelId: db.prepare('UPDATE settings SET welcome_channel_id = ? WHERE guild_id = ?;'),
updateLeaveChannelId: db.prepare('UPDATE settings SET leave_channel_id = ? WHERE guild_id = ?;'),
updateCrownChannelId: db.prepare('UPDATE settings SET crown_channel_id = ? WHERE guild_id = ?;'),
Expand All @@ -135,6 +146,10 @@ const settings = {
updateAutoRoleId: db.prepare('UPDATE settings SET auto_role_id = ? WHERE guild_id = ?;'),
updateVerificationRoleId: db.prepare('UPDATE settings SET verification_role_id = ? WHERE guild_id = ?;'),
updateCrownRoleId: db.prepare('UPDATE settings SET crown_role_id = ? WHERE guild_id = ?;'),
updateLogMessageDelete: db.prepare('UPDATE settings SET log_message_delete = ? WHERE guild_id = ?;'),
updateLogMessageEdit: db.prepare('UPDATE settings SET log_message_edit = ? WHERE guild_id = ?;'),
updateLogRoleChange: db.prepare('UPDATE settings SET log_role_change = ? WHERE guild_id = ?;'),
updateLogNameChange: db.prepare('UPDATE settings SET log_name_change = ? WHERE guild_id = ?;'),
updateRandomColor: db.prepare('UPDATE settings SET random_color = ? WHERE guild_id = ?;'),
updateAutoKick: db.prepare('UPDATE settings SET auto_kick = ? WHERE guild_id = ?;'),
updatePointTracking: db.prepare('UPDATE settings SET point_tracking = ? WHERE guild_id = ?;'),
Expand Down

0 comments on commit 5f6f0c5

Please sign in to comment.