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