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.



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

#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
# File 'lib/ircbot/plugin.rb', line 22

def self.command?(name)
  !! commands[name.to_s]
end

.commandsObject



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

#[](key) ⇒ Object



46
47
48
# File 'lib/ircbot/plugin.rb', line 46

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

#argObject



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

#commandObject



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

Messages

Returns:

  • (Boolean)


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

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

#done(text = nil) ⇒ Object

Operations



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

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

#helpObject



73
74
75
# File 'lib/ircbot/plugin.rb', line 73

def help
  self[:help] || "commands: %s" % self.class.commands.keys.sort.join(",")
end

#inspectObject



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

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

#me?Boolean

Returns:

  • (Boolean)


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

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

#nickObject



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

def nick
  message.prefix.nick
end

#setupObject



37
38
# File 'lib/ircbot/plugin.rb', line 37

def setup
end

#to_sObject



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

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