Bobbey Posted August 4, 2019 Share Posted August 4, 2019 This snippet is for people who pay for the electricity that runs their bots. These functions could save you a whole lot of power when you're not botting but the machine is not turned off. I assume the time of day you're botting affects ban rates. I also assume people have schedules for when they want to be botting. One could, for example, use this code to sleep after 11PM until 10AM. If you shut down your bots and run this command, your bot manager will keep running, but the machine will go to sleep until specified. Then in your bot manager you can test when the system time is later than the wakeup time and, if so, startup your bots again. I have tested this code and it simply freezes all programs and resumes them when the specified time has passed. My machine went from 100 watts to 8 watts when asleep. private static int sleep(String password, int seconds) throws Exception { String[] cmd = { "sudo", "-S", "rtcwake", "-s", seconds, "-m", "mem" }; Runtime runtime = Runtime.getRuntime(); Process process = runtime.exec(cmd); OutputStream os = process.getOutputStream(); os.write(new String(password + "\n").getBytes()); os.flush(); os.close(); process.waitFor(); String output = readFile(process.getInputStream()); if (output != null && !output.isEmpty()) { System.out.println(output); } String error = readFile(process.getErrorStream()); if (error != null && !error.isEmpty()) { System.out.println(error); } return process.exitValue(); } private static String readFile(InputStream inputStream) throws Exception { if (inputStream == null) { return ""; } StringBuilder sb = new StringBuilder(); BufferedReader bufferedReader = null; try { bufferedReader = new BufferedReader(new InputStreamReader(inputStream)); String line = bufferedReader.readLine(); while (line != null) { sb.append(line); line = bufferedReader.readLine(); } return sb.toString(); } finally { if (bufferedReader != null) { bufferedReader.close(); } } } Any questions or ideas for additional information on this post is appreciated! 1 Quote Link to comment Share on other sites More sharing options...
Token Posted August 4, 2019 Share Posted August 4, 2019 I never thought about this, nice idea. I would design the system to launch the bot manager on startup instead, write a linux service that manages sleeping and starting/stopping the bot manager. This helps if there are any additional reboots in the future since services can be scheduled to automatically start with the kernel. 1 Quote Link to comment Share on other sites More sharing options...
Bobbey Posted August 4, 2019 Author Share Posted August 4, 2019 5 minutes ago, Token said: I never thought about this, nice idea. I would design the system to launch the bot manager on startup instead, write a linux service that manages sleeping and starting/stopping the bot manager. This helps if there are any additional reboots in the future since services can be scheduled to automatically start with the kernel. I agree with you. But did you know that this method does not even require the bot manager to restart Quote Link to comment Share on other sites More sharing options...
Token Posted August 4, 2019 Share Posted August 4, 2019 1 minute ago, Bobbey said: I agree with you. But did you know that this method does not even require the bot manager to restart Yes I figured that from what you said, but the application controlling the system vs system controlling application is just about design principles. You can also register your application as a service. Doing it from the service side may spare you from executing system commands from java which is usually quite annoying, and can run into tons of issues depending on distribution. My only concern was the cost of having a jvm running in the background doing this check for when to wake up, which could also impact the electricity usage of the system. 1 Quote Link to comment Share on other sites More sharing options...
Bobbey Posted August 4, 2019 Author Share Posted August 4, 2019 27 minutes ago, Token said: Yes I figured that from what you said, but the application controlling the system vs system controlling application is just about design principles. Very true 27 minutes ago, Token said: My only concern was the cost of having a jvm running in the background doing this check for when to wake up, which could also impact the electricity usage of the system. The java program will freeze and not use any power 1 Quote Link to comment Share on other sites More sharing options...