-
Notifications
You must be signed in to change notification settings - Fork 0
/
siftdude.py
183 lines (155 loc) · 6.7 KB
/
siftdude.py
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
import requests
import json
import os
import time
import threading
import re
import random
import pygame
import colorama
import clipboard
import keyboard
import pyautogui
# Initialize colorama
colorama.init()
# Set to keep track of retrieved message IDs and user messages
retrieved_message_ids = set()
user_messages = set()
# Variable to indicate if the script is running
running = True
# Function to save auto action coordinates to a file
def save_auto_action_coordinates(x, y, filename):
with open(filename, "w") as f:
f.write(f"{x},{y}")
# Function to load auto action coordinates from a file
def load_auto_action_coordinates(filename):
try:
with open(filename, "r") as f:
coordinates = f.read().strip().split(',')
if len(coordinates) == 2:
return int(coordinates[0]), int(coordinates[1])
except (FileNotFoundError, ValueError):
pass
return None
# Function to get confirmation for coordinates
def get_coordinates_confirmation(filename, action_name):
use_existing = input(f"Would you like to use the last {action_name} coordinates? (y/n): ")
if use_existing.lower() == 'y':
existing_coordinates = load_auto_action_coordinates(filename)
if existing_coordinates:
print(f"Using existing {action_name} coordinates: {existing_coordinates}")
return existing_coordinates
print(f"Please hover your mouse over the {action_name} and press 's' to save the coordinates.")
keyboard.wait('s', suppress=True)
new_coordinates = pyautogui.position()
save_auto_action_coordinates(new_coordinates[0], new_coordinates[1], filename)
print(f"New {action_name} coordinates saved: {new_coordinates}")
return new_coordinates
# Read the filename of the JSON file from config.json
config_filename = "config.json"
try:
with open(config_filename, 'r') as config_file:
config_data = json.load(config_file)
except (FileNotFoundError, json.JSONDecodeError):
config_data = {} # If there's an error or the file doesn't exist, initialize an empty config dictionary
# Load the settings from the specified file
settings_filename = config_data.get("config_filename", "settings.json")
try:
with open(settings_filename, 'r') as settings_file:
settings_data = json.load(settings_file)
bot_token = settings_data.get("bot_token", "")
target_user_ids = settings_data.get("target_user_ids", [])
target_channels = settings_data.get("target_channels", [])
auto_action_mode = settings_data.get("auto_action_mode", False)
textbox_coordinates_file_name = settings_data.get("textbox_coordinates_file_name", "textbox_coordinates.txt")
redeem_coordinates_file_name = settings_data.get("redeem_coordinates_file_name", "redeem_coordinates.txt")
except (FileNotFoundError, json.JSONDecodeError):
bot_token = ""
target_user_ids = []
target_channels = []
auto_action_mode = False
textbox_coordinates_file_name = "textbox_coordinates.txt"
redeem_coordinates_file_name = "redeem_coordinates.txt"
# Check if auto action mode is enabled
textbox_coordinates = None
empty_space_coordinates = None
redeem_coordinates = None
if auto_action_mode:
textbox_coordinates = get_coordinates_confirmation(textbox_coordinates_file_name, "textbox")
# Prompt for an empty space between textbox and redeem
empty_space_coordinates = get_coordinates_confirmation("empty_space_coordinates.txt", "empty space")
redeem_coordinates = get_coordinates_confirmation(redeem_coordinates_file_name, "redeem button")
else:
print("Auto action mode is disabled.")
def display_message(channelid, message):
message_id = message.get('id')
if message_id not in retrieved_message_ids:
retrieved_message_ids.add(message_id)
author_id = message.get('author', {}).get('id')
content = message.get('content')
if author_id in target_user_ids and content not in user_messages:
lines = content.split('\n')
if len(lines) > 1:
cleaned_content = random.choice(lines)
else:
cleaned_content = lines[0]
copy_to_clipboard(cleaned_content)
play_sound("t.mp3") # Play the sound "t.mp3"
if auto_action_mode:
# Click the textbox (twice)
pyautogui.click(textbox_coordinates[0], textbox_coordinates[1])
time.sleep(0.05)
pyautogui.click(textbox_coordinates[0], textbox_coordinates[1])
keyboard.press_and_release('ctrl+a')
time.sleep(0.05)
keyboard.press_and_release('ctrl+a')
keyboard.press_and_release('ctrl+v')
pyautogui.click(empty_space_coordinates[0], empty_space_coordinates[1])
# Click the redeem button (twice)
pyautogui.click(redeem_coordinates[0], redeem_coordinates[1])
pyautogui.click(redeem_coordinates[0], redeem_coordinates[1])
print(colorama.Fore.GREEN + "Auto redeem done")
print(colorama.Style.RESET_ALL)
if cleaned_content.strip(): # Check if the cleaned content is not empty
print(colorama.Fore.YELLOW + "Message:")
print(cleaned_content)
print(colorama.Style.RESET_ALL)
user_messages.add(content)
def retrieve_latest_messages(channelid):
headers = {
'authorization': bot_token
}
params = {
'limit': 1 # Update to retrieve the last 5 messages
}
r = requests.get(f'https://discord.com/api/v8/channels/{channelid}/messages', headers=headers, params=params)
try:
messages = json.loads(r.text)
except json.JSONDecodeError as e:
print("JSON decode error:", e)
return []
if not isinstance(messages, list) or len(messages) == 0:
return []
return messages
def play_sound(sound_filename):
try:
pygame.mixer.init()
pygame.mixer.music.load(sound_filename)
pygame.mixer.music.play()
except Exception as e:
print("Error playing sound:", e)
# Copy the message content to the clipboard
def copy_to_clipboard(content):
clipboard.copy(content)
# Set the loop to run indefinitely
while True:
if running and bot_token and target_user_ids and target_channels:
headers = {
'authorization': bot_token
}
for channel_id in target_channels:
latest_messages = retrieve_latest_messages(channel_id)
if latest_messages:
for message in latest_messages:
display_message(channel_id, message)
time.sleep(0.05) # Add a wait time of 0.05 seconds before the next iteration