class King
Constants
- KEY
- PLUGIN
- STYLE_TITLE
Public Class Methods
Source
# File plugins/king.rb, line 47 def self.crown_holder(network:, channel:, store: RabbotDb) holder = load_holder(network: network, channel: channel, store: store) return holder if holder.is_a?(Hash) && holder["date"] == today_key top = ChannelStats.top_nicks(network: network, channel: channel, limit: 1, store: store).first return nil unless top holder = { "date" => today_key, "nick" => top[:nick], "count" => top[:count] } save_holder(network: network, channel: channel, holder: holder, store: store) holder end
Source
# File plugins/king.rb, line 27 def self.load_holder(network:, channel:, store: RabbotDb) store.get_plugin_json( plugin: PLUGIN, key: KEY, network: network, channel: channel, default: {} ) end
Source
# File plugins/king.rb, line 63 def self.report(network:, channel:, store: RabbotDb) holder = crown_holder(network: network, channel: channel, store: store) return "No channel activity recorded yet" unless holder header = IrcFormat.report_header(tag: "KING", title: "daily crown", style: STYLE_TITLE) body = "#{holder['nick']} rules today with #{holder['count']} messages" footer = IrcFormat.report_footer(holder["date"]) [header, body, footer].join("\n") end
Source
# File plugins/king.rb, line 37 def self.save_holder(network:, channel:, holder:, store: RabbotDb) store.set_plugin_json( plugin: PLUGIN, key: KEY, network: network, channel: channel, value: holder ) end
Source
# File plugins/king.rb, line 23 def self.today_key Time.now.utc.strftime("%Y-%m-%d") end
Public Instance Methods
Source
# File plugins/king.rb, line 73 def execute(m) unless m.channel m.reply "Use !king in a channel" return end themed_flood_safe_reply(m, self.class.report(network: bot.config.server, channel: m.channel.name)) end