class ProtonBot::Plugin
Plugin
object. Use it to alter bot's behavior @see www.rubydoc.info/gems/protonbot/file/plugin-demo.md @!attribute [r] name
@return [String] Plugin's name
@!attribute [r] version
@return [String] Plugin's version
@!attribute [r] description
@return [String] Plugin's description
@!attribute [r] name
@return [String] Plugin's name
@!attribute [r] hooks
@return [Array<Hook>] Plugin's hooks
@!attribute [rw] bot
@return [Bot] Bot
@!attribute [rw] Log
@return [LogWrapper] Log
@!attribute [rw] path
@return [String] Path
@!attribute [rw] core
@return [Plugin] Core plugin
Attributes
Public Class Methods
@param block [Proc]
# File lib/protonbot/plugin.rb, line 26 def initialize(&block) @hooks = [] @block = block @numeric = ProtonBot::Numeric end
Public Instance Methods
Shortcut for `hook(type: :command, …) {}` @param pattern [Hash<Symbol>] @param block [Proc] @return [Hook] hook
# File lib/protonbot/plugin.rb, line 59 def cmd(pattern = {}, &block) hook(pattern.merge(type: :command), &block) end
Emits passed event @param dat [Hash<Symbol>]
# File lib/protonbot/plugin.rb, line 65 def emit(dat = {}) dat[:plug].emit(dat) if dat[:plug] end
Emits passed event in other thread @param dat [Hash<Symbol>]
# File lib/protonbot/plugin.rb, line 71 def emitt(dat = {}) dat[:plug].emitt(dat) if dat[:plug] end
Shortcut for `define_singleton_method(…)` @param name [String,Symbol] @param block [Proc]
# File lib/protonbot/plugin.rb, line 91 def fun(name, &block) define_singleton_method(name, &block) end
Creates hook and returns it @param pattern [Hash<Symbol>] @param block [Proc] @return [Hook] hook
# File lib/protonbot/plugin.rb, line 49 def hook(pattern = {}, &block) h = ProtonBot::Hook.new(pattern, &block) @hooks << h h end
@return [String] Output
# File lib/protonbot/plugin.rb, line 96 def inspect %(<#ProtonBot::Plugin:#{object_id.to_s(16)} @name=#{name} @version=#{version}>) end
Starts plugin @return [Plugin] self
# File lib/protonbot/plugin.rb, line 34 def launch @plugins = @bot.plugins instance_exec(&@block) raise ProtonBot::PluginError, 'Plugin-name is not set!' unless @name raise ProtonBot::PluginError, 'Plugin-description is not set!' unless @description raise ProtonBot::PluginError, 'Plugin-description is not set!' unless @description end
Runs given file (.rb is appended automatically) @param fname [String]
# File lib/protonbot/plugin.rb, line 77 def run(fname) if @name == 'Core' instance_eval File.read("#{Gem.loaded_specs['protonbot'].lib_dirs_glob}/" \ "protonbot/core_plugin/#{fname}.rb"), "#{name}/#{fname}.rb" else instance_exec do instance_eval File.read(File.expand_path("#{path}/#{fname}.rb")), "#{name}/#{fname}.rb" end end end