diff --git a/config.yaml b/config.yaml index d191493..d732fa9 100644 --- a/config.yaml +++ b/config.yaml @@ -2,9 +2,12 @@ General: log_file: 'D:\Poe\logs\Client.txt' log_level: 'DEBUG' Chat: + # Define chat messages with the following placeholders: + # message, date, channel, user, guild, to_from, item, amount, currency, tab, row, col, league, pickup: 'Your item {item} for {amount} {currency} is ready to pickup.' wait: 'I am currently busy. Please wait.' ty: 'Thank you and good luck.' + sold: 'Sorry, {item} is already sold' Parser: re_log: '(?P\d\d\d\d/\d\d/\d\d \d\d:\d\d:\d\d) (\d+) (\S+) \[(?P\S+) (\S+) (\d+)\] (?P[#@%$&]?)(?PTo|From)?\s?(?P<\S+>)? ?(?P[^:]+): (?P.*)' re_trade: 'Hi, I would like to buy your (?P.+) listed for (?P\d+) (?P\S+) in (?P\S+) \(stash tab "(?P.+)"; position: left (?P\d+), top (?P\d+)\)' diff --git a/src/sendkeys.py b/src/sendkeys.py index 3e9e8e3..142854f 100644 --- a/src/sendkeys.py +++ b/src/sendkeys.py @@ -1,32 +1,54 @@ from pywinauto.application import Application +from src import data def send_text(text: str) -> None: app = Application() app.connect(title='Path of Exile') win = app.window_(title_re='Path of Exile') + text = escape_mods(text) win.TypeKeys('{ENTER}^A{DELETE}' + text + '{ENTER}', with_spaces=True) +def escape_mods(text: str) -> str: + text = text.replace('%', '{%}') + text = text.replace('+', '{+}') + text = text.replace('^', '{^}') + return text + + def send_to(user: str, text: str) -> None: send_text(f'@{user} {text}') -def invite(user: str) -> None: - send_text(f'/invite {user}') +def send_to_format(type: str, message: data.Message, conf: dict()) -> None: + """[summary] + + Args: + type (str): [description] + message (data.Message): [description] + conf (dict): [description] + """ + text = conf['Chat'][type].format(message=message.message, + date=message.date, + channel=message.channel.name, + user=message.user, + guild=message.guild, + to_from=message.to_from, + item=message.trade.item, + amount=message.trade.amount, + currency=message.trade.currency, + tab=message.trade.tab, + row=message.trade.row, + col=message.trade.col, + league=message.trade.league) + send_to(message.user, text) -def send_ty(user: str, conf: dict) -> None: - send_to(user, conf['Chat']['ty']) +def invite(message: data.Message) -> None: + send_text(f'/invite {message.user}') -def send_wait(user: str, conf: dict) -> None: - send_to(user, conf['Chat']['wait']) - - -def send_pickup(user: str, item: str, amount: int, currency: str, conf: dict) -> None: - text = conf['Chat']['pickup'].replace('{item}', item) - text = text.replace('{amount}', str(amount)) - text = text.replace('{currency}', currency) - send_to(user, text) +def trade(message: data.Message) -> None: + send_text(f'/tradewith {message.user}') diff --git a/tests/test_keyboard.py b/tests/test_keyboard.py index 6ad1a2b..34812c4 100644 --- a/tests/test_keyboard.py +++ b/tests/test_keyboard.py @@ -1,5 +1,6 @@ from src import sendkeys from src import config +from src import data def test_sendkeys(): @@ -7,12 +8,16 @@ def test_sendkeys(): def test_send_to(): - sendkeys.send_to('Sinusal', 'Hi, how are you?') + sendkeys.send_to('Sinusal', 'Your item level 21 23% Vaal Impurity of Lightning for 18 chaos is ready to pickup.') def test_pickup(): conf = config.read_config(r'config.yaml') - sendkeys.send_pickup('Sinusal', 'Watcher\'s Eye', 11, 'Exalts', conf) + data.compile_regex(conf) + text = '2021/03/08 23:24:52 17931875 bb3 [INFO Client 1492] @From Sinusal: Hi, I would like to buy your level 21 23% Vaal Impurity of Lightning ' \ + 'listed for 18 chaos in Ritual (stash tab "$"; position: left 22, top 5)' + message = data.Message.from_text(text) + sendkeys.send_to_format('pickup', message, conf) def test_wait(): @@ -22,4 +27,13 @@ def test_wait(): def test_ty(): conf = config.read_config(r'config.yaml') - sendkeys.send_ty('Sinusal', conf) \ No newline at end of file + sendkeys.send_ty('Sinusal', conf) + + +def test_sold(): + conf = config.read_config(r'config.yaml') + data.compile_regex(conf) + text = '2021/03/08 23:24:52 17931875 bb3 [INFO Client 1492] @From Sinusal: Hi, I would like to buy your level 21 23% Vaal Impurity of Lightning ' \ + 'listed for 18 chaos in Ritual (stash tab "$"; position: left 22, top 5)' + message = data.Message.from_text(text) + sendkeys.send_to_format('sold', message, conf)