Files
no-twitter-bot/src/bot/features/helpCommand.ts
Lucid 2050e61706
All checks were successful
Main / build-and-push-docker-image (20.x) (push) Successful in 3m32s
Added mutation key to features.
2025-12-10 19:39:15 -05:00

87 lines
3.8 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/incrimentMutation.js";
const composer = new Composer<Context>();
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, mutationKey });
// const GROUP_IDS = process.env.GROUP_IDS
// ? process.env.GROUP_IDS.split(",")
// : undefined;
// 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, mutationKey })
.toPromise()
.then(async () => {
if (ctx.msg && ctx.chat && ctx.msg.from) {
// Checks if the chat is private
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\\.`,
{
parse_mode: "MarkdownV2",
reply_parameters: { message_id: ctx.msg.message_id }
}
);
}
// Checks if chat is a group.
if (ctx.chat.type !== "private") {
const chatMember = await ctx.getChatMember(ctx.msg.from.id);
// Checks if the user is an admin.
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\\.`,
{
parse_mode: "MarkdownV2",
reply_parameters: { message_id: ctx.msg.message_id }
}
);
} else {
/**
* Doesn't respond to regular users in groups. This is to prevent users spamming the command.
* Especially since this one includes some political opinions/messages.
*/
return;
}
}
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\\.`,
{
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 }
}
);
}
});
}
});
export { composer as helpCommand };