From 8076a215e0de64345e19bfdb7ce63d4c670f5d89 Mon Sep 17 00:00:00 2001 From: Oliver Hartmann Date: Tue, 11 May 2021 22:39:58 +0200 Subject: [PATCH] Send message to poe if "@user " is detected --- config.yaml | 1 + src/clipboard.py | 13 +++++++++---- src/data.py | 5 ++++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/config.yaml b/config.yaml index 518be07..15c21c8 100644 --- a/config.yaml +++ b/config.yaml @@ -13,3 +13,4 @@ Chat: 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)|(''d)) like to buy your ?(?P\d*) (?P.+) (listed )?for (my )?(?P\d+) (?P\D+) in (?P\w+)\.?( \(stash tab "(?P.+)"; position: left (?P\d+), top (?P\d+)\))?' + re_clipboard_prefix: '^@(?P\S+) ' # this regex is used as a prefix for re_trade diff --git a/src/clipboard.py b/src/clipboard.py index cc9c254..bd058c9 100644 --- a/src/clipboard.py +++ b/src/clipboard.py @@ -1,6 +1,7 @@ import tkinter as tk import time from . import data +from src import sendkeys def clipboard_poll(app: tk) -> None: @@ -14,8 +15,12 @@ def clipboard_poll(app: tk) -> None: if new_text != text: data.log.info(new_text) text = new_text - res = data.re_clipboard.search(text) - if res: - trade = data.Trade.by_regex_result(res) - data.log.info(trade) + res_prefix = data.re_clipboard_prefix.search(text) + if res_prefix: + data.log.info(f'User: {res_prefix["user"]}') + res = data.re_clipboard.search(text) + sendkeys.send_text(text) + if res: + trade = data.Trade.by_regex_result(res) + data.log.info(trade) time.sleep(0.2) diff --git a/src/data.py b/src/data.py index 965b6d6..041589b 100644 --- a/src/data.py +++ b/src/data.py @@ -12,12 +12,14 @@ re_log = re.compile( r'(?P[#@%$&]?)(?PTo|From)?\s?(?P<\S+>)? ?(?P[^:]+): (?P.*)' ) re_clipboard = None +re_clipboard_prefix = None + log = logging.getLogger(__name__) logging.basicConfig(level=logging.DEBUG, format='%(levelname)-8s:: %(message)s') def compile_regex(conf: dict): - global re_trade, re_log, re_clipboard + global re_trade, re_log, re_clipboard, re_clipboard_prefix if 'General' in conf: if 're_log' in conf['Parser']: re_log = re.compile(conf['Parser']['re_log']) @@ -25,6 +27,7 @@ def compile_regex(conf: dict): re_trade = re.compile(conf['Parser']['re_trade']) if 're_clipboard_prefix' in conf['Parser']: re_clipboard = re.compile(conf['Parser']['re_clipboard_prefix'] + conf['Parser']['re_trade']) + re_clipboard_prefix = re.compile(conf['Parser']['re_clipboard_prefix'] + '.*') class Channel(Enum):