Class: CrazyDoll::Plugin
- Inherits:
-
Object
show all
- Includes:
- Net::IRC::Constants
- Defined in:
- lib/crazy_doll/plugin_manager.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(manager, config) ⇒ Plugin
Returns a new instance of Plugin.
152
153
154
155
156
157
158
159
160
161
162
|
# File 'lib/crazy_doll/plugin_manager.rb', line 152
def initialize(manager, config)
@manager = manager
@irc = manager.irc
@my_config = config.config_of self.class.to_s
@master_config = config.config_of 'Core'
@config = config
@opts, @line, @params = {}, '', {}
register_keys
register_events
init if respond_to?(:init)
end
|
Instance Attribute Details
#line ⇒ Object
Returns the value of attribute line.
150
151
152
|
# File 'lib/crazy_doll/plugin_manager.rb', line 150
def line
@line
end
|
#opts ⇒ Object
Returns the value of attribute opts.
150
151
152
|
# File 'lib/crazy_doll/plugin_manager.rb', line 150
def opts
@opts
end
|
#params ⇒ Object
Returns the value of attribute params.
151
152
153
|
# File 'lib/crazy_doll/plugin_manager.rb', line 151
def params
@params
end
|
Class Method Details
.config(&block) ⇒ Object
278
279
280
281
282
|
# File 'lib/crazy_doll/plugin_manager.rb', line 278
def config(&block)
@config ||= CrazyDoll::PluginManager::Config.new(self)
return @config unless block_given?
block.call(@config)
end
|
Instance Method Details
#c ⇒ Object
208
209
210
|
# File 'lib/crazy_doll/plugin_manager.rb', line 208
def c
@my_config
end
|
#config ⇒ Object
204
205
206
|
# File 'lib/crazy_doll/plugin_manager.rb', line 204
def config
@master_config
end
|
#current_channel ⇒ Object
223
224
225
226
227
228
229
230
231
|
# File 'lib/crazy_doll/plugin_manager.rb', line 223
def current_channel
if opts.respond_to?(:channel)
opts.channel
elsif opts.respond_to?(:to) and opts.to =~ /^#/
opts.to
else
raise ArgumentError, "opts don't respond to :channel and :to isn't a channel"
end
end
|
#current_nick ⇒ Object
212
213
214
|
# File 'lib/crazy_doll/plugin_manager.rb', line 212
def current_nick
config.nick.name
end
|
#custom_messages(prefix = '!', type = :priv) ⇒ Object
179
180
181
182
183
184
185
186
187
188
189
190
|
# File 'lib/crazy_doll/plugin_manager.rb', line 179
def custom_messages(prefix='!', type=:priv)
reg = Regexp.new("^#{prefix}")
return unless opts.message =~ reg
message = opts.message.gsub(reg, '')
for regexp, original_line, method, where in self.class.config.custom_messages
if where.include?(type) and message =~ regexp
@params = $~.to_crazy_doll_params(original_line)
send(method)
end
end
end
|
#custom_messages_chan ⇒ Object
192
193
194
|
# File 'lib/crazy_doll/plugin_manager.rb', line 192
def custom_messages_chan
custom_messages('!', :chan)
end
|
#custom_messages_priv ⇒ Object
196
197
198
|
# File 'lib/crazy_doll/plugin_manager.rb', line 196
def custom_messages_priv
custom_messages('', :priv)
end
|
#get(url) ⇒ Object
252
253
254
|
# File 'lib/crazy_doll/plugin_manager.rb', line 252
def get(url)
HTTParty.get(url)
end
|
#join(chan, pass = nil) ⇒ Object
233
234
235
|
# File 'lib/crazy_doll/plugin_manager.rb', line 233
def join(chan, pass=nil)
post JOIN, chan, pass
end
|
#parse_message(message) ⇒ Object
256
257
258
259
260
261
|
# File 'lib/crazy_doll/plugin_manager.rb', line 256
def parse_message(message)
message.
gsub('{{me}}', current_nick).
gsub('{{to}}', reply_to).
gsub('{{channel}}', reply_to_a_channel? ? current_channel : '')
end
|
#post(*args) ⇒ Object
200
201
202
|
# File 'lib/crazy_doll/plugin_manager.rb', line 200
def post(*args)
@irc.post(*args)
end
|
#register_events ⇒ Object
164
165
166
167
168
169
170
171
|
# File 'lib/crazy_doll/plugin_manager.rb', line 164
def register_events
for method in methods.grep(/^(sys|get|put)_/)
type, name = method.split('_', 2)
@manager.register(type, self, { :method_name => name, :real_method_name => method })
end
@manager.register(:get, self, { :method_name => :chanmsg, :real_method_name => :custom_messages_chan })
@manager.register(:get, self, { :method_name => :privmsg, :real_method_name => :custom_messages_priv })
end
|
#register_keys ⇒ Object
173
174
175
176
177
|
# File 'lib/crazy_doll/plugin_manager.rb', line 173
def register_keys
for key,opts in self.class.config.keys
c.register(self, key, opts[0], opts[1])
end
end
|
#reply(message, with_nick = true) ⇒ Object
241
242
243
244
245
246
247
248
249
250
|
# File 'lib/crazy_doll/plugin_manager.rb', line 241
def reply(message, with_nick=true)
message = parse_message(message)
case opts.command
when 'PRIVMSG' then say reply_to, message
when 'JOIN' then say current_channel, message
else
p opts
raise ArgumentError, "can't reply"
end
end
|
#reply_to ⇒ Object
216
217
218
219
220
221
|
# File 'lib/crazy_doll/plugin_manager.rb', line 216
def reply_to
case opts.command
when 'PRIVMSG' then opts.to.match(/^#/) ? opts.to : opts.from.nick
when 'JOIN' then opts.from.nick
end
end
|
#reply_to_a_channel? ⇒ Boolean
Also known as:
reply_to_a_channel
263
264
265
|
# File 'lib/crazy_doll/plugin_manager.rb', line 263
def reply_to_a_channel?
(reply_to || '') =~ /^#/
end
|
#say(to, message) ⇒ Object
237
238
239
|
# File 'lib/crazy_doll/plugin_manager.rb', line 237
def say(to, message)
post PRIVMSG, to, message
end
|
#talked_with_me? ⇒ Boolean
Also known as:
talked_with_me
269
270
271
272
|
# File 'lib/crazy_doll/plugin_manager.rb', line 269
def talked_with_me?
return false unless opts.message
opts.message.downcase.include?(current_nick.downcase)
end
|