Skip to content

Commit

Permalink
🔎 Verification, fixes #11
Browse files Browse the repository at this point in the history
  • Loading branch information
Pexilo committed Oct 11, 2022
2 parents 2a24180 + b784a91 commit 5a256f9
Show file tree
Hide file tree
Showing 17 changed files with 748 additions and 108 deletions.
8 changes: 4 additions & 4 deletions 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.2.3-blue.svg?cacheSeconds=2592000&style=for-the-badge" />
<img alt="Version" src="https://img.shields.io/badge/version-1.2.4-blue.svg?cacheSeconds=2592000&style=for-the-badge" />
</a>
<a href="https://discord.com/api/oauth2/authorize?client_id=877249354954580059&permissions=1099932462166&scope=bot%20applications.commands" target="_blank">
<img src="https://dcbadge.vercel.app/api/shield/877249354954580059?bot=true?&theme=blurple" />
Expand Down Expand Up @@ -41,7 +41,7 @@ Stealthy is my first ambitious personal project, it has been under development s

- Complete logging system
- Ban, kick, warm, mute users
- Blacklist protection against bots raids and scammers
- Blacklist, Verification protection
- Discord invites suppression
- Lock, slowdown, clear channels

Expand All @@ -58,7 +58,7 @@ Stealthy is my first ambitious personal project, it has been under development s
## 🌎 Supported Languages

#### • ☕ English᲼᲼᲼᲼᲼᲼᲼᲼• 💃 Spanish
#### • 🥖 French᲼᲼᲼᲼᲼᲼᲼᲼᲼᲼• 🥨 Deutsch
#### • 🥖 French᲼᲼᲼᲼᲼᲼᲼᲼• 🥨 Deutsch

> Thanks to Github Copilot for making most of the translations possible... 😵‍💫
Expand Down Expand Up @@ -135,7 +135,7 @@ _Note: Your bot must have all privileged gateway intents checked to work properl
```
TOKEN=your-bot-token
DEEPL_API_KEY=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX:fx
MONGO_URI=mongodb+srv://username:password@clusterName.6bo3a.mongodb.net/Data
MONGO_URI=mongodb+srv://username:password@clusterName.xxxxx.mongodb.net/Data
```

