class Synacrb::State
Public Class Methods
new()
click to toggle source
# File lib/synacrb/state.rb, line 3 def initialize @channels = {} @users = {} end
Public Instance Methods
channels()
click to toggle source
# File lib/synacrb/state.rb, line 7 def channels @channels end
get_private_channel(user)
click to toggle source
Search for a private channel with user
# File lib/synacrb/state.rb, line 33 def get_private_channel(user) @users.keys .map { |channel| @channels[channel] } .compact .find { |channel| channel.private } # the server doesn't send PMs you don't have access to end
get_recipient(channel)
click to toggle source
Search for the recipient in a private channel
# File lib/synacrb/state.rb, line 42 def get_recipient(channel) if channel.private return nil end get_recipient_unchecked channel.id end
get_recipient_unchecked(channel_id)
click to toggle source
Search for the recipient in a private channel. If the channel isn't private, it returns the first user it can find that has a special mode in that channel. So you should probably make sure it's private first.
# File lib/synacrb/state.rb, line 53 def get_recipient_unchecked(channel_id) @users.values .find { |user| user.modes.keys .any { |channel| channel == channel_id }} end
update(packet)
click to toggle source
# File lib/synacrb/state.rb, line 13 def update(packet) if packet.instance_of? Common::ChannelDeleteReceive unless packet.inner.instance_of? Common::Channel packet.inner = Common::Channel.new(*packet.inner) end @channels.delete packet.inner.id elsif packet.instance_of? Common::ChannelReceive unless packet.inner.instance_of? Common::Channel packet.inner = Common::Channel.new(*packet.inner) end @channels[packet.inner.id] = packet.inner elsif packet.instance_of? Common::UserReceive unless packet.inner.instance_of? Common::User packet.inner = Common::User.new(*packet.inner) end @users[packet.inner.id] = packet.inner end end
users()
click to toggle source
# File lib/synacrb/state.rb, line 10 def users @users end