Class: Ircbot::Plugin
Defined Under Namespace
Classes: InitialMessage, Null
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(plugins = nil) ⇒ Plugin
Returns a new instance of Plugin.
30
31
32
33
34
35
|
# File 'lib/ircbot/plugin.rb', line 30
def initialize(plugins = nil)
@plugins = plugins || Plugins.new
@message = InitialMessage.new(self.class.name)
@running = false
@attrs = Mash.new
end
|
Instance Attribute Details
Returns the value of attribute message.
17
18
19
|
# File 'lib/ircbot/plugin.rb', line 17
def message
@message
end
|
#plugin_name ⇒ Object
Returns the value of attribute plugin_name.
20
21
22
|
# File 'lib/ircbot/plugin.rb', line 20
def plugin_name
@plugin_name
end
|
Returns the value of attribute plugins.
18
19
20
|
# File 'lib/ircbot/plugin.rb', line 18
def plugins
@plugins
end
|
Returns the value of attribute running.
19
20
21
|
# File 'lib/ircbot/plugin.rb', line 19
def running
@running
end
|
Class Method Details
.command?(name) ⇒ Boolean
22
23
24
|
# File 'lib/ircbot/plugin.rb', line 22
def self.command?(name)
!! commands[name.to_s]
end
|
26
27
28
|
# File 'lib/ircbot/plugin.rb', line 26
def self.commands
@commands ||= (public_instance_methods - Plugin.public_instance_methods + %w(help) - %w(reply)).inject({}) {|h,k| h[k.to_s] = 1; h }
end
|
Instance Method Details
46
47
48
|
# File 'lib/ircbot/plugin.rb', line 46
def [](key)
@attrs[key]
end
|
96
97
98
|
# File 'lib/ircbot/plugin.rb', line 96
def arg
(message.message =~ /\A#{config.nick}\./) ? (a = $'.to_s.strip.split; a.shift; a.join) : ''
end
|
#attrs=(hash) ⇒ Object
62
63
64
|
# File 'lib/ircbot/plugin.rb', line 62
def attrs=(hash)
@attrs = Mash.new(hash)
end
|
92
93
94
|
# File 'lib/ircbot/plugin.rb', line 92
def command
(message.message =~ /\A#{config.nick}\./) ? $'.to_s.strip.split.first.to_s : ''
end
|
#direct? ⇒ Boolean
80
81
82
|
# File 'lib/ircbot/plugin.rb', line 80
def direct?
message.channel == config.nick
end
|
#done(text = nil) ⇒ Object
69
70
71
|
# File 'lib/ircbot/plugin.rb', line 69
def done(text = nil)
throw :done, text
end
|
73
74
75
|
# File 'lib/ircbot/plugin.rb', line 73
def help
self[:help] || "commands: %s" % self.class.commands.keys.sort.join(",")
end
|
54
55
56
|
# File 'lib/ircbot/plugin.rb', line 54
def inspect
"<%sPlugin: %s>" % [running ? '*' : '', plugin_name]
end
|
#me? ⇒ Boolean
84
85
86
|
# File 'lib/ircbot/plugin.rb', line 84
def me?
!! (message.message =~ /\A#{config.nick}\./)
end
|
88
89
90
|
# File 'lib/ircbot/plugin.rb', line 88
def nick
message.prefix.nick
end
|
37
38
|
# File 'lib/ircbot/plugin.rb', line 37
def setup
end
|
58
59
60
|
# File 'lib/ircbot/plugin.rb', line 58
def to_s
"%s%s" % [running ? '*' : '', plugin_name]
end
|