Added cache exchange urq, fixed eslint, added prettier, upgraded yarn, added statsSite command.
All checks were successful
Main / build-and-push-docker-image (20.x) (push) Successful in 4m58s

This commit is contained in:
2026-01-02 10:10:20 -05:00
parent c088d7c4a5
commit df433c1951
7 changed files with 301 additions and 49 deletions

View 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 };

View File

@@ -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";
@@ -20,6 +20,7 @@ import { helpCommand } from "./features/helpCommand.js";
import { embedCheck } from "./features/embedCheck.js";
import { registerGroup } from "./features/registerBotCommand.js";
import { getGroupStats } from "./features/getGroupStatsCommand.js";
import { statsSiteCommand } from "./features/statsSiteCommand.js";
interface Dependencies {
config: Config;
@@ -74,6 +75,7 @@ export function createBot(
protectedBot.use(helpCommand);
protectedBot.use(registerGroup);
protectedBot.use(getGroupStats);
protectedBot.use(statsSiteCommand);
// Blacklist Feature
protectedBot.use(twitterBlacklist);