2. Rename the file `example.env` > `.env`
Expand Down
2 changes: 1 addition & 1 deletion example.env
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
TOKEN=your-bot-token
DEEPL_API_KEY=XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX:fx
MONGO_URI=mongodb+srv://username:password@clusterName.6bo3a.mongodb.net/Data
MONGO_URI=mongodb+srv://username:password@clusterName.xxxxx.mongodb.net/Data
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.2.3",
"version": "1.2.4",
"description": "Lightweight, easy to use discord bot meant to enrich the lifestyle of your server.",
"main": "src/client.js",
"scripts": {
Expand Down
260 changes: 208 additions & 52 deletions src/commands/admin/setup-Ids.js

Large diffs are not rendered by default.

8 changes: 7 additions & 1 deletion src/db-model/guild.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const guildSchema = new mongoose.Schema({
moderationTools: {
enabled: {
type: Array,
default: ["blacklist"],
default: ["blacklist", "verifyCaptcha"],
},
},

Expand Down Expand Up @@ -37,6 +37,12 @@ const guildSchema = new mongoose.Schema({
fields: { type: Array, default: [] },
},

verify: {
channel: { type: String, default: null },
message: { type: String, default: null },
role: { type: String, default: null },
},

autoRole: {
roles: { type: Array, default: [] },
},
Expand Down
12 changes: 10 additions & 2 deletions src/interactions/buttons/clear-confirm-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,22 @@ module.exports = class ClearConfirmButton extends Button {
const { errors } = this.client.la[lang];
const { clearConfirm } = this.client.la[lang].interactions.buttons;

// get the amount of messages to delete from the message content
const number = message.content.match(/\d+/)[0];
let realNb;

// realNb will be the real number of messages to delete
let realNb,
err41 = false; // if the messages are older than 14 days
await channel
.bulkDelete(number)
.then((nb) => (realNb = nb.size))
.catch((e) => {
err41 = true;
return button.editReply(errors.error41);
});
if (err41) return;

// wait for deletes to be done
await this.client.Wait(2000);

button.editReply({
Expand All @@ -30,7 +38,7 @@ module.exports = class ClearConfirmButton extends Button {
const logsChannel = this.client.channels.cache.get(fetchGuild.logs.channel);
const enabledLogs = fetchGuild.logs.enabled;
if (!logsChannel || !enabledLogs.includes("channels")) return;
await this.client.LogsChannelPermsCheck(guild, interaction, errors);
await this.client.LogsChannelPermsCheck(guild, button, errors);

logsChannel
.send({
Expand Down
21 changes: 20 additions & 1 deletion src/interactions/buttons/moderation-tools-buttons.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@ const { Button } = require("sheweny");

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

async execute(button) {
Expand All @@ -26,6 +31,20 @@ module.exports = class moderationToolsButtons extends Button {

button.editReply(moderationTools.delDcInv.reply);
break;

case "verify-captcha-tool-enable":
if (!modTools.includes("verifyCaptcha")) modTools.push("verifyCaptcha");

button.editReply(moderationTools.verifyCaptcha.reply1);
break;

case "verify-captcha-tool-disable":
if (modTools.includes("verifyCaptcha")) {
modTools.splice(modTools.indexOf("verifyCaptcha"), 1);
}

button.editReply(moderationTools.verifyCaptcha.reply2);
break;
}

await this.client.UpdateGuild(guild, {
Expand Down
14 changes: 10 additions & 4 deletions src/interactions/buttons/setup-first-button.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,18 +47,24 @@ module.exports = class SetupMenuButton extends Button {
{
label: setupFirst.modal1.option5.label,
description: setupFirst.modal1.option5.description,
value: "blacklist_option",
emoji: "🛡️",
value: "verify_option",
emoji: "🔎",
},
{
label: setupFirst.modal1.option6.label,
description: setupFirst.modal1.option6.description,
value: "moderation_option",
emoji: "🗡️",
value: "blacklist_option",
emoji: "🛡️",
},
{
label: setupFirst.modal1.option7.label,
description: setupFirst.modal1.option7.description,
value: "moderation_option",
emoji: "🗡️",
},
{
label: setupFirst.modal1.option8.label,
description: setupFirst.modal1.option8.description,
value: "lang_option",
emoji: "🌐",
},
Expand Down
111 changes: 111 additions & 0 deletions src/interactions/buttons/verify-buttons.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
const { Button } = require("sheweny");
const { PermissionFlagsBits } = require("discord.js");

module.exports = class verifyButton extends Button {
constructor(client) {
super(client, ["verify", /verify-.*/, "verify-edit"]);
}

async execute(button) {
const { guild, member } = button;
const { fetchGuild, lang } = await this.client.FetchAndGetLang(guild);
const { errors } = this.client.la[lang];
const { verify } = this.client.la[lang].interactions.buttons;

const me = await guild.members.fetchMe();
const requiredPerms = ["ManageRoles"];

if (!me.permissions.has(PermissionFlagsBits.ManageRoles))
return selectMenu.editReply({
content: eval(errors.error52),
});

const role = guild.roles.cache.get(fetchGuild.verify.role);
if (!role)
return button.editReply({
content: errors.error54,
});

switch (button.customId) {
case "verify":
if (!(await this.client.Defer(button))) return;

// check the member verification
if (member.roles.cache.has(role.id))
return button.editReply({
content: verify.alreadyVerified,
});

// check if the captcha is disabled
if (!fetchGuild.moderationTools.enabled.includes("verifyCaptcha")) {
member.roles.add(role).catch(() => undefined);
return button.editReply({ content: verify.reply1 });
}

// generate sequence and send it with the button id
const sequence = await this.client.GenerateCaptcha();
button.editReply({
embeds: [
this.client
.Embed()
.setTitle(verify.embed1.title)
.setDescription(verify.embed1.description)
.setFields({
name: verify.embed1.field1,
value: `\`\`\`${sequence}\`\`\``,
}),
],
components: [
this.client.ButtonRow([
{
customId: `verify-${sequence}`,
label: verify.button1,
style: "SECONDARY",
emoji: "🤖",
},
]),
],
});
break;

case "verify-edit":
if (!(await this.client.Defer(button))) return;

button.editReply({
content: verify.reply2,
components: [
this.client.ButtonRow([
{
customId: "verify-captcha-tool-enable",
label: verify.button2,
style: "SECONDARY",
emoji: "✅",
},
{
customId: "verify-captcha-tool-disable",
label: verify.button3,
style: "SECONDARY",
emoji: "❌",
},
]),
],
});
break;

case button.customId.match(/verify\-.{5}/g)[0]: // verify-xxxxx
// get the sequence and send it with the modal id
const sendSequence = button.customId.split("-")[1];
await button.showModal(
this.client.ModalRow(`verify-${sendSequence}`, verify.modal1.title, [
{
customId: "verify-input",
label: verify.modal1.field1,
style: "Short",
placeholder: `${sendSequence}`,
required: true,
},
])
);
}
}
};
47 changes: 47 additions & 0 deletions src/interactions/modals/verify-modal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
const { Modal } = require("sheweny");

module.exports = class verifyModal extends Modal {
constructor(client) {
super(client, [/verify-.*/]);
}

async execute(modal) {
const { guild, user, customId, fields } = modal;

const { fetchGuild, lang } = await this.client.FetchAndGetLang(guild);
const { errors } = this.client.la[lang];
const { verify } = this.client.la[lang].interactions.modals;

const userSequence = fields.getTextInputValue("verify-input");

const role = guild.roles.cache.get(fetchGuild.verify.role);
if (!role)
return modal.editReply({
content: errors.error54,
});
const member = guild.members.cache.get(user.id);

// check if the entered sequence is correct
if (!userSequence === customId.split("-")[1]) {
modal.reply({
content: verify.badCode,
ephemeral: true,
});
}

// check the member verification
if (member.roles.cache.has(role.id)) {
return modal.reply({
content: verify.alreadyVerified,
ephemeral: true,
});
}

// add the role
member.roles.add(role);
modal.reply({
content: verify.reply,
ephemeral: true,
});
}
};
2 changes: 2 additions & 0 deletions src/interactions/select-menus/moderation-tools-select.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ module.exports = class moderationToolsSelect extends SelectMenu {
return moderationTools.spelledValues.blacklist;
case "delDcInvites":
return moderationTools.spelledValues.delDcInv;
case "verifyCaptcha":
return moderationTools.spelledValues.verifyCaptcha;
}
})
.join(", ");
Expand Down
Loading

0 comments on commit 5a256f9

Please sign in to comment.