mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-10-04 18:38:39 +02:00
Seen: Factorize code used for checks.
This commit is contained in:
parent
02b8c39138
commit
468d2762c1
@ -225,6 +225,17 @@ class Seen(callbacks.Plugin):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
irc.reply(format(_('I have not seen %s.'), name))
|
irc.reply(format(_('I have not seen %s.'), name))
|
||||||
|
|
||||||
|
def _checkChannelPresence(self, irc, channel, target, you):
|
||||||
|
if channel not in irc.state.channels:
|
||||||
|
irc.error(_("I'm not in %s." % channel), Raise=True)
|
||||||
|
if target not in irc.state.channels[channel].users:
|
||||||
|
if you:
|
||||||
|
msg = format(_('You must be in %s to use this command.'), channel)
|
||||||
|
else:
|
||||||
|
msg = format(_('%s must be in %s to use this command.'),
|
||||||
|
target, channel)
|
||||||
|
irc.error(msg, Raise=True)
|
||||||
|
|
||||||
@internationalizeDocstring
|
@internationalizeDocstring
|
||||||
def seen(self, irc, msg, args, channel, name):
|
def seen(self, irc, msg, args, channel, name):
|
||||||
"""[<channel>] <nick>
|
"""[<channel>] <nick>
|
||||||
@ -236,11 +247,7 @@ class Seen(callbacks.Plugin):
|
|||||||
if name and ircutils.strEqual(name, irc.nick):
|
if name and ircutils.strEqual(name, irc.nick):
|
||||||
irc.reply(_("You've found me!"))
|
irc.reply(_("You've found me!"))
|
||||||
return
|
return
|
||||||
if channel not in irc.state.channels:
|
self._checkChannelPresence(irc, channel, msg.nick, True)
|
||||||
irc.error(_("I'm not in %s." % channel), Raise=True)
|
|
||||||
if msg.nick not in irc.state.channels[channel].users:
|
|
||||||
irc.error(format('You must be in %s to use this command.', channel))
|
|
||||||
return
|
|
||||||
self._seen(irc, channel, name)
|
self._seen(irc, channel, name)
|
||||||
seen = wrap(seen, ['channel', 'something'])
|
seen = wrap(seen, ['channel', 'something'])
|
||||||
|
|
||||||
@ -258,11 +265,7 @@ class Seen(callbacks.Plugin):
|
|||||||
if name and ircutils.strEqual(name, irc.nick):
|
if name and ircutils.strEqual(name, irc.nick):
|
||||||
irc.reply(_("You've found me!"))
|
irc.reply(_("You've found me!"))
|
||||||
return
|
return
|
||||||
if channel not in irc.state.channels:
|
self._checkChannelPresence(irc, channel, msg.nick, True)
|
||||||
irc.error(_("I'm not in %s." % channel), Raise=True)
|
|
||||||
if msg.nick not in irc.state.channels[channel].users:
|
|
||||||
irc.error(format('You must be in %s to use this command.', channel))
|
|
||||||
return
|
|
||||||
if name and optlist:
|
if name and optlist:
|
||||||
raise callbacks.ArgumentError
|
raise callbacks.ArgumentError
|
||||||
elif name:
|
elif name:
|
||||||
@ -299,11 +302,7 @@ class Seen(callbacks.Plugin):
|
|||||||
Returns the last thing said in <channel>. <channel> is only necessary
|
Returns the last thing said in <channel>. <channel> is only necessary
|
||||||
if the message isn't sent in the channel itself.
|
if the message isn't sent in the channel itself.
|
||||||
"""
|
"""
|
||||||
if channel not in irc.state.channels:
|
self._checkChannelPresence(irc, channel, msg.nick, True)
|
||||||
irc.error(_("I'm not in %s." % channel), Raise=True)
|
|
||||||
if msg.nick not in irc.state.channels[channel].users:
|
|
||||||
irc.error(format('You must be in %s to use this command.', channel))
|
|
||||||
return
|
|
||||||
self._last(irc, channel)
|
self._last(irc, channel)
|
||||||
last = wrap(last, ['channel'])
|
last = wrap(last, ['channel'])
|
||||||
|
|
||||||
@ -333,11 +332,7 @@ class Seen(callbacks.Plugin):
|
|||||||
<channel> is only necessary if the message isn't sent in the channel
|
<channel> is only necessary if the message isn't sent in the channel
|
||||||
itself.
|
itself.
|
||||||
"""
|
"""
|
||||||
if channel not in irc.state.channels:
|
self._checkChannelPresence(irc, channel, msg.nick, True)
|
||||||
irc.error(_("I'm not in %s." % channel), Raise=True)
|
|
||||||
if msg.nick not in irc.state.channels[channel].users:
|
|
||||||
irc.error(format('You must be in %s to use this command.', channel))
|
|
||||||
return
|
|
||||||
self._user(irc, channel, user)
|
self._user(irc, channel, user)
|
||||||
user = wrap(user, ['channel', 'otherUser'])
|
user = wrap(user, ['channel', 'otherUser'])
|
||||||
|
|
||||||
@ -351,13 +346,10 @@ class Seen(callbacks.Plugin):
|
|||||||
"""
|
"""
|
||||||
if nick is None:
|
if nick is None:
|
||||||
nick = msg.nick
|
nick = msg.nick
|
||||||
if channel not in irc.state.channels:
|
you = True
|
||||||
irc.error(_('I am not in %s.') % channel)
|
else:
|
||||||
return
|
you = False
|
||||||
if nick not in irc.state.channels[channel].users:
|
self._checkChannelPresence(irc, channel, nick, you)
|
||||||
irc.error(format(_('%s must be in %s to use this command.'),
|
|
||||||
('You' if nick == msg.nick else nick), channel))
|
|
||||||
return
|
|
||||||
if nick is None:
|
if nick is None:
|
||||||
nick = msg.nick
|
nick = msg.nick
|
||||||
end = None # By default, up until the most recent message.
|
end = None # By default, up until the most recent message.
|
||||||
|
Loading…
Reference in New Issue
Block a user