-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathDiscordGithubStatus.plugin.js
More file actions
107 lines (97 loc) · 3.97 KB
/
DiscordGithubStatus.plugin.js
File metadata and controls
107 lines (97 loc) · 3.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
/**
* @name DiscordGithubStatus
* @authorId 334677994570383363
* @authorLink https://twitter.com/SilentDefault
* @source https://raw.githubusercontent.com/silentdefault/Discord-to-GitHub-Status/master/DiscordGithubStatus.plugin.js
*/
module.exports = class DiscordGithubStatus {
customStatus = {};
getName() { return "Discord-to-GitHub Status"; }
getDescription() { return "Send Discord Status to your GitHub Status."; }
getVersion() { return "1.0.0"; }
getAuthor() { return "SilentDefault"; } // Your name
setData(key, value) {
BdApi.setData(this.getName(), key, value);
}
getData(key) {
return BdApi.getData(this.getName(), key);
}
load() {
this.githubPAT = this.getData("githubPAT");
}
start() {
this.observer();
}
stop() {
this.requestGitHub().send(JSON.stringify({ query: `mutation {changeUserStatus(input: {message: "", emoji: ""}) {clientMutationId}}` }));
}
observer() {
if(this.githubPAT){
let a = BdApi.findModuleByProps("guildPositions").customStatus;
if (this.customStatus != a) {
if (a != null) {
var emojis = ["🧠", "💻", "📚", "🤙", "😎", "🤠", "👓", "💎", "🏆", "📍", "✅", "🎓", "🔥"];
let emoji = (typeof a.emojiName === "undefined") ? "" : `", emoji: "` + emojis[Math.floor(Math.random() * emojis.length)];
this.requestGitHub().send(JSON.stringify({ query: `mutation {changeUserStatus(input: {message: "${a.text + emoji}"}) {clientMutationId}}` }));
} else {
this.requestGitHub().send(JSON.stringify({ query: `mutation {changeUserStatus(input: {message: "Enriching the brain", emoji: "🧠"}) {clientMutationId}}` }));
}
}
this.customStatus = a;
}
}
requestGitHub() {
let req = new XMLHttpRequest();
req.open("POST", "https://api.github.com/graphql", true);
req.setRequestHeader("Authorization", "bearer " + this.githubPAT);
req.onload = () => {
if (req.status < 400) {
return;
}
BdApi.showToast(`Animated Status: Can't change status on GitHub: ${Status.errorString(req.status)}`, { type: "error" });
};
return req;
}
getSettingsPanel() {
let settings = document.createElement("div");
settings.appendChild(GUI.newDivider());
let label = document.createElement("h2");
label.innerText = "GitHub Personal Acces Token:";
settings.appendChild(label);
settings.appendChild(GUI.newDivider());
let GitHubPersonalAccesToken = document.createElement("input");
GitHubPersonalAccesToken.type="password";
GitHubPersonalAccesToken.className = "inputDefault-_djjkz input-cIJ7To";
GitHubPersonalAccesToken.value = this.getData("githubPAT");
GitHubPersonalAccesToken.placeholder = "here";
settings.appendChild(GitHubPersonalAccesToken);
settings.appendChild(GUI.newDivider());
let save = GUI.newButton("Save");
save.onclick = () => {
this.setData("githubPAT",GitHubPersonalAccesToken.value);
BdApi.showToast("Settings were saved!", { type: "success" });
this.load();
this.stop();
this.start();
};
settings.appendChild(save);
return settings;
}
}
const GUI = {
newDivider: (size = "15px") => {
let divider = document.createElement("div");
divider.style.minHeight = size;
divider.style.minWidth = size;
return divider;
},
newButton: (text, filled = true) => {
let button = document.createElement("button");
button.className = "button-38aScr colorBrand-3pXr91 sizeSmall-2cSMqn grow-q77ONN";
if (filled) button.classList.add("lookFilled-1Gx00P");
else button.classList.add("lookOutlined-3sRXeN");
button.classList.add("colorGreen-29iAKY");
button.innerText = text;
return button;
},
};