module Dialog::BotApi
Public Class Methods
apiAction(args)
click to toggle source
# File lib/telegram/botapi.rb, line 29 def apiAction(args) args[:perf][:preApiAction] = Time.now op = args[:api][:op] Dialog.logger.debug "Operation #{op}: #{args[:smsg]}\n" a = args[:bot].api.send("#{op}".to_sym, args[:smsg]) Dialog.logger.debug "API Answer - #{a}" args[:perf][:postApiAction] = Time.now if a["ok"] == true return a else Dialog.logger.info "ERROR in bot.api interaction #{"#{op}".to_sym}, msg: #{args[:smsg]}" end args[:smsg] = {} args[:api] = {} args[:x] = {} end
apiActionGet(args)
click to toggle source
# File lib/telegram/botapi.rb, line 17 def apiActionGet(args) args[:api][:op] = "get#{args[:api][:op]}" a = apiAction(args) return a end
apiActionSend(args)
click to toggle source
# File lib/telegram/botapi.rb, line 23 def apiActionSend(args) args[:api][:op] = "send#{args[:api][:op]}" a = apiAction(args) return a end
runMetacommand__info(args)
click to toggle source
# File lib/telegram/infra_info.rb, line 17 def runMetacommand__info(args) if args[:mmsg][:reply] == nil args[:smsg][:text] = "О чём именно вам дать информацию?\n Отметьте объект с помощью 'Reply' и отправьте ему сообщение '_info' или '_инфо'\n" Bot::BotApi.new.apiActionSend(args) else text = "Информация об объекте:\n\n" text = text + "Как-то раз (а именно, <b>#{DateTime.strptime(args[:mmsg][:reply][:mmsg][:date].to_s,'%s')}</b>) \n" text = text + "пользователь <b>#{args[:mmsg][:reply][:mmsg][:username]}</b> с ID <b>#{args[:mmsg][:reply][:mmsg][:user_id]}</b> \n" text = text + "отправил сообщение с ID \"<b>#{args[:mmsg][:reply][:mmsg][:message_id]}</b>\"\n" text = text + "в чат контекста \"<b>#{args[:mmsg][:reply][:mmsg][:chat_context]}</b>\" под названием \"<b>#{args[:mmsg][:reply][:mmsg][:chat_title]}</b>\" с ID \"<b>#{args[:mmsg][:reply][:mmsg][:chat_id]}</b>\"\n" text = text + "(на самом деле, это был forward сообщения пользователя <b>#{args[:mmsg][:reply][:mmsg][:forward][:from][:username]}</b> с ID <b>#{args[:mmsg][:reply][:mmsg][:forward][:from][:user_id]}</b> от <b>#{DateTime.strptime(args[:mmsg][:reply][:mmsg][:forward][:date].to_s,'%s')}</b>\n" if ! args[:mmsg][:reply][:mmsg][:forward].nil? text = text + "Сообщение было отредактировано <b>#{DateTime.strptime(args[:mmsg][:reply][:mmsg][:edit][:date].to_s,'%s')}</b>\n" if ! args[:mmsg][:reply][:mmsg][:edit].nil? text = text + "\nДополнительная информация:\n" text = text + "Order(Порядок): \"<b>#{args[:mmsg][:reply][:mmsg][:_order]}</b>\"\n" text = text + "Family(Семейство): \"<b>#{args[:mmsg][:reply][:mmsg][:_family]}</b>\"\n" if args[:mmsg][:reply][:mmsg][:_order] == Bot::Naming::Class::Message::Order.Media text = text + "ID файла: \"<b>#{args[:mmsg][:reply][:mmsg][:media][:file_id]}</b>\"\n" text = text + "Название файла: \"<b>#{args[:mmsg][:reply][:mmsg][:media][:file_name]}</b>\"\n" if ! args[:mmsg][:reply][:mmsg][:media][:file_name].nil? text = text + "MIME-тип: \"<b>#{args[:mmsg][:reply][:mmsg][:media][:mime_type]}</b>\"\n" if ! args[:mmsg][:reply][:mmsg][:media][:mime_type].nil? text = text + "Размер файла: \"<b>#{args[:mmsg][:reply][:mmsg][:media][:file_size]} байта</b>\"\n" text = text + "Описание к #{args[:mmsg][:reply][:mmsg][:_family]} : \"<b>#{args[:mmsg][:reply][:mmsg][:media][:caption]}</b>\n" if ! args[:mmsg][:reply][:mmsg][:media][:caption] == nil end args[:smsg][:text] = text end end
socks5_connection()
click to toggle source
# File lib/telegram/botapi.rb, line 48 def socks5_connection require 'telegram/bot/adapters/socks5' host = "https://#{Dialog.config.proxy.host}:#{Dialog.config.proxy.port}" proxy_opts = { uri: URI.parse(host), user: Dialog.config.proxy.login, password: Dialog.config.proxy.pass, socks: true } c = Faraday.new(url: Dialog.config.host.apiUri, ssl: {verify:false}, request: { proxy: proxy_opts }) do |c| c.request :multipart c.request :url_encoded Faraday::Adapter.register_middleware socks5: Telegram::Bot::Adapters::Socks5 c.adapter :socks5 end return c end