mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-30 06:49:24 +01:00
Seen: show when the target is currently in the channel (#1559)
This commit is contained in:
parent
ec9e731fa5
commit
7cd700b4ae
@ -195,9 +195,14 @@ class Seen(callbacks.Plugin):
|
|||||||
if len(results) == 1:
|
if len(results) == 1:
|
||||||
(nick, info) = results[0]
|
(nick, info) = results[0]
|
||||||
(when, said) = info
|
(when, said) = info
|
||||||
reply = format(_('%s was last seen in %s %s ago'),
|
if nick in irc.state.channels[channel].users:
|
||||||
nick, channel,
|
reply = format(_('%s was last seen in %s %s ago, and is in the channel now'),
|
||||||
utils.timeElapsed(time.time()-when))
|
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 self.registryValue('showLastMessage', channel, irc.network):
|
||||||
if minisix.PY2:
|
if minisix.PY2:
|
||||||
said = said.decode('utf8')
|
said = said.decode('utf8')
|
||||||
@ -207,13 +212,20 @@ class Seen(callbacks.Plugin):
|
|||||||
L = []
|
L = []
|
||||||
for (nick, info) in results:
|
for (nick, info) in results:
|
||||||
(when, said) = info
|
(when, said) = info
|
||||||
L.append(format(_('%s (%s ago)'), nick,
|
if nick in irc.state.channels[channel].users:
|
||||||
utils.timeElapsed(time.time()-when)))
|
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'))))
|
irc.reply(format(_('%s could be %L'), name, (L, _('or'))))
|
||||||
else:
|
else:
|
||||||
irc.reply(format(_('I haven\'t seen anyone matching %s.'), name))
|
irc.reply(format(_('I haven\'t seen anyone matching %s.'), name))
|
||||||
except KeyError:
|
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):
|
def _checkChannelPresence(self, irc, channel, target, you):
|
||||||
if channel not in irc.state.channels:
|
if channel not in irc.state.channels:
|
||||||
@ -277,8 +289,13 @@ class Seen(callbacks.Plugin):
|
|||||||
db = self.db
|
db = self.db
|
||||||
try:
|
try:
|
||||||
(when, said) = db.seen(channel, '<last>')
|
(when, said) = db.seen(channel, '<last>')
|
||||||
reply = format(_('Someone was last seen in %s %s ago'),
|
pattern = r'<(.*?)>'
|
||||||
channel, utils.timeElapsed(time.time()-when))
|
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):
|
if self.registryValue('showLastMessage', channel, irc.network):
|
||||||
reply = _('%s: %s') % (reply, said)
|
reply = _('%s: %s') % (reply, said)
|
||||||
irc.reply(reply)
|
irc.reply(reply)
|
||||||
@ -303,14 +320,22 @@ class Seen(callbacks.Plugin):
|
|||||||
db = self.db
|
db = self.db
|
||||||
try:
|
try:
|
||||||
(when, said) = db.seen(channel, user.id)
|
(when, said) = db.seen(channel, user.id)
|
||||||
reply = format(_('%s was last seen in %s %s ago'),
|
if user.name in irc.state.channels[channel].users:
|
||||||
user.name, channel,
|
reply = format(_('%s was last seen in %s %s ago and is in the channel now'),
|
||||||
utils.timeElapsed(time.time()-when))
|
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):
|
if self.registryValue('showLastMessage', channel, irc.network):
|
||||||
reply = _('%s: %s') % (reply, said)
|
reply = _('%s: %s') % (reply, said)
|
||||||
irc.reply(reply)
|
irc.reply(reply)
|
||||||
except KeyError:
|
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
|
@internationalizeDocstring
|
||||||
def user(self, irc, msg, args, channel, user):
|
def user(self, irc, msg, args, channel, user):
|
||||||
|
@ -83,12 +83,10 @@ class ChannelDBTestCase(ChannelPluginTestCase):
|
|||||||
self.assertNotError('seen last')
|
self.assertNotError('seen last')
|
||||||
self.assertNotError('list')
|
self.assertNotError('list')
|
||||||
self.assertNotError('config plugins.Seen.minimumNonWildcard 2')
|
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,
|
self.assertRegexp('seen user %s' % self.nick,
|
||||||
'^%s was last seen' % self.nick)
|
'^%s was last seen' % self.nick)
|
||||||
|
self.assertError('seen *')
|
||||||
|
self.assertNotError('seen %s' % self.nick)
|
||||||
self.assertNotError('config plugins.Seen.minimumNonWildcard 0')
|
self.assertNotError('config plugins.Seen.minimumNonWildcard 0')
|
||||||
orig = conf.supybot.protocols.irc.strictRfc()
|
orig = conf.supybot.protocols.irc.strictRfc()
|
||||||
try:
|
try:
|
||||||
@ -101,6 +99,28 @@ class ChannelDBTestCase(ChannelPluginTestCase):
|
|||||||
finally:
|
finally:
|
||||||
conf.supybot.protocols.irc.strictRfc.setValue(orig)
|
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):
|
def testSeenNoUser(self):
|
||||||
self.irc.feedMsg(ircmsgs.join(self.channel, self.irc.nick,
|
self.irc.feedMsg(ircmsgs.join(self.channel, self.irc.nick,
|
||||||
prefix=self.prefix))
|
prefix=self.prefix))
|
||||||
|
Loading…
Reference in New Issue
Block a user