Compare commits
19 Commits
graphql
...
5c5e2ee5ba
| Author | SHA1 | Date | |
|---|---|---|---|
| 5c5e2ee5ba | |||
| cc4abb3385 | |||
| 299530b0dd | |||
| b8db58a71a | |||
| 8dce37fe08 | |||
| 593083d994 | |||
| d816568522 | |||
| 1361fab0ad | |||
| f6db2d5d7a | |||
| df433c1951 | |||
| c088d7c4a5 | |||
| 66fb9cef85 | |||
| 789803da59 | |||
| 8d8b7f4c3a | |||
| 0177aae79a | |||
| 8076b984f5 | |||
| 2050e61706 | |||
| 465fbf96c9 | |||
| 30546606d7 |
@@ -9,4 +9,5 @@ SERVER_PORT=3000
|
||||
BOT_ADMINS=[1]
|
||||
GROUP_IDS=-
|
||||
GRAPHQL_URL=http://localhost:3000/api/graphql
|
||||
GRAPHQL_API_TOKEN="token-here"
|
||||
GRAPHQL_API_TOKEN="token-here"
|
||||
GRAPHQL_MUTATION_KEY="token-here"
|
||||
4
.gitignore
vendored
4
.gitignore
vendored
@@ -135,4 +135,6 @@ data/
|
||||
|
||||
# Ignore SQLite database
|
||||
*.db
|
||||
*.db-journal
|
||||
*.db-journal
|
||||
|
||||
build
|
||||
@@ -1,9 +1,11 @@
|
||||
import globals from "globals";
|
||||
import pluginJs from "@eslint/js";
|
||||
import { defineConfig, globalIgnores } from "eslint/config";
|
||||
import tseslint from "typescript-eslint";
|
||||
|
||||
/** @type {import('eslint').Linter.Config[]} */
|
||||
export default [
|
||||
export default defineConfig([
|
||||
globalIgnores(["build/"]),
|
||||
{ files: ["**/*.{js,mjs,cjs,ts}"] },
|
||||
{ languageOptions: { globals: globals.browser } },
|
||||
pluginJs.configs.recommended,
|
||||
@@ -22,4 +24,4 @@ export default [
|
||||
]
|
||||
}
|
||||
}
|
||||
];
|
||||
]);
|
||||
|
||||
32
package.json
32
package.json
@@ -3,7 +3,7 @@
|
||||
"type": "module",
|
||||
"version": "3.1.0",
|
||||
"private": true,
|
||||
"packageManager": "yarn@4.9.2",
|
||||
"packageManager": "yarn@4.12.0",
|
||||
"description": "This grammY powered Telegram bot is designed to delete Twitter/X links and reformat services from whitelisted groups. This one is the main bot for the LCM Telegram groups/communities.",
|
||||
"imports": {
|
||||
"#root/*": "./build/src/*"
|
||||
@@ -32,26 +32,30 @@
|
||||
"@grammyjs/i18n": "1.1.2",
|
||||
"@grammyjs/parse-mode": "1.11.1",
|
||||
"@grammyjs/runner": "2.0.3",
|
||||
"@grammyjs/types": "3.22.2",
|
||||
"@hono/node-server": "1.19.4",
|
||||
"@grammyjs/types": "3.23.0",
|
||||
"@hono/node-server": "1.19.9",
|
||||
"@urql/core": "^6.0.1",
|
||||
"axios": "^1.13.3",
|
||||
"callback-data": "1.1.1",
|
||||
"grammy": "1.38.2",
|
||||
"hono": "4.9.9",
|
||||
"grammy": "1.39.3",
|
||||
"hono": "4.11.6",
|
||||
"iso-639-1": "3.1.5",
|
||||
"pino": "9.12.0",
|
||||
"pino-pretty": "13.1.1",
|
||||
"tsx": "4.20.6",
|
||||
"valibot": "1.1.0"
|
||||
"pino": "10.3.0",
|
||||
"pino-pretty": "13.1.3",
|
||||
"tsx": "4.21.0",
|
||||
"valibot": "1.2.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@antfu/eslint-config": "5.4.1",
|
||||
"@types/node": "^24.5.2",
|
||||
"eslint": "^9.36.0",
|
||||
"@antfu/eslint-config": "7.2.0",
|
||||
"@eslint/js": "^9.39.2",
|
||||
"@types/node": "^25.0.10",
|
||||
"eslint": "^9.39.2",
|
||||
"husky": "^9.1.7",
|
||||
"lint-staged": "^16.2.3",
|
||||
"lint-staged": "^16.2.7",
|
||||
"prettier": "3.8.1",
|
||||
"tsc-watch": "^7.2.0",
|
||||
"typescript": "^5.9.2"
|
||||
"typescript": "^5.9.3",
|
||||
"typescript-eslint": "^8.54.0"
|
||||
},
|
||||
"lint-staged": {
|
||||
"*.ts": "eslint"
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
import { Composer } from "grammy";
|
||||
import type { Context } from "#root/bot/context.js";
|
||||
import { logHandle } from "#root/bot/helpers/logging.js";
|
||||
import urql from "#root/lib/urql.js";
|
||||
import increment from "#root/lib/graphql/mutations/incrimentMutation.js";
|
||||
import { urql } from "#root/main.js";
|
||||
import increment from "#root/lib/graphql/mutations/incrementMutation.js";
|
||||
|
||||
const composer = new Composer<Context>();
|
||||
|
||||
@@ -16,7 +16,9 @@ feature.hears(
|
||||
/^\/botInfo/,
|
||||
logHandle("bot-info-command"),
|
||||
async (ctx: Context) => {
|
||||
await urql.mutation(increment, { trigger: true });
|
||||
const mutationKey = process.env.GRAPHQL_MUTATION_KEY || "";
|
||||
|
||||
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) {
|
||||
@@ -43,21 +45,21 @@ feature.hears(
|
||||
}
|
||||
);
|
||||
await ctx.reply(
|
||||
`[Lucid](https://werewolfkid.monster) made this bot as a protest against the enshittification of Twitter and Nazi\\-fication of it\\ ever since Elon Must did a Nazi salute at a Trump Rally celebrating Trump\\'s second inauguration\\.`,
|
||||
`[Lucid](https://werewolfkid.monster) made this bot as a protest against the enshittification and Nazi\\-fication of Twitter\\ ever since Elon Musk took it over. The final straw aws when he did a Nazi salute at a Trump Rally celebrating Trump\\'s second inauguration\\.`,
|
||||
{
|
||||
parse_mode: "MarkdownV2",
|
||||
reply_parameters: { message_id: ctx.msg.message_id }
|
||||
}
|
||||
);
|
||||
await ctx.reply(
|
||||
`Recently there have been reports of extremist right\\-wing individuals doxxing and harassing anyone left of center\\. The victims have come out to state that they\\'ve had several accounts hacked into\\, including onces with unique passwords\\. It is clear that these assholes are using some kind of script kiddie malware to capture\\/steal credentials and possibly even stored passwords\\.`,
|
||||
`There have been reports of extremist right\\-wing individuals doxxing and harassing anyone left of center\\. The victims have come out to state that they\\'ve had several accounts hacked into\\, including onces with unique passwords\\. It is clear that these assholes are using some kind of script kiddie malware to capture\\/steal credentials and possibly even stored passwords\\.`,
|
||||
{
|
||||
parse_mode: "MarkdownV2",
|
||||
reply_parameters: { message_id: ctx.msg.message_id }
|
||||
}
|
||||
);
|
||||
return await ctx.reply(
|
||||
`Lucid decided it was time to make a statement\\. Twitter\\/X is not safe anymore\\. The fandom doesn\\'t need it\\. It should be boycotted and not allowed anymore\\. Thus decided to try making this bot public\\-use to test it's viability\\. Feel free to add this bot into your own group\\. All it needs is an admin role with the permission to delete messages\\.`,
|
||||
`Lucid decided it was time to make a statement\\. Twitter\\/X is not safe anymore\\. The fandom doesn\\'t need it\\. It should be boycotted and not allowed anymore\\. Thus they decided to try making this bot public\\-use to test it's viability\\. Feel free to add this bot into your own group\\. All it needs is an admin role with the permission to delete messages\\.`,
|
||||
{
|
||||
parse_mode: "MarkdownV2",
|
||||
reply_parameters: { message_id: ctx.msg.message_id }
|
||||
|
||||
53
src/bot/features/botStatsSiteCommand.ts
Normal file
53
src/bot/features/botStatsSiteCommand.ts
Normal file
@@ -0,0 +1,53 @@
|
||||
import { Composer } from "grammy";
|
||||
import type { Context } from "#root/bot/context.js";
|
||||
import { logHandle } from "#root/bot/helpers/logging.js";
|
||||
import { urql } from "#root/main.js";
|
||||
import increment from "#root/lib/graphql/mutations/incrementMutation.js";
|
||||
|
||||
const composer = new Composer<Context>();
|
||||
|
||||
const feature = composer.chatType(["private", "group", "supergroup"]);
|
||||
|
||||
/**
|
||||
* What triggers this feature and adds to the log when it has been triggered.
|
||||
* The trigger is the command "/botInfo"
|
||||
*/
|
||||
feature.hears(
|
||||
/^\/botStats/,
|
||||
logHandle("site-stats-command"),
|
||||
async (ctx: Context) => {
|
||||
const mutationKey = process.env.GRAPHQL_MUTATION_KEY || "";
|
||||
|
||||
await urql.mutation(increment, { trigger: true, mutationKey });
|
||||
|
||||
// Checks if the context includes a message property.
|
||||
if (ctx.msg && ctx.chat && ctx.msg.from) {
|
||||
// Doesn't respond to regular users in groups. This is to prevent users spamming the command.
|
||||
if (ctx.chat.type !== "private") {
|
||||
const chatMember = await ctx.getChatMember(ctx.msg.from.id);
|
||||
|
||||
if (!["creator", "administrator"].includes(chatMember.status)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
await urql
|
||||
.mutation(increment, { command: true, mutationKey })
|
||||
.toPromise()
|
||||
.then(async () => {
|
||||
if (ctx.msg) {
|
||||
// Replies to the message.
|
||||
return await ctx.reply(
|
||||
`The bot statistics website can be found at https://bot\\-stats\\.werewolfkid\\.monster/\\.`,
|
||||
{
|
||||
parse_mode: "MarkdownV2",
|
||||
reply_parameters: { message_id: ctx.msg.message_id }
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
export { composer as statsSiteCommand };
|
||||
@@ -3,8 +3,8 @@ import type { Context } from "#root/bot/context.js";
|
||||
import { logHandle } from "#root/bot/helpers/logging.js";
|
||||
import metaLinkCheck from "#root/lib/metaLinkCheck.js";
|
||||
import twitterLinkCheck from "#root/lib/twitterLinkCheck.js";
|
||||
import urql from "#root/lib/urql.js";
|
||||
import increment from "#root/lib/graphql/mutations/incrimentMutation.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";
|
||||
|
||||
@@ -17,12 +17,14 @@ const feature = composer.chatType(["group", "supergroup"]);
|
||||
* 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 });
|
||||
const mutationKey = process.env.GRAPHQL_MUTATION_KEY || "";
|
||||
|
||||
await urql.mutation(increment, { trigger: true, mutationKey });
|
||||
|
||||
if (ctx.chat && ctx.msg) {
|
||||
const groupName = ctx.chat?.title;
|
||||
const groupID = ctx.chat?.id;
|
||||
const groupUsername = ctx.chat?.username;
|
||||
const groupName = ctx.chat?.title || "";
|
||||
const groupID = ctx.chat?.id.toString() || "";
|
||||
const groupUsername = ctx.chat?.username || "";
|
||||
let deletedLinks = 0;
|
||||
|
||||
const username = ctx.msg.from?.username;
|
||||
@@ -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
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
96
src/bot/features/getGroupStatsCommand.ts
Normal file
96
src/bot/features/getGroupStatsCommand.ts
Normal file
@@ -0,0 +1,96 @@
|
||||
import { Composer } from "grammy";
|
||||
import type { Context } from "#root/bot/context.js";
|
||||
import { logHandle } from "#root/bot/helpers/logging.js";
|
||||
import { urql } from "#root/main.js";
|
||||
import increment from "#root/lib/graphql/mutations/incrementMutation.js";
|
||||
import getGroupStats from "#root/lib/graphql/queries/getGroupStatsQuery.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 "/groupStats"
|
||||
*/
|
||||
feature.hears(
|
||||
/^\/groupStats/,
|
||||
logHandle("groups-stats-command"),
|
||||
async (ctx: Context) => {
|
||||
const mutationKey = process.env.GRAPHQL_MUTATION_KEY || "";
|
||||
|
||||
await urql.mutation(increment, { trigger: true, mutationKey });
|
||||
|
||||
// Checks if the context includes a message property.
|
||||
if (ctx.msg && ctx.chat && ctx.msg.from) {
|
||||
// Doesn't respond to regular users in groups. This is to prevent users spamming the command.
|
||||
const chatMember = await ctx.getChatMember(ctx.msg.from.id);
|
||||
if (!["creator", "administrator"].includes(chatMember.status)) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Stringify the groupID
|
||||
const groupID = ctx.chat?.id.toString() || "";
|
||||
|
||||
// Query to get group stats.
|
||||
await urql
|
||||
.query(getGroupStats, {
|
||||
groupID
|
||||
})
|
||||
.toPromise()
|
||||
.then(async res => {
|
||||
// Replies to the message.
|
||||
if (ctx.msg) {
|
||||
// Check if the group has a document in the database and respond accordingly.
|
||||
if (res.data.getGroupStats !== null) {
|
||||
const { name, username, linksDeleted } = res.data.getGroupStats;
|
||||
|
||||
await ctx.reply(
|
||||
`Your group is registered in the database as "${name}" ${
|
||||
username.length
|
||||
? `with a username of ${name}`
|
||||
: `without a public username`
|
||||
}\\.\n\nThe bot has successfully deleted ${linksDeleted} links from your group\\.`,
|
||||
{
|
||||
parse_mode: "MarkdownV2",
|
||||
reply_parameters: { message_id: ctx.msg.message_id }
|
||||
}
|
||||
);
|
||||
|
||||
return await ctx.reply(
|
||||
`If you need to update this information you can use the \\/registerGroup command\\.`,
|
||||
{
|
||||
parse_mode: "MarkdownV2",
|
||||
reply_parameters: { message_id: ctx.msg.message_id }
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
// Default response //
|
||||
|
||||
await ctx.reply(
|
||||
`Your group was not found in the database\\. You can use the \\/registerGroup command to add your group to the database\\.`,
|
||||
{
|
||||
parse_mode: "MarkdownV2",
|
||||
reply_parameters: { message_id: ctx.msg.message_id }
|
||||
}
|
||||
);
|
||||
|
||||
return await ctx.reply(
|
||||
`This is optional\\. If the bot ever removes a link in your group then the group information will be added to the database and tracked from then on\\.`,
|
||||
{
|
||||
parse_mode: "MarkdownV2",
|
||||
reply_parameters: { message_id: ctx.msg.message_id }
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
return await urql
|
||||
.mutation(increment, { command: true, mutationKey })
|
||||
.toPromise();
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
export { composer as getGroupStats };
|
||||
@@ -1,8 +1,9 @@
|
||||
import { Composer } from "grammy";
|
||||
import type { Context } from "#root/bot/context.js";
|
||||
import { logHandle } from "#root/bot/helpers/logging.js";
|
||||
import urql from "#root/lib/urql.js";
|
||||
import increment from "#root/lib/graphql/mutations/incrimentMutation.js";
|
||||
import { urql } from "#root/main.js";
|
||||
import increment from "#root/lib/graphql/mutations/incrementMutation.js";
|
||||
import getCommandsList, { Commands } from "#root/lib/getCommandsList.js";
|
||||
|
||||
const composer = new Composer<Context>();
|
||||
|
||||
@@ -13,7 +14,12 @@ const feature = composer.chatType(["group", "supergroup", "private"]);
|
||||
* The trigger is the command "/help"
|
||||
*/
|
||||
feature.hears(/^\/help/, logHandle("help"), async (ctx: Context) => {
|
||||
await urql.mutation(increment, { trigger: true });
|
||||
const apiKey = process.env.GRAPHQL_API_TOKEN || "";
|
||||
const mutationKey = process.env.GRAPHQL_MUTATION_KEY || "";
|
||||
const statsSite = process.env.STATS_SITE || "";
|
||||
|
||||
await urql.mutation(increment, { trigger: true, mutationKey });
|
||||
const commandsListArr = await getCommandsList(`${statsSite}api/bot`, apiKey);
|
||||
|
||||
// const GROUP_IDS = process.env.GROUP_IDS
|
||||
// ? process.env.GROUP_IDS.split(",")
|
||||
@@ -22,7 +28,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) {
|
||||
@@ -30,7 +36,7 @@ feature.hears(/^\/help/, logHandle("help"), async (ctx: Context) => {
|
||||
if (ctx.chat.type === "private") {
|
||||
// Responds with message.
|
||||
await ctx.reply(
|
||||
`Currently I have no commands for the public beta\\. I require no configuration\\. Simply add me to a group and make me an admin with the permission to delete messages\\. From there I will start deleting any Twitter\\/X and Meta links I detect\\. I also check embeds and forwards\\. Use /\\botInfo to learn more about my mission and why I was created\\.`,
|
||||
`I require no configuration\\. Simply add me to a group and make me an admin with the permission to delete messages\\. From there I will start deleting any Twitter\\/X and Meta links I detect\\. I also check embeds and forwards\\.`,
|
||||
{
|
||||
parse_mode: "MarkdownV2",
|
||||
reply_parameters: { message_id: ctx.msg.message_id }
|
||||
@@ -46,7 +52,7 @@ feature.hears(/^\/help/, logHandle("help"), async (ctx: Context) => {
|
||||
if (["creator", "administrator"].includes(chatMember.status)) {
|
||||
// Respond with message.
|
||||
await ctx.reply(
|
||||
`Currently I have no commands for the public beta\\. I require no configuration\\. If I am not working\\, make sure I have an admin role with the permission to delete messages\\. I should already be deleting any Twitter\\/X and Meta links I detect\\. I also check embeds and forwards\\. Use /\\botInfo to learn more about my mission and why I was created\\.`,
|
||||
`I require no configuration\\. If I am not working\\, make sure I have an admin role with the permission to delete messages\\. I should already be deleting any Twitter\\/X and Meta links I detect\\. I also check embeds and forwards\\.`,
|
||||
{
|
||||
parse_mode: "MarkdownV2",
|
||||
reply_parameters: { message_id: ctx.msg.message_id }
|
||||
@@ -61,6 +67,17 @@ feature.hears(/^\/help/, logHandle("help"), async (ctx: Context) => {
|
||||
}
|
||||
}
|
||||
|
||||
const commandsListStr = commandsListArr.reduce((prev, curr) => {
|
||||
const { command, description, groups } = curr;
|
||||
|
||||
return (prev += `**Command**: ${command} \\- ${description}\\.\nGroups: ${groups ? "✔️" : "❌"} \\| Private: ${curr.private ? "✔️" : "❌"}\n\n`);
|
||||
}, "Here are a list of my commands:\n\n");
|
||||
|
||||
await ctx.reply(commandsListStr, {
|
||||
parse_mode: "MarkdownV2",
|
||||
reply_parameters: { message_id: ctx.msg.message_id }
|
||||
});
|
||||
|
||||
await ctx.reply(
|
||||
`In the future a public GitHub repo will be set up with a mirror of the private git that the bot code is stored on\\. That repo will be used to handle bug reports and feature requests\\. Including requests to check for more domains\\.`,
|
||||
{
|
||||
@@ -69,13 +86,13 @@ feature.hears(/^\/help/, logHandle("help"), async (ctx: Context) => {
|
||||
}
|
||||
);
|
||||
|
||||
return await ctx.reply(
|
||||
`Down with fascism\\! Fuck MAGA\\! Fuck Trump\\! Fuck Nazis\\! Trans rights are human rights\\! Trans women are women\\! Trans men are men\\! Never let them take away your happiness\\!`,
|
||||
{
|
||||
parse_mode: "MarkdownV2",
|
||||
reply_parameters: { message_id: ctx.msg.message_id }
|
||||
}
|
||||
);
|
||||
// return await ctx.reply(
|
||||
// `Down with fascism\\! Fuck MAGA\\! Fuck Trump\\! Fuck Nazis\\! Trans rights are human rights\\! Trans women are women\\! Trans men are men\\! Never let them take away your happiness\\!`,
|
||||
// {
|
||||
// parse_mode: "MarkdownV2",
|
||||
// reply_parameters: { message_id: ctx.msg.message_id }
|
||||
// }
|
||||
// );
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ 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 { 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";
|
||||
|
||||
@@ -17,9 +17,11 @@ const feature = composer.chatType(["group", "supergroup"]);
|
||||
*/
|
||||
feature.hears(
|
||||
metaRegex,
|
||||
logHandle("blacklist-detection-meta"),
|
||||
logHandle("banlist-detection-meta"),
|
||||
async (ctx: Context) => {
|
||||
await urql.mutation(increment, { trigger: true });
|
||||
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;
|
||||
@@ -27,25 +29,34 @@ feature.hears(
|
||||
ctx.msg.delete();
|
||||
|
||||
return await urql
|
||||
.mutation(increment, { link: true })
|
||||
.mutation(increment, { link: true, mutationKey })
|
||||
.toPromise()
|
||||
.then(async () => {
|
||||
if (ctx.msg) {
|
||||
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;
|
||||
const groupUsername = ctx.chat?.username;
|
||||
const groupName = ctx.chat?.title || "";
|
||||
const groupID = ctx.chat?.id.toString() || "";
|
||||
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
|
||||
})
|
||||
);
|
||||
}
|
||||
});
|
||||
@@ -53,4 +64,4 @@ feature.hears(
|
||||
}
|
||||
);
|
||||
|
||||
export { composer as metaBlacklist };
|
||||
export { composer as metaBanlist };
|
||||
65
src/bot/features/registerGroupCommand.ts
Normal file
65
src/bot/features/registerGroupCommand.ts
Normal file
@@ -0,0 +1,65 @@
|
||||
import { Composer } from "grammy";
|
||||
import type { Context } from "#root/bot/context.js";
|
||||
import { logHandle } from "#root/bot/helpers/logging.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";
|
||||
|
||||
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 "/registerGroup"
|
||||
*/
|
||||
feature.hears(
|
||||
/^\/registerGroup/,
|
||||
logHandle("register-group-command"),
|
||||
async (ctx: Context) => {
|
||||
const mutationKey = process.env.GRAPHQL_MUTATION_KEY || "";
|
||||
|
||||
await urql.mutation(increment, { trigger: true, mutationKey });
|
||||
|
||||
// Checks if the context includes a message property.
|
||||
if (ctx.msg && ctx.chat && ctx.msg.from) {
|
||||
// Doesn't respond to regular users in groups. This is to prevent users spamming the command.
|
||||
const chatMember = await ctx.getChatMember(ctx.msg.from.id);
|
||||
if (!["creator", "administrator"].includes(chatMember.status)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const groupName = ctx.chat?.title || "";
|
||||
const groupID = ctx.chat?.id.toString() || ""; // Stringify the groupID
|
||||
const groupUsername = ctx.chat?.username || "";
|
||||
|
||||
// Add or update the group
|
||||
await urql
|
||||
.mutation(addGroup, {
|
||||
groupID,
|
||||
groupName,
|
||||
groupUsername,
|
||||
mutationKey
|
||||
})
|
||||
.toPromise()
|
||||
.then(async () => {
|
||||
await urql
|
||||
.mutation(increment, { command: true, mutationKey })
|
||||
.toPromise();
|
||||
|
||||
if (ctx.msg) {
|
||||
// Replies to the message.
|
||||
return await ctx.reply(
|
||||
`Your group has been successfully added to the database\\.`,
|
||||
{
|
||||
parse_mode: "MarkdownV2",
|
||||
reply_parameters: { message_id: ctx.msg.message_id }
|
||||
}
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
export { composer as registerGroup };
|
||||
67
src/bot/features/tiktokBanlist.ts
Normal file
67
src/bot/features/tiktokBanlist.ts
Normal file
@@ -0,0 +1,67 @@
|
||||
import { Composer } from "grammy";
|
||||
import type { Context } from "#root/bot/context.js";
|
||||
import { logHandle } from "#root/bot/helpers/logging.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";
|
||||
import { tiktokRegex } from "#root/lib/tiktokLinkCheck.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 TikTok links within messages.
|
||||
*/
|
||||
feature.hears(
|
||||
tiktokRegex,
|
||||
logHandle("banlist-detection-tiktok"),
|
||||
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;
|
||||
// Deletes the offending message.
|
||||
ctx.msg.delete();
|
||||
|
||||
return await urql
|
||||
.mutation(increment, { link: true, mutationKey })
|
||||
.toPromise()
|
||||
.then(async () => {
|
||||
if (ctx.msg && ctx.chat) {
|
||||
// Replies to the user informing them of the action.
|
||||
await ctx.reply(
|
||||
`@${username} TikTok links 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 || "";
|
||||
|
||||
return await urql
|
||||
.mutation(addGroup, {
|
||||
groupID,
|
||||
groupName,
|
||||
groupUsername,
|
||||
mutationKey
|
||||
})
|
||||
.toPromise()
|
||||
.then(() =>
|
||||
urql.mutation(incrementGroup, {
|
||||
groupID,
|
||||
linksDeleted: 1,
|
||||
mutationKey
|
||||
})
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
export { composer as tiktokBanlist };
|
||||
@@ -2,8 +2,8 @@ import { Composer } from "grammy";
|
||||
import type { Context } from "#root/bot/context.js";
|
||||
import { logHandle } from "#root/bot/helpers/logging.js";
|
||||
import { twitterRegex } from "#root/lib/twitterLinkCheck.js";
|
||||
import urql from "#root/lib/urql.js";
|
||||
import increment from "#root/lib/graphql/mutations/incrimentMutation.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";
|
||||
|
||||
@@ -17,9 +17,11 @@ const feature = composer.chatType(["group", "supergroup"]);
|
||||
*/
|
||||
feature.hears(
|
||||
twitterRegex,
|
||||
logHandle("blacklist-detection-twitter"),
|
||||
logHandle("banlist-detection-twitter"),
|
||||
async (ctx: Context) => {
|
||||
await urql.mutation(increment, { trigger: true });
|
||||
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;
|
||||
@@ -27,25 +29,34 @@ feature.hears(
|
||||
ctx.msg.delete();
|
||||
|
||||
return await urql
|
||||
.mutation(increment, { link: true })
|
||||
.mutation(increment, { link: true, mutationKey })
|
||||
.toPromise()
|
||||
.then(async () => {
|
||||
if (ctx.msg) {
|
||||
if (ctx.msg && ctx.chat) {
|
||||
// Replies to the user informing them of the action.
|
||||
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" }
|
||||
);
|
||||
|
||||
const groupName = ctx.chat?.title;
|
||||
const groupID = ctx.chat?.id;
|
||||
const groupUsername = ctx.chat?.username;
|
||||
const groupName = ctx.chat?.title || "";
|
||||
const groupID = ctx.chat?.id.toString() || "";
|
||||
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
|
||||
})
|
||||
);
|
||||
}
|
||||
});
|
||||
@@ -53,4 +64,4 @@ feature.hears(
|
||||
}
|
||||
);
|
||||
|
||||
export { composer as twitterBlacklist };
|
||||
export { composer as twitterBanlist };
|
||||
@@ -1,21 +1,24 @@
|
||||
import { Composer } from "grammy";
|
||||
import type { Context } from "#root/bot/context.js";
|
||||
import { logHandle } from "#root/bot/helpers/logging.js";
|
||||
import urql from "#root/lib/urql.js";
|
||||
import increment from "#root/lib/graphql/mutations/incrimentMutation.js";
|
||||
import { urql } from "#root/main.js";
|
||||
import increment from "#root/lib/graphql/mutations/incrementMutation.js";
|
||||
|
||||
const composer = new Composer<Context>();
|
||||
|
||||
const feature = composer.chatType("private");
|
||||
|
||||
/**
|
||||
* 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 });
|
||||
const mutationKey = process.env.GRAPHQL_MUTATION_KEY || "";
|
||||
|
||||
await urql.mutation(increment, { trigger: true, mutationKey });
|
||||
|
||||
await urql
|
||||
.mutation(increment, { command: true })
|
||||
.mutation(increment, { command: true, mutationKey })
|
||||
.toPromise()
|
||||
.then(async () => {
|
||||
if (ctx.msg) {
|
||||
|
||||
@@ -5,7 +5,7 @@ import type { BotConfig } from "grammy";
|
||||
import { unhandledFeature } from "#root/bot/features/unhandled.js";
|
||||
import { welcomeFeature } from "#root/bot/features/welcome.js";
|
||||
import { errorHandler } from "#root/bot/handlers/error.js";
|
||||
import { i18n, isMultipleLocales } from "#root/bot/i18n.js";
|
||||
import { i18n } from "#root/bot/i18n.js";
|
||||
import { session } from "#root/bot/middlewares/session.js";
|
||||
import { updateLogger } from "#root/bot/middlewares/update-logger.js";
|
||||
import { autoChatAction } from "@grammyjs/auto-chat-action";
|
||||
@@ -13,11 +13,15 @@ import { hydrate } from "@grammyjs/hydrate";
|
||||
import { hydrateReply, parseMode } from "@grammyjs/parse-mode";
|
||||
import { sequentialize } from "@grammyjs/runner";
|
||||
import { MemorySessionStorage, Bot as TelegramBot } from "grammy";
|
||||
import { twitterBlacklist } from "./features/twitterBlacklist.js";
|
||||
import { metaBlacklist } from "./features/metaBlacklist.js";
|
||||
import { twitterBanlist } from "./features/twitterBanlist.js";
|
||||
import { metaBanlist } from "./features/metaBanlist.js";
|
||||
import { tiktokBanlist } from "./features/tiktokBanlist.js";
|
||||
import { botInfoCommand } from "./features/botInfoCommand.js";
|
||||
import { helpCommand } from "./features/helpCommand.js";
|
||||
import { embedCheck } from "./features/embedCheck.js";
|
||||
import { registerGroup } from "./features/registerGroupCommand.js";
|
||||
import { getGroupStats } from "./features/getGroupStatsCommand.js";
|
||||
import { statsSiteCommand } from "./features/botStatsSiteCommand.js";
|
||||
|
||||
interface Dependencies {
|
||||
config: Config;
|
||||
@@ -70,10 +74,14 @@ export function createBot(
|
||||
// Commands
|
||||
protectedBot.use(botInfoCommand);
|
||||
protectedBot.use(helpCommand);
|
||||
protectedBot.use(registerGroup);
|
||||
protectedBot.use(getGroupStats);
|
||||
protectedBot.use(statsSiteCommand);
|
||||
|
||||
// Blacklist Feature
|
||||
protectedBot.use(twitterBlacklist);
|
||||
protectedBot.use(metaBlacklist);
|
||||
// banlist Feature
|
||||
protectedBot.use(twitterBanlist);
|
||||
protectedBot.use(metaBanlist);
|
||||
protectedBot.use(tiktokBanlist);
|
||||
protectedBot.use(embedCheck);
|
||||
|
||||
// must be the last handler
|
||||
|
||||
30
src/lib/getCommandsList.ts
Normal file
30
src/lib/getCommandsList.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import axios from "axios";
|
||||
|
||||
export interface Commands {
|
||||
command: String;
|
||||
description: String;
|
||||
groups: boolean;
|
||||
private: boolean;
|
||||
}
|
||||
|
||||
const fetchCommandsList = async (
|
||||
url: string,
|
||||
apiKey: string
|
||||
): Promise<Commands[]> => {
|
||||
let commandsList = [] as Commands[];
|
||||
|
||||
await axios
|
||||
.get(url, {
|
||||
headers: { "x-api-key": apiKey }
|
||||
})
|
||||
.then(res => {
|
||||
commandsList = res.data;
|
||||
})
|
||||
.catch(res => {
|
||||
console.error(res);
|
||||
});
|
||||
|
||||
return commandsList;
|
||||
};
|
||||
|
||||
export default fetchCommandsList;
|
||||
@@ -2,21 +2,19 @@ import { gql } from "@urql/core";
|
||||
|
||||
const addGroup = gql`
|
||||
mutation addGroup(
|
||||
$groupID: BigInt
|
||||
$groupName: String
|
||||
$groupID: String!
|
||||
$groupName: String!
|
||||
$groupUsername: String
|
||||
$mutationKey: String
|
||||
) {
|
||||
addGroup(
|
||||
groupID: $groupID
|
||||
groupName: $groupName
|
||||
groupUsername: $groupUsername
|
||||
mutationKey: $mutationKey
|
||||
) {
|
||||
telegramID
|
||||
name
|
||||
username
|
||||
linksDeleted
|
||||
createdAt
|
||||
updatedAt
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
@@ -1,14 +1,19 @@
|
||||
import { gql } from "@urql/core";
|
||||
|
||||
const incrementGroup = gql`
|
||||
mutation incrementGroup($groupID: BigInt, $linksDeleted: Int) {
|
||||
incrementGroup(groupID: $groupID, linksDeleted: $linksDeleted) {
|
||||
telegramID
|
||||
mutation incrementGroup(
|
||||
$groupID: String!
|
||||
$linksDeleted: Int!
|
||||
$mutationKey: String
|
||||
) {
|
||||
incrementGroup(
|
||||
groupID: $groupID
|
||||
linksDeleted: $linksDeleted
|
||||
mutationKey: $mutationKey
|
||||
) {
|
||||
name
|
||||
username
|
||||
linksDeleted
|
||||
createdAt
|
||||
updatedAt
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
22
src/lib/graphql/mutations/incrementMutation.ts
Normal file
22
src/lib/graphql/mutations/incrementMutation.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
import { gql } from "@urql/core";
|
||||
|
||||
const increment = gql`
|
||||
mutation increment(
|
||||
$command: Boolean
|
||||
$link: Boolean
|
||||
$trigger: Boolean
|
||||
$mutationKey: String
|
||||
) {
|
||||
increment(
|
||||
command: $command
|
||||
link: $link
|
||||
trigger: $trigger
|
||||
mutationKey: $mutationKey
|
||||
) {
|
||||
createdAt
|
||||
updatedAt
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export default increment;
|
||||
@@ -1,12 +0,0 @@
|
||||
import { gql } from "@urql/core";
|
||||
|
||||
const increment = gql`
|
||||
mutation increment($command: Boolean, $link: Boolean, $trigger: Boolean) {
|
||||
increment(command: $command, link: $link, trigger: $trigger) {
|
||||
createdAt
|
||||
updatedAt
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export default increment;
|
||||
13
src/lib/graphql/queries/getGroupStatsQuery.ts
Normal file
13
src/lib/graphql/queries/getGroupStatsQuery.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { gql } from "@urql/core";
|
||||
|
||||
const getGroupStats = gql`
|
||||
query getGroupStats($groupID: String!) {
|
||||
getGroupStats(groupID: $groupID) {
|
||||
name
|
||||
username
|
||||
linksDeleted
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
export default getGroupStats;
|
||||
@@ -5,7 +5,7 @@ const metaRegex =
|
||||
/**
|
||||
* This function will check if a url matches Meta services links using regex.
|
||||
*
|
||||
* @param linkUrl representing a suspected blacklisted url
|
||||
* @param linkUrl representing a suspected url on the banlist
|
||||
* @returns flag
|
||||
*/
|
||||
const metaLinkCheck = (linkUrl: string): boolean => {
|
||||
|
||||
21
src/lib/tiktokLinkCheck.ts
Normal file
21
src/lib/tiktokLinkCheck.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
// Global regex used to detect TikTok links.
|
||||
const tiktokRegex = /(tiktok\.com)/gi;
|
||||
|
||||
/**
|
||||
* This function will check if a url matches TikTok services links using regex.
|
||||
*
|
||||
* @param linkUrl representing a suspected url on the banlist
|
||||
* @return flag
|
||||
*/
|
||||
const tiktokLinkCheck = (linkUrl: string): boolean => {
|
||||
let flag = false;
|
||||
|
||||
if (linkUrl.match(tiktokRegex)) {
|
||||
flag = true;
|
||||
}
|
||||
|
||||
return flag;
|
||||
};
|
||||
|
||||
export { tiktokRegex };
|
||||
export default tiktokLinkCheck;
|
||||
@@ -4,7 +4,7 @@ const twitterRegex = /(x\.com|twitter\.com)/gi;
|
||||
/**
|
||||
* This function will check if a url matches Twitter/X services links using regex.
|
||||
*
|
||||
* @param linkUrl representing a suspected blacklisted url
|
||||
* @param linkUrl representing a suspected url on the banlist
|
||||
* @return flag
|
||||
*/
|
||||
const twitterLinkCheck = (linkUrl: string): boolean => {
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
import { Client, cacheExchange, fetchExchange } from "@urql/core";
|
||||
|
||||
const urql = new Client({
|
||||
url: process.env.GRAPHQL_URL || "",
|
||||
exchanges: [cacheExchange, fetchExchange],
|
||||
fetchOptions: {
|
||||
headers: {
|
||||
"x-api-key": process.env?.GRAPHQL_API_TOKEN || ""
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
export default urql;
|
||||
11
src/main.ts
11
src/main.ts
@@ -8,6 +8,7 @@ import { config } from "#root/config.js";
|
||||
import { logger } from "#root/logger.js";
|
||||
import { createServer, createServerManager } from "#root/server/index.js";
|
||||
import { run } from "@grammyjs/runner";
|
||||
import { cacheExchange, Client, fetchExchange } from "@urql/core";
|
||||
|
||||
async function startPolling(config: PollingConfig) {
|
||||
const bot = createBot(config.botToken, {
|
||||
@@ -112,3 +113,13 @@ function onShutdown(cleanUp: () => Promise<void>) {
|
||||
process.on("SIGINT", handleShutdown);
|
||||
process.on("SIGTERM", handleShutdown);
|
||||
}
|
||||
|
||||
export const urql = new Client({
|
||||
url: process.env.GRAPHQL_URL || "",
|
||||
exchanges: [fetchExchange, cacheExchange],
|
||||
fetchOptions: {
|
||||
headers: {
|
||||
"x-api-key": process.env?.GRAPHQL_API_TOKEN || ""
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user