From 21120c03a0594a30c916689bf1a1bca655a0c249 Mon Sep 17 00:00:00 2001 From: Noah Date: Mon, 28 Aug 2023 23:31:20 -0700 Subject: [PATCH] improved targeted responses --- src/pywiki_lite.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/pywiki_lite.py b/src/pywiki_lite.py index c42c65c..453b0d8 100644 --- a/src/pywiki_lite.py +++ b/src/pywiki_lite.py @@ -44,7 +44,7 @@ def resource_path(relative_path): def get_version(): - return "1.64" # Version Number + return "1.65" # Version Number class TwitchBotGUI(tk.Tk): @@ -270,7 +270,13 @@ def message_user(self, event): if selected_index: item_index = int(selected_index[0]) selected_item = self.user_list.get(item_index) - thread = threading.Thread(target=lambda: self.bot.generate_response(selected_item, '@ ' + selected_item)) + if selected_item.lower() in self.bot.last_message.keys(): + thread = threading.Thread( + target=lambda: self.bot.generate_response(selected_item, + self.bot.last_message[selected_item.lower()])) + else: + thread = threading.Thread( + target=lambda: self.bot.generate_response(selected_item, '@ ' + selected_item)) thread.start() def show_popup(self, event): @@ -560,12 +566,14 @@ def __init__(self, username, client_id, client_secret, token, channel, openai_ap + '&grant_type=client_credentials' + '').json() + print(self.client_credentials) self.openai_api_key = openai_api_key openai.api_key = self.openai_api_key self.pronoun_cache = {} self.users = [] self.message_queue = collections.deque(maxlen=10) + self.last_message = {} self.verify() self.channel_id = self.get_channel_id(channel) @@ -793,6 +801,7 @@ def get_game_info(self, game, **kwargs): data = 'fields *; where name ~ "' + escape(game) + '";' print(data) response = requests.post(url, headers=headers, data=data) + print(response) game_info = json.dumps(response.json()) print(game_info) return game_info @@ -1087,6 +1096,7 @@ def on_pubmsg(self, c, e): print(author + ": " + message) app.append_to_log(author + ": " + message) self.message_queue.append(author + ": " + message) + self.last_message[author.lower()] = message # If a chat message starts with an exclamation point, try to run it as a command if e.arguments[0].startswith('!'):