Ejemplo n.º 1
0
def invite_payment(update, _):
    referrals = sql.get_completed_referrals(referrer=update.message.chat.id)
    if not referrals:
        update.message.reply_markdown(
            text=text.NO_COMPLETED_REFERRALS,
            reply_markup=menu.show(menu=text.PAYMENT))
    else:
        for (ref_id, ref_nick) in referrals:
            sql.add_completed_referral(referrer=update.message.chat.id,
                                       referral=ref_id)
            update.message.reply_markdown(
                text=text.SUCCESSFUL_REFERRAL.format(nick=ref_nick),
                reply_markup=menu.show(menu=text.PAYMENT))
        return state.INVITE
Ejemplo n.º 2
0
def street_second_event(context):
    if len(context.job.context) == 3:
        (chat_id, money_retention, high) = context.job.context
        context.bot.send_message(chat_id=chat_id,
                                 text=text.STREET_RETENTION_TEXT.format(
                                     high=text.three_digits(n=high),
                                     money=text.three_digits(n=money_retention)),
                                 reply_markup=menu.show(menu=text.RETENTION),
                                 parse_mode=ParseMode.MARKDOWN)
    else:
        context.bot.send_message(chat_id=context.job.context[0],
                                 text=text.STREET_ESCAPE_TEXT,
                                 reply_markup=menu.show(menu=text.SELL_GOODS),
                                 parse_mode=ParseMode.MARKDOWN)
Ejemplo n.º 3
0
def rating_money(update, _):
    top = sql.get_rating(param="money")
    update.message.reply_markdown(text=(text.RATING_MONEY_TEXT + "\n".join(
        text.RATING_MONEY_LINE.format(name=nick,
                                      number=text.three_digits(n=money))
        for (nick, money) in top)),
                                  reply_markup=menu.show(menu=text.RATING))
    return state.RATING
Ejemplo n.º 4
0
def to_desc_2(update, _):
    sql.buying_grow_box(telegram_id=update.message.chat.id,
                        name=config.XS["SIZE"],
                        price=str(config.XS["PRICE"]))
    update.message.reply_markdown(
        text=text.TRAIN_DESC_2_TEXT,
        reply_markup=menu.show(menu=text.TRAIN_DESC_2))
    return state.TRAIN_DESC_2
Ejemplo n.º 5
0
def send_letter(update, context):
    if len(update.message.text) > config.LETTER_MAX_LEN:
        update.message.reply_markdown(text=text.ERROR_LETTER, reply_markup=menu.show(menu=text.BACK))
        return state.LETTER
    else:
        developers = sql.get_dev_id()
        player_nick = sql.get_from_table(telegram_id=update.message.chat.id, table="users", field="nick")
        for developer in developers:
            try:
                context.bot.send_message(chat_id=developer,
                                         text=(text.LETTER_HEADING
                                               + update.message.text).format(nick=player_nick),
                                         parse_mode=ParseMode.MARKDOWN)
            except TelegramError:
                continue
        update.message.reply_markdown(text=text.LETTER_SEND, reply_markup=menu.show(menu=text.INFO))
        return state.INFO
Ejemplo n.º 6
0
def rating_harvest(update, _):
    top = sql.get_rating(param="harvest_sum")
    update.message.reply_markdown(
        text=(text.RATING_HARVEST_SUM_TEXT + "\n".join(
            text.RATING_HARVEST_SUM_LINE.format(
                name=nick, number=text.three_digits(n=harvest_sum))
            for (nick, harvest_sum) in top)),
        reply_markup=menu.show(menu=text.RATING))
    return state.RATING
Ejemplo n.º 7
0
def balance(update, _):
    (money, high,
     chip) = sql.get_balance(telegram_id=update.message.from_user.id)
    update.message.reply_markdown(text=text.BALANCE.format(
        money=text.three_digits(n=money),
        high=text.three_digits(n=high),
        chip=text.three_digits(n=chip)),
                                  reply_markup=menu.show(menu=text.HOME))
    return state.HOME
Ejemplo n.º 8
0
def to_market(update, _):
    update.message.reply_photo(photo=open(file=config.XS["PATH"], mode='rb'),
                               caption=text.HIGH_GROWING_CAPTION.format(
                                   about=config.XS["DESC"],
                                   name=config.XS["NAME"],
                                   mining=config.XS["MINING"],
                                   price=config.XS["PRICE"]),
                               reply_markup=menu.show(menu=text.TRAIN_MARKET),
                               parse_mode=ParseMode.MARKDOWN)
    return state.TRAIN_MARKET
Ejemplo n.º 9
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)
Ejemplo n.º 10
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
Ejemplo n.º 11
0
def nick_valid(update, _):
    if check_nick(nickname=update.message.text):
        if sql.update_nick(nick=update.message.text,
                           telegram_id=update.message.chat.id):
            update.message.reply_markdown(
                text=text.TRAIN_NICK_VALID_TEXT,
                reply_markup=menu.show(menu=text.MAIN))
            return state.MAIN
        else:
            update.message.reply_markdown(text=text.TRAIN_NICK_NOT_VALID_TEXT,
                                          reply_markup=menu.no_menu())
            return state.TRAIN_NICK
    else:
        update.message.reply_markdown(text=text.TRAIN_NICK_ERROR_TEXT)
        return state.TRAIN_NICK
