wm: mohandes-bot

ref: 7f016c237a6ddddaedf899510d87f7200e82c9c1
dir: /Telbot.rb/

View raw version
require 'telegram/bot'

token = "6672739302:AAE56rxiQugSQpngM-3q5EJv8xnHp2JMbSQ"
id = "@mohandese_riazi_dan_bot"
admin = 331358784
silent = false

Signal.trap('INT') do
  bot.stop
end

def SendWithReply(text)
  bot.api.send_message(chat_id: message.chat.id, reply_to_message_id: message.message_id, text: text);
end

Telegram::Bot::Client.run(token) do |bot|
  bot.listen do |message|
    case message
    when Telegram::Bot::Types::Message

      # if message.edit_date.is_a?(Integer) && message.reply_to_message.from.username.eql?("mohandese_riazi_dan_bot") then
      #   begin
      #     a = message.text;
      #
      #     bot.api.editMessageText(chat_id: message.reply_to_message.chat.id, message_id: message.message_id + 1, text: "#{eval(a)}");
      #   rescue Telegram::Bot::Exceptions::ResponseError => re
      #     bot.api.send_message(chat_id: message.chat.id, reply_to_message_id: message.message_id, text: re.message);
      #   end
      # els

      if (!silent) || message.from.id == admin then
        if message.chat.type.eql?("supergroup") then
          if message.reply_to_message.is_a?(Telegram::Bot::Types::Message) && message.reply_to_message.from.username.eql?("mohandese_riazi_dan_bot") then
            begin
              a = message.text;

              if (message.from.id == admin) then
                if (a.eql?("off"))
                  silent = true
                end
                if (a.eql?("on"))
                  silent = false
                end
              end

              #if message.edit_date.is_a?(Integer) then
              #  bot.api.editMessageText(chat_id: message.reply_to_message.chat.id, message_id: message.message_id + 1, text: "#{eval(a)}");
              #else
              bot.api.send_message(chat_id: message.chat.id, reply_to_message_id: message.message_id, text: "#{eval(a)}");
              #end
            rescue => error
              sleep(1);
              bot.api.send_message(chat_id: message.chat.id, reply_to_message_id: message.message_id, text: error.message);
            rescue SyntaxError => se
              bot.api.send_message(chat_id: message.chat.id, reply_to_message_id: message.message_id, text: se.message);#"Syntax Error Dash.");
            rescue NoMemoryError => nme
              bot.api.send_message(chat_id: message.chat.id, reply_to_message_id: message.message_id, text: nme.message);
            rescue ResponseError => RE
              bot.api.send_message(chat_id: admin, reply_to_message_id: message.message_id, text: RE.message);
            end
          end
          if message.text.is_a?(String) && message.text.start_with?("#{id} ") then
            begin
              a = message.text;
              a.slice! "#{id} "

              if (message.from.id == admin) then
                if (a.eql?("off"))
                  silent = true
                end
                if (a.eql?("on"))
                  silent = false
                end
              end

              bot.api.send_message(chat_id: message.chat.id, reply_to_message_id: message.message_id, text: "#{eval(a)}");
            rescue => error
              sleep(1);
              bot.api.send_message(chat_id: message.chat.id, reply_to_message_id: message.message_id, text: error.message);
            rescue SyntaxError => se
              bot.api.send_message(chat_id: message.chat.id, reply_to_message_id: message.message_id, text: se.message);#"Syntax Error Dash.");
            rescue NoMemoryError => nme
              bot.api.send_message(chat_id: message.chat.id, reply_to_message_id: message.message_id, text: nme.message);
            rescue ResponseError => RE
              bot.api.send_message(chat_id: admin, reply_to_message_id: message.message_id, text: RE.message);
            end
          end
        elsif message.chat.type.eql?("private") then
          begin
            if (message.chat.id == admin) then
              if (message.text.eql?("off"))
                silent = true
              end
              if (message.text.eql?("on"))
                silent = false
              end
            end
            a = message.text;
            bot.api.send_message(chat_id: message.chat.id, text: "#{eval(a)}");
          rescue => error
            sleep(1);
            bot.api.send_message(chat_id: message.chat.id, text: error.message);
          rescue SyntaxError => se
            bot.api.send_message(chat_id: message.chat.id, text: se.message);#"Syntax Error Dash.");
          rescue NoMemoryError => nme
            bot.api.send_message(chat_id: message.chat.id, text: nme.message);
          rescue ResponseError => RE
            bot.api.send_message(chat_id: admin, reply_to_message_id: message.message_id, text: RE.message);
          end
        end
      end
    end
  end
end