Page Menu
Home
desp's stash
Search
Configure Global Search
Log In
Files
F369019
DiscordBot.java
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
5 KB
Subscribers
None
DiscordBot.java
View Options
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
;
}
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
//System.out.println(temp);
try
{
Thread
.
sleep
(
2000
);
}
catch
(
InterruptedException
e
)
{
e
.
printStackTrace
();}
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"
;
}
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"
)))
{
//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
Details
Attached
Mime Type
text/x-c
Expires
Sun, Jul 6, 4:22 AM (13 h, 56 m)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
ac/6e/ce51c7fcc897e2878c30dbf18745
Attached To
rARPC Discord Anime RPC
Event Timeline
Log In to Comment