diff --git a/config.json b/config.json index dc4bca6..3dc3c6b 100644 --- a/config.json +++ b/config.json @@ -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 }, diff --git a/dist/index.js b/dist/index.js index a382a89..c279027 100644 --- a/dist/index.js +++ b/dist/index.js @@ -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: @@ -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; +}; diff --git a/dist/util/readConfig.js b/dist/util/readConfig.js deleted file mode 100644 index 9954a6b..0000000 --- a/dist/util/readConfig.js +++ /dev/null @@ -1,12 +0,0 @@ -"use strict"; -var __importDefault = (this && this.__importDefault) || function (mod) { - return (mod && mod.__esModule) ? mod : { "default": mod }; -}; -Object.defineProperty(exports, "__esModule", { value: true }); -exports.readConfig = void 0; -var fs_1 = __importDefault(require("fs")); -function readConfig(path) { - var data = fs_1.default.readFileSync(path, 'utf8'); - return JSON.parse(data); -} -exports.readConfig = readConfig; diff --git a/package.json b/package.json index 8bdb1ff..56d674c 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/readme.md b/readme.md index 8dd5f70..c0f9145 100644 --- a/readme.md +++ b/readme.md @@ -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", @@ -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** diff --git a/src/index.ts b/src/index.ts index 619163a..ef95540 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,4 @@ -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"; @@ -6,7 +6,6 @@ import {readJson} from "./util/readJson.js"; import {MessageMatcher} from "./message/MessageMatcher.js"; import {ResponseInterface} from "./interface/ResponseInterface"; - /** --- Declare constants --- */ const path = require('path'); @@ -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 @@ -62,4 +62,20 @@ client.on('messageCreate', async (message) => { }); // Login to Discord with your client's token -client.login(settings.token); \ No newline at end of file +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; +} + diff --git a/src/interface/SettingsInterface.ts b/src/interface/SettingsInterface.ts index b5dc5ff..dad9755 100644 --- a/src/interface/SettingsInterface.ts +++ b/src/interface/SettingsInterface.ts @@ -2,6 +2,7 @@ export interface SettingsInterface { token: string; bot: BotConfig; support_channels: string[]; + excluded_roles: string[]; urls: UrlsConfig; images: ImagesConfig; debug: boolean;