From f061275ce6ead35a9b37b8aecd1b86021913d27e Mon Sep 17 00:00:00 2001 From: Lucid Kobold Date: Mon, 29 Sep 2025 01:03:15 -0400 Subject: [PATCH] Added conditional to respond appositely to private messages. Added documentation. Denoted which commands are only available to admins or in private. --- src/bot/features/helpCommand.ts | 106 +++++++++++++++++++------------- 1 file changed, 64 insertions(+), 42 deletions(-) diff --git a/src/bot/features/helpCommand.ts b/src/bot/features/helpCommand.ts index cb9e563..56617b5 100644 --- a/src/bot/features/helpCommand.ts +++ b/src/bot/features/helpCommand.ts @@ -4,53 +4,63 @@ import { logHandle } from "#root/bot/helpers/logging.js"; const composer = new Composer(); -const feature = composer.chatType(["group", "supergroup"]); +const feature = composer.chatType(["group", "supergroup", "private"]); -feature.hears( - "/help", - logHandle("blacklist-detection"), - async (ctx: Context) => { - const GROUP_IDS = process.env.GROUP_IDS - ? process.env.GROUP_IDS.split(",") - : undefined; +/** + * What triggers this feature and adds to the log when it has been triggered. + * The trigger is the command "/help" + */ +feature.hears("/help", logHandle("help"), async (ctx: Context) => { + const GROUP_IDS = process.env.GROUP_IDS + ? process.env.GROUP_IDS.split(",") + : undefined; - if (ctx.chat && ctx.msg) { - if (GROUP_IDS !== undefined) { - const groupID = ctx.chat.id; - const flag = GROUP_IDS.includes(`${groupID}`); - // const username = ctx.msg.from?.username; - - if (flag) { - await ctx.reply( - `**Here are the availible commands you can use:**\n\n/getGroupID \\- replied with the ID of the group I am in\\.\n\n/isLCMGRoup \\- Checks if this group's ID is on the whitelist and responds accordingly\\.\n\n/botInfo \\- Info about me and how to fork me to deploy for your own use\\.\n\n/help \\- Displays this help message\\.`, - { - parse_mode: "MarkdownV2", - reply_parameters: { message_id: ctx.msg.message_id } - } - ); + // Checks there is a chat and msg property in the context. + if (ctx.chat && ctx.msg) { + // CHecks if the chat is private + if (ctx.chat.type === "private") { + // Responds with the command list. + return await ctx.reply( + `**Here are the available commands you can use:**\n\n/getGroupID _ADMIN ONLY | Only available in groups_\\- Replies with the ID of the group I am in\\.\n\n/isWKCGRoup _ADMIN ONLY_ \\- Checks if this group's ID is on the whitelist and responds accordingly\\.\n\n/botInfo _Private Command_\\- Info about me and how to fork me to deploy for your own use\\.\n\n/help\\- Displays this help message\\.`, + { + parse_mode: "MarkdownV2", + reply_parameters: { message_id: ctx.msg.message_id } } + ); + } - if (!flag) { - await ctx.reply( - `**Since this is not a whitelisted group the features are limited\\!\\!**\n\nHere are the availible commands you can use:\n\n/isLCMGRoup \\- Checks if this group's ID is on the whitelist and responds accordingly\\.\n\n/botInfo \\- Info about me and how to fork me to deploy for your own use\\.\n\n/help \\- Displays this help message\\.`, - { - parse_mode: "MarkdownV2", - reply_parameters: { message_id: ctx.msg.message_id } - } - ); - await ctx.reply( - `This group is NOT in the whitelisted and is NOT a part of the LCM Telegram groups/communities\\. I am a bot designed to delete any Twitter/X links and reformatting services within groups\\. You can fork me from this link: https://github\\.com/lucid\\-creations\\-media/no\\-twitter\\-bot and deploy me for use in your own groups\\!`, - { - parse_mode: "MarkdownV2", - reply_parameters: { message_id: ctx.msg.message_id } - } - ); - } + // Checks if the whitelist is set up. + if (GROUP_IDS !== undefined) { + const groupID = ctx.chat.id; + const flag = GROUP_IDS.includes(`${groupID}`); + + // Checks if the chat is in the whitelist. + if (flag) { + // Responds with the command list. + return await ctx.reply( + `**Here are the available commands you can use:**\n\n/getGroupID _ADMIN ONLY_ \\- Replies with the ID of the group I am in\\.\n\n/isWKCGRoup _ADMIN ONLY_ \\- Checks if this group's ID is on the whitelist and responds accordingly\\.\n\n/botInfo _Private Command_\\- Info about me and how to fork me to deploy for your own use\\.\n\n/help\\- Displays this help message\\.`, + { + parse_mode: "MarkdownV2", + reply_parameters: { message_id: ctx.msg.message_id } + } + ); } - if (!GROUP_IDS) { - await ctx.reply( - `There was a problem retrieving the whitelist. Check the env variables and try again\\.`, + // Checks if the chat is not in the whitelist. + if (!flag) { + await ctx + // Responds with the command list with a warning that the available commands are limited. + .reply( + `**Since this is not a whitelisted group the features are limited\\!\\!**\n\nHere are the available commands you can use:\n\n/isWKCGRoup _ADMIN ONLY_\\- Checks if this group's ID is on the whitelist and responds accordingly\\.\n\n/botInfo _Private Command_\\- Info about me and how to fork me to deploy for your own use\\.\n\n/help \\- Displays this help message\\.`, + { + parse_mode: "MarkdownV2", + reply_parameters: { message_id: ctx.msg.message_id } + } + ) + .then(() => {}); + // Sends a follow-up message with information about the bot. + return await ctx.reply( + `This group is NOT in the whitelisted and is NOT a part of the WKC Telegram groups/communities\\. I am a bot designed to delete any Twitter/X and Meta links along with corresponding reformatting services within whitelisted groups\\. You can fork me from this link: https://github\\.com/lucid\\-creations\\-media/no\\-twitter\\-bot and deploy me for use in your own groups\\!`, { parse_mode: "MarkdownV2", reply_parameters: { message_id: ctx.msg.message_id } @@ -58,7 +68,19 @@ feature.hears( ); } } + + // Checks if the whitelist is not set up. + if (!GROUP_IDS) { + // Sends a warning that the whitelist is not set up or the bot cannot access it. + return await ctx.reply( + `There was a problem retrieving the whitelist\\. Check the env variables and try again\\.`, + { + parse_mode: "MarkdownV2", + reply_parameters: { message_id: ctx.msg.message_id } + } + ); + } } -); +}); export { composer as helpCommand };