Method: WeChat::Bot::Client#start_runloop_thread

Defined in:
lib/wechat/bot/client.rb

#start_runloop_threadObject

Runloop 监听



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/wechat/bot/client.rb', line 58

def start_runloop_thread
  @is_alive = true
  retry_count = 0

  Thread.new do
    while alive?
      begin
        status = sync_check
        if status[:retcode] == "0"
          if status[:selector].nil?
            @is_alive = false
          elsif status[:selector] != "0"
            sync_messages
          end
        elsif status[:retcode] == "1100"
          @bot.logger.info("账户在手机上进行登出操作")
          @is_alive = false
          break
        elsif [ "1101", "1102" ].include?(status[:retcode])
          @bot.logger.info("账户在手机上进行登出或在其他地方进行登录操作操作")
          @is_alive = false
          break
        end

        retry_count = 0
      rescue Exception => e
        retry_count += 1
        @bot.logger.fatal(e)
      end

      sleep 1
    end

    logout
  end
end