from enum import Enum import re import datetime re_trade = re.compile( r'Hi, I would like to buy your (?P.+) listed for (?P\d+) (?P\S+) in (?P\S+) ' r'\(stash tab "(?P.+)"; position: left (?P\d+), top (?P\d+)\)' ) class Channel(Enum): WHISPER = 0 GLOBAL = 1 PARTY = 2 LOCAL = 3 TRADE = 4 GUILD = 5 channel_mapping = {'#': Channel.GLOBAL, '@': Channel.WHISPER, '%': Channel.PARTY, '': Channel.LOCAL, '$': Channel.TRADE, '&': Channel.GUILD} class Trade(): def __init__(self, item: str, amount: int, currency: str, tab: str, row: int, col: int, league: str) -> None: self.item = item self.amount = amount self.currency = currency self.tab = tab self.row = row self.col = col self.league = league class Message(): def __init__(self, message: str, date: datetime.datetime, user: str, channel: Channel, guild: str = None, to_from: str = None) -> None: self.message = message self.date = date self.channel = channel self.user = user self.guild = guild self.to_from = to_from self.trade = None if self.channel is Channel.WHISPER: self.parse_trade() def __str__(self) -> str: text = f'{self.date} - {self.channel.name}: ' if self.to_from: text = text + f'{self.to_from} ' if self.guild: text = text + f'<{self.guild}> ' text = text + f'{self.user}: {self.message}' return text def parse_trade(self) -> None: res = re_trade.search(self.message) if res: self.trade = Trade(item=res['item'], amount=int(res['amount']), currency=res['currency'], tab=res['tab'], row=int(res['row']), col=int(res['col']), league=res['league'])