/
client.rb
85 lines (68 loc) · 1.95 KB
/
client.rb
1
2
3
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#--
# Copyleft meh. [http://meh.paranoid.pk | meh@paranoici.org]
#
# This file is part of failirc.
#
# failirc is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published
# by the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# failirc is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with failirc. If not, see <http://www.gnu.org/licenses/>.
#++
require 'failirc/version'
require 'failirc/common/utils'
require 'failirc/common/events'
require 'failirc/common/modules'
require 'failirc/common/modes'
require 'failirc/common/mask'
require 'failirc/client/dispatcher'
module IRC
class Client
extend Forwardable
attr_reader :options, :dispatcher, :created_on
def_delegators :@dispatcher, :connect, :running?
def_delegators :@events, :register, :dispatch, :observe, :fire, :hook
def_delegators :@pool, :do
def_delegators :@modules, :load
def initialize (options={})
@options = HashWithIndifferentAccess.new(options)
@dispatcher = Dispatcher.new(self)
@events = Events.new(self)
@pool = ThreadPool.new
@modules = Modules.new(self, '/failirc/client/modules')
if @options[:modules]
@options[:modules].each {|name, data|
begin
mod = @modules.load(name, data)
if mod
mod.define_singleton_method :client do
self
end
hook mod
IRC.debug "#{name} loaded"
else
IRC.debug "#{name} had some errors"
end
rescue LoadError
IRC.debug "#{name} not found"
end
}
end
end
def start
fire :start, self
@dispatcher.start
end
def stop
fire :stop, self
@dispatcher.stop
end
end
end