Sha256: ad281971b81d5fe281f21091ac86251c9116e9683203cc095afa54cbc9f80eea
Contents?: true
Size: 1.59 KB
Versions: 11
Compression:
Stored size: 1.59 KB
Contents
# Stores quotes and replies with a random stored quote. class Robut::Plugin::Quips include Robut::Plugin desc "add quip <text> - adds a quip to the quip database" match /^add quip (.+)/, :sent_to_me => true do |new_quip| if add_quip(new_quip) reply "I added the quip to the quip database" else reply "I didn't add the quip, since it was already added" end end desc "remove quip <text> - removes a quip from the quip database" match /^remove quip (.+)/, :sent_to_me => true do |quip| if remove_quip(quip) reply "I removed the quip from the quip database" else reply "I couldn't remove the quip, since it wasn't in the quip database" end end desc "quip - returns a random quip" match /^quip$/, :sent_to_me => true do quip = random_quip if quip reply quip else reply "I don't know any quips" end end # The list of quips stored in the quip database def quips # I'd love to use a set here, but it doesn't serialize right to yaml store["quips"] ||= [] end # Update the list of quips stored in the quip database def quips=(new_quips) # I'd love to use a set here, but it doesn't serialize right to yaml store["quips"] = new_quips end # Adds +quip+ to the quip database def add_quip(quip) self.quips = (quips + Array(quip)) unless quips.include?(quip) end # Removes +quip+ from the quip database def remove_quip(quip) self.quips = (quips - Array(quip)) if quips.include?(quip) end # Returns a random quip def random_quip quips[rand(quips.length)] unless quips.empty? end end
Version data entries
11 entries across 11 versions & 2 rubygems