Secured command to prevent spam from regular users.
All checks were successful
Main / build-and-push-docker-image (20.x) (pull_request) Successful in 3m1s

This commit is contained in:
2025-10-21 15:09:21 -04:00
parent 10d8f02160
commit d71e736bee
2 changed files with 33 additions and 11 deletions

View File

@@ -15,7 +15,16 @@ feature.hears(
logHandle("bot-info-command"), logHandle("bot-info-command"),
async (ctx: Context) => { async (ctx: Context) => {
// Checks if the context includes a message property. // Checks if the context includes a message property.
if (ctx.msg) { 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;
}
}
// Replies to the message. // Replies to the message.
await ctx.reply( await ctx.reply(
`I am a bot designed to delete any Twitter/X and Meta links along with corresponding reformatting services\\. I now check embedded links\\!`, `I am a bot designed to delete any Twitter/X and Meta links along with corresponding reformatting services\\. I now check embedded links\\!`,

View File

@@ -16,10 +16,10 @@ feature.hears(/^\/help/, logHandle("help"), async (ctx: Context) => {
: undefined; : undefined;
// Checks there is a chat and msg property in the context. // Checks there is a chat and msg property in the context.
if (ctx.chat && ctx.msg) { if (ctx.chat && ctx.msg && ctx.msg.from) {
// Checks if the chat is private // Checks if the chat is private
if (ctx.chat.type === "private") { if (ctx.chat.type === "private") {
// Responds with the command list. // Responds with message.
await ctx.reply( 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\\.`, `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\\.`,
{ {
@@ -29,14 +29,27 @@ feature.hears(/^\/help/, logHandle("help"), async (ctx: Context) => {
); );
} }
// Checks if chat is a group.
if (ctx.chat.type !== "private") { if (ctx.chat.type !== "private") {
await ctx.reply( const chatMember = await ctx.getChatMember(ctx.msg.from.id);
`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\\.`,
{ // Checks if the user is an admin.
parse_mode: "MarkdownV2", if (["creator", "administrator"].includes(chatMember.status)) {
reply_parameters: { message_id: ctx.msg.message_id } // 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( await ctx.reply(
@@ -48,7 +61,7 @@ feature.hears(/^\/help/, logHandle("help"), async (ctx: Context) => {
); );
return await ctx.reply( return await ctx.reply(
`Down with fascism\\! Fuck MAGA\\! Fuck Trump\\! Fuck Nazis\\! Trans rights are human rights\\! Trans women are women\\! Trans men and men\\! Never let them take awy your happiness\\!`, `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", parse_mode: "MarkdownV2",
reply_parameters: { message_id: ctx.msg.message_id } reply_parameters: { message_id: ctx.msg.message_id }