Пример #1
0
def send_text(message):
    global dict_with_state

    try:
        print(dict_with_state[message.from_user.id])

        #-----------------Настройка-------------
        if dict_with_state[message.from_user.id] == 'settings':  # try
            bot.send_message(message.chat.id, ' olololo ')
            print("settings")
            change_settings_command(message)
        elif dict_with_state[message.from_user.id] == 'settings_api_qiwi':
            print("settings api")
            change_settings_qiwi_api(message)

        #-----------------Обмен-------------

        elif "Buy" in dict_with_state[message.from_user.id]:
            request_to_qiwi(message)
            print("request_to_qiwi")

        else:
            text_command(message)

    except:
        text_command(message)
Пример #2
0
def change_settings_qiwi_api(message):
    global dict_with_state
    dict_with_state[
        message.from_user.id] = ''  # button for main menu and revert
    print("hop hop")

    bot.send_message(message.chat.id, ' Write in db ')

    try:
        update_info_bot = session.query(UserBotInfo).filter(
            UserBotInfo.id_telegram == str(message.from_user.id)).first()
        update_info_bot.keyqiwi = str(message.text)
        session.commit()
        print("update")

    except:

        try:
            newUserBotInfo = UserBotInfo(str(message.text),
                                         str(message.from_user.id))
            session.add(newUserBotInfo)
            session.commit()
            print("insert")

        except:

            print("failed db")

    print(message.text)
    print(message.from_user.id)
    dict_with_state[message.from_user.id] = ''
    conn.hmset("pythonDict", dict_with_state)  # redis
Пример #3
0
def history_of_exchanges(message):
    bot.send_message(message.chat.id, ' История операций ')

    for count_coins, sum_deal, telephone, id_telegram in session.query(
            BotDeals.count_coins,
            BotDeals.sum_deal,
            BotDeals.telephone,
            BotDeals.id_telegram,
    ).filter(BotDeals.id_telegram == message.from_user.id):
        bot.send_message(
            message.chat.id, " Купили " + str(count_coins) + " в количеcтве " +
            str(count_coins) + " за  " + str(sum_deal) + " рублей  " + " у  " +
            str(telephone))
Пример #4
0
 def start_message(message):
     rows = {
         'Произвести обмен', 'История операций', 'Настройки', 'Информация',
         'Курсы обмена', '/menu'
     }
     keyboardMain = BotKeyboard()
     key = keyboardMain.gef_native(rows,
                                   resize_keyboard=True,
                                   one_time_keyboard=True)
     bot.send_message(message.chat.id,
                      'Добро пожаловать в телеграм бот botname',
                      reply_markup=key)
     dict_with_state[message.from_user.id] = ''
Пример #5
0
def choice_crypto_sale(message):
    global dict_with_state

    #  global numberforBuy

    # numberforBuy = message.text.replace("/Buy", "")

    bot.send_message(message.chat.id, 'Введите количество монет')
    # bot.register_next_step_handler(message, numberforBuy, get_number)

    #  bot.register_next_step_handler(message, lambda msg: request_to_qiwi(numberforBuy, msg))

    dict_with_state[message.from_user.id] = message.text

    conn.hmset("pythonDict", dict_with_state)  #redis
Пример #6
0
def text_command(message):
    if message.text == 'Произвести обмен':
        to_exchange_coin(message)

    elif message.text == 'Мои обмены':
        bot.send_message(message.chat.id, ' Мои обмены ')
        history_of_exchanges(message)
    elif message.text == 'Настройки':
        change_settings(message)
    if message.text == 'Информация':
        bot.send_message(message.chat.id, ' Информация ')
        get_informations(message)

    elif message.text == 'Курсы обмена':
        get_exchange_rates(message)
Пример #7
0
def to_exchange_coin(message):
    bot.send_message(message.chat.id, ' Обмен валюты ')

    for id, count_coins, price, text, telephone in session.query(
            CryptoSale.id, CryptoSale.count_coins, CryptoSale.price,
            CryptoSale.text, CryptoSale.telephone):
        print("nothing")
        print(count_coins, price, text, telephone)

        command = "/Buy" + str(id)
        bot.send_message(
            message.chat.id,
            " В количеcтве " + str(count_coins) + " по цене за монету " +
            str(price) + " Монета -" + str(text) + " Номер для покупки:  " +
            str(telephone) + " " + command,
        )
