mirror of
https://github.com/ION606/selmerBot.git
synced 2026-06-05 23:06:14 +00:00
Updated the way the verification system works and added custom admin role integration
This commit is contained in:
@@ -8,24 +8,26 @@ module.exports = {
|
||||
const arg = interaction.options.data[0];
|
||||
const guild = bot.guilds.cache.get(interaction.guildId);
|
||||
|
||||
if (!checkRole(bot, guild, interaction.user.id)) { return interaction.reply('Insufficient Permissions!'); }
|
||||
checkRole(bot, guild, interaction.user.id).then((isAllowed) => {
|
||||
if (isAllowed) { return interaction.reply('Insufficient Permissions!'); }
|
||||
|
||||
var channel;
|
||||
if (arg) {
|
||||
channel = arg.channel;
|
||||
} else {
|
||||
channel = interaction.channel;
|
||||
}
|
||||
var channel;
|
||||
if (arg) {
|
||||
channel = arg.channel;
|
||||
} else {
|
||||
channel = interaction.channel;
|
||||
}
|
||||
|
||||
let role = interaction.guild.roles.cache.find(r => r.name === "@everyone");
|
||||
channel.permissionOverwrites.edit(role.id, {
|
||||
VIEW_CHANNEL: true,
|
||||
SEND_MESSAGES: false,
|
||||
READ_MESSAGE_HISTORY: true,
|
||||
ATTACH_FILES: false
|
||||
let role = interaction.guild.roles.cache.find(r => r.name === "@everyone");
|
||||
channel.permissionOverwrites.edit(role.id, {
|
||||
VIEW_CHANNEL: true,
|
||||
SEND_MESSAGES: false,
|
||||
READ_MESSAGE_HISTORY: true,
|
||||
ATTACH_FILES: false
|
||||
});
|
||||
|
||||
interaction.reply(`${channel} has been locked!`);
|
||||
});
|
||||
|
||||
interaction.reply(`${channel} has been locked!`);
|
||||
},
|
||||
options: [{name: 'channel', description: 'The channel to lock (defaults to current channel)', type: Constants.ApplicationCommandOptionTypes.CHANNEL, required: false}]
|
||||
}
|
||||
@@ -99,51 +99,53 @@ function moderation_handler(bot, interaction, command) {
|
||||
const guild = interaction.guild;
|
||||
|
||||
//Verify
|
||||
if (!checkRole(bot, guild, interaction.user.id)) { return interaction.reply('Insufficient Permission!'); }
|
||||
checkRole(bot, guild, interaction.user.id).then((isAllowed) => {
|
||||
if (!isAllowed) { return interaction.reply('Insufficient Permission!'); }
|
||||
|
||||
const mentioned = interaction.options.data.filter((arg) => { return (arg.name == 'user'); })[0].user;
|
||||
if (mentioned && mentioned.id == interaction.user.id) { return interaction.reply(`You can't ${command} yourself!`); }
|
||||
const mentioned = interaction.options.data.filter((arg) => { return (arg.name == 'user'); })[0].user;
|
||||
if (mentioned && mentioned.id == interaction.user.id) { return interaction.reply(`You can't ${command} yourself!`); }
|
||||
|
||||
const reasonInit = interaction.options.data.filter((arg) => { return (arg.name == 'reason'); })[0];
|
||||
const reason = (reasonInit) ? reasonInit.value : "None";
|
||||
const reasonInit = interaction.options.data.filter((arg) => { return (arg.name == 'reason'); })[0];
|
||||
const reason = (reasonInit) ? reasonInit.value : "None";
|
||||
|
||||
const user = guild.members.resolve(mentioned.id);
|
||||
const user = guild.members.resolve(mentioned.id);
|
||||
|
||||
if (user && (user.roles.highest.position > guild.members.resolve(bot.user).roles.highest.position)) {
|
||||
return interaction.reply("I'm not high enough in the role hierarchy to do that!\n_To raise my place, go to **Server Settings -> Roles** then drag me up!_");
|
||||
}
|
||||
if (user && (user.roles.highest.position > guild.members.resolve(bot.user).roles.highest.position)) {
|
||||
return interaction.reply("I'm not high enough in the role hierarchy to do that!\n_To raise my place, go to **Server Settings -> Roles** then drag me up!_");
|
||||
}
|
||||
|
||||
|
||||
// if (command != 'unban' && !mentioned || !reason) { return message.channel.send(`Please use the following format: _!<command> <user> <reason>`); }
|
||||
// if (command == 'unban' && !args[0] && !reason) { return message.channel.send("Please use the following format: _!unban <user_tag>#<user_discriminator> <reason>\nExample: _!unban John#1122_"); }
|
||||
// if (command == 'ban' && guild.members.cache.get(mentioned.id).bannable) { message.reply("This user is not bannable!"); } //Broken
|
||||
// if (command == 'ban' && !message.guild.members.cache.get(mentioned.id)) { message.reply("This user is not in the server"); }
|
||||
|
||||
switch (command) {
|
||||
case 'kick': kick(guild, mentioned);
|
||||
log(bot, interaction, command, mentioned, reason, SEVCODES.medium);
|
||||
break;
|
||||
|
||||
case 'ban': toggle_ban(guild, interaction, mentioned, true, reason);
|
||||
log(bot, interaction, command, mentioned, reason, SEVCODES.high);
|
||||
break;
|
||||
|
||||
//Leave the then() catch() thing, it needs to be async
|
||||
case 'unban': toggle_ban(guild, interaction, false, reason).then((user) => { log(bot, interaction, command, user, reason, SEVCODES.none)}).catch((note) => { interaction.reply(note); });
|
||||
break;
|
||||
|
||||
case 'mute': toggle_mute(bot, guild, command, interaction, mentioned, reason, true);
|
||||
break;
|
||||
|
||||
case 'unmute': toggle_mute(bot, guild, command, interaction, mentioned, reason, true);
|
||||
break;
|
||||
// if (command != 'unban' && !mentioned || !reason) { return message.channel.send(`Please use the following format: _!<command> <user> <reason>`); }
|
||||
// if (command == 'unban' && !args[0] && !reason) { return message.channel.send("Please use the following format: _!unban <user_tag>#<user_discriminator> <reason>\nExample: _!unban John#1122_"); }
|
||||
// if (command == 'ban' && guild.members.cache.get(mentioned.id).bannable) { message.reply("This user is not bannable!"); } //Broken
|
||||
// if (command == 'ban' && !message.guild.members.cache.get(mentioned.id)) { message.reply("This user is not in the server"); }
|
||||
|
||||
// case 'timeout': timeOut(bot, mentioned, message, args, command, reason);
|
||||
// shouldIlog = false;
|
||||
// break;
|
||||
|
||||
default: console.log(`ERROR! Moderation Command "${command}" has somehow been used!`);
|
||||
}
|
||||
switch (command) {
|
||||
case 'kick': kick(guild, mentioned);
|
||||
log(bot, interaction, command, mentioned, reason, SEVCODES.medium);
|
||||
break;
|
||||
|
||||
case 'ban': toggle_ban(guild, interaction, mentioned, true, reason);
|
||||
log(bot, interaction, command, mentioned, reason, SEVCODES.high);
|
||||
break;
|
||||
|
||||
//Leave the then() catch() thing, it needs to be async
|
||||
case 'unban': toggle_ban(guild, interaction, false, reason).then((user) => { log(bot, interaction, command, user, reason, SEVCODES.none)}).catch((note) => { interaction.reply(note); });
|
||||
break;
|
||||
|
||||
case 'mute': toggle_mute(bot, guild, command, interaction, mentioned, reason, true);
|
||||
break;
|
||||
|
||||
case 'unmute': toggle_mute(bot, guild, command, interaction, mentioned, reason, true);
|
||||
break;
|
||||
|
||||
// case 'timeout': timeOut(bot, mentioned, message, args, command, reason);
|
||||
// shouldIlog = false;
|
||||
// break;
|
||||
|
||||
default: console.log(`ERROR! Moderation Command "${command}" has somehow been used!`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
||||
+16
-1
@@ -86,6 +86,19 @@ async function execute(interaction, Discord, Client, bot) {
|
||||
if (!channel) { return interaction.reply({content: 'The specified channel does not exist!', ephemeral: true}); }
|
||||
|
||||
dbo.updateOne({_id: 'announcement'}, { $set: { 'channel': channel.id } });
|
||||
} else if (command == "add_mod_role") {
|
||||
dbo.findOne({_id: "roles"}).then((doc) => {
|
||||
const role = args[i].value;
|
||||
if (!doc.commands.includes(role)) {
|
||||
dbo.updateOne({_id: "roles"}, { $push: { commands: role } });
|
||||
interaction.reply({ content: "Role added!", ephemeral: true });
|
||||
} else {
|
||||
interaction.reply({ content: "This role is already a command role!", ephemeral: true });
|
||||
}
|
||||
});
|
||||
} else if (command == "remove_mod_role") {
|
||||
dbo.updateOne({_id: "roles"}, { $pull: { commands: { $in: [ args[i].value ] }} });
|
||||
interaction.reply({ content: "Role removed!", ephemeral: true });
|
||||
} else {
|
||||
interaction.reply({content: "Please chose a valid option", ephemeral: true});
|
||||
}
|
||||
@@ -128,7 +141,9 @@ module.exports = {
|
||||
{name: 'log_channel', description: 'Sets the logging channel', type: Constants.ApplicationCommandOptionTypes.CHANNEL },
|
||||
{name: 'log_severity', description: 'Sets the logging Severity (logs this/lower tiers)', type: Constants.ApplicationCommandOptionTypes.STRING, choices: [{name: 'none', value: 'none'}, {name: 'low', value: 'low'}, {name: 'medium', value: 'medium'}, {name: 'high', value: 'high'}] },
|
||||
{name: 'announcement_role', description: 'Sets the role to be pinged for reminders', type: Constants.ApplicationCommandOptionTypes.ROLE},
|
||||
{name: 'announcement_channel', description: 'Sets the channel for reminders', type: Constants.ApplicationCommandOptionTypes.CHANNEL}
|
||||
{name: 'announcement_channel', description: 'Sets the channel for reminders', type: Constants.ApplicationCommandOptionTypes.CHANNEL},
|
||||
{name: 'add_mod_role', description: 'Make a role into an admin role for Selmer Bot, able to execute ALL Selmer Bot commands', type: Constants.ApplicationCommandOptionTypes.ROLE},
|
||||
{name: 'remove_mod_role', description: 'Remove a Selmer Bot moderation role', type: Constants.ApplicationCommandOptionTypes.ROLE}
|
||||
// {name: 'help', description: 'gets help with setup commands', type: Constants.ApplicationCommandOptionTypes.STRING, choices: [{name: 'welcome', value: 'welcome'}, {name: 'logs', value: 'logs'}, {name: 'announcement', value: 'announcement'}]}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
const { checkRole } = require('./verify.js');
|
||||
const { Constants } = require('discord.js');
|
||||
|
||||
|
||||
module.exports = {
|
||||
name: 'unlock',
|
||||
description: 'Unlock a channel',
|
||||
execute(interaction, Discord, Client, bot) {
|
||||
const arg = interaction.options.data[0];
|
||||
const guild = bot.guilds.cache.get(interaction.guildId);
|
||||
|
||||
checkRole(bot, guild, interaction.user.id).then((isAllowed) => {
|
||||
if (!isAllowed) { return message.reply('Insufficient Permissions!'); }
|
||||
|
||||
var channel;
|
||||
if (arg) {
|
||||
channel = arg.channel;
|
||||
} else {
|
||||
channel = interaction.channel;
|
||||
}
|
||||
|
||||
let role = interaction.guild.roles.cache.find(r => r.name === "@everyone");
|
||||
|
||||
channel.permissionOverwrites.edit(role.id, {
|
||||
VIEW_CHANNEL: true,
|
||||
SEND_MESSAGES: true,
|
||||
READ_MESSAGE_HISTORY: true,
|
||||
ATTACH_FILES: true
|
||||
});
|
||||
|
||||
interaction.reply(`${channel} has been unlocked!`);
|
||||
});
|
||||
},
|
||||
options: [{name: 'channel', description: 'The channel to unlock (defaults to current channel)', type: Constants.ApplicationCommandOptionTypes.CHANNEL, required: false}]
|
||||
}
|
||||
+31
-24
@@ -1,32 +1,39 @@
|
||||
function checkRole(bot, guild, userId, cal = false) {
|
||||
var roleName;
|
||||
|
||||
if (cal) {
|
||||
roleName = "Selmer Bot Calendar";
|
||||
} else {
|
||||
roleName = "Selmer Bot Commands";
|
||||
}
|
||||
const Discord = require('discord.js');
|
||||
|
||||
const role = guild.roles.cache.find((role) => { return (role.name == roleName); })
|
||||
const user = guild.members.cache.get(userId);
|
||||
/**
|
||||
* @param {Discord.Guild} guild
|
||||
* @returns {Promise<Boolean>}
|
||||
*/
|
||||
function checkRole(bot, guild, userId) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const user = guild.members.cache.get(userId);
|
||||
|
||||
return (role != undefined && user.roles.cache.has(role.id)); // || user.id == guild.ownerId || bot.inDebugMode
|
||||
// return (role != undefined && user.roles.cache.has(role.id)); // || user.id == guild.ownerId || bot.inDebugMode
|
||||
|
||||
// Maybe implement this later, useless for now
|
||||
bot.mongoconnection.then((client) => {
|
||||
// const role = client.db(message.guild.id).collection("admin-roles");
|
||||
const a = new Array();
|
||||
client.db(guild.id).collection("SETUP").findOne({_id: "roles"}).then((doc) => {
|
||||
const comRoles = doc.commands;
|
||||
const role = guild.roles.cache.find((role) => { return (role.name == "Selmer Bot Commands"); });
|
||||
const hasPreAdminRole = (role != undefined && user.roles.cache.has(role.id) || user.id == guild.ownerId);
|
||||
|
||||
/*Maybe implement this later, useless for now
|
||||
const client = new MongoClient(mongouri, { useNewUrlParser: true, useUnifiedTopology: true, serverApi: ServerApiVersion.v1 });
|
||||
client.connect(err => {
|
||||
|
||||
|
||||
const role = client.db(message.guild.id).collection("admin-roles");
|
||||
shop.find().toArray(function(err, itemstemp) {
|
||||
if (err) throw err;
|
||||
|
||||
items = [...itemstemp];
|
||||
|
||||
client.close();
|
||||
if (!comRoles) {
|
||||
resolve(hasPreAdminRole);
|
||||
} else {
|
||||
const hasRoles = [];
|
||||
Promise.all(comRoles.map((val) => {
|
||||
if (user.roles.cache.has(val)) {
|
||||
hasRoles.push(true);
|
||||
}
|
||||
})).then(() => {
|
||||
resolve(hasRoles.length > 0 || hasPreAdminRole);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
});*/
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user