Some more sendkeys messages

This commit is contained in:
Oliver Hartmann 2021-03-14 14:02:57 +01:00
parent d67b574969
commit 1c50451187
3 changed files with 55 additions and 16 deletions

View File

@ -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<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<ToFrom>To|From)?\s?(?P<guild><\S+>)? ?(?P<user>[^:]+): (?P<message>.*)'
re_trade: 'Hi, I would like to buy your (?P<item>.+) listed for (?P<amount>\d+) (?P<currency>\S+) in (?P<league>\S+) \(stash tab "(?P<tab>.+)"; position: left (?P<col>\d+), top (?P<row>\d+)\)'

View File

@ -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}')

View File

@ -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)
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)