Seen: show when the target is currently in the channel (#1559)

This commit is contained in:
Matias Wilkman 2023-10-09 20:31:50 +03:00 committed by GitHub
parent ec9e731fa5
commit 7cd700b4ae
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 61 additions and 16 deletions

View File

@ -195,9 +195,14 @@ class Seen(callbacks.Plugin):
if len(results) == 1:
(nick, info) = results[0]
(when, said) = info
reply = format(_('%s was last seen in %s %s ago'),
nick, channel,
utils.timeElapsed(time.time()-when))
if nick in irc.state.channels[channel].users:
reply = format(_('%s was last seen in %s %s ago, and is in the channel now'),
nick, channel,
utils.timeElapsed(time.time()-when))
else:
reply = format(_('%s was last seen in %s %s ago'),
nick, channel,
utils.timeElapsed(time.time()-when))
if self.registryValue('showLastMessage', channel, irc.network):
if minisix.PY2:
said = said.decode('utf8')
@ -207,13 +212,20 @@ class Seen(callbacks.Plugin):
L = []
for (nick, info) in results:
(when, said) = info
L.append(format(_('%s (%s ago)'), nick,
utils.timeElapsed(time.time()-when)))
if nick in irc.state.channels[channel].users:
L.append(format(_('%s (%s ago, and is in the channel now)'), nick,
utils.timeElapsed(time.time()-when)))
else:
L.append(format(_('%s (%s ago)'), nick,
utils.timeElapsed(time.time()-when)))
irc.reply(format(_('%s could be %L'), name, (L, _('or'))))
else:
irc.reply(format(_('I haven\'t seen anyone matching %s.'), name))
except KeyError:
irc.reply(format(_('I have not seen %s.'), name))
if name in irc.state.channels[channel].users:
irc.reply(format(_("%s is in the channel right now."), name))
else:
irc.reply(format(_('I have not seen %s.'), name))
def _checkChannelPresence(self, irc, channel, target, you):
if channel not in irc.state.channels:
@ -277,8 +289,13 @@ class Seen(callbacks.Plugin):
db = self.db
try:
(when, said) = db.seen(channel, '<last>')
reply = format(_('Someone was last seen in %s %s ago'),
channel, utils.timeElapsed(time.time()-when))
pattern = r'<(.*?)>'
match = re.search(pattern, said)
if not match:
irc.error(format(_('I couldn\'t parse the nick of the speaker of the last line.')), Raise=True)
nick = match.group(1)
reply = format(_('Last seen in %s was %s, %s ago'),
channel, nick, utils.timeElapsed(time.time()-when))
if self.registryValue('showLastMessage', channel, irc.network):
reply = _('%s: %s') % (reply, said)
irc.reply(reply)
@ -303,14 +320,22 @@ class Seen(callbacks.Plugin):
db = self.db
try:
(when, said) = db.seen(channel, user.id)
reply = format(_('%s was last seen in %s %s ago'),
user.name, channel,
utils.timeElapsed(time.time()-when))
if user.name in irc.state.channels[channel].users:
reply = format(_('%s was last seen in %s %s ago and is in the channel now'),
user.name, channel,
utils.timeElapsed(time.time()-when))
else:
reply = format(_('%s was last seen in %s %s ago'),
user.name, channel,
utils.timeElapsed(time.time()-when))
if self.registryValue('showLastMessage', channel, irc.network):
reply = _('%s: %s') % (reply, said)
irc.reply(reply)
except KeyError:
irc.reply(format(_('I have not seen %s.'), user.name))
if user.name in irc.state.channels[channel].users:
irc.reply(format(_("%s is in the channel right now."), user.name))
else:
irc.reply(format(_('I have not seen %s.'), user.name))
@internationalizeDocstring
def user(self, irc, msg, args, channel, user):

View File

@ -83,12 +83,10 @@ class ChannelDBTestCase(ChannelPluginTestCase):
self.assertNotError('seen last')
self.assertNotError('list')
self.assertNotError('config plugins.Seen.minimumNonWildcard 2')
self.assertError('seen *')
self.assertNotError('seen %s' % self.nick)
m = self.assertNotError('seen %s' % self.nick.upper())
self.assertIn(self.nick.upper(), m.args[1])
self.assertRegexp('seen user %s' % self.nick,
'^%s was last seen' % self.nick)
self.assertError('seen *')
self.assertNotError('seen %s' % self.nick)
self.assertNotError('config plugins.Seen.minimumNonWildcard 0')
orig = conf.supybot.protocols.irc.strictRfc()
try:
@ -101,6 +99,28 @@ class ChannelDBTestCase(ChannelPluginTestCase):
finally:
conf.supybot.protocols.irc.strictRfc.setValue(orig)
def testSeenNickInChannel(self):
# Test case: 'seen' with a nick (user in channel)
self.irc.feedMsg(ircmsgs.join(self.channel, self.irc.nick,
prefix=self.prefix))
self.assertRegexp('seen %s' % self.nick, 'is in the channel right now')
m = self.assertNotError('seen %s' % self.nick.upper())
self.assertIn(self.nick.upper(), m.args[1])
def testSeenUserInChannel(self):
# Test case: 'seen' with a user (user in channel)
self.irc.feedMsg(ircmsgs.join(self.channel, self.irc.nick,
prefix=self.prefix))
self.assertRegexp('seen user %s' % self.nick, 'is in the channel right now')
def testSeenNickNotInChannel(self):
# Test case: 'seen' with a nick (user not in channel)
testnick = "user123"
self.irc.feedMsg(ircmsgs.join(self.channel, testnick, "user123!baz"))
self.irc.feedMsg(ircmsgs.part(self.channel, prefix="user123!baz"))
self.assertNotRegexp("seen %s" % testnick, "is in the channel right now")
def testSeenNoUser(self):
self.irc.feedMsg(ircmsgs.join(self.channel, self.irc.nick,
prefix=self.prefix))