Skip to content

Commit

Permalink
fuck
Browse files Browse the repository at this point in the history
  • Loading branch information
Dragon1320 committed Aug 18, 2018
1 parent 9fab937 commit 0774b52
Show file tree
Hide file tree
Showing 4 changed files with 302 additions and 95 deletions.
36 changes: 32 additions & 4 deletions src/web/routes/api/guilds.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,34 @@ const { authUser, authAdmin } = require("../../middlewares");
const router = express.Router();
const apiLogger = new Logger();

router.get("/temp/userguilds", authUser, async (req, res) => {

let user_guilds;
try {

user_guilds = await axios({
method: "get",
url: "https://discordapp.com/api/v6/users/@me/guilds",
headers: {
"Authorization": `Bearer ${req.session.discord.access_token}`
}
});
} catch(error) {

apiLogger.error(error);
return res.json({ status: 500, message: "Internal Server Error", error });
}

let user_admin_guilds = [];
for (let user_guild of user_guilds.data) {
if ((user_guild.permissions & 8) === 8) {
user_admin_guilds.push(user_guild);
}
}

res.json(user_admin_guilds);
});

router.post("/", authAdmin, async (req, res) => {

// Get input.
Expand Down Expand Up @@ -167,7 +195,7 @@ router.get("/@me", authUser, async (req, res) => {
method: "get",
url: "https://discordapp.com/api/v6/users/@me/guilds",
headers: {
"Authorization": `Bearer ${"HYrvwyjKjkkxlKWRtpf6VFaCQNYlpm"}`
"Authorization": `Bearer ${req.session.discord.access_token}`
}
});
} catch(error) {
Expand Down Expand Up @@ -228,7 +256,7 @@ router.route("/@me/:discord_id").get(authUser, async (req, res) => {
method: "get",
url: "https://discordapp.com/api/v6/users/@me/guilds",
headers: {
"Authorization": `Bearer ${"HYrvwyjKjkkxlKWRtpf6VFaCQNYlpm"}`
"Authorization": `Bearer ${req.session.discord.access_token}`
}
});
} catch(error) {
Expand Down Expand Up @@ -287,7 +315,7 @@ router.route("/@me/:discord_id").get(authUser, async (req, res) => {
method: "get",
url: "https://discordapp.com/api/v6/users/@me/guilds",
headers: {
"Authorization": `Bearer ${"HYrvwyjKjkkxlKWRtpf6VFaCQNYlpm"}`
"Authorization": `Bearer ${req.session.discord.access_token}`
}
});
} catch(error) {
Expand Down Expand Up @@ -441,7 +469,7 @@ router.route("/@me/:discord_id").get(authUser, async (req, res) => {
method: "get",
url: "https://discordapp.com/api/v6/users/@me/guilds",
headers: {
"Authorization": `Bearer ${"HYrvwyjKjkkxlKWRtpf6VFaCQNYlpm"}`
"Authorization": `Bearer ${req.session.discord.access_token}`
}
});
} catch(error) {
Expand Down
63 changes: 63 additions & 0 deletions src/web/static/js/server-select.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
"use strict";

const getCookie = (cname) => {
let name = cname + "=";
let decodedCookie = decodeURIComponent(document.cookie);
let ca = decodedCookie.split(';');
for (let i = 0; i < ca.length; i++) {
let c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
return "";
}

const initServerSelect = () => {

const server_select = document.getElementById("server-select");
const server_image = document.getElementById("current-server-img");

//const guilds = new XMLHttpRequest();
//guilds.open("GET", "/api/v3/guilds/temp/userguilds", false);
//guilds.send();

//const guilds_res = JSON.parse(guilds.response);

const guilds_res = [{

id: "405129031445381120",
icon: "cc25586f0ba64afbc7d3bcf09b78bbac",
name: "fstest-hardcoded"
}];

let i = 0;
for (let guild_res of guilds_res) {

const cookie = getCookie("guild");
if (cookie === "") {
document.cookie = "guild=" + guild_res.id;
}

server_select.innerHTML += `<a id="server-${guild_res.id}" class="dropdown-item waves-effect waves-light server-selector-thingy">
<img src="${guild_res.icon === null ? "https://cdn.discordapp.com/embed/avatars/0.png" : `https://cdn.discordapp.com/icons/${guild_res.id}/${guild_res.icon}.png`}" class="rounded-circle z-depth-0 mr-2"
alt="there is supposed to be an image but dragon 馃叡roke it" style="background-color: #333333; height: 32px">
${guild_res.name}
</a>`;

const current_id = getCookie("guild");
if (current_id === guild_res.id) {
server_image.src = `${guild_res.icon === null ? "https://cdn.discordapp.com/embed/avatars/0.png" : `https://cdn.discordapp.com/icons/${guild_res.id}/${guild_res.icon}.png`}`;
}

i++;
}

$(".server-selector-thingy").click(function () {
document.cookie = "guild=" + $(this).attr("id").substring(7);
location.reload();
});
}

0 comments on commit 0774b52

Please sign in to comment.