54 lines
1.7 KiB
TypeScript
54 lines
1.7 KiB
TypeScript
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 }) // Increments the trigger count
|
|
.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 };
|