コード例 #1
0
ファイル: bot_rot.py プロジェクト: rottedBen/telegram-bots
def get_price_maggot(update: Update, context: CallbackContext):
    (eth_per_maggot, dollar_per_maggot,
     rot_per_maggot) = get_price_maggot_raw()

    supply_cap_maggot = get_supply_cap_raw(maggot_contract)
    supply_cat_pretty = number_to_beautiful(supply_cap_maggot)
    market_cap = number_to_beautiful(
        int(float(supply_cap_maggot) * dollar_per_maggot))

    maggot_per_rot = 1 / rot_per_maggot

    holders = get_number_holder_token(maggot_contract)
    message = ""

    if str(dollar_per_maggot)[0:10] == "0.07514950":
        message = message + "Parts of Uniswap info seems down. Price might be outdated.\n"

    message = message + "<code>(MAGGOT) MaggotToken" \
              + "\nETH: Ξ" + str(eth_per_maggot)[0:10] \
              + "\nUSD: $" + str(dollar_per_maggot)[0:10] \
              + "\n" \
              + "\n1ROT    = " + str(maggot_per_rot)[0:4] + " MAGGOT" \
              + "\nS.  Cap = " + supply_cat_pretty \
              + "\nM.  Cap = $" + market_cap \
              + "\nHolders = " + str(holders) + "</code>"

    chat_id = update.message.chat_id
    util.create_and_send_vote("MAGGOT", "price", update.message.from_user.name,
                              zerorpc_client_data_aggregator)
    context.bot.send_message(chat_id=chat_id, text=message, parse_mode='html')
コード例 #2
0
ファイル: bot_charts.py プロジェクト: rottedBen/telegram-bots
def get_latest_actions(update: Update, context: CallbackContext):
    chat_id = update.message.chat_id
    query_received = update.message.text.split('/set_faq')
    if len(query_received) == 1:
        ticker, addr = __get_default_token_channel(chat_id)
        if ticker is not None:
            latest_actions_pretty = general_end_functions.get_last_actions_token_in_eth_pair(
                ticker, uni_wrapper, graphql_client_uni, addr)
            util.create_and_send_vote(ticker, "actions",
                                      update.message.from_user.name,
                                      zerorpc_client_data_aggregator)
            context.bot.send_message(chat_id=chat_id,
                                     text=latest_actions_pretty,
                                     disable_web_page_preview=True,
                                     parse_mode='html')
        else:
            context.bot.send_message(chat_id=chat_id,
                                     text=rejection_no_default_ticker_message)
    elif len(query_received) == 2:
        token_ticker = query_received[1]
        latest_actions_pretty = general_end_functions.get_last_actions_token_in_eth_pair(
            token_ticker, uni_wrapper, graphql_client_uni)
        util.create_and_send_vote(token_ticker, "actions",
                                  update.message.from_user.name,
                                  zerorpc_client_data_aggregator)
        context.bot.send_message(chat_id=chat_id,
                                 text=latest_actions_pretty,
                                 disable_web_page_preview=True,
                                 parse_mode='html')
    else:
        context.bot.send_message(
            chat_id=chat_id,
            text="Please use the format /last_actions TOKEN_TICKER")
コード例 #3
0
ファイル: bot_chonk.py プロジェクト: rottedBen/telegram-bots
def get_price_token(update: Update, context: CallbackContext):
    message = general_end_functions.get_price(contract, pair_contract,
                                              graphql_client_eth,
                                              graphql_client_uni, name,
                                              decimals)
    chat_id = update.message.chat_id
    util.create_and_send_vote(name, "price", update.message.from_user.name,
                              zerorpc_client_data_aggregator)
    context.bot.send_message(chat_id=chat_id,
                             text=message,
                             parse_mode='html',
                             reply_markup=reply_markup_price,
                             disable_web_page_preview=True)
