-
Notifications
You must be signed in to change notification settings - Fork 2
/
gulpy.py
138 lines (102 loc) · 3.91 KB
/
gulpy.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
import time
import random
from selenium.webdriver import ActionChains
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By
import undetected_chromedriver as uc
# Prepare Selenium Driver Options
options = uc.ChromeOptions()
# options.add_argument('--headless') # Run Selenium Driver in Headless Mode
# options.add_argument('--no-sandbox') # No Sandbox for Selenium Driver
# options.add_argument('--disable-dev-shm-usage') # Disable Dev Shm Usage for Selenium Driver
# Create Selenium Driver
driver: uc.Chrome = uc.Chrome(options=options)
# Initialize Action Chains
action_chains: ActionChains = ActionChains(driver)
# Set Window Size [ 800 x 800 ]
driver.set_window_position(0, 0)
driver.set_window_size(800, 800)
# Preference Flags
set_once = False
def the_gulper_bot(driver: uc.Chrome):
"""The Gulper Bot: A bot that gulps the blobs in the game gulper.io
Args:
driver (webdriver.Chrome): Selenium Chrome Driver
Returns:
None
"""
global set_once
# Load Gulper.io
driver.get("https://gulper.io/") # Load Gulper.io
time.sleep(3) # Wait for page to load
# Find Web Body in Driver
body = driver.find_element(By.TAG_NAME, "body")
body_width = body.size['width']
body_height = body.size['height']
# Set Settings for Once
if not set_once:
driver.execute_script("document.getElementById('show-lbrd').click()")
driver.execute_script("document.getElementById('show-nicks').click()")
driver.execute_script("document.getElementById('show-map').click()")
driver.execute_script("document.getElementById('graph-qual').click()")
driver.execute_script("document.getElementById('framerate').click()")
set_once = True
time.sleep(0.25)
time.sleep(10)
# Hide Ads
driver.execute_script("window.ADS_BLOCKED = true;")
# Hide Stats
driver.execute_script(
"document.getElementById('stats').style.display = 'none'")
# Wait for 0.25 seconds
time.sleep(0.25)
# Press Tab Key
body.send_keys(Keys.TAB)
time.sleep(0.5)
# Type Nickname
random_names = []
random_names.append("GULPY_BOT_" + str(random.randint(100, 9999)))
input_box = driver.switch_to.active_element
input_box.send_keys(random_names[random.randint(0, len(random_names) - 1)])
# Wait for 1 second
time.sleep(1)
# Find Element By Id [ start-btn ] and Click
start_btn = driver.find_element(By.ID, "start-btn")
start_btn.click()
# Wait for 1 second
time.sleep(5)
# Step Counter
step = 0
driver.execute_script(
"document.getElementById('stats').style.display = 'none'")
while True:
step += 1
# Check If Elelment by Id [ game-stats ] is Visible
game_stats = driver.find_element(By.ID, "game-stats")
if game_stats.is_displayed():
# Game Over
break
try:
# Hover Mouse in Random Position
position_x = random.randint(-1 *
int(body_width/2)+10, int(body_width/2)-10)
position_y = random.randint(-1 * int(body_height/2) +
10, int(body_height/2)-10)
action_chains.move_to_element(body).move_by_offset(
position_x, position_y).perform()
print("Moving to: " + str(position_x) + ", " + str(position_y))
time.sleep(0.1)
action_chains.move_to_element(body).move_by_offset(0, 0).perform()
except Exception as e:
# Print Error
print(e, position_x, position_y)
# Wait for 0.25 seconds
time.sleep(0.1)
if step % 10 == 0:
# Try to Remove Stats
driver.execute_script(
"document.getElementById('stats').style.display = 'none'")
# Restart Game
the_gulper_bot(driver)
# Run the Gulper Bot
the_gulper_bot(driver)