cinchrb / cinch

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

idle method always return 0 #262

Closed noraj closed 5 years ago

noraj commented 5 years ago

m.user.idle is always equal to 0 for users even if I use bot.irc.send "WHOIS #{m.user.nick}" just before.

https://github.com/cinchrb/cinch/blob/c66bbe7805426ed0053d52550f134b0a66f42c93/lib/cinch/irc.rb#L666-L680

On the debug output of the bot I can see the logger is viewing 0.

But when I used the IRC command /WHOIS user I can see the idle time is not zero.

noraj commented 5 years ago

I tried using m.user.refresh

Queries the IRC server for information on the user. This will set the User’s state to not synced. After all information are received, the object will be set back to synced.

and also m.user.monitor

Starts monitoring a user’s online state by either using MONITOR or periodically running WHOIS.

before using m.user.idle but that's still returning zero.

dominikh commented 5 years ago

Are you trying to get the idle time of the bot, or a user who invoked a command? Naturally, neither will be idle. If the server reports the user as not idle there isn't much we can do about that.

noraj commented 5 years ago

After starting m.user.monitor, I see the idle value is increasing, but when using m.user.idle I get 0 So m.user.idle is resetting the idle time.

I know that on inspircd ircd, when a user is using /NOTICE this is resetting its idle time and also when someone is using /PING toward a target this is reseting the target iedle time.

noraj commented 5 years ago

Are you trying to get the idle time of the bot, or a user who invoked a command? Naturally, neither will be idle. If the server reports the user as not idle there isn't much we can do about that.

I'm trying to get the idle time of a user. The server don't report it as 0 because as I said using the /WHOIS on an IRC client report the correct idle time.

noraj commented 5 years ago

Is that not because when using #idle this is calling an underlying PING command toward the user? So this is resetting the user idle time (inspircd behavior).

dominikh commented 5 years ago

We're not PINGing the user.

noraj commented 5 years ago

It is very easy to reproduce.

Create a bot joining an inspircd server using this block:

  on :private, /^!test$/ do |m|
    m.reply m.user.idle.to_s
  end

Then send a private message !test to the bot, the user will always receive zero.

Then send /WHOIS username with the user all you'll get the right idle time.

PS : this is maybe doing this behavior with other ircd than inspircd.


Then you can also put m.user.monitor in another block, and then looking at the bot logger you'll see the idle time received from the whois increasing.

So this is not an inspircd issue but a cinch issue: #idle method is resetting the idle time of the targeted user.

dominikh commented 5 years ago

Of course the user will get a zero idle time. He literally just sent a message to the bot. He's not idle.

noraj commented 5 years ago

@dominikh I restarted the server and now and now it is behaving like you said: idle time is the because the user just sent a message. Of course I'm dumb. But that's weird that the WHOIS command was returning me an idle time of several minutes just after the user send a message, now I tried again and this is not doing it anymore.

noraj commented 5 years ago

@dominikh How can I get an synced version of idle instead of having the result of the last WHOIS? Do I need to call #refresh before?

dominikh commented 5 years ago

Do I need to call #refresh before?

Yes.