diff --git a/.dist/audio.js b/.dist/audio.js index e98dad7..24751a8 100644 --- a/.dist/audio.js +++ b/.dist/audio.js @@ -37,12 +37,12 @@ class Voice { this.updateWave(); } updateWave() { - const func = this.waveFucnion(); + const func = this.waveFunction(); for (let i = 0; i < this.buffer.length; i++) { this.buffer[i] = func(i / this.audioCtx.sampleRate, this.freq); } } - waveFucnion() { + waveFunction() { if (typeof this.wave === 'function') { return this.wave; } @@ -127,12 +127,12 @@ class Voice { } static setNotificationSound(sound) { let userinfos = getBulkInfo(); - userinfos.preferances.notisound = sound; + userinfos.preferences.notisound = sound; localStorage.setItem("userinfos", JSON.stringify(userinfos)); } static getNotificationSound() { let userinfos = getBulkInfo(); - return userinfos.preferances.notisound; + return userinfos.preferences.notisound; } } export { Voice as Voice }; diff --git a/.dist/channel.js b/.dist/channel.js index 50f0467..1565e18 100644 --- a/.dist/channel.js +++ b/.dist/channel.js @@ -16,7 +16,7 @@ class Channel { name; id; parent_id; - parrent; + parent; children; guild_id; messageids; @@ -80,7 +80,7 @@ class Channel { this.name = JSON.name; this.id = JSON.id; this.parent_id = JSON.parent_id; - this.parrent = null; + this.parent = null; this.children = []; this.guild_id = JSON.guild_id; this.messageids = {}; @@ -131,12 +131,12 @@ class Channel { } for (const thing of member.roles) { if (this.permission_overwrites[thing.id]) { - let perm = this.permission_overwrites[thing.id].getPermision(name); + let perm = this.permission_overwrites[thing.id].getPermission(name); if (perm) { return perm === 1; } } - if (thing.permissions.getPermision(name)) { + if (thing.permissions.getPermission(name)) { return true; } } @@ -152,12 +152,12 @@ class Channel { this.children.sort((a, b) => { return a.position - b.position; }); } resolveparent(guild) { - this.parrent = guild.channelids[this.parent_id]; - this.parrent ??= null; - if (this.parrent !== null) { - this.parrent.children.push(this); + this.parent = guild.channelids[this.parent_id]; + this.parent ??= null; + if (this.parent !== null) { + this.parent.children.push(this); } - return this.parrent === null; + return this.parent === null; } calculateReorder() { let position = -1; @@ -290,9 +290,9 @@ class Channel { if (this.guild !== this.localuser.lookingguild) { return null; } - else if (this.parrent) { + else if (this.parent) { for (const thing of search) { - if (thing["all"] === this.parrent) { + if (thing["all"] === this.parent) { for (const thing2 of thing.children[1].children) { if (thing2["all"] === this) { return thing2; @@ -338,32 +338,32 @@ class Channel { event.preventDefault(); if (container) { that.move_id = this.id; - if (that.parrent) { - that.parrent.children.splice(that.parrent.children.indexOf(that), 1); + if (that.parent) { + that.parent.children.splice(that.parent.children.indexOf(that), 1); } - that.parrent = this; + that.parent = this; container.prepend(Channel.dragged[1]); this.children.unshift(that); } else { console.log(this, Channel.dragged); that.move_id = this.parent_id; - if (that.parrent) { - that.parrent.children.splice(that.parrent.children.indexOf(that), 1); + if (that.parent) { + that.parent.children.splice(that.parent.children.indexOf(that), 1); } else { this.guild.headchannels.splice(this.guild.headchannels.indexOf(that), 1); } - that.parrent = this.parrent; - if (that.parrent) { + that.parent = this.parent; + if (that.parent) { const build = []; - for (let i = 0; i < that.parrent.children.length; i++) { - build.push(that.parrent.children[i]); - if (that.parrent.children[i] === this) { + for (let i = 0; i < that.parent.children.length; i++) { + build.push(that.parent.children[i]); + if (that.parent.children[i] === this) { build.push(that); } } - that.parrent.children = build; + that.parent.children = build; } else { const build = []; @@ -383,7 +383,7 @@ class Channel { } createChannel(name, type) { fetch(this.info.api.toString() + "/guilds/" + this.guild.id + "/channels", { - method: "Post", + method: "POST", headers: this.headers, body: JSON.stringify({ name: name, @@ -506,14 +506,13 @@ class Channel { } ; const j = await fetch(this.info.api.toString() + "/channels/" + this.id + "/messages?limit=100", { - method: 'GET', headers: this.headers, }); - const responce = await j.json(); - if (responce.length !== 100) { + const response = await j.json(); + if (response.length !== 100) { this.allthewayup = true; } - for (const thing of responce) { + for (const thing of response) { const messager = new Message(thing, this); if (this.messageids[messager.id] === undefined) { this.messageids[messager.id] = messager; @@ -536,25 +535,24 @@ class Channel { } const out = this; await fetch(this.info.api.toString() + "/channels/" + this.id + "/messages?before=" + this.messages[this.messages.length - 1].id + "&limit=100", { - method: "GET", headers: this.headers - }).then((j) => { return j.json(); }).then(responce => { + }).then((j) => { return j.json(); }).then(response => { //messages.innerHTML = ''; - //responce.reverse() + //response.reverse() let next; - if (responce.length === 0) { + if (response.length === 0) { out.allthewayup = true; } - for (const i in responce) { + for (const i in response) { let messager; if (!next) { - messager = new Message(responce[i], this); + messager = new Message(response[i], this); } else { messager = next; } - if (responce[+i + 1] !== undefined) { - next = new Message(responce[+i + 1], this); + if (response[+i + 1] !== undefined) { + next = new Message(response[+i + 1], this); } else { next = undefined; @@ -589,7 +587,7 @@ class Channel { this.type = JSON.type; this.name = JSON.name; this.parent_id = JSON.parent_id; - this.parrent = null; + this.parent = null; this.children = []; this.guild_id = JSON.guild_id; this.messageids = {}; @@ -771,15 +769,15 @@ class Channel { this.permission_overwritesar.push([role.id, perm]); } async updateRolePermissions(id, perms) { - const permision = this.permission_overwrites[id]; - permision.allow = perms.allow; - permision.deny = perms.deny; + const permission = this.permission_overwrites[id]; + permission.allow = perms.allow; + permission.deny = perms.deny; await fetch(this.info.api.toString() + "/channels/" + this.id + "/permissions/" + id, { method: "PUT", headers: this.headers, body: JSON.stringify({ - allow: permision.allow.toString(), - deny: permision.deny.toString(), + allow: permission.allow.toString(), + deny: permission.deny.toString(), id: id, type: 0 }) diff --git a/.dist/direct.js b/.dist/direct.js index d51c3f9..a39d928 100644 --- a/.dist/direct.js +++ b/.dist/direct.js @@ -19,7 +19,7 @@ class Direct extends Guild { this.roles = []; this.roleids = {}; this.prevchannel = undefined; - this.properties.name = "Dirrect Messages"; + this.properties.name = "Direct Messages"; for (const thing of JSON) { const temp = new Group(thing, this); this.channels.push(temp); @@ -75,7 +75,7 @@ class Group extends Channel { this.name ??= this.localuser.user.username; this.id = JSON.id; this.parent_id = null; - this.parrent = null; + this.parent = null; this.children = []; this.guild_id = "@me"; this.messageids = {}; diff --git a/.dist/embed.js b/.dist/embed.js index cb0e10e..172bdd3 100644 --- a/.dist/embed.js +++ b/.dist/embed.js @@ -166,10 +166,10 @@ class Embed { const div = document.createElement("div"); div.classList.add("embed"); if (this.json.provider) { - const providor = document.createElement("p"); - providor.classList.add("provider"); - providor.textContent = this.json.provider.name; - div.append(providor); + const provider = document.createElement("p"); + provider.classList.add("provider"); + provider.textContent = this.json.provider.name; + div.append(provider); } const a = document.createElement("a"); a.href = this.json.url; diff --git a/.dist/guild.js b/.dist/guild.js index 07afa58..ff6b29d 100644 --- a/.dist/guild.js +++ b/.dist/guild.js @@ -417,7 +417,7 @@ class Guild { this.channelids[JSON.id] = thischannel; this.channels.push(thischannel); thischannel.resolveparent(this); - if (!thischannel.parrent) { + if (!thischannel.parent) { this.headchannels.push(thischannel); } this.calculateReorder(); @@ -479,8 +479,8 @@ class Guild { build.push(thing) }else{ console.log("fail"); - if(thing.parrent){ - thing.parrent.delChannel(JSON); + if(thing.parent){ + thing.parent.delChannel(JSON); } } } @@ -490,7 +490,7 @@ class Guild { } createChannel(name, type) { fetch(this.info.api.toString() + "/guilds/" + this.id + "/channels", { - method: "Post", + method: "POST", headers: this.headers, body: JSON.stringify({ name: name, type: type }) }); diff --git a/.dist/localuser.js b/.dist/localuser.js index ea9751c..14b10a7 100644 --- a/.dist/localuser.js +++ b/.dist/localuser.js @@ -5,6 +5,7 @@ import { User } from "./user.js"; import { markdown } from "./markdown.js"; import { Fullscreen } from "./fullscreen.js"; import { setTheme } from "./login.js"; +const wsCodesRetry = new Set([4000, 4003, 4005, 4007, 4008, 4009]); class Localuser { packets; token; @@ -25,6 +26,8 @@ class Localuser { ws; typing; wsinterval; + connectionSucceed = 0; + errorBackoff = 0; constructor(userinfo) { this.packets = 1; this.token = userinfo.token; @@ -162,7 +165,7 @@ class Localuser { break; case "TYPING_START": if (this.initialized) { - this.typeingStart(temp); + this.typingStart(temp); } break; case "USER_UPDATE": @@ -202,13 +205,15 @@ class Localuser { const guildy = new Guild(temp.d, this, this.user); this.guilds.push(guildy); this.guildids[guildy.id] = guildy; - document.getElementById("servers").insertBefore(guildy.generateGuildIcon(), document.getElementById("bottomseperator")); + document.getElementById("servers").insertBefore(guildy.generateGuildIcon(), document.getElementById("bottomseparator")); } } } else if (temp.op === 10) { console.log("heartbeat down"); this.wsinterval = setInterval(_ => { + if (this.connectionSucceed === 0) + this.connectionSucceed = Date.now(); this.ws.send(JSON.stringify({ op: 1, d: this.packets })); }, temp.d.heartbeat_interval); this.packets = 1; @@ -221,22 +226,33 @@ class Localuser { console.error(error); } }); - this.ws.addEventListener('close', (event) => { - clearInterval(this.wsinterval); - console.log('WebSocket closed'); - console.warn(event); - if (event.code !== 4000) { - this.unload(); - document.getElementById("loading").classList.remove("doneloading"); - document.getElementById("loading").classList.add("loading"); - this.initwebsocket().then(_ => { - this.loaduser(); - this.init(); - document.getElementById("loading").classList.add("doneloading"); - document.getElementById("loading").classList.remove("loading"); - console.log("done loading"); - }); + this.ws.addEventListener("close", event => { + console.log("WebSocket closed with code " + event.code); + if (this.wsinterval) + clearInterval(this.wsinterval); + this.unload(); + document.getElementById("loading").classList.remove("doneloading"); + document.getElementById("loading").classList.add("loading"); + if (((event.code > 1000 && event.code < 1016) || wsCodesRetry.has(event.code))) { + if (this.connectionSucceed !== 0 && Date.now() > this.connectionSucceed + 20000) + this.errorBackoff = 0; + else + this.errorBackoff++; + this.connectionSucceed = 0; + document.getElementById("load-desc").innerHTML = "Unable to connect to the Spacebar server, retrying in " + Math.round(0.2 + (this.errorBackoff * 2.8)) + " seconds..."; + setTimeout(() => { + document.getElementById("load-desc").textContent = "Retrying..."; + this.initwebsocket().then(() => { + this.loaduser(); + this.init(); + document.getElementById("loading").classList.add("doneloading"); + document.getElementById("loading").classList.remove("loading"); + console.log("done loading"); + }); + }, 200 + (this.errorBackoff * 2800)); } + else + document.getElementById("load-desc").textContent = "Unable to connect to the Spacebar server. Please try logging out and back in."; }); await promise; return; @@ -340,7 +356,7 @@ class Localuser { const br = document.createElement("hr"); br.classList.add("lightbr"); serverlist.appendChild(br); - br.id = "bottomseperator"; + br.id = "bottomseparator"; const div = document.createElement("div"); div.textContent = "+"; div.classList.add("addserver", "servericon"); @@ -410,7 +426,7 @@ class Localuser { thing.unreads(this.guildhtml[thing.id]); } } - typeingStart(typing) { + typingStart(typing) { if (this.channelfocus.id === typing.d.channel_id) { const memb = typing.d.member; let name; @@ -506,15 +522,15 @@ class Localuser { } } genusersettings() { - const hypothetcialprofie = document.createElement("div"); + const hypotheticalProfile = document.createElement("div"); let file = null; let newprouns = null; let newbio = null; let hypouser = new User(this.user, this, true); function regen() { - hypothetcialprofie.textContent = ""; + hypotheticalProfile.textContent = ""; const hypoprofile = hypouser.buildprofile(-1, -1); - hypothetcialprofie.appendChild(hypoprofile); + hypotheticalProfile.appendChild(hypoprofile); } regen(); this.usersettings = new Fullscreen(["hdiv", @@ -560,7 +576,7 @@ class Localuser { }, Voice.sounds.indexOf(Voice.getNotificationSound())] ], ["vdiv", - ["html", hypothetcialprofie] + ["html", hypotheticalProfile] ] ], _ => { }, function () { console.log(this); diff --git a/.dist/login.js b/.dist/login.js index 47d5cdc..75180aa 100644 --- a/.dist/login.js +++ b/.dist/login.js @@ -25,9 +25,9 @@ function setDefaults() { localStorage.setItem("userinfos", JSON.stringify({ currentuser: null, users: {}, - preferances: { + preferences: { theme: "Dark", - notifcations: false, + notifications: false, notisound: "three", }, })); @@ -36,15 +36,15 @@ function setDefaults() { if (userinfos.users === undefined) { userinfos.users = {}; } - if (userinfos.preferances === undefined) { - userinfos.preferances = { + if (userinfos.preferences === undefined) { + userinfos.preferences = { theme: "Dark", - notifcations: false, + notifications: false, notisound: "three", }; } - if (userinfos.preferances && (userinfos.preferances.notisound === undefined)) { - userinfos.preferances.notisound = "three"; + if (userinfos.preferences && (userinfos.preferences.notisound === undefined)) { + userinfos.preferences.notisound = "three"; } localStorage.setItem("userinfos", JSON.stringify(userinfos)); } @@ -160,7 +160,7 @@ async function login(username, password) { try { const info = JSON.parse(localStorage.getItem("instanceinfo")); const url = new URL(info.login); - return await fetch(url.origin + '/api/auth/login', options).then(responce => responce.json()) + return await fetch(url.origin + '/api/auth/login', options).then(response => response.json()) .then((response) => { console.log(response, response.message); if ("Invalid Form Body" === response.message) { diff --git a/.dist/markdown.js b/.dist/markdown.js index f247258..bbf11bf 100644 --- a/.dist/markdown.js +++ b/.dist/markdown.js @@ -298,15 +298,15 @@ function markdown(text, { keep = false, stdsize = false } = {}) { if (find === count) { appendcurrent(); i = j; - const underscores = "~~"; + const tildes = "~~"; if (count === 2) { const s = document.createElement("s"); if (keep) { - s.append(underscores); + s.append(tildes); } s.appendChild(markdown(build, { keep: keep, stdsize: stdsize })); if (keep) { - s.append(underscores); + s.append(tildes); } span.appendChild(s); } @@ -333,17 +333,17 @@ function markdown(text, { keep = false, stdsize = false } = {}) { if (find === count) { appendcurrent(); i = j; - const underscores = "||"; + const pipes = "||"; if (count === 2) { const j = document.createElement("j"); if (keep) { - j.append(underscores); + j.append(pipes); } j.appendChild(markdown(build, { keep: keep, stdsize: stdsize })); j.classList.add("spoiler"); j.onclick = markdown.unspoil; if (keep) { - j.append(underscores); + j.append(pipes); } span.appendChild(j); } diff --git a/.dist/member.js b/.dist/member.js index 7bbaa83..7143cbf 100644 --- a/.dist/member.js +++ b/.dist/member.js @@ -127,7 +127,7 @@ class Member { } isAdmin() { for (const role of this.roles) { - if (role.permissions.getPermision("ADMINISTRATOR")) { + if (role.permissions.getPermission("ADMINISTRATOR")) { return true; } } diff --git a/.dist/message.js b/.dist/message.js index 64defe9..cd6e004 100644 --- a/.dist/message.js +++ b/.dist/message.js @@ -258,11 +258,11 @@ class Message { build.appendChild(text); if (this.attachments.length) { console.log(this.attachments); - const attatch = document.createElement("tr"); + const attach = document.createElement("tr"); for (const thing of this.attachments) { - attatch.appendChild(thing.getHTML()); + attach.appendChild(thing.getHTML()); } - messagedwrap.appendChild(attatch); + messagedwrap.appendChild(attach); } if (this.embeds.length) { const embeds = document.createElement("tr"); diff --git a/.dist/permissions.js b/.dist/permissions.js index 010101e..5725dd7 100644 --- a/.dist/permissions.js +++ b/.dist/permissions.js @@ -8,10 +8,10 @@ class Permissions { this.allow = BigInt(allow); this.deny = BigInt(deny); } - getPermisionbit(b, big) { + getPermissionbit(b, big) { return Boolean((big >> BigInt(b)) & 1n); } - setPermisionbit(b, state, big) { + setPermissionbit(b, state, big) { const bit = 1n << BigInt(b); return (big & ~bit) | (BigInt(state) << BigInt(b)); //thanks to geotale for this code :3 } @@ -233,30 +233,30 @@ class Permissions { i++; } } - getPermision(name) { - if (this.getPermisionbit(Permissions.map[name], this.allow)) { + getPermission(name) { + if (this.getPermissionbit(Permissions.map[name], this.allow)) { return 1; } - else if (this.getPermisionbit(Permissions.map[name], this.deny)) { + else if (this.getPermissionbit(Permissions.map[name], this.deny)) { return -1; } else { return 0; } } - setPermision(name, setto) { + setPermission(name, setto) { const bit = Permissions.map[name]; if (setto === 0) { - this.deny = this.setPermisionbit(bit, false, this.deny); - this.allow = this.setPermisionbit(bit, false, this.allow); + this.deny = this.setPermissionbit(bit, false, this.deny); + this.allow = this.setPermissionbit(bit, false, this.allow); } else if (setto === 1) { - this.deny = this.setPermisionbit(bit, false, this.deny); - this.allow = this.setPermisionbit(bit, true, this.allow); + this.deny = this.setPermissionbit(bit, false, this.deny); + this.allow = this.setPermissionbit(bit, true, this.allow); } else if (setto === -1) { - this.deny = this.setPermisionbit(bit, true, this.deny); - this.allow = this.setPermisionbit(bit, false, this.allow); + this.deny = this.setPermissionbit(bit, true, this.deny); + this.allow = this.setPermissionbit(bit, false, this.allow); } else { console.error("invalid number entered:" + setto); diff --git a/.dist/settings.js b/.dist/settings.js index 42a4ead..08ce7bd 100644 --- a/.dist/settings.js +++ b/.dist/settings.js @@ -62,7 +62,7 @@ class Buttons { } save() { } } -class PermisionToggle { +class PermissionToggle { rolejson; permissions; owner; @@ -87,7 +87,7 @@ class PermisionToggle { generateCheckbox() { const div = document.createElement("div"); div.classList.add("tritoggle"); - const state = this.permissions.getPermision(this.rolejson.name); + const state = this.permissions.getPermission(this.rolejson.name); const on = document.createElement("input"); on.type = "radio"; on.name = this.rolejson.name; @@ -97,7 +97,7 @@ class PermisionToggle { } ; on.onclick = _ => { - this.permissions.setPermision(this.rolejson.name, 1); + this.permissions.setPermission(this.rolejson.name, 1); this.owner.changed(); }; const no = document.createElement("input"); @@ -109,7 +109,7 @@ class PermisionToggle { } ; no.onclick = _ => { - this.permissions.setPermision(this.rolejson.name, 0); + this.permissions.setPermission(this.rolejson.name, 0); this.owner.changed(); }; if (this.permissions.hasDeny) { @@ -122,7 +122,7 @@ class PermisionToggle { } ; off.onclick = _ => { - this.permissions.setPermision(this.rolejson.name, -1); + this.permissions.setPermission(this.rolejson.name, -1); this.owner.changed(); }; } @@ -151,7 +151,7 @@ class RoleList extends Buttons { this.permission = new Permissions("0"); } for (const thing of Permissions.info) { - options.addPermisionToggle(thing, this.permission); // + options.addPermissionToggle(thing, this.permission); // } for (const i of permissions) { this.buttons.push([guild.getRole(i[0]).name, i[0]]); // @@ -181,8 +181,8 @@ class Options { this.options = []; this.owner = owner; } - addPermisionToggle(roleJSON, permissions) { - this.options.push(new PermisionToggle(roleJSON, permissions, this)); + addPermissionToggle(roleJSON, permissions) { + this.options.push(new PermissionToggle(roleJSON, permissions, this)); } generateHTML() { const div = document.createElement("div");