class Logbook
Constants
- RABBOT_ROOT
Public Class Methods
Source
# File plugins/logbook.rb, line 37 def self.admin_allowed?(network:, channel:, nick:, is_op:) ChannelTrust.human_admin_nick?( network: network, channel: channel, nick: nick, is_op: is_op ) end
Source
# File plugins/logbook.rb, line 57 def self.bot_nicks(cinch_bot) ([cinch_bot.nick, cinch_bot.config.nick] + Array(cinch_bot.config.nicks)) .compact .map { |nick| nick.to_s.strip } .reject(&:empty?) .uniq end
Source
# File plugins/logbook.rb, line 50 def self.capture_message?(channel:, user_nick:, bot_nick:, text:) return false if channel.nil? || channel.to_s.strip.empty? return false if user_nick.to_s.casecmp?(bot_nick.to_s) !text.to_s.strip.empty? end
Source
# File plugins/logbook.rb, line 19 def self.command_pattern /logbook(?:\s+(.+))?$/i end
Source
# File plugins/logbook.rb, line 46 def self.denial_message "Only registered human admins can query retained bot logs." end
Source
# File plugins/logbook.rb, line 150 def self.disconnect_text(message) message&.message.to_s end
Source
# File plugins/logbook.rb, line 33 def self.parse_command(args) BotLogStore.parse_command(args) end
Source
# File plugins/logbook.rb, line 65 def self.resolve_bot_id(cinch_bot, root: RABBOT_ROOT) BotLogStore.resolve_bot_id(root: root, nicks: bot_nicks(cinch_bot)) || BotLogStore.normalize_bot_id(cinch_bot.nick) end
Public Instance Methods
Source
# File plugins/logbook.rb, line 70 def bot_id @bot_id ||= self.class.resolve_bot_id(bot) end
Source
# File plugins/logbook.rb, line 158 def execute(m, args = nil) return unless BotIdentity.owner_bot?(bot) network = bot.config.server channel = m.channel&.name is_op = m.channel ? m.channel.opped?(m.user) : false unless self.class.admin_allowed?(network: network, channel: channel, nick: m.user.nick, is_op: is_op) return themed_flood_safe_reply(m, self.class.denial_message) end parsed = self.class.parse_command(args) report = BotLogStore.dispatch(parsed, default_bot_id: bot_id) themed_flood_safe_reply(m, report) end
Source
# File plugins/logbook.rb, line 100 def on_action(m) return unless m.channel return if m.user.nick.casecmp?(bot.nick).zero? record( kind: "action", channel: m.channel.name, nick: m.user.nick, text: m.action ) end
Source
# File plugins/logbook.rb, line 145 def on_connect(_m) server = bot.config.server record(kind: "connect", text: "Connected to #{server}") end
Source
# File plugins/logbook.rb, line 154 def on_disconnect(m) record(kind: "disconnect", text: self.class.disconnect_text(m)) end
Source
# File plugins/logbook.rb, line 112 def on_join(m) return unless m.channel record( kind: "join", channel: m.channel.name, nick: m.user.nick, text: "" ) end
Source
# File plugins/logbook.rb, line 84 def on_message(m) return unless self.class.capture_message?( channel: m.channel&.name, user_nick: m.user.nick, bot_nick: bot.nick, text: m.message ) record( kind: "message", channel: m.channel.name, nick: m.user.nick, text: m.message ) end
Source
# File plugins/logbook.rb, line 123 def on_part(m) return unless m.channel record( kind: "part", channel: m.channel.name, nick: m.user.nick, text: m.message.to_s ) end
Source
# File plugins/logbook.rb, line 134 def on_topic(m) return unless m.channel record( kind: "topic", channel: m.channel.name, nick: m.user.nick, text: m.message.to_s ) end
Source
# File plugins/logbook.rb, line 74 def record(kind:, text:, channel: nil, nick: nil) BotLogStore.record_event( bot_id: bot_id, kind: kind, text: text, channel: channel, nick: nick ) end