Skip to content

Commit 1ee7068

Browse files
added captcha checks to prevent working through captchas, added auto theatre, randomized delays, fixed some errors, sorta fixed and messed up autogratis and fixed some visual errors
1 parent 8b8c643 commit 1ee7068

7 files changed

+800
-659
lines changed

src/autoBuild.js

+39-18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// var r = Math.round(e.building.points * Math.pow(e.building.points_factor, e.next_level)) - Math.round(e.building.points * Math.pow(e.building.points_factor, e.level))
2-
31
class AutoBuild extends ModernUtil {
42
constructor(c, s) {
53
super(c, s);
@@ -11,10 +9,34 @@ class AutoBuild extends ModernUtil {
119
this.shiftHeld = false;
1210

1311
/* Active always, check if the towns are in the active list */
14-
this.enable = setInterval(this.main, 20000);
12+
this.interval = setInterval(this.main.bind(this), 20000);
1513

1614
/* Add listener that change the Senate look */
1715
uw.$.Observer(GameEvents.window.open).subscribe("modernSenate", this.updateSenate);
16+
17+
this.simulateCaptcha = false;
18+
this.captchaActive = false;
19+
20+
/* Check for captcha conditions every 300ms */
21+
this.checkCaptchaInterval = setInterval(() => {
22+
if (this.simulateCaptcha || $('.botcheck').length || $('#recaptcha_window').length) {
23+
if (!this.captchaActive) {
24+
this.console.log('Captcha active, autobuild stopped working');
25+
clearInterval(this.interval);
26+
this.captchaActive = true;
27+
}
28+
} else {
29+
if (this.captchaActive) {
30+
this.console.log('Captcha resolved, autobuild resumed');
31+
this.startInterval(); // Restart autobuild
32+
this.captchaActive = false;
33+
}
34+
}
35+
}, 300);
36+
}
37+
38+
startInterval() {
39+
this.interval = setInterval(this.main.bind(this), 20000);
1840
}
1941

2042
settings = () => {
@@ -43,7 +65,7 @@ class AutoBuild extends ModernUtil {
4365
<div class="game_border_corner corner2"></div>
4466
<div class="game_border_corner corner3"></div>
4567
<div class="game_border_corner corner4"></div>
46-
<div id="auto_build_title" style="cursor: pointer; filter: ${this.enable ? 'brightness(100%) saturate(186%) hue-rotate(241deg)' : ''}" class="game_header bold" onclick="window.modernBot.autoBuild.toggle()"> Auto Build <span class="command_count"></span>
68+
<div id="auto_build_title" style="cursor: pointer; filter: ${this.interval ? 'brightness(100%) saturate(186%) hue-rotate(241deg)' : ''}" class="game_header bold" onclick="window.modernBot.autoBuild.toggle()"> Auto Build <span class="command_count"></span>
4769
<div style="position: absolute; right: 10px; top: 4px; font-size: 10px;"> (click to toggle) </div>
4870
</div>
4971
<div id="buildings_lvl_buttons"></div>
@@ -56,14 +78,13 @@ class AutoBuild extends ModernUtil {
5678
if (handler.context !== "building_senate") return;
5779

5880
// Edit the width of the window to fit the new element
59-
handler.wnd.setWidth(850)
81+
handler.wnd.setWidth(850);
6082

6183
// Compute the id of the window
62-
const id = `gpwnd_${handler.wnd.getID()}`
84+
const id = `gpwnd_${handler.wnd.getID()}`;
6385

6486
// Loop until the element is found
6587
const updateView = () => {
66-
6788
const interval = setInterval(() => {
6889
const $window = $('#' + id);
6990

@@ -100,22 +121,21 @@ class AutoBuild extends ModernUtil {
100121
setTimeout(() => {
101122
clearInterval(interval);
102123
}, 100);
103-
}
124+
};
104125

105126
// subscribe to set content event
106127
const oldSetContent = handler.wnd.setContent2;
107128
handler.wnd.setContent2 = (...params) => {
108129
updateView();
109130
oldSetContent(...params);
110-
}
111-
112-
}
131+
};
132+
};
113133

114134
/* Given the town id, set the polis in the settings menu */
115135
setPolisInSettings = town_id => {
116136
let town = uw.ITowns.towns[town_id];
117137

118-
/* If the town is in the active list set*/
138+
/* If the town is in the active list set */
119139
let town_buildings = this.towns_buildings?.[town_id] ?? { ...town.buildings()?.attributes } ?? {};
120140
let buildings = { ...town.buildings().attributes };
121141

@@ -134,7 +154,7 @@ class AutoBuild extends ModernUtil {
134154
</div>`;
135155
};
136156

137-
/* If the town is in a group, the the groups */
157+
/* If the town is in a group, the groups */
138158
const groups =
139159
`(${Object.values(uw.ITowns.getTownGroups())
140160
.filter(group => group.id > 0 && group.id !== -1 && group.towns[town_id])
@@ -273,20 +293,21 @@ class AutoBuild extends ModernUtil {
273293
town_id: town_id,
274294
};
275295
uw.gpAjax.ajaxPost('frontend_bridge', 'execute', data);
276-
this.console.log(`${town.getName()}: buildUp ${type}`);
277-
await this.sleep(500);
296+
this.console.log(`${town.getName()}: Build Up ${type}`);
297+
await this.sleep(1234);
278298
};
279299

280300
/* Make post request to tear building down */
281-
postTearDown = async (type, town_id) => {
301+
postTearDown = async (type, town_id, town) => {
282302
let data = {
283303
model_url: 'BuildingOrder',
284304
action_name: 'tearDown',
285305
arguments: { building_id: type },
286306
town_id: town_id,
287307
};
288308
uw.gpAjax.ajaxPost('frontend_bridge', 'execute', data);
289-
await this.sleep(500);
309+
this.console.log(`${town.getName()}: Build Down ${type}`);
310+
await this.sleep(1234);
290311
};
291312

292313
/* return true if the quee is full */
@@ -358,7 +379,7 @@ class AutoBuild extends ModernUtil {
358379
return false;
359380
}
360381
if (target[build] < buildings[build]) {
361-
await this.postTearDown(build, town_id);
382+
await this.postTearDown(build, town_id, town);
362383
return true;
363384
}
364385
return false;

src/autoGratis.js

+18-12
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class AutoGratis extends ModernUtil {
2525
<div class="left"></div>
2626
<div class="right"></div>
2727
<div class="caption js-caption">Gratis<div class="effect js-effect"></div></div>
28-
</div> button (try every 4 seconds)
28+
</div> button (try every 2.5 seconds)
2929
</div>
3030
</div>
3131
`;
@@ -38,7 +38,7 @@ class AutoGratis extends ModernUtil {
3838
'filter',
3939
'brightness(100%) saturate(186%) hue-rotate(241deg)',
4040
);
41-
this.autogratis = setInterval(this.main, 4000);
41+
this.autogratis = setInterval(this.main, 2500);
4242
} else {
4343
uw.$('#auto_gratis_title').css('filter', '');
4444
clearInterval(this.autogratis);
@@ -49,14 +49,15 @@ class AutoGratis extends ModernUtil {
4949

5050
/* Main loop for the autogratis bot */
5151
main = () => {
52-
const el = uw.$('.type_building_queue.type_free').not('#dummy_free');
53-
if (el.length) el.click();
54-
55-
const town = uw.ITowns.getCurrentTown();
56-
for (let model of town.buildingOrders().models) {
57-
if (model.attributes.building_time < 300) {
58-
this.callGratis(town.id, model.id)
59-
return;
52+
const el = uw.$('.type_building_queue.type_free').not('.disabled').not('#dummy_free');
53+
if (el.length) {
54+
el.click();
55+
const town = uw.ITowns.getCurrentTown();
56+
for (let model of town.buildingOrders().models) {
57+
if (model.attributes.building_time < 300) {
58+
this.callGratis(town.id, model.id);
59+
return;
60+
}
6061
}
6162
}
6263
};
@@ -70,7 +71,12 @@ class AutoGratis extends ModernUtil {
7071
"order_id": order_id
7172
},
7273
"town_id": town_id
73-
}
74+
};
75+
76+
// Add console log
77+
this.console.log(`${uw.ITowns.towns[town_id].getName()}: calling gratis for order ${order_id}`);
78+
7479
uw.gpAjax.ajaxPost('frontend_bridge', 'execute', data);
75-
}
80+
};
81+
7682
}

src/autoHide.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class AutoHide extends ModernUtil {
5858
<div style="position: absolute; right: 10px; top: 4px; font-size: 10px;"> (click to toggle) </div>
5959
</div>
6060
<div style="padding: 5px; font-weight: 600">
61-
Check every 5 seconds, if there is more then 5000 iron store it in the hide
61+
Check every 5 seconds, if there is more then 15000 iron store it in the hide
6262
</div>
6363
</div>
6464
`;
@@ -96,7 +96,7 @@ class AutoHide extends ModernUtil {
9696
if (this.activePolis == 0) return;
9797
const town = uw.ITowns.towns[this.activePolis];
9898
const { iron } = town.resources()
99-
if (iron > 5000) {
99+
if (iron > 15000) {
100100
this.storeIron(this.activePolis, iron)
101101
}
102102
}

0 commit comments

Comments
 (0)