Commit 931f5e2ca25a4aa8dc5f401085fc1e42aa55d227
- Diff rendering mode:
- inline
- side by side
IRC.rb
(9 / 5)
|   | |||
| 6 | 6 | require 'IRCUser' | |
| 7 | 7 | require 'IRCUtil' | |
| 8 | 8 | ||
| 9 | |||
| 10 | |||
| 11 | 9 | # Class IRC is a master class that handles connection to the irc | |
| 12 | 10 | # server and pasring of IRC events, through the IRCEvent class. | |
| 13 | 11 | class IRC | |
| … | … | ||
| 149 | 149 | IRCConnection.send_to_server("WHO #{user}") | |
| 150 | 150 | end | |
| 151 | 151 | private | |
| 152 | def thread_event (event) | ||
| 153 | @threads << Thread.new(event) {|localevent| | ||
| 154 | localevent.process | ||
| 152 | def thread_event(event) | ||
| 153 | @threads << Thread.new(event) { |localevent| | ||
| 154 | begin | ||
| 155 | localevent.process | ||
| 156 | rescue => e | ||
| 157 | puts "Error: #{e.message}" | ||
| 158 | puts e.backtrace.map { |e| " from #{e}\n" } | ||
| 159 | exit -1 | ||
| 160 | end | ||
| 155 | 161 | } | |
| 156 | 162 | end | |
| 157 | 163 | end |
IRCBot.rb
(4 / 1)
|   | |||
| 5 | 5 | def initialize(nick, server, port, realname='RBot') | |
| 6 | 6 | super | |
| 7 | 7 | ||
| 8 | IRCEvent.add_handler("unhandled", lambda { |event| __send__("on_#{event.type}".to_sym, event) } ) | ||
| 8 | IRCEvent.add_handler("unhandled", lambda { |event| | ||
| 9 | method_id = "on_#{event.type}".to_sym | ||
| 10 | __send__(method_id, event) if respond_to?(method_id) | ||
| 11 | }) | ||
| 9 | 12 | end | |
| 10 | 13 | end |

