From 2050e61706dcf2f590500003949d8ce0b08b4b69 Mon Sep 17 00:00:00 2001 From: Lucid Date: Wed, 10 Dec 2025 19:39:15 -0500 Subject: [PATCH] Added mutation key to features. --- src/bot/features/botInfoCommand.ts | 6 +++-- src/bot/features/embedCheck.ts | 26 ++++++++++++------- src/bot/features/helpCommand.ts | 6 +++-- src/bot/features/metaBlacklist.ts | 19 +++++++++++--- src/bot/features/twitterBlacklist.ts | 19 +++++++++++--- src/bot/features/welcome.ts | 7 +++-- src/lib/graphql/mutations/addGroupMutation.ts | 2 ++ .../mutations/incrementGroupMutation.ts | 12 +++++++-- .../graphql/mutations/incrimentMutation.ts | 14 ++++++++-- 9 files changed, 84 insertions(+), 27 deletions(-) diff --git a/src/bot/features/botInfoCommand.ts b/src/bot/features/botInfoCommand.ts index 2d867bf..917e7d1 100644 --- a/src/bot/features/botInfoCommand.ts +++ b/src/bot/features/botInfoCommand.ts @@ -8,6 +8,8 @@ const composer = new Composer(); const feature = composer.chatType(["private", "group", "supergroup"]); +const mutationKey = process.env.GRAPHQL_MUTATION_KEY || ""; + /** * What triggers this feature and adds to the log when it has been triggered. * The trigger is the command "/botInfo" @@ -16,7 +18,7 @@ feature.hears( /^\/botInfo/, logHandle("bot-info-command"), async (ctx: Context) => { - await urql.mutation(increment, { trigger: true }); + await urql.mutation(increment, { trigger: true, mutationKey }); // Checks if the context includes a message property. if (ctx.msg && ctx.chat && ctx.msg.from) { @@ -30,7 +32,7 @@ feature.hears( } await urql - .mutation(increment, { command: true }) + .mutation(increment, { command: true, mutationKey }) .toPromise() .then(async () => { if (ctx.msg) { diff --git a/src/bot/features/embedCheck.ts b/src/bot/features/embedCheck.ts index 4177fc2..b36d4df 100644 --- a/src/bot/features/embedCheck.ts +++ b/src/bot/features/embedCheck.ts @@ -12,12 +12,14 @@ const composer = new Composer(); const feature = composer.chatType(["group", "supergroup"]); +const mutationKey = process.env.GRAPHQL_MUTATION_KEY || ""; + /** * What triggers this feature and adds to the log when it has been triggered. * The trigger is anytime an embedded url is detected. */ feature.on("message::url", logHandle("embed-check"), async (ctx: Context) => { - await urql.mutation(increment, { trigger: true }); + await urql.mutation(increment, { trigger: true, mutationKey }); if (ctx.chat && ctx.msg) { const groupName = ctx.chat?.title; @@ -49,7 +51,7 @@ feature.on("message::url", logHandle("embed-check"), async (ctx: Context) => { deletedLinks++; await urql - .mutation(increment, { link: true }) + .mutation(increment, { link: true, mutationKey }) .toPromise() .then(async () => { if (ctx.msg) { @@ -69,7 +71,7 @@ feature.on("message::url", logHandle("embed-check"), async (ctx: Context) => { deletedLinks++; await urql - .mutation(increment, { link: true }) + .mutation(increment, { link: true, mutationKey }) .toPromise() .then(async () => { if (ctx.msg) { @@ -89,7 +91,7 @@ feature.on("message::url", logHandle("embed-check"), async (ctx: Context) => { deletedLinks++; await urql - .mutation(increment, { link: true }) + .mutation(increment, { link: true, mutationKey }) .toPromise() .then(async () => { if (ctx.msg) { @@ -114,7 +116,7 @@ feature.on("message::url", logHandle("embed-check"), async (ctx: Context) => { deletedLinks++; await urql - .mutation(increment, { link: true }) + .mutation(increment, { link: true, mutationKey }) .toPromise() .then(async () => { if (ctx.msg) { @@ -134,7 +136,7 @@ feature.on("message::url", logHandle("embed-check"), async (ctx: Context) => { deletedLinks++; await urql - .mutation(increment, { link: true }) + .mutation(increment, { link: true, mutationKey }) .toPromise() .then(async () => { if (ctx.msg) { @@ -154,7 +156,7 @@ feature.on("message::url", logHandle("embed-check"), async (ctx: Context) => { deletedLinks++; await urql - .mutation(increment, { link: true }) + .mutation(increment, { link: true, mutationKey }) .toPromise() .then(async () => { if (ctx.msg) { @@ -169,12 +171,18 @@ feature.on("message::url", logHandle("embed-check"), async (ctx: Context) => { if (deletedLinks) { return await urql - .mutation(addGroup, { groupID, groupName, groupUsername }) + .mutation(addGroup, { + groupID, + groupName, + groupUsername, + mutationKey + }) .toPromise() .then(() => urql.mutation(incrementGroup, { groupID, - linksDeleted: deletedLinks + linksDeleted: deletedLinks, + mutationKey }) ); } diff --git a/src/bot/features/helpCommand.ts b/src/bot/features/helpCommand.ts index 23295a7..1c7c6db 100644 --- a/src/bot/features/helpCommand.ts +++ b/src/bot/features/helpCommand.ts @@ -8,12 +8,14 @@ const composer = new Composer(); const feature = composer.chatType(["group", "supergroup", "private"]); +const mutationKey = process.env.GRAPHQL_MUTATION_KEY || ""; + /** * 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) => { - await urql.mutation(increment, { trigger: true }); + await urql.mutation(increment, { trigger: true, mutationKey }); // const GROUP_IDS = process.env.GROUP_IDS // ? process.env.GROUP_IDS.split(",") @@ -22,7 +24,7 @@ feature.hears(/^\/help/, logHandle("help"), async (ctx: Context) => { // Checks there is a chat and msg property in the context. if (ctx.chat && ctx.msg && ctx.msg.from) { await urql - .mutation(increment, { command: true }) + .mutation(increment, { command: true, mutationKey }) .toPromise() .then(async () => { if (ctx.msg && ctx.chat && ctx.msg.from) { diff --git a/src/bot/features/metaBlacklist.ts b/src/bot/features/metaBlacklist.ts index 8eaadc8..5cd3549 100644 --- a/src/bot/features/metaBlacklist.ts +++ b/src/bot/features/metaBlacklist.ts @@ -11,6 +11,8 @@ const composer = new Composer(); const feature = composer.chatType(["group", "supergroup"]); +const mutationKey = process.env.GRAPHQL_MUTATION_KEY || ""; + /** * 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. @@ -19,7 +21,7 @@ feature.hears( metaRegex, logHandle("blacklist-detection-meta"), async (ctx: Context) => { - await urql.mutation(increment, { trigger: true }); + await urql.mutation(increment, { trigger: true, mutationKey }); if (ctx.chat && ctx.msg) { const username = ctx.msg.from?.username; @@ -27,7 +29,7 @@ feature.hears( ctx.msg.delete(); return await urql - .mutation(increment, { link: true }) + .mutation(increment, { link: true, mutationKey }) .toPromise() .then(async () => { if (ctx.msg) { @@ -42,10 +44,19 @@ feature.hears( const groupUsername = ctx.chat?.username; return await urql - .mutation(addGroup, { groupID, groupName, groupUsername }) + .mutation(addGroup, { + groupID, + groupName, + groupUsername, + mutationKey + }) .toPromise() .then(() => - urql.mutation(incrementGroup, { groupID, linksDeleted: 1 }) + urql.mutation(incrementGroup, { + groupID, + linksDeleted: 1, + mutationKey + }) ); } }); diff --git a/src/bot/features/twitterBlacklist.ts b/src/bot/features/twitterBlacklist.ts index 8e04bfe..303a5f4 100644 --- a/src/bot/features/twitterBlacklist.ts +++ b/src/bot/features/twitterBlacklist.ts @@ -11,6 +11,8 @@ const composer = new Composer(); const feature = composer.chatType(["group", "supergroup"]); +const mutationKey = process.env.GRAPHQL_MUTATION_KEY || ""; + /** * 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. @@ -19,7 +21,7 @@ feature.hears( twitterRegex, logHandle("blacklist-detection-twitter"), async (ctx: Context) => { - await urql.mutation(increment, { trigger: true }); + await urql.mutation(increment, { trigger: true, mutationKey }); if (ctx.chat && ctx.msg) { const username = ctx.msg.from?.username; @@ -27,7 +29,7 @@ feature.hears( ctx.msg.delete(); return await urql - .mutation(increment, { link: true }) + .mutation(increment, { link: true, mutationKey }) .toPromise() .then(async () => { if (ctx.msg) { @@ -42,10 +44,19 @@ feature.hears( const groupUsername = ctx.chat?.username; return await urql - .mutation(addGroup, { groupID, groupName, groupUsername }) + .mutation(addGroup, { + groupID, + groupName, + groupUsername, + mutationKey + }) .toPromise() .then(() => - urql.mutation(incrementGroup, { groupID, linksDeleted: 1 }) + urql.mutation(incrementGroup, { + groupID, + linksDeleted: 1, + mutationKey + }) ); } }); diff --git a/src/bot/features/welcome.ts b/src/bot/features/welcome.ts index d491291..fc3b604 100644 --- a/src/bot/features/welcome.ts +++ b/src/bot/features/welcome.ts @@ -7,15 +7,18 @@ import increment from "#root/lib/graphql/mutations/incrimentMutation.js"; const composer = new Composer(); const feature = composer.chatType("private"); + +const mutationKey = process.env.GRAPHQL_MUTATION_KEY || ""; + /** * What triggers this feature and adds to the log when it has been triggered. * The trigger is the command "/start" or "start" */ feature.command("start", logHandle("command-start"), async ctx => { - await urql.mutation(increment, { trigger: true }); + await urql.mutation(increment, { trigger: true, mutationKey }); await urql - .mutation(increment, { command: true }) + .mutation(increment, { command: true, mutationKey }) .toPromise() .then(async () => { if (ctx.msg) { diff --git a/src/lib/graphql/mutations/addGroupMutation.ts b/src/lib/graphql/mutations/addGroupMutation.ts index 1998157..e139a83 100644 --- a/src/lib/graphql/mutations/addGroupMutation.ts +++ b/src/lib/graphql/mutations/addGroupMutation.ts @@ -5,11 +5,13 @@ const addGroup = gql` $groupID: BigInt $groupName: String $groupUsername: String + $mutationKey: String ) { addGroup( groupID: $groupID groupName: $groupName groupUsername: $groupUsername + mutationKey: $mutationKey ) { telegramID name diff --git a/src/lib/graphql/mutations/incrementGroupMutation.ts b/src/lib/graphql/mutations/incrementGroupMutation.ts index dc378a0..0470aca 100644 --- a/src/lib/graphql/mutations/incrementGroupMutation.ts +++ b/src/lib/graphql/mutations/incrementGroupMutation.ts @@ -1,8 +1,16 @@ import { gql } from "@urql/core"; const incrementGroup = gql` - mutation incrementGroup($groupID: BigInt, $linksDeleted: Int) { - incrementGroup(groupID: $groupID, linksDeleted: $linksDeleted) { + mutation incrementGroup( + $groupID: BigInt + $linksDeleted: Int + $mutationKey: String + ) { + incrementGroup( + groupID: $groupID + linksDeleted: $linksDeleted + mutationKey: $mutationKey + ) { telegramID name username diff --git a/src/lib/graphql/mutations/incrimentMutation.ts b/src/lib/graphql/mutations/incrimentMutation.ts index 7303e73..3960b1e 100644 --- a/src/lib/graphql/mutations/incrimentMutation.ts +++ b/src/lib/graphql/mutations/incrimentMutation.ts @@ -1,8 +1,18 @@ import { gql } from "@urql/core"; const increment = gql` - mutation increment($command: Boolean, $link: Boolean, $trigger: Boolean) { - increment(command: $command, link: $link, trigger: $trigger) { + mutation increment( + $command: Boolean + $link: Boolean + $trigger: Boolean + $mutationKey: String + ) { + increment( + command: $command + link: $link + trigger: $trigger + mutationKey: $mutationKey + ) { createdAt updatedAt }