Example #1
0
def farm(update, context):
    farm_text, ripened_high = generate_farm_text(
        telegram_id=update.message.from_user.id)
    context.bot.send_message(
        chat_id=update.message.from_user.id,
        text=(text.FARM_BUTTON.join("**") + text.FARM_DESC_START + farm_text +
              text.FARM_DESC_END.format(all=text.three_digits(
                  n=sum(ripened_high)))),
        reply_markup=menu.inline_button(text=text.HARVEST_INLINE,
                                        data=config.PATTERN_HARVEST),
        parse_mode=ParseMode.MARKDOWN)
    return state.HOME
Example #2
0
def street_first_event(context):
    if context.job.context[0] == "sell":
        (chat_id, sold_high, unsold_high, earned_money) = context.job.context[1::]
        context.bot.send_message(chat_id=chat_id,
                                 text=text.STREET_SELL_TEXT.format(
                                     money=text.three_digits(n=earned_money),
                                     sold=text.three_digits(n=sold_high),
                                     unsold=text.three_digits(n=unsold_high)
                                 ),
                                 reply_markup=menu.show(menu=text.SELL_GOODS),
                                 parse_mode=ParseMode.MARKDOWN)
    else:
        (chat_id, high, detention_chance, money_for_escape) = context.job.context[1::]
        context.bot.send_message(chat_id=chat_id,
                                 text=text.STREET_DETENTION_TEXT.format(
                                     high=text.three_digits(n=high),
                                     money=text.three_digits(n=money_for_escape),
                                     chance=detention_chance
                                 ),
                                 reply_markup=menu.show(menu=text.DETENTION),
                                 parse_mode=ParseMode.MARKDOWN)
Example #3
0
def game(update, context):
    if context.user_data["in_game_flag"]:
        return state.TWENTY_ONE
    try:
        chips_bet = int(update.message.text)
    except ValueError:
        update.message.reply_markdown(
            text=text.ENTER_ERROR_MESSAGE.format(min=text.three_digits(n=config.MIN_CHIPS_FOR_TWENTY_ONE)))
        return state.TWENTY_ONE_ENTER_BET
    else:
        if chips_bet <= 0:
            update.message.reply_markdown(
                text=text.ENTER_ERROR_MESSAGE.format(min=text.three_digits(n=config.MIN_CHIPS_FOR_TWENTY_ONE)))
            return state.TWENTY_ONE_ENTER_BET
        chips_in_balance = sql.chips_in_balance(telegram_id=update.message.chat.id)
        if chips_bet > chips_in_balance:
            update.message.reply_markdown(text=text.FEW_CHIPS_FOR_BET)
            return state.TWENTY_ONE_ENTER_BET
        else:
            context.user_data["in_game_flag"] = True
            context.user_data["BET"] = chips_bet
            update.message.reply_markdown(text=text.BET_IS_ACCEPTED)
            try:
                context.job_queue.run_once(
                    callback=job_first_cards_message,
                    when=2,
                    context=(update.message.chat.id,
                             context.user_data["data"][1],
                             context.user_data["BET"],
                             context.user_data['BANKER'],
                             context.user_data['YOU'],
                             context.user_data["BOTTOM_CARD"],
                             context.user_data['entry_message_id']))
            except TelegramError as mysterious_error:
                for developer in sql.get_dev_id():
                    context.bot.send_message(chat_id=developer,
                                             text=mysterious_error)
            return state.TWENTY_ONE
Example #4
0
def finish(update, context):
    telegram_id, game_message_id = update.callback_query.message.chat.id, update.callback_query.message.message_id
    user = context.user_data
    data, bet, banker, you, bottom_card = user['data'], user['BET'], user['BANKER'], user['YOU'], user['BOTTOM_CARD']
    you['points'], _, _ = calc_points(deck=you['deck'], number=you['number_open_cards'])
    banker['points'], _, _ = calc_points(deck=banker['deck'], number=banker['number_open_cards'])

    game_message = text.GAME_MESSAGE.format(n=text.three_digits(n=data[1]),
                                            bet=text.three_digits(n=bet),
                                            b_cards=' '.join(banker['deck'][:banker['number_open_cards']]),
                                            b_points=banker['points'],
                                            you_cards=' '.join(you['deck'][:you['number_open_cards']]),
                                            you_points=you['points'],
                                            bottom=bottom_card)
    do_exceeded(context)
    sql.update_twenty_one_data(data=context.user_data["data"][:-1], prize=context.user_data["prize"])
    context.bot.edit_message_text(chat_id=telegram_id,
                                  message_id=game_message_id,
                                  text=game_message + "\n*Результат:* ☠Проигрыш _(выход из Игры)_",
                                  reply_markup=None,
                                  parse_mode=ParseMode.MARKDOWN)
    context.job_queue.run_once(callback=job_back_to_twenty_one_menu, when=1.5, context=telegram_id)
    context.user_data["in_game_flag"] = False
