Class: ModSpox::Plugin
- Inherits:
-
Object
- Object
- ModSpox::Plugin
- Includes:
- Models
- Defined in:
- lib/mod_spox/Plugin.rb
Instance Method Summary collapse
-
#add_sig(args) ⇒ Object
Adds a new signature for the given plugin Required args: :sig and :method Optional args: :group, :req, :desc, and :params.
-
#destroy ⇒ Object
Called before the object is destroyed by the ModSpox::PluginManager.
-
#error(to, message) ⇒ Object
- to
- Where message is going message
-
message Send an error message to target.
-
#information(to, message) ⇒ Object
- to
- Where message is going message
-
message Send an information message to target.
-
#initialize(args) ⇒ Plugin
constructor
A new instance of Plugin.
-
#me ⇒ Object
Returns the nick model of the bot.
-
#name ⇒ Object
Returns the name of the class.
-
#plugin_const(const) ⇒ Object
Returns constant given from plugin module.
-
#reply(target, message) ⇒ Object
- target
- target for message message
-
string message This is a helper method that will send an outgoing Privmsg to the given target.
-
#warning(to, message) ⇒ Object
- to
- Where message is going message
-
message Send an warning message to target.
Constructor Details
#initialize(args) ⇒ Plugin
Returns a new instance of Plugin.
7 8 9 10 11 12 |
# File 'lib/mod_spox/Plugin.rb', line 7 def initialize(args) @pipeline = args[:pipeline] @plugin_module = args[:plugin_module] raise Exceptions::BotException.new('Plugin creation failed to supply message pipeline') unless @pipeline.is_a?(Pipeline) @pipeline.hook_plugin(self) end |
Instance Method Details
#add_sig(args) ⇒ Object
Adds a new signature for the given plugin Required args: :sig and :method Optional args: :group, :req, :desc, and :params
64 65 66 67 68 69 70 71 72 |
# File 'lib/mod_spox/Plugin.rb', line 64 def add_sig(args) raise ModSpox::Exceptions::InvalidType.new('You must provide a hash for creating new signatures') unless args.is_a?(Hash) args[:params] = nil unless args[:params] sig = Signature.find_or_create(:signature => args[:sig], :plugin => name, :method => args[:method].to_s, :params => args[:params], :group_id => args[:group].nil? ? nil : args[:group].pk) sig.description = args[:desc] if args.has_key?(:desc) sig.requirement = args[:req] if args.has_key?(:req) sig.save end |
#destroy ⇒ Object
Called before the object is destroyed by the ModSpox::PluginManager
15 16 17 |
# File 'lib/mod_spox/Plugin.rb', line 15 def destroy Logger.info("Destroy method for plugin #{name} has not been defined.") end |
#error(to, message) ⇒ Object
- to
-
Where message is going
- message
-
message
Send an error message to target
91 92 93 |
# File 'lib/mod_spox/Plugin.rb', line 91 def error(to, ) reply to, "\2#{name} (error):\2 #{}" end |
#information(to, message) ⇒ Object
- to
-
Where message is going
- message
-
message
Send an information message to target
77 78 79 |
# File 'lib/mod_spox/Plugin.rb', line 77 def information(to, ) reply to, "\2#{name} (info):\2 #{}" end |
#me ⇒ Object
Returns the nick model of the bot
33 34 35 36 37 38 39 40 |
# File 'lib/mod_spox/Plugin.rb', line 33 def me nick = Models::Nick.filter(:botnick => true).first if(nick) return nick else raise Exception.new("Fatal Error: I don't know who I am.") end end |
#name ⇒ Object
Returns the name of the class
20 21 22 |
# File 'lib/mod_spox/Plugin.rb', line 20 def name self.class.name.to_s.gsub(/^.+:/, '') end |
#plugin_const(const) ⇒ Object
Returns constant given from plugin module. Raises ModSpox::Exceptions::InvalidType exception if constant is not found within the module Note: Use _ for depth (ie: Foo::Bar::Fee if Fee is wanted give: :Foo_Bar_Fee)
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/mod_spox/Plugin.rb', line 45 def plugin_const(const) klass = @plugin_module begin const.to_s.split('_').each do |part| klass = klass.const_get(part.to_sym) end rescue NameError => boom raise ModSpox::Exceptions::InvalidType.new("Requested constant has not been defined within the plugins module (#{const}): #{boom}") end if(klass.nil?) raise ModSpox::Exceptions::InvalidType.new("Requested constant has not been defined within the plugins module (#{const})") else return klass end end |
#reply(target, message) ⇒ Object
- target
-
target for message
- message
-
string message
This is a helper method that will send an outgoing Privmsg to the given target
28 29 30 |
# File 'lib/mod_spox/Plugin.rb', line 28 def reply(target, ) @pipeline << Messages::Outgoing::Privmsg.new(target, ) end |
#warning(to, message) ⇒ Object
- to
-
Where message is going
- message
-
message
Send an warning message to target
84 85 86 |
# File 'lib/mod_spox/Plugin.rb', line 84 def warning(to, ) reply to, "\2#{name} (warn):\2 #{}" end |