dist/helpers/raffle.js
/**
 * Starting a new raffle
 * @param ctx Context of the message that started
 */
Starting a new raffle
@param ctx Context of the message that started
Starting a new raffle @param ctx Context of the message that started
async function startRaffle(ctx) {
    const chat = await chat_1.findChat(ctx.chat.id);
    const raffle = await models_1.addRaffle(ctx.chat.id);
    if (chat.raffleMessage) {
        raffle.raffleMessage = chat.raffleMessage;
        await raffle.save();
    }
    if (chat.winnerMessage) {
        raffle.winnerMessage = chat.winnerMessage;
        await raffle.save();
    }
    const options = {
        reply_markup: getButtons(raffle, chat.language),
        parse_mode: 'HTML',
        disable_web_page_preview: true,
    };
    let sent;
    if (raffle.raffleMessage) {
        const raffleMessage = raffle.raffleMessage;
        if (raffleMessage.text) {
            raffleMessage.text = raffleMessage.text.replace('$numberOfParticipants', '0');
        }
        else {
            raffleMessage.caption = raffleMessage.caption.replace('$numberOfParticipants', '0');
        }
        sent = await ctx.telegram.sendCopy(ctx.chat.id, raffleMessage, {
            reply_markup: getButtons(raffle, chat.language),
            parse_mode: 'HTML',
            disable_web_page_preview: true,
        });
    }
    else {
        sent = await ctx.replyWithHTML(locale_1.loc(chat.number > 1 ? 'raffle_text_multiple' : 'raffle_text', chat.language), options);
    }
    raffle.messageId = sent.message_id;
    await raffle.save();
}
async function startRaffle ( ctx ) { const chat = await chat_1 . findChat ( ctx . chat . id ) ; const raffle = await models_1 . addRaffle ( ctx . chat . id ) ; if ( chat . raffleMessage ) { raffle . raffleMessage = chat . raffleMessage ; await raffle . save ( ) ; } if ( chat . winnerMessage ) { raffle . winnerMessage = chat . winnerMessage ; await raffle . save ( ) ; } const options = { reply_markup : getButtons ( raffle , chat . language ) , parse_mode : 'HTML' , disable_web_page_preview : true , } ; let sent ; if ( raffle . raffleMessage ) { const raffleMessage = raffle . raffleMessage ; if ( raffleMessage . text ) { raffleMessage . text = raffleMessage . text . replace ( '$numberOfParticipants' , '0' ) ; } else { raffleMessage . caption = raffleMessage . caption . replace ( '$numberOfParticipants' , '0' ) ; } sent = await ctx . telegram . sendCopy ( ctx . chat . id , raffleMessage , { reply_markup : getButtons ( raffle , chat . language ) , parse_mode : 'HTML' , disable_web_page_preview : true , } ) ; } else { sent = await ctx . replyWithHTML ( locale_1 . loc ( chat . number > 1 ? 'raffle_text_multiple' : 'raffle_text' , chat . language ) , options ) ; } raffle . messageId = sent . message_id ; await raffle . save ( ) ; }
Starting a new raffle
 @param ctx Context of the message that started
Starting a new raffle @param ctx Context of the message that started
// Get chat // Add raffle // Save raffle message if required // Add buttons // Send message // Save sent message id