-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlightbot.js
295 lines (232 loc) · 7.66 KB
/
lightbot.js
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
// A small general purpose bot in Javascript
// Open source: https://github.com/EverybodyPrograms/Lightbot
// Thanks to Ninjasupeatsninja / SirJosh3917 for EEJSIDE:
// https://sirjosh3917.github.io/EEJSIDE/
// Send me requests / bug reports for the bot:
// Discord: joo#2111
// Github: j0w0 (Add an issue to the repo)
// How to use the bot:
// 1: Get lightbot.html from the repository
// 2: Open it in a text editor, and scroll down to toggles in the file
// 3: Edit the toggles to your liking (and maybe edit some other stuff)
// 4: Put in username, password and world ID
// (Preferrably use your own account on your own world)
// _______ ____ _____ _____ _ ______ _____
// |__ __/ __ \ / ____|/ ____| | | ____|/ ____|
// | | | | | | | __| | __| | | |__ | (___
// | | | | | | | |_ | | |_ | | | __| \___ \
// | | | |__| | |__| | |__| | |____| |____ ____) |
// |_| \____/ \_____|\_____|______|______|_____/
// Input your username here so you can use commands
var yourUsername = "joo456";
// Change false to true to turn on snake
// Warning: snake can be laggy depending on your PC and connection
var snakeON = true;
// Change false to true to turn on crown to fun
// You must be the owner of the world to use this
// A bit buggy, turn off if it isnt working well.
var crowntowin = false;
// Change false to true to turn on trophy to win
// You must be the owner of the world to use this
var trophytowin = false;
// Change false to true to turn on admins
// You must be the owner of the world to use this
var admins = true;
// Change false to true to turn on bans
// You must use the owner of the world to use this
var bans = true;
// Change false to true to turn on friends get edits
// You must use the owner of the world to use this
var friendsgetedit = true;
// Change false to true to turn on welcomes
var welcomes = true;
// Change false to true to turn on goodbyes
var goodbyes = true;
// Change false to true to turn on death commands
var deathCommands = true;
var adminlist =
["a", //Put users in here inside quotes
"x",
"x"];
var banlist =
["x", //Put users in here inside quotes
"y",
"z"];
/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
///////////////////// THE CODE ////////////////////////
/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////
var snakeDelay = 10;
var loop;
var i;
var player = [];
var layer;
var x;
var y;
var blockid;
// The snake function
function snake() {
switch (blockid) {
case 1088: { // White
connection.send("b", layer, x, y, 9);
} break;
case 9: { // Grey
connection.send("b", layer, x, y, 182);
} break;
case 182: { // Black
if (loop) { // White
connection.send("b", layer, x, y, 1088);
}
else { // Nothing
connection.send("b", layer, x, y, 0);
}
} break;
case 12: { // Red // Orange
connection.send("b", layer, x, y, 1018);
} break;
case 1018: { // Orange // Yellow
connection.send("b", layer, x, y, 13);
} break;
case 13: { // Yellow // Green
connection.send("b", layer, x, y, 14);
} break;
case 14: { // Green // Cyan
connection.send("b", layer, x, y, 15);
} break;
case 15: { // Cyan // Blue
connection.send("b", layer, x, y, 10);
} break;
case 10: { // Orange // Yellow
connection.send("b", layer, x, y, 11);
} break;
}
}
// add a callback handler
connection.addMessageCallback("*", function(m) {
switch(m.type) {
// Joining started
case "init": {
log(getCookie("username"));
owner = m.getString(0);
isOwner = m.getBoolean(15);
// send "init2"
if (yourUsername != "x") {
connection.send("init2");
}
else {
log("===================================");
log("Please input your username!!!");
log("Open the html file in a text editor and scroll down to toggles.");
log("===================================");
}
} break;
// Joining finished
case "init2": {
connection.send("say", "[Lightbot by joo456] Joined!");
connection.send("say", "[Lightbot by joo456] Being controlled by: " + yourUsername);
} break;
// on a player joining:
case "add": {
playerid = m.getInt(0);
username = m.getString(1);
isFriend = m.getBoolean(12);
if (username == yourUsername) {
var yourID = playerid;
}
player[playerid] = username;
if (welcomes) {
connection.send("say", "Hi " + username);
}
if (admins) {
for (i = 0; i < adminlist.length; i++) {
if (adminlist[i] == username) {
connection.send("say","/ge " + username);
log(username + " given edit. Reason: is admin");
}
}
}
if (friendsgetedit && isFriend) {
connection.send("say","/ge " + username);
log(username + " given edit. Reason: is friend");
}
if (bans) {
for (i = 0; i < banlist.length; i++) {
if (banlist[i] == username) {
connection.send("say","/kick " + username+ " You're on the ban list");
log(username + " kicked. Reason: on ban list");
}
}
}
} break;
// when someone leaves
case "left": {
if (goodbyes) {
connection.send("say", "Bye " + username);
}
} break;
// when someone says something
case "say": {
var playerid = m.getInt(0);
var input = m.getString(1);
// if (m.getInt(0) == yourUsername) {
// If they say !help
if(input == "!help") {
connection.send("pm",playerid, "!download - Show the download link");
connection.send("pm",playerid, "!loopon - make snakes loop back instead of ending");
connection.send("pm",playerid, "!loopoff - make snakes end instead of looping");
connection.send("pm",playerid, "!oof - Kills you");
connection.send("pm",playerid, "!OOF - Resets you");
}
if(input == "!loopon") {
loop = true;
}
if(input == "!loopoff") {
loop = false;
}
if (deathCommands) {
if(input == "!oof") {
connection.send("say", "/kill " + player[playerid]);
log(player[playerid] + " killed");
}
if(input == "!OOF") {
connection.send("say", "/reset " + player[playerid]);
log(player[playerid] + " reset");
}
}
// }
// if they said "!download"
if(m.getString(1) == "!download") {
// tell them that
connection.send("say", "There is no download for this bot, it runs in your browser! Check out the Everybody Edits JavaScript IDE!");
connection.send("say", "https://github.com/EverybodyPrograms/Lightbot");
}
} break;
// when someone places a block
case "b": {
if (snakeON) {
layer = m.getInt(0);
x = m.getUInt(1);
y = m.getUInt(2);
blockid = m.getUInt(3);
setTimeout(snake, snakeDelay);
}
} break;
// when someone touches a crown
case "k": {
if (crowntowin) {
var crownid = m.getInt(0);
connection.send("say", "/ge " + player[crownid]);
}
} break;
// when someone collects a trophy
case "ks": {
if (trophytowin) {
var wonid = m.getInt(0);
connection.send("say", "/ge " + player[wonid]);
}
} break;
}});
connection.send("init");