module QuoteStore
Constants
- KEY
- PLUGIN
Public Instance Methods
Source
# File lib/quote_store.rb, line 24 def add(network:, channel:, nick:, text:, store: RabbotDb) quotes = list(network: network, channel: channel, store: store) entry = { "id" => SecureRandom.hex(4), "nick" => nick.to_s, "text" => text.to_s.strip, "at" => store.iso_time(Time.now) } quotes << entry store.set_plugin_json(plugin: PLUGIN, key: KEY, network: network, channel: channel, value: quotes) entry end
Source
# File lib/quote_store.rb, line 12 def list(network:, channel:, store: RabbotDb) Array( store.get_plugin_json( plugin: PLUGIN, key: KEY, network: network, channel: channel, default: [] ) ) end
Source
# File lib/quote_store.rb, line 37 def random(network:, channel:, rand: ->(max) { Random.rand(0...max) }, store: RabbotDb) quotes = list(network: network, channel: channel, store: store) return nil if quotes.empty? quotes[rand.call(quotes.length)] end