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) ⇒ Object
- #handle_hilight(user, host, message) ⇒ 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
Constructor Details
#initialize(channel, flag = '!') ⇒ Channel
Returns a new instance of Channel.
90 91 92 93 94 95 96 |
# File 'lib/erasmus.rb', line 90 def initialize(channel, flag='!') @name = channel @flag = flag @flags = {} @blacklists = [] end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
88 89 90 |
# File 'lib/erasmus.rb', line 88 def name @name end |
#server ⇒ Object
Returns the value of attribute server.
87 88 89 |
# File 'lib/erasmus.rb', line 87 def server @server end |
Instance Method Details
#allowed?(user) ⇒ Boolean
144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/erasmus.rb', line 144 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) ⇒ Object
134 135 136 137 138 139 140 141 142 |
# File 'lib/erasmus.rb', line 134 def handle_flag(user, host, flag, arguments) if allowed? user begin @flags[flag].call(user, host, arguments) rescue NoMethodError #say("Sorry, there's no action associated with the flag #{flag}.") end end end |
#handle_hilight(user, host, message) ⇒ Object
132 133 |
# File 'lib/erasmus.rb', line 132 def handle_hilight(user, host, ) end |
#handle_public_message(user, host, message) ⇒ Object
122 123 124 125 126 127 128 129 130 |
# File 'lib/erasmus.rb', line 122 def (user, host, ) if =~ /^#{@server.nick}: (.*)$/ handle_hilight(user, host, $1) elsif =~ /^#{@flag}(\S+)\s(.*)$/ command = $1 arguments = $2.split(/\s/) handle_flag(user, host, command, arguments) end end |
#hilight_user(user, message) ⇒ Object
110 111 112 |
# File 'lib/erasmus.rb', line 110 def hilight_user(user, ) @server.say_to_channel(@name, "#{user}: #{}") end |
#join ⇒ Object
98 99 100 |
# File 'lib/erasmus.rb', line 98 def join @server.say "JOIN ##{@name}" end |
#notice_channel(message) ⇒ Object
118 119 120 |
# File 'lib/erasmus.rb', line 118 def notice_channel() @server.notice_channel(@name, ) end |
#notice_user(user, message) ⇒ Object
114 115 116 |
# File 'lib/erasmus.rb', line 114 def notice_user(user, ) @server.notice_user(user, ) end |
#part(message = 'Bai~') ⇒ Object
102 103 104 |
# File 'lib/erasmus.rb', line 102 def part(='Bai~') @server.say "PART ##{@name} :#{}" end |
#say(message) ⇒ Object
106 107 108 |
# File 'lib/erasmus.rb', line 106 def say() @server.say_to_channel(@name, ) end |