From a3738cb9f4d9da9b9b2ecaac9330392934f0e87c Mon Sep 17 00:00:00 2001 From: Robin H. Johnson Date: Sun, 10 Aug 2008 17:38:16 +0000 Subject: [PATCH] seen: Refactor, channel names, privacy start - We should always include channel names in messages. - Ensure the gettext strings are kept common, as there was some drift before. - Provide an initial framework for channel and message privacy. Signed-off-by: Robin H. Johnson diff --git a/data/rbot/plugins/seen.rb b/data/rbot/plugins/seen.rb index 0fc6f07..6ffc9c0 100644 --- a/data/rbot/plugins/seen.rb +++ b/data/rbot/plugins/seen.rb @@ -8,6 +8,25 @@ define_structure :Saw, :nick, :time, :type, :where, :message class SeenPlugin < Plugin + + MSG_PUBLIC = "saying \"%{message}\" in %{where}" + MSG_ACTION = "doing *%{nick} %{message}* in %{where}" + MSG_NICK = "changing nick from %{nick} to %{message}" + MSG_PART = "leaving %{where} (%{message})" + MSG_PART_EMPTY = "leaving %{where}" + MSG_JOIN = "joining %{where}" + MSG_QUIT = "quitting IRC (%{message})" + MSG_TOPIC = "changing the topic of %{where} to \"%{message}\"" + + CHANPRIV_CHAN = "a private channel" + CHANPRIV_MSG_TOPIC = "changing the topic of %{where}" + + MSGPRIV_MSG_PUBLIC = "speaking in %{where}" + MSGPRIV_MSG_ACTION = "doing something in %{where}" + + FORMAT_NORMAL = "%{nick} was last seen %{when}, %{doing}" + FORMAT_WITH_BEFORE = "%{nick} was last seen %{when}, %{doing} and %{time} before %{did_before}" + Config.register Config::IntegerValue.new('seen.max_results', :default => 3, :validate => Proc.new{|v| v >= 0}, :desc => _("Maximum number of seen users to return in search (0 = no limit).")) @@ -85,21 +104,36 @@ def seen(reg) before = reg.first end + # TODO: a message should not be disclosed if: + # - it was said in a channel that was/is invite-only, private or secret + # - UNLESS the requester is also in the channel now, or the request is made + # in the channel? + msg_privacy = false + # TODO: a channel or it's topic should not be disclosed if: + # - the channel was/is private or secret + # - UNLESS the requester is also in the channel now, or the request is made + # in the channel? + chan_privacy = false + + # What should be displayed for channel? + where = chan_privacy ? _(CHANPRIV_CHAN) : saw.where + formats = { - :normal => _("%{nick} was last seen %{when}, %{doing}"), - :with_before => _("%{nick} was last seen %{when}, %{doing} and %{time} before %{did_before}") + :normal => _(FORMAT_NORMAL), + :with_before => _(FORMAT_WITH_BEFORE) } if before && [:PART, :QUIT].include?(saw.type.to_sym) && [:PUBLIC, :ACTION].include?(before.type.to_sym) did_before = case before.type.to_sym when :PUBLIC - _("saying \"%{message}\"") + _(msg_privacy ? MSGPRIV_MSG_PUBLIC : MSG_PUBLIC) when :ACTION - _("doing *%{nick} %{message}*") + _(msg_privacy ? MSGPRIV_MSG_ACTION : MSG_ACTION) end % { :nick => saw.nick, - :message => before.message + :message => before.message, + :where => where } format = :with_before @@ -127,24 +161,24 @@ def seen(reg) doing = case saw.type.to_sym when :PUBLIC - _("saying \"%{message}\"") + _(msg_privacy ? MSGPRIV_MSG_PUBLIC : MSG_PUBLIC) when :ACTION - _("doing *%{message}*") + _(msg_privacy ? MSGPRIV_MSG_ACTION : MSG_ACTION) when :NICK - _("changing nick from %{nick} to %{message}") + _(MSG_NICK) when :PART if saw.message.empty? - _("leaving %{where}") + _(MSG_PART_EMPTY) else - _("leaving %{where} (%{message})") + _(MSG_PART) end when :JOIN - _("joining %{where}") + _(MSG_JOIN) when :QUIT - _("quitting IRC (%{message})") + _(MSG_QUIT) when :TOPIC - _("changing the topic of %{where} to \"%{message}\"") - end % { :message => saw.message, :where => saw.where, :nick => saw.nick } + _(chan_privacy ? CHANPRIV_MSG_TOPIC : MSG_TOPIC) + end % { :message => saw.message, :where => where, :nick => saw.nick } case format when :normal @@ -165,6 +199,9 @@ def seen(reg) end def store(m, saw) + # TODO: we need to store the channel state INVITE/SECRET/PRIVATE here, in + # some symbolic form, so that we know the prior state of the channel when + # it comes time to display. reg = @registry[saw.nick] if reg && reg.is_a?(Array)