Files
no-twitter-bot/src/bot/features/metaBanlist.ts
T
Lucid 705bb73f19
Main / build-and-push-docker-image (20.x) (push) Successful in 4m9s
Update action flow for detected links to prevent bot/program crashing.
2026-04-01 17:11:37 -04:00

69 lines
2.4 KiB
TypeScript

import { Composer } from "grammy";
import type { Context } from "#root/bot/context.js";
import { logHandle } from "#root/bot/helpers/logging.js";
import { metaRegex } from "#root/lib/metaLinkCheck.js";
import { urql } from "#root/main.js";
import increment from "#root/lib/graphql/mutations/incrementMutation.js";
import addGroup from "#root/lib/graphql/mutations/addGroupMutation.js";
import incrementGroup from "#root/lib/graphql/mutations/incrementGroupMutation.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 uses the global Twitter regex to detect Twitter and X links within messages.
*/
feature.hears(
metaRegex,
logHandle("banlist-detection-meta"),
async (ctx: Context) => {
const mutationKey = process.env.GRAPHQL_MUTATION_KEY || "";
await urql.mutation(increment, { trigger: true, mutationKey });
if (ctx.chat && ctx.msg) {
const username = ctx.msg.from?.username;
return await urql
.mutation(increment, { link: 1, mutationKey })
.toPromise()
.then(async () => {
if (ctx.msg && ctx.chat) {
// Replies to the user informing them of the action.
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" }
);
const groupName = ctx.chat?.title || "";
const groupID = ctx.chat?.id.toString() || "";
const groupUsername = ctx.chat?.username || "";
// Deletes the offending message.
ctx.msg.delete();
return await urql
.mutation(addGroup, {
groupID,
groupName,
groupUsername,
mutationKey
})
.toPromise()
.then(() =>
urql.mutation(incrementGroup, {
groupID,
linksDeleted: 1,
mutationKey
})
);
}
});
}
}
);
export { composer as metaBanlist };