Module: Krtek::Irc::Responses
- Included in:
- Client
- Defined in:
- lib/krtek/responses.rb
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(base) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/krtek/responses.rb', line 4 def self.included(base) base.extend(ClassMethods) base.class_attribute :server_callbacks base.server_reply 'PRIVMSG' do |m| who = sender_nick(m[:prefix]) channel = m[:params].first = m[:params].slice(1..-1).join(' ').gsub(/^:/, '') trigger(:privmsg, who, channel, ) end base.server_reply '001', 'RPL_WELCOME' do |m| @nick = m[:params].first trigger(:nick, @nick) end base.server_reply 'PING' do |m| pong(m[:params].first) trigger(:ping, *m[:params]) end base.server_reply 'JOIN' do |m| trigger(:join, sender_nick(m[:prefix]), m[:params].first) end base.server_reply '433', 'ERR_NICKNAMEINUSE' do |m| @nick = nil end end |
Instance Method Details
#handle_parsed_message(m) ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/krtek/responses.rb', line 64 def (m) if handler = self.class.server_callbacks[m[:command]] instance_exec(m, &handler[:callback]) # error codes 400 to 599 trigger(:error, handler[:name]) if (m[:command].to_i / 100) > 3 else end end |
#parse_message(message) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/krtek/responses.rb', line 48 def () result = {} parts = .split(' ') result[:prefix] = parts.shift.gsub(/^:/, '') if parts[0] =~ /^:/ result[:command] = parts.shift result[:params] = parts.take_while { |e| e[0] != ':' } if result[:params].size < parts.size full_string = parts.slice(result[:params].size..-1).join(" ") full_string.gsub!(/^:/, '') result[:params] << full_string end result end |