aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorWolfgang Müller2021-04-27 15:50:36 +0200
committerWolfgang Müller2021-04-28 20:15:53 +0200
commit5abde2e5cac9700c42babaf90c35e2cc2be25477 (patch)
tree9b4e093410bfd73f95aa22162bc3dda84f555cb8
parente64b6f8e5f6c1af57cf6c5dd9ad74cb934b57c44 (diff)
downloadquarg-5abde2e5cac9700c42babaf90c35e2cc2be25477.tar.gz
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.
-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,
}