aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--quarg/quassel/formatter.py27
1 files 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,
}