-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path03_Bot.py
More file actions
68 lines (51 loc) · 2.43 KB
/
03_Bot.py
File metadata and controls
68 lines (51 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#this AI bot will chat with only person who chat history has been given
# to this openai file, this will analysis chat and reply accordingly
import pyautogui
import time
import pyperclip
from openai import OpenAI
client = OpenAI(
api_key="Your OpenAI API Key",
)
def is_last_message_from_sender(chat_log, sender_name="Thy Professor Gb"):
# Split the chat log into individual messages
messages = chat_log.strip().split("/2024] ")[-1]
if sender_name in messages:
return True
return False
# Step 1: Click on the chrome icon at coordinates (1639, 1412)
pyautogui.click(1400, 1044)
time.sleep(1) # Wait for 1 second to ensure the click is registered
while True:
time.sleep(5)
# Step 2: Drag the mouse from (1003, 237) to (2187, 1258) to select the text
pyautogui.moveTo(898,299)
pyautogui.dragTo(1827, 888, duration=2.0, button='left') # Drag for 1 second
# Step 3: Copy the selected text to the clipboard
pyautogui.hotkey('ctrl', 'c')
time.sleep(2) # Wait for 1 second to ensure the copy command is completed
pyautogui.click(1892, 993)
# Step 4: Retrieve the text from the clipboard and store it in a variable
chat_history = pyperclip.paste()
# Print the copied text to verify
print(chat_history)
print(is_last_message_from_sender(chat_history))
if is_last_message_from_sender(chat_history):
completion = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a person named Raimal who speaks hindi as well as english. You are from Pakistan and you are a coder. You analyze chat history and roast people in a funny way. Output should be the next chat response (text message only)"},
{"role": "system", "content": "Do not start like this [21:02, 12/6/2024] Haroon: "},
{"role": "user", "content": chat_history}
]
)
response = completion.choices[0].message.content
pyperclip.copy(response)
# Step 5: Click at coordinates (1808, 1328)
pyautogui.click(1180, 957)
time.sleep(1) # Wait for 1 second to ensure the click is registered
# Step 6: Paste the text
pyautogui.hotkey('ctrl', 'v')
time.sleep(1) # Wait for 1 second to ensure the paste command is completed
# Step 7: Press Enter
pyautogui.press('enter')