import { Api } from 'telegram' ; import { Snake } from '../../client' ; import BigInt from 'big-integer' ; import { MessageContext } from '../../Context/MessageContext' ; import * as Update from '../../Update' ; export async function GetMessages ( snakeClient , chatId , messageId ) { try { let messageIds = messageId ; let type = await snakeClient . telegram . getEntity ( chatId ) ; if ( type . type == 'channel' ) { let results = await snakeClient . client . invoke ( new Api . channels . GetMessages ( { channel : chatId , id : messageIds , } ) ) ; let final = new ResultsGetMessage ( ) ; await final . init ( results , snakeClient ) ; return final ; } else { let results = await snakeClient . client . invoke ( new Api . messages . GetMessages ( { id : messageIds , } ) ) ; let final = new ResultsGetMessage ( ) ; await final . init ( results , snakeClient ) ; return final ; } } catch ( error ) { return snakeClient . _handleError ( error , `telegram.getMessages(${ chatId },${ JSON . stringify ( messageId ) })` ) ; } } export class ResultsGetMessage { messages ! : MessageContext [ ] ; date : number | Date = Math . floor ( Date . now ( ) / 1000 ) ; constructor ( ) { } async init ( results , SnakeClient ) { let tempMessages = [ ] ; if ( results instanceof Api . messages . ChannelMessages ) { for ( let i = 0 ; i < results . messages . length ; i ++ ) { let msg = results . messages [ i ] as Api . Message ; let msgc = new MessageContext ( ) ; await msgc . init ( msg , SnakeClient ) ; tempMessages . push ( msgc ) ; } } if ( results instanceof Api . messages . Messages ) { for ( let i = 0 ; i < results . messages . length ; i ++ ) { let msg = results . messages [ i ] as Api . Message ; let msgc = new MessageContext ( ) ; await msgc . init ( msg , SnakeClient ) ; tempMessages . push ( msgc ) ; } } this . messages = tempMessages ; return this ; } }