-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcookie_bot.py
141 lines (107 loc) · 5.01 KB
/
cookie_bot.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
from selenium import webdriver
from selenium.common.exceptions import ElementNotInteractableException, NoSuchElementException, StaleElementReferenceException
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.action_chains import ActionChains
from time import sleep
from os import system
system('cls')
url = "https://orteil.dashnet.org/cookieclicker/"
LOOPS = 50
BAKERY_NAME = "SN33DS"
MAX_OPTIONS = 16
class Cookie_Clicker_Bot:
def __init__(self):
self.driver = webdriver.Chrome()
self.driver.maximize_window()
self.driver.get(url)
assert "Cookie Clicker" in self.driver.title
sleep(10)
self.load_game()
sleep(5)
self.set_bakery_name()
sleep(5)
self.game()
#sleep(5)
#self.save_game()
sleep(10)
self.driver.close()
def set_bakery_name(self):
# As you have probably guessed, this sets your bakery's name if it isn't already set | Change BAKERY_NAME at the top to set your own name.
if self.driver.find_element_by_xpath('//*[@id="bakeryName"]').text != (BAKERY_NAME + "' bakery"):
self.driver.find_element_by_xpath('//*[@id="bakeryName"]').click()
sleep(1)
self.driver.find_element_by_xpath('//*[@id="bakeryNameInput"]').send_keys(BAKERY_NAME)
sleep(1)
self.driver.find_element_by_xpath('//*[@id="promptOption0"]').click()
else:
pass
def load_game(self):
self.driver.find_element_by_xpath('/html').send_keys(Keys.CONTROL, 'o')
with open('save.txt', 'r') as file:
save_text = file.read()
self.driver.find_element_by_xpath('//*[@id="textareaPrompt"]').send_keys(save_text)
self.driver.find_element_by_xpath('//*[@id="promptOption0"]').click()
def save_game(self):
reset = ActionChains(self.driver)
action = ActionChains(self.driver)
self.driver.find_element_by_xpath('//*[@id="prefsButton"]').click()
sleep(2)
body = self.driver.find_element_by_xpath('/html/body')
# el = self.driver.find_element_by_css_selector('#menu > div.subsection > div:nth-child(3) > a:nth-child(1)')
# location = el.location
# print(location)
reset.move_to_element_with_offset(body ,0, 0)
reset.perform()
action.move_by_offset(493, 305).click() # might need to change these numbers, just run once with the above uncommented to know what to put in.
action.perform()
sleep(1)
save = self.driver.find_element_by_xpath('//*[@id="textareaPrompt"]').text
with open('save.txt', 'w') as file:
file.write(save)
sleep(2)
self.driver.find_element_by_xpath('//*[@id="promptOption0"]').click()
sleep(5)
self.driver.find_element_by_xpath('//*[@id="menu"]/div[1]').click()
print('Game saved !')
def golden_cookie(self):
try: # Should click on the golden cookie if it is on screen
self.driver.find_element_by_xpath('//*[@id="shimmers"]/div').click()
except NoSuchElementException:
pass
def remove_achievements(self):
try: # This is to remove the achievements
self.driver.find_element_by_class_name('framed close sidenote').click()
except NoSuchElementException:
for f in range(10):
try:
self.driver.find_element_by_xpath(f'//*[@id="notes"]/div[{f}]').click()
except NoSuchElementException:
pass
def game(self):
# This is the 'game' loop
cookies = 350
buys = 15
for i in range(LOOPS): # Loop throught 'LOOPS' amount of time
print(f'Currently on loop {i}')
self.golden_cookie()
for c in range(cookies): # Starts by clicking the cookie 'cookies' amount of time
self.driver.find_element_by_id('bigCookie').click()
if c % 50 == 0: # Checks for golden cokkie every so often
self.golden_cookie()
self.golden_cookie()
if i >= 1: # Then tries to buy the first 'power up' but only after second loop
try:
self.driver.find_element_by_xpath('//*[@id="upgrade0"]').click()
except StaleElementReferenceException:
pass
self.remove_achievements()
self.golden_cookie()
for _ in range(buys): # Finally it loops throught all buyable items 'buys' amount of time
for n in range(MAX_OPTIONS, -1, -1):
try:
self.driver.find_element_by_xpath(f'//*[@id="product{n}"]').click()
except ElementNotInteractableException:
pass
cookies += 5 # Also adds a few units to cookies cause you will need more cookies over time
self.save_game()
bot = Cookie_Clicker_Bot()