mirror of
https://github.com/ergochat/ergo.git
synced 2024-12-23 11:12:44 +01:00
commit
937e519595
@ -2,9 +2,12 @@
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
import logging
|
import logging
|
||||||
|
import re
|
||||||
import sys
|
import sys
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
|
MASK_MAGIC_REGEX = re.compile(r'[*?!@]')
|
||||||
|
|
||||||
def to_unixnano(timestamp):
|
def to_unixnano(timestamp):
|
||||||
return int(timestamp) * (10**9)
|
return int(timestamp) * (10**9)
|
||||||
|
|
||||||
@ -100,6 +103,8 @@ def convert(infile):
|
|||||||
# channel access lists
|
# channel access lists
|
||||||
# CA #mychannel shivaram +AFORafhioqrstv 1600134478 shivaram
|
# CA #mychannel shivaram +AFORafhioqrstv 1600134478 shivaram
|
||||||
chname, username, flags, set_at = parts[1], parts[2], parts[3], int(parts[4])
|
chname, username, flags, set_at = parts[1], parts[2], parts[3], int(parts[4])
|
||||||
|
if MASK_MAGIC_REGEX.search(username):
|
||||||
|
continue
|
||||||
chname = parts[1]
|
chname = parts[1]
|
||||||
chdata = out['channels'][chname]
|
chdata = out['channels'][chname]
|
||||||
flags = parts[3]
|
flags = parts[3]
|
||||||
@ -135,14 +140,31 @@ def convert(infile):
|
|||||||
chdata['amode'][username] = 'h'
|
chdata['amode'][username] = 'h'
|
||||||
elif 'v' in flags or 'V' in flags:
|
elif 'v' in flags or 'V' in flags:
|
||||||
chdata['amode'][username] = 'v'
|
chdata['amode'][username] = 'v'
|
||||||
|
elif 'S' in flags:
|
||||||
|
# take the first entry as the successor
|
||||||
|
if not chdata.get('successor'):
|
||||||
|
chdata['successor'] = username
|
||||||
else:
|
else:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# do some basic integrity checks
|
# do some basic integrity checks
|
||||||
|
def validate_user(name):
|
||||||
|
if not name:
|
||||||
|
return False
|
||||||
|
return bool(out['users'].get(name))
|
||||||
|
|
||||||
|
invalid_channels = []
|
||||||
|
|
||||||
for chname, chdata in out['channels'].items():
|
for chname, chdata in out['channels'].items():
|
||||||
founder = chdata.get('founder')
|
if not validate_user(chdata.get('founder')):
|
||||||
if founder not in out['users']:
|
if validate_user(chdata.get('successor')):
|
||||||
raise ValueError("no user corresponding to channel founder", chname, chdata.get('founder'))
|
chdata['founder'] = chdata['successor']
|
||||||
|
else:
|
||||||
|
invalid_channels.append(chname)
|
||||||
|
|
||||||
|
for chname in invalid_channels:
|
||||||
|
logging.warning("Unable to find a valid founder for channel %s, discarding it", chname)
|
||||||
|
del out['channels'][chname]
|
||||||
|
|
||||||
return out
|
return out
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user