-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
211 lines (176 loc) · 6.79 KB
/
main.py
File metadata and controls
211 lines (176 loc) · 6.79 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
"""
AI AutoReply Bot - Advanced Chat Automation
================
Features:
- Real-time chat monitoring using screen automation
- OpenAI GPT integration for intelligent responses
- Automatic message detection and reply
- Screen coordinate detection and interaction
- Clipboard operations for message handling
- Advanced chat history analysis
"""
import pyautogui
import time
import pyperclip
from openai import OpenAI
# Configuration
OPENAI_API_KEY = "<Your Key Here>"
# Screen coordinates (you need to adjust these for your screen)
CHROME_ICON = (1639, 1412)
CHAT_SELECT_START = (972, 202)
CHAT_SELECT_END = (2213, 1278)
MESSAGE_BOX = (1808, 1328)
CLICK_POSITION = (1994, 281)
# Initialize OpenAI client
client = OpenAI(api_key=OPENAI_API_KEY)
def get_screen_coordinates():
"""Helper function to get current mouse coordinates """
print("Move mouse to desired position and press Ctrl+C to get coordinates")
print("Press Ctrl+Break to stop")
while True:
try:
position = pyautogui.position()
print(f"Current position: {position}")
time.sleep(1)
except KeyboardInterrupt:
break
def is_last_message_from_sender(chat_log, sender_name="Rohan Das"):
"""
Check if the last message in chat log is from specified sender
"""
# Split the chat log into individual messages
messages = chat_log.strip().split("/2024] ")[-1]
if sender_name in messages:
return True
return False
def generate_ai_response(chat_history):
"""Generate intelligent response using OpenAI GPT"""
try:
completion = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[
{"role": "system", "content": "You are a person named Naruto who speaks hindi as well as english. You are from India 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] Rohan Das: "},
{"role": "user", "content": chat_history}
]
)
return completion.choices[0].message.content
except Exception as e:
return f"Sorry, having technical difficulties! 🤖 Error: {str(e)[:50]}..."
def send_message(message):
"""Send message through chat interface"""
# Copy message to clipboard
pyperclip.copy(message)
# Click on message box
pyautogui.click(MESSAGE_BOX)
time.sleep(1)
# Paste the message
pyautogui.hotkey('ctrl', 'v')
time.sleep(1)
# Press Enter to send
pyautogui.press('enter')
print(f"✅ Sent: {message}")
def capture_chat_history():
"""Capture chat history from screen"""
# Drag to select chat text
pyautogui.moveTo(CHAT_SELECT_START)
pyautogui.dragTo(CHAT_SELECT_END, duration=2.0, button='left')
# Copy selected text
pyautogui.hotkey('ctrl', 'c')
time.sleep(2)
pyautogui.click(CLICK_POSITION)
# Get text from clipboard
chat_history = pyperclip.paste()
return chat_history
def main_bot():
"""Main bot function"""
print("🤖 AI AutoReply Bot Starting...")
print("=" * 50)
# Click on Chrome icon to focus
print("Focusing on browser...")
pyautogui.click(CHROME_ICON)
time.sleep(1)
print("🚀 Bot is now active! Monitoring chat...")
print("Press Ctrl+C to stop the bot")
while True:
try:
time.sleep(5) # Check every 5 seconds
# Capture current chat history
chat_history = capture_chat_history()
print("📱 Checking for new messages...")
print(f"Last few characters: ...{chat_history[-100:]}")
# Check if last message is from sender (not us)
if is_last_message_from_sender(chat_history):
print("🔔 New message detected! Generating response...")
# Generate AI response
response = generate_ai_response(chat_history)
print(f"🤖 Generated response: {response}")
# Send the response
send_message(response)
# Wait a bit before next check
time.sleep(10)
except KeyboardInterrupt:
print("\n🛑 Bot stopped by user")
break
except Exception as e:
print(f"❌ Error: {e}")
time.sleep(5)
def setup_coordinates():
"""Helper to set up screen coordinates"""
print("🔧 Screen Coordinate Setup")
print("=" * 30)
print("This helps you find the correct coordinates for your screen")
print("Current coordinates in use:")
print(f"Chrome Icon: {CHROME_ICON}")
print(f"Chat Selection: {CHAT_SELECT_START} to {CHAT_SELECT_END}")
print(f"Message Box: {MESSAGE_BOX}")
print("\nTo get new coordinates, run the coordinate detector:")
choice = input("Run coordinate detector? (y/n): ")
if choice.lower() == 'y':
get_screen_coordinates()
def test_openai():
"""Test OpenAI integration"""
print("🧪 Testing OpenAI Integration...")
test_command = '''
[20:30, 12/6/2024] Naruto: jo sunke coding ho sake?
[20:30, 12/6/2024] Rohan Das: https://www.youtube.com/watch?v=DzmG-4-OASQ
[20:30, 12/6/2024] Rohan Das: ye
[20:30, 12/6/2024] Rohan Das: https://www.youtube.com/watch?v=DzmG-4-OASQ
[20:31, 12/6/2024] Naruto: This is hindi
[20:31, 12/6/2024] Naruto: send me some english songs
[20:31, 12/6/2024] Naruto: but wait
[20:31, 12/6/2024] Naruto: this song is amazing
[20:31, 12/6/2024] Naruto: so I will stick to it
[20:31, 12/6/2024] Naruto: send me some english song also
[20:31, 12/6/2024] Rohan Das: hold on
[20:31, 12/6/2024] Naruto: I know what you are about to send
[20:32, 12/6/2024] Naruto: 😂😂
[20:32, 12/6/2024] Rohan Das: https://www.youtube.com/watch?v=ar-3chBG4NU
ye hindi English mix hai but best hai
[20:33, 12/6/2024] Naruto: okok
[20:33, 12/6/2024] Rohan Das: Haan
'''
response = generate_ai_response(test_command)
print(f"✅ AI Response: {response}")
if __name__ == "__main__":
print("🤖 AI AutoReply Bot")
print("=" * 50)
print("Choose an option:")
print("1. Start Auto-Reply Bot")
print("2. Setup Screen Coordinates")
print("3. Test OpenAI Integration")
print("4. Get Current Mouse Coordinates")
choice = input("\nEnter choice (1-4): ")
if choice == "1":
if OPENAI_API_KEY == "<Your Key Here>":
print("⚠️ Please set your OpenAI API key first!")
else:
main_bot()
elif choice == "2":
setup_coordinates()
elif choice == "3":
test_openai()
elif choice == "4":
get_screen_coordinates()
else:
print("Invalid choice!")