コード例 #4
0
ファイル: bot_charts.py プロジェクト: rottedBen/telegram-bots
def get_candlestick(update: Update, context: CallbackContext):
    chat_id = update.message.chat_id

    query_received = update.message.text.split(' ')
    default_default_token = default_token
    if len(query_received) == 1:
        channel_token = __get_default_token_channel(chat_id)
        if channel_token is not None:
            default_default_token = channel_token[0]
        else:
            context.bot.send_message(chat_id=chat_id,
                                     text=rejection_no_default_ticker_message)
            pass

    time_type, k_hours, k_days, tokens = commands_util.check_query(
        query_received, default_default_token)
    t_to = int(time.time())
    t_from = t_to - (k_days * 3600 * 24) - (k_hours * 3600)
    trending = util.get_banner_txt(zerorpc_client_data_aggregator)

    if isinstance(tokens, list):
        for token in tokens:
            (message, path, reply_markup_chart
             ) = general_end_functions.send_candlestick_pyplot(token,
                                                               charts_path,
                                                               k_days,
                                                               k_hours,
                                                               t_from,
                                                               t_to,
                                                               txt=trending)
            util.create_and_send_vote(token, "chart",
                                      update.message.from_user.name,
                                      zerorpc_client_data_aggregator)
            context.bot.send_photo(chat_id=chat_id,
                                   photo=open(path, 'rb'),
                                   caption=message,
                                   parse_mode="html",
                                   reply_markup=reply_markup_chart)
    else:
        (message, path,
         reply_markup_chart) = general_end_functions.send_candlestick_pyplot(
             tokens, charts_path, k_days, k_hours, t_from, t_to, txt=trending)
        util.create_and_send_vote(tokens, "chart",
                                  update.message.from_user.name,
                                  zerorpc_client_data_aggregator)
        context.bot.send_photo(chat_id=chat_id,
                               photo=open(path, 'rb'),
                               caption=message,
                               parse_mode="html",
                               reply_markup=reply_markup_chart)
コード例 #5
0
ファイル: bot_rot.py プロジェクト: rottedBen/telegram-bots
def get_price_rot(update: Update, context: CallbackContext):
    chat_id = update.message.chat_id
    ticker = "ROT"
    contract_from_ticker = requests_util.get_token_contract_address(ticker)
    pprint.pprint(contract_from_ticker)
    button_list_price = [[
        InlineKeyboardButton('refresh',
                             callback_data='r_p_' + contract_from_ticker +
                             "_t_" + ticker)
    ]]
    reply_markup_price = InlineKeyboardMarkup(button_list_price)
    message = general_end_functions.get_price(contract_from_ticker, "",
                                              graphql_client_eth,
                                              graphql_client_uni,
                                              ticker.upper(), 10**18)
    util.create_and_send_vote(ticker, "price", update.message.from_user.name,
                              zerorpc_client_data_aggregator)
    context.bot.send_message(chat_id=chat_id,
                             text=message,
                             parse_mode='html',
                             reply_markup=reply_markup_price,
                             disable_web_page_preview=True)
