Class: Erasmus::Channel
- Inherits:
-
Object
- Object
- Erasmus::Channel
- Defined in:
- lib/erasmus.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#server ⇒ Object
Returns the value of attribute server.
Instance Method Summary collapse
- #allowed?(user) ⇒ Boolean
- #handle_flag(user, host, flag, arguments, source) ⇒ Object
- #handle_public_message(user, host, message) ⇒ Object
- #hilight_user(user, message) ⇒ Object
-
#initialize(channel, flag = '!') ⇒ Channel
constructor
A new instance of Channel.
- #join ⇒ Object
- #notice_channel(message) ⇒ Object
- #notice_user(user, message) ⇒ Object
- #part(message = 'Bai~') ⇒ Object
- #say(message) ⇒ Object
- #whois(user) ⇒ Object
Constructor Details
#initialize(channel, flag = '!') ⇒ Channel
Returns a new instance of Channel.
109 110 111 112 113 114 115 |
# File 'lib/erasmus.rb', line 109 def initialize(channel, flag='!') @name = channel @flag = flag @flags = {} @blacklists = [] end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
107 108 109 |
# File 'lib/erasmus.rb', line 107 def name @name end |
#server ⇒ Object
Returns the value of attribute server.
106 107 108 |
# File 'lib/erasmus.rb', line 106 def server @server end |
Instance Method Details
#allowed?(user) ⇒ Boolean
167 168 169 170 171 172 173 174 175 176 177 178 179 180 |
# File 'lib/erasmus.rb', line 167 def allowed?(user) begin @blacklists.each do |blacklist| blacklist.call(user) end rescue NotAllowedException return false rescue => detail say("Uh oh: #{detail}") return false else return true end end |
#handle_flag(user, host, flag, arguments, source) ⇒ Object
157 158 159 160 161 162 163 164 165 |
# File 'lib/erasmus.rb', line 157 def handle_flag(user, host, flag, arguments, source) if allowed? user begin @flags[flag].call(user, host, arguments, source) rescue NoMethodError #say("Sorry, there's no action associated with the flag #{flag}.") end end end |
#handle_public_message(user, host, message) ⇒ Object
145 146 147 148 149 150 151 152 153 154 155 |
# File 'lib/erasmus.rb', line 145 def (user, host, ) if =~ /^#{@server.nick}: (\S+)\s(.*)$/ command = $1 arguments = $2.split(/\s/) handle_flag(user, host, command, arguments, :hilight) elsif =~ /^#{@flag}(\S+)\s(.*)$/ command = $1 arguments = $2.split(/\s/) handle_flag(user, host, command, arguments, :flag) end end |
#hilight_user(user, message) ⇒ Object
129 130 131 |
# File 'lib/erasmus.rb', line 129 def hilight_user(user, ) @server.say_to_channel(@name, "#{user}: #{}") end |
#join ⇒ Object
117 118 119 |
# File 'lib/erasmus.rb', line 117 def join @server.say "JOIN ##{@name}" end |
#notice_channel(message) ⇒ Object
137 138 139 |
# File 'lib/erasmus.rb', line 137 def notice_channel() @server.notice_channel(@name, ) end |
#notice_user(user, message) ⇒ Object
133 134 135 |
# File 'lib/erasmus.rb', line 133 def notice_user(user, ) @server.notice_user(user, ) end |
#part(message = 'Bai~') ⇒ Object
121 122 123 |
# File 'lib/erasmus.rb', line 121 def part(='Bai~') @server.say "PART ##{@name} :#{}" end |
#say(message) ⇒ Object
125 126 127 |
# File 'lib/erasmus.rb', line 125 def say() @server.say_to_channel(@name, ) end |
#whois(user) ⇒ Object
141 142 143 |
# File 'lib/erasmus.rb', line 141 def whois(user) @server.whois(user) end |