Skip to content

Commit

Permalink
🔗 Moderation Tools menu, fixes
Browse files Browse the repository at this point in the history
🤖 New "moderation tools" system, enable or disable moderation features
🔗 Discord invites suppressor can be enabled with moderation tools menu (disabled by default)
⏹️ moderation-tools-buttons.js to enable a specific feature from a button interraction
🛹 moderation-tools-select.js handler for the selected moderation tools
🗃️ New moderationTools field in db model
⚙️ UseApplicationCommands user permission now required to use commands
✍️ Removed the redundant "Setup" repeat for the setup menu
❎ Removed .gitattributes file
📂 Change location of setup-Ids.js
  • Loading branch information
Pexilo committed Aug 30, 2022
1 parent f1d7440 commit 8d93453
Show file tree
Hide file tree
Showing 13 changed files with 173 additions and 19 deletions.
2 changes: 0 additions & 2 deletions .gitattributes

This file was deleted.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div align="center">
<img src="https://user-images.githubusercontent.com/67436391/182243493-2dbaf788-fb39-463b-bcb9-05303d7d4a7f.png" align="center">
<a href="https://github.com/Pexilo/Stealthy/releases" target="_blank">
<img alt="Version" src="https://img.shields.io/badge/version-1.1.3-blue.svg?cacheSeconds=2592000&style=for-the-badge" />
<img alt="Version" src="https://img.shields.io/badge/version-1.1.4-blue.svg?cacheSeconds=2592000&style=for-the-badge" />
</a>
<a href="https://discord.com/api/oauth2/authorize?client_id=877249354954580059&permissions=8&scope=bot%20applications.commands" target="_blank">
<img src="https://dcbadge.vercel.app/api/shield/877249354954580059?bot=true?&theme=blurple" />
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "stealthy",
"version": "1.1.3",
"version": "1.1.4",
"description": "Lightweight, easy to use discord bot meant to enrich the lifestyle of your server.",
"main": "src/client.js",
"scripts": {
Expand Down
1 change: 1 addition & 0 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const client = new ShewenyClient({
type: "SLASH_COMMAND",
channel: "GUILD",
cooldown: 3,
userPermissions: ["UseApplicationCommands"],
},
},
events: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -927,6 +927,25 @@ module.exports = class SetupBotCommand extends Command {
case "blacklist":
if (!(await this.client.Defer(interaction))) return;

const blacklistState =
fetchGuild.moderationTools.enabled.includes("blacklist");
if (!blacklistState) {
return interaction.editReply({
content:
"`🛡️` Blacklist feature is disabled\n\n> Would you like to activate it?",
components: [
this.client.ButtonRow([
{
customId: "blacklist-tool",
label: "",
style: "SUCCESS",
emoji: "✅",
},
]),
],
});
}

const choice = options.getString("choice");
const format = options.getString("format");
const time =
Expand All @@ -947,7 +966,7 @@ module.exports = class SetupBotCommand extends Command {
}

return interaction.editReply({
content: `\`🔒\` ${this.client.Capitalize(
content: `\`🛡️\` ${this.client.Capitalize(
choice.replace(/_/g, " ")
)} is now set to: \`${this.client.PrettyMs(time, {
verbose: true,
Expand Down
7 changes: 7 additions & 0 deletions src/db-model/guild.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ const guildSchema = new mongoose.Schema({
id: String,
language: { type: String, default: "en" },

moderationTools: {
enabled: {
type: Array,
default: ["blacklist"],
},
},

logs: {
channel: { type: String, default: null },
enabled: {
Expand Down
4 changes: 3 additions & 1 deletion src/events/guild/guildMemberAdd.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ module.exports = class guildMemberAddTracker extends Event {
const fetchGuild = await this.client.getGuild(guild);
const logsChannel = this.client.channels.cache.get(fetchGuild.logs.channel);
const enabledLogs = fetchGuild.logs.enabled;
const blacklistState =
fetchGuild.moderationTools.enabled.includes("blacklist");

if (logsChannel && enabledLogs.includes("joinLeave")) {
let warn = false;
Expand Down Expand Up @@ -47,7 +49,7 @@ module.exports = class guildMemberAddTracker extends Event {
text: `${member.user.tag} - ${member.user.id}`,
});

if (warn) {
if (warn && blacklistState) {
member.timeout(blacklistTime);
EmbedInfo.setTitle("Account temporarilly blacklisted")
.setDescription(
Expand Down
12 changes: 7 additions & 5 deletions src/events/messages/messageCreate.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,25 @@ module.exports = class messageCreateTracker extends Event {

const { guild, channel, member } = message;

if (!member) return;

if (!member || message.author.bot) return;
if (
(message.content.includes("discord.gg/") ||
message.content.includes("discord.com/invite/")) &&
(!message.author.bot || !member.permissions.has("ManageMessages"))
!member.permissions.has("ManageMessages")
) {
const fetchGuild = await this.client.getGuild(guild);
const delDcInvitesState =
fetchGuild.moderationTools.enabled.includes("delDcInvites");
if (!delDcInvitesState) return;

message.delete();

const logsChannel = this.client.channels.cache.get(
fetchGuild.logs.channel
);
const enabledLogs = fetchGuild.logs.enabled;

if (logsChannel && enabledLogs.includes("moderation")) {
message.delete();

return logsChannel
.send({
embeds: [
Expand Down
4 changes: 2 additions & 2 deletions src/interactions/buttons/JTC-buttons.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ module.exports = class JTCSetupButtons extends Button {
parent: noParent ? null : firstCategory,
})
.then(async (channel) => channel.lockPermissions())
.catch((_e) => undefined);
.catch(() => undefined);

//set the channel in the database
await this.client.updateGuild(guild, {
Expand Down Expand Up @@ -115,7 +115,7 @@ module.exports = class JTCSetupButtons extends Button {

case "channels-names-JTC":
const channelNames = fetchGuild.joinToCreate.names.join(", ");
//prepare the modal, intercepted in interactionCreate class (temp)

await button.showModal(
this.client.ModalRow("channels-names-JTC", "JTC channel names", [
{
Expand Down
39 changes: 39 additions & 0 deletions src/interactions/buttons/moderation-tools-buttons.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
const { Button } = require("sheweny");

module.exports = class moderationToolsButtons extends Button {
constructor(client) {
super(client, ["blacklist-tool", "delDcInvites-tool"]);
}

async execute(button) {
if (!(await this.client.Defer(button))) return;

const { guild } = button;
const fetchGuild = await this.client.getGuild(guild);
const moderationTools = fetchGuild.moderationTools.enabled;

switch (button.customId) {
case "blacklist-tool":
moderationTools.push("blacklist");

button.editReply({
content:
"`🛡️` Blacklist feature is now enabled ✅\n\n> You can re-run your command",
});
break;

case "delDcInvites-tool":
moderationTools.push("delDcInvites");

button.editReply({
content:
"`🔗` Discord links suppressor is now enabled ✅\n\n> You can re-run your command",
});
break;
}

await this.client.updateGuild(guild, {
"moderationTools.enabled": moderationTools,
});
}
};
18 changes: 12 additions & 6 deletions src/interactions/buttons/setupMenu-firstMsg-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,39 +22,45 @@ module.exports = class SetupMenuButton extends Button {
"What feature do you want to configure?",
[
{
label: "Channels Setup",
label: "Channels",
description: "REQUIRED - Configure the channels used by the bot.",
value: "channel_option",
emoji: "📚",
},
{
label: "Join to Create Setup",
label: "Join to Create",
description:
"OPTIONAL - Lighten your voice channels with just one",
value: "jtc_option",
emoji: "🔊",
},
{
label: "Role Claim Setup",
label: "Role Claim",
description: "OPTIONAL - Let users claim roles from a message",
value: "roleclaim_option",
emoji: "🗂️",
},
{
label: "Auto Role Setup",
label: "Auto Role",
description: "OPTIONAL - Give roles to newcomers",
value: "autorole_option",
emoji: "🎩",
},
{
label: "Blacklist Setup",
label: "Blacklist",
description:
"OPTIONAL - Protect your server against bots, scams, etc.",
value: "blacklist_option",
emoji: "🛡️",
},
{
label: "Language Setup",
label: "Moderation Tools",
description: "OPTIONAL - Enable or disable moderation features",
value: "moderation_option",
emoji: "🗡️",
},
{
label: "Language",
description: "OPTIONAL - (WIP - Not implemented yet)",
value: "lang_option",
emoji: "🌐",
Expand Down
33 changes: 33 additions & 0 deletions src/interactions/select-menus/moderation-tools-select.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const { SelectMenu } = require("sheweny");

module.exports = class moderationToolsSelect extends SelectMenu {
constructor(client) {
super(client, ["moderation-tools-select"]);
}

async execute(selectMenu) {
if (!(await this.client.Defer(selectMenu))) return;
const { guild, values } = selectMenu;

await this.client.updateGuild(guild, {
"moderationTools.enabled": values,
});

const spelledValues = values
.map((value) => {
switch (value) {
case "blacklist":
return "\n`🛡️` Blacklist";
case "delDcInvites":
return "\n`🔗` Discord Invites Suppressor";
}
})
.join(", ");

return selectMenu.editReply({
content: `**Moderation tools enabled:**${
!spelledValues ? " ❎" : spelledValues
}`,
});
}
};
47 changes: 47 additions & 0 deletions src/interactions/select-menus/setupMenu-secondMsg-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,23 @@ module.exports = class SetupMenu2MsgSelect extends SelectMenu {
case "blacklist_option":
const blacklistTime = fetchGuild.blackList.time;
const blacklistMinAge = fetchGuild.blackList.minAge;
const blacklistState =
fetchGuild.moderationTools.enabled.includes("blacklist");

if (!blacklistState) {
return interaction.editReply({
content:
"`🛡️` Blacklist feature is disabled\n\n> Would you like to activate it?",
components: this.client.ButtonRow([
{
customId: "blacklist-tool",
label: "",
style: "SUCCESS",
emoji: "✅",
},
]),
});
}

return selectMenu.editReply({
content: `\`🛡️\` **Blacklist** is a feature that **prevents freshly created accounts from joining your server**. New accounts are often **bots, scams and adverts** that could be used maliciously to **harm your server users**.\n\nBlacklist is **activated by default**, you can change the times according to **your needs**:\n> \`Blacklist length: ${this.client.PrettyMs(
Expand Down Expand Up @@ -267,6 +284,36 @@ module.exports = class SetupMenu2MsgSelect extends SelectMenu {
]),
],
});

case "moderation_option":
const moderationTools = fetchGuild.moderationTools;

return selectMenu.editReply({
components: [
this.client.SelectMenuRow(
"moderation-tools-select",
"Manage your tools",
[
{
label: "Blacklist",
description: "Protect your server against bots, scams, etc.",
value: "blacklist",
emoji: "🛡️",
default: moderationTools.enabled.includes("blacklist"),
},
{
label: "Discord invites suppressor",
description:
"Automatically deletes invitations sent by non-moderators",
value: "delDcInvites",
emoji: "🔗",
default: moderationTools.enabled.includes("delDcInvites"),
},
],
{ min: 0, max: 2 }
),
],
});
}
}
};

0 comments on commit 8d93453

Please sign in to comment.