コード例 #6
0
ファイル: bot_rot.py プロジェクト: rottedBen/telegram-bots
def get_chart_price_pyplot(update: Update, context: CallbackContext):
    chat_id = update.message.chat_id
    global last_time_checked_price_chart

    query_received = update.message.text.split(' ')
    if update.message.from_user.first_name == 'Ben':
        print("hello me")
        last_time_checked_price_chart = 1

    time_type, time_start, k_hours, k_days, query_ok, simple_query, token = check_query(
        query_received)

    if query_ok:
        new_time = round(time.time())
        if new_time - last_time_checked_price_chart > 60:
            if update.message.from_user.first_name != 'Ben':
                last_time_checked_price_chart = new_time
            list_time_price = []

            with open(price_file_path, newline='') as csvfile:
                spamreader = csv.reader(csvfile, delimiter=' ', quotechar='|')
                for row in spamreader:
                    list_time_price.append((row[0], row[1]))

            now = datetime.utcnow()

            filtered_values = [
                x for x in list_time_price if now -
                strp_date(x[0]) < timedelta(days=k_days, hours=k_hours)
            ]

            dates_pure = keep_dates(filtered_values)
            price = [float(value[1]) for value in filtered_values]

            print_chart_price(dates_pure, price)

            if simple_query:
                caption = "Chart since the bot starting logging the price.\nCurrent price: <pre>$" + str(
                    price[-1])[0:10] + "</pre>"
            else:
                caption = "Price of the last " + str(time_start) + str(
                    time_type) + ".\nCurrent price: <pre>$" + str(
                        price[-1])[0:10] + "</pre>"
            ad = get_ad()
            caption = caption + "\n" + ad
            util.create_and_send_vote("ROT", "chart",
                                      update.message.from_user.name,
                                      zerorpc_client_data_aggregator)
            context.bot.send_photo(chat_id=chat_id,
                                   photo=open(chart_price_file_path, 'rb'),
                                   caption=caption,
                                   parse_mode="html")
        else:
            context.bot.send_message(
                chat_id=chat_id,
                text=
                "Displaying charts only once every minute. Don't abuse this function"
            )
    else:
        context.bot.send_message(
            chat_id=chat_id,
            text=
            "Request badly formated. Please use /getchart time type (example: /getchart 3 h for the last 3h time range). Simply editing your message will not work, please send a new correctly formated message."
        )
コード例 #7
0
ファイル: bot_charts.py プロジェクト: rottedBen/telegram-bots
def get_price_token(update: Update, context: CallbackContext):
    chat_id = update.message.chat_id

    query_received = update.message.text.split(' ')
    if len(query_received) == 2:
        ticker = query_received[1]
        contract_from_ticker = requests_util.get_token_contract_address(ticker)
        pprint.pprint(contract_from_ticker)
        if contract_from_ticker is None:
            context.bot.send_message(chat_id=chat_id,
                                     text='Contract address for ticker ' +
                                     ticker + ' not found.')
        else:
            util.create_and_send_vote(ticker, "price",
                                      update.message.from_user.name,
                                      zerorpc_client_data_aggregator)
            button_list_price = [[
                InlineKeyboardButton('refresh',
                                     callback_data='r_p_' +
                                     contract_from_ticker + "_t_" + ticker)
            ]]
            reply_markup_price = InlineKeyboardMarkup(button_list_price)
            message = general_end_functions.get_price(contract_from_ticker,
                                                      pair_contract,
                                                      graphql_client_eth,
                                                      graphql_client_uni,
                                                      ticker.upper(), decimals)
            context.bot.send_message(chat_id=chat_id,
                                     text=message,
                                     parse_mode='html',
                                     reply_markup=reply_markup_price,
                                     disable_web_page_preview=True)
    elif len(query_received) == 1:  # TODO: merge all those duplicate things
        ticker, addr = __get_default_token_channel(chat_id)
        if ticker is not None:
            if addr is None or addr == "":
                context.bot.send_message(chat_id=chat_id,
                                         text='Contract address for ticker ' +
                                         ticker + ' not found.')
            else:
                util.create_and_send_vote(ticker, "price",
                                          update.message.from_user.name,
                                          zerorpc_client_data_aggregator)
                button_list_price = [[
                    InlineKeyboardButton('refresh',
                                         callback_data='r_p_' + addr + "_t_" +
                                         ticker)
                ]]
                reply_markup_price = InlineKeyboardMarkup(button_list_price)
                message = general_end_functions.get_price(
                    addr, pair_contract, graphql_client_eth,
                    graphql_client_uni, ticker.upper(), decimals)
                context.bot.send_message(chat_id=chat_id,
                                         text=message,
                                         parse_mode='html',
                                         reply_markup=reply_markup_price,
                                         disable_web_page_preview=True)
        else:
            message = rejection_no_default_ticker_message
            context.bot.send_message(chat_id=chat_id,
                                     text=message,
                                     parse_mode='html')
    else:
        context.bot.send_message(
            chat_id=chat_id,
            text='Please specify the ticker of the desired token.')