Module: ConfigMenu
- Included in:
- OpenAIBot
- Defined in:
- lib/config_menu.rb
Class Method Summary collapse
Instance Method Summary collapse
- #config_menu ⇒ Object
- #handle_config_query ⇒ Object
- #handle_model_query ⇒ Object
- #model_selection_menu ⇒ Object
Class Method Details
.included(base) ⇒ Object
4 5 6 7 8 9 10 |
# File 'lib/config_menu.rb', line 4 def self.included(base) base. :handle_config_query base.on_command "/config" do $original_config_message_id = @msg. $config_message_id = reply("clicky buttons:", reply_markup: ). end end |
Instance Method Details
#config_menu ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/config_menu.rb', line 33 def = { "Select model >>" => "/get_model_menu", "Restart" => "/restart", "Toggle price info" => "/toggle_price_info", "Done" => "/config_done" } Telegram::Bot::Types::InlineKeyboardMarkup.new( inline_keyboard: .map { |k, v| [Telegram::Bot::Types::InlineKeyboardButton.new(text: k, callback_data: v)] } ) end |
#handle_config_query ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/config_menu.rb', line 48 def handle_config_query return unless @update.is_a? Telegram::Bot::Types::CallbackQuery return unless @user.username == config.owner_username case @update.data when "/get_model_menu" @api.(chat_id: @chat.id, message_id: $config_message_id, reply_markup: , text: "Select model") when "/restart" init_session when "/toggle_price_info" if config.respond_to?(:show_price_info) config.show_price_info = !config.show_price_info else config.show_price_info = false end ("Now #{config.show_price_info ? "" : "NOT "}showing price info") when "/go_back" @api.(chat_id: @chat.id, message_id: $config_message_id, reply_markup: , text: "Config menu") when "/config_done" safe_delete_by_id($config_message_id, from_bot: true) safe_delete_by_id($original_config_message_id) else handle_model_query end end |
#handle_model_query ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/config_menu.rb', line 74 def handle_model_query return unless @update.is_a? Telegram::Bot::Types::CallbackQuery return unless @update.data.start_with? "/set_model " return unless @user.username == config.owner_username model = @update.data.delete_prefix("/set_model ").to_sym return if OpenAI::Model::MODEL_INFO[model].nil? text = if current_thread.model.to_sym == model "Already set to `#{model}`" else "Was `#{current_thread.model.to_s}`, now `#{model}`" end current_thread.model = OpenAI::Model.new(model) (text, parse_mode: "Markdown") end |
#model_selection_menu ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/config_menu.rb', line 12 def = [] OpenAI::Model::MODEL_INFO.each do |model, info| << [ Telegram::Bot::Types::InlineKeyboardButton.new( text: "#{model} - #{sprintf('%.2f', info[:output_price])}$", callback_data: "/set_model #{model}" ) ] end << [ Telegram::Bot::Types::InlineKeyboardButton.new( text: "<< Go back", callback_data: "/go_back" ) ] Telegram::Bot::Types::InlineKeyboardMarkup.new(inline_keyboard: ) end |