Skip to content

Commit 1261422

Browse files
committed
refactor(middleware): reformatted logger initialization, added whitespace, and modified isSupergroupOrChannel method to isValidChatType with additional chat type handling.
1 parent ae96393 commit 1261422

1 file changed

Lines changed: 18 additions & 9 deletions

File tree

src/middleware/ActionFilter.ts

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import { Logger } from "../config/logger";
22
import { SafeExecution } from "../decorators/SafeExecution";
33
import { Middleware } from "./mid";
4-
const logger = new Logger({file:"ActionFilter.log",level:'info',timestampFormat:'locale'})
4+
const logger = new Logger({
5+
file: "ActionFilter.log",
6+
level: "info",
7+
timestampFormat: "locale",
8+
});
59
export class ActionFilter extends Middleware {
610
@SafeExecution()
711
/**
@@ -29,7 +33,7 @@ export class ActionFilter extends Middleware {
2933
*/
3034
async userInGroup(): Promise<void> {
3135
const userId = this.ctx.message?.reply_to_message?.from?.id;
32-
36+
3337
if (!userId) {
3438
await this.ctx.reply(
3539
"Unable to determine the user ID. Please ensure you are replying to a valid user.",
@@ -84,15 +88,20 @@ export class ActionFilter extends Middleware {
8488

8589
return this.nxt();
8690
}
87-
isSupergroupOrChannel() {
91+
isValidChatType() {
8892
const chat = this.ctx.chat;
93+
console.log("chat:", chat);
8994

90-
if (chat && (chat.type === "supergroup" || chat.type === "channel")) {
91-
return this.nxt();
92-
} else {
93-
this.ctx.reply(
94-
"This command can only be used in supergroups or channels."
95-
);
95+
if (chat) {
96+
if (chat.type === "supergroup" || chat.type === "channel") {
97+
return this.nxt();
98+
} else if (chat.type === "private") {
99+
this.ctx.reply(
100+
"This command can only be used in supergroups or channels."
101+
);
102+
} else {
103+
this.ctx.reply("This command is not allowed in this type of chat.");
104+
}
96105
}
97106
}
98107
}

0 commit comments

Comments
 (0)