cinchrb / cinch

The IRC Bot Building Framework
http://www.rubydoc.info/gems/cinch
MIT License
1k stars 180 forks source link

A synced attribute ('user' for #<Bot nick="...">) has not been available for X seconds... #151

Closed lpeabody closed 10 years ago

lpeabody commented 10 years ago

I'm basically running an identical copy of the first example listed on the main page of the repository.

Here's my code:

require 'cinch'
require 'pp'

host = 'irc.twitch.tv'
user = 'PeebzNationBot'
nick = 'PeebzNationBot'
port = 6667
channels = ['#peebznation']
password = 'expunged'

bot = Cinch::Bot.new do
  configure do |c|
    c.server = host
    c.port = port
    c.user = user
    c.nick = nick
    c.password = password
    c.channels = channels
  end

  on :message, "hello" do |m|
    m.reply "Hello, #{m.user.nick}"
    # pp m
  end
end

bot.start

Here's the error that gets produced:

[2013/12/23 21:04:48.495] >> :peebznation!peebznation@peebznation.tmi.twitch.tv PRIVMSG #peebznation :hello
[2013/12/23 21:04:48.496] !! [New thread] For #<Cinch::Handler @event=:message pattern=#<Cinch::Pattern:0x007fded9872ed0 @prefix=/^/, @pattern=/hello/, @suffix=/$/>>: #<Thread:0x007fded9064158> -- 1 in total.
[2013/12/23 21:04:48.497] << WHOIS peebznationbot peebznationbot 
[2013/12/23 21:04:48.876] >> :tmi.twitch.tv 421 peebznationbot WHOIS :Unknown command
[2013/12/23 21:04:58.473] !! A synced attribute ('user' for #<Bot nick="peebznationbot">) has not been available for 10 seconds, still waiting
[2013/12/23 21:04:58.473] !!   /Users/lpeabody/.rvm/gems/ruby-2.0.0-p353@twitchmech/gems/cinch-2.0.11/lib/cinch/syncable.rb:67:in `attr'
[2013/12/23 21:04:58.473] !!   /Users/lpeabody/.rvm/gems/ruby-2.0.0-p353@twitchmech/gems/cinch-2.0.11/lib/cinch/user.rb:139:in `attr'
[2013/12/23 21:04:58.474] !!   /Users/lpeabody/.rvm/gems/ruby-2.0.0-p353@twitchmech/gems/cinch-2.0.11/lib/cinch/user.rb:383:in `method_missing'
[2013/12/23 21:04:58.474] !!   /Users/lpeabody/.rvm/gems/ruby-2.0.0-p353@twitchmech/gems/cinch-2.0.11/lib/cinch/user.rb:246:in `block in mask'
[2013/12/23 21:04:58.474] !!   /Users/lpeabody/.rvm/gems/ruby-2.0.0-p353@twitchmech/gems/cinch-2.0.11/lib/cinch/user.rb:241:in `gsub'
[2013/12/23 21:04:58.474] !!   /Users/lpeabody/.rvm/gems/ruby-2.0.0-p353@twitchmech/gems/cinch-2.0.11/lib/cinch/user.rb:241:in `mask'
[2013/12/23 21:04:58.474] !!   /Users/lpeabody/.rvm/gems/ruby-2.0.0-p353@twitchmech/gems/cinch-2.0.11/lib/cinch/target.rb:38:in `block in msg'
[2013/12/23 21:04:58.474] !!   /Users/lpeabody/.rvm/gems/ruby-2.0.0-p353@twitchmech/gems/cinch-2.0.11/lib/cinch/target.rb:36:in `each'
[2013/12/23 21:04:58.474] !!   /Users/lpeabody/.rvm/gems/ruby-2.0.0-p353@twitchmech/gems/cinch-2.0.11/lib/cinch/target.rb:36:in `msg'
[2013/12/23 21:04:58.474] !!   /Users/lpeabody/.rvm/gems/ruby-2.0.0-p353@twitchmech/gems/cinch-2.0.11/lib/cinch/channel.rb:398:in `msg'
[2013/12/23 21:04:58.474] !!   /Users/lpeabody/.rvm/gems/ruby-2.0.0-p353@twitchmech/gems/cinch-2.0.11/lib/cinch/message.rb:164:in `reply'
[2013/12/23 21:04:58.474] !!   main.rb:26:in `block (2 levels) in <main>'
[2013/12/23 21:04:58.474] !!   /Users/lpeabody/.rvm/gems/ruby-2.0.0-p353@twitchmech/gems/cinch-2.0.11/lib/cinch/handler.rb:86:in `instance_exec'
[2013/12/23 21:04:58.475] !!   /Users/lpeabody/.rvm/gems/ruby-2.0.0-p353@twitchmech/gems/cinch-2.0.11/lib/cinch/handler.rb:86:in `block in call'
[2013/12/23 21:05:08.553] !! A synced attribute ('user' for #<Bot nick="peebznationbot">) has not been available for 20 seconds, still waiting
[2013/12/23 21:05:08.554] !!   /Users/lpeabody/.rvm/gems/ruby-2.0.0-p353@twitchmech/gems/cinch-2.0.11/lib/cinch/syncable.rb:67:in `attr'
[2013/12/23 21:05:08.554] !!   /Users/lpeabody/.rvm/gems/ruby-2.0.0-p353@twitchmech/gems/cinch-2.0.11/lib/cinch/user.rb:139:in `attr'
[2013/12/23 21:05:08.554] !!   /Users/lpeabody/.rvm/gems/ruby-2.0.0-p353@twitchmech/gems/cinch-2.0.11/lib/cinch/user.rb:383:in `method_missing'
[2013/12/23 21:05:08.554] !!   /Users/lpeabody/.rvm/gems/ruby-2.0.0-p353@twitchmech/gems/cinch-2.0.11/lib/cinch/user.rb:246:in `block in mask'
[2013/12/23 21:05:08.554] !!   /Users/lpeabody/.rvm/gems/ruby-2.0.0-p353@twitchmech/gems/cinch-2.0.11/lib/cinch/user.rb:241:in `gsub'
[2013/12/23 21:05:08.554] !!   /Users/lpeabody/.rvm/gems/ruby-2.0.0-p353@twitchmech/gems/cinch-2.0.11/lib/cinch/user.rb:241:in `mask'
[2013/12/23 21:05:08.554] !!   /Users/lpeabody/.rvm/gems/ruby-2.0.0-p353@twitchmech/gems/cinch-2.0.11/lib/cinch/target.rb:38:in `block in msg'
[2013/12/23 21:05:08.554] !!   /Users/lpeabody/.rvm/gems/ruby-2.0.0-p353@twitchmech/gems/cinch-2.0.11/lib/cinch/target.rb:36:in `each'
[2013/12/23 21:05:08.554] !!   /Users/lpeabody/.rvm/gems/ruby-2.0.0-p353@twitchmech/gems/cinch-2.0.11/lib/cinch/target.rb:36:in `msg'
[2013/12/23 21:05:08.554] !!   /Users/lpeabody/.rvm/gems/ruby-2.0.0-p353@twitchmech/gems/cinch-2.0.11/lib/cinch/channel.rb:398:in `msg'
[2013/12/23 21:05:08.554] !!   /Users/lpeabody/.rvm/gems/ruby-2.0.0-p353@twitchmech/gems/cinch-2.0.11/lib/cinch/message.rb:164:in `reply'
[2013/12/23 21:05:08.554] !!   main.rb:26:in `block (2 levels) in <main>'
[2013/12/23 21:05:08.554] !!   /Users/lpeabody/.rvm/gems/ruby-2.0.0-p353@twitchmech/gems/cinch-2.0.11/lib/cinch/handler.rb:86:in `instance_exec'
[2013/12/23 21:05:08.554] !!   /Users/lpeabody/.rvm/gems/ruby-2.0.0-p353@twitchmech/gems/cinch-2.0.11/lib/cinch/handler.rb:86:in `block in call'
[2013/12/23 21:05:13.865] >> :peebznation!peebznation@peebznation.tmi.twitch.tv JOIN #peebznation 
[2013/12/23 21:05:14.283] >> :jtv MODE #peebznation +o peebznation 
[2013/12/23 21:05:18.632] !! A synced attribute ('user' for #<Bot nick="peebznationbot">) has not been available for 30 seconds, still waiting
[2013/12/23 21:05:18.632] !!   /Users/lpeabody/.rvm/gems/ruby-2.0.0-p353@twitchmech/gems/cinch-2.0.11/lib/cinch/syncable.rb:67:in `attr'
[2013/12/23 21:05:18.632] !!   /Users/lpeabody/.rvm/gems/ruby-2.0.0-p353@twitchmech/gems/cinch-2.0.11/lib/cinch/user.rb:139:in `attr'
[2013/12/23 21:05:18.632] !!   /Users/lpeabody/.rvm/gems/ruby-2.0.0-p353@twitchmech/gems/cinch-2.0.11/lib/cinch/user.rb:383:in `method_missing'
[2013/12/23 21:05:18.632] !!   /Users/lpeabody/.rvm/gems/ruby-2.0.0-p353@twitchmech/gems/cinch-2.0.11/lib/cinch/user.rb:246:in `block in mask'
[2013/12/23 21:05:18.632] !!   /Users/lpeabody/.rvm/gems/ruby-2.0.0-p353@twitchmech/gems/cinch-2.0.11/lib/cinch/user.rb:241:in `gsub'
[2013/12/23 21:05:18.632] !!   /Users/lpeabody/.rvm/gems/ruby-2.0.0-p353@twitchmech/gems/cinch-2.0.11/lib/cinch/user.rb:241:in `mask'
[2013/12/23 21:05:18.632] !!   /Users/lpeabody/.rvm/gems/ruby-2.0.0-p353@twitchmech/gems/cinch-2.0.11/lib/cinch/target.rb:38:in `block in msg'
[2013/12/23 21:05:18.632] !!   /Users/lpeabody/.rvm/gems/ruby-2.0.0-p353@twitchmech/gems/cinch-2.0.11/lib/cinch/target.rb:36:in `each'
[2013/12/23 21:05:18.633] !!   /Users/lpeabody/.rvm/gems/ruby-2.0.0-p353@twitchmech/gems/cinch-2.0.11/lib/cinch/target.rb:36:in `msg'
[2013/12/23 21:05:18.633] !!   /Users/lpeabody/.rvm/gems/ruby-2.0.0-p353@twitchmech/gems/cinch-2.0.11/lib/cinch/channel.rb:398:in `msg'
[2013/12/23 21:05:18.633] !!   /Users/lpeabody/.rvm/gems/ruby-2.0.0-p353@twitchmech/gems/cinch-2.0.11/lib/cinch/message.rb:164:in `reply'
[2013/12/23 21:05:18.633] !!   main.rb:26:in `block (2 levels) in <main>'
[2013/12/23 21:05:18.633] !!   /Users/lpeabody/.rvm/gems/ruby-2.0.0-p353@twitchmech/gems/cinch-2.0.11/lib/cinch/handler.rb:86:in `instance_exec'
[2013/12/23 21:05:18.633] !!   /Users/lpeabody/.rvm/gems/ruby-2.0.0-p353@twitchmech/gems/cinch-2.0.11/lib/cinch/handler.rb:86:in `block in call'
[2013/12/23 21:05:18.633] !!   Giving up...
[2013/12/23 21:05:18.633] !! /Users/lpeabody/.rvm/gems/ruby-2.0.0-p353@twitchmech/gems/cinch-2.0.11/lib/cinch/syncable.rb:21:in `wait_until_synced': 'user' for #<Bot nick="peebznationbot"> (Cinch::Exceptions::SyncedAttributeNotAvailable)
[2013/12/23 21:05:18.633] !!    /Users/lpeabody/.rvm/gems/ruby-2.0.0-p353@twitchmech/gems/cinch-2.0.11/lib/cinch/syncable.rb:67:in `attr'
[2013/12/23 21:05:18.633] !!    /Users/lpeabody/.rvm/gems/ruby-2.0.0-p353@twitchmech/gems/cinch-2.0.11/lib/cinch/user.rb:139:in `attr'
[2013/12/23 21:05:18.633] !!    /Users/lpeabody/.rvm/gems/ruby-2.0.0-p353@twitchmech/gems/cinch-2.0.11/lib/cinch/user.rb:383:in `method_missing'
[2013/12/23 21:05:18.633] !!    /Users/lpeabody/.rvm/gems/ruby-2.0.0-p353@twitchmech/gems/cinch-2.0.11/lib/cinch/user.rb:246:in `block in mask'
[2013/12/23 21:05:18.633] !!    /Users/lpeabody/.rvm/gems/ruby-2.0.0-p353@twitchmech/gems/cinch-2.0.11/lib/cinch/user.rb:241:in `gsub'
[2013/12/23 21:05:18.633] !!    /Users/lpeabody/.rvm/gems/ruby-2.0.0-p353@twitchmech/gems/cinch-2.0.11/lib/cinch/user.rb:241:in `mask'
[2013/12/23 21:05:18.633] !!    /Users/lpeabody/.rvm/gems/ruby-2.0.0-p353@twitchmech/gems/cinch-2.0.11/lib/cinch/target.rb:38:in `block in msg'
[2013/12/23 21:05:18.633] !!    /Users/lpeabody/.rvm/gems/ruby-2.0.0-p353@twitchmech/gems/cinch-2.0.11/lib/cinch/target.rb:36:in `each'
[2013/12/23 21:05:18.633] !!    /Users/lpeabody/.rvm/gems/ruby-2.0.0-p353@twitchmech/gems/cinch-2.0.11/lib/cinch/target.rb:36:in `msg'
[2013/12/23 21:05:18.633] !!    /Users/lpeabody/.rvm/gems/ruby-2.0.0-p353@twitchmech/gems/cinch-2.0.11/lib/cinch/channel.rb:398:in `msg'
[2013/12/23 21:05:18.633] !!    /Users/lpeabody/.rvm/gems/ruby-2.0.0-p353@twitchmech/gems/cinch-2.0.11/lib/cinch/message.rb:164:in `reply'
[2013/12/23 21:05:18.633] !!    main.rb:26:in `block (2 levels) in <main>'
[2013/12/23 21:05:18.633] !!    /Users/lpeabody/.rvm/gems/ruby-2.0.0-p353@twitchmech/gems/cinch-2.0.11/lib/cinch/handler.rb:86:in `instance_exec'
[2013/12/23 21:05:18.633] !!    /Users/lpeabody/.rvm/gems/ruby-2.0.0-p353@twitchmech/gems/cinch-2.0.11/lib/cinch/handler.rb:86:in `block in call'
[2013/12/23 21:05:18.633] !! [Thread done] For #<Cinch::Handler @event=:message pattern=#<Cinch::Pattern:0x007fded9872ed0 @prefix=/^/, @pattern=/hello/, @suffix=/$/>>: #<Thread:0x007fded9064158> -- 0 remaining.

Running ruby v2.0.0.-p353 and the following gemset:

bigdecimal (1.2.0)
bundler (1.3.5)
bundler-unload (1.0.2)
cinch (2.0.11)
coderay (1.1.0)
executable-hooks (1.2.6)
io-console (0.4.2)
json (1.7.7)
method_source (0.8.2)
minitest (4.3.2)
pry (0.9.12.4)
psych (2.0.0)
rake (0.9.6)
rdoc (4.0.0)
rubygems-bundler (1.4.2)
rvm (1.11.3.8)
slop (3.4.7)
test-unit (2.0.0.0)

Any thoughts? I have zero experience with Ruby threading, though it seems like there is a problem establishing a lock on user? Help!

dominikh commented 10 years ago

:tmi.twitch.tv 421 peebznationbot WHOIS :Unknown command

Run it on an actual IRC server, not something that pretends to be but fails horribly.

lpeabody commented 10 years ago

That's very helpful, thank you.

mikbe commented 10 years ago

Yep, this is a bug and it still doesn't work with Twitch.

dominikh commented 10 years ago

Twitch doesn't run an actual IRC server, as it doesn't implement the specification. Cinch only supports actual IRC servers, not things that implement a subset of the protocol.

blutorange commented 10 years ago

I came across the same issue, and it seems to be related to how twitch handles incoming messages. While it is true cinch does not have to support non-IRC servers, it is nice when we can reuse an existing framework. Here's a quick work-around that allows me to send messages to twitch. Basically, it circumvents all and every checks and pre-processing cinch does, make sure you know what you are doing when using this. Add the following lines to your file:

class Cinch::Message
    def twitch(string)
        string = string.to_s.gsub('<','&lt;').gsub('>','&gt;')
        bot.irc.send ":#{bot.config.user}!#{bot.config.user}@#{bot.config.user}.tmi.twitch.tv PRIVMSG #{channel} :#{string}"
    end
end

And use m.twitch instead of m.reply. You should also give your password with c.password='oauth:XXXXXXXX', where oauth is your twitch oauth pass. You can get it here: http://www.twitchapps.com/tmi/ Also, the channel must be all lowercase. Even a twitch channel called 360Chrism will only work if you change that to 360chrism.

Note that this will transmit the message as is - it will neither split it on linebreaks (use string.split(/\r\n|\r|\n/).each do |line| ; <...> ; end), and it will not check if it is too long (max is 510 bytes total, ie what gets passed to Cinch::IRC#send), nor does it take care of the encoding issues or color codes. Check out the source code at http://rubydoc.info/gems/cinch/Cinch/Channel#msg-instance_method and http://rubydoc.info/gems/cinch/Cinch/Target#msg-instance_method , it implements the above-mentioned.

MelonSmasher commented 10 years ago

@blutorange Thanks for the patch, it works like a charm.

SkylerLipthay commented 10 years ago

@blutorange You are a hero in my eyes.

thisusernameistaken commented 10 years ago

Thanks @blutorange this work nicely!