Class: Robut::Plugin::Lunch
- Inherits:
-
Object
- Object
- Robut::Plugin::Lunch
- Includes:
- Robut::Plugin
- Defined in:
- lib/robut/plugin/lunch.rb
Overview
Where should we go to lunch today?
Instance Attribute Summary
Attributes included from Robut::Plugin
#connection, #private_sender, #reply_to
Instance Method Summary collapse
-
#handle(time, sender_nick, message) ⇒ Object
Replies with a random string selected from
places
. -
#new_place(place) ⇒ Object
Stores
place
as a new lunch place. -
#places ⇒ Object
Returns the list of lunch places we know about.
-
#places=(v) ⇒ Object
Sets the list of lunch places to
v
. -
#remove_place(place) ⇒ Object
Removes
place
from the list of lunch places. -
#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
Instance Method Details
#handle(time, sender_nick, message) ⇒ Object
Replies with a random string selected from places
.
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/robut/plugin/lunch.rb', line 16 def handle(time, sender_nick, ) words = words() phrase = words.join(' ') # lunch? if phrase =~ /(lunch|food)\?/i if places.empty? reply "I don't know about any lunch places" else reply places[rand(places.length)] + "!" end # @robut lunch places elsif phrase == "lunch places" && sent_to_me?() if places.empty? reply "I don't know about any lunch places" else reply places.join(', ') end # @robut new lunch place Green Leaf elsif phrase =~ /(?:new|add) lunch place (.*)/i && sent_to_me?() place = $1 new_place(place) reply "Ok, I'll add \"#{place}\" to the the list of lunch places" # @robut remove lunch place Green Leaf elsif phrase =~ /remove lunch place (.*)/i && sent_to_me?() place = $1 remove_place(place) reply "I removed \"#{place}\" from the list of lunch places" end end |
#new_place(place) ⇒ Object
Stores place
as a new lunch place.
47 48 49 50 |
# File 'lib/robut/plugin/lunch.rb', line 47 def new_place(place) store["lunch_places"] ||= [] store["lunch_places"] = (store["lunch_places"] + Array(place)).uniq end |
#places ⇒ Object
Returns the list of lunch places we know about.
59 60 61 |
# File 'lib/robut/plugin/lunch.rb', line 59 def places store["lunch_places"] ||= [] end |
#places=(v) ⇒ Object
Sets the list of lunch places to v
64 65 66 |
# File 'lib/robut/plugin/lunch.rb', line 64 def places=(v) store["lunch_places"] = v end |
#remove_place(place) ⇒ Object
Removes place
from the list of lunch places.
53 54 55 56 |
# File 'lib/robut/plugin/lunch.rb', line 53 def remove_place(place) store["lunch_places"] ||= [] store["lunch_places"] = store["lunch_places"] - Array(place) end |
#usage ⇒ Object
Returns a description of how to use this plugin
6 7 8 9 10 11 12 13 |
# File 'lib/robut/plugin/lunch.rb', line 6 def usage [ "lunch? / food? - #{nick} will suggest a place to go eat", "#{at_nick} lunch places - lists all the lunch places #{nick} knows about", "#{at_nick} (add|new) lunch place <place> - tells #{nick} about a new place to eat", "#{at_nick} remove lunch place <place> - tells #{nick} not to suggest <place> anymore" ] end |