Sha256: a64bd27cb6eca1ff9df67bdd96f963135b4a694d70465bd73c7fc4d1f1b65b0d
Contents?: true
Size: 1.63 KB
Versions: 2
Compression:
Stored size: 1.63 KB
Contents
# Where should we go to lunch today? class Robut::Plugin::Lunch < Robut::Plugin::Base # Replies with a random string selected from +places+. def handle(time, sender_nick, message) words = words(message) 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?(message) 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 lunch place (.*)/i && sent_to_me?(message) place = $1 new_place(place) reply "Ok, I'll add \"#{place}\" to the the list of lunch places" # @robut remove luynch place Green Leaf elsif phrase =~ /remove lunch place (.*)/i && sent_to_me?(message) place = $1 remove_place(place) reply "I removed \"#{place}\" from the list of lunch places" end end # Stores +place+ as a new lunch place. def new_place(place) store["lunch_places"] ||= [] store["lunch_places"] = (store["lunch_places"] + Array(place)).uniq end # Removes +place+ from the list of lunch places. def remove_place(place) store["lunch_places"] ||= [] store["lunch_places"] = store["lunch_places"] - Array(place) end # Returns the list of lunch places we know about. def places store["lunch_places"] ||= [] end # Sets the list of lunch places to +v+ def places=(v) store["lunch_places"] = v end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
robut-0.2.1 | lib/robut/plugin/lunch.rb |
robut-0.2.0 | lib/robut/plugin/lunch.rb |