From 5abde2e5cac9700c42babaf90c35e2cc2be25477 Mon Sep 17 00:00:00 2001 From: Wolfgang Müller Date: Tue, 27 Apr 2021 15:50:36 +0200 Subject: formatter: Implement truncation of joined/quit users in netsplits The list of users that have quit or joined after a netsplit can become quite large. Quassel itself cuts reporting off after printing 15 users, so let's follow that. Note that this will not affect queries - the search is performed against the whole netsplit message. --- quarg/quassel/formatter.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/quarg/quassel/formatter.py b/quarg/quassel/formatter.py index 59793fc..ed33719 100644 --- a/quarg/quassel/formatter.py +++ b/quarg/quassel/formatter.py @@ -76,20 +76,21 @@ def parse_netsplit(splitmsg): # ... however, the last element contains the split servers instead servers = elements.pop().split(' ', 1) - # TODO: This takes ages if the netsplit was large - users = [User.from_sender(e) for e in elements] + # This list can be unwieldily large. Mirror quassel's behaviour and cut off + # after printing 15 users. If there were any more users than this, have + # rest contain a value larger than 0 + users = [User.from_sender(e) for e in elements[0:15]] + rest = max(0, len(elements) - 15) - return users, servers + return users, servers, rest -def format_netsplit_join(msg): - users, (srv_left, srv_right) = parse_netsplit(msg.message) - have_joined = ', '.join(user.nick for user in users) - return f'=> Netsplit between {srv_left} and {srv_right} ended. Users joined: {have_joined}' +def format_netsplit(quit, msg): + users, (srv_left, srv_right), rest = parse_netsplit(msg.message) + affected = ', '.join(user.nick for user in users) + (f' ({rest} more)' if rest else '') + if quit: + return f'<= Netsplit between {srv_left} and {srv_right}. Users quit: {affected}' + return f'=> Netsplit between {srv_left} and {srv_right} ended. Users joined: {affected}' -def format_netsplit_quit(msg): - users, (srv_left, srv_right) = parse_netsplit(msg.message) - have_quit = ', '.join(user.nick for user in users) - return f'<= Netsplit between {srv_left} and {srv_right}. Users quit: {have_quit}' def fmt(string): return partial(lambda string, msg: string.format(**msg._asdict()), string) @@ -110,7 +111,7 @@ FORMATTERS = { MessageType.ERROR: format_generic, MessageType.DAYCHANGE: format_generic, MessageType.TOPIC: format_generic, - MessageType.NETSPLIT_JOIN: format_netsplit_join, - MessageType.NETSPLIT_QUIT: format_netsplit_quit, + MessageType.NETSPLIT_JOIN: partial(format_netsplit, False), + MessageType.NETSPLIT_QUIT: partial(format_netsplit, True), MessageType.INVITE: format_generic, } -- cgit v1.2.3-2-gb3c3