import logging import os import telebot from dotenv import load_dotenv from bots.common.commands_dict import commands from bots.common.helpers import non_slash from bots.helpers import ShowView load_dotenv() available_commands = list(commands.keys()) bot = telebot.TeleBot(os.getenv("OPENBB_TELEGRAM_BOT_TOKEN")) bot_commands = [ telebot.types.BotCommand("/about", "Bot information"), telebot.types.BotCommand("/cmds", "List of commands"), ] for key, value in commands.items(): bot_commands.append( telebot.types.BotCommand( key.replace("-", "_"), value["function"].__doc__.split("Parameters")[0][:256].strip(), ) ) bot.set_my_commands(commands=bot_commands) def detect_valid_command(message): cmd = message.text[1:] full_cmd = cmd.split("/")[0] return full_cmd in available_commands @bot.message_handler(commands=["start", "Start", "about", "help"]) def send_welcome(message): text = """ Welcome to *OpenBB Terminal Bot* 🦋 Investment Research for Everyone Check the available commands with /cmds """ markdown = telebot.types.InlineKeyboardMarkup() markdown.add( telebot.types.InlineKeyboardButton( "Star us on GitHub", url="https://github.com/OpenBB-finance/OpenBBTerminal", ) ) markdown.add( telebot.types.InlineKeyboardButton( "Join us on Discord", url="https://discord.gg/XHsYvvjjWg" ) ) bot.send_message( chat_id=message.chat.id, text=text, reply_markup=markdown, parse_mode="MARKDOWN" ) @bot.message_handler(commands=["cmds", "commands"]) def send_cmds(message): helptext = ( "\n/disc_fidelity\n" "/ins_last/ticker \n" "\n/opt_unu\n" "/opt_iv/ticker\n" "/opt_vsurf/ticker \n" "/opt_hist/ticker \n" "/opt_oi/ticker \n" "/opt_vol/ticker \n" "/opt_overview/ticker \n" "/opt_chain/ticker \n" "\n/ta_summary/ticker\n" "/ta_view/ticker\n" "/ta_recom/ticker\n" "/ta_obv/ticker \n" "/ta_fib/ticker \n" "/ta_ad/ticker \n" "/ta_cg/ticker \n" "/ta_fisher/ticker \n" "/ta_cci/ticker \n" "/ta_ema/ticker \n" "/ta_sma/ticker \n" "/ta_wma/ticker \n" "/ta_hma/ticker \n" "/ta_zlma/ticker \n" "/ta_aroon/ticker \n" "/ta_adosc/ticker \n" "/ta_macd/ticker \n" "/ta_kc/ticker \n" "/ta_adx/ticker \n" "/ta_rsi/ticker \n" "/ta_stoch/ticker \n" "/ta_bbands/ticker \n" "/ta_donchian/ticker \n" "\n/dd_est/ticker\n" "/dd_sec/ticker\n" "/dd_analyst/ticker\n" "/dd_supplier/ticker\n" "/dd_customer/ticker\n" "/dd_arktrades/ticker\n" "/dd_pt/ticker \n" "\n/dps_hsi \n" "/dps_shorted/(NUM)\n" "/dps_psi/ticker\n" "/dps_spos/ticker\n" "/dps_dpotc/ticker\n" "/dps_pos \n" "/dps_sidtc \n" "/dps_ftd/ticker \n" "\n/scr_presets_default\n" "/scr_presets_custom\n" "/scr_historical/(SIGNAL) \n" "/scr_overview/(PRESET) \n" "/scr_technical/(PRESET) \n" "/scr_valuation/(PRESET) \n" "/scr_financial/(PRESET) \n" "/scr_ownership/(PRESET) \n" "/scr_performance/(PRESET) \n" "\n/gov_histcont/ticker\n" "/gov_lobbying/ticker \n" "/gov_toplobbying \n" "/gov_lastcontracts \n" "/gov_contracts/ticker \n" "/gov_qtrcontracts \n" "/gov_lasttrades \n" "/gov_gtrades/ticker \n" "/gov_topbuys \n" "/gov_topsells \n" "\n` = Past Transaction Days`\n" "` = Past Transaction Months`" "\n/econ_softs\n" "/econ_meats\n" "/econ_energy\n" "/econ_metals\n" "/econ_grains\n" "/econ_futures\n" "/econ_usbonds\n" "/econ_glbonds\n" "/econ_indices\n" "/econ_overview\n" "/econ_currencies\n" "/econ_valuation \n" "/econ_performance \n" ) bot.reply_to(message, helptext) @bot.message_handler(func=lambda m: m.text[0] == "/") def send_command(message): bot.send_chat_action(message.chat.id, action="typing") non_slash( message.text, lambda x: bot.reply_to(message, x), lambda x, y, z: ShowView().telegram(x, message, bot, y, **z), ) if __name__ == "__main__": # TODO: replace with GST logging logger = logging.getLogger() logger.setLevel(logging.DEBUG) logger.addHandler(logging.StreamHandler()) bot.infinity_polling()