File tree Expand file tree Collapse file tree 3 files changed +21
-7
lines changed
Expand file tree Collapse file tree 3 files changed +21
-7
lines changed Original file line number Diff line number Diff line change @@ -187,8 +187,17 @@ export class UserCommands {
187187 await reply . textReply ( `Here is the invite link for this group: ${ chat . invite_link } ` ) ;
188188 } else {
189189 // If no link exists, try to generate a new one (requires admin rights)
190- const inviteLink = await ctx . api . exportChatInviteLink ( ctx . chat ! . id ) ;
191- await reply . textReply ( `Here is the invite link for this group: ${ inviteLink } ` ) ;
190+ if ( chat . permissions ?. can_change_info ) {
191+ try {
192+ // Try to export a new invite link
193+ const inviteLink = await ctx . api . exportChatInviteLink ( ctx . chat ! . id ) ;
194+ await reply . textReply ( `Here is the invite link for this group: ${ inviteLink } ` ) ;
195+ } catch ( err : any ) {
196+ await reply . textReply ( 'Sorry, I do not have permission to generate the invite link.' ) ;
197+ }
198+ } else {
199+ await reply . textReply ( 'I do not have enough permissions to generate an invite link.' ) ;
200+ }
192201 }
193202 }
194203 /**
Original file line number Diff line number Diff line change @@ -40,7 +40,7 @@ export class CopBot {
4040
4141 const isProduction = Config . environment === 'production' ;
4242 const webhookPath = `/bot/${ Config . token } ` ;
43- const webhookURL = `https://51a3-20-208-130-133.ngrok-free.app ${ webhookPath } ` ;
43+ const webhookURL = `${ Config . web_hook } ${ webhookPath } ` ;
4444 const mode = isProduction ? 'webhook' : 'long-polling' ;
4545
4646 logger . info ( `Environment: ${ Config . environment } ` ) ;
@@ -49,6 +49,10 @@ export class CopBot {
4949
5050 if ( isProduction ) {
5151 try {
52+ const result = await this . _bot . api . deleteWebhook ( ) ;
53+ if ( result ) {
54+ await this . _bot . api . getUpdates ( { offset : - 1 } ) ;
55+ }
5256 const app = express ( ) ;
5357 app . use ( express . json ( ) ) ;
5458 app . post ( webhookPath , async ( req , res ) => {
@@ -89,6 +93,8 @@ export class CopBot {
8993 } else {
9094 try {
9195 await this . _bot . api . deleteWebhook ( ) ;
96+
97+ this . _bot . api . getUpdates ( { offset : - 1 } ) ;
9298 await startBot ( mode ) ;
9399 } catch ( err : any ) {
94100 console . error ( 'Error during long-polling mode:' , err ) ;
Original file line number Diff line number Diff line change @@ -14,10 +14,9 @@ export function RestrictToGroupChats() {
1414
1515 try {
1616 if ( chat . type === 'supergroup' || chat . type === 'group' ) {
17- return await next ( ) ;
18- }
19-
20- if ( chat . type === 'private' ) {
17+ await next ( ) ;
18+ return ;
19+ } else if ( chat . type === 'private' ) {
2120 await reply . textReply ( 'This command can only be used in group chats.' ) ;
2221 close ( ) ;
2322 } else if ( chat . type === 'channel' ) {
You can’t perform that action at this time.
0 commit comments