Skip to content

Commit b29ae7e

Browse files
committed
refactor: Update ctx property access, simplify user authentication middleware, and clarify bot command descriptions.
1 parent 3331190 commit b29ae7e

4 files changed

Lines changed: 14 additions & 25 deletions

File tree

src/handlers/command-handlers.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export const startCommandHandler = async (ctx) => {
88
`• 📁 Files & Study Materials\n` +
99
`• 📚 Syllabuses & PDFs\n` +
1010
`• 📝 Notes & Resources\n\n` +
11-
`Use /search to find and download files!\n` +
11+
`Use /search to find links to files!\n` +
1212
`Use /help to see all available commands.`;
1313

1414
await ctx.reply(welcomeMessage, { parse_mode: "Markdown" });
@@ -23,7 +23,7 @@ export const helpCommandHandler = async (ctx) => {
2323
`🤖 *Learnverse Bot Help*\n\n` +
2424
`I am here to help you access study materials, notes, and syllabuses easily.\n\n` +
2525
`*Available Commands:*\n` +
26-
`/search - 🔍 Find file, syllabus & notes\n` +
26+
`/search - 🔍 Find file, syllabus & notes links\n` +
2727
`/help - ℹ️ Show this help message\n` +
2828
`/start - 🔄 Restart the bot session\n\n` +
2929
`_Select /search to browse materials by Branch > Year > Subject_`;

src/helpers/bot-helpers.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
export const isBot = (ctx) => {
2-
return ctx.update?.message?.from?.is_bot;
2+
return ctx.from?.is_bot;
33
};
44

55
export const isPrivateChat = (ctx) => {
6-
return ctx.update?.message?.chat?.type === "private";
6+
return ctx.chat?.type === "private";
77
};
88

99
export const checkIfNewUser = (ctx) => {
10-
return ctx.update?.message?.new_chat_participant;
10+
return ctx.message?.new_chat_participant;
1111
};
1212

1313
export const checkGroupChat = (ctx) => {
14-
return ctx.update?.message?.chat?.type === "group";
14+
return ctx.chat?.type === "group" || ctx.chat?.type === "supergroup";
1515
};

src/helpers/user-helper.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ export const createUserIfNotExists = async (ctx) => {
1515
}
1616

1717
const user = {
18-
chatId: ctx.update.message.chat.id,
19-
firstName: ctx.update.message.from.first_name,
20-
lastName: ctx.update.message.from.last_name,
21-
username: ctx.update.message.from.username,
22-
language_code: ctx.update.message.from.language_code,
18+
chatId: ctx.chat?.id,
19+
firstName: ctx.from?.first_name,
20+
lastName: ctx.from?.last_name,
21+
username: ctx.from?.username,
22+
language_code: ctx.from?.language_code,
2323
};
2424

2525
const newUser = await createUser(user);

src/middlewares/userAuthAndSetupMiddleware.js

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,11 @@ import logger from "../helpers/logger.js";
1010
import fs from "fs";
1111

1212
export const userAuthAndSetupMiddleware = async (ctx, next) => {
13-
// Skip middleware for callback queries (inline button clicks)
14-
// Callback queries don't have message context and are already authenticated
15-
if (ctx.updateType === "callback_query") {
16-
logger.debug("Skipping middleware for callback query");
17-
return next();
18-
}
19-
20-
// Only validate for messages and commands
21-
if (!ctx.update.message) {
22-
// Skip for other update types (edited messages, etc.)
23-
return next();
24-
}
25-
2613
// reject if the user is a bot
2714
if (isBot(ctx)) {
28-
ctx.reply("You are a bot, bots are not allowed");
15+
if (isPrivateChat(ctx)) {
16+
await ctx.reply("You are a bot, bots are not allowed");
17+
}
2918
return;
3019
}
3120

0 commit comments

Comments
 (0)