Example #5
0
def entry(update, context):
    if not sql.get_from_table(telegram_id=update.message.chat.id, table="balance", field="chip"):
        update.message.reply_markdown(text=text.INSUFFICIENT_CHIPS)
        return state.TWENTY_ONE
    context.user_data["data"] = sql.get_twenty_one_data(telegram_id=update.message.chat.id)
    context.user_data["data"][1] += 1
    context.user_data["BANKER"], context.user_data["YOU"], context.user_data["BOTTOM_CARD"] = start_of_game()
    banker, you, bottom_card = context.user_data["BANKER"], context.user_data["YOU"], context.user_data["BOTTOM_CARD"]
    entry_message = update.message.reply_markdown(
                            text=(text.ENTRY_MESSAGE.format(b_cards=banker['deck'][0],
                                                            b_points=banker['points'],
                                                            you_cards=you['deck'][0],
                                                            you_points=you['points'],
                                                            bottom=bottom_card,
                                                            balance=text.three_digits(n=context.user_data['data'][12]))
                                  + text.TO_ENTER_BET),
                            reply_markup=menu.no_menu())
    context.user_data["entry_message_id"] = entry_message["message_id"]
    return state.TWENTY_ONE_ENTER_BET
Example #6
0
def harvest(update, context):
    telegram_id = update.callback_query.message.chat.id
    ripening_number, _, ripened_high = ut.farm_stats(telegram_id=telegram_id)
    high_number = sum(ripened_high)

    if high_number and ripening_number:
        sql.high_to_balance(telegram_id=telegram_id, high=high_number)
        sql.to_zero_farm_amendments(telegram_id=telegram_id)
        context.bot.edit_message_text(
            text=text.FARM_HARVEST.format(number=text.three_digits(
                n=high_number)),
            chat_id=telegram_id,
            message_id=update.callback_query.message.message_id,
            parse_mode=ParseMode.MARKDOWN)
        return state.HOME
    else:
        context.bot.edit_message_text(
            text=text.HARVEST_ERROR,
            chat_id=telegram_id,
            message_id=update.callback_query.message.message_id,
            parse_mode=ParseMode.MARKDOWN)
        return state.HOME
Example #7
0
def street(update, context):
    update.message.reply_markdown(
        text=text.STREET_START_TEXT.format(high=text.three_digits(n=context.user_data["high"])),
        reply_markup=menu.no_menu())

    context.job_queue.run_once(callback=waiting_3_sec, when=2, context=update.message.chat_id)
    context.job_queue.run_once(callback=waiting_2_sec, when=2.5, context=update.message.chat_id)
    context.job_queue.run_once(callback=waiting_1_sec, when=3.25, context=update.message.chat_id)

    weights, price, escape_weights = [], 0, []
    paid_time = sql.get_from_table(telegram_id=update.message.chat.id, table="paid", field="safer_street")
    places = config.PLACES if paid_time < datetime.today() else config.PLACES_PAY
    if update.message.text == text.OUTSKIRTS_BUTTON:
        weights, price, escape_weights = places[0]["PROB"], places[0]["PRICE"], places[0]["ESCAPE"]
    elif update.message.text == text.CENTRE_BUTTON:
        weights, price, escape_weights = places[1]["PROB"], places[1]["PRICE"], places[1]["ESCAPE"]

    if choices(population=config.FIRST_EVENT, weights=weights, k=1) == ["sell"]:
        sold_high, unsold_high, earned_money = ut.street_exchange(high=context.user_data["high"], price=price)
        sql.high_to_money(telegram_id=update.message.chat.id, high=sold_high, money=earned_money)
        context.job_queue.run_once(
            callback=street_first_event,
            when=5,
            context=("sell", update.message.chat.id, sold_high, unsold_high, earned_money)
        )
        return state.SELL_GOODS
    else:
        detention_chance = randint(a=escape_weights[0], b=escape_weights[1])
        money_for_escape = ut.money_for_escape(money=context.user_data["money_in_balance"])
        context.user_data["detention_chance"] = detention_chance
        context.user_data["money_for_escape"] = money_for_escape
        context.job_queue.run_once(
            callback=street_first_event,
            when=5,
            context=("detention", update.message.chat.id, context.user_data["high"], detention_chance, money_for_escape)
        )
        return state.STREET_DETENTION
