merge eslint changes

This commit is contained in:
MathMan05 2024-09-02 15:32:42 -05:00
commit 1183dc40ce

View file

@ -1,3 +1,4 @@
import{Guild}from"./guild.js";
import{Channel}from"./channel.js";
import{Direct}from"./direct.js";
@ -7,7 +8,7 @@ import {Dialog} from "./dialog.js";
import{getapiurls, getBulkInfo, setTheme, Specialuser}from"./login.js";
import{ SnowFlake }from"./snowflake.js";
import{ Message }from"./message.js";
import { channeljson, memberChunk, memberjson, messageCreateJson, presencejson, readyjson, wsjson } from "./jsontypes.js";
import{ channeljson, memberjson, presencejson, readyjson }from"./jsontypes.js";
import{ Member }from"./member.js";
import{ FormError, Settings }from"./settings.js";
import{ MarkDown }from"./markdown.js";
@ -91,10 +92,12 @@ class Localuser{
for(const thing of ready.d.read_state.entries){
const channel=this.resolveChannelFromID(thing.id);
if(!channel){continue;}
if(!channel){
continue;
}
const guild=channel.guild;
if(guild===undefined){
continue
continue;
}
const guildid=guild.snowflake;
(this.guildids.get(guildid.id) as Guild).channelids[thing.channel_id].readStateInfo(thing);
@ -105,7 +108,7 @@ class Localuser{
user.relationshipType=thing.type;
}
this.pingEndpoint()
this.pingEndpoint();
}
outoffocus():void{
const servers=document.getElementById("servers") as HTMLDivElement;
@ -124,14 +127,14 @@ class Localuser{
this.guilds=[];
this.guildids=new Map();
if(this.ws){
this.ws.close(4001)
this.ws.close(4001);
}
SnowFlake.clear();
}
swapped=false;
async initwebsocket():Promise<void>{
let returny:()=>void;
const ws= new WebSocket(this.serverurls.gateway.toString()+"?encoding=json&v=9"+(DecompressionStream?"&compress=zlib-stream":""));;
const ws= new WebSocket(this.serverurls.gateway.toString()+"?encoding=json&v=9"+(DecompressionStream?"&compress=zlib-stream":""));
this.ws=ws;
let ds:DecompressionStream;
let w:WritableStreamDefaultWriter;
@ -143,32 +146,31 @@ class Localuser{
w= ds.writable.getWriter();
r=ds.readable.getReader();
arr=new Uint8Array();
}
const promise=new Promise<void>((res)=>{
returny=res
ws.addEventListener('open', (_event) => {
console.log('WebSocket connected');
const promise=new Promise<void>(res=>{
returny=res;
ws.addEventListener("open", _event=>{
console.log("WebSocket connected");
ws.send(JSON.stringify({
"op": 2,
"d": {
"token":this.token,
"capabilities": 16381,
"properties": {
"browser": "Jank Client",
"client_build_number": 0,//might update this eventually lol
"release_channel": "Custom",
"browser_user_agent": navigator.userAgent
op: 2,
d: {
token: this.token,
capabilities: 16381,
properties: {
browser: "Jank Client",
client_build_number: 0,//might update this eventually lol
release_channel: "Custom",
browser_user_agent: navigator.userAgent
},
"compress": !!DecompressionStream,
"presence": {
"status": "online",
"since": null,//new Date().getTime()
"activities": [],
"afk": false
compress: Boolean(DecompressionStream),
presence: {
status: "online",
since: null,//new Date().getTime()
activities: [],
afk: false
}
}
}))
}));
});
const textdecode=new TextDecoder();
if(DecompressionStream){
@ -190,16 +192,16 @@ class Localuser{
}
});
let order=new Promise<void>((res)=>(res()));
let order=new Promise<void>(res=>(res()));
ws.addEventListener('message', async (event) => {
ws.addEventListener("message", async event=>{
const temp2=order;
order=new Promise<void>(async (res)=>{
order=new Promise<void>(async res=>{
await temp2;
let temp:{op:number,t:string};
try{
if(event.data instanceof Blob){
const buff=await event.data.arrayBuffer()
const buff=await event.data.arrayBuffer();
const array=new Uint8Array(buff);
const temparr=new Uint8Array(array.length+arr.length);
@ -220,13 +222,13 @@ class Localuser{
if(temp.op===0&&temp.t==="READY"){
returny();
}
await this.handleEvent(temp as wsjson);
await this.handleEvent(temp);
}catch(e){
console.error(e);
}finally{
res();
}
})
});
});
ws.addEventListener("close",async event=>{
@ -253,7 +255,7 @@ class Localuser{
this.serverurls=newurls;
this.userinfo.json.serverurls=this.info;
this.userinfo.updateLocal();
break
break;
}
case 4:
@ -264,14 +266,13 @@ class Localuser{
this.serverurls=newurls;
this.userinfo.json.serverurls=this.info;
this.userinfo.updateLocal();
break
break;
}
}
case 5:
{
const breakappart=new URL(this.info.wellknown).origin.split(".");
const url="https://"+breakappart[breakappart.length-2]+"."+breakappart[breakappart.length-1]
const url="https://"+breakappart.at(-2)+"."+breakappart.at(-1);
const newurls=await getapiurls(url);
if(newurls){
this.info=newurls;
@ -279,7 +280,7 @@ class Localuser{
this.userinfo.json.serverurls=this.info;
this.userinfo.updateLocal();
}
break
break;
}
}
setTimeout(()=>{
@ -298,9 +299,8 @@ class Localuser{
});
await promise;
return;
}
async handleEvent(temp:wsjson){
async handleEvent(temp){
console.debug(temp);
if(temp.s)this.lastSequence=temp.s;
if(temp.op==0){
@ -312,38 +312,15 @@ class Localuser{
break;
case"MESSAGE_DELETE":
console.log(temp.d);
temp.d.guild_id??="@me";
const guild=this.guildids.get(temp.d.guild_id);
if(guild){
const channel=guild.channelids[temp.d.guild_id]
if(channel){
const message=channel.messages.get(temp.d.id);
if(message){
message.deleteEvent();
}
}
}
SnowFlake.getSnowFlakeFromID(temp.d.id,Message).getObject().deleteEvent();
break;
case"READY":
this.gottenReady(temp as readyjson);
break;
case "MESSAGE_UPDATE":{
temp.d.guild_id??="@me";
const guild=this.guildids.get(temp.d.guild_id);
if(guild){
const channel=guild.channelids[temp.d.guild_id]
if(channel){
const message=channel.messages.get(temp.d.id);
if(message){
case"MESSAGE_UPDATE":
const message=SnowFlake.getSnowFlakeFromID(temp.d.id,Message).getObject();
message.giveData(temp.d);
}
}
}
break;
}
case"TYPING_START":
if(this.initialized){
this.typingStart(temp);
@ -356,7 +333,7 @@ class Localuser{
users.userupdate(temp.d);
}
}
break
break;
case"CHANNEL_UPDATE":
if(this.initialized){
this.updateChannel(temp.d);
@ -399,14 +376,13 @@ class Localuser{
if(temp.d.member){
thing=await Member.new(temp.d.member,guild) as Member;
}else{
thing={id:temp.d.user_id}
thing={id: temp.d.user_id};
}
message.reactionAdd(temp.d.emoji,thing);
}
break;
case"MESSAGE_REACTION_REMOVE":
if(SnowFlake.hasSnowFlakeFromID(temp.d.message_id,Message)){
const message=SnowFlake.getSnowFlakeFromID(temp.d.message_id,Message).getObject();
console.log("test");
message.reactionRemove(temp.d.emoji,temp.d.user_id);
@ -414,37 +390,36 @@ class Localuser{
break;
case"MESSAGE_REACTION_REMOVE_ALL":
if(SnowFlake.hasSnowFlakeFromID(temp.d.message_id, Message)){
const messageReactionRemoveAll = SnowFlake.getSnowFlakeFromID(temp.d.message_id, Message).getObject()
messageReactionRemoveAll.reactionRemoveAll()
const messageReactionRemoveAll = SnowFlake.getSnowFlakeFromID(temp.d.message_id, Message).getObject();
messageReactionRemoveAll.reactionRemoveAll();
}
break
break;
case"MESSAGE_REACTION_REMOVE_EMOJI":
if(SnowFlake.hasSnowFlakeFromID(temp.d.message_id, Message)){
const messageReactionRemoveEmoji = SnowFlake.getSnowFlakeFromID(temp.d.message_id, Message).getObject()
messageReactionRemoveEmoji.reactionRemoveEmoji(temp.d.emoji)
const messageReactionRemoveEmoji = SnowFlake.getSnowFlakeFromID(temp.d.message_id, Message).getObject();
messageReactionRemoveEmoji.reactionRemoveEmoji(temp.d.emoji);
}
break;
case"GUILD_MEMBERS_CHUNK":
this.gotChunk(temp.d);
break;
}
}else if(temp.op===10){
if(!this.ws)return;
console.log("heartbeat down");
this.heartbeat_interval=temp.d.heartbeat_interval;
this.ws.send(JSON.stringify({op:1,d:this.lastSequence}))
this.ws.send(JSON.stringify({op: 1,d: this.lastSequence}));
}else if(temp.op===11){
setTimeout(_=>{
if(!this.ws)return;
if (this.connectionSucceed===0) this.connectionSucceed=Date.now()
this.ws.send(JSON.stringify({op:1,d:this.lastSequence}))
},this.heartbeat_interval)
if(this.connectionSucceed===0)this.connectionSucceed=Date.now();
this.ws.send(JSON.stringify({op: 1,d: this.lastSequence}));
},this.heartbeat_interval);
}
}
heartbeat_interval:number;
resolveChannelFromID(ID:string):Channel|undefined{
let resolve=this.guilds.find(guild => guild.channelids[ID]);
const resolve=this.guilds.find(guild=>guild.channelids[ID]);
if(resolve){
return resolve.channelids[ID];
}
@ -480,11 +455,12 @@ class Localuser{
this.buildservers();
if(location[3]==="channels"){
const guild=this.loadGuild(location[4]);
if(!guild){return;}
if(!guild){
return;
}
guild.loadChannel(location[5]);
this.channelfocus=guild.channelids[location[5]];
}
}
loaduser():void{
(document.getElementById("username") as HTMLSpanElement).textContent=this.user.username;
@ -509,7 +485,7 @@ class Localuser{
if(!guild)return;
if(guild.html){
guild.html.classList.add("serveropen")
guild.html.classList.add("serveropen");
}
this.lookingguild=guild;
(document.getElementById("serverName") as HTMLElement).textContent=guild.properties.name;
@ -518,7 +494,7 @@ class Localuser{
channels.innerHTML="";
const html=guild.getHTML();
channels.appendChild(html);
console.log("found :3",html)
console.log("found :3",html);
return guild;
}
buildservers():void{
@ -529,7 +505,7 @@ class Localuser{
div.classList.add("home","servericon");
img.src="/icons/home.svg";
img.classList.add("svgtheme","svgicon")
img.classList.add("svgtheme","svgicon");
img["all"]=this.guildids.get("@me");
(this.guildids.get("@me") as Guild).html=outdiv;
const unread=document.createElement("div");
@ -538,20 +514,20 @@ class Localuser{
outdiv.append(div);
div.appendChild(img);
outdiv.classList.add("servernoti")
outdiv.classList.add("servernoti");
serverlist.append(outdiv);
img.onclick=function(){
this["all"].loadGuild();
this["all"].loadChannel();
}
};
const sentdms=document.createElement("div");
sentdms.classList.add("sentdms");
serverlist.append(sentdms);
sentdms.id="sentdms";
const br=document.createElement("hr")
const br=document.createElement("hr");
br.classList.add("lightbr");
serverlist.appendChild(br)
serverlist.appendChild(br);
for(const thing of this.guilds){
if(thing instanceof Direct){
(thing as Direct).unreaddms();
@ -568,11 +544,11 @@ class Localuser{
const div=document.createElement("div");
div.textContent="+";
div.classList.add("home","servericon")
serverlist.appendChild(div)
div.classList.add("home","servericon");
serverlist.appendChild(div);
div.onclick=_=>{
this.createGuild();
}
};
const guilddsdiv=document.createElement("div");
const guildDiscoveryContainer=document.createElement("img");
guildDiscoveryContainer.src="/icons/explore.svg";
@ -583,7 +559,6 @@ class Localuser{
guildDiscoveryContainer.addEventListener("click", ()=>{
this.guildDiscovery();
});
}
this.unreads();
}
@ -593,7 +568,7 @@ class Localuser{
const fields:{name:string,icon:string|null}={
name: "",
icon: null,
}
};
const full=new Dialog(["tabs",[
["Join using invite",[
"vdiv",
@ -604,15 +579,14 @@ class Localuser{
inviteurl=this.value;
}
],
["html",error]
,
["html",error],
["button",
"",
"Submit",
_=>{
let parsed="";
if(inviteurl.includes("/")){
parsed=inviteurl.split("/")[inviteurl.split("/").length-1]
parsed=inviteurl.split("/")[inviteurl.split("/").length-1];
}else{
parsed=inviteurl;
}
@ -623,7 +597,7 @@ class Localuser{
if(_.message){
error.textContent=_.message;
}
})
});
}
]
@ -638,7 +612,7 @@ class Localuser{
reader.readAsDataURL(target.files[0]);
reader.onload=()=>{
fields.icon=reader.result as string;
}
};
}],
["textbox","Name:","",function(event:InputEvent){
const target=event.target as HTMLInputElement;
@ -647,14 +621,14 @@ class Localuser{
["button","","submit",()=>{
this.makeGuild(fields).then(_=>{
if(_.message){
alert(_.errors.name._errors[0].message)
alert(_.errors.name._errors[0].message);
}else{
full.hide();
}
})
});
}]
]]
]])
]]);
full.show();
}
async makeGuild(fields:{name:string,icon:string|null}){
@ -684,7 +658,7 @@ class Localuser{
const guilds=document.createElement("div");
guilds.id="discovery-guild-content";
json.guilds.forEach((guild)=>{
json.guilds.forEach(guild=>{
const content=document.createElement("div");
content.classList.add("discovery-guild");
@ -720,12 +694,12 @@ class Localuser{
headers: this.headers
});
if(joinRes.ok) full.hide();
})
});
guilds.appendChild(content);
})
});
content.appendChild(guilds);
}
messageCreate(messagep:messageCreateJson):void{
messageCreate(messagep):void{
messagep.d.guild_id??="@me";
const guild=this.guildids.get(messagep.d.guild_id);
if(!guild)return;
@ -734,30 +708,31 @@ class Localuser{
}
unreads():void{
for(const thing of this.guilds){
if(thing.id==="@me"){continue;}
if(thing.id==="@me"){
continue;
}
const html=this.guildhtml.get(thing.id);
thing.unreads(html);
}
}
async typingStart(typing):Promise<void>{
if(this.channelfocus?.id===typing.d.channel_id){
const guild=this.guildids.get(typing.d.guild_id);
if(!guild)return;
const memb=await Member.new(typing.d.member,guild);
if(!memb)return;
if(memb.id===this.user.id){
console.log("you is typing")
console.log("you is typing");
return;
}
console.log("user is typing and you should see it");
this.typing.set(memb,new Date().getTime());
this.typing.set(memb,Date.now());
setTimeout(this.rendertyping.bind(this),10000);
this.rendertyping();
}
}
updatepfp(file:Blob):void{
var reader = new FileReader();
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = ()=>{
fetch(this.info.api+"/users/@me",{
@ -768,11 +743,10 @@ class Localuser{
})
});
};
}
updatebanner(file:Blob|null):void{
if(file){
var reader = new FileReader();
const reader = new FileReader();
reader.readAsDataURL(file);
reader.onload = ()=>{
fetch(this.info.api+"/users/@me",{
@ -792,8 +766,6 @@ class Localuser{
})
});
}
}
updateProfile(json:{bio?:string,pronouns?:string,accent_color?:number}){
fetch(this.info.api+"/users/@me/profile",{
@ -807,7 +779,7 @@ class Localuser{
let build="";
let showing=false;
let i=0;
const curtime=new Date().getTime()-5000;
const curtime=Date.now()-5000;
for(const thing of this.typing.keys()){
if(this.typing.get(thing) as number>curtime){
if(i!==0){
@ -837,21 +809,21 @@ class Localuser{
typingtext.classList.add("hidden");
}
}
showusersettings(){
async showusersettings(){
const settings=new Settings("Settings");
{
const userOptions=settings.addButton("User Settings",{ltr: true});
const hypotheticalProfile=document.createElement("div");
let file:undefined|File|null=undefined;
let newpronouns:string|undefined=undefined;
let newbio:string|undefined=undefined;
let hypouser=this.user.clone();
let file:undefined|File|null;
let newpronouns:string|undefined;
let newbio:string|undefined;
const hypouser=this.user.clone();
let color:string;
async function regen(){
hypotheticalProfile.textContent="";
const hypoprofile=await hypouser.buildprofile(-1,-1);
hypotheticalProfile.appendChild(hypoprofile)
hypotheticalProfile.appendChild(hypoprofile);
}
regen();
const settingsLeft=userOptions.addOptions("");
@ -860,7 +832,7 @@ class Localuser{
const finput=settingsLeft.addFileInput("Upload pfp:",_=>{
if(file){
this.updatepfp(file)
this.updatepfp(file);
}
},{clear: true});
finput.watchForChange(_=>{
@ -870,7 +842,7 @@ class Localuser{
hypouser.hypotheticalpfp=true;
regen();
return;
};
}
if(_.length){
file=_[0];
const blob = URL.createObjectURL(file);
@ -879,10 +851,10 @@ class Localuser{
regen();
}
});
let bfile:undefined|File|null=undefined;
let bfile:undefined|File|null;
const binput=settingsLeft.addFileInput("Upload banner:",_=>{
if(bfile!==undefined){
this.updatebanner(bfile)
this.updatebanner(bfile);
}
},{clear: true});
binput.watchForChange(_=>{
@ -904,7 +876,7 @@ class Localuser{
let changed=false;
const pronounbox=settingsLeft.addTextInput("Pronouns",_=>{
if(newpronouns||newbio||changed){
this.updateProfile({pronouns:newpronouns,bio:newbio,accent_color:parseInt("0x"+color.substr(1),16)});
this.updateProfile({pronouns: newpronouns,bio: newbio,accent_color: Number.parseInt("0x"+color.substr(1),16)});
}
},{initText: this.user.pronouns});
pronounbox.watchForChange(_=>{
@ -926,14 +898,14 @@ class Localuser{
}else{
color="transparent";
}
const colorPicker=settingsLeft.addColorInput("Profile color",(_)=>{},{initColor:color});
const colorPicker=settingsLeft.addColorInput("Profile color",_=>{},{initColor: color});
colorPicker.watchForChange(_=>{
console.log()
console.log();
color=_;
hypouser.accent_color=parseInt("0x"+_.substr(1),16);
hypouser.accent_color=Number.parseInt("0x"+_.substr(1),16);
changed=true;
regen();
})
});
}
{
const tas=settings.addButton("Themes & sounds");
@ -950,7 +922,7 @@ class Localuser{
Voice.setNotificationSound(sounds[_]);
},sounds,{defaultIndex: sounds.indexOf(Voice.getNotificationSound())}).watchForChange(_=>{
Voice.noises(sounds[_]);
})
});
}
{
@ -959,8 +931,8 @@ class Localuser{
fixsvgtheme();
userinfos.accent_color=_;
localStorage.setItem("userinfos",JSON.stringify(userinfos));
document.documentElement.style.setProperty('--accent-color', userinfos.accent_color);
},{initColor:userinfos.accent_color})
document.documentElement.style.setProperty("--accent-color", userinfos.accent_color);
},{initColor: userinfos.accent_color});
}
}
{
@ -986,10 +958,10 @@ class Localuser{
headers: this.headers
});
form.addTextInput("Code:","code",{required: true});
})
});
}else{
security.addButtonInput("","Enable 2FA",async ()=>{
let secret=""
let secret="";
for(let i=0;i<18;i++){
secret+="ABCDEFGHIJKLMNOPQRSTUVWXYZ234567"[Math.floor(Math.random()*32)];
}
@ -1017,18 +989,22 @@ class Localuser{
form.addTextInput("Account Password:","password",{required: true,password: true});
form.addTextInput("Code:","code",{required: true});
form.setValue("secret",secret);
})
});
}
security.addButtonInput("","Change discriminator",()=>{
const form=security.addSubForm("Change Discriminator",(_)=>{security.returnFromSub()},{
const form=security.addSubForm("Change Discriminator",_=>{
security.returnFromSub();
},{
fetchURL: (this.info.api+"/users/@me/"),
headers: this.headers,
method: "PATCH"
});
form.addTextInput("New discriminator:","discriminator")
form.addTextInput("New discriminator:","discriminator");
});
security.addButtonInput("","Change email",()=>{
const form=security.addSubForm("Change Email",(_)=>{security.returnFromSub()},{
const form=security.addSubForm("Change Email",_=>{
security.returnFromSub();
},{
fetchURL: (this.info.api+"/users/@me/"),
headers: this.headers,
method: "PATCH"
@ -1040,7 +1016,9 @@ class Localuser{
form.addTextInput("New email:","email");
});
security.addButtonInput("","Change username",()=>{
const form=security.addSubForm("Change Username",(_)=>{security.returnFromSub()},{
const form=security.addSubForm("Change Username",_=>{
security.returnFromSub();
},{
fetchURL: (this.info.api+"/users/@me/"),
headers: this.headers,
method: "PATCH"
@ -1052,7 +1030,9 @@ class Localuser{
form.addTextInput("New username:","username");
});
security.addButtonInput("","Change password",()=>{
const form=security.addSubForm("Change Password",(_)=>{security.returnFromSub()},{
const form=security.addSubForm("Change Password",_=>{
security.returnFromSub();
},{
fetchURL: (this.info.api+"/users/@me/"),
headers: this.headers,
method: "PATCH"
@ -1066,7 +1046,7 @@ class Localuser{
form.addTextInput("New password:","").watchForChange(text=>{
in1=text;
});
const copy=form.addTextInput("New password again:","")
const copy=form.addTextInput("New password again:","");
copy.watchForChange(text=>{
in2=text;
});
@ -1076,9 +1056,9 @@ class Localuser{
}else{
throw new FormError(copy,"Passwords don't match");
}
})
});
}
});
};
genSecurity();
}
{
@ -1102,39 +1082,43 @@ class Localuser{
});
const connectionJSON=await connectionRes.json();
window.open(connectionJSON.url, "_blank", "noopener noreferrer");
})
});
}else{
container.classList.add("disabled");
container.title="This connection has been disabled server-side.";
}
connectionContainer.appendChild(container);
})
})
});
});
connections.addHTMLArea(connectionContainer);
}
{
const devPortal=settings.addButton("Developer Portal");
let appName="";
devPortal.addTextInput("Name:", value => {
appName=value
const teamsRes = await fetch(this.info.api + "/teams", {
headers: this.headers
});
devPortal.addButtonInput("", "Create application", async () => {
if (appName.trim().length == 0) {
return alert("Please enter a name for the application.");
}
const teams = await teamsRes.json();
const res=await fetch(this.info.api+"/applications", {
method: "POST",
headers: this.headers,
body: JSON.stringify({
name: appName
})
});
const json=await res.json();
devPortal.addButtonInput("", "Create application", ()=>{
const form = devPortal.addSubForm("Create application",(json:any)=>{
if(json.message) form.error("name", json.message);
else{
devPortal.returnFromSub();
this.manageApplication(json.id);
})
}
}, {
fetchURL: this.info.api + "/applications",
headers: this.headers,
method: "POST"
});
form.addTextInput("Name", "name", { required: true });
form.addSelect("Team", "team_id", ["Personal", ...teams.map(team=>team.name)], {
defaultIndex: 0
});
});
const appListContainer=document.createElement("div");
appListContainer.id="app-list-container";
@ -1161,8 +1145,8 @@ class Localuser{
this.manageApplication(application.id);
});
appListContainer.appendChild(container);
})
})
});
});
devPortal.addHTMLArea(appListContainer);
}
settings.show();
@ -1193,7 +1177,7 @@ class Localuser{
reader.readAsDataURL(event.target.files[0]);
reader.onload=()=>{
fields.icon=reader.result;
}
};
}]
]
],
@ -1251,7 +1235,7 @@ class Localuser{
]
]
]
)
);
appDialog.show();
}
async manageBot(appId=""){
@ -1272,7 +1256,7 @@ class Localuser{
],
["hdiv",
["textbox", "Bot username:", json.bot.username, event=>{
fields.username=event.target.value
fields.username=event.target.value;
}],
["vdiv",
fields.avatar ? ["img", fields.avatar, [128, 128]] : ["text", "No avatar"],
@ -1281,7 +1265,7 @@ class Localuser{
reader.readAsDataURL(event.target.files[0]);
reader.onload=()=>{
fields.avatar=reader.result;
}
};
}]
]
],
@ -1327,23 +1311,24 @@ class Localuser{
readonly waitingmembers:Map<string,Map<string,(returns:memberjson|undefined)=>void>>=new Map();
readonly presences:Map<string,presencejson>=new Map();
async resolvemember(id:string,guildid:string):Promise<memberjson|undefined>{
if(guildid==="@me"){return undefined}
if(guildid==="@me"){
return undefined;
}
let guildmap=this.waitingmembers.get(guildid);
if(!guildmap){
guildmap=new Map();
this.waitingmembers.set(guildid,guildmap);
}
const promise:Promise<memberjson|undefined>=new Promise((res)=>{
const promise:Promise<memberjson|undefined>=new Promise(res=>{
guildmap.set(id,res);
this.getmembers();
})
});
return await promise;
}
fetchingmembers:Map<string,boolean>=new Map();
noncemap:Map<string,(r:[memberjson[],string[]])=>void>=new Map();
noncebuild:Map<string,[memberjson[],string[],number[]]>=new Map();
async gotChunk(chunk:memberChunk){
async gotChunk(chunk:{chunk_index:number,chunk_count:number,nonce:string,not_found?:string[],members?:memberjson[],presences:presencejson[]}){
for(const thing of chunk.presences){
if(thing.user){
this.presences.set(thing.user.id,thing);
@ -1361,15 +1346,16 @@ class Localuser{
if(arr[2].length===chunk.chunk_count){
console.log("got through");
this.noncebuild.delete(chunk.nonce);
const func=this.noncemap.get(chunk.nonce)
const func=this.noncemap.get(chunk.nonce);
if(!func)return;
func([arr[0],arr[1]]);
this.noncemap.delete(chunk.nonce);
}
}
async getmembers(){
const promise=new Promise(res=>{setTimeout(res,10)});
const promise=new Promise(res=>{
setTimeout(res,10);
});
await promise;//allow for more to be sent at once :P
if(this.ws){
this.waitingmembers.forEach(async (value,guildid)=>{
@ -1378,12 +1364,16 @@ class Localuser{
return;
}
const build:string[]=[];
for(const key of keys){build.push(key);if(build.length===100){break;}};
for(const key of keys){
build.push(key);if(build.length===100){
break;
}
}
if(!build.length){
this.waitingmembers.delete(guildid);
return
};
const promise:Promise<[memberjson[],string[]]>=new Promise((res)=>{
return;
}
const promise:Promise<[memberjson[],string[]]>=new Promise(res=>{
const nonce=""+Math.floor(Math.random()*100000000000);
this.noncemap.set(nonce,res);
this.noncebuild.set(nonce,[[],[],[]]);
@ -1399,9 +1389,8 @@ class Localuser{
}
}));
this.fetchingmembers.set(guildid,true);
})
const prom=await promise;;
});
const prom=await promise;
const data=prom[0];
for(const thing of data){
if(value.has(thing.id)){
@ -1413,7 +1402,7 @@ class Localuser{
}
for(const thing of prom[1]){
if(value.has(thing)){
const func=value.get(thing)
const func=value.get(thing);
if(!func)continue;
func(undefined);
value.delete(thing);
@ -1421,7 +1410,7 @@ class Localuser{
}
this.fetchingmembers.delete(guildid);
this.getmembers();
})
});
}
}
async pingEndpoint(){
@ -1462,20 +1451,22 @@ export {Localuser};
let fixsvgtheme:Function;
{
let last:string;
const dud=document.createElement("p")
dud.classList.add("svgtheme")
const dud=document.createElement("p");
dud.classList.add("svgtheme");
document.body.append(dud);
const css=window.getComputedStyle(dud);
function fixsvgtheme_(){
//console.log(things);
const color=css.color;
if(color===last) {return};
if(color===last){
return;
}
last=color;
const thing=color.replace("rgb(","").replace(")","").split(",");
//sconsole.log(thing);
const r=+thing[0]/255;
const g=+thing[1]/255;
const b=+thing[2]/255;
const r=Number(thing[0])/255;
const g=Number(thing[1])/255;
const b=Number(thing[2])/255;
const max=Math.max(r,g,b);
const min=Math.min(r,g,b);
const l=(max+min)/2;
@ -1483,10 +1474,10 @@ let fixsvgtheme:Function;
let s:number;
let h:number;
if(max!==min){
if(l<=.5){
if(l<=0.5){
s=(max-min)/(max+min);
}else{
s=(max-min)/(2.0-max-min);
s=(max-min)/(2-max-min);
}
if(r===max){
h=(g-b)/(max-min);
@ -1500,13 +1491,12 @@ let fixsvgtheme:Function;
h=0;
}
const rot=Math.floor(h*60)+"deg";
const invert=.5-(s/2)+"";
const invert=0.5-(s/2)+"";
const brightness=Math.floor((l*200))+"%";
document.documentElement.style.setProperty('--rot', rot);
document.documentElement.style.setProperty('--invert', invert);
document.documentElement.style.setProperty('--brightness', brightness);
document.documentElement.style.setProperty("--rot", rot);
document.documentElement.style.setProperty("--invert", invert);
document.documentElement.style.setProperty("--brightness", brightness);
}
fixsvgtheme=fixsvgtheme_;
setTimeout(fixsvgtheme_,100);