Class: Qbot::Base
- Inherits:
-
Object
- Object
- Qbot::Base
- Defined in:
- lib/qbot/base.rb
Class Method Summary collapse
Instance Method Summary collapse
- #cache ⇒ Object
- #call(message) ⇒ Object
-
#initialize(pattern, &block) ⇒ Base
constructor
A new instance of Base.
- #post(text, **options) ⇒ Object
Constructor Details
#initialize(pattern, &block) ⇒ Base
Returns a new instance of Base.
47 48 49 50 |
# File 'lib/qbot/base.rb', line 47 def initialize(pattern, &block) @pattern = pattern @callback = block end |
Class Method Details
.cron(pattern, &block) ⇒ Object
21 22 23 |
# File 'lib/qbot/base.rb', line 21 def cron(pattern, &block) schedule(pattern, &block) end |
.on(pattern, &block) ⇒ Object
16 17 18 19 |
# File 'lib/qbot/base.rb', line 16 def on(pattern, &block) pattern = Regexp.new(pattern.to_s) unless Regexp === pattern Qbot.app.add(new(pattern, &block)) end |
.usage(text) ⇒ Object
25 26 27 |
# File 'lib/qbot/base.rb', line 25 def usage(text) on(/^#{prefix}help\s+#{name.downcase}\b/) { post(text) } end |
Instance Method Details
#cache ⇒ Object
63 64 65 |
# File 'lib/qbot/base.rb', line 63 def cache Qbot.app.storage.namespace(self.class.name) end |
#call(message) ⇒ Object
52 53 54 55 56 57 |
# File 'lib/qbot/base.rb', line 52 def call() = return unless @pattern =~ .text.to_s.strip instance_exec($~, &@callback) end |
#post(text, **options) ⇒ Object
59 60 61 |
# File 'lib/qbot/base.rb', line 59 def post(text, **) Qbot.app.adapter.reply_to(, text, **) end |