badges
This commit is contained in:
parent
2440babacb
commit
6e37f84bd5
5 changed files with 122 additions and 3 deletions
|
@ -11,6 +11,7 @@ import { Settings } from "./settings.js";
|
|||
import { MarkDown } from "./markdown.js";
|
||||
const wsCodesRetry = new Set([4000, 4003, 4005, 4007, 4008, 4009]);
|
||||
class Localuser {
|
||||
badges = new Map();
|
||||
lastSequence = null;
|
||||
token;
|
||||
userinfo;
|
||||
|
|
|
@ -121,6 +121,32 @@ class User {
|
|||
async resolvemember(guild) {
|
||||
return await Member.resolveMember(this, guild);
|
||||
}
|
||||
async getUserProfile() {
|
||||
return (await fetch(`${this.info.api}/users/${this.id.replace("#clone", "")}/profile?with_mutual_guilds=true&with_mutual_friends=true`, {
|
||||
headers: this.localuser.headers
|
||||
})).json();
|
||||
}
|
||||
resolving = false;
|
||||
async getBadge(id) {
|
||||
console.log(id, ":3");
|
||||
if (this.localuser.badges.has(id)) {
|
||||
return this.localuser.badges.get(id);
|
||||
}
|
||||
else {
|
||||
if (this.resolving) {
|
||||
await this.resolving;
|
||||
return this.localuser.badges.get(id);
|
||||
}
|
||||
const prom = await this.getUserProfile();
|
||||
this.resolving = prom;
|
||||
const badges = prom.badges;
|
||||
this.resolving = false;
|
||||
for (const thing of badges) {
|
||||
this.localuser.badges.set(thing.id, thing);
|
||||
}
|
||||
return this.localuser.badges.get(id);
|
||||
}
|
||||
}
|
||||
buildpfp() {
|
||||
const pfp = document.createElement('img');
|
||||
pfp.src = this.getpfpsrc();
|
||||
|
@ -235,6 +261,26 @@ class User {
|
|||
this.setstatus("online");
|
||||
div.classList.add("hypoprofile", "flexttb");
|
||||
}
|
||||
const badgediv = document.createElement("div");
|
||||
badgediv.classList.add("badges");
|
||||
(async () => {
|
||||
console.log(this.badge_ids, ":3");
|
||||
if (!this.badge_ids)
|
||||
return;
|
||||
for (const id of this.badge_ids) {
|
||||
const badgejson = await this.getBadge(id);
|
||||
const badge = document.createElement("a");
|
||||
badge.classList.add("badge");
|
||||
const img = document.createElement("img");
|
||||
img.src = badgejson.icon;
|
||||
badge.append(img);
|
||||
const span = document.createElement("span");
|
||||
span.textContent = badgejson.description;
|
||||
badge.append(span);
|
||||
badge.href = badgejson.link;
|
||||
badgediv.append(badge);
|
||||
}
|
||||
})();
|
||||
{
|
||||
const pfp = await this.buildstatuspfp();
|
||||
div.appendChild(pfp);
|
||||
|
@ -246,6 +292,7 @@ class User {
|
|||
const usernamehtml = document.createElement("h2");
|
||||
usernamehtml.textContent = this.username;
|
||||
userbody.appendChild(usernamehtml);
|
||||
userbody.appendChild(badgediv);
|
||||
const discrimatorhtml = document.createElement("h3");
|
||||
discrimatorhtml.classList.add("tag");
|
||||
discrimatorhtml.textContent = this.username + "#" + this.discriminator;
|
||||
|
|
|
@ -15,6 +15,7 @@ import { MarkDown } from "./markdown.js";
|
|||
const wsCodesRetry=new Set([4000,4003,4005,4007,4008,4009]);
|
||||
|
||||
class Localuser{
|
||||
badges:Map<string,{id:string,description:string,icon:string,link:string}>=new Map();
|
||||
lastSequence:number|null=null;
|
||||
token:string;
|
||||
userinfo:Specialuser;
|
||||
|
|
|
@ -1925,3 +1925,27 @@ form div{
|
|||
border-radius:.1in;
|
||||
height:17px;
|
||||
}
|
||||
.badge{
|
||||
display:flex;
|
||||
color:white;
|
||||
width:fit-content;
|
||||
img{
|
||||
width: .1in;
|
||||
height: .1in;
|
||||
}
|
||||
background: var(--profile-bg);
|
||||
padding: .04in;
|
||||
border-radius: .07in;
|
||||
font-size: .12in;
|
||||
align-items: center;
|
||||
border: solid .01in var(--black);
|
||||
box-sizing: border-box;
|
||||
}
|
||||
.badges{
|
||||
width:fit-content;
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
flex-wrap: wrap;
|
||||
justify-content: flex-start;
|
||||
align-items: center;
|
||||
}
|
|
@ -25,7 +25,7 @@ class User{
|
|||
premium_since: string;
|
||||
premium_type: number;
|
||||
theme_colors: string;
|
||||
badge_ids: string;
|
||||
badge_ids: string[];
|
||||
members: WeakMap<Guild, Member|undefined|Promise<Member|undefined>>=new WeakMap();
|
||||
private status:string;
|
||||
clone(){
|
||||
|
@ -121,6 +121,34 @@ class User{
|
|||
async resolvemember(guild:Guild){
|
||||
return await Member.resolveMember(this,guild);
|
||||
}
|
||||
|
||||
async getUserProfile(){
|
||||
return (await fetch(`${this.info.api}/users/${this.id.replace("#clone","")}/profile?with_mutual_guilds=true&with_mutual_friends=true`,{
|
||||
headers:this.localuser.headers
|
||||
})).json()
|
||||
}
|
||||
resolving:false|Promise<any>=false;
|
||||
async getBadge(id:string){
|
||||
console.log(id,":3")
|
||||
if(this.localuser.badges.has(id)){
|
||||
return this.localuser.badges.get(id);
|
||||
}else{
|
||||
if(this.resolving)
|
||||
{
|
||||
await this.resolving;
|
||||
return this.localuser.badges.get(id);
|
||||
}
|
||||
|
||||
const prom=await this.getUserProfile();
|
||||
this.resolving=prom;
|
||||
const badges=prom.badges;
|
||||
this.resolving=false;
|
||||
for(const thing of badges){
|
||||
this.localuser.badges.set(thing.id,thing);
|
||||
}
|
||||
return this.localuser.badges.get(id);
|
||||
}
|
||||
}
|
||||
buildpfp(){
|
||||
const pfp=document.createElement('img');
|
||||
pfp.src=this.getpfpsrc();
|
||||
|
@ -236,7 +264,25 @@ class User{
|
|||
this.setstatus("online");
|
||||
div.classList.add("hypoprofile","flexttb");
|
||||
}
|
||||
|
||||
const badgediv=document.createElement("div");
|
||||
badgediv.classList.add("badges");
|
||||
(async ()=>{
|
||||
console.log(this.badge_ids,":3")
|
||||
if(!this.badge_ids) return;
|
||||
for(const id of this.badge_ids){
|
||||
const badgejson=await this.getBadge(id);
|
||||
const badge=document.createElement("a");
|
||||
badge.classList.add("badge")
|
||||
const img=document.createElement("img");
|
||||
img.src=badgejson.icon;
|
||||
badge.append(img);
|
||||
const span=document.createElement("span");
|
||||
span.textContent=badgejson.description;
|
||||
badge.append(span);
|
||||
badge.href=badgejson.link;
|
||||
badgediv.append(badge);
|
||||
}
|
||||
})()
|
||||
{
|
||||
const pfp=await this.buildstatuspfp();
|
||||
div.appendChild(pfp);
|
||||
|
@ -248,7 +294,7 @@ class User{
|
|||
const usernamehtml=document.createElement("h2");
|
||||
usernamehtml.textContent=this.username;
|
||||
userbody.appendChild(usernamehtml);
|
||||
|
||||
userbody.appendChild(badgediv);
|
||||
const discrimatorhtml=document.createElement("h3");
|
||||
discrimatorhtml.classList.add("tag");
|
||||
discrimatorhtml.textContent=this.username+"#"+this.discriminator;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue