From 7a745a52863aaa8796d7a0b31ada9bc42eae71d7 Mon Sep 17 00:00:00 2001 From: MathMan05 Date: Sat, 27 Jul 2024 12:51:42 -0500 Subject: [PATCH] general changes and reducing logs --- .dist/direct.js | 3 --- .dist/embed.js | 2 -- .dist/file.js | 1 - .dist/localuser.js | 12 +--------- .dist/member.js | 3 +-- .dist/message.js | 20 ++++++++++------- .dist/user.js | 35 ++++++++++++++++++++++++----- webpage/direct.ts | 3 --- webpage/embed.ts | 9 ++++---- webpage/file.ts | 4 ++-- webpage/jsontypes.ts | 53 +++++++++++++++++++++++++++++++++++++++----- webpage/localuser.ts | 14 ++---------- webpage/member.ts | 3 +-- webpage/message.ts | 20 ++++++++++------- webpage/style.css | 2 +- webpage/user.ts | 40 +++++++++++++++++++++++++++------ 16 files changed, 146 insertions(+), 78 deletions(-) diff --git a/.dist/direct.js b/.dist/direct.js index babd339..091cc4c 100644 --- a/.dist/direct.js +++ b/.dist/direct.js @@ -7,7 +7,6 @@ class Direct extends Guild { constructor(json, owner) { super(-1, owner, null); this.message_notifications = 0; - console.log(json); this.owner = owner; if (!this.localuser) { console.error("Owner was not included, please fix"); @@ -169,13 +168,11 @@ class Group extends Channel { const noti = document.createElement("div"); noti.classList.add("unread", "notiunread", "pinged"); noti.textContent = "" + this.mentions; - console.log(this.mentions); div["noti"] = noti; div.append(noti); const buildpfp = this.user.buildpfp(); div["all"] = this; buildpfp.classList.add("mentioned"); - console.log(this); div.append(buildpfp); sentdms.append(div); div.onclick = _ => { diff --git a/.dist/embed.js b/.dist/embed.js index 279c4d4..5033ecd 100644 --- a/.dist/embed.js +++ b/.dist/embed.js @@ -5,7 +5,6 @@ class Embed { owner; json; constructor(json, owner) { - console.log(json); this.type = this.getType(json); this.owner = owner; this.json = json; @@ -41,7 +40,6 @@ class Embed { return this.guild.localuser; } generateRich() { - console.log(this.json); const div = document.createElement("div"); if (this.json.color) { div.style.backgroundColor = "#" + this.json.color.toString(16); diff --git a/.dist/file.js b/.dist/file.js index 90979c1..2e80120 100644 --- a/.dist/file.js +++ b/.dist/file.js @@ -10,7 +10,6 @@ class File { url; size; constructor(fileJSON, owner) { - console.log(fileJSON); this.owner = owner; this.id = fileJSON.id; this.filename = fileJSON.filename; diff --git a/.dist/localuser.js b/.dist/localuser.js index 65c20f6..ed30238 100644 --- a/.dist/localuser.js +++ b/.dist/localuser.js @@ -288,7 +288,6 @@ class Localuser { if (!guild) { guild = this.guildids.get("@me"); } - console.log(this.guildids, id, guild); if (this.lookingguild) { this.lookingguild.html.classList.remove("serveropen"); } @@ -345,7 +344,6 @@ class Localuser { div.classList.add("home", "servericon"); serverlist.appendChild(div); div.onclick = _ => { - console.log("clicked :3"); this.createGuild(); }; const guildDiscoveryContainer = document.createElement("div"); @@ -356,7 +354,6 @@ class Localuser { this.guildDiscovery(); }); } - console.log("test"); this.unreads(); } createGuild() { @@ -369,7 +366,6 @@ class Localuser { "Invite Link/Code", "", function () { - console.log(this); inviteurl = this.value; } ], @@ -389,7 +385,6 @@ class Localuser { method: "POST", headers: this.headers, }).then(r => r.json()).then(_ => { - console.log(_); if (_.message) { error.textContent = _.message; } @@ -463,13 +458,11 @@ class Localuser { this.unreads(); } unreads() { - console.log(this.guildhtml); for (const thing of this.guilds) { if (thing.id === "@me") { continue; } const html = this.guildhtml.get(thing.id); - console.log(html); thing.unreads(html); } } @@ -506,7 +499,6 @@ class Localuser { updatepfp(file) { var reader = new FileReader(); reader.readAsDataURL(file); - console.log(this.headers); reader.onload = () => { fetch(this.info.api.toString() + "/users/@me", { method: "PATCH", @@ -515,7 +507,6 @@ class Localuser { avatar: reader.result, }) }); - console.log(reader.result); }; } updatepronouns(pronouns) { @@ -559,7 +550,6 @@ class Localuser { else { build += " is typing"; } - console.log(typingtext.classList); if (showing) { typingtext.classList.remove("hidden"); document.getElementById("typingtext").textContent = build; @@ -573,7 +563,7 @@ class Localuser { let file = null; let newprouns = null; let newbio = null; - let hypouser = new User(this.user, this, true); + let hypouser = this.user.clone(); function regen() { hypotheticalProfile.textContent = ""; const hypoprofile = hypouser.buildprofile(-1, -1); diff --git a/.dist/member.js b/.dist/member.js index e6261e7..0e9d5c4 100644 --- a/.dist/member.js +++ b/.dist/member.js @@ -54,12 +54,11 @@ class Member { this.user = memberjson; } else { - console.log(this.user, memberjson); if (SnowFlake.getSnowFlakeFromID(this?.id, User)) { this.user = SnowFlake.getSnowFlakeFromID(this.id, User).getObject(); return; } - this.user = new User(this.user, owner.localuser); + this.user = new User(membery.user, owner.localuser); } } get guild() { diff --git a/.dist/message.js b/.dist/message.js index 0063d38..aa81af8 100644 --- a/.dist/message.js +++ b/.dist/message.js @@ -62,7 +62,6 @@ class Message { this.giveData(messagejson); } giveData(messagejson) { - console.log(messagejson); for (const thing of Object.keys(messagejson)) { if (thing === "attachments") { this.attachments = []; @@ -83,15 +82,19 @@ class Message { this.member = new Member(messagejson.member, this.guild); continue; } + else if (thing === "embeds") { + this.embeds = []; + for (const thing in messagejson.embeds) { + console.log(thing, messagejson.embeds); + this.embeds[thing] = new Embed(messagejson.embeds[thing], this); + } + continue; + } this[thing] = messagejson[thing]; } - for (const thing in this.embeds) { - console.log(thing, this.embeds); - this.embeds[thing] = new Embed(this.embeds[thing], this); - } - this.author = new User(this.author, this.localuser); - for (const thing in this.mentions) { - this.mentions[thing] = new User(this.mentions[thing], this.localuser); + this.author = new User(messagejson.author, this.localuser); + for (const thing in messagejson.mentions) { + this.mentions[thing] = new User(messagejson.mentions[thing], this.localuser); } if (!this.member && this.guild.id !== "@me") { this.author.resolvemember(this.guild).then(_ => { @@ -311,6 +314,7 @@ class Message { messagedwrap.appendChild(attach); } if (this.embeds.length) { + console.log(this.embeds); const embeds = document.createElement("div"); embeds.classList.add("flexltr"); for (const thing of this.embeds) { diff --git a/.dist/user.js b/.dist/user.js index 1ac96e6..1403982 100644 --- a/.dist/user.js +++ b/.dist/user.js @@ -14,6 +14,31 @@ class User { discriminator; pronouns; bot; + public_flags; + accent_color; + banner; + premium_since; + premium_type; + theme_colors; + badge_ids; + clone() { + return new User({ + username: this.username, + id: this.id + "#clone", + public_flags: this.public_flags, + discriminator: this.discriminator, + avatar: this.avatar, + accent_color: this.accent_color, + banner: this.banner, + bio: this.bio.rawString, + premium_since: this.premium_since, + premium_type: this.premium_type, + bot: this.bot, + theme_colors: this.theme_colors, + pronouns: this.pronouns, + badge_ids: this.badge_ids + }, this.owner); + } get id() { return this.snowflake.id; } @@ -29,13 +54,13 @@ class User { }); }); } - static checkuser(userjson, owner) { - if (User.userids[userjson.id]) { - return User.userids[userjson.id]; + static checkuser(user, owner) { + if (User.userids[user.id]) { + return User.userids[user.id]; } else { - const tempuser = new User(userjson, owner, true); - User.userids[userjson.id] = tempuser; + const tempuser = new User(user, owner, true); + User.userids[user.id] = tempuser; return tempuser; } } diff --git a/webpage/direct.ts b/webpage/direct.ts index 2f81528..f0f4a68 100644 --- a/webpage/direct.ts +++ b/webpage/direct.ts @@ -11,7 +11,6 @@ class Direct extends Guild{ constructor(json:dirrectjson[],owner:Localuser){ super(-1,owner,null); this.message_notifications=0; - console.log(json); this.owner=owner; if(!this.localuser){ console.error("Owner was not included, please fix") @@ -167,13 +166,11 @@ class Group extends Channel{ const noti=document.createElement("div"); noti.classList.add("unread","notiunread","pinged"); noti.textContent=""+this.mentions; - console.log(this.mentions) div["noti"]=noti; div.append(noti) const buildpfp=this.user.buildpfp(); div["all"]=this; buildpfp.classList.add("mentioned"); - console.log(this); div.append(buildpfp) sentdms.append(div); div.onclick=_=>{ diff --git a/webpage/embed.ts b/webpage/embed.ts index e582d3a..6432c3e 100644 --- a/webpage/embed.ts +++ b/webpage/embed.ts @@ -1,18 +1,18 @@ import {Fullscreen} from "./fullscreen.js"; import {Message} from "./message.js"; import {MarkDown} from "./markdown.js"; +import { embedjson } from "./jsontypes.js"; class Embed{ type:string; owner:Message; - json; - constructor(json, owner:Message){ - console.log(json); + json:embedjson; + constructor(json:embedjson, owner:Message){ this.type=this.getType(json); this.owner=owner; this.json=json; } - getType(json){ + getType(json:embedjson){ return json.type||"rich"; } generateHTML(){ @@ -43,7 +43,6 @@ class Embed{ return this.guild.localuser; } generateRich(){ - console.log(this.json) const div=document.createElement("div"); if(this.json.color){ div.style.backgroundColor="#"+this.json.color.toString(16); diff --git a/webpage/file.ts b/webpage/file.ts index d71d384..8687e06 100644 --- a/webpage/file.ts +++ b/webpage/file.ts @@ -1,6 +1,7 @@ import { Message } from "./message.js"; import { Fullscreen } from "./fullscreen.js"; -type filejson= {id:string,filename:string,content_type:string,width:number,height:number,proxy_url:string|undefined,url:string,size:number}; +import { filejson } from "./jsontypes.js"; + class File{ owner:Message; id:string; @@ -12,7 +13,6 @@ class File{ url:string; size:number; constructor(fileJSON:filejson,owner:Message){ - console.log(fileJSON); this.owner=owner; this.id=fileJSON.id; this.filename=fileJSON.filename; diff --git a/webpage/jsontypes.ts b/webpage/jsontypes.ts index 8726007..f98cb92 100644 --- a/webpage/jsontypes.ts +++ b/webpage/jsontypes.ts @@ -267,13 +267,54 @@ type messagejson={ edited_timestamp: string, tts: boolean, mention_everyone: boolean, - mentions: [], - mention_roles: [], - attachments: [], - embeds: [], - reactions: [], + mentions: [], //need examples to fix + mention_roles: [], //need examples to fix + attachments: filejson[], + embeds: embedjson[], + reactions: [], //ToDo nonce: string, pinned: boolean, type: number } -export {readyjson,dirrectjson,channeljson,guildjson,rolesjson,userjson,memberjson,mainuserjson,messagejson}; +type filejson={ + id:string, + filename:string, + content_type:string, + width:number, + height:number, + proxy_url:string|undefined, + url:string, + size:number +}; +type embedjson={ + type:string|null, + color?:number, + author:{ + icon_url?:string, + name?:string, + url?:string, + title?:string, + }, + title?:string, + url?:string, + description?:string, + fields?:{ + name:string, + value:string, + inline:boolean, + }[], + footer?:{ + icon_url?:string, + text?:string, + thumbnail?:string, + }, + timestamp?:string, + thumbnail:{ + proxy_url:string, + url:string, + }, + provider:{ + name:string, + } +} +export {readyjson,dirrectjson,channeljson,guildjson,rolesjson,userjson,memberjson,mainuserjson,messagejson,filejson,embedjson}; diff --git a/webpage/localuser.ts b/webpage/localuser.ts index e3b2f9f..9eca905 100644 --- a/webpage/localuser.ts +++ b/webpage/localuser.ts @@ -7,7 +7,7 @@ import {Fullscreen} from "./fullscreen.js"; import {setTheme, Specialuser} from "./login.js"; import { SnowFlake } from "./snowflake.js"; import { Message } from "./message.js"; -import { channeljson, readyjson } from "./jsontypes.js"; +import { channeljson, readyjson, userjson } from "./jsontypes.js"; const wsCodesRetry=new Set([4000,4003,4005,4007,4008,4009]); @@ -303,7 +303,6 @@ class Localuser{ if(!guild){ guild=this.guildids.get("@me"); } - console.log(this.guildids,id,guild); if(this.lookingguild){ this.lookingguild.html.classList.remove("serveropen"); } @@ -364,7 +363,6 @@ class Localuser{ div.classList.add("home","servericon") serverlist.appendChild(div) div.onclick=_=>{ - console.log("clicked :3") this.createGuild(); } @@ -377,7 +375,6 @@ class Localuser{ }); } - console.log("test"); this.unreads(); } createGuild(){ @@ -391,7 +388,6 @@ class Localuser{ "Invite Link/Code", "", function(){ - console.log(this) inviteurl=this.value; } ], @@ -411,7 +407,6 @@ class Localuser{ method:"POST", headers:this.headers, }).then(r=>r.json()).then(_=>{ - console.log(_); if(_.message){ error.textContent=_.message; } @@ -493,11 +488,9 @@ class Localuser{ this.unreads(); } unreads():void{ - console.log(this.guildhtml) for(const thing of this.guilds){ if(thing.id==="@me"){continue;} const html=this.guildhtml.get(thing.id); - console.log(html); thing.unreads(html); } } @@ -533,7 +526,6 @@ class Localuser{ updatepfp(file:Blob):void{ var reader = new FileReader(); reader.readAsDataURL(file); - console.log(this.headers); reader.onload = ()=>{ fetch(this.info.api.toString()+"/users/@me",{ method:"PATCH", @@ -542,7 +534,6 @@ class Localuser{ avatar:reader.result, }) }); - console.log(reader.result); }; } @@ -586,7 +577,6 @@ class Localuser{ }else{ build+=" is typing"; } - console.log(typingtext.classList); if(showing){ typingtext.classList.remove("hidden"); document.getElementById("typingtext").textContent=build; @@ -599,7 +589,7 @@ class Localuser{ let file=null; let newprouns=null; let newbio=null; - let hypouser=new User(this.user,this,true); + let hypouser=this.user.clone(); function regen(){ hypotheticalProfile.textContent=""; const hypoprofile=hypouser.buildprofile(-1,-1); diff --git a/webpage/member.ts b/webpage/member.ts index 325f687..5f43bcd 100644 --- a/webpage/member.ts +++ b/webpage/member.ts @@ -52,12 +52,11 @@ class Member{ if(error){ this.user=memberjson as User; }else{ - console.log(this.user,memberjson); if(SnowFlake.getSnowFlakeFromID(this?.id,User)){ this.user=SnowFlake.getSnowFlakeFromID(this.id,User).getObject(); return; } - this.user=new User(this.user,owner.localuser); + this.user=new User((membery as memberjson).user,owner.localuser); } } get guild(){ diff --git a/webpage/message.ts b/webpage/message.ts index 13e8577..f5876f3 100644 --- a/webpage/message.ts +++ b/webpage/message.ts @@ -68,7 +68,6 @@ class Message{ } giveData(messagejson:messagejson){ - console.log(messagejson); for(const thing of Object.keys(messagejson)){ if(thing==="attachments"){ this.attachments=[]; @@ -85,17 +84,21 @@ class Message{ }else if(thing==="member"){ this.member=new Member(messagejson.member,this.guild); continue; + }else if(thing ==="embeds"){ + this.embeds=[]; + for(const thing in messagejson.embeds){ + console.log(thing,messagejson.embeds) + this.embeds[thing]=new Embed(messagejson.embeds[thing],this); + } + continue; } this[thing]=messagejson[thing]; } - for(const thing in this.embeds){ - console.log(thing,this.embeds) - this.embeds[thing]=new Embed(this.embeds[thing],this); - } - this.author=new User(this.author,this.localuser); - for(const thing in this.mentions){ - this.mentions[thing]=new User(this.mentions[thing],this.localuser); + + this.author=new User(messagejson.author,this.localuser); + for(const thing in messagejson.mentions){ + this.mentions[thing]=new User(messagejson.mentions[thing],this.localuser); } if(!this.member&&this.guild.id!=="@me"){ this.author.resolvemember(this.guild).then(_=>{ @@ -316,6 +319,7 @@ class Message{ messagedwrap.appendChild(attach) } if(this.embeds.length){ + console.log(this.embeds); const embeds = document.createElement("div") embeds.classList.add("flexltr"); for(const thing of this.embeds){ diff --git a/webpage/style.css b/webpage/style.css index 30d8865..f7b0614 100644 --- a/webpage/style.css +++ b/webpage/style.css @@ -83,7 +83,7 @@ th { flex-wrap: nowrap; flex-direction: column; max-height: 20in; - padding: .02in .2in 0 .1in; + padding: .02in .1in 0 .1in; flex-shrink: 0; width: 100%; box-sizing: border-box; diff --git a/webpage/user.ts b/webpage/user.ts index 860a127..4591e43 100644 --- a/webpage/user.ts +++ b/webpage/user.ts @@ -5,6 +5,7 @@ import {Contextmenu} from "./contextmenu.js"; import {Localuser} from "./localuser.js"; import {Guild} from "./guild.js"; import { SnowFlake } from "./snowflake.js"; +import { userjson } from "./jsontypes.js"; class User{ static userids={}; @@ -17,6 +18,31 @@ class User{ discriminator:string; pronouns:string; bot:boolean; + public_flags: number; + accent_color: string; + banner: string; + premium_since: string; + premium_type: number; + theme_colors: string; + badge_ids: string; + clone(){ + return new User({ + username:this.username, + id:this.id+"#clone", + public_flags:this.public_flags, + discriminator:this.discriminator, + avatar:this.avatar, + accent_color:this.accent_color, + banner:this.banner, + bio:this.bio.rawString, + premium_since:this.premium_since, + premium_type:this.premium_type, + bot:this.bot, + theme_colors:this.theme_colors, + pronouns:this.pronouns, + badge_ids:this.badge_ids + },this.owner) + } get id(){ return this.snowflake.id; } @@ -33,12 +59,12 @@ class User{ }); }) } - static checkuser(userjson,owner:Localuser){ - if(User.userids[userjson.id]){ - return User.userids[userjson.id]; + static checkuser(user:User|userjson,owner:Localuser):User{ + if(User.userids[user.id]){ + return User.userids[user.id]; }else{ - const tempuser=new User(userjson,owner,true) - User.userids[userjson.id]=tempuser; + const tempuser=new User(user as userjson,owner,true) + User.userids[user.id]=tempuser; return tempuser; } } @@ -48,7 +74,7 @@ class User{ get localuser(){ return this.owner; } - constructor(userjson,owner:Localuser,dontclone=false){ + constructor(userjson:userjson,owner:Localuser,dontclone=false){ this.owner=owner; if(!owner){console.error("missing localuser")} if(dontclone){ @@ -78,7 +104,7 @@ class User{ pfp.classList.add("userid:"+this.id); return pfp; } - userupdate(json){ + userupdate(json:userjson){ if(json.avatar!==this.avatar){ console.log this.changepfp(json.avatar);