Class: Robut::Plugin::Sayings
- Inherits:
-
Object
- Object
- Robut::Plugin::Sayings
- Includes:
- Robut::Plugin
- Defined in:
- lib/robut/plugin/sayings.rb
Overview
A simple regex => response plugin.
Class Attribute Summary collapse
-
.sayings ⇒ Object
A list of arrays.
Attributes included from Robut::Plugin
#connection, #private_sender, #reply_to
Instance Method Summary collapse
-
#handle(time, sender_nick, message) ⇒ Object
For each element in sayings, creates a regex out of the first element, tries to match
messageto it, and replies with the second element if it found a match. -
#usage ⇒ Object
Returns a description of how to use this plugin.
Methods included from Robut::Plugin
#at_nick, #fake_message, included, #initialize, #nick, #reply, #sent_to_me?, #store, #without_nick, #words
Class Attribute Details
.sayings ⇒ Object
A list of arrays. The first element is a regex, the second is the reply sent if the regex matches. After the first match, we don’t try to match any other sayings. Configuration looks like the following:
[["you're the worst", "I know."], ["sucks", "You know something, you suck!" ]]
All regex matches are case-insensitive.
13 14 15 |
# File 'lib/robut/plugin/sayings.rb', line 13 def @sayings end |
Instance Method Details
#handle(time, sender_nick, message) ⇒ Object
For each element in sayings, creates a regex out of the first element, tries to match message to it, and replies with the second element if it found a match. Robut::Plugin::Sayings will only respond once to each message, with the first match.
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/robut/plugin/sayings.rb', line 26 def handle(time, sender_nick, ) # Tries to respond to any message sent to robut. if sent_to_me?() self.class..each do || if words().join(' ').match(/#{.first}/i) reply(.last) return end end end end |
#usage ⇒ Object
Returns a description of how to use this plugin
18 19 20 |
# File 'lib/robut/plugin/sayings.rb', line 18 def usage "#{at_nick} <words> - if <words> matches a regular expression defined in the Chatfile, responds with the specified response" end |