From e815476da4780fd7956023e6c46d5d35d0bc5519 Mon Sep 17 00:00:00 2001 From: spla Date: Sat, 28 Jan 2023 21:19:15 +0100 Subject: [PATCH] =?UTF-8?q?No=20respon=20si=20es=20mencionen=20dos=20o=20m?= =?UTF-8?q?=C3=A9s=20usuaris.=20Ja=20dona=20respostes=20de=20tres=20o=20m?= =?UTF-8?q?=C3=A9s=20tuts?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- mastobot.py | 45 ++++++++++++++++++++++++++++++++++++++++----- post.py | 8 ++++++-- xatapi.py | 2 +- 3 files changed, 47 insertions(+), 8 deletions(-) diff --git a/mastobot.py b/mastobot.py index de8f528..b75d278 100644 --- a/mastobot.py +++ b/mastobot.py @@ -83,6 +83,8 @@ if __name__ == '__main__': for notif in notifications: + post_array = [] + notification_id = notif.id if notif.type != 'mention': @@ -107,6 +109,20 @@ if __name__ == '__main__': if reply == True: + content = cleanhtml(text) + + search_char = '@' + + counter = len([element for element in content.split() if search_char in element]) + + if counter > 1: + + print(f'Notification {notification_id} dissmised') + + mastodon.notifications_dismiss(notification_id) + + continue + prompt = unescape(query_word) if prompt[:7] == 'imatge:': @@ -126,6 +142,8 @@ if __name__ == '__main__': mastodon.status_post(post_text, in_reply_to_id=status_id, media_ids={image_id}, visibility=visibility) + mastodon.notifications_dismiss(notification_id) + else: post_text = f'@{username} {prompt[8:]}' @@ -134,6 +152,8 @@ if __name__ == '__main__': mastodon.status_post(post_text, in_reply_to_id=status_id, visibility=visibility) + mastodon.notifications_dismiss(notification_id) + except: pass @@ -142,6 +162,10 @@ if __name__ == '__main__': mastodon.status_post(post_text, in_reply_to_id=status_id, visibility=visibility) + print(f'Notification {notification_id} replied') + + mastodon.notifications_dismiss(notification_id) + else: post = Post() @@ -154,17 +178,28 @@ if __name__ == '__main__': post_array = post.split(answer, username) - for postit in post_array: + i = 0 + while i < len(post_array): - post_id = mastodon.status_post(postit, in_reply_to_id=status_id,visibility=visibility).id + print(f'array element: {i} of {len(post_array)}, username: {username}, status_id: {status_id}, post: {post_array[i]}') + + post_id = mastodon.status_post(post_array[i], in_reply_to_id=status_id, visibility=visibility).id status_id = post_id - time.sleep(2) + i += 1 - print(f'Notification {notification_id} replied') + print(f'Notification {notification_id} replied') - mastodon.notifications_dismiss(notification_id) + mastodon.notifications_dismiss(notification_id) + + if isinstance(post, Post): + + post.clear() + + time.sleep(1) + + continue else: diff --git a/post.py b/post.py index 2c8c449..1e81b0c 100644 --- a/post.py +++ b/post.py @@ -11,6 +11,10 @@ class Post: self.n = n self.array = array + def clear(self): + + self.array.clear() + def split(self, post, username): self.post = post @@ -22,7 +26,7 @@ class Post: self.n = post_len / 500 start = 0 - end = 494 + end = 488 i = 0 while i < self.n: @@ -32,7 +36,7 @@ class Post: self.array.append(post) start = end-len(self.username) - end = end + 494 + end = end + 488 i += 1 diff --git a/xatapi.py b/xatapi.py index fe447ab..3681649 100644 --- a/xatapi.py +++ b/xatapi.py @@ -50,7 +50,7 @@ class Xat: data = { 'model': "text-davinci-003", 'prompt': prompt, - 'max_tokens': 500, + 'max_tokens': 750, 'temperature': 0 }