Added embed feature
This commit is contained in:
79
src/bot/features/embedCheck.ts
Normal file
79
src/bot/features/embedCheck.ts
Normal file
@@ -0,0 +1,79 @@
|
||||
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.on(
|
||||
"message:entities:url",
|
||||
logHandle("embed-check"),
|
||||
async (ctx: Context) => {
|
||||
if (ctx.chat && ctx.msg) {
|
||||
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 && ctx.msg.entities) {
|
||||
const embeds = ctx.msg.entities.filter(e => e.type === "text_link");
|
||||
|
||||
if (embeds.length) {
|
||||
const metaLinks = embeds.filter(({ url }) =>
|
||||
url.match(
|
||||
/(facebook.com|meta.com|instagram.com|threads.net|whatsapp.com)/gi
|
||||
)
|
||||
);
|
||||
const twitterLinks = embeds.filter(({ url }) =>
|
||||
url.match(/(x.com|twitter.com)/gi)
|
||||
);
|
||||
|
||||
if (metaLinks.length && twitterLinks.length) {
|
||||
ctx.msg.delete();
|
||||
return await ctx.reply(
|
||||
`@${username} Twitter and X links along with reformatting services for Twitter posts are not allowed here\\. Also Facebook and meta links along with with links to meta\\-owned services are not allowed here\\. Please consider sharing the media directly or from other social media sources or websites\\. No administration action was taken against you other than the message being deleted\\.`,
|
||||
{ parse_mode: "MarkdownV2" }
|
||||
);
|
||||
}
|
||||
|
||||
if (metaLinks.length) {
|
||||
ctx.msg.delete();
|
||||
return await ctx.reply(
|
||||
`@${username} Facebook and meta links along with with links to meta\\-owned services are not allowed here\\. Please consider sharing the media directly or from other social media sources or websites\\. No administration action was taken against you other than the message being deleted\\.`,
|
||||
{ parse_mode: "MarkdownV2" }
|
||||
);
|
||||
}
|
||||
|
||||
if (twitterLinks.length) {
|
||||
ctx.msg.delete();
|
||||
return await ctx.reply(
|
||||
`@${username} Twitter and X links along with reformatting services for Twitter posts are not allowed here\\. Please consider sharing the media directly or from other social media sources or websites\\. No administration action was taken against you other than the message being deleted\\.`,
|
||||
{ parse_mode: "MarkdownV2" }
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!GROUP_IDS) {
|
||||
console.info("Group IDS:", process.env.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 embedCheck };
|
||||
@@ -21,6 +21,7 @@ import { botInfoCommand } from "./features/botInfoCommand.js";
|
||||
import { getGroupIDCommand } from "./features/getGroupIDCommand.js";
|
||||
import { helpCommand } from "./features/helpCommand.js";
|
||||
import { isLCMGroup } from "./features/isLCMGroup.js";
|
||||
import { embedCheck } from "./features/embedCheck.js";
|
||||
|
||||
interface Dependencies {
|
||||
config: Config;
|
||||
@@ -81,6 +82,7 @@ export function createBot(
|
||||
// Blacklist Feature
|
||||
protectedBot.use(twitterBlacklist);
|
||||
protectedBot.use(metaBlacklist);
|
||||
protectedBot.use(embedCheck);
|
||||
|
||||
// must be the last handler
|
||||
protectedBot.use(unhandledFeature);
|
||||
|
||||
Reference in New Issue
Block a user