banner/accent_color support for profiles

This commit is contained in:
MathMan05
2024-08-16 20:10:57 -05:00
parent 1eea6cc005
commit d4a8393f69
10 changed files with 365 additions and 23 deletions

View File

@@ -52,6 +52,7 @@ class Localuser {
this.guilds = [];
this.guildids = new Map();
this.user = new User(ready.d.user, this);
this.user.setstatus("online");
this.mfa_enabled = ready.d.user.mfa_enabled;
this.userinfo.username = this.user.username;
this.userinfo.pfpsrc = this.user.getpfpsrc();
@@ -609,6 +610,30 @@ class Localuser {
});
};
}
updatebanner(file) {
if (file) {
var reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = () => {
fetch(this.info.api + "/users/@me", {
method: "PATCH",
headers: this.headers,
body: JSON.stringify({
banner: reader.result,
})
});
};
}
else {
fetch(this.info.api + "/users/@me", {
method: "PATCH",
headers: this.headers,
body: JSON.stringify({
banner: null,
})
});
}
}
updateProfile(json) {
fetch(this.info.api + "/users/@me/profile", {
method: "PATCH",
@@ -664,9 +689,10 @@ class Localuser {
let newpronouns = undefined;
let newbio = undefined;
let hypouser = this.user.clone();
function regen() {
let color;
async function regen() {
hypotheticalProfile.textContent = "";
const hypoprofile = hypouser.buildprofile(-1, -1);
const hypoprofile = await hypouser.buildprofile(-1, -1);
hypotheticalProfile.appendChild(hypoprofile);
}
regen();
@@ -687,9 +713,31 @@ class Localuser {
regen();
}
});
let bfile = undefined;
const binput = settingsLeft.addFileInput("Upload banner:", _ => {
if (bfile !== undefined) {
this.updatebanner(bfile);
}
});
binput.watchForChange(_ => {
if (_.length) {
bfile = _[0];
const blob = URL.createObjectURL(bfile);
hypouser.banner = blob;
hypouser.hypotheticalbanner = true;
regen();
}
});
const bclear = settingsLeft.addButtonInput("Clear banner", "Clear", () => {
bfile = null;
hypouser.banner = null;
settingsLeft.changed();
regen();
});
let changed = false;
const pronounbox = settingsLeft.addTextInput("Pronouns", _ => {
if (newpronouns || newbio) {
this.updateProfile({ pronouns: newpronouns, bio: newbio });
if (newpronouns || newbio || changed) {
this.updateProfile({ pronouns: newpronouns, bio: newbio, accent_color: parseInt("0x" + color.substr(1), 16) });
}
}, { initText: this.user.pronouns });
pronounbox.watchForChange(_ => {
@@ -704,6 +752,20 @@ class Localuser {
hypouser.bio = new MarkDown(_, this);
regen();
});
if (this.user.accent_color) {
color = "#" + this.user.accent_color.toString(16);
}
else {
color = "transparent";
}
const colorPicker = settingsLeft.addColorInput("Profile color", (_) => { }, { initColor: color });
colorPicker.watchForChange(_ => {
console.log();
color = _;
hypouser.accent_color = parseInt("0x" + _.substr(1), 16);
changed = true;
regen();
});
}
{
const tas = settings.addButton("Themes & sounds");
@@ -1022,6 +1084,7 @@ class Localuser {
}
//---------- resolving members code -----------
waitingmembers = new Map();
presences = new Map();
async resolvemember(id, guildid) {
if (!this.waitingmembers.has(guildid)) {
this.waitingmembers.set(guildid, new Map());
@@ -1038,6 +1101,9 @@ class Localuser {
noncemap = new Map();
noncebuild = new Map();
async gotChunk(chunk) {
for (const thing of chunk.presences) {
this.presences.set(thing.user.id, thing);
}
console.log(chunk);
chunk.members ??= [];
const arr = this.noncebuild.get(chunk.nonce);