使用Turntabler获取消息“DEBUG - :连接失败:连接未打开”

时间:2013-11-09 22:08:47

标签: ruby

我正在使用Turntabler,一个用于与turntable.fm交互的Ruby gem。我创建了这个简单的“Hello World”程序:

require 'turntabler'
require_relative 'config.rb'

config = KevbotConfiguration.load_config # Reads a YAML file

Turntabler.run(config[:email], config[:password], :room => config[:room], :reconnect => true, :reconnect_wait => 30) do
  on :user_spoke do |message|
    # Respond to "/hello" command
    if (message.content =~ /^\/hello$/)
      room.say("Hey! How are you @#{message.sender.name}?")
    end
  end
end

当我运行此程序时,它会失败并显示以下消息:

$ ruby src/main.rb 
D, [2013-11-09T15:57:17.602019 #10407] DEBUG -- : Connection failed: Connection is not open
D, [2013-11-09T15:57:47.634282 #10407] DEBUG -- : Attempting to reconnect
D, [2013-11-09T15:57:47.719336 #10407] DEBUG -- : Connection failed: Connection is not open
D, [2013-11-09T15:58:17.744107 #10407] DEBUG -- : Attempting to reconnect
D, [2013-11-09T15:58:17.828378 #10407] DEBUG -- : Connection failed: Connection is not open
D, [2013-11-09T15:58:47.854309 #10407] DEBUG -- : Attempting to reconnect
# etc.

我该怎么做才能解决这个问题?


编辑:这是config.rb的内容:

module KevbotConfiguration
    require 'yaml'

    def self.load_config
        return YAML.load_file('config.yaml')
    end
end

1 个答案:

答案 0 :(得分:0)

由于我直接从YAML读取config哈希值,我必须使用字符串来访问哈希值而不是符号:

Turntabler.run(config['email'], config['password'], :room => config['room'] #...


更一般地说,发生的事情是我的电子邮件,密码和房间没有正确传递给Turntabler.run。在我的例子中,以错误的方式访问哈希元素导致传递nil三个参数。