dist/helpers/checkAdmin.js
/**
 * Checking if user is admin at chat, deletes message if not
 * @param ctx Context of the message
 * @param shouldDelete If the message shouldbe deleted
 * @returns true if the user is admin
 */
Checking if user is admin at chat, deletes message if not
@param ctx Context of the message
@param shouldDelete If the message shouldbe deleted
@returns true if the user is admin
Checking if user is admin at chat deletes message if not @param ctx Context of the message @param shouldDelete If the message shouldbe deleted @returns true if the user is admin
async function checkIfAdmin(ctx, shouldDelete = true) {
    try {
        if (ctx.from && ctx.from.id === parseInt(process.env.ADMIN, 10)) {
            return true;
        }
        if (ctx.from &&
            ctx.from.username &&
            ctx.from.username === 'GroupAnonymousBot') {
            return true;
        }
        if (['channel', 'private'].indexOf(ctx.chat.type) > -1)
            return true;
        const member = await ctx.telegram.getChatMember(ctx.chat.id, ctx.from.id);
        const isAdmin = ['administrator', 'creator'].includes(member.status);
        if (!isAdmin) {
            try {
                if (shouldDelete) {
                    await ctx.telegram.deleteMessage(ctx.chat.id, ctx.message.message_id);
                }
            }
            catch (err) {
            }
        }
        return isAdmin;
    }
    catch (err) {
        console.log(err);
        try {
            if (shouldDelete) {
                await ctx.telegram.deleteMessage(ctx.chat.id, ctx.message.message_id);
            }
        }
        catch (err) {
        }
        return false;
    }
}
async function checkIfAdmin ( ctx , shouldDelete = true ) { try { if ( ctx . from && ctx . from . id === parseInt ( process . env . ADMIN , 10 ) ) { return true ; } if ( ctx . from && ctx . from . username && ctx . from . username === 'GroupAnonymousBot' ) { return true ; } if ( [ 'channel' , 'private' ] . indexOf ( ctx . chat . type ) > - 1 ) return true ; const member = await ctx . telegram . getChatMember ( ctx . chat . id , ctx . from . id ) ; const isAdmin = [ 'administrator' , 'creator' ] . includes ( member . status ) ; if ( ! isAdmin ) { try { if ( shouldDelete ) { await ctx . telegram . deleteMessage ( ctx . chat . id , ctx . message . message_id ) ; } } catch ( err ) { } } return isAdmin ; } catch ( err ) { console . log ( err ) ; try { if ( shouldDelete ) { await ctx . telegram . deleteMessage ( ctx . chat . id , ctx . message . message_id ) ; } } catch ( err ) { } return false ; } }
Checking if user is admin at chat, deletes message if not
 @param ctx Context of the message
 @param shouldDelete If the message shouldbe deleted
 @returns true if the user is admin
Checking if user is admin at chat deletes message if not @param ctx Context of the message @param shouldDelete If the message shouldbe deleted @returns true if the user is admin
// Channel and private are always true // Check if admin // Delete message if not admin // Do nothing // Return result // Delete message // Do nothing // In case if something goes wrong