This is really similar to my other project but the key difference is that instead of using the Rich Presence API this sets your custom status (and the way processes are found and matched is different).
Though at a certain point this used to work, I have not updated it in 4 years while Discord have most likely changed their internal API.
Using this might be a violation of Discord TOS as this code uses your discord token to pretend to be the user and set the custom status.
I highly recommend looking through the code and making sure the script you give your discord token to (it's almost the same as giving away your password) does no harm.
I don't recommend looking through the code too much as most of it is recycled from my older project which literally has a disclaimer So don't expect the code to make sense
.
This uses the windows API so it only works on windows.
First put discord account's token inside token.txt
.
Compile main.rs
and write custom commands inside config.ini
(config.ini
doesn't use .ini file syntax).
There is an example config.ini
file included.
If you are going to run the .exe file move the config forder to the target (where the .exe file is) directory.
If you are going to run via cargo run --release
you don't need to move the file.
The following arguments can be used:
text
static string which will be used as a custom status textemoji
static emoji which will be used as the custom status emojiregex
(used withformat
)
the regex to match the window's text and split it into groups. Example:(.) and (.)
would match and groupone and two
as
{
0: "one and two",
1: "one",
2: "two"
}
format
(used withregex
)
this is a string used to put the groups into one piece. Example:{2} and {1}
. The number inside{}
is the group's index (indexing starts from 1, 0 is the entire matched regex). If group 2 matched totwo
and group 1 matched toone
the final string will betwo and one
.fallback
(optionally used withformat
andregex
if nothing is matched)
ifregex
andformat
don't match anything this will be the status insteadfallback_emoji
optionally used together withfallback
as the emoji
There are plenty of tutorials online for example this.
Here's a step by step guide (this is for Firefox but it's probably really similar on other browsers)
- Open discord on your browser
- Press f12 to open developer tools and open
network
- Find a request with an
Authorization
field inRequest headers
(if you don't find anything refresh). TheAuthorization
value is the token you need to put intoken.txt
.
You want to display a custom status that is only set when watching youtube
- Find a regex that matches the browser window with youtube and write it down
".* YouTube .*"
- Set
emoji
andtext
to whatever you want (I'll leaveemoji
blank here)
text = watching youtube
".* YouTube .*"
text = watching youtube
You want your custom status to have the name and artist of a song you're listening to on spotify
- Find a regex that matches the spotify window and doesn't match other windows
"^[^-]*? - (?!Mozilla)(?!IntelliJ)(?!Discord)[^-]*$"
This regex exludes windows like IntelliJ IDEA, Discord and Mozilla Firefox but matches everything else in a formattext - more text
- Set
regex
to group the important parts of the window's name
regex = (.*) - (.*)
- Set
format
to put together the final text
format = listening to {2} by {1}
- Set
emoji
emoji = 🎵
"^[^-]*? - (?!Mozilla)(?!IntelliJ)(?!Discord)[^-]*$"
regex = (.*) - (.*)
format = listening to {2} by {1}
emoji = 🎵