Some fixes for the guild tag

This commit is contained in:
Oliver Hartmann 2021-03-08 22:22:53 +01:00
parent ee24f8a47b
commit f0e10a7679

View File

@ -22,14 +22,24 @@ channel_mapping = {'#': Channel.GLOBAL,
'&': Channel.GUILD} '&': Channel.GUILD}
class Message(): class Message():
def __init__(self, message: str, date: datetime.datetime, user: str, channel: Channel) -> None: def __init__(self,
message: str,
date: datetime.datetime,
user: str,
channel: Channel,
guild: str) -> None:
self.message = message self.message = message
self.date = date self.date = date
self.user = user self.user = user
self.channel = channel self.channel = channel
self.guild = guild
def __str__(self) -> str: def __str__(self) -> str:
return f'{self.date} - {self.channel.name}: {self.user}: {self.message}' text = f'{self.date} - {self.channel.name}: '
if self.guild:
text = text + f'<{self.guild}> '
text = text + f'{self.user}: {self.message}'
return text
def follow(thefile: str): def follow(thefile: str):
thefile.seek(0, 2) thefile.seek(0, 2)
@ -43,11 +53,14 @@ def follow(thefile: str):
def parse_string(text: str) -> Message: def parse_string(text: str) -> Message:
# result = parse('{date} {time} {timemicro} {noidea} [{level} {client} {id}]{mess_type:1}{user}: {message}', text) # result = parse('{date} {time} {timemicro} {noidea} [{level} {client} {id}]{mess_type:1}{user}: {message}', text)
result = re.search('(?P<date>\d\d\d\d/\d\d/\d\d \d\d:\d\d:\d\d) (\d+) (\S+) \[(?P<level>\S+) (\S+) (\d+)\] (?P<channel>[#@%$&]*)(?P<user>[^:]+): (?P<message>.*)', text) result = re.search('(?P<date>\d\d\d\d/\d\d/\d\d \d\d:\d\d:\d\d) (\d+) (\S+) \[(?P<level>\S+) (\S+) (\d+)\] (?P<channel>[#@%$&]?)(?P<guild><\S+>)? ?(?P<user>[^:]+): (?P<message>.*)', text)
if not result: if not result:
return None return None
date = datetime.datetime.strptime(result.group('date'), '%Y/%m/%d %H:%M:%S') date = datetime.datetime.strptime(result.group('date'), '%Y/%m/%d %H:%M:%S')
return Message(result.group('message'), date, result.group('user'), channel_mapping[result.group('channel')]) guild = result.group('guild')
if guild:
guild = guild.strip('<>')
return Message(result.group('message'), date, result.group('user'), channel_mapping[result.group('channel')], guild)
def setup_args() -> argparse.Namespace: def setup_args() -> argparse.Namespace: