Page MenuHomedesp's stash

No OneTemporary

diff --git a/src/me/despawningbone/selfbot/DiscordBot.java b/src/me/despawningbone/selfbot/DiscordBot.java
index e156923..b5e301c 100644
--- a/src/me/despawningbone/selfbot/DiscordBot.java
+++ b/src/me/despawningbone/selfbot/DiscordBot.java
@@ -1,126 +1,125 @@
package me.despawningbone.selfbot;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import com.sun.jna.Native;
import com.sun.jna.Platform;
import com.sun.jna.platform.win32.WinDef.HWND;
import club.minnced.discord.rpc.DiscordEventHandlers;
import club.minnced.discord.rpc.DiscordRPC;
import club.minnced.discord.rpc.DiscordRichPresence;
import com.sun.jna.platform.win32.User32;
public class DiscordBot {
public static String prevTitle = "";
public static DiscordRichPresence prevPresence = new DiscordRichPresence();
public static boolean cleared = false;
public static void main(String[] args) {
DiscordRPC lib = DiscordRPC.INSTANCE;
String applicationId = "542685911607934986";
String steamId = "";
DiscordEventHandlers handlers = new DiscordEventHandlers();
handlers.ready = (user) -> System.out.println("Ready!");
lib.Discord_Initialize(applicationId, handlers, true, steamId);
new Thread(() -> {
while(true) {
lib.Discord_RunCallbacks();
String temp = "";
if(Platform.isWindows()) {
char[] buffer = new char[2048];
HWND hwnd = User32.INSTANCE.GetForegroundWindow();
User32.INSTANCE.GetWindowText(hwnd, buffer, 1024);
temp = Native.toString(buffer);
} else if(Platform.isMac()) {
final String[] script = {"osascript", "-e", "tell application \"System Events\"", "-e", "tell (first process whose frontmost is true) to return name of window 1", "-e", "end tell"};
try (BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(Runtime.getRuntime().exec(script).getInputStream()))) {
String buffer = null;
while ((buffer = bufferedReader.readLine()) != null) {
temp = buffer;
- System.out.println(temp);
}
} catch (IOException e) {
e.printStackTrace();
}
}
+ //System.out.println(temp);
+
try {
Thread.sleep(2000);
} catch (InterruptedException e) {e.printStackTrace();}
- if(temp.contains("- Watch Anime") || temp.contains("Online Sub - AnimeKisa")) {
- if(temp.contains("AnimeKisa")) {
- String title = temp.substring(6).split(" Online Sub - AnimeKisa")[0];
- if(!prevTitle.equals(title)) {
- System.out.println(title);
- String[] split = title.split("Episode");
- String epi = "Episode" + split[1]; //animekisa puts everything with episode
- String name = split[0];
- DiscordRichPresence presence = new DiscordRichPresence();
- presence.details = name;
- if(!epi.isEmpty()) presence.state = epi;
- presence.largeImageKey = "animekisa";
- presence.largeImageText = "animekisa";
- //presence.startTimestamp = System.currentTimeMillis() / 1000; // epoch second
- System.out.println(presence.details);
- System.out.println(presence.state);
- //presence.details = "";
- lib.Discord_UpdatePresence(presence);
- prevTitle = title;
- prevPresence = presence;
- cleared = false;
+
+ String site = null;
+ if(temp.contains("- Watch Anime")) site = "OtakuStream";
+ else if(temp.contains("Online Sub - AnimeKisa")) site = "AnimeKisa";
+ else if(temp.contains("- Anime Twist")) site = "Twist.moe";
+ if(site != null) {
+ String title = null, epi = null, name = null;
+ DiscordRichPresence presence = new DiscordRichPresence();
+ switch(site) {
+ case "AnimeKisa":
+ title = temp.split("Online Sub")[0].substring(6);
+ epi = title.substring(title.lastIndexOf("Episode"));
+ name = title.substring(0, title.lastIndexOf(epi) - 1); //animekisa puts everything with episode
+ break;
+ case "Twist.moe":
+ title = temp.split("- Anime Twist")[0];
+ epi = title.substring(title.lastIndexOf("Episode"));
+ name = title.substring(0, title.lastIndexOf(epi) - 1);
+ break;
+ case "OtakuStream": //not removing otakustream support in hope of it returning one day ;-;
+ title = temp.split("- Watch Anime")[0];
+ System.out.println(title);
+ String[] split = title.split("Episode");
+ epi = "";
+ name = split[0];
+ if(!temp.contains("- Watch Anime Movie Online English Subbed")) {
+ if(split.length < 2) continue; //theres no reason for it to not have episodes if its not movie
+ epi = "Episode" + split[1];
+ } else {
+ epi = "Anime Movie";
}
- } else {
- String title = temp.split("- Watch Anime")[0];
- if(!prevTitle.equals(title)) {
- System.out.println(title);
- String[] split = title.split("Episode");
- String epi = "";
- String name = split[0];
- if(!temp.contains("- Watch Anime Movie Online English Subbed")) {
- if(split.length < 2) continue; //theres no reason for it to not have episodes if its not movie
- epi = "Episode" + split[1];
- } else {
- epi = "Anime Movie";
- }
- DiscordRichPresence presence = new DiscordRichPresence();
- presence.details = name;
- if(!epi.isEmpty()) presence.state = epi;
- presence.largeImageKey = "otakustream";
- presence.largeImageText = "OtakuStream";
- //presence.startTimestamp = System.currentTimeMillis() / 1000; // epoch second
- System.out.println(presence.details);
- System.out.println(presence.state);
- //presence.details = "";
- lib.Discord_UpdatePresence(presence);
- prevTitle = title;
- prevPresence = presence;
- cleared = false;
- }
- }
+ break;
+ }
+ //System.out.println(title);
+ if(title != null && !prevTitle.equals(title)) { //update only if not match
+ presence.details = name;
+ if(!epi.isEmpty()) presence.state = epi;
+ presence.largeImageKey = site.toLowerCase().replaceAll("[^A-Za-z0-9]", ""); //key is always alphanumeric lowercase
+ presence.largeImageText = site;
+ //presence.startTimestamp = System.currentTimeMillis() / 1000; // epoch second
+ System.out.println(presence.details);
+ System.out.println(presence.state);
+ //presence.details = "";
+ lib.Discord_UpdatePresence(presence);
+ prevTitle = title;
+ prevPresence = presence;
+ cleared = false;
+ }
} else {
- if(!cleared && !temp.contains(" - Discord") && !temp.contains("工作切換") && !temp.contains("Picture-in-Picture")) {
+ if(!cleared && !(temp.contains(" - Discord") || temp.contains("工作切換") || temp.contains("Picture-in-Picture"))) { //exclude discord, tab switch and pip windows
lib.Discord_ClearPresence();
cleared = true;
prevTitle = "";
}
/*if(prevPresence.details != null && !prevPresence.details.equals("Idle")) {
DiscordRichPresence presence = new DiscordRichPresence();
presence.details = "Idle";
presence.largeImageKey = "otakustream";
presence.largeImageText = "OtakuStream";
lib.Discord_UpdatePresence(presence);
prevPresence = presence;
}*/
}
}
}, "RPC-Callback-Handler").start();
}
}

File Metadata

Mime Type
text/x-diff
Expires
Thu, Nov 14, 12:44 PM (7 h, 5 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
6b/d8/0b23274592ebf012cbcebfebc6e3

Event Timeline