compiled JS

This commit is contained in:
MathMan05 2024-08-12 16:08:22 -05:00
parent 2c068a7978
commit ebce7c0099
5 changed files with 161 additions and 111 deletions

View file

@ -59,6 +59,27 @@ class Direct extends Guild {
} }
} }
} }
const dmPermissions = new Permissions("0");
dmPermissions.setPermission("ADD_REACTIONS", 1);
dmPermissions.setPermission("VIEW_CHANNEL", 1);
dmPermissions.setPermission("SEND_MESSAGES", 1);
dmPermissions.setPermission("EMBED_LINKS", 1);
dmPermissions.setPermission("ATTACH_FILES", 1);
dmPermissions.setPermission("READ_MESSAGE_HISTORY", 1);
dmPermissions.setPermission("MENTION_EVERYONE", 1);
dmPermissions.setPermission("USE_EXTERNAL_EMOJIS", 1);
dmPermissions.setPermission("USE_APPLICATION_COMMANDS", 1);
dmPermissions.setPermission("USE_EXTERNAL_STICKERS", 1);
dmPermissions.setPermission("USE_EMBEDDED_ACTIVITIES", 1);
dmPermissions.setPermission("USE_SOUNDBOARD", 1);
dmPermissions.setPermission("USE_EXTERNAL_SOUNDS", 1);
dmPermissions.setPermission("SEND_VOICE_MESSAGES", 1);
dmPermissions.setPermission("SEND_POLLS", 1);
dmPermissions.setPermission("USE_EXTERNAL_APPS", 1);
dmPermissions.setPermission("CONNECT", 1);
dmPermissions.setPermission("SPEAK", 1);
dmPermissions.setPermission("STREAM", 1);
dmPermissions.setPermission("USE_VAD", 1);
class Group extends Channel { class Group extends Channel {
user; user;
constructor(json, owner) { constructor(json, owner) {
@ -190,9 +211,8 @@ class Group extends Channel {
isAdmin() { isAdmin() {
return false; return false;
} }
hasPermission(name, member) { hasPermission(name) {
const perm = new Permissions("248896"); return dmPermissions.hasPermission(name);
return !!perm.getPermission(name);
} }
} }
export { Direct, Group }; export { Direct, Group };

View file

@ -175,14 +175,6 @@ function userSettings() {
thisuser.showusersettings(); thisuser.showusersettings();
} }
document.getElementById("settings").onclick = userSettings; document.getElementById("settings").onclick = userSettings;
function userConnections() {
thisuser.userConnections.show();
}
document.getElementById("connections").onclick = userConnections;
function devPortal() {
thisuser.devPortal.show();
}
document.getElementById("dev-portal").onclick = devPortal;
if (mobile) { if (mobile) {
document.getElementById("channelw").onclick = function () { document.getElementById("channelw").onclick = function () {
document.getElementById("channels").parentNode.classList.add("collapse"); document.getElementById("channels").parentNode.classList.add("collapse");

View file

@ -246,7 +246,6 @@ class Localuser {
break; break;
case "READY": case "READY":
this.gottenReady(temp); this.gottenReady(temp);
this.genusersettings();
break; break;
case "MESSAGE_UPDATE": case "MESSAGE_UPDATE":
const message = SnowFlake.getSnowFlakeFromID(temp.d.id, Message).getObject(); const message = SnowFlake.getSnowFlakeFromID(temp.d.id, Message).getObject();
@ -806,23 +805,13 @@ class Localuser {
}); });
} }
} }
settings.show(); {
} const connections = settings.addButton("Connections");
/**
@deprecated
This should be made to not be used anymore
**/
genusersettings() {
const connectionContainer = document.createElement("div"); const connectionContainer = document.createElement("div");
connectionContainer.id = "connection-container"; connectionContainer.id = "connection-container";
this.userConnections = new Dialog(["html", fetch(this.info.api + "/connections", {
connectionContainer
], () => { }, async () => {
connectionContainer.innerHTML = "";
const res = await fetch(this.info.api + "/connections", {
headers: this.headers headers: this.headers
}); }).then(r => r.json()).then(json => {
const json = await res.json();
Object.keys(json).sort(key => json[key].enabled ? -1 : 1).forEach(key => { Object.keys(json).sort(key => json[key].enabled ? -1 : 1).forEach(key => {
const connection = json[key]; const connection = json[key];
const container = document.createElement("div"); const container = document.createElement("div");
@ -843,20 +832,18 @@ class Localuser {
connectionContainer.appendChild(container); connectionContainer.appendChild(container);
}); });
}); });
connections.addHTMLArea(connectionContainer);
}
{
const devPortal = settings.addButton("Developer Portal");
let appName = ""; let appName = "";
const appListContainer = document.createElement("div"); devPortal.addTextInput("Name:", value => {
appListContainer.id = "app-list-container"; appName = value;
this.devPortal = new Dialog(["vdiv", });
["hdiv", devPortal.addButtonInput("", "Create application", async () => {
["textbox", "Name:", appName, event => { if (appName.trim().length == 0) {
appName = event.target.value;
}],
["button",
"",
"Create application",
async () => {
if (appName.trim().length == 0)
return alert("Please enter a name for the application."); return alert("Please enter a name for the application.");
}
const res = await fetch(this.info.api + "/applications", { const res = await fetch(this.info.api + "/applications", {
method: "POST", method: "POST",
headers: this.headers, headers: this.headers,
@ -866,19 +853,12 @@ class Localuser {
}); });
const json = await res.json(); const json = await res.json();
this.manageApplication(json.id); this.manageApplication(json.id);
this.devPortal.hide();
}
]
],
["html",
appListContainer
]
], () => { }, async () => {
appListContainer.innerHTML = "";
const res = await fetch(this.info.api + "/applications", {
headers: this.headers
}); });
const json = await res.json(); const appListContainer = document.createElement("div");
appListContainer.id = "app-list-container";
fetch(this.info.api + "/applications", {
headers: this.headers
}).then(r => r.json()).then(json => {
json.forEach(application => { json.forEach(application => {
const container = document.createElement("div"); const container = document.createElement("div");
if (application.cover_image) { if (application.cover_image) {
@ -893,12 +873,14 @@ class Localuser {
name.textContent = application.name + (application.bot ? " (Bot)" : ""); name.textContent = application.name + (application.bot ? " (Bot)" : "");
container.appendChild(name); container.appendChild(name);
container.addEventListener("click", async () => { container.addEventListener("click", async () => {
this.devPortal.hide();
this.manageApplication(application.id); this.manageApplication(application.id);
}); });
appListContainer.appendChild(container); appListContainer.appendChild(container);
}); });
}); });
devPortal.addHTMLArea(appListContainer);
}
settings.show();
} }
async manageApplication(appId = "") { async manageApplication(appId = "") {
const res = await fetch(this.info.api + "/applications/" + appId, { const res = await fetch(this.info.api + "/applications/" + appId, {

View file

@ -28,7 +28,7 @@ class Permissions {
Permissions.info = [ Permissions.info = [
{ {
name: "CREATE_INSTANT_INVITE", name: "CREATE_INSTANT_INVITE",
readableName: "Create instance invite", readableName: "Create invite",
description: "Allows the user to create invites for the guild" description: "Allows the user to create invites for the guild"
}, },
{ {
@ -44,7 +44,7 @@ class Permissions {
{ {
name: "ADMINISTRATOR", name: "ADMINISTRATOR",
readableName: "Administrator", readableName: "Administrator",
description: "Allows all permissions and bypasses channel permission overwrites" description: "Allows all permissions and bypasses channel permission overwrites. This is a dangerous permission!"
}, },
{ {
name: "MANAGE_CHANNELS", name: "MANAGE_CHANNELS",
@ -73,17 +73,17 @@ class Permissions {
}, },
{ {
name: "STREAM", name: "STREAM",
readableName: "Stream", readableName: "Video",
description: "Allows the user to stream" description: "Allows the user to stream"
}, },
{ {
name: "VIEW_CHANNEL", name: "VIEW_CHANNEL",
readableName: "View channel", readableName: "View channels",
description: "Allows the user to view the channel" description: "Allows the user to view the channel"
}, },
{ {
name: "SEND_MESSAGES", name: "SEND_MESSAGES",
readableName: "Send Messages", readableName: "Send messages",
description: "Allows user to send messages" description: "Allows user to send messages"
}, },
{ {
@ -113,7 +113,7 @@ class Permissions {
}, },
{ {
name: "MENTION_EVERYONE", name: "MENTION_EVERYONE",
readableName: "Mention everyone", readableName: "Mention @everyone, @here and all roles",
description: "Allows the user to mention everyone" description: "Allows the user to mention everyone"
}, },
{ {
@ -153,8 +153,8 @@ class Permissions {
}, },
{ {
name: "USE_VAD", name: "USE_VAD",
readableName: "use voice-activity-detection", readableName: "Use voice activity detection",
description: "Allows user to use voice-activity-detection" description: "Allows users to speak in a voice channel by simply talking"
}, },
{ {
name: "CHANGE_NICKNAME", name: "CHANGE_NICKNAME",
@ -178,7 +178,7 @@ class Permissions {
}, },
{ {
name: "MANAGE_GUILD_EXPRESSIONS", name: "MANAGE_GUILD_EXPRESSIONS",
readableName: "Manage guild expressions", readableName: "Manage expressions",
description: "Allows for managing emoji, stickers, and soundboards" description: "Allows for managing emoji, stickers, and soundboards"
}, },
{ {
@ -223,14 +223,56 @@ class Permissions {
}, },
{ {
name: "USE_EMBEDDED_ACTIVITIES", name: "USE_EMBEDDED_ACTIVITIES",
readableName: "Use embedded activities", readableName: "Use activities",
description: "Allows the user to use embedded activities" description: "Allows the user to use embedded activities"
}, },
{ {
name: "MODERATE_MEMBERS", name: "MODERATE_MEMBERS",
readableName: "Moderate members", readableName: "Timeout members",
description: "Allows the user to time out other users to prevent them from sending or reacting to messages in chat and threads, and from speaking in voice and stage channels" description: "Allows the user to time out other users to prevent them from sending or reacting to messages in chat and threads, and from speaking in voice and stage channels"
}, },
{
name: "VIEW_CREATOR_MONETIZATION_ANALYTICS",
readableName: "View creator monetization analytics",
description: "Allows for viewing role subscription insights"
},
{
name: "USE_SOUNDBOARD",
readableName: "Use soundboard",
description: "Allows for using soundboard in a voice channel"
},
{
name: "CREATE_GUILD_EXPRESSIONS",
readableName: "Create expressions",
description: "Allows for creating emojis, stickers, and soundboard sounds, and editing and deleting those created by the current user."
},
{
name: "CREATE_EVENTS",
readableName: "Create events",
description: "Allows for creating scheduled events, and editing and deleting those created by the current user."
},
{
name: "USE_EXTERNAL_SOUNDS",
readableName: "Use external sounds",
description: "Allows the usage of custom soundboard sounds from other servers"
},
{
name: "SEND_VOICE_MESSAGES",
readableName: "Send voice messages",
description: "Allows sending voice messages"
},
{
name: "SEND_POLLS",
readableName: "Create polls",
description: "Allows sending polls"
},
{
name: "USE_EXTERNAL_APPS",
readableName: "Use external apps",
description: "Allows user-installed apps to send public responses. " +
"When disabled, users will still be allowed to use their apps but the responses will be ephemeral. " +
"This only applies to apps not also installed to the server."
},
]; ];
Permissions.map = {}; Permissions.map = {};
let i = 0; let i = 0;
@ -251,8 +293,21 @@ class Permissions {
return 0; return 0;
} }
} }
hasPermission(name) {
if (this.deny) {
console.warn("This function may of been used in error, think about using getPermision instead");
}
if (this.getPermissionbit(Permissions.map[name], this.allow))
return true;
if (name != "ADMINISTRATOR")
return this.hasPermission("ADMINISTRATOR");
return false;
}
setPermission(name, setto) { setPermission(name, setto) {
const bit = Permissions.map[name]; const bit = Permissions.map[name];
if (!bit) {
return console.error("Tried to set permission to " + setto + " for " + name + " but it doesn't exist");
}
if (setto === 0) { if (setto === 0) {
this.deny = this.setPermissionbit(bit, false, this.deny); this.deny = this.setPermissionbit(bit, false, this.deny);
this.allow = this.setPermissionbit(bit, false, this.allow); this.allow = this.setPermissionbit(bit, false, this.allow);

View file

@ -293,6 +293,7 @@ class Permissions{
} }
} }
hasPermission(name:string):boolean{ hasPermission(name:string):boolean{
if(this.deny){console.warn("This function may of been used in error, think about using getPermision instead")}
if (this.getPermissionbit(Permissions.map[name] as number,this.allow)) return true; if (this.getPermissionbit(Permissions.map[name] as number,this.allow)) return true;
if (name != "ADMINISTRATOR") return this.hasPermission("ADMINISTRATOR"); if (name != "ADMINISTRATOR") return this.hasPermission("ADMINISTRATOR");
return false; return false;