Ejemplo n.º 12
0
def street_choice_place(update, context):
    chat_id = update.message.chat.id
    try:
        high = int(update.message.text)
    except ValueError:
        update.message.reply_markdown(text=text.STREET_NOT_EXPECTED_NUMBER, reply_markup=menu.show(menu=text.BACK))
        return state.STREET_ENTER_HIGH
    else:
        if high < config.MIN_HIGH_FOR_STREET:
            update.message.reply_markdown(
                text=text.STREET_NOT_EXPECTED_NUMBER, reply_markup=menu.show(menu=text.BACK))
            return state.STREET_ENTER_HIGH
        else:
            high_in_balance = sql.get_from_table(telegram_id=chat_id, table="balance", field="high")
            money_in_balance = sql.get_from_table(telegram_id=chat_id, table="balance", field="money")
            if (high_in_balance < high) or (money_in_balance < config.MIN_MONEY_FOR_STREET):
                update.message.reply_markdown(text=text.INSUFFICIENT_FUNDS, reply_markup=menu.show(menu=text.BACK))
                return state.STREET_ENTER_HIGH
            else:
                context.user_data["high"] = high
                context.user_data["money_in_balance"] = money_in_balance
                update.message.reply_markdown(
                    text=text.STREET_CHOICE_PLACE, reply_markup=menu.show(menu=text.STREET_PLACES))
                return state.STREET_CHOICE_PLACE
Ejemplo n.º 13
0
def start(update, _):
    if "twenty_one" not in sql.get_all_tables_name():
        sql.create_new_table()
    if sql.is_reg(telegram_id=update.message.from_user.id) is None:
        sql.reg(telegram_id=update.message.from_user.id)
        if len(update.message.text) > len("/start"):
            try:
                referrer = int(update.message.text.split()[-1])
            except ValueError:
                pass
            else:
                if sql.get_from_table(telegram_id=referrer,
                                      table="users",
                                      field="nick"):
                    sql.add_referral(referrer=referrer,
                                     referral=update.message.chat.id)
        train.to_desc_1(update, _)
        return state.TRAIN_DESC_1
    elif not update.message.from_user.is_bot:
        update.message.reply_markdown(text=text.MENU_DESC,
                                      reply_markup=menu.show(menu=text.MAIN))
        return state.MAIN
Ejemplo n.º 14
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
Ejemplo n.º 15
0
def default(update, _):
    update.message.reply_markdown(text=text.ERROR_MESSAGE,
                                  reply_markup=menu.show(menu=text.MAIN))
    return state.MAIN
Ejemplo n.º 16
0
def bribe_after_retention(update, context):
    sql.bribe(telegram_id=update.message.chat.id,
              money=context.user_data["money_retention"],
              high=context.user_data["high"])
    update.message.reply_markdown(text=text.STREET_BRIBE_TEXT, reply_markup=menu.show(menu=text.SELL_GOODS))
    return state.SELL_GOODS
Ejemplo n.º 17
0
def version(update, _):
    update.message.reply_markdown(text=text.VERSION, reply_markup=menu.show(menu=text.INFO))
    return state.INFO
Ejemplo n.º 18
0
def invite(update, _):
    update.message.reply_markdown(text=text.REFERRAL_LINK.format(
        id=update.message.chat.id))
    update.message.reply_markdown(text=text.INVITE_DESC,
                                  reply_markup=menu.show(menu=text.PAYMENT))
    return state.INVITE
Ejemplo n.º 19
0
def info(update, _):
    update.message.reply_markdown(text=text.INFO_DESC, reply_markup=menu.show(menu=text.INFO))
    return state.INFO
Ejemplo n.º 20
0
def home(update, _):
    update.message.reply_markdown(text=text.HOME_DESC,
                                  reply_markup=menu.show(menu=text.HOME))
    return state.HOME
Ejemplo n.º 21
0
def side_job(update, _):
    update.message.reply_markdown(text=text.SIDE_JOB_DESC,
                                  reply_markup=menu.show(menu=text.SIDE_JOB))
    return state.SIDE_JOB
Ejemplo n.º 22
0
def rating(update, _):
    update.message.reply_markdown(text=text.RATING_DESC,
                                  reply_markup=menu.show(menu=text.RATING))
    return state.RATING
Ejemplo n.º 23
0
def to_desc_1(update, _):
    update.message.reply_markdown(
        text=text.TRAIN_DESC_1_TEXT,
        reply_markup=menu.show(menu=text.TRAIN_DESC_1))
Ejemplo n.º 24
0
def reload(update, _):
    update.message.reply_markdown(text=text.MENU_RELOAD,
                                  reply_markup=menu.show(menu=text.MAIN))
    return state.MAIN
Ejemplo n.º 25
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
Ejemplo n.º 26
0
def retention_notify(update, _):
    update.message.reply_markdown(text=text.STREET_RETENTION_NOTIFY, reply_markup=menu.show(menu=text.RETENTION))
    return state.STREET_RETENTION
Ejemplo n.º 27
0
def to_sell_goods(update, _):
    update.message.reply_markdown(text="", reply_markup=menu.show(menu=text.SELL_GOODS))
    return state.SELL_GOODS
Ejemplo n.º 28
0
def back_to_main(update, _):
    update.message.reply_markdown(text=text.BACK_TO_MENU_DESC,
                                  reply_markup=menu.show(menu=text.MAIN))
    return state.MAIN
Ejemplo n.º 29
0
def markets(update, _):
    update.message.reply_markdown(text=text.MARKETS_DESC,
                                  reply_markup=menu.show(menu=text.MARKETS))
    return state.MARKETS
Ejemplo n.º 30
0
def letter(update, _):
    update.message.reply_markdown(text=text.LETTER_DESC, reply_markup=menu.show(menu=text.BACK))
    return state.LETTER