Example #8
0
def dealer_result(update, _):
    try:
        high = int(update.message.text)
    except ValueError:
        update.message.reply_markdown(text=text.NOT_POSITIVE_NUMBER, reply_markup=menu.show(menu=text.BACK))
        return state.DEALER
    else:
        if high <= 0:
            update.message.reply_markdown(text=text.NOT_POSITIVE_NUMBER, reply_markup=menu.show(menu=text.BACK))
            return state.DEALER
        else:
            high_in_balance = sql.get_from_table(telegram_id=update.message.chat.id, table="balance", field="high")
            if high > high_in_balance:
                update.message.reply_markdown(text=text.NOT_ENOUGH_HIGH.format(high=high_in_balance),
                                              reply_markup=menu.show(menu=text.BACK))
                return state.DEALER
            elif config.HIGH_MIN <= high <= config.HIGH_MAX:
                money = ut.money_transfer(high=high)
                sql.high_to_money(telegram_id=update.message.chat.id, high=update.message.text, money=money)
                if high < config.BID_1["HIGH"]:
                    update.message.reply_markdown(
                        text=text.BAD_HIGH_EXCHANGE.format(
                            high=text.three_digits(n=high), money=text.three_digits(n=money)),
                        reply_markup=menu.show(menu=text.SELL_GOODS))
                else:
                    update.message.reply_markdown(
                        text=text.HIGH_EXCHANGE.format(high=text.three_digits(n=high),
                                                       money=text.three_digits(n=money)),
                        reply_markup=menu.show(menu=text.SELL_GOODS))
                return state.SELL_GOODS
            else:
                sql.high_to_money(telegram_id=update.message.chat.id, high=update.message.text, money=config.MONEY_MAX)
                update.message.reply_markdown(
                    text=text.HIGH_EXCHANGE.format(high=text.three_digits(n=high),
                                                   money=text.three_digits(n=config.MONEY_MAX)),
                    reply_markup=menu.show(menu=text.SELL_GOODS))
                return state.SELL_GOODS
Example #9
0
def street_enter_high(update, _):
    (money, high, _) = sql.get_balance(telegram_id=update.message.from_user.id)
    update.message.reply_markdown(
        text=text.STREET_ENTER_HIGH_TEXT.format(money=text.three_digits(n=money), high=text.three_digits(n=high)),
        reply_markup=menu.show(menu=text.BACK))
    return state.STREET_ENTER_HIGH
Example #10
0
def dealer(update, _):
    (_, high, _) = sql.get_balance(telegram_id=update.message.from_user.id)
    update.message.reply_markdown(text=text.DEALER_DESC.format(high=text.three_digits(n=high)),
                                  reply_markup=menu.show(menu=text.BACK))
    return state.DEALER
Example #11
0
def my_stats(update, context):
    if context.user_data["in_game_flag"]:
        return state.TWENTY_ONE
    stats = sql.twenty_one_stats(telegram_id=update.message.chat.id)
    win_percent = round(100 * stats[3] / stats[2], 3) if stats[2] else 0
    update.message.reply_markdown(text=text.MY_STATS_TEXT.format(nick=stats[0],
                                                                 balance=text.three_digits(n=stats[13]),
                                                                 games=text.three_digits(n=stats[2]),
                                                                 win=text.three_digits(n=stats[3]),
                                                                 nature_21=text.three_digits(n=stats[8]),
                                                                 golden_21=text.three_digits(n=stats[11]),
                                                                 five_pictures=text.three_digits(n=stats[9]),
                                                                 three_sevens=text.three_digits(n=stats[10]),
                                                                 six_seven_eight=text.three_digits(n=stats[12]),
                                                                 win_percent=win_percent if stats[2] >= 20 else '-',
                                                                 lose=text.three_digits(n=stats[4]),
                                                                 total_win=text.three_digits(n=stats[7]),
                                                                 max_win=text.three_digits(n=stats[5]),
                                                                 max_lose=text.three_digits(n=stats[6])))
    return state.TWENTY_ONE