Hashir Kashif commited on
Commit ·
9157c1b
1
Parent(s): 692102f
Add application file
Browse files- app.py +266 -0
- channels.txt +0 -0
- packages.txt +1 -0
- pending.txt +0 -0
- requirements.txt +2 -0
- screenshot.png +0 -0
app.py
ADDED
|
@@ -0,0 +1,266 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import time
|
| 2 |
+
import gradio as gr
|
| 3 |
+
import threading
|
| 4 |
+
from selenium import webdriver
|
| 5 |
+
from selenium.webdriver.chrome.options import Options
|
| 6 |
+
from selenium.webdriver.common.by import By
|
| 7 |
+
from selenium.webdriver.support.wait import WebDriverWait
|
| 8 |
+
from selenium.webdriver.support import expected_conditions as EC
|
| 9 |
+
from selenium.webdriver.common.keys import Keys
|
| 10 |
+
import secrets
|
| 11 |
+
import os
|
| 12 |
+
total_dm_done = 0
|
| 13 |
+
def in_dm_code(driver, server_link):
|
| 14 |
+
time.sleep(1)
|
| 15 |
+
text_box = driver.find_element(By.CSS_SELECTOR,"[role='textbox']")
|
| 16 |
+
text_box.send_keys("Joining w8")
|
| 17 |
+
time.sleep(1)
|
| 18 |
+
text_box.send_keys(Keys.ENTER)
|
| 19 |
+
time.sleep(3)
|
| 20 |
+
text_box = driver.find_element(By.CSS_SELECTOR,"[role='textbox']")
|
| 21 |
+
# join server
|
| 22 |
+
try:
|
| 23 |
+
join_btn = WebDriverWait(driver, 3).until(
|
| 24 |
+
EC.presence_of_element_located((By.XPATH, "//button/div[contains(text(), 'Join')]"))
|
| 25 |
+
)
|
| 26 |
+
except:
|
| 27 |
+
current_channel_url = driver.current_url
|
| 28 |
+
current_channel = current_channel_url[current_channel_url.find("@me/"):].replace("@me/", "")
|
| 29 |
+
# send link code
|
| 30 |
+
with open('pending.txt') as file:
|
| 31 |
+
contents = file.read()
|
| 32 |
+
search_word = current_channel
|
| 33 |
+
if str(search_word) +"2" in contents:
|
| 34 |
+
print('Already pending..Sending last message')
|
| 35 |
+
text_box.send_keys("Now don't message me again understood")
|
| 36 |
+
time.sleep(0.5)
|
| 37 |
+
text_box.send_keys(Keys.ENTER)
|
| 38 |
+
global total_dm_done
|
| 39 |
+
total_dm_done-=1
|
| 40 |
+
return True
|
| 41 |
+
elif str(search_word) +"1" in contents:
|
| 42 |
+
current_channel = str(current_channel) + "2"
|
| 43 |
+
print('Already pending..Giving last chance')
|
| 44 |
+
text_box.send_keys("bro send join link??")
|
| 45 |
+
time.sleep(0.5)
|
| 46 |
+
text_box.send_keys(Keys.ENTER)
|
| 47 |
+
file = open("pending.txt", "a") # append mode
|
| 48 |
+
file.write(f"{current_channel} \n")
|
| 49 |
+
file.close()
|
| 50 |
+
return False
|
| 51 |
+
|
| 52 |
+
else:
|
| 53 |
+
current_channel = str(current_channel) + "1"
|
| 54 |
+
print("New channel working on it")
|
| 55 |
+
file = open("pending.txt", "a") # append mode
|
| 56 |
+
file.write(f"{current_channel} \n")
|
| 57 |
+
file.close()
|
| 58 |
+
text_box.send_keys("Send join link asap")
|
| 59 |
+
time.sleep(1)
|
| 60 |
+
text_box.send_keys(Keys.ENTER)
|
| 61 |
+
return False
|
| 62 |
+
driver.execute_script("""function getElementsByXPath(xpath, parent)
|
| 63 |
+
{
|
| 64 |
+
let results = [];
|
| 65 |
+
let query = document.evaluate(xpath, parent || document,
|
| 66 |
+
null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
|
| 67 |
+
for (let i = 0, length = query.snapshotLength; i < length; ++i) {
|
| 68 |
+
results.push(query.snapshotItem(i));
|
| 69 |
+
}
|
| 70 |
+
return results;
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
var div_list = getElementsByXPath("//button/div[contains(text(), 'Join')]")
|
| 74 |
+
var div_array = [...div_list]; // converts NodeList to Array
|
| 75 |
+
div_array.forEach(div => {
|
| 76 |
+
|
| 77 |
+
div.innerHTML = "Joined";
|
| 78 |
+
|
| 79 |
+
}); """)
|
| 80 |
+
time.sleep(1)
|
| 81 |
+
driver.save_screenshot("./screenshot.png")
|
| 82 |
+
time.sleep(0.5)
|
| 83 |
+
|
| 84 |
+
# plus_icon = driver.find_element(By.CSS_SELECTOR, "[aria-label='Upload a file or send invites']").click()
|
| 85 |
+
# time.sleep(1)
|
| 86 |
+
input_element = driver.find_element(By.CSS_SELECTOR, "[class='file-input']")
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
input_element.send_keys(os.getcwd()+'/screenshot.png')
|
| 90 |
+
time.sleep(2)
|
| 91 |
+
text_box.send_keys("see")
|
| 92 |
+
time.sleep(0.5)
|
| 93 |
+
text_box.send_keys(Keys.ENTER)
|
| 94 |
+
# join_btn.click()
|
| 95 |
+
# time.sleep(5)
|
| 96 |
+
# # go back after joining
|
| 97 |
+
# driver.execute_script("window.history.go(-1)")
|
| 98 |
+
time.sleep(2)
|
| 99 |
+
|
| 100 |
+
|
| 101 |
+
text_box.send_keys("done")
|
| 102 |
+
time.sleep(0.5)
|
| 103 |
+
text_box.send_keys(Keys.ENTER)
|
| 104 |
+
time.sleep(0.5)
|
| 105 |
+
text_box.send_keys(server_link)
|
| 106 |
+
time.sleep(0.5)
|
| 107 |
+
text_box.send_keys(Keys.ENTER)
|
| 108 |
+
time.sleep(0.5)
|
| 109 |
+
text_box.send_keys("Now you join")
|
| 110 |
+
time.sleep(1.5)
|
| 111 |
+
text_box.send_keys(Keys.ENTER)
|
| 112 |
+
time.sleep(1)
|
| 113 |
+
return True
|
| 114 |
+
|
| 115 |
+
def j4j_msg_req(invites, server_link):
|
| 116 |
+
global stop_thread
|
| 117 |
+
options = Options()
|
| 118 |
+
options.add_experimental_option("excludeSwitches", ["enable-logging"])
|
| 119 |
+
|
| 120 |
+
# for headless chrome
|
| 121 |
+
# ----
|
| 122 |
+
options.add_argument("--no-sandbox")
|
| 123 |
+
options.add_argument("--headless=new")
|
| 124 |
+
options.add_argument('--disable-gpu')
|
| 125 |
+
options.add_argument("--disable-dev-shm-usage")
|
| 126 |
+
#-----
|
| 127 |
+
options.add_argument('user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, likeGecko) Chrome/68.0.3440.84 Safari/537.36')
|
| 128 |
+
|
| 129 |
+
driver = webdriver.Chrome(options=options)
|
| 130 |
+
|
| 131 |
+
driver.get("https://discord.com/login")
|
| 132 |
+
time.sleep(5)
|
| 133 |
+
driver.execute_script("""function login(token) {
|
| 134 |
+
setInterval(() => {
|
| 135 |
+
document.body.appendChild(document.createElement `iframe`).contentWindow.localStorage.token = `"${token}"`
|
| 136 |
+
}, 50);
|
| 137 |
+
|
| 138 |
+
}
|
| 139 |
+
|
| 140 |
+
login('NzczODEwMjIzMTc2NjEzOTI4.G4QxbX.9kvMIM-NLjrxQV9sDTPPnzL6rlp4Wy7-1XYKyE');""")
|
| 141 |
+
time.sleep(5)
|
| 142 |
+
driver.get("https://discord.com/channels/@me/")
|
| 143 |
+
time.sleep(5)
|
| 144 |
+
setting_check = WebDriverWait(driver, 30).until(
|
| 145 |
+
EC.presence_of_element_located((By.CSS_SELECTOR, "[aria-label='User Settings']"))
|
| 146 |
+
)
|
| 147 |
+
|
| 148 |
+
print("logged in succesfully")
|
| 149 |
+
# message request: accept dm code
|
| 150 |
+
|
| 151 |
+
# driver.find_element(By.XPATH, "//*[contains(text(), 'Message Requests')]").click()
|
| 152 |
+
# time.sleep(3)
|
| 153 |
+
# accept_dm = WebDriverWait(driver, 100).until(
|
| 154 |
+
# EC.presence_of_element_located((By.XPATH, "//*[contains(text(), 'Accept DM')]"))
|
| 155 |
+
# )
|
| 156 |
+
# print(accept_dm)
|
| 157 |
+
# accept_dm.click()
|
| 158 |
+
|
| 159 |
+
# normal dm open code
|
| 160 |
+
# driver.find_element(By.XPATH, "//*[contains(text(), 'Message Requests')]").click()
|
| 161 |
+
|
| 162 |
+
|
| 163 |
+
time.sleep(2)
|
| 164 |
+
while(True):
|
| 165 |
+
if stop_thread:
|
| 166 |
+
driver.quit()
|
| 167 |
+
break
|
| 168 |
+
time.sleep(2)
|
| 169 |
+
# msg_req = False
|
| 170 |
+
try:
|
| 171 |
+
msg_req = WebDriverWait(driver, 1).until(
|
| 172 |
+
EC.presence_of_element_located((By.XPATH, "//*[contains(text(), 'Message Requests')]"))
|
| 173 |
+
)
|
| 174 |
+
msg_req.click()
|
| 175 |
+
time.sleep(1)
|
| 176 |
+
# accept_dm = driver.find_element(By.XPATH,"//*[contains(text(), 'Accept DM')]/../../preceding-sibling::div[1]")
|
| 177 |
+
try:
|
| 178 |
+
accept_dm = driver.find_element(By.XPATH,"//*[contains(text(), 'Accept DM')]/../../preceding-sibling::div[1]")
|
| 179 |
+
except:
|
| 180 |
+
driver.find_element(By.XPATH,"//*[contains(text(), 'Spam')]").click()
|
| 181 |
+
time.sleep(1)
|
| 182 |
+
driver.find_element(By.XPATH,"//*[contains(text(), 'Accept DM')]").click()
|
| 183 |
+
time.sleep(2)
|
| 184 |
+
|
| 185 |
+
try:
|
| 186 |
+
accept_dm.click()
|
| 187 |
+
except:
|
| 188 |
+
pass
|
| 189 |
+
except Exception as e:
|
| 190 |
+
driver.find_element(By.XPATH, "//div[contains(text(), 'Friends')]").click()
|
| 191 |
+
print(e)
|
| 192 |
+
dm = driver.find_element(By.XPATH,"//*[@aria-label='Servers']/preceding-sibling::div[2]")
|
| 193 |
+
if("tutorial" in str(dm.get_attribute("class"))):
|
| 194 |
+
# check message request
|
| 195 |
+
print("No dm found")
|
| 196 |
+
continue
|
| 197 |
+
else:
|
| 198 |
+
print("dm found")
|
| 199 |
+
dm.click()
|
| 200 |
+
time.sleep(2)
|
| 201 |
+
text_box = driver.find_element(By.CSS_SELECTOR,"[role='textbox']")
|
| 202 |
+
text_box.click()
|
| 203 |
+
time.sleep(1)
|
| 204 |
+
current_channel_url = driver.current_url
|
| 205 |
+
current_channel = current_channel_url[current_channel_url.find("@me/"):].replace("@me/", "")
|
| 206 |
+
with open('channels.txt') as file:
|
| 207 |
+
contents = file.read()
|
| 208 |
+
search_word = current_channel
|
| 209 |
+
if search_word in contents:
|
| 210 |
+
print('channel already done')
|
| 211 |
+
driver.find_element(By.XPATH, "//div[contains(text(), 'Friends')]").click()
|
| 212 |
+
continue
|
| 213 |
+
else:
|
| 214 |
+
print("New channel working on it")
|
| 215 |
+
|
| 216 |
+
dm_done = in_dm_code(driver ,server_link)
|
| 217 |
+
# get current dm channel number
|
| 218 |
+
current_channel_url = driver.current_url
|
| 219 |
+
current_channel = current_channel_url[current_channel_url.find("@me/"):].replace("@me/", "")
|
| 220 |
+
print(current_channel)
|
| 221 |
+
if dm_done:
|
| 222 |
+
total_dm_done+=1
|
| 223 |
+
file = open("channels.txt", "a") # append mode
|
| 224 |
+
file.write(f"{current_channel} \n")
|
| 225 |
+
file.close()
|
| 226 |
+
time.sleep(0.5)
|
| 227 |
+
if total_dm_done==int(invites):
|
| 228 |
+
driver.quit()
|
| 229 |
+
break
|
| 230 |
+
driver.find_element(By.XPATH, "//div[contains(text(), 'Friends')]").click()
|
| 231 |
+
|
| 232 |
+
print(f"Program ended with aproximately {total_dm_done} Joins")
|
| 233 |
+
total_dm_done = 0
|
| 234 |
+
|
| 235 |
+
|
| 236 |
+
|
| 237 |
+
if stop_thread:
|
| 238 |
+
return None
|
| 239 |
+
|
| 240 |
+
|
| 241 |
+
|
| 242 |
+
|
| 243 |
+
stop_thread = False
|
| 244 |
+
|
| 245 |
+
|
| 246 |
+
def output(anything, invites, server_link):
|
| 247 |
+
global stop_thread
|
| 248 |
+
stop_thread = False
|
| 249 |
+
if "stop" in anything:
|
| 250 |
+
stop_thread = True
|
| 251 |
+
return 201
|
| 252 |
+
t1 = threading.Thread(target=j4j_msg_req, args=(invites,server_link))
|
| 253 |
+
|
| 254 |
+
t1.start()
|
| 255 |
+
return 200
|
| 256 |
+
|
| 257 |
+
|
| 258 |
+
iface = gr.Interface(
|
| 259 |
+
fn=output,
|
| 260 |
+
inputs=[gr.Textbox(label="Enter start or stop"),gr.Textbox(label="Enter number of invites"),gr.Textbox(label="Enter server link")],
|
| 261 |
+
outputs=gr.Number(), # Adjust the image size here
|
| 262 |
+
title="Enter start or stop",
|
| 263 |
+
description="Start or stop j4j message request Bot",
|
| 264 |
+
)
|
| 265 |
+
|
| 266 |
+
iface.launch()
|
channels.txt
ADDED
|
File without changes
|
packages.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
chromium-driver
|
pending.txt
ADDED
|
File without changes
|
requirements.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
selenium >=4.0.0, < 5.0.0
|
| 2 |
+
# gradio==3.50
|
screenshot.png
ADDED
|