Пример #8
0
def change_settings(message):
    global dict_with_state

    bot.send_message(message.chat.id, ' change_settings ')

    keyboardSettings = telebot.types.ReplyKeyboardMarkup()

    # keyboardMain.row('/All', '/Key') #Произвести обмен, мои обмены, настройки, ифнормация
    keyboardSettings.row(
        'Ввести ключ API от QIWI'
    )  # некошерные команды, а просто текст. Но с красивой клавой можно только так
    keyboardSettings.row('Мои адреса')
    keyboardSettings.row('Уведомления')
    keyboardSettings.row('/menu')

    bot.send_message(message.chat.id,
                     ' Settings ',
                     reply_markup=keyboardSettings)

    dict_with_state[message.from_user.id] = 'settings'
    conn.hmset("pythonDict", dict_with_state)  # redis
Пример #9
0
def send_p2p(my_login, api_access_token, to_qw, comment, sum_p2p, message):
    bot.send_message(message.chat.id, ' send_p2p ')

    s = requests.Session()
    s.headers = {'content-type': 'application/json'}
    s.headers['authorization'] = 'Bearer ' + api_access_token
    s.headers['User-Agent'] = 'Android v3.2.0 MKT'
    s.headers['Accept'] = 'application/json'
    postjson = json.loads(
        '{"id":"","sum":{"amount":"","currency":""},"paymentMethod":{"type":"Account","accountId":"643"},"comment":"' + comment + '","fields":{"account":""}}')
    postjson['id'] = str(int(time.time() * 1000))
    postjson['sum']['amount'] = sum_p2p
    postjson['sum']['currency'] = '643'
    postjson['fields']['account'] = to_qw
    res = s.post('https://edge.qiwi.com/sinap/api/v2/terms/99/payments', json=postjson)
    print(json.loads(res.text))
    print(res.text)
    bot.send_message(message.chat.id, ' wtf ')

    '''
    try:

        print(json.loads(res.text.state.code))

        bot.send_message(message.chat.id, json.loads(res.text.transaction.state.code))  # не кошер, еще подумаю где лучше делать
        if (json.loads(res.text.transaction.state.code) == 'Accepted'):
            status = 'ok'
        else:
            status = 'false'

    except:
        # bot.send_message(message.chat.id, res.text.message)
        status = 'false'
        bot.send_message(message.chat.id, res.text)

    '''

    if "Accepted" in res.text:
        bot.send_message(message.chat.id, 'All OK')
        status = 'ok'
    else:
        status = 'false'
        bot.send_message(message.chat.id, res.text)



    print("finish him")

    return status
Пример #10
0
def get_informations(message):

    keyboardInformations = telebot.types.ReplyKeyboardMarkup(
        resize_keyboard=True)
    # keyboardMain.row('/All', '/Key') #Произвести обмен, мои обмены, настройки, ифнормация
    keyboardInformations.row(
        'О нас'
    )  # некошерные команды, а просто текст. Но с красивой клавой можно только так
    keyboardInformations.row('Поддержка')
    keyboardInformations.row('Главное меню')
    keyboardInformations.row('/menu')

    bot.send_message(message.chat.id,
                     ' Информация ',
                     reply_markup=keyboardInformations)

    @bot.message_handler(content_types=['text'])
    def send_text(message):
        if message.text == 'О нас':
            bot.send_message(message.chat.id, ' Crocc - это калево ')
        elif message.text == 'Поддержка':
            bot.send_message(message.chat.id, ' Брат за брата ')
Пример #11
0
def change_settings_command(message):
    global dict_with_state
    if message.text == 'Ввести ключ API от QIWI':
        bot.send_message(message.chat.id, ' Введите  ваш  ключ API от QIWI ')
        dict_with_state[message.from_user.id] = 'settings_api_qiwi'

    elif message.text == 'Настройки':
        bot.send_message(message.chat.id, ' !Настройки ')
    elif message.text == 'Информация':
        bot.send_message(message.chat.id, ' Информация! ')
Пример #12
0
def send_p2p(api_access_token, to_qw, comment, sum_p2p, message):
    bot.send_message(message.chat.id, ' send_p2p ')

    s = requests.Session()
    s.headers = {'content-type': 'application/json'}
    s.headers['authorization'] = 'Bearer ' + api_access_token
    s.headers['User-Agent'] = 'Android v3.2.0 MKT'
    s.headers['Accept'] = 'application/json'
    postjson = json.loads(
        '{"id":"","sum":{"amount":"","currency":""},"paymentMethod":{"type":"Account","accountId":"643"},"comment":"' + comment + '","fields":{"account":""}}')
    postjson['id'] = str(int(time.time() * 1000))
    postjson['sum']['amount'] = sum_p2p
    postjson['sum']['currency'] = '643'
    postjson['fields']['account'] = to_qw
    res = s.post('https://edge.qiwi.com/sinap/api/v2/terms/99/payments', json=postjson)

    if "Accepted" in res.text:
        bot.send_message(message.chat.id, 'All OK')
        status = 'ok'
    else:
        status = 'false'
        bot.send_message(message.chat.id, res.text)

    return status
Пример #13
0
def get_informations(message):
    bot.send_message(message.chat.id, ' Поддержка ')
Пример #14
0
print('res4')

postjson = json.loads(
    '{"id":"","sum":{"amount":"","currency":""},"paymentMethod":{"type":"Account","accountId":"643"},"comment":"'
    + 'crypto' + '","fields":{"account":""}}')
postjson['id'] = str(int(time.time() * 1000))
postjson['sum']['amount'] = 1
postjson['sum']['currency'] = '643'
postjson['fields']['account'] = '+79055377771'
print('res2')

res = s.post('https://edge.qiwi.com/sinap/api/v2/terms/99/payments',
             json=postjson)
print('res3')

bot.send_message(message.chat.id, ' wtf ')

try:
    bot.send_message(message.chat.id, res.text.transaction.state.code
                     )  # не кошер, еще подумаю где лучше делать
    if (res.text.transaction.state.code == 'Accepted'):
        status = 'ok'
    else:
        status = 'false'

except:
    # bot.send_message(message.chat.id, res.text.message)
    status = 'false'
    bot.send_message(message.chat.id, "Qiwi failed")

print("finish him")
Пример #15
0
def get_exchange_rates(message):
    bot.send_message(message.chat.id, 'Курсы обмена:   ')
Пример #16
0
 def send_text(message):
     if message.text == 'О нас':
         bot.send_message(message.chat.id, ' Crocc - это калево ')
     elif message.text == 'Поддержка':
         bot.send_message(message.chat.id, ' Брат за брата ')
Пример #17
0
def start_message(message):
    bot.send_message(message.chat.id,
                     'Добро пожаловать в телеграм бот cracc',
                     reply_markup=keyboardMain)
    bot.send_message(message.chat.id, ' working ')
    dict_with_state[message.from_user.id] = ''
Пример #18
0
def request_to_qiwi(message):
    print("qiwi qiwi to me")
    global dict_with_state

    id_deal = dict_with_state[message.from_user.id].replace("/Buy", "")
    for id, countcoins, price, text, telephone in session.query(
            CryptoSale.id,
            CryptoSale.countcoins,
            CryptoSale.price,
            CryptoSale.text,
            CryptoSale.telephone,
    ).filter(CryptoSale.id == str(id_deal)):
        print("nothing")
    print(countcoins, price, text, telephone)
    countCoinAvailable = countcoins

    for keyqiwi, id_telegram in session.query(
            UserBotInfo.keyqiwi,
            UserBotInfo.id_telegram,
    ).filter(UserBotInfo.id_telegram == str(message.from_user.id)):
        print("nothing")
    print(keyqiwi, id_telegram)
    api_access_token = keyqiwi

    countCoin = message.text

    #------бронькаем нужное количество монеточек--------

    #может быть фейл, тип во время работы ребутнется и не вернется обратно заброненное, но такая хуйня может быть в любой момент как бы и всегда будет плохо

    print("broniruyu motrherfucke")
    '''
        update_info_bot = session.query(CryptoSale).filter(CryptoSale.id == int(id_deal)).first()
        update_info_bot.countcoins = int(countCoinAvailable) - int(countCoin)
        session.commit()

        result = db.session.query(User.money).with_for_update().filter_by(id=userid).first()
        money = result[0]
        user.money = money - 0.1
        '''

    update_info_bot = session.query(CryptoSale).with_for_update(
        of=CryptoSale).filter(CryptoSale.id == int(id_deal)).first()
    update_info_bot.countcoins = int(countCoinAvailable) - int(countCoin)
    session.commit()

    # ---------------------------------------------------

    status = ''
    if (int(countCoin) <= int(countCoinAvailable)):  # проверить число ли
        print("Отлично! Работаем дальше!")

        sum_p2p = int(countCoin) * int(price)
        print(" sum_p2p " + str(sum_p2p))
        # status = send_p2p('', api_access_token, telephone, 'coin', sum_p2p, message) qiwi qiwi to me
        status = 'ok'
        print(" status " + str(status))

        # ok или трабл
        if (status == 'ok'):

            print("status - OK")
            # добавление произведенной сделки

            newDeal = BotDeals(int(countCoin), int(sum_p2p), str(telephone),
                               str(id_telegram), str(text))
            #newDeal = BotDeals(44, 988, 'din don din', 424, '(text)')

            session.add(newDeal)
            session.commit()

            bot.send_message(message.chat.id,
                             'Деньги были переведены на счет продавца')
        else:
            bot.send_message(message.chat.id, 'Qiwi failed')
    else:
        print("all wrong")
        bot.send_message(message.chat.id, 'All failed')

    if (status != 'ok'):

        update_info_bot = session.query(CryptoSale).with_for_update(
            of=CryptoSale).filter(CryptoSale.id == int(id_deal)).first()
        update_info_bot.countcoins = update_info_bot.countcoins + int(
            countCoin)
        session.commit()

    dict_with_state[message.from_user.id] = ''
    conn.hmset("pythonDict", dict_with_state)  # redis
Пример #19
0
def request_to_qiwi(message):
    global dict_with_state
    id_deal = dict_with_state[message.from_user.id].replace("/Buy", "")
    for id, count_coins, price, text, telephone in session.query(
            CryptoSale.id,
            CryptoSale.count_coins,
            CryptoSale.price,
            CryptoSale.text,
            CryptoSale.telephone,
    ).filter(CryptoSale.id == str(id_deal)):
        count_coin_available = count_coins

    for keyqiwi, id_telegram in session.query(
            UserBotInfo.keyqiwi,
            UserBotInfo.id_telegram,
    ).filter(UserBotInfo.id_telegram == str(message.from_user.id)):
        api_access_token = keyqiwi

    count_coin = message.text
    '''
    update_info_bot = session.query(CryptoSale).filter(CryptoSale.id == int(id_deal)).first()
    update_info_bot.count_coins = int(count_coin_available) - int(count_coin)
    session.commit()

    result = db.session.query(User.money).with_for_update().filter_by(id=userid).first()
    money = result[0]
    user.money = money - 0.1
    '''

    update_info_bot = session.query(CryptoSale).with_for_update(
        of=CryptoSale).filter(CryptoSale.id == int(id_deal)).first()
    update_info_bot.count_coins = int(count_coin_available) - int(count_coin)
    session.commit()

    # ---------------------------------------------------

    status = ''
    if (int(count_coin) <= int(count_coin_available)):
        sum_p2p = int(count_coin) * int(price)
        print(" sum_p2p " + str(sum_p2p))
        # status = 'ok'
        send_p2p(api_access_token, telephone, 'comment', sum_p2p, message)
        print(" status " + str(status))

        if (status == 'ok'):
            newDeal = BotDeals(int(count_coin), int(sum_p2p), str(telephone),
                               str(id_telegram), str(text))
            session.add(newDeal)
            session.commit()

            bot.send_message(message.chat.id,
                             'Деньги были переведены на счет продавца')
        else:
            bot.send_message(message.chat.id, 'Qiwi failed')
    else:
        print("all wrong")
        bot.send_message(message.chat.id, 'All failed')

    if (status != 'ok'):
        update_info_bot = session.query(CryptoSale).with_for_update(
            of=CryptoSale).filter(CryptoSale.id == int(id_deal)).first()
        update_info_bot.count_coins = update_info_bot.count_coins + int(
            count_coin)
        session.commit()

    dict_with_state[message.from_user.id] = ''
    conn.hmset("pythonDict", dict_with_state)  # redis