-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOSSBotV2.java
More file actions
404 lines (344 loc) · 11.2 KB
/
OSSBotV2.java
File metadata and controls
404 lines (344 loc) · 11.2 KB
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
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
package scripts.ossbot;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.lang.Thread.State;
import java.time.Duration;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.TimeZone;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import org.tribot.api.General;
import org.tribot.api.input.Keyboard;
import org.tribot.api.util.Screenshots;
import org.tribot.api2007.GameTab;
import org.tribot.api2007.Player;
import org.tribot.api2007.GameTab.TABS;
import org.tribot.script.Script;
import org.tribot.script.ScriptManifest;
import org.tribot.script.interfaces.Ending;
import org.tribot.script.interfaces.MessageListening07;
import org.tribot.script.interfaces.Starting;
import scripts.ossbot.commandInterface.Command;
import scripts.ossbot.commands.*;
import scripts.ossbot.constants.OssBotConstants;
import scripts.ossbot.methods.BotFiles;
import scripts.ossbot.methods.OssBotMethods;
import scripts.ossbot.methods.Ranking;
import scripts.ossbot.threads.Announcer;
import scripts.ossbot.threads.LoginTracker;
import scripts.ossbot.threads.Tracker;
import scripts.ossbot.threads.WebDownloader;
@ScriptManifest(authors = { "xmax" }, category = "OSSBot", name = "OSSBot", version = 1.00, description = "A bot for all", gameMode = 1)
public class OSSBotV2 extends Script implements MessageListening07, Starting, Ending{
private List<Command> validCommands = new ArrayList<Command>();
private static boolean PM = false;
private static String issuerName = null;
private static String issuerCommand = null;
private static int issuerRank = -1;
private static boolean lock = false;
private static boolean inCC = false;
private static boolean loggedIn = false;
private static boolean isBanned = false;
private static long lastClicked = System.currentTimeMillis();
private static long lastTracked = ZonedDateTime.now().toInstant().toEpochMilli();
public static boolean getLock() { return lock; }
public static void setLock(boolean lock) { OSSBotV2.lock = lock; }
public static boolean getInCC() { return inCC; }
public static void setInCC(boolean inCC) { OSSBotV2.inCC = inCC; }
public static boolean getLoggedIn() { return loggedIn; }
public static void setLoggedIn(boolean loggedIn) { OSSBotV2.loggedIn = loggedIn; }
public static boolean getIsBanned() { return isBanned; }
public static void setIsBanned(boolean isBanned) { OSSBotV2.isBanned = isBanned; }
public static long getLastClicked() { return lastClicked; }
public static void setLastClicked(long lastClicked) { OSSBotV2.lastClicked = lastClicked; }
public static long getLastTracked() { return lastTracked; }
public static void setLastTracked(long lastTracked) { OSSBotV2.lastTracked = lastTracked; }
public static void setPM(boolean PM) { OSSBotV2.PM = PM; }
public static boolean getPM() { return PM; }
@Override
public void run() {
WebDownloader wd = new WebDownloader();
Tracker t = new Tracker();
Announcer a = new Announcer();
LoginTracker lt = new LoginTracker();
Thread webDownloader = new Thread(wd);
Thread tracker = new Thread(t);
Thread announcer = new Thread(a);
Thread loginTracker = new Thread(lt);
while(!isBanned)
{
if(!lock && loggedIn)
{
GameTab.open(TABS.CLAN);
}
try{
if(webDownloader.getState().equals(State.TERMINATED))
{
webDownloader = new Thread(wd);
}
else if(!webDownloader.isAlive())
{
webDownloader.start();
}
if(announcer.getState().equals(State.TERMINATED))
{
announcer = new Thread(a);
}
else if(!announcer.isAlive())
{
announcer.start();
}
if(loginTracker.getState().equals(State.TERMINATED))
{
loginTracker = new Thread(lt);
}
else if(!loginTracker.isAlive())
{
loginTracker.start();
}
if(tracker.getState().equals(State.TERMINATED))
{
tracker = new Thread(t);
}
else if(!tracker.isAlive())
{
tracker.start();
}
}
catch (Exception e)
{
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
General.println(sw.toString());
General.println("Web downloader: " + webDownloader.getState());
General.println("Announcer: " + announcer.getState());
General.println("Login Tracker: " + loginTracker.getState());
General.println("Tracker: " + tracker.getState());
}
General.sleep(150);
}
BotFiles.botLogger("Account is now banned or locked, shutting down.");
}
@Override
public void onEnd() {
General.println("Shutting down...");
}
@Override
public void onStart() {
this.setAIAntibanState(false);
this.setLoginBotState(false);
General.useAntiBanCompliance(false);
General.println("Creating all command classes...");
Collections.addAll(validCommands,
new Ball8(),
new Config(),
new Announcement(),
new Help(),
new Data(),
new Comp(),
new Top(),
new Time(),
new Price(),
new Levelup(),
new Joke(),
new Poll(),
new CML(),
new Calc(),
new Caps(),
new Fact(),
new Offsite(),
new Examine(),
new Screenie(),
new Flipcoin(),
new Cluesolver(),
new Qfc(),
new Cleanup(),
new Info(),
new Reverse());
General.println("Commands created.");
TimeZone.setDefault(TimeZone.getTimeZone("UTC"));
General.println("Time and date: " + ZonedDateTime.now().format(DateTimeFormatter.ofPattern("MMM d, yyyy HH:mm:ss z")));
Keyboard.setSpeed(0.1);
File playerDataDirectory = new File(OssBotConstants.PLAYER_DATA_DIRECTORY);
File chatLogsDirectory = new File(OssBotConstants.CHAT_LOG_DIRECTORY);
File botLogDirectory = new File(OssBotConstants.BOT_LOG_DIRECTORY);
File announcerDirectory = new File(OssBotConstants.ANNOUNCER_DIRECTORY);
File downloadsDirectory = new File(OssBotConstants.DOWNLOADED_DATA_DIRECTORY);
File competitionDirectory = new File(OssBotConstants.COMPETITION_DATA_DIRECTORY);
competitionDirectory.mkdirs();
downloadsDirectory.mkdirs();
announcerDirectory.mkdirs();
botLogDirectory.mkdirs();
playerDataDirectory.mkdirs();
chatLogsDirectory.mkdirs();
}
@Override
public void clanMessageReceived(String name, String message) {
setPM(false);
name = OssBotMethods.standardiseName(name);
String botName = OssBotMethods.standardiseName(Player.getRSPlayer().getName());
chatLogger(name, message);
charsTypedTracker(name, message);
if(message.toLowerCase().contains("Attempting to kick player from friends chat...".toLowerCase()))
{
kickMessage(name);
}
isItACommand(name, message, botName);
}
private void kickMessage(String name) {
BotFiles.botLogger(("Kick message detected."));
String fileName = "kick - "+ name + " - " + ZonedDateTime.now().format(DateTimeFormatter.ofPattern("MMM d yyyy HH-mm-ss z")) + ".png";
if(Screenshots.take(fileName, false, false))
{
OssBotMethods.uploadToImgur(fileName, OssBotConstants.IMGUR_KICK_ALBUM_ID);
}
else
{
BotFiles.botLogger("Failed to take screenshot of kick message.");
}
}
private void charsTypedTracker(String name, String message) {
File[] allPlayerDirectories = new File(OssBotConstants.PLAYER_DATA_DIRECTORY).listFiles();
for(File playerDirectory : allPlayerDirectories)
{
String playerName = OssBotMethods.standardiseName(playerDirectory.getName());
if(playerName.equalsIgnoreCase(name))
{
File playerCharPropertiesFile = new File(OssBotConstants.PLAYER_DATA_DIRECTORY + playerName + OssBotConstants.SEPARATOR + OssBotConstants.PLAYER_TYPING_DATA);
if(!playerCharPropertiesFile.exists())
{
BotFiles.createPlayerProperties(playerCharPropertiesFile);
}
BotFiles.updateTypingProperties(message, playerCharPropertiesFile);
return;
}
}
}
private void preCommandInitiation() {
lock = true;
final Duration timeout = Duration.ofSeconds(OssBotConstants.TIMEOUT_DURATION);
ExecutorService executor = Executors.newSingleThreadExecutor();
final Future<String> Handler = executor.submit(new Callable<String>(){
@Override
public String call() throws Exception {
findCommand();
return null;
}
});
try{
Handler.get(timeout.toMillis(), TimeUnit.MILLISECONDS);
} catch(Exception e) {
Handler.cancel(true);
OssBotMethods.printException(e);
}
executor.shutdownNow();
lock = false;
}
private void findCommand() {
for(Command command : validCommands)
{
if(command.checkCallNames())
{
if(command.canExecute())
{
command.execute();
}
return;
}
}
General.println(getIssuerCommand() + " is not a valid command");
}
private void setIssuerName(String issuerName) {
OSSBotV2.issuerName = issuerName;
}
public static String getIssuerName() {
return issuerName;
}
private void setIssuerCommand(String issuerCommand) {
OSSBotV2.issuerCommand = issuerCommand;
}
public static String getIssuerCommand() {
return issuerCommand;
}
private void setIssuerRank(int issuerRank) {
OSSBotV2.issuerRank = issuerRank;
}
public static int getIssuerRank() {
return issuerRank;
}
@Override
public void duelRequestReceived(String arg0, String arg1) {
}
@Override
public void personalMessageReceived(String name, String message) {
setPM(true);
name = OssBotMethods.standardiseName(name);
String botName = OssBotMethods.standardiseName(Player.getRSPlayer().getName());
chatLogger(name, message);
isItACommand(name, message, botName);
}
private void chatLogger(String name, String message) {
DateTimeFormatter time = DateTimeFormatter.ofPattern("HH:mm:ss");
DateTimeFormatter date = DateTimeFormatter.ofPattern("MMM d, yyyy");
ZonedDateTime currentTime = ZonedDateTime.now();
File todaysChatLogFile = new File(OssBotConstants.CHAT_LOG_DIRECTORY, currentTime.format(date) + ".txt");
try{
if(!todaysChatLogFile.exists())
{
todaysChatLogFile.createNewFile();
General.println("New day started in chat logs: " + currentTime.format(date));
}
FileWriter chatLogger = new FileWriter(todaysChatLogFile, true);
String log = "[" + currentTime.format(time) + "] " + name + ": " + message + System.lineSeparator();
if(getPM())
{
log = "[PM]" + log;
}
chatLogger.write(log);
chatLogger.close();
} catch (IOException e) {
e.printStackTrace();
}
}
private void isItACommand(String name, String message, String botName)
{
if(message.startsWith("!!") && !name.equals(botName))
{
GameTab.open(TABS.CLAN);
while(lock)
{
General.sleep(1000);
General.println("Waiting...");
}
setIssuerName(name);
setIssuerCommand(message.substring(2));
setIssuerRank(Ranking.getPlayerRank(""));
preCommandInitiation();
}
}
@Override
public void playerMessageReceived(String arg0, String arg1) {
}
@Override
public void serverMessageReceived(String arg0) {
}
@Override
public void tradeRequestReceived(String name) {
/* lock = true;
PM = false;
Keyboard.typeSend("Beep boop I am a bot. Trading me does nothing.");
Messenger.messageFormatter(name + " has traded me! Why? Fuck do I know. I am a bot. Beep boop.");
lock = false;*/
}
}