Class: Ircbot::Plugin

Inherits:
Object show all
Defined in:
lib/ircbot/plugin.rb

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.



27
28
29
30
31
32
# File 'lib/ircbot/plugin.rb', line 27

def initialize(plugins = nil)
  @plugins = plugins || Plugins.new
  @message = InitialMessage.new(self.class.name)
  @running = false
  @attrs   = Mash.new
end

Instance Attribute Details

#messageObject

Returns the value of attribute message.



17
18
19
# File 'lib/ircbot/plugin.rb', line 17

def message
  @message
end

#plugin_nameObject

Returns the value of attribute plugin_name.



20
21
22
# File 'lib/ircbot/plugin.rb', line 20

def plugin_name
  @plugin_name
end

#pluginsObject

Returns the value of attribute plugins.



18
19
20
# File 'lib/ircbot/plugin.rb', line 18

def plugins
  @plugins
end

#runningObject

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

Returns:

  • (Boolean)


22
23
24
25
# File 'lib/ircbot/plugin.rb', line 22

def self.command?(name)
  @commands ||= (public_instance_methods - Plugin.public_instance_methods).inject({"setup"=>1, "help"=>1}) {|h,k| h[k.to_s] = 1; h }
  !! @commands[name.to_s]
end

Instance Method Details

#[](key) ⇒ Object



43
44
45
# File 'lib/ircbot/plugin.rb', line 43

def [](key)
  @attrs[key]
end

#argObject



93
94
95
# File 'lib/ircbot/plugin.rb', line 93

def arg
  (message.message =~ /\A#{config.nick}\./) ? (a = $'.to_s.strip.split; a.shift; a.join) : ''
end

#attrs=(hash) ⇒ Object



59
60
61
# File 'lib/ircbot/plugin.rb', line 59

def attrs=(hash)
  @attrs = Mash.new(hash)
end

#commandObject



89
90
91
# File 'lib/ircbot/plugin.rb', line 89

def command
  (message.message =~ /\A#{config.nick}\./) ? $'.to_s.strip.split.first.to_s : ''
end

#direct?Boolean

Messages

Returns:

  • (Boolean)


77
78
79
# File 'lib/ircbot/plugin.rb', line 77

def direct?
  message.channel == config.nick
end

#done(text = nil) ⇒ Object

Operations



66
67
68
# File 'lib/ircbot/plugin.rb', line 66

def done(text = nil)
  throw :done, text
end

#helpObject



70
71
72
# File 'lib/ircbot/plugin.rb', line 70

def help
  raise "no helps for #{plugin_name}"
end

#inspectObject



51
52
53
# File 'lib/ircbot/plugin.rb', line 51

def inspect
  "<%sPlugin: %s>" % [running ? '*' : '', plugin_name]
end

#me?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/ircbot/plugin.rb', line 81

def me?
  !! (message.message =~ /\A#{config.nick}\./)
end

#nickObject



85
86
87
# File 'lib/ircbot/plugin.rb', line 85

def nick
  message.prefix.nick
end

#setupObject



34
35
# File 'lib/ircbot/plugin.rb', line 34

def setup
end

#to_sObject



55
56
57
# File 'lib/ircbot/plugin.rb', line 55

def to_s
  "%s%s" % [running ? '*' : '', plugin_name]
end