Class: Balotelli::Base
Constant Summary
Core::Router::RouteCollisionError
Class Method Summary
collapse
Instance Method Summary
collapse
match, match?, on, setup_router
Methods included from Core::IRC
configure, connect, join, names, pong, privmsg, sgets, sputs
class_variable_get
Constructor Details
#initialize(block, message, matchdata) ⇒ Base
18
19
20
21
22
|
# File 'lib/balotelli/base.rb', line 18
def initialize(block, message, matchdata)
@message = message
@block = block
@matchdata = matchdata
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, **params, &block) ⇒ Object
57
58
59
60
61
62
63
|
# File 'lib/balotelli/base.rb', line 57
def method_missing(method, *args, **params, &block)
if method =~ /__([[[:upper:]]_]+)__/
self.class.instance_variable_get("@#{Regexp.last_match(1)}".downcase)
else
super
end
end
|
Class Method Details
.inherited(subclass) ⇒ Object
78
79
80
81
82
|
# File 'lib/balotelli/base.rb', line 78
def inherited(subclass)
super
subclass.setup
end
|
.mod_match(str, priv = false) ⇒ Object
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
# File 'lib/balotelli/base.rb', line 99
def mod_match(str, priv = false)
if str =~ /\A[^a-zA-Z0-9\s]?(\S+) ?(.*)/
if (mod = @cache[:modules][Regexp.last_match(1).downcase])
mod.match(Regexp.last_match(2), priv)
end
elsif str == :join
match = nil
@modules.each do |_, m|
if (match = m.match(:join))
break(match)
end
end
match
end
end
|
.register(mod, namespace = nil) ⇒ Object
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/balotelli/base.rb', line 84
def register(mod, namespace = nil)
if namespace
mod.instance_variable_set(:@commands_namespace, namespace.intern)
mod.instance_exec(namespace) do |n|
define_method(:commands_namespace) { n.intern }
end
end
@modules[mod.commands_namespace] ||= mod
@cache[:modules] = Hash[@modules.map { |k, v| [k.to_s, v] }]
end
|
.register_special(mod) ⇒ Object
95
96
97
|
# File 'lib/balotelli/base.rb', line 95
def register_special(mod)
@routes.merge!(mod.instance_variable_get(:@routes))
end
|
.run ⇒ Object
115
116
117
118
119
|
# File 'lib/balotelli/base.rb', line 115
def run
while (str = sgets)
process(str)
end
end
|
.setup ⇒ Object
69
70
71
72
73
74
75
76
|
# File 'lib/balotelli/base.rb', line 69
def setup
setup_router
@pool = Thread::Pool.new(Thread::Pool.cpu_count)
@modules = {}
@cache = Hash.new { |hash, key| hash[key] = {} }
@cvs = {}
end
|
Instance Method Details
#execute! ⇒ Object
Also known as:
execute
24
25
26
|
# File 'lib/balotelli/base.rb', line 24
def execute!
instance_exec(@message, @matchdata, &@block)
end
|
#get_user_list(channel) ⇒ Object
38
39
40
41
42
43
|
# File 'lib/balotelli/base.rb', line 38
def get_user_list(channel)
execute_in_mutex(channel) do
self.class.names(channel)
end
cache[:user_list][channel]
end
|
#kick(params) ⇒ Object
34
35
36
|
# File 'lib/balotelli/base.rb', line 34
def kick(params)
Core::Kick.new(params, self.class).execute!
end
|
#out(message_string, destination = nil) ⇒ Object
30
31
32
|
# File 'lib/balotelli/base.rb', line 30
def out(message_string, destination = nil)
self.class.privmsg((destination || @message.responder), message_string)
end
|