Added graphql calls every time a feature is triggered, the bot responds to a command, and deletes a link
This commit is contained in:
@@ -2,6 +2,10 @@ 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/lib/urql.js";
|
||||
import increment from "#root/lib/graphql/mutations/incrimentMutation.js";
|
||||
import addGroup from "#root/lib/graphql/mutations/addGroupMutation.js";
|
||||
import incrementGroup from "#root/lib/graphql/mutations/incrementGroupMutation.js";
|
||||
|
||||
const composer = new Composer<Context>();
|
||||
|
||||
@@ -15,52 +19,37 @@ feature.hears(
|
||||
metaRegex,
|
||||
logHandle("blacklist-detection-meta"),
|
||||
async (ctx: Context) => {
|
||||
// Pulling the group IDs from the env variables.
|
||||
const GROUP_IDS = process.env.GROUP_IDS
|
||||
? process.env.GROUP_IDS.split(",")
|
||||
: undefined;
|
||||
await urql.mutation(increment, { trigger: true });
|
||||
|
||||
if (ctx.chat && ctx.msg) {
|
||||
const username = ctx.msg.from?.username;
|
||||
// Deletes the offending message.
|
||||
ctx.msg.delete();
|
||||
// Replies to the user informing them of the action.
|
||||
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" }
|
||||
);
|
||||
|
||||
return await urql
|
||||
.mutation(increment, { link: true })
|
||||
.toPromise()
|
||||
.then(async () => {
|
||||
if (ctx.msg) {
|
||||
// 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;
|
||||
const groupUsername = ctx.chat?.username;
|
||||
|
||||
return await urql
|
||||
.mutation(addGroup, { groupID, groupName, groupUsername })
|
||||
.toPromise()
|
||||
.then(() =>
|
||||
urql.mutation(incrementGroup, { groupID, linksDeleted: 1 })
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// if (ctx.chat && ctx.msg) {
|
||||
// if (GROUP_IDS !== undefined) {
|
||||
// // Checking if the message is from a whitelisted group.
|
||||
// const groupID = ctx.chat.id;
|
||||
// const flag = GROUP_IDS.includes(`${groupID}`);
|
||||
// const username = ctx.msg.from?.username;
|
||||
|
||||
// if (flag) {
|
||||
// // Deletes the offending message.
|
||||
// ctx.msg.delete();
|
||||
// // Replies to the user informing them of the action.
|
||||
// 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 the env variables are misconfigured an error is sent to the group.
|
||||
// if (!GROUP_IDS) {
|
||||
// console.info("Group IDS:", process.env.GROUP_IDS);
|
||||
// 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 }
|
||||
// }
|
||||
// );
|
||||
// }
|
||||
// }
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user