fix type hinting issues in send_modes/send_kicks (IRCChannel)

This commit is contained in:
jesopo 2020-02-27 10:09:28 +00:00
parent 74b53f1765
commit 7293243429

View file

@ -215,26 +215,30 @@ class Channel(IRCObject.Object):
def send_tagmsg(self, tags: dict): def send_tagmsg(self, tags: dict):
return self.server.send_tagmsg(self.name, tags) return self.server.send_tagmsg(self.name, tags)
def _chunks(self, n: int, l: typing.List[typing.Tuple[str, str]]): def _chunks(self, chunk: int, n: int) -> typing.List[typing.List[int]]:
return [l[i:i+n] for i in range(0, len(l), n)] return [list(range(i, i+chunk)) for i in range(0, n, chunk)]
def send_mode(self, mode: str=None, target: typing.List[str]=None): def send_mode(self, mode: str=None, target: typing.List[str]=None):
return self.server.send_mode(self.name, mode, target) return self.server.send_mode(self.name, mode, target)
def send_modes(self, modes: typing.List[typing.Tuple[str, str]], add: bool): def send_modes(self, modes: typing.List[typing.Tuple[str, str]], add: bool):
chunk_n = min(6, chunk_n = min(6,
int(self.server.isupport.get("MODES", "3") or "6")) int(self.server.isupport.get("MODES", "3") or "6"))
for chunk in self._chunks(chunk_n, modes):
modes, args = list(zip(*chunk)) for chunk in self._chunks(chunk_n, len(modes)):
mode_str = "%s%s" % ("+" if add else "-", "".join(modes)) chunk_items = modes[chunk[0]:chunk[0]+len(chunk)]
self.server.send_mode(self.name, mode_str, args) chunk_modes = [i[0] for i in chunk_items]
chunk_args = [i[1] for i in chunk_items]
mode_str = "%s%s" % ("+" if add else "-", "".join(chunk_modes))
self.server.send_mode(self.name, mode_str, chunk_args)
def send_kick(self, target: str, reason: str=None): def send_kick(self, target: str, reason: str=None):
return self.server.send_kick(self.name, target, reason) return self.server.send_kick(self.name, target, reason)
def send_kicks(self, targets: typing.List[str], reason: str=None): def send_kicks(self, targets: typing.List[str], reason: str=None):
chunk_n = min(4, self.server.targmax.get("KICK", 1)) chunk_n = min(4, self.server.targmax.get("KICK", 1))
for chunk in self._chunks(chunk_n, targets): for chunk in self._chunks(chunk_n, len(targets)):
chan_str = ",".join([self.name]*len(chunk)) chan_str = ",".join([self.name]*len(chunk))
self.server.send_kick(chan_str, ",".join(chunk), reason) nicks = targets[chunk[0]:chunk[0]+len(chunk)]
self.server.send_kick(chan_str, ",".join(nicks), reason)
def send_ban(self, hostmask: str): def send_ban(self, hostmask: str):
return self.server.send_mode(self.name, "+b", [hostmask]) return self.server.send_mode(self.name, "+b", [hostmask])