Class: IRC::Client

Inherits:
Object show all
Defined in:
lib/failirc/client.rb,
lib/failirc/client/user.rb,
lib/failirc/client/users.rb,
lib/failirc/client/client.rb,
lib/failirc/client/module.rb,
lib/failirc/client/server.rb,
lib/failirc/client/channel.rb,
lib/failirc/client/clients.rb,
lib/failirc/client/channels.rb,
lib/failirc/client/dispatcher.rb,
lib/failirc/client/modules/Base.rb,
lib/failirc/client/modules/Logger.rb,
lib/failirc/client/dispatcher/event.rb,
lib/failirc/client/dispatcher/eventdispatcher.rb,
lib/failirc/client/dispatcher/connectiondispatcher.rb

Defined Under Namespace

Modules: Modules Classes: Channel, Channels, Client, Clients, Dispatcher, Module, Server, User, Users

Constant Summary collapse

Event =
Dispatcher::Event

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(conf, verbose) ⇒ Client

Returns a new instance of Client.



39
40
41
42
43
44
45
46
47
48
# File 'lib/failirc/client.rb', line 39

def initialize (conf, verbose)
    @version = IRC::VERSION
    @verbose = verbose

    @modules = {}

    @dispatcher = Dispatcher.new self

    self.config = conf
end

Instance Attribute Details

#configObject

Returns the value of attribute config.



37
38
39
# File 'lib/failirc/client.rb', line 37

def config
  @config
end

#dispatcherObject (readonly)

Returns the value of attribute dispatcher.



37
38
39
# File 'lib/failirc/client.rb', line 37

def dispatcher
  @dispatcher
end

#modulesObject (readonly)

Returns the value of attribute modules.



37
38
39
# File 'lib/failirc/client.rb', line 37

def modules
  @modules
end

#verboseObject (readonly)

Returns the value of attribute verbose.



37
38
39
# File 'lib/failirc/client.rb', line 37

def verbose
  @verbose
end

#versionObject (readonly)

Returns the value of attribute version.



37
38
39
# File 'lib/failirc/client.rb', line 37

def version
  @version
end

Instance Method Details

#alias(*args) ⇒ Object



131
132
133
# File 'lib/failirc/client.rb', line 131

def alias (*args)
    dispatcher.alias(*args)
end

#connect(*args) ⇒ Object



119
120
121
# File 'lib/failirc/client.rb', line 119

def connect (*args)
    @dispatcher.connection.connect(*args)
end

#execute(*args) ⇒ Object



151
152
153
# File 'lib/failirc/client.rb', line 151

def execute (*args)
    @dispatcher.execute(*args)
end

#loadModule(name, path = nil, reload = false) ⇒ Object



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
# File 'lib/failirc/client.rb', line 50

def loadModule (name, path=nil, reload=false)
    if @modules[name] && !reload
        return
    end

    begin 
        if path[0] == '/'
            $LOAD_PATH.push path
            require name
            $LOAD_PATH.pop
        else
            require "#{path}/#{name}"
        end

        klass = eval("Modules::#{name}") rescue nil

        if klass
            @modules[name] = klass.new(self)
            self.debug "Loaded `#{name}`."
        else
            raise Exception
        end
    rescue Exception => e
        self.debug "Failed to load `#{name}`."
        self.debug e
    end
end

#nickObject



139
140
141
# File 'lib/failirc/client.rb', line 139

def nick
    @config.elements['config/informations/nick'].text
end

#realNameObject



147
148
149
# File 'lib/failirc/client.rb', line 147

def realName
    @config.elements['config/informations/realName'].text
end

#register(*args) ⇒ Object



135
136
137
# File 'lib/failirc/client.rb', line 135

def register (*args)
    dispatcher.register(*args)
end

#rehashObject



155
156
157
# File 'lib/failirc/client.rb', line 155

def rehash
    self.config = @configReference
end

#server(identifier) ⇒ Object



127
128
129
# File 'lib/failirc/client.rb', line 127

def server (identifier)
    dispatcher.server identifier
end

#serversObject



123
124
125
# File 'lib/failirc/client.rb', line 123

def servers
    dispatcher.servers[:byName]
end

#startObject



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/failirc/client.rb', line 78

def start
    if @started
        return
    end

    if !@config
        raise 'config is missing'
    end

    @started = true

    @config.elements.each('config/servers/server') {|element|
        self.connect({
            :host => element.attributes['host'],
            :port => element.attributes['port'],

            :ssl      => element.attributes['ssl'],
            :ssl_cert => element.attributes['sslCert'],
            :ssl_key  => element.attributes['sslKey']
        }, element)
    }

    @dispatcher.start
end

#stopObject



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/failirc/client.rb', line 103

def stop
    @stopping = true

    begin
        dispatcher.stop

        @modules.each {|mod|
            mod.finalize
        }
    rescue
    end

    @stopping = false
    @started  = false
end

#userObject



143
144
145
# File 'lib/failirc/client.rb', line 143

def user
    @config.elements['config/informations/user'].text
end