0

我正在使用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
4

1 回答 1

0

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

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


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

于 2013-11-09T22:14:56.237 回答