Skip to content
This repository has been archived by the owner on Sep 18, 2022. It is now read-only.

Add working member region #14

Draft
wants to merge 17 commits into
base: main
Choose a base branch
from
24 changes: 22 additions & 2 deletions app/app.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,34 @@
<!--<input type="button" id="send" value="Send" onclick="sendMsg()">-->
</div>
<div id="member-region">
<div style="margin-left: 10px">
<div style="margin-left: 10px;position: relative; display:none">
<!--<a href="settings" target="_blank">Settings</a><br>-->
<b>CustomDiscord Dev</b><br>
<!-- <b>CustomDiscord Dev</b><br> -->
<!--<button onclick="setTheme('theme-dark')">🌙 Switch to Dark Theme</button><br>
<button onclick="setTheme('theme-default')">🌞 Switch to Light Theme</button><br>
<button onclick="setTheme('')">🚫 Remove Theme</button>
<button id="btnstatuschange">Change Status</button>-->




</div>
<div id="memberlist-controls">
<div id="memberlist-controls-popout"></div>
<div id="memberlist-controls-minimize"></div>
</div>
<div id="memberlist">
<div class="role">
<span class="rolename">online</span>
<div class="rolemember">
<div class="message-author">
<img class="message-author-avatar role-avatar" src="https://cdn.discordapp.com/avatars/318394797822050315/2fa77b5d206a2fff02a98e039ec78cc0.webp">
<div class="message-author-name role-username">cfp#7174</div>
<div class="role-status">Coding</div>
</div>
</div>
</div>
</div>
</div>
</div>
<!--
Expand Down
96 changes: 96 additions & 0 deletions app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ function setStatus() {
}
setTimeout(function() {
updateUserRegion();
reloadMemberList();
}, 100);
};
}
Expand Down Expand Up @@ -165,6 +166,89 @@ function reloadChannelList() {
channelsDiv.appendChild(guild.channellist);
}

function reloadMemberList() {
var memberDiv = $("memberlist");
var guildId = cache.getGuild(cache.current).id;
var guild = client.guilds.cache.get(guildId);
while(memberDiv.firstChild) memberDiv.removeChild(memberDiv.lastChild);

var status = ["online", "idle", "dnd", "offline"];
console.log(status);

status.forEach(s => {
console.log(s);
var users = guild.members.cache.filter(m => m.presence.status === s);
if(users.size !== 0) {
var role = document.createElement("div");
role.classList.add("role");

var roleName = document.createElement("span");
roleName.classList.add("rolename");
roleName.innerText = s;
role.appendChild(roleName);

for (let value of users) {
console.log("Adding " + value[1].user.tag);
console.log(value[1]);
var user = value[1].user;

var rolemember = document.createElement("div");
rolemember.classList.add("rolemember");
if(s === "offline") {
rolemember.style.filter = "grayscale(100%)";
}
role.appendChild(rolemember);
var avatar = document.createElement("img");
avatar.classList.add("member-avatar");
avatar.src = user.displayAvatarURL();
rolemember.appendChild(avatar);

var memberInfo = document.createElement("div");
memberInfo.classList.add("member-info");
rolemember.appendChild(memberInfo);

var username = document.createElement("div");
username.classList.add("member-username");
username.innerText = guild.member(user).displayName;
if(guild.owner.user.tag === user.tag) { // TODO: Add option for displaying discrim after username (requires settings)
username.innerHTML = escapeHTML(username.innerText) + "<img class='crown' src='../img/crown.svg'>";
if(user.bot) {
username.innerHTML = username.innerText + ' <span class="botBadge">BOT</span>';
}
} else {
if(user.bot) {
username.innerHTML = escapeHTML(username.innerText) + ' <span class="botBadge">BOT</span>';
}
}

memberInfo.appendChild(username);
var rolestatus = document.createElement("div");
rolestatus.classList.add("member-status"); // user.presence.status for online status
if(user.presence.activities[0]) {
// rolestatus.innerText = user.presence.activities[0].name;

var status = user.presence.activities[0].name;
var prefix = "\u2753"; // question mark
if(user.presence.activities[0].type == "PLAYING") prefix = "\u{1F3AE}"; // game controller
if(user.presence.activities[0].type == "WATCHING") prefix = "\u{1F5A5}"; // monitor
if(user.presence.activities[0].type == "LISTENING") prefix = "\u{1F3A7}"; // headphones
if(user.presence.activities[0].type == "STREAMING") prefix = "\u{1F3A5}"; // video camera
rolestatus.innerText = prefix + " " + status;
} else {
rolestatus.innerText = "";
}
memberInfo.appendChild(rolestatus);

// var user.displayAvatarURL());
}

memberDiv.appendChild(role);
} else {
console.log("Role empty " + s + ", skipping");
}
});
}

function updateUserRegion() {
$("user-region-name").innerText = client.user.tag;
$("user-region-avatar").style.backgroundImage = "url('" + client.user.displayAvatarURL() + "')";
Expand Down Expand Up @@ -331,6 +415,18 @@ function onLoaded() {
reloadChannelList();
loadMessageHistory();
updateUserRegion();
reloadMemberList();

var b0 = $("memberlist-controls-popout");
var b1 = $("memberlist-controls-minimize");
if(b0 && b1) {
b0.addEventListener("click", () => alert("Coming soon™️"));
b1.addEventListener("click", () => {
var reg = $("member-region")
reg.classList.toggle("minimized");
});
}

console.log("Loaded CustomDC!");
}

Expand Down
6 changes: 5 additions & 1 deletion background/dc_listeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,8 @@ client.on('typingStart', (channel, user) => {
//console.log(user.username + " schreibt");
//$("typing").innerHTML = "<b>" + author + "</b> is typing...";
}*/
});
});

client.on('presenceUpdate', (oldMember, newMember) => {
reloadMemberList(); // I KNOW THIS IS NOT A GOOD WAY TO RELOAD EVERYTHING PUT IT WILL COME IN NEXT PR
});
3 changes: 3 additions & 0 deletions background/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,7 @@ function loadMessageHistory() {
}
function reloadChannelList() {
if(isAppOpen()) clientWindow.reloadChannelList();
}
function reloadMemberList() {
if(isAppOpen()) clientWindow.reloadMemberList();
}
9 changes: 9 additions & 0 deletions img/crown.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading