Skip to content

Instantly share code, notes, and snippets.

@CoolElectronics
Created December 19, 2022 04:23
Show Gist options
  • Save CoolElectronics/9e8a2552dbd61263bcb0fd7934d58b52 to your computer and use it in GitHub Desktop.
Save CoolElectronics/9e8a2552dbd61263bcb0fd7934d58b52 to your computer and use it in GitHub Desktop.
status changer
/**
* @name StatusChanger
* @author CoolElectronics
* @description Switches status every hour or so
* @version 0.0.1
*/
var server;
const statuses = [
"they go here",
];
module.exports = class StatusChanger {
/* BD functions */
getName() { return "Status Changer"; }
getVersion() { return "0.0.1"; }
getAuthor() { return "CoolElectronics"; }
getDescription() { return "changes your status"; }
load() {
this.cancel = false;
this.timeout = 1 * 60 * 60 * 1000;
Status.authToken = "put your token here i'm not giving you mine";
}
start() {
this.cancel = false;
this.startLoop();
}
loop() {
let status = statuses[Math.floor(Math.random() * statuses.length)];
BdApi.showToast("changing status to " + status);
Status.Set(status);
if (!this.cancel) {
this.startLoop();
}
}
startLoop() {
this.currentTimeout = setTimeout(() => this.loop(), this.timeout + Math.random() * this.timeout);
}
stop() {
if (this.currentTimeout != null) {
clearTimeout(this.currentTimeout);
this.currentTimeout = null;
}
this.cancel = true;
}
}
/* Status API */
const Status = {
strerror: (req) => {
if (req.status < 400) return undefined;
if (req.status == 401) return "Invalid AuthToken";
// Discord _sometimes_ returns an error message
let json = JSON.parse(req.response);
for (const s of ["errors", "custom_status", "text", "_errors", 0, "message"])
if ((json == undefined) || ((json = json[s]) == undefined))
return "bru";
return json;
},
Set: async (status) => {
let req = new XMLHttpRequest();
req.open("PATCH", "/api/v9/users/@me/settings", true);
req.setRequestHeader("authorization", Status.authToken);
req.setRequestHeader("content-type", "application/json");
req.onload = () => {
let err = Status.strerror(req);
if (err != undefined)
BdApi.showToast(`Animated Status: Error: ${err}`, { type: "error" });
};
req.send(JSON.stringify({
custom_status: {
text: status
}
}));
},
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment