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
- #choose_place(sender_nick) ⇒ Object
-
#handle(time, sender_nick, message) ⇒ Object
Replies with a random string selected from
places. -
#new_place(place) ⇒ Object
Stores
placeas 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
placefrom 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
#choose_place(sender_nick) ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/robut/plugin/lunch.rb', line 47 def choose_place(sender_nick) excluded = sender_nick =~ /\bchu\b/i ? /\bchu\b/i : nil # excluded = sender_nick =~ /\bclemmer\b/i ? /^[^g]/i : nil valid_places = places valid_places = places.reject { |p| p =~ excluded } unless excluded.nil? return valid_places[rand(valid_places.length)] end |
#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 45 |
# 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 $stderr.puts "*************************** -> #{sender_nick}" reply choose_place(sender_nick) + "!" 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.
56 57 58 59 |
# File 'lib/robut/plugin/lunch.rb', line 56 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.
68 69 70 |
# File 'lib/robut/plugin/lunch.rb', line 68 def places store["lunch_places"] ||= [] end |
#places=(v) ⇒ Object
Sets the list of lunch places to v
73 74 75 |
# File 'lib/robut/plugin/lunch.rb', line 73 def places=(v) store["lunch_places"] = v end |
#remove_place(place) ⇒ Object
Removes place from the list of lunch places.
62 63 64 65 |
# File 'lib/robut/plugin/lunch.rb', line 62 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 |