From 06afec27388809ee6ea169bdce80eed964056df7 Mon Sep 17 00:00:00 2001 From: jesopo Date: Sun, 7 Jun 2020 17:46:38 +0100 Subject: [PATCH] WHOIS should have nick, user/host/real are required, handle NOSUCHUSER --- ircrobots/server.py | 14 ++++++++++---- ircrobots/struct.py | 12 +++++++----- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/ircrobots/server.py b/ircrobots/server.py index d75e257..72fb03d 100644 --- a/ircrobots/server.py +++ b/ircrobots/server.py @@ -439,7 +439,7 @@ class Server(IServer): return None return MaybeAwait(_assure) - def send_whois(self, target: str) -> Awaitable[Whois]: + def send_whois(self, target: str) -> Awaitable[Optional[Whois]]: folded = self.casefold(target) fut = self.send(build("WHOIS", [target, target])) @@ -449,6 +449,7 @@ class Server(IServer): obj = Whois() while True: line = await self.wait_for(Responses([ + ERR_NOSUCHUSER, RPL_WHOISUSER, RPL_WHOISSERVER, RPL_WHOISOPERATOR, @@ -459,9 +460,14 @@ class Server(IServer): RPL_WHOISSECURE, RPL_ENDOFWHOIS ], params)) - - if line.command == RPL_WHOISUSER: - obj.username, obj.hostname, _, obj.realname = line.params[2:] + if line.command == ERR_NOSUCHUSER: + return None + elif line.command == RPL_WHOISUSER: + nick, user, host, _, real = line.params[1:] + obj.nickname = nick + obj.username = user + obj.hostname = host + obj.realname = real elif line.command == RPL_WHOISIDLE: obj.idle, signon, _ = line.params[2:] obj.signon = int(signon) diff --git a/ircrobots/struct.py b/ircrobots/struct.py index 3124f94..6bfc8a3 100644 --- a/ircrobots/struct.py +++ b/ircrobots/struct.py @@ -11,9 +11,11 @@ class Whois(object): signon: Optional[int] = None idle: Optional[int] = None - username: Optional[str] = None - hostname: Optional[str] = None - realname: Optional[str] = None - account: Optional[str] = None - channels: Optional[List[str]] = None + + nickname: str = "" + username: str = "" + hostname: str = "" + realname: str = "" + account: Optional[str] = None +