Module: Cinch::Plugin
- Includes:
- Helpers
- Defined in:
- lib/cinch/plugin.rb
Defined Under Namespace
Modules: ClassMethods
Instance Attribute Summary collapse
- #bot ⇒ Bot readonly
Class Method Summary collapse
Instance Method Summary collapse
-
#config ⇒ Hash
Provides access to plugin-specific options.
-
#execute(*args) ⇒ void
abstract
This method will be executed whenever a message matches the match pattern of the plugin.
- #initialize(bot) ⇒ Object private
-
#listen(*args) ⇒ void
abstract
This method will be executed whenever an event the plugin listens to occurs.
-
#synchronize(*args) { ... } ⇒ void
Since Cinch uses threads, all handlers can be run simultaneously, even the same handler multiple times.
Methods included from Helpers
Instance Attribute Details
Class Method Details
.included(by) ⇒ Object
301 302 303 |
# File 'lib/cinch/plugin.rb', line 301 def self.included(by) by.extend ClassMethods end |
Instance Method Details
#config ⇒ Hash
Provides access to plugin-specific options.
297 298 299 |
# File 'lib/cinch/plugin.rb', line 297 def config @bot.config.plugins.[self.class] || {} end |
#execute(*args) ⇒ void
This method returns an undefined value.
This method will be executed whenever a message matches the match pattern of the plugin.
291 292 |
# File 'lib/cinch/plugin.rb', line 291 def execute(*args) end |
#initialize(bot) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
266 267 268 269 |
# File 'lib/cinch/plugin.rb', line 266 def initialize(bot) @bot = bot self.class.__register_with_bot(bot, self) end |
#listen(*args) ⇒ void
This method returns an undefined value.
This method will be executed whenever an event the plugin listens to occurs.
282 283 |
# File 'lib/cinch/plugin.rb', line 282 def listen(*args) end |
#synchronize(*args) { ... } ⇒ void
This method returns an undefined value.
Since Cinch uses threads, all handlers can be run simultaneously, even the same handler multiple times. This also means, that your code has to be thread-safe. Most of the time, this is not a problem, but if you are accessing stored data, you will most likely have to synchronize access to it. Instead of managing all mutexes yourself, Cinch provides a synchronize method, which takes a name and block.
Synchronize blocks with the same name share the same mutex, which means that only one of them will be executed at a time.
272 273 274 |
# File 'lib/cinch/plugin.rb', line 272 def synchronize(*args, &block) @bot.synchronize(*args, &block) end |