Skip to content

Commit b751e2c

Browse files
committed
fix: middleware, message check, and database services: rename isSupergroupOrChannel to isValidChatType, remove blacklist terms initialization, update GroupSettingsService to use BlackListJson, and add new methods to
1 parent 5cecd14 commit b751e2c

5 files changed

Lines changed: 35 additions & 21 deletions

File tree

src/middleware/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class CmdMid {
1515
static async AdminStatus(ctx: Context, nxt: NextFunction) {
1616
await new AdminChecker(ctx, nxt).checkAdminStatus();
1717
}
18-
static async isSupergroupOrChannel(ctx: Context, nxt: NextFunction) {
19-
await new ActionFilter(ctx, nxt).isSupergroupOrChannel();
18+
static async isValidChatType(ctx: Context, nxt: NextFunction) {
19+
await new ActionFilter(ctx, nxt).isValidChatType();
2020
}
2121
}

src/service/MessageCheck.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,6 @@ export class MessageCheck {
163163
`Bot added to group ${chat.title} by ${from?.username}`,
164164
"GROUP"
165165
);
166-
// Initialize blacklist terms from BlackListJson
167-
await BlacklistService.storeBlacklistTerms(groupSettings);
168166
} else {
169167
logger.info(
170168
`Bot re-added to existing group ${chat.title} by ${from?.username}`,

src/service/db/group/index.ts

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Context } from "grammy";
22
import { DatabaseService } from "..";
33
import { GroupSettings } from "../../../entities/GroupSettings";
4+
import * as BlackListJson from "../../../helper/black_list.json";
45

56
export class GroupSettingsService extends DatabaseService {
67
private groupSettingsRepo = this.getRepo(GroupSettings);
@@ -23,17 +24,21 @@ export class GroupSettingsService extends DatabaseService {
2324
async init(ctx: Context) {
2425
const chat = ctx.chat!;
2526
const from = ctx.from;
26-
return await this.save(
27-
await this.create({
28-
group_id: chat.id,
29-
group_name: chat.title,
30-
welcome_message: "",
31-
chat_permissions: (await ctx.api.getChat(chat.id)).permissions,
32-
rules: "",
33-
description: "",
34-
black_list: [],
35-
added_by_id: from?.id,
36-
})
27+
const bl = BlackListJson.map((item: { term: string }) =>
28+
item.term.toLowerCase()
3729
);
30+
const group = await this.create({
31+
group_id: chat.id,
32+
group_name: chat.title,
33+
welcome_message: "",
34+
chat_permissions: (await ctx.api.getChat(chat.id)).permissions,
35+
rules: "",
36+
description: "",
37+
black_list: bl,
38+
added_by_id: from?.id,
39+
approvedUsers: [],
40+
members: [],
41+
});
42+
return await this.groupSettingsRepo.save(group);
3843
}
3944
}

src/service/db/user/Approved.ts

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,20 @@ export class ApprovedUserService extends DatabaseService {
2020
});
2121
}
2222
async getByGroup(groupSettings: GroupSettings): Promise<ApprovedUser[]> {
23-
return this.approvedUserRepo.find({
24-
where: { group: { id: groupSettings.id } }, // Use the ID to filter
25-
relations: ["group"],
26-
});
27-
}
23+
return this.approvedUserRepo.find({
24+
where: { group: { id: groupSettings.id } }, // Use the ID to filter
25+
relations: ["group"],
26+
});
27+
}
28+
async getByUserIdAndGroup(
29+
userId: number,
30+
groupId: number
31+
): Promise<ApprovedUser | null> {
32+
return this.approvedUserRepo.findOne({
33+
where: { user: { id: userId }, group: { id: groupId } },
34+
relations: ["user", "group"],
35+
});
36+
}
2837
async remove(id: number): Promise<void> {
2938
await this.approvedUserRepo.delete(id);
3039
}

src/service/db/user/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ export class UserService extends DatabaseService {
1010
}
1111

1212
async getByTelegramId(telegramId: number) {
13-
return this.userRepo.findOne({ where: { telegram_id: telegramId } });
13+
return await this.userRepo.findOne({
14+
where: { telegram_id: 6376425576 },
15+
});
1416
}
1517
async save(user: User) {
1618
return this.userRepo.save(user);

0 commit comments

Comments
 (0)