File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff 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 } ` ,
Original file line number Diff line number Diff line change 11import { Context } from "grammy" ;
22import { DatabaseService } from ".." ;
33import { GroupSettings } from "../../../entities/GroupSettings" ;
4+ import * as BlackListJson from "../../../helper/black_list.json" ;
45
56export 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}
Original file line number Diff line number Diff 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 }
Original file line number Diff line number Diff 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 ) ;
You can’t perform that action at this time.
0 commit comments