Updated company name. Protected command from non admins. Added documentation.
All checks were successful
Main / build-and-push-docker-image (20.x) (pull_request) Successful in 1m6s
All checks were successful
Main / build-and-push-docker-image (20.x) (pull_request) Successful in 1m6s
This commit is contained in:
@@ -1,57 +0,0 @@
|
||||
import { Composer } from "grammy";
|
||||
import type { Context } from "#root/bot/context.js";
|
||||
import { logHandle } from "#root/bot/helpers/logging.js";
|
||||
|
||||
const composer = new Composer<Context>();
|
||||
|
||||
const feature = composer.chatType(["group", "supergroup"]);
|
||||
|
||||
feature.hears(
|
||||
"/isLCMGroup",
|
||||
logHandle("is-LCM-group"),
|
||||
async (ctx: Context) => {
|
||||
const GROUP_IDS = process.env.GROUP_IDS
|
||||
? process.env.GROUP_IDS.split(",")
|
||||
: undefined;
|
||||
|
||||
if (ctx.chat && ctx.msg) {
|
||||
const groupID = ctx.chat.id;
|
||||
|
||||
if (GROUP_IDS !== undefined) {
|
||||
const flag = GROUP_IDS.includes(`${groupID}`);
|
||||
|
||||
if (flag) {
|
||||
await ctx.reply(
|
||||
`This group is in the whitelisted and is a part of the LCM Telegram groups/communities\\. I should be deleting any Twitter/X links and reformatting services within this group\\.`,
|
||||
{
|
||||
parse_mode: "MarkdownV2",
|
||||
reply_parameters: { message_id: ctx.msg.message_id }
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (!flag) {
|
||||
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 }
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (!GROUP_IDS) {
|
||||
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 isLCMGroup };
|
||||
80
src/bot/features/isWKCGroup.ts
Normal file
80
src/bot/features/isWKCGroup.ts
Normal file
@@ -0,0 +1,80 @@
|
||||
import { Composer } from "grammy";
|
||||
import type { Context } from "#root/bot/context.js";
|
||||
import { logHandle } from "#root/bot/helpers/logging.js";
|
||||
|
||||
const composer = new Composer<Context>();
|
||||
|
||||
const feature = composer.chatType(["group", "supergroup"]);
|
||||
|
||||
/**
|
||||
* What triggers this feature and adds to the log when it has been triggered.
|
||||
* The trigger is the command "/isWKCGroup"
|
||||
*/
|
||||
feature.hears(
|
||||
"/isWKCGroup",
|
||||
logHandle("is-WKC-group"),
|
||||
async (ctx: Context) => {
|
||||
// Pulling the group IDs from the env variables.
|
||||
const GROUP_IDS = process.env.GROUP_IDS
|
||||
? process.env.GROUP_IDS.split(",")
|
||||
: undefined;
|
||||
|
||||
// Checking that context has chat, msg, and msg.from properties
|
||||
if (ctx.chat && ctx.msg && ctx.msg.from) {
|
||||
const groupID = ctx.chat.id;
|
||||
const chatMember = await ctx.getChatMember(ctx.msg.from.id);
|
||||
|
||||
// Checking if the user is an admin.
|
||||
if (["creator", "administrator"].includes(chatMember.status)) {
|
||||
if (GROUP_IDS !== undefined) {
|
||||
const flag = GROUP_IDS.includes(`${groupID}`);
|
||||
|
||||
// Checking if the group is whitelisted.
|
||||
if (flag) {
|
||||
// Confirming that the group is whitelisted and should be deleting detected messages.
|
||||
await ctx.reply(
|
||||
`This group is in the whitelisted and is a part of the WKC Telegram groups/communities\\. I should be deleting any Twitter/X and Meta links along with corresponding reformatting services within this group\\.`,
|
||||
{
|
||||
parse_mode: "MarkdownV2",
|
||||
reply_parameters: { message_id: ctx.msg.message_id }
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
if (!flag) {
|
||||
// Informing the user that features are blocked because the group is not in the whitelist.
|
||||
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 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 }
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
if (!GROUP_IDS) {
|
||||
// Altering that the whitelist is not set or the bot cannot access it.
|
||||
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 }
|
||||
}
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// Informing the user that they need to be an admin to use this command.
|
||||
await ctx.reply(
|
||||
`You have to be an admin of this group to use this command\\!`,
|
||||
{
|
||||
parse_mode: "MarkdownV2",
|
||||
reply_parameters: { message_id: ctx.msg.message_id }
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
export { composer as isWKCGroup };
|
||||
@@ -19,7 +19,7 @@ import { botInfoCommand } from "./features/botInfoCommand.js";
|
||||
import { getGroupIDCommand } from "./features/getGroupIDCommand.js";
|
||||
import { helpCommand } from "./features/helpCommand.js";
|
||||
import { embedCheck } from "./features/embedCheck.js";
|
||||
import { isWKCGroup } from "./features/isLCMGroup.js";
|
||||
import { isWKCGroup } from "./features/isWKCGroup.js";
|
||||
|
||||
interface Dependencies {
|
||||
config: Config;
|
||||
|
||||
Reference in New Issue
Block a user