Compare commits

..

2 Commits

Author SHA1 Message Date
Lucid 68895a79e8 Upgrade dependencies
Main / build-and-push-docker-image (20.x) (pull_request) Successful in 6m16s
2026-04-01 17:14:10 -04:00
Lucid cfc30097d5 Upgrade dependencies 2026-04-01 17:12:40 -04:00
17 changed files with 353 additions and 574 deletions
+3 -3
View File
@@ -46,10 +46,10 @@
"valibot": "1.3.1"
},
"devDependencies": {
"@antfu/eslint-config": "7.7.3",
"@eslint/js": "^9.39.4",
"@antfu/eslint-config": "8.0.0",
"@eslint/js": "^10.0.1",
"@types/node": "^25.5.0",
"eslint": "^9.39.4",
"eslint": "^10.1.0",
"husky": "^9.1.7",
"lint-staged": "^16.4.0",
"prettier": "3.8.1",
+1 -1
View File
@@ -32,7 +32,7 @@ feature.hears(
}
await urql
.mutation(increment, { command: true, mutationKey }) // Increments the trigger count
.mutation(increment, { command: true, mutationKey })
.toPromise()
.then(async () => {
if (ctx.msg) {
+1 -1
View File
@@ -32,7 +32,7 @@ feature.hears(
}
await urql
.mutation(increment, { command: true, mutationKey }) // Increments the trigger count
.mutation(increment, { command: true, mutationKey })
.toPromise()
.then(async () => {
if (ctx.msg) {
+16 -20
View File
@@ -2,13 +2,12 @@ import { Composer } from "grammy";
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, { twitterRegex } from "#root/lib/twitterLinkCheck.js";
import twitterLinkCheck from "#root/lib/twitterLinkCheck.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 tiktokLinkCheck from "#root/lib/tiktokLinkCheck.js";
import fetchLink from "#root/lib/fetchLink.js";
const composer = new Composer<Context>();
@@ -21,10 +20,8 @@ const feature = composer.chatType(["group", "supergroup"]);
feature.on("message::url", logHandle("embed-check"), async (ctx: Context) => {
const mutationKey = process.env.GRAPHQL_MUTATION_KEY || "";
// Increments the trigger count
await urql.mutation(increment, { trigger: true, mutationKey });
// Checks there is a chat and msg property in the context.
if (ctx.chat && ctx.msg) {
const groupName = ctx.chat?.title || "";
const groupID = ctx.chat?.id.toString() || "";
@@ -44,25 +41,24 @@ feature.on("message::url", logHandle("embed-check"), async (ctx: Context) => {
// If the all embeds array isn't empty filter through them to check for every type of disallowed link.
if (allEmbeds.length) {
detectedLinks +=
allEmbeds.filter(({ url }) => metaLinkCheck(url)).length || 0;
const metaLinks = allEmbeds.filter(({ url }) => metaLinkCheck(url));
const twitterLinks = allEmbeds.filter(({ url }) => twitterLinkCheck(url));
const tiktokLinks = allEmbeds.filter(({ url }) => tiktokLinkCheck(url));
detectedLinks += (
await Promise.all(
allEmbeds.map(async ({ url }) => {
// Checks for a false positive.
if (twitterLinkCheck(url)) {
return await fetchLink(url, twitterRegex);
// Handles Meta & Facebook Links
if (metaLinks.length) {
detectedLinks += metaLinks.length;
}
return false;
})
)
).reduce((acc, curr) => {
return (acc += curr ? 1 : 0);
}, 0);
detectedLinks +=
allEmbeds.filter(({ url }) => tiktokLinkCheck(url)).length || 0;
// Handles Twitter/X links.
if (twitterLinks.length) {
detectedLinks += twitterLinks.length;
}
// Handles TikTok links.
if (tiktokLinks.length) {
detectedLinks += tiktokLinks.length;
}
}
if (detectedLinks) {
+1 -4
View File
@@ -3,7 +3,7 @@ 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 getCommandsList from "#root/lib/getCommandsList.js";
import getCommandsList, { Commands } from "#root/lib/getCommandsList.js";
const composer = new Composer<Context>();
@@ -18,9 +18,7 @@ feature.hears(/^\/help/, logHandle("help"), async (ctx: Context) => {
const mutationKey = process.env.GRAPHQL_MUTATION_KEY || "";
const statsSite = process.env.STATS_SITE || "";
// Increments the trigger count
await urql.mutation(increment, { trigger: true, mutationKey });
// Retrieve the command list
const commandsListArr = await getCommandsList(`${statsSite}api/bot`, apiKey);
// const GROUP_IDS = process.env.GROUP_IDS
@@ -69,7 +67,6 @@ feature.hears(/^\/help/, logHandle("help"), async (ctx: Context) => {
}
}
// Create a readable command list string.
const commandsListStr = commandsListArr.reduce((prev, curr) => {
const { command, description, groups } = curr;
-2
View File
@@ -21,10 +21,8 @@ feature.hears(
async (ctx: Context) => {
const mutationKey = process.env.GRAPHQL_MUTATION_KEY || "";
// Increments the trigger count
await urql.mutation(increment, { trigger: true, mutationKey });
// Checks there is a chat and msg property in the context.
if (ctx.chat && ctx.msg) {
const username = ctx.msg.from?.username;
-1
View File
@@ -19,7 +19,6 @@ feature.hears(
async (ctx: Context) => {
const mutationKey = process.env.GRAPHQL_MUTATION_KEY || "";
// Increments the trigger count
await urql.mutation(increment, { trigger: true, mutationKey });
// Checks if the context includes a message property.
-1
View File
@@ -21,7 +21,6 @@ feature.hears(
async (ctx: Context) => {
const mutationKey = process.env.GRAPHQL_MUTATION_KEY || "";
// Increments the trigger count
await urql.mutation(increment, { trigger: true, mutationKey });
if (ctx.chat && ctx.msg) {
+1 -8
View File
@@ -6,7 +6,6 @@ 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 fetchLink from "#root/lib/fetchLink.js";
const composer = new Composer<Context>();
@@ -22,10 +21,8 @@ feature.hears(
async (ctx: Context) => {
const mutationKey = process.env.GRAPHQL_MUTATION_KEY || "";
// Increments the trigger count
await urql.mutation(increment, { trigger: true, mutationKey });
// Checks there is a chat and msg property in the context.
if (ctx.chat && ctx.msg) {
const username = ctx.msg.from?.username;
@@ -33,11 +30,7 @@ feature.hears(
.mutation(increment, { link: 1, mutationKey })
.toPromise()
.then(async () => {
if (ctx.msg && ctx.chat && ctx.msg.text) {
// Checks for a false positive
const truePositive = await fetchLink(ctx.msg.text, twitterRegex);
if (!truePositive) return;
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\\.`,
-1
View File
@@ -15,7 +15,6 @@ const feature = composer.chatType("private");
feature.command("start", logHandle("command-start"), async ctx => {
const mutationKey = process.env.GRAPHQL_MUTATION_KEY || "";
// Increments the trigger count
await urql.mutation(increment, { trigger: true, mutationKey });
await urql
-49
View File
@@ -1,49 +0,0 @@
/**
* This function will fetch a url to follow all redirects and compare the base url
* with the RegEx to validate false and true positives.
*
* @param message The message that originally triggered the provided RegEx
* @param banRegEx RegEx to check against
* @returns @type boolean
*/
const linkChecker = async (message: string, banRegEx: RegExp) => {
const detectedLinks = message.split(" ").map(subStr => {
if (banRegEx.test(subStr)) {
return subStr;
}
});
if (!detectedLinks || detectedLinks.length === 0) {
return false;
}
const resolvedURLs = detectedLinks.map(async string => {
if (string === undefined) {
return false;
}
const url =
string.startsWith("http://") || string.startsWith("https://")
? string
: `https://${string}`;
const res = await fetch(url, {
headers: {
"user-agent":
"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:140.0) Gecko/20100101 Firefox/140.0"
}
});
const resolvedURL = new URL(res.url);
const baseURL = resolvedURL.hostname.split(".").slice(-2).join(".");
if (/^x\.com/i.test(baseURL)) {
return true;
}
});
return (await Promise.all(resolvedURLs)).includes(true);
};
export default linkChecker;
+2 -9
View File
@@ -1,18 +1,11 @@
import axios from "axios";
export interface Commands {
command: string;
description: string;
command: String;
description: String;
groups: boolean;
private: boolean;
}
/**
* Fetched a list of commands with a provided url and API key.
* @param url The url to query.
* @interface Commands
* @param apiKey The api for the url.
* @returns Array of Commands object.
*/
const fetchCommandsList = async (
url: string,
+1 -1
View File
@@ -6,7 +6,7 @@ const metaRegex =
* This function will check if a url matches Meta services links using regex.
*
* @param linkUrl representing a suspected url on the banlist
* @returns @type boolean
* @returns flag
*/
const metaLinkCheck = (linkUrl: string): boolean => {
let flag = false;
+1 -1
View File
@@ -5,7 +5,7 @@ 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
* @returns @type boolean
* @return flag
*/
const tiktokLinkCheck = (linkUrl: string): boolean => {
let flag = false;
+1 -1
View File
@@ -5,7 +5,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 url on the banlist
* @returns @type boolean
* @return flag
*/
const twitterLinkCheck = (linkUrl: string): boolean => {
let flag = false;
-1
View File
@@ -1,5 +1,4 @@
#!/usr/bin/env tsx
/* eslint-disable @typescript-eslint/no-unused-vars */
import type { PollingConfig, WebhookConfig } from "#root/config.js";
import type { RunnerHandle } from "@grammyjs/runner";
+324 -469
View File
File diff suppressed because it is too large Load Diff