Class: IRC::StatefulChannel
- Inherits:
-
Object
- Object
- IRC::StatefulChannel
- Defined in:
- lib/rhuidean/stateful_channel.rb
Overview
Represents a channel on IRC.
Constant Summary collapse
- STATUS_MODES =
{ 'o' => :oper, 'v' => :voice }
- LIST_MODES =
{ 'b' => :ban, 'e' => :except, 'I' => :invex }
- PARAM_MODES =
{ 'l' => :limited, 'k' => :keyed }
- BOOL_MODES =
{ 'i' => :invite_only, 'm' => :moderated, 'n' => :no_external, 'p' => :private, 's' => :secret, 't' => :topic_lock }
Instance Attribute Summary collapse
-
#modes ⇒ Object
readonly
instance attributes.
-
#name ⇒ Object
readonly
instance attributes.
-
#users ⇒ Object
readonly
instance attributes.
Instance Method Summary collapse
-
#add_user(user) ⇒ Object
Add a user to our userlist.
-
#delete_user(user) ⇒ Object
Remove a user from our userlist.
-
#initialize(name, client) ⇒ StatefulChannel
constructor
Creates a new
StatefulChannel. -
#parse_modes(m, modes, params) ⇒ Object
Parse a mode string.
-
#to_s ⇒ Object
Represent ourselves in a string.
Constructor Details
#initialize(name, client) ⇒ StatefulChannel
Creates a new StatefulChannel. The channel has an EventQueue, but it really points to the EventQueue of the StatefulClient that created it. This kind of breaks OOP, but it allows the Channel to post relevant events back to the client, like mode changes.
- name
-
the name of the channel
- client
-
the
IRC::Clientthat sees us - returns
-
self
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/rhuidean/stateful_channel.rb', line 33 def initialize(name, client) # The Client we belong to @client = client # The channel's key @key = nil # The channel's user limit @limit = 0 # The channel's modes @modes = [] # The name of the channel, including the prefix @name = name # The list of StatefulUsers on the channel keyed by nickname @users = IRCHash.new(@client.casemapping) end |
Instance Attribute Details
#modes ⇒ Object (readonly)
instance attributes
20 21 22 |
# File 'lib/rhuidean/stateful_channel.rb', line 20 def modes @modes end |
#name ⇒ Object (readonly)
instance attributes
20 21 22 |
# File 'lib/rhuidean/stateful_channel.rb', line 20 def name @name end |
#users ⇒ Object (readonly)
instance attributes
20 21 22 |
# File 'lib/rhuidean/stateful_channel.rb', line 20 def users @users end |
Instance Method Details
#add_user(user) ⇒ Object
Add a user to our userlist. This also adds us to the user’s channel list.
- user
-
the
StatefulUserto add - returns
-
self
73 74 75 76 77 78 |
# File 'lib/rhuidean/stateful_channel.rb', line 73 def add_user(user) @users[user.nickname] = user user.join_channel(self) self end |
#delete_user(user) ⇒ Object
Remove a user from our userlist. This also removes us from the user’s channel list.
- user
-
a
StatefulUseror the name of one - returns
-
self(nil on catastrophic failure)
87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/rhuidean/stateful_channel.rb', line 87 def delete_user(user) if user.class == String @users[user].part_channel(self) @users.delete(user) self elsif user.class == StatefulUser user.part_channel(self) @users.delete(user.nickname) self else nil end end |
#parse_modes(m, modes, params) ⇒ Object
Parse a mode string. Update channel state for modes we know, and fire off events.
- m
-
the IRC::Message object
- modes
-
the mode string
- params
-
an array of the params tokenized by space
- returns
-
nothing of consequence…
129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/rhuidean/stateful_channel.rb', line 129 def parse_modes(m, modes, params) mode = nil # :add or :del modes.each_char do |c| flag, param = nil if c == '+' mode = :add next elsif c == '-' mode = :del next end # Status modes if STATUS_MODES.include?(c) flag = STATUS_MODES[c] param = params.shift # Status modes from RPL_ISUPPORT elsif @client.status_modes.keys.include?(c) flag = c.to_sym param = params.shift # List modes elsif LIST_MODES.include?(c) flag = LIST_MODES[c] param = params.shift # List modes from RPL_ISUPPORT elsif @client.channel_modes[:list].include?(c) flag = c.to_sym param = params.shift # Always has a param (some send the key, some send '*') elsif c == 'k' flag = :keyed param = params.shift @key = mode == :add ? param : nil # Has a param when +, doesn't when - elsif c == 'l' flag = :limited param = params.shift if mode == :add @limit = mode == :add ? param : 0 # Always has a param from RPL_ISUPPORT elsif @client.channel_modes[:always].include?(c) flag = c.to_sym param = params.shift # Has a parm when +, doesn't when - from RPL_ISUPPORT elsif @client.channel_modes[:set].include?(c) flag = c.to_sym param = params.shift if mode == :add # The rest, no param elsif BOOL_MODES.include?(c) flag = BOOL_MODES[c] # The rest, no param from RPL_ISUPPORT elsif @client.channel_modes[:bool].include?(c) flag = c.to_sym end # Add non-status and non-list modes to the channel's modes unless junk_cmode?(c) if mode == :add @modes << flag else @modes.delete(flag) end end # Update status modes for users if status_mode?(c) if mode == :add @users[param].add_status_mode(flag, self) elsif mode == :del @users[param].delete_status_mode(flag, self) end end # And send out events for everything event = "mode_#{flag.to_s}".to_sym @client.eventq.post(event, m, mode, param) end end |
#to_s ⇒ Object
Represent ourselves in a string.
- returns
-
our name
62 63 64 |
# File 'lib/rhuidean/stateful_channel.rb', line 62 def to_s @name end |