snowflake and cleaning up classes

This commit is contained in:
MathMan05 2024-07-23 23:01:45 -05:00
parent 14d1c69c7d
commit 7eb3ff6cab
21 changed files with 584 additions and 361 deletions

View file

@ -2,6 +2,7 @@
import { Member } from "./member.js";
import { MarkDown } from "./markdown.js";
import { Contextmenu } from "./contextmenu.js";
import { SnowFlake } from "./snowflake.js";
class User {
static userids = {};
owner;
@ -16,12 +17,12 @@ class User {
static contextmenu = new Contextmenu("User Menu");
static setUpContextMenu() {
this.contextmenu.addbutton("Copy user id", function () {
navigator.clipboard.writeText(this.id);
navigator.clipboard.writeText(this.id.id);
});
this.contextmenu.addbutton("Message user", function () {
fetch(this.info.api.toString() + "/v9/users/@me/channels", { method: "POST",
body: JSON.stringify({ "recipients": [this.id] }),
headers: this.headers
body: JSON.stringify({ "recipients": [this.id.id] }),
headers: this.localuser.headers
});
});
}
@ -52,6 +53,10 @@ class User {
this.bio = new MarkDown(userjson[thing], this.localuser);
continue;
}
if (thing === "id") {
this.id = new SnowFlake(userjson[thing], this);
continue;
}
this[thing] = userjson[thing];
}
this.hypotheticalpfp = false;
@ -67,7 +72,7 @@ class User {
const pfp = document.createElement('img');
pfp.src = this.getpfpsrc();
pfp.classList.add("pfp");
pfp.classList.add("userid:" + this.id);
pfp.classList.add("userid:" + this.id.id);
return pfp;
}
userupdate(json) {
@ -77,7 +82,7 @@ class User {
}
}
bind(html, guild = null) {
if (guild && guild.id !== "@me") {
if (guild && guild.id.id !== "@me") {
Member.resolve(this, guild).then(_ => {
_.bind(html);
}).catch(_ => {
@ -96,7 +101,7 @@ class User {
this.hypotheticalpfp = false;
const src = this.getpfpsrc();
console.log(src);
for (const thing of document.getElementsByClassName("userid:" + this.id)) {
for (const thing of document.getElementsByClassName("userid:" + this.id.id)) {
thing.src = src;
}
}
@ -105,7 +110,7 @@ class User {
return this.avatar;
}
if (this.avatar != null) {
return this.info.cdn.toString() + "avatars/" + this.id + "/" + this.avatar + ".png";
return this.info.cdn.toString() + "avatars/" + this.id.id + "/" + this.avatar + ".png";
}
else {
return this.info.cdn.toString() + "embed/avatars/3.png";