Skip to content

Commit

Permalink
Merge pull request #9 from AVMG20/excluded_roles
Browse files Browse the repository at this point in the history
Add Excluded Roles Feature to Bot
  • Loading branch information
AVMG20 authored Apr 8, 2023
2 parents b913c90 + 3ee20fc commit 6a76c7d
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 28 deletions.
6 changes: 5 additions & 1 deletion config.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@
"SUPPORT CHANNEL ID's HERE"
],

"excluded_roles": [
"EXCLUDED ROLE ID's HERE"
],

"urls": {
"allowed_urls": [
"https://pastebin.com",
"https://termbin.com",
"https://termbin.com"
],
"max_content_size_in_bytes": 314572
},
Expand Down
18 changes: 16 additions & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ client.on('messageCreate', function (message) { return __awaiter(void 0, void 0,
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
// Ignore messages from bots and messages that are not in the support channels
if (message.author.bot || !settings.support_channels.includes(message.channelId))
// Ignore messages that should not be responded to
if (!botShouldRespond(message))
return [2 /*return*/];
_a.label = 1;
case 1:
Expand Down Expand Up @@ -114,3 +114,17 @@ client.on('messageCreate', function (message) { return __awaiter(void 0, void 0,
}); });
// Login to Discord with your client's token
client.login(settings.token);
/** --- Helper functions --- */
var botShouldRespond = function (message) {
var _a;
// Ignore messages from bots
if (message.author.bot)
return false;
// Ignore messages that are not in the support channels
if (!settings.support_channels.includes(message.channelId))
return false;
// Ignore messages that are from users with excluded roles
if ((_a = message.member) === null || _a === void 0 ? void 0 : _a.roles.cache.some(function (role) { return settings.excluded_roles.includes(role.id); }))
return false;
return true;
};
12 changes: 0 additions & 12 deletions dist/util/readConfig.js

This file was deleted.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "smart-support-bot",
"private": true,
"version": "1.2.0",
"version": "1.2.1",
"scripts": {
"build": "tsc",
"start": "node dist/index.js",
Expand Down
18 changes: 11 additions & 7 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ an explanation of its contents:
"support_channels": [
"CHANNEL IDS HERE"
],
"excluded_roles": [
"ROLE IDS HERE"
],
"urls": {
"allowed_urls": [
"https://pastebin.com",
Expand All @@ -110,18 +113,19 @@ an explanation of its contents:
- **`"token"`**: Replace **`"BOT TOKEN HERE"`** with your bot's token.
- **`"bot"`**: Configure the bot's activity type, message, and status.
- **`"activity"`**: Set the activity type (e.g., **`"PLAYING"`**, **`"STREAMING"`**, **`"LISTENING"`**, *
*`"WATCHING"`**, or **`"COMPETING"`**).
***`"WATCHING"`***, or **`"COMPETING"`**).
- **`"activity_message"`**: Set a custom message for the bot's status.
- **`"activity_status"`**: Set the bot's online status (e.g., **`"online"`**, **`"idle"`**, **`"dnd"`** or *
*`"invisible"`**).
***`"invisible"`***).
- **`"support_channels"`**: Replace **`"CHANNEL IDS HERE"`** with an array of channel IDs where the bot should operate.
- **`"excluded_roles"`**: Replace **`"ROLE IDS HERE"`** with an array of role IDs that should be excluded from bot reactions.
- **`"urls"`**: Configure URL handling options.
- **`"allowed_urls"`**: Add an array of allowed URLs to parse.
- **`"max_content_size_in_bytes"`**: Set the maximum content size for URLs.
- **`"allowed_urls"`**: Add an array of allowed URLs to parse.
- **`"max_content_size_in_bytes"`**: Set the maximum content size for URLs.
- **`"images"`**: Configure image handling options.
- **`"max_size_in_bytes"`**: Set the maximum image size for parsing.
- **`"parse_language"`**: Set the language used for parsing images.
- **`"message_reaction"`**: Set the reaction to add to messages with images.
- **`"max_size_in_bytes"`**: Set the maximum image size for parsing.
- **`"parse_language"`**: Set the language used for parsing images.
- **`"message_reaction"`**: Set the reaction to add to messages with images.
- **`"debug"`**: Set to **`true`** to enable extra debug messages.

## **Configuring Responses**
Expand Down
26 changes: 21 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import {Client, GatewayIntentBits, PresenceStatusData} from 'discord.js';
import {Client, GatewayIntentBits, Message, PresenceStatusData} from 'discord.js';
import {assertActivityType} from "./util/assertActivityType.js";
import {MessageReader, MessageReaderConfig} from "./message/MessageReader.js";
import {SettingsInterface} from "./interface/SettingsInterface";
import {readJson} from "./util/readJson.js";
import {MessageMatcher} from "./message/MessageMatcher.js";
import {ResponseInterface} from "./interface/ResponseInterface";


/** --- Declare constants --- */

const path = require('path');
Expand Down Expand Up @@ -42,8 +41,9 @@ client.once('ready', async () => {

// Listen for messages
client.on('messageCreate', async (message) => {
// Ignore messages from bots and messages that are not in the support channels
if (message.author.bot || !settings.support_channels.includes(message.channelId)) return;

// Ignore messages that should not be responded to
if (!botShouldRespond(message)) return;

try {
// Read the message
Expand All @@ -62,4 +62,20 @@ client.on('messageCreate', async (message) => {
});

// Login to Discord with your client's token
client.login(settings.token);
client.login(settings.token);

/** --- Helper functions --- */

const botShouldRespond = (message: Message): boolean => {
// Ignore messages from bots
if (message.author.bot) return false;

// Ignore messages that are not in the support channels
if (!settings.support_channels.includes(message.channelId)) return false;

// Ignore messages that are from users with excluded roles
if (message.member?.roles.cache.some(role => settings.excluded_roles.includes(role.id))) return false;

return true;
}

1 change: 1 addition & 0 deletions src/interface/SettingsInterface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export interface SettingsInterface {
token: string;
bot: BotConfig;
support_channels: string[];
excluded_roles: string[];
urls: UrlsConfig;
images: ImagesConfig;
debug: boolean;
Expand Down

0 comments on commit 6a76c7d

Please sign in to comment.