def get_services_account(irc, nick): """irc object, nick str Returns a tuple (status, name). status indicates whether the nick is logged in to NickServ. 1: user not seen, 2: WHOIS in progress, 3: user known to be not logged in, 4: user logged in but expired, 5: logged in and current. The second element of the tuple is None for statuses 1-3 and the NickServ account name for statuses 4-5. """ if nick not in whois.keys(): # user hasn't been seen before irc.queueMsg(ircmsgs.whois(nick, nick)) whois[nick] = None # None indicates that a WHOIS is in process return (1, ) elif whois[nick] == None: # user has been seen but WHOIS did not yet finish return (2, ) elif whois[nick] == -1: # user is known, but is not logged in to NickServ # we'll check again, in case they have logged in since the last time irc.queueMsg(ircmsgs.whois(nick, nick)) return (3, ) else: # user is known and authenticated if time.time() - whois[nick][1] > 36000: # but ten hour have passed, so refresh the entry irc.queueMsg(ircmsgs.whois(nick, nick)) return (4, whois[nick][0]) else: # known and authenticated less than ten hours ago return (5, whois[nick][0])
def auth(self, irc, msg, args): """takes no argument Tries to authenticate you using network services. If you get no reply, it means you are not authenticated to the network services.""" nick = ircutils.toLower(msg.nick) self._requests[(irc.network, msg.nick)] = (time.time(), msg.prefix, irc) irc.queueMsg(ircmsgs.whois(nick, nick))
def whatNick(self, irc, msg, args, otherIrc, nick): """[<network>] <nick> """ # The double nick here is necessary because single-nick WHOIS only works # if the nick is on the same server (*not* the same network) as the user # giving the command. Yeah, it made me say wtf too. nick = ircutils.toLower(nick) otherIrc.queueMsg(ircmsgs.whois(nick, nick)) self._whois[(otherIrc, nick)] = (irc, msg, {})
def whois(self, irc, msg, args, otherIrc, nick): """[<network>] <nick> Returns the WHOIS response <network> gives for <nick>. <network> is only necessary if the network is different than the network the command is sent on. """ # The double nick here is necessary because single-nick WHOIS only works # if the nick is on the same server (*not* the same network) as the user # giving the command. Yeah, it made me say wtf too. nick = ircutils.toLower(nick) otherIrc.queueMsg(ircmsgs.whois(nick, nick)) self._whois[(otherIrc, nick)] = (irc, msg, {}, 'whois')
def testWhois(self): with conf.supybot.protocols.irc.strictRfc.context(True): self.assertEqual(str(ircmsgs.whois('foo')), 'WHOIS :foo\r\n') self.assertEqual(str(ircmsgs.whois('foo,bar')), 'WHOIS :foo,bar\r\n') self.assertRaises(AssertionError, ircmsgs.whois, '#foo') self.assertRaises(AssertionError, ircmsgs.whois, 'foo,#foo')
def processAccount(self, irc, msg, nick, callback): if nick in self._cache: callback[0](*callback[1:]) else: self._requests[(irc.network, nick)] = callback irc.queueMsg(ircmsgs.whois(nick, nick))
def doJoin(self, irc, msg): self._add(irc, msg, "join") nick = msg.nick irc.queueMsg(ircmsgs.whois(nick, nick))
def sendWhois(self, irc, nick, do_reply=False, *args): nick = nick.lower() irc.queueMsg(ircmsgs.whois(nick, nick)) if do_reply: self.replies[nick] = [args[0], args[1:]]