whois.idle is an int, change whois.channels to ChannelUser objects (modes!)

This commit is contained in:
jesopo 2020-06-12 14:23:04 +01:00
parent c4df2e2175
commit db851e0ba2
2 changed files with 21 additions and 10 deletions

View File

@ -7,7 +7,7 @@ from time import monotonic
from asyncio_throttle import Throttler from asyncio_throttle import Throttler
from async_timeout import timeout from async_timeout import timeout
from ircstates import Emit, Channel from ircstates import Emit, Channel, ChannelUser
from ircstates.numerics import * from ircstates.numerics import *
from ircstates.server import ServerDisconnectedException from ircstates.server import ServerDisconnectedException
from irctokens import build, Line, tokenise from irctokens import build, Line, tokenise
@ -448,7 +448,7 @@ class Server(IServer):
args.append(target) args.append(target)
fut = self.send(build("WHOIS", args)) fut = self.send(build("WHOIS", args))
async def _assure(): async def _assure() -> Optional[Whois]:
await fut await fut
params = [ANY, Folded(self.casefold(target))] params = [ANY, Folded(self.casefold(target))]
obj = Whois() obj = Whois()
@ -475,20 +475,29 @@ class Server(IServer):
obj.hostname = host obj.hostname = host
obj.realname = real obj.realname = real
elif line.command == RPL_WHOISIDLE: elif line.command == RPL_WHOISIDLE:
obj.idle, signon, _ = line.params[2:] idle, signon, _ = line.params[2:]
obj.idle = int(idle)
obj.signon = int(signon) obj.signon = int(signon)
elif line.command == RPL_WHOISACCOUNT: elif line.command == RPL_WHOISACCOUNT:
obj.account = line.params[2] obj.account = line.params[2]
elif line.command == RPL_WHOISCHANNELS: elif line.command == RPL_WHOISCHANNELS:
channels = list(filter(bool, line.params[2].split(" "))) channels = list(filter(bool, line.params[2].split(" ")))
for i, channel in enumerate(channels):
while channel[0] in self.isupport.prefix.prefixes:
channel = channel[1:]
channels[i] = channel
if obj.channels is None: if obj.channels is None:
obj.channels = [] obj.channels = []
obj.channels += channels
for i, channel in enumerate(channels):
symbols = ""
while channel[0] in self.isupport.prefix.prefixes:
symbols += channel[0]
channel = channel[1:]
channel_user = ChannelUser()
for symbol in symbols:
mode = self.isupport.prefix.from_prefix(symbol)
if mode is not None:
channel_user.modes.append(mode)
obj.channels.append(channel_user)
elif line.command == RPL_ENDOFWHOIS: elif line.command == RPL_ENDOFWHOIS:
return obj return obj
return MaybeAwait(_assure) return MaybeAwait(_assure)

View File

@ -1,6 +1,8 @@
from typing import List, Optional from typing import List, Optional
from dataclasses import dataclass from dataclasses import dataclass
from ircstates import ChannelUser
class Whois(object): class Whois(object):
server: Optional[str] = None server: Optional[str] = None
server_info: Optional[str] = None server_info: Optional[str] = None
@ -11,7 +13,7 @@ class Whois(object):
signon: Optional[int] = None signon: Optional[int] = None
idle: Optional[int] = None idle: Optional[int] = None
channels: Optional[List[str]] = None channels: Optional[List[ChannelUser]] = None
nickname: str = "" nickname: str = ""
username: str = "" username: str = ""