fix id and snowflake
This commit is contained in:
parent
5e9405207b
commit
4f80104e2e
17 changed files with 263 additions and 235 deletions
|
@ -13,7 +13,7 @@ class Channel {
|
||||||
owner;
|
owner;
|
||||||
headers;
|
headers;
|
||||||
name;
|
name;
|
||||||
id;
|
snowflake;
|
||||||
parent_id;
|
parent_id;
|
||||||
parent;
|
parent;
|
||||||
children;
|
children;
|
||||||
|
@ -37,6 +37,9 @@ class Channel {
|
||||||
infinite;
|
infinite;
|
||||||
idToPrev = new Map();
|
idToPrev = new Map();
|
||||||
idToNext = new Map();
|
idToNext = new Map();
|
||||||
|
get id() {
|
||||||
|
return this.snowflake.id;
|
||||||
|
}
|
||||||
static setupcontextmenu() {
|
static setupcontextmenu() {
|
||||||
this.contextmenu.addbutton("Copy channel id", function () {
|
this.contextmenu.addbutton("Copy channel id", function () {
|
||||||
console.log(this);
|
console.log(this);
|
||||||
|
@ -66,7 +69,7 @@ class Channel {
|
||||||
}
|
}
|
||||||
sortPerms() {
|
sortPerms() {
|
||||||
this.permission_overwritesar.sort((a, b) => {
|
this.permission_overwritesar.sort((a, b) => {
|
||||||
const order = this.guild.roles.findIndex(_ => _.id === a[0]) - this.guild.roles.findIndex(_ => _.id === b[0]);
|
const order = this.guild.roles.findIndex(_ => _.snowflake === a[0]) - this.guild.roles.findIndex(_ => _.snowflake === b[0]);
|
||||||
return order;
|
return order;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -108,7 +111,7 @@ class Channel {
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
this.headers = this.owner.headers;
|
this.headers = this.owner.headers;
|
||||||
this.name = JSON.name;
|
this.name = JSON.name;
|
||||||
this.id = new SnowFlake(JSON.id, this);
|
this.snowflake = new SnowFlake(JSON.id, this);
|
||||||
this.parent_id = new SnowFlake(JSON.parent_id, undefined);
|
this.parent_id = new SnowFlake(JSON.parent_id, undefined);
|
||||||
this.parent = null;
|
this.parent = null;
|
||||||
this.children = [];
|
this.children = [];
|
||||||
|
@ -160,8 +163,8 @@ class Channel {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
for (const thing of member.roles) {
|
for (const thing of member.roles) {
|
||||||
if (this.permission_overwrites.get(thing.id.id)) {
|
if (this.permission_overwrites.get(thing.id)) {
|
||||||
let perm = this.permission_overwrites.get(thing.id.id).getPermission(name);
|
let perm = this.permission_overwrites.get(thing.id).getPermission(name);
|
||||||
if (perm) {
|
if (perm) {
|
||||||
return perm === 1;
|
return perm === 1;
|
||||||
}
|
}
|
||||||
|
@ -193,7 +196,7 @@ class Channel {
|
||||||
let position = -1;
|
let position = -1;
|
||||||
let build = [];
|
let build = [];
|
||||||
for (const thing of this.children) {
|
for (const thing of this.children) {
|
||||||
const thisthing = { id: thing.id, position: undefined, parent_id: undefined };
|
const thisthing = { id: thing.snowflake, position: undefined, parent_id: undefined };
|
||||||
if (thing.position < position) {
|
if (thing.position < position) {
|
||||||
thing.position = thisthing.position = position + 1;
|
thing.position = thisthing.position = position + 1;
|
||||||
}
|
}
|
||||||
|
@ -344,7 +347,7 @@ class Channel {
|
||||||
if (!this.hasunreads) {
|
if (!this.hasunreads) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fetch(this.info.api.toString() + "/channels/" + this.id + "/messages/" + this.lastmessageid + "/ack", {
|
fetch(this.info.api.toString() + "/channels/" + this.snowflake + "/messages/" + this.lastmessageid + "/ack", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
body: JSON.stringify({})
|
body: JSON.stringify({})
|
||||||
|
@ -367,7 +370,7 @@ class Channel {
|
||||||
const that = Channel.dragged[0];
|
const that = Channel.dragged[0];
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
if (container) {
|
if (container) {
|
||||||
that.move_id = this.id;
|
that.move_id = this.snowflake;
|
||||||
if (that.parent) {
|
if (that.parent) {
|
||||||
that.parent.children.splice(that.parent.children.indexOf(that), 1);
|
that.parent.children.splice(that.parent.children.indexOf(that), 1);
|
||||||
}
|
}
|
||||||
|
@ -412,13 +415,13 @@ class Channel {
|
||||||
return div;
|
return div;
|
||||||
}
|
}
|
||||||
createChannel(name, type) {
|
createChannel(name, type) {
|
||||||
fetch(this.info.api.toString() + "/guilds/" + this.guild.id + "/channels", {
|
fetch(this.info.api.toString() + "/guilds/" + this.guild.snowflake + "/channels", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
name: name,
|
name: name,
|
||||||
type: type,
|
type: type,
|
||||||
parent_id: this.id,
|
parent_id: this.snowflake,
|
||||||
permission_overwrites: [],
|
permission_overwrites: [],
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
@ -427,7 +430,7 @@ class Channel {
|
||||||
let name = this.name;
|
let name = this.name;
|
||||||
let topic = this.topic;
|
let topic = this.topic;
|
||||||
let nsfw = this.nsfw;
|
let nsfw = this.nsfw;
|
||||||
const thisid = this.id;
|
const thisid = this.snowflake;
|
||||||
const thistype = this.type;
|
const thistype = this.type;
|
||||||
const full = new Fullscreen(["hdiv",
|
const full = new Fullscreen(["hdiv",
|
||||||
["vdiv",
|
["vdiv",
|
||||||
|
@ -458,7 +461,7 @@ class Channel {
|
||||||
console.log(full);
|
console.log(full);
|
||||||
}
|
}
|
||||||
deleteChannel() {
|
deleteChannel() {
|
||||||
fetch(this.info.api.toString() + "/channels/" + this.id, {
|
fetch(this.info.api.toString() + "/channels/" + this.snowflake, {
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
headers: this.headers
|
headers: this.headers
|
||||||
});
|
});
|
||||||
|
@ -501,7 +504,7 @@ class Channel {
|
||||||
return snowflake.getObject();
|
return snowflake.getObject();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const gety = await fetch(this.info.api.toString() + "/channels/" + this.id + "/messages?limit=1&around=" + id, { headers: this.headers });
|
const gety = await fetch(this.info.api.toString() + "/channels/" + this.snowflake + "/messages?limit=1&around=" + id, { headers: this.headers });
|
||||||
const json = await gety.json();
|
const json = await gety.json();
|
||||||
return new Message(json[0], this);
|
return new Message(json[0], this);
|
||||||
}
|
}
|
||||||
|
@ -526,7 +529,7 @@ class Channel {
|
||||||
}
|
}
|
||||||
this.makereplybox();
|
this.makereplybox();
|
||||||
this.buildmessages();
|
this.buildmessages();
|
||||||
history.pushState(null, null, "/channels/" + this.guild_id + "/" + this.id);
|
history.pushState(null, null, "/channels/" + this.guild_id + "/" + this.snowflake);
|
||||||
document.getElementById("channelname").textContent = "#" + this.name;
|
document.getElementById("channelname").textContent = "#" + this.name;
|
||||||
console.log(this);
|
console.log(this);
|
||||||
document.getElementById("typebox").contentEditable = "" + this.canMessage;
|
document.getElementById("typebox").contentEditable = "" + this.canMessage;
|
||||||
|
@ -537,7 +540,7 @@ class Channel {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
const j = await fetch(this.info.api.toString() + "/channels/" + this.id + "/messages?limit=100", {
|
const j = await fetch(this.info.api.toString() + "/channels/" + this.snowflake + "/messages?limit=100", {
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
});
|
});
|
||||||
const response = await j.json();
|
const response = await j.json();
|
||||||
|
@ -548,22 +551,22 @@ class Channel {
|
||||||
for (const thing of response) {
|
for (const thing of response) {
|
||||||
const message = new Message(thing, this);
|
const message = new Message(thing, this);
|
||||||
if (prev) {
|
if (prev) {
|
||||||
this.idToNext.set(message.id, prev.id);
|
this.idToNext.set(message.snowflake, prev.id);
|
||||||
this.idToPrev.set(prev.id, message.id);
|
this.idToPrev.set(prev.id, message.snowflake);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.lastmessage = message;
|
this.lastmessage = message;
|
||||||
}
|
}
|
||||||
prev = message;
|
prev = message;
|
||||||
if (this.messageids.get(message.id) === undefined) {
|
if (this.messageids.get(message.snowflake) === undefined) {
|
||||||
this.messageids.set(message.id, message);
|
this.messageids.set(message.snowflake, message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delChannel(JSON) {
|
delChannel(JSON) {
|
||||||
const build = [];
|
const build = [];
|
||||||
for (const thing of this.children) {
|
for (const thing of this.children) {
|
||||||
if (thing.id !== JSON.id) {
|
if (thing.snowflake !== JSON.id) {
|
||||||
build.push(thing);
|
build.push(thing);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -573,7 +576,7 @@ class Channel {
|
||||||
if (this.allthewayup) {
|
if (this.allthewayup) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
await fetch(this.info.api.toString() + "/channels/" + this.id + "/messages?before=" + id + "&limit=100", {
|
await fetch(this.info.api.toString() + "/channels/" + this.snowflake + "/messages?before=" + id + "&limit=100", {
|
||||||
headers: this.headers
|
headers: this.headers
|
||||||
}).then((j) => { return j.json(); }).then(response => {
|
}).then((j) => { return j.json(); }).then(response => {
|
||||||
let next;
|
let next;
|
||||||
|
@ -596,11 +599,11 @@ class Channel {
|
||||||
next = undefined;
|
next = undefined;
|
||||||
console.log("ohno", +i + 1);
|
console.log("ohno", +i + 1);
|
||||||
}
|
}
|
||||||
if (this.messageids.get(messager.id) === undefined) {
|
if (this.messageids.get(messager.snowflake) === undefined) {
|
||||||
this.idToNext.set(messager.id, previd);
|
this.idToNext.set(messager.snowflake, previd);
|
||||||
this.idToPrev.set(previd, messager.id);
|
this.idToPrev.set(previd, messager.snowflake);
|
||||||
previd = messager.id;
|
previd = messager.snowflake;
|
||||||
this.messageids.set(messager.id, messager);
|
this.messageids.set(messager.snowflake, messager);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
console.log("How???");
|
console.log("How???");
|
||||||
|
@ -621,8 +624,8 @@ class Channel {
|
||||||
if (this.messageids.get(this.lastreadmessageid)) {
|
if (this.messageids.get(this.lastreadmessageid)) {
|
||||||
id = this.lastreadmessageid;
|
id = this.lastreadmessageid;
|
||||||
}
|
}
|
||||||
else if (this.lastmessage.id) {
|
else if (this.lastmessage.snowflake) {
|
||||||
id = this.goBackIds(this.lastmessage.id, 50);
|
id = this.goBackIds(this.lastmessage.snowflake, 50);
|
||||||
console.log("shouldn't");
|
console.log("shouldn't");
|
||||||
}
|
}
|
||||||
messages.append(this.infinite.getDiv(id.id));
|
messages.append(this.infinite.getDiv(id.id));
|
||||||
|
@ -666,7 +669,7 @@ class Channel {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.typing = new Date().getTime() + 6000;
|
this.typing = new Date().getTime() + 6000;
|
||||||
fetch(this.info.api.toString() + "/channels/" + this.id + "/typing", {
|
fetch(this.info.api.toString() + "/channels/" + this.snowflake + "/typing", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: this.headers
|
headers: this.headers
|
||||||
});
|
});
|
||||||
|
@ -709,7 +712,7 @@ class Channel {
|
||||||
body.message_reference = replyjson;
|
body.message_reference = replyjson;
|
||||||
}
|
}
|
||||||
console.log(body);
|
console.log(body);
|
||||||
return await fetch(this.info.api.toString() + "/channels/" + this.id + "/messages", {
|
return await fetch(this.info.api.toString() + "/channels/" + this.snowflake + "/messages", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
body: JSON.stringify(body)
|
body: JSON.stringify(body)
|
||||||
|
@ -730,7 +733,7 @@ class Channel {
|
||||||
console.log(attachments[i]);
|
console.log(attachments[i]);
|
||||||
formData.append("files[" + i + "]", attachments[i]);
|
formData.append("files[" + i + "]", attachments[i]);
|
||||||
}
|
}
|
||||||
return await fetch(this.info.api.toString() + "/channels/" + this.id + "/messages", {
|
return await fetch(this.info.api.toString() + "/channels/" + this.snowflake + "/messages", {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: formData,
|
body: formData,
|
||||||
headers: { "Authorization": this.headers.Authorization }
|
headers: { "Authorization": this.headers.Authorization }
|
||||||
|
@ -742,13 +745,13 @@ class Channel {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const messagez = new Message(messagep.d, this);
|
const messagez = new Message(messagep.d, this);
|
||||||
console.log(this.lastmessageid, messagez.id, ":3");
|
console.log(this.lastmessageid, messagez.snowflake, ":3");
|
||||||
this.idToNext.set(this.lastmessageid, messagez.id);
|
this.idToNext.set(this.lastmessageid, messagez.snowflake);
|
||||||
this.idToPrev.set(messagez.id, this.lastmessageid);
|
this.idToPrev.set(messagez.snowflake, this.lastmessageid);
|
||||||
this.lastmessageid = messagez.id;
|
this.lastmessageid = messagez.snowflake;
|
||||||
this.messageids.set(messagez.id, messagez);
|
this.messageids.set(messagez.snowflake, messagez);
|
||||||
if (messagez.author === this.localuser.user) {
|
if (messagez.author === this.localuser.user) {
|
||||||
this.lastreadmessageid = messagez.id;
|
this.lastreadmessageid = messagez.snowflake;
|
||||||
if (this.myhtml) {
|
if (this.myhtml) {
|
||||||
this.myhtml.classList.remove("cunread");
|
this.myhtml.classList.remove("cunread");
|
||||||
}
|
}
|
||||||
|
@ -815,25 +818,25 @@ class Channel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async addRoleToPerms(role) {
|
async addRoleToPerms(role) {
|
||||||
await fetch(this.info.api.toString() + "/channels/" + this.id + "/permissions/" + role.id, {
|
await fetch(this.info.api.toString() + "/channels/" + this.snowflake + "/permissions/" + role.snowflake, {
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
allow: "0",
|
allow: "0",
|
||||||
deny: "0",
|
deny: "0",
|
||||||
id: role.id,
|
id: role.snowflake,
|
||||||
type: 0
|
type: 0
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
const perm = new Permissions("0", "0");
|
const perm = new Permissions("0", "0");
|
||||||
this.permission_overwrites.set(role.id.id, perm);
|
this.permission_overwrites.set(role.id, perm);
|
||||||
this.permission_overwritesar.push([role.id, perm]);
|
this.permission_overwritesar.push([role.snowflake, perm]);
|
||||||
}
|
}
|
||||||
async updateRolePermissions(id, perms) {
|
async updateRolePermissions(id, perms) {
|
||||||
const permission = this.permission_overwrites.get(id);
|
const permission = this.permission_overwrites.get(id);
|
||||||
permission.allow = perms.allow;
|
permission.allow = perms.allow;
|
||||||
permission.deny = perms.deny;
|
permission.deny = perms.deny;
|
||||||
await fetch(this.info.api.toString() + "/channels/" + this.id + "/permissions/" + id, {
|
await fetch(this.info.api.toString() + "/channels/" + this.snowflake + "/permissions/" + id, {
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
|
|
|
@ -15,7 +15,7 @@ class Direct extends Guild {
|
||||||
this.headers = this.localuser.headers;
|
this.headers = this.localuser.headers;
|
||||||
this.channels = [];
|
this.channels = [];
|
||||||
this.channelids = {};
|
this.channelids = {};
|
||||||
this.id = new SnowFlake("@me", this);
|
this.snowflake = new SnowFlake("@me", this);
|
||||||
this.properties = {};
|
this.properties = {};
|
||||||
this.roles = [];
|
this.roles = [];
|
||||||
this.roleids = new Map();
|
this.roleids = new Map();
|
||||||
|
@ -24,7 +24,7 @@ class Direct extends Guild {
|
||||||
for (const thing of JSON) {
|
for (const thing of JSON) {
|
||||||
const temp = new Group(thing, this);
|
const temp = new Group(thing, this);
|
||||||
this.channels.push(temp);
|
this.channels.push(temp);
|
||||||
this.channelids[temp.id.id] = temp;
|
this.channelids[temp.id] = temp;
|
||||||
}
|
}
|
||||||
this.headchannels = this.channels;
|
this.headchannels = this.channels;
|
||||||
}
|
}
|
||||||
|
@ -73,7 +73,7 @@ class Group extends Channel {
|
||||||
this.user = this.localuser.user;
|
this.user = this.localuser.user;
|
||||||
}
|
}
|
||||||
this.name ??= this.localuser.user.username;
|
this.name ??= this.localuser.user.username;
|
||||||
this.id = new SnowFlake(JSON.id, this);
|
this.snowflake = new SnowFlake(JSON.id, this);
|
||||||
this.parent_id = null;
|
this.parent_id = null;
|
||||||
this.parent = null;
|
this.parent = null;
|
||||||
this.children = [];
|
this.children = [];
|
||||||
|
@ -112,17 +112,17 @@ class Group extends Channel {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.buildmessages();
|
this.buildmessages();
|
||||||
history.pushState(null, null, "/channels/" + this.guild_id + "/" + this.id);
|
history.pushState(null, null, "/channels/" + this.guild_id + "/" + this.snowflake);
|
||||||
document.getElementById("channelname").textContent = "@" + this.name;
|
document.getElementById("channelname").textContent = "@" + this.name;
|
||||||
}
|
}
|
||||||
messageCreate(messagep) {
|
messageCreate(messagep) {
|
||||||
const messagez = new Message(messagep.d, this);
|
const messagez = new Message(messagep.d, this);
|
||||||
this.idToNext.set(this.lastmessageid, messagez.id);
|
this.idToNext.set(this.lastmessageid, messagez.snowflake);
|
||||||
this.idToPrev.set(messagez.id, this.lastmessageid);
|
this.idToPrev.set(messagez.snowflake, this.lastmessageid);
|
||||||
this.lastmessageid = messagez.id;
|
this.lastmessageid = messagez.snowflake;
|
||||||
this.messageids.set(messagez.id, messagez);
|
this.messageids.set(messagez.snowflake, messagez);
|
||||||
if (messagez.author === this.localuser.user) {
|
if (messagez.author === this.localuser.user) {
|
||||||
this.lastreadmessageid = messagez.id;
|
this.lastreadmessageid = messagez.snowflake;
|
||||||
if (this.myhtml) {
|
if (this.myhtml) {
|
||||||
this.myhtml.classList.remove("cunread");
|
this.myhtml.classList.remove("cunread");
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,7 +10,7 @@ class Guild {
|
||||||
headers;
|
headers;
|
||||||
channels;
|
channels;
|
||||||
channelids;
|
channelids;
|
||||||
id;
|
snowflake;
|
||||||
properties;
|
properties;
|
||||||
roles;
|
roles;
|
||||||
roleids;
|
roleids;
|
||||||
|
@ -21,6 +21,9 @@ class Guild {
|
||||||
parent_id;
|
parent_id;
|
||||||
member;
|
member;
|
||||||
html;
|
html;
|
||||||
|
get id() {
|
||||||
|
return this.snowflake.id;
|
||||||
|
}
|
||||||
static contextmenu = new Contextmenu("guild menu");
|
static contextmenu = new Contextmenu("guild menu");
|
||||||
static setupcontextmenu() {
|
static setupcontextmenu() {
|
||||||
Guild.contextmenu.addbutton("Copy Guild id", function () {
|
Guild.contextmenu.addbutton("Copy Guild id", function () {
|
||||||
|
@ -63,7 +66,7 @@ class Guild {
|
||||||
const s1 = settings.addButton("roles");
|
const s1 = settings.addButton("roles");
|
||||||
const permlist = [];
|
const permlist = [];
|
||||||
for (const thing of this.roles) {
|
for (const thing of this.roles) {
|
||||||
permlist.push([thing.id, thing.permissions]);
|
permlist.push([thing.snowflake, thing.permissions]);
|
||||||
}
|
}
|
||||||
s1.options.push(new RoleList(permlist, this, this.updateRolePermissions.bind(this)));
|
s1.options.push(new RoleList(permlist, this, this.updateRolePermissions.bind(this)));
|
||||||
settings.show();
|
settings.show();
|
||||||
|
@ -76,7 +79,7 @@ class Guild {
|
||||||
this.headers = this.owner.headers;
|
this.headers = this.owner.headers;
|
||||||
this.channels = [];
|
this.channels = [];
|
||||||
this.channelids = {};
|
this.channelids = {};
|
||||||
this.id = new SnowFlake(json.id, this);
|
this.snowflake = new SnowFlake(json.id, this);
|
||||||
this.properties = json.properties;
|
this.properties = json.properties;
|
||||||
this.roles = [];
|
this.roles = [];
|
||||||
this.roleids = new Map();
|
this.roleids = new Map();
|
||||||
|
@ -85,13 +88,13 @@ class Guild {
|
||||||
for (const roley of json.roles) {
|
for (const roley of json.roles) {
|
||||||
const roleh = new Role(roley, this);
|
const roleh = new Role(roley, this);
|
||||||
this.roles.push(roleh);
|
this.roles.push(roleh);
|
||||||
this.roleids.set(roleh.id, roleh);
|
this.roleids.set(roleh.snowflake, roleh);
|
||||||
}
|
}
|
||||||
Member.resolve(member, this).then(_ => this.member = _);
|
Member.resolve(member, this).then(_ => this.member = _);
|
||||||
for (const thing of json.channels) {
|
for (const thing of json.channels) {
|
||||||
const temp = new Channel(thing, this);
|
const temp = new Channel(thing, this);
|
||||||
this.channels.push(temp);
|
this.channels.push(temp);
|
||||||
this.channelids[temp.id.id] = temp;
|
this.channelids[temp.id] = temp;
|
||||||
}
|
}
|
||||||
this.headchannels = [];
|
this.headchannels = [];
|
||||||
for (const thing of this.channels) {
|
for (const thing of this.channels) {
|
||||||
|
@ -119,7 +122,7 @@ class Guild {
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
"guilds": {
|
"guilds": {
|
||||||
[this.id.id]: {
|
[this.id]: {
|
||||||
"message_notifications": noti
|
"message_notifications": noti
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -158,7 +161,7 @@ class Guild {
|
||||||
full.show();
|
full.show();
|
||||||
}
|
}
|
||||||
async leave() {
|
async leave() {
|
||||||
return fetch(this.info.api.toString() + "/users/@me/guilds/" + this.id, {
|
return fetch(this.info.api.toString() + "/users/@me/guilds/" + this.snowflake, {
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
headers: this.headers
|
headers: this.headers
|
||||||
});
|
});
|
||||||
|
@ -177,7 +180,7 @@ class Guild {
|
||||||
let position = -1;
|
let position = -1;
|
||||||
let build = [];
|
let build = [];
|
||||||
for (const thing of this.headchannels) {
|
for (const thing of this.headchannels) {
|
||||||
const thisthing = { id: thing.id, position: undefined, parent_id: undefined };
|
const thisthing = { id: thing.snowflake, position: undefined, parent_id: undefined };
|
||||||
if (thing.position <= position) {
|
if (thing.position <= position) {
|
||||||
thing.position = (thisthing.position = position + 1);
|
thing.position = (thisthing.position = position + 1);
|
||||||
}
|
}
|
||||||
|
@ -208,7 +211,7 @@ class Guild {
|
||||||
if (serverbug) {
|
if (serverbug) {
|
||||||
for (const thing of build) {
|
for (const thing of build) {
|
||||||
console.log(build, thing);
|
console.log(build, thing);
|
||||||
fetch(this.info.api.toString() + "/v9/guilds/" + this.id + "/channels", {
|
fetch(this.info.api.toString() + "/v9/guilds/" + this.snowflake + "/channels", {
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
body: JSON.stringify([thing])
|
body: JSON.stringify([thing])
|
||||||
|
@ -216,7 +219,7 @@ class Guild {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fetch(this.info.api.toString() + "/v9/guilds/" + this.id + "/channels", {
|
fetch(this.info.api.toString() + "/v9/guilds/" + this.snowflake + "/channels", {
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
body: JSON.stringify(build)
|
body: JSON.stringify(build)
|
||||||
|
@ -238,7 +241,7 @@ class Guild {
|
||||||
const noti = document.createElement("div");
|
const noti = document.createElement("div");
|
||||||
noti.classList.add("unread");
|
noti.classList.add("unread");
|
||||||
divy.append(noti);
|
divy.append(noti);
|
||||||
this.localuser.guildhtml[this.id.id] = divy;
|
this.localuser.guildhtml.set(this.id, divy);
|
||||||
if (this.properties.icon != null) {
|
if (this.properties.icon != null) {
|
||||||
const img = document.createElement("img");
|
const img = document.createElement("img");
|
||||||
img.classList.add("pfp", "servericon");
|
img.classList.add("pfp", "servericon");
|
||||||
|
@ -308,7 +311,7 @@ class Guild {
|
||||||
full.show();
|
full.show();
|
||||||
}
|
}
|
||||||
async delete() {
|
async delete() {
|
||||||
return fetch(this.info.api.toString() + "/guilds/" + this.id + "/delete", {
|
return fetch(this.info.api.toString() + "/guilds/" + this.snowflake + "/delete", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
});
|
});
|
||||||
|
@ -355,7 +358,7 @@ class Guild {
|
||||||
const build = { read_states: [] };
|
const build = { read_states: [] };
|
||||||
for (const thing of this.channels) {
|
for (const thing of this.channels) {
|
||||||
if (thing.hasunreads) {
|
if (thing.hasunreads) {
|
||||||
build.read_states.push({ channel_id: thing.id, message_id: thing.lastmessageid, read_state_type: 0 });
|
build.read_states.push({ channel_id: thing.snowflake, message_id: thing.lastmessageid, read_state_type: 0 });
|
||||||
thing.lastreadmessageid = thing.lastmessageid;
|
thing.lastreadmessageid = thing.lastmessageid;
|
||||||
thing.myhtml.classList.remove("cunread");
|
thing.myhtml.classList.remove("cunread");
|
||||||
}
|
}
|
||||||
|
@ -370,7 +373,7 @@ class Guild {
|
||||||
hasRole(r) {
|
hasRole(r) {
|
||||||
console.log("this should run");
|
console.log("this should run");
|
||||||
if (r instanceof Role) {
|
if (r instanceof Role) {
|
||||||
r = r.id.id;
|
r = r.id;
|
||||||
}
|
}
|
||||||
return this.member.hasRole(r);
|
return this.member.hasRole(r);
|
||||||
}
|
}
|
||||||
|
@ -392,7 +395,7 @@ class Guild {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
loadGuild() {
|
loadGuild() {
|
||||||
this.localuser.loadGuild(this.id.id);
|
this.localuser.loadGuild(this.id);
|
||||||
}
|
}
|
||||||
updateChannel(JSON) {
|
updateChannel(JSON) {
|
||||||
SnowFlake.getSnowFlakeFromID(JSON.id, Channel).getObject().updateChannel(JSON);
|
SnowFlake.getSnowFlakeFromID(JSON.id, Channel).getObject().updateChannel(JSON);
|
||||||
|
@ -484,14 +487,14 @@ class Guild {
|
||||||
this.printServers();
|
this.printServers();
|
||||||
}
|
}
|
||||||
createChannel(name, type) {
|
createChannel(name, type) {
|
||||||
fetch(this.info.api.toString() + "/guilds/" + this.id + "/channels", {
|
fetch(this.info.api.toString() + "/guilds/" + this.snowflake + "/channels", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
body: JSON.stringify({ name: name, type: type })
|
body: JSON.stringify({ name: name, type: type })
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
async createRole(name) {
|
async createRole(name) {
|
||||||
const fetched = await fetch(this.info.api.toString() + "/guilds/" + this.id + "roles", {
|
const fetched = await fetch(this.info.api.toString() + "/guilds/" + this.snowflake + "roles", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
|
@ -502,7 +505,7 @@ class Guild {
|
||||||
});
|
});
|
||||||
const json = await fetched.json();
|
const json = await fetched.json();
|
||||||
const role = new Role(json, this);
|
const role = new Role(json, this);
|
||||||
this.roleids[role.id.id] = role;
|
this.roleids.set(role.snowflake, role);
|
||||||
this.roles.push(role);
|
this.roles.push(role);
|
||||||
return role;
|
return role;
|
||||||
}
|
}
|
||||||
|
@ -510,7 +513,7 @@ class Guild {
|
||||||
const role = this.roleids[id];
|
const role = this.roleids[id];
|
||||||
role.permissions.allow = perms.allow;
|
role.permissions.allow = perms.allow;
|
||||||
role.permissions.deny = perms.deny;
|
role.permissions.deny = perms.deny;
|
||||||
await fetch(this.info.api.toString() + "/guilds/" + this.id + "/roles/" + this.id, {
|
await fetch(this.info.api.toString() + "/guilds/" + this.snowflake + "/roles/" + this.snowflake, {
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
|
|
|
@ -60,12 +60,12 @@ class Localuser {
|
||||||
for (const thing of ready.d.guilds) {
|
for (const thing of ready.d.guilds) {
|
||||||
const temp = new Guild(thing, this, members[thing.id]);
|
const temp = new Guild(thing, this, members[thing.id]);
|
||||||
this.guilds.push(temp);
|
this.guilds.push(temp);
|
||||||
this.guildids[temp.id.id] = temp;
|
this.guildids[temp.id] = temp;
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
const temp = new Direct(ready.d.private_channels, this);
|
const temp = new Direct(ready.d.private_channels, this);
|
||||||
this.guilds.push(temp);
|
this.guilds.push(temp);
|
||||||
this.guildids[temp.id.id] = temp;
|
this.guildids[temp.id] = temp;
|
||||||
}
|
}
|
||||||
console.log(ready.d.user_guild_settings.entries);
|
console.log(ready.d.user_guild_settings.entries);
|
||||||
for (const thing of ready.d.user_guild_settings.entries) {
|
for (const thing of ready.d.user_guild_settings.entries) {
|
||||||
|
@ -80,7 +80,7 @@ class Localuser {
|
||||||
if (guild === undefined) {
|
if (guild === undefined) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const guildid = guild.id;
|
const guildid = guild.snowflake;
|
||||||
this.guildids[guildid.id].channelids[thing.channel_id].readStateInfo(thing);
|
this.guildids[guildid.id].channelids[thing.channel_id].readStateInfo(thing);
|
||||||
}
|
}
|
||||||
this.typing = [];
|
this.typing = [];
|
||||||
|
@ -193,7 +193,7 @@ class Localuser {
|
||||||
{
|
{
|
||||||
const guildy = new Guild(temp.d, this, this.user);
|
const guildy = new Guild(temp.d, this, this.user);
|
||||||
this.guilds.push(guildy);
|
this.guilds.push(guildy);
|
||||||
this.guildids[guildy.id.id] = guildy;
|
this.guildids[guildy.id] = guildy;
|
||||||
document.getElementById("servers").insertBefore(guildy.generateGuildIcon(), document.getElementById("bottomseparator"));
|
document.getElementById("servers").insertBefore(guildy.generateGuildIcon(), document.getElementById("bottomseparator"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -251,21 +251,21 @@ class Localuser {
|
||||||
}
|
}
|
||||||
updateChannel(JSON) {
|
updateChannel(JSON) {
|
||||||
SnowFlake.getSnowFlakeFromID(JSON.guild_id, Guild).getObject().updateChannel(JSON);
|
SnowFlake.getSnowFlakeFromID(JSON.guild_id, Guild).getObject().updateChannel(JSON);
|
||||||
if (JSON.guild_id === this.lookingguild.id.id) {
|
if (JSON.guild_id === this.lookingguild.id) {
|
||||||
this.loadGuild(JSON.guild_id);
|
this.loadGuild(JSON.guild_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
createChannel(JSON) {
|
createChannel(JSON) {
|
||||||
JSON.guild_id ??= "@me";
|
JSON.guild_id ??= "@me";
|
||||||
SnowFlake.getSnowFlakeFromID(JSON.guild_id, Guild).getObject().createChannelpac(JSON);
|
SnowFlake.getSnowFlakeFromID(JSON.guild_id, Guild).getObject().createChannelpac(JSON);
|
||||||
if (JSON.guild_id === this.lookingguild.id.id) {
|
if (JSON.guild_id === this.lookingguild.id) {
|
||||||
this.loadGuild(JSON.guild_id);
|
this.loadGuild(JSON.guild_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delChannel(JSON) {
|
delChannel(JSON) {
|
||||||
JSON.guild_id ??= "@me";
|
JSON.guild_id ??= "@me";
|
||||||
this.guildids[JSON.guild_id].delChannel(JSON);
|
this.guildids[JSON.guild_id].delChannel(JSON);
|
||||||
if (JSON.guild_id === this.lookingguild.id) {
|
if (JSON.guild_id === this.lookingguild.snowflake) {
|
||||||
this.loadGuild(JSON.guild_id);
|
this.loadGuild(JSON.guild_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -466,17 +466,17 @@ class Localuser {
|
||||||
unreads() {
|
unreads() {
|
||||||
console.log(this.guildhtml);
|
console.log(this.guildhtml);
|
||||||
for (const thing of this.guilds) {
|
for (const thing of this.guilds) {
|
||||||
if (thing.id.id === "@me") {
|
if (thing.id === "@me") {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
thing.unreads(this.guildhtml[thing.id.id]);
|
thing.unreads(this.guildhtml[thing.id]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
typingStart(typing) {
|
typingStart(typing) {
|
||||||
if (this.channelfocus.id === typing.d.channel_id) {
|
if (this.channelfocus.snowflake === typing.d.channel_id) {
|
||||||
const memb = typing.d.member;
|
const memb = typing.d.member;
|
||||||
let name;
|
let name;
|
||||||
if (memb.id === this.user.id) {
|
if (memb.id === this.user.snowflake) {
|
||||||
console.log("you is typing");
|
console.log("you is typing");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -72,7 +72,7 @@ class Member {
|
||||||
let id;
|
let id;
|
||||||
if (unkown instanceof User) {
|
if (unkown instanceof User) {
|
||||||
user = unkown;
|
user = unkown;
|
||||||
id = user.id;
|
id = user.snowflake;
|
||||||
}
|
}
|
||||||
else if (typeof unkown === typeof "") {
|
else if (typeof unkown === typeof "") {
|
||||||
id = new SnowFlake(unkown, undefined);
|
id = new SnowFlake(unkown, undefined);
|
||||||
|
@ -80,39 +80,39 @@ class Member {
|
||||||
else {
|
else {
|
||||||
return new Member(unkown, guild);
|
return new Member(unkown, guild);
|
||||||
}
|
}
|
||||||
if (guild.id.id === "@me") {
|
if (guild.id === "@me") {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
if (!Member.already[guild.id.id]) {
|
if (!Member.already[guild.id]) {
|
||||||
Member.already[guild.id.id] = {};
|
Member.already[guild.id] = {};
|
||||||
}
|
}
|
||||||
else if (Member.already[guild.id.id][id]) {
|
else if (Member.already[guild.id][id]) {
|
||||||
const memb = Member.already[guild.id.id][id];
|
const memb = Member.already[guild.id][id];
|
||||||
if (memb instanceof Promise) {
|
if (memb instanceof Promise) {
|
||||||
return await memb;
|
return await memb;
|
||||||
}
|
}
|
||||||
return memb;
|
return memb;
|
||||||
}
|
}
|
||||||
const promoise = fetch(guild.info.api.toString() + "/users/" + id + "/profile?with_mutual_guilds=true&with_mutual_friends_count=true&guild_id=" + guild.id, { headers: guild.headers }).then(_ => _.json()).then(json => {
|
const promoise = fetch(guild.info.api.toString() + "/users/" + id + "/profile?with_mutual_guilds=true&with_mutual_friends_count=true&guild_id=" + guild.snowflake, { headers: guild.headers }).then(_ => _.json()).then(json => {
|
||||||
const memb = new Member(json, guild);
|
const memb = new Member(json, guild);
|
||||||
Member.already[guild.id.id][id] = memb;
|
Member.already[guild.id][id] = memb;
|
||||||
console.log("resolved");
|
console.log("resolved");
|
||||||
return memb;
|
return memb;
|
||||||
});
|
});
|
||||||
Member.already[guild.id.id][id] = promoise;
|
Member.already[guild.id][id] = promoise;
|
||||||
try {
|
try {
|
||||||
return await promoise;
|
return await promoise;
|
||||||
}
|
}
|
||||||
catch (_) {
|
catch (_) {
|
||||||
const memb = new Member(user, guild, true);
|
const memb = new Member(user, guild, true);
|
||||||
Member.already[guild.id.id][id] = memb;
|
Member.already[guild.id][id] = memb;
|
||||||
return memb;
|
return memb;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hasRole(ID) {
|
hasRole(ID) {
|
||||||
console.log(this.roles, ID);
|
console.log(this.roles, ID);
|
||||||
for (const thing of this.roles) {
|
for (const thing of this.roles) {
|
||||||
if (thing.id.id === ID) {
|
if (thing.id === ID) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -133,7 +133,7 @@ class Member {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this.guild.properties.owner_id === this.user.id.id;
|
return this.guild.properties.owner_id === this.user.id;
|
||||||
}
|
}
|
||||||
bind(html) {
|
bind(html) {
|
||||||
if (html.tagName === "SPAN") {
|
if (html.tagName === "SPAN") {
|
||||||
|
|
|
@ -14,7 +14,7 @@ class Message {
|
||||||
mentions;
|
mentions;
|
||||||
mention_roles;
|
mention_roles;
|
||||||
attachments; //probably should be its own class tbh, should be Attachments[]
|
attachments; //probably should be its own class tbh, should be Attachments[]
|
||||||
id;
|
snowflake;
|
||||||
message_reference;
|
message_reference;
|
||||||
type;
|
type;
|
||||||
timestamp;
|
timestamp;
|
||||||
|
@ -22,6 +22,9 @@ class Message {
|
||||||
static del;
|
static del;
|
||||||
static resolve;
|
static resolve;
|
||||||
div;
|
div;
|
||||||
|
get id() {
|
||||||
|
return this.snowflake.id;
|
||||||
|
}
|
||||||
static setup() {
|
static setup() {
|
||||||
this.del = new Promise(_ => { this.resolve = _; });
|
this.del = new Promise(_ => { this.resolve = _; });
|
||||||
Message.setupcmenu();
|
Message.setupcmenu();
|
||||||
|
@ -71,7 +74,7 @@ class Message {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else if (thing === "id") {
|
else if (thing === "id") {
|
||||||
this.id = new SnowFlake(messagejson.id, this);
|
this.snowflake = new SnowFlake(messagejson.id, this);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
this[thing] = messagejson[thing];
|
this[thing] = messagejson[thing];
|
||||||
|
@ -95,7 +98,7 @@ class Message {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
canDelete() {
|
canDelete() {
|
||||||
return this.channel.hasPermission("MANAGE_MESSAGES") || this.author.id === this.localuser.user.id;
|
return this.channel.hasPermission("MANAGE_MESSAGES") || this.author.snowflake === this.localuser.user.snowflake;
|
||||||
}
|
}
|
||||||
get channel() {
|
get channel() {
|
||||||
return this.owner;
|
return this.owner;
|
||||||
|
@ -137,14 +140,14 @@ class Message {
|
||||||
return build;
|
return build;
|
||||||
}
|
}
|
||||||
async edit(content) {
|
async edit(content) {
|
||||||
return await fetch(this.info.api.toString() + "/channels/" + this.channel.id + "/messages/" + this.id.id, {
|
return await fetch(this.info.api.toString() + "/channels/" + this.channel.snowflake + "/messages/" + this.id, {
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
body: JSON.stringify({ content: content })
|
body: JSON.stringify({ content: content })
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
delete() {
|
delete() {
|
||||||
fetch(`${this.info.api.toString()}/channels/${this.channel.id}/messages/${this.id.id}`, {
|
fetch(`${this.info.api.toString()}/channels/${this.channel.snowflake}/messages/${this.id}`, {
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
});
|
});
|
||||||
|
@ -154,22 +157,22 @@ class Message {
|
||||||
this.div.innerHTML = "";
|
this.div.innerHTML = "";
|
||||||
this.div = null;
|
this.div = null;
|
||||||
}
|
}
|
||||||
const prev = this.channel.idToPrev[this.id.id];
|
const prev = this.channel.idToPrev.get(this.snowflake);
|
||||||
const next = this.channel.idToNext[this.id.id];
|
const next = this.channel.idToNext.get(this.snowflake);
|
||||||
this.channel.idToNext[prev] = next;
|
this.channel.idToNext.set(prev, next);
|
||||||
this.channel.idToPrev[next] = prev;
|
this.channel.idToPrev.set(next, prev);
|
||||||
delete this.channel.messageids[this.id.id];
|
this.channel.messageids.delete(this.snowflake);
|
||||||
const regen = this.channel.messageids[prev];
|
const regen = prev.getObject();
|
||||||
if (regen) {
|
if (regen) {
|
||||||
regen.generateMessage();
|
regen.generateMessage();
|
||||||
}
|
}
|
||||||
if (this.channel.lastmessage === this) {
|
if (this.channel.lastmessage === this) {
|
||||||
this.channel.lastmessage = this.channel.messageids[prev];
|
this.channel.lastmessage = prev.getObject();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
generateMessage(premessage = null) {
|
generateMessage(premessage = null) {
|
||||||
if (!premessage) {
|
if (!premessage) {
|
||||||
premessage = this.channel.messageids[this.channel.idToNext[this.id.id]];
|
premessage = this.channel.idToNext.get(this.snowflake)?.getObject();
|
||||||
}
|
}
|
||||||
const div = this.div;
|
const div = this.div;
|
||||||
if (this === this.channel.replyingto) {
|
if (this === this.channel.replyingto) {
|
||||||
|
@ -240,7 +243,7 @@ class Message {
|
||||||
const newt = (new Date(this.timestamp).getTime()) / 1000;
|
const newt = (new Date(this.timestamp).getTime()) / 1000;
|
||||||
current = (newt - old) > 600;
|
current = (newt - old) > 600;
|
||||||
}
|
}
|
||||||
const combine = (premessage?.author?.id != this.author.id) || (current) || this.message_reference;
|
const combine = (premessage?.author?.snowflake != this.author.snowflake) || (current) || this.message_reference;
|
||||||
if (combine) {
|
if (combine) {
|
||||||
const pfp = this.author.buildpfp();
|
const pfp = this.author.buildpfp();
|
||||||
this.author.bind(pfp);
|
this.author.bind(pfp);
|
||||||
|
@ -328,7 +331,7 @@ class Message {
|
||||||
}
|
}
|
||||||
buildhtml(premessage, del = Message.del) {
|
buildhtml(premessage, del = Message.del) {
|
||||||
if (this.div) {
|
if (this.div) {
|
||||||
console.error(`HTML for ${this.id} already exists, aborting`);
|
console.error(`HTML for ${this.snowflake} already exists, aborting`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//premessage??=messages.lastChild;
|
//premessage??=messages.lastChild;
|
||||||
|
|
|
@ -5,7 +5,7 @@ class Role {
|
||||||
permissions;
|
permissions;
|
||||||
owner;
|
owner;
|
||||||
color;
|
color;
|
||||||
id;
|
snowflake;
|
||||||
name;
|
name;
|
||||||
info;
|
info;
|
||||||
hoist;
|
hoist;
|
||||||
|
@ -13,12 +13,15 @@ class Role {
|
||||||
mentionable;
|
mentionable;
|
||||||
unicode_emoji;
|
unicode_emoji;
|
||||||
headers;
|
headers;
|
||||||
|
get id() {
|
||||||
|
return this.snowflake.id;
|
||||||
|
}
|
||||||
constructor(JSON, owner) {
|
constructor(JSON, owner) {
|
||||||
this.headers = owner.headers;
|
this.headers = owner.headers;
|
||||||
this.info = owner.info;
|
this.info = owner.info;
|
||||||
for (const thing of Object.keys(JSON)) {
|
for (const thing of Object.keys(JSON)) {
|
||||||
if (thing === "id") {
|
if (thing === "id") {
|
||||||
this.id = new SnowFlake(JSON.id, this);
|
this.snowflake = new SnowFlake(JSON.id, this);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
this[thing] = JSON[thing];
|
this[thing] = JSON[thing];
|
||||||
|
|
|
@ -7,13 +7,16 @@ class User {
|
||||||
static userids = {};
|
static userids = {};
|
||||||
owner;
|
owner;
|
||||||
hypotheticalpfp;
|
hypotheticalpfp;
|
||||||
id;
|
snowflake;
|
||||||
avatar;
|
avatar;
|
||||||
username;
|
username;
|
||||||
bio;
|
bio;
|
||||||
discriminator;
|
discriminator;
|
||||||
pronouns;
|
pronouns;
|
||||||
bot;
|
bot;
|
||||||
|
get id() {
|
||||||
|
return this.snowflake.id;
|
||||||
|
}
|
||||||
static contextmenu = new Contextmenu("User Menu");
|
static contextmenu = new Contextmenu("User Menu");
|
||||||
static setUpContextMenu() {
|
static setUpContextMenu() {
|
||||||
this.contextmenu.addbutton("Copy user id", function () {
|
this.contextmenu.addbutton("Copy user id", function () {
|
||||||
|
@ -54,7 +57,7 @@ class User {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (thing === "id") {
|
if (thing === "id") {
|
||||||
this.id = new SnowFlake(userjson[thing], this);
|
this.snowflake = new SnowFlake(userjson[thing], this);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
this[thing] = userjson[thing];
|
this[thing] = userjson[thing];
|
||||||
|
@ -72,7 +75,7 @@ class User {
|
||||||
const pfp = document.createElement('img');
|
const pfp = document.createElement('img');
|
||||||
pfp.src = this.getpfpsrc();
|
pfp.src = this.getpfpsrc();
|
||||||
pfp.classList.add("pfp");
|
pfp.classList.add("pfp");
|
||||||
pfp.classList.add("userid:" + this.id.id);
|
pfp.classList.add("userid:" + this.id);
|
||||||
return pfp;
|
return pfp;
|
||||||
}
|
}
|
||||||
userupdate(json) {
|
userupdate(json) {
|
||||||
|
@ -82,7 +85,7 @@ class User {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bind(html, guild = null) {
|
bind(html, guild = null) {
|
||||||
if (guild && guild.id.id !== "@me") {
|
if (guild && guild.id !== "@me") {
|
||||||
Member.resolve(this, guild).then(_ => {
|
Member.resolve(this, guild).then(_ => {
|
||||||
_.bind(html);
|
_.bind(html);
|
||||||
}).catch(_ => {
|
}).catch(_ => {
|
||||||
|
@ -101,7 +104,7 @@ class User {
|
||||||
this.hypotheticalpfp = false;
|
this.hypotheticalpfp = false;
|
||||||
const src = this.getpfpsrc();
|
const src = this.getpfpsrc();
|
||||||
console.log(src);
|
console.log(src);
|
||||||
for (const thing of document.getElementsByClassName("userid:" + this.id.id)) {
|
for (const thing of document.getElementsByClassName("userid:" + this.id)) {
|
||||||
thing.src = src;
|
thing.src = src;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -110,7 +113,7 @@ class User {
|
||||||
return this.avatar;
|
return this.avatar;
|
||||||
}
|
}
|
||||||
if (this.avatar != null) {
|
if (this.avatar != null) {
|
||||||
return this.info.cdn.toString() + "avatars/" + this.id.id + "/" + this.avatar + ".png";
|
return this.info.cdn.toString() + "avatars/" + this.id + "/" + this.avatar + ".png";
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return this.info.cdn.toString() + "embed/avatars/3.png";
|
return this.info.cdn.toString() + "embed/avatars/3.png";
|
||||||
|
|
|
@ -22,7 +22,7 @@ class Channel{
|
||||||
owner:Guild;
|
owner:Guild;
|
||||||
headers:Localuser["headers"];
|
headers:Localuser["headers"];
|
||||||
name:string;
|
name:string;
|
||||||
id:SnowFlake<Channel>;
|
snowflake:SnowFlake<Channel>;
|
||||||
parent_id:SnowFlake<Channel>;
|
parent_id:SnowFlake<Channel>;
|
||||||
parent:Channel;
|
parent:Channel;
|
||||||
children:Channel[];
|
children:Channel[];
|
||||||
|
@ -46,6 +46,9 @@ class Channel{
|
||||||
infinite:InfiniteScroller;
|
infinite:InfiniteScroller;
|
||||||
idToPrev:Map<SnowFlake<Message>,SnowFlake<Message>>=new Map();
|
idToPrev:Map<SnowFlake<Message>,SnowFlake<Message>>=new Map();
|
||||||
idToNext:Map<SnowFlake<Message>,SnowFlake<Message>>=new Map();
|
idToNext:Map<SnowFlake<Message>,SnowFlake<Message>>=new Map();
|
||||||
|
get id(){
|
||||||
|
return this.snowflake.id;
|
||||||
|
}
|
||||||
static setupcontextmenu(){
|
static setupcontextmenu(){
|
||||||
this.contextmenu.addbutton("Copy channel id",function(){
|
this.contextmenu.addbutton("Copy channel id",function(){
|
||||||
console.log(this)
|
console.log(this)
|
||||||
|
@ -81,7 +84,7 @@ class Channel{
|
||||||
}
|
}
|
||||||
sortPerms(){
|
sortPerms(){
|
||||||
this.permission_overwritesar.sort((a,b)=>{
|
this.permission_overwritesar.sort((a,b)=>{
|
||||||
const order=this.guild.roles.findIndex(_=>_.id===a[0])-this.guild.roles.findIndex(_=>_.id===b[0]);
|
const order=this.guild.roles.findIndex(_=>_.snowflake===a[0])-this.guild.roles.findIndex(_=>_.snowflake===b[0]);
|
||||||
return order;
|
return order;
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -127,7 +130,7 @@ class Channel{
|
||||||
this.owner=owner;
|
this.owner=owner;
|
||||||
this.headers=this.owner.headers;
|
this.headers=this.owner.headers;
|
||||||
this.name=JSON.name;
|
this.name=JSON.name;
|
||||||
this.id=new SnowFlake(JSON.id,this);
|
this.snowflake=new SnowFlake(JSON.id,this);
|
||||||
this.parent_id=new SnowFlake(JSON.parent_id,undefined);
|
this.parent_id=new SnowFlake(JSON.parent_id,undefined);
|
||||||
this.parent=null;
|
this.parent=null;
|
||||||
this.children=[];
|
this.children=[];
|
||||||
|
@ -175,8 +178,8 @@ class Channel{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
for(const thing of member.roles){
|
for(const thing of member.roles){
|
||||||
if(this.permission_overwrites.get(thing.id.id)){
|
if(this.permission_overwrites.get(thing.id)){
|
||||||
let perm=this.permission_overwrites.get(thing.id.id).getPermission(name);
|
let perm=this.permission_overwrites.get(thing.id).getPermission(name);
|
||||||
if(perm){
|
if(perm){
|
||||||
return perm===1;
|
return perm===1;
|
||||||
}
|
}
|
||||||
|
@ -208,7 +211,7 @@ class Channel{
|
||||||
let position=-1;
|
let position=-1;
|
||||||
let build=[];
|
let build=[];
|
||||||
for(const thing of this.children){
|
for(const thing of this.children){
|
||||||
const thisthing={id:thing.id,position:undefined,parent_id:undefined};
|
const thisthing={id:thing.snowflake,position:undefined,parent_id:undefined};
|
||||||
if(thing.position<position){
|
if(thing.position<position){
|
||||||
thing.position=thisthing.position=position+1;
|
thing.position=thisthing.position=position+1;
|
||||||
}
|
}
|
||||||
|
@ -355,7 +358,7 @@ class Channel{
|
||||||
if(!this.hasunreads){
|
if(!this.hasunreads){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fetch(this.info.api.toString()+"/channels/"+this.id+"/messages/"+this.lastmessageid+"/ack",{
|
fetch(this.info.api.toString()+"/channels/"+this.snowflake+"/messages/"+this.lastmessageid+"/ack",{
|
||||||
method:"POST",
|
method:"POST",
|
||||||
headers:this.headers,
|
headers:this.headers,
|
||||||
body:JSON.stringify({})
|
body:JSON.stringify({})
|
||||||
|
@ -380,7 +383,7 @@ class Channel{
|
||||||
const that=Channel.dragged[0];
|
const that=Channel.dragged[0];
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
if(container){
|
if(container){
|
||||||
that.move_id=this.id;
|
that.move_id=this.snowflake;
|
||||||
if(that.parent){
|
if(that.parent){
|
||||||
that.parent.children.splice(that.parent.children.indexOf(that),1);
|
that.parent.children.splice(that.parent.children.indexOf(that),1);
|
||||||
}
|
}
|
||||||
|
@ -423,13 +426,13 @@ class Channel{
|
||||||
return div;
|
return div;
|
||||||
}
|
}
|
||||||
createChannel(name:string,type:number){
|
createChannel(name:string,type:number){
|
||||||
fetch(this.info.api.toString()+"/guilds/"+this.guild.id+"/channels",{
|
fetch(this.info.api.toString()+"/guilds/"+this.guild.snowflake+"/channels",{
|
||||||
method:"POST",
|
method:"POST",
|
||||||
headers:this.headers,
|
headers:this.headers,
|
||||||
body:JSON.stringify({
|
body:JSON.stringify({
|
||||||
name: name,
|
name: name,
|
||||||
type: type,
|
type: type,
|
||||||
parent_id: this.id,
|
parent_id: this.snowflake,
|
||||||
permission_overwrites:[],
|
permission_overwrites:[],
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -438,7 +441,7 @@ class Channel{
|
||||||
let name=this.name;
|
let name=this.name;
|
||||||
let topic=this.topic;
|
let topic=this.topic;
|
||||||
let nsfw=this.nsfw;
|
let nsfw=this.nsfw;
|
||||||
const thisid=this.id;
|
const thisid=this.snowflake;
|
||||||
const thistype=this.type;
|
const thistype=this.type;
|
||||||
const full=new Fullscreen(
|
const full=new Fullscreen(
|
||||||
["hdiv",
|
["hdiv",
|
||||||
|
@ -471,7 +474,7 @@ class Channel{
|
||||||
console.log(full)
|
console.log(full)
|
||||||
}
|
}
|
||||||
deleteChannel(){
|
deleteChannel(){
|
||||||
fetch(this.info.api.toString()+"/channels/"+this.id,{
|
fetch(this.info.api.toString()+"/channels/"+this.snowflake,{
|
||||||
method:"DELETE",
|
method:"DELETE",
|
||||||
headers:this.headers
|
headers:this.headers
|
||||||
})
|
})
|
||||||
|
@ -513,7 +516,7 @@ class Channel{
|
||||||
if(snowflake.getObject()){
|
if(snowflake.getObject()){
|
||||||
return snowflake.getObject();
|
return snowflake.getObject();
|
||||||
}else{
|
}else{
|
||||||
const gety=await fetch(this.info.api.toString()+"/channels/"+this.id+"/messages?limit=1&around="+id,{headers:this.headers})
|
const gety=await fetch(this.info.api.toString()+"/channels/"+this.snowflake+"/messages?limit=1&around="+id,{headers:this.headers})
|
||||||
const json=await gety.json();
|
const json=await gety.json();
|
||||||
return new Message(json[0],this);
|
return new Message(json[0],this);
|
||||||
}
|
}
|
||||||
|
@ -538,7 +541,7 @@ class Channel{
|
||||||
}
|
}
|
||||||
this.makereplybox();
|
this.makereplybox();
|
||||||
this.buildmessages();
|
this.buildmessages();
|
||||||
history.pushState(null, null,"/channels/"+this.guild_id+"/"+this.id);
|
history.pushState(null, null,"/channels/"+this.guild_id+"/"+this.snowflake);
|
||||||
document.getElementById("channelname").textContent="#"+this.name;
|
document.getElementById("channelname").textContent="#"+this.name;
|
||||||
console.log(this);
|
console.log(this);
|
||||||
(document.getElementById("typebox") as HTMLInputElement).contentEditable=""+this.canMessage;
|
(document.getElementById("typebox") as HTMLInputElement).contentEditable=""+this.canMessage;
|
||||||
|
@ -546,7 +549,7 @@ class Channel{
|
||||||
lastmessage:Message;
|
lastmessage:Message;
|
||||||
async putmessages(){
|
async putmessages(){
|
||||||
if(this.allthewayup){return};
|
if(this.allthewayup){return};
|
||||||
const j=await fetch(this.info.api.toString()+"/channels/"+this.id+"/messages?limit=100",{
|
const j=await fetch(this.info.api.toString()+"/channels/"+this.snowflake+"/messages?limit=100",{
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -558,21 +561,21 @@ class Channel{
|
||||||
for(const thing of response){
|
for(const thing of response){
|
||||||
const message=new Message(thing,this);
|
const message=new Message(thing,this);
|
||||||
if(prev){
|
if(prev){
|
||||||
this.idToNext.set(message.id,prev.id);
|
this.idToNext.set(message.snowflake,prev.id);
|
||||||
this.idToPrev.set(prev.id,message.id);
|
this.idToPrev.set(prev.id,message.snowflake);
|
||||||
}else{
|
}else{
|
||||||
this.lastmessage=message;
|
this.lastmessage=message;
|
||||||
}
|
}
|
||||||
prev=message;
|
prev=message;
|
||||||
if(this.messageids.get(message.id)===undefined){
|
if(this.messageids.get(message.snowflake)===undefined){
|
||||||
this.messageids.set(message.id,message);
|
this.messageids.set(message.snowflake,message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delChannel(JSON){
|
delChannel(JSON){
|
||||||
const build=[];
|
const build=[];
|
||||||
for(const thing of this.children){
|
for(const thing of this.children){
|
||||||
if(thing.id!==JSON.id){
|
if(thing.snowflake!==JSON.id){
|
||||||
build.push(thing)
|
build.push(thing)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -583,7 +586,7 @@ class Channel{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
await fetch(this.info.api.toString()+"/channels/"+this.id+"/messages?before="+id+"&limit=100",{
|
await fetch(this.info.api.toString()+"/channels/"+this.snowflake+"/messages?before="+id+"&limit=100",{
|
||||||
headers:this.headers
|
headers:this.headers
|
||||||
}).then((j)=>{return j.json()}).then(response=>{
|
}).then((j)=>{return j.json()}).then(response=>{
|
||||||
let next:Message;
|
let next:Message;
|
||||||
|
@ -604,11 +607,11 @@ class Channel{
|
||||||
next=undefined;
|
next=undefined;
|
||||||
console.log("ohno",+i+1);
|
console.log("ohno",+i+1);
|
||||||
}
|
}
|
||||||
if(this.messageids.get(messager.id)===undefined){
|
if(this.messageids.get(messager.snowflake)===undefined){
|
||||||
this.idToNext.set(messager.id,previd);
|
this.idToNext.set(messager.snowflake,previd);
|
||||||
this.idToPrev.set(previd,messager.id);
|
this.idToPrev.set(previd,messager.snowflake);
|
||||||
previd=messager.id;
|
previd=messager.snowflake;
|
||||||
this.messageids.set(messager.id,messager);
|
this.messageids.set(messager.snowflake,messager);
|
||||||
}else{
|
}else{
|
||||||
console.log("How???")
|
console.log("How???")
|
||||||
}
|
}
|
||||||
|
@ -627,8 +630,8 @@ class Channel{
|
||||||
let id:SnowFlake<Message>;
|
let id:SnowFlake<Message>;
|
||||||
if(this.messageids.get(this.lastreadmessageid)){
|
if(this.messageids.get(this.lastreadmessageid)){
|
||||||
id=this.lastreadmessageid;
|
id=this.lastreadmessageid;
|
||||||
}else if(this.lastmessage.id){
|
}else if(this.lastmessage.snowflake){
|
||||||
id=this.goBackIds(this.lastmessage.id,50);
|
id=this.goBackIds(this.lastmessage.snowflake,50);
|
||||||
console.log("shouldn't")
|
console.log("shouldn't")
|
||||||
}
|
}
|
||||||
messages.append(this.infinite.getDiv(id.id));
|
messages.append(this.infinite.getDiv(id.id));
|
||||||
|
@ -668,7 +671,7 @@ class Channel{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.typing=new Date().getTime()+6000;
|
this.typing=new Date().getTime()+6000;
|
||||||
fetch(this.info.api.toString()+"/channels/"+this.id+"/typing",{
|
fetch(this.info.api.toString()+"/channels/"+this.snowflake+"/typing",{
|
||||||
method:"POST",
|
method:"POST",
|
||||||
headers:this.headers
|
headers:this.headers
|
||||||
})
|
})
|
||||||
|
@ -708,7 +711,7 @@ class Channel{
|
||||||
body.message_reference=replyjson;
|
body.message_reference=replyjson;
|
||||||
}
|
}
|
||||||
console.log(body)
|
console.log(body)
|
||||||
return await fetch(this.info.api.toString()+"/channels/"+this.id+"/messages",{
|
return await fetch(this.info.api.toString()+"/channels/"+this.snowflake+"/messages",{
|
||||||
method:"POST",
|
method:"POST",
|
||||||
headers:this.headers,
|
headers:this.headers,
|
||||||
body:JSON.stringify(body)
|
body:JSON.stringify(body)
|
||||||
|
@ -728,7 +731,7 @@ class Channel{
|
||||||
console.log(attachments[i])
|
console.log(attachments[i])
|
||||||
formData.append("files["+i+"]",attachments[i]);
|
formData.append("files["+i+"]",attachments[i]);
|
||||||
}
|
}
|
||||||
return await fetch(this.info.api.toString()+"/channels/"+this.id+"/messages", {
|
return await fetch(this.info.api.toString()+"/channels/"+this.snowflake+"/messages", {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
body: formData,
|
body: formData,
|
||||||
headers:{"Authorization":this.headers.Authorization}
|
headers:{"Authorization":this.headers.Authorization}
|
||||||
|
@ -738,13 +741,13 @@ class Channel{
|
||||||
messageCreate(messagep:any):void{
|
messageCreate(messagep:any):void{
|
||||||
if(!this.hasPermission("VIEW_CHANNEL")){return}
|
if(!this.hasPermission("VIEW_CHANNEL")){return}
|
||||||
const messagez=new Message(messagep.d,this);
|
const messagez=new Message(messagep.d,this);
|
||||||
console.log(this.lastmessageid,messagez.id,":3");
|
console.log(this.lastmessageid,messagez.snowflake,":3");
|
||||||
this.idToNext.set(this.lastmessageid,messagez.id);
|
this.idToNext.set(this.lastmessageid,messagez.snowflake);
|
||||||
this.idToPrev.set(messagez.id,this.lastmessageid);
|
this.idToPrev.set(messagez.snowflake,this.lastmessageid);
|
||||||
this.lastmessageid=messagez.id;
|
this.lastmessageid=messagez.snowflake;
|
||||||
this.messageids.set(messagez.id,messagez);
|
this.messageids.set(messagez.snowflake,messagez);
|
||||||
if(messagez.author===this.localuser.user){
|
if(messagez.author===this.localuser.user){
|
||||||
this.lastreadmessageid=messagez.id;
|
this.lastreadmessageid=messagez.snowflake;
|
||||||
if(this.myhtml){
|
if(this.myhtml){
|
||||||
this.myhtml.classList.remove("cunread");
|
this.myhtml.classList.remove("cunread");
|
||||||
}
|
}
|
||||||
|
@ -806,25 +809,25 @@ class Channel{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async addRoleToPerms(role:Role){
|
async addRoleToPerms(role:Role){
|
||||||
await fetch(this.info.api.toString()+"/channels/"+this.id+"/permissions/"+role.id,{
|
await fetch(this.info.api.toString()+"/channels/"+this.snowflake+"/permissions/"+role.snowflake,{
|
||||||
method:"PUT",
|
method:"PUT",
|
||||||
headers:this.headers,
|
headers:this.headers,
|
||||||
body:JSON.stringify({
|
body:JSON.stringify({
|
||||||
allow:"0",
|
allow:"0",
|
||||||
deny:"0",
|
deny:"0",
|
||||||
id:role.id,
|
id:role.snowflake,
|
||||||
type:0
|
type:0
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
const perm=new Permissions("0","0");
|
const perm=new Permissions("0","0");
|
||||||
this.permission_overwrites.set(role.id.id,perm);
|
this.permission_overwrites.set(role.id,perm);
|
||||||
this.permission_overwritesar.push([role.id,perm]);
|
this.permission_overwritesar.push([role.snowflake,perm]);
|
||||||
}
|
}
|
||||||
async updateRolePermissions(id:string,perms:Permissions){
|
async updateRolePermissions(id:string,perms:Permissions){
|
||||||
const permission=this.permission_overwrites.get(id);
|
const permission=this.permission_overwrites.get(id);
|
||||||
permission.allow=perms.allow;
|
permission.allow=perms.allow;
|
||||||
permission.deny=perms.deny;
|
permission.deny=perms.deny;
|
||||||
await fetch(this.info.api.toString()+"/channels/"+this.id+"/permissions/"+id,{
|
await fetch(this.info.api.toString()+"/channels/"+this.snowflake+"/permissions/"+id,{
|
||||||
method:"PUT",
|
method:"PUT",
|
||||||
headers:this.headers,
|
headers:this.headers,
|
||||||
body:JSON.stringify({
|
body:JSON.stringify({
|
||||||
|
|
|
@ -18,7 +18,7 @@ class Direct extends Guild{
|
||||||
this.headers=this.localuser.headers;
|
this.headers=this.localuser.headers;
|
||||||
this.channels=[];
|
this.channels=[];
|
||||||
this.channelids={};
|
this.channelids={};
|
||||||
this.id=new SnowFlake("@me",this);
|
this.snowflake=new SnowFlake("@me",this);
|
||||||
this.properties={};
|
this.properties={};
|
||||||
this.roles=[];
|
this.roles=[];
|
||||||
this.roleids=new Map();
|
this.roleids=new Map();
|
||||||
|
@ -27,7 +27,7 @@ class Direct extends Guild{
|
||||||
for(const thing of JSON){
|
for(const thing of JSON){
|
||||||
const temp=new Group(thing,this);
|
const temp=new Group(thing,this);
|
||||||
this.channels.push(temp);
|
this.channels.push(temp);
|
||||||
this.channelids[temp.id.id]=temp;
|
this.channelids[temp.id]=temp;
|
||||||
}
|
}
|
||||||
this.headchannels=this.channels;
|
this.headchannels=this.channels;
|
||||||
}
|
}
|
||||||
|
@ -75,7 +75,7 @@ class Group extends Channel{
|
||||||
this.user=this.localuser.user;
|
this.user=this.localuser.user;
|
||||||
}
|
}
|
||||||
this.name??=this.localuser.user.username;
|
this.name??=this.localuser.user.username;
|
||||||
this.id=new SnowFlake(JSON.id,this);
|
this.snowflake=new SnowFlake(JSON.id,this);
|
||||||
this.parent_id=null;
|
this.parent_id=null;
|
||||||
this.parent=null;
|
this.parent=null;
|
||||||
this.children=[];
|
this.children=[];
|
||||||
|
@ -114,17 +114,17 @@ class Group extends Channel{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.buildmessages();
|
this.buildmessages();
|
||||||
history.pushState(null, null,"/channels/"+this.guild_id+"/"+this.id);
|
history.pushState(null, null,"/channels/"+this.guild_id+"/"+this.snowflake);
|
||||||
document.getElementById("channelname").textContent="@"+this.name;
|
document.getElementById("channelname").textContent="@"+this.name;
|
||||||
}
|
}
|
||||||
messageCreate(messagep){
|
messageCreate(messagep){
|
||||||
const messagez=new Message(messagep.d,this);
|
const messagez=new Message(messagep.d,this);
|
||||||
this.idToNext.set(this.lastmessageid,messagez.id);
|
this.idToNext.set(this.lastmessageid,messagez.snowflake);
|
||||||
this.idToPrev.set(messagez.id,this.lastmessageid);
|
this.idToPrev.set(messagez.snowflake,this.lastmessageid);
|
||||||
this.lastmessageid=messagez.id;
|
this.lastmessageid=messagez.snowflake;
|
||||||
this.messageids.set(messagez.id,messagez);
|
this.messageids.set(messagez.snowflake,messagez);
|
||||||
if(messagez.author===this.localuser.user){
|
if(messagez.author===this.localuser.user){
|
||||||
this.lastreadmessageid=messagez.id;
|
this.lastreadmessageid=messagez.snowflake;
|
||||||
if(this.myhtml){
|
if(this.myhtml){
|
||||||
this.myhtml.classList.remove("cunread");
|
this.myhtml.classList.remove("cunread");
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ class Fullscreen{
|
||||||
this.html.classList.add("nonimagecenter");
|
this.html.classList.add("nonimagecenter");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tohtml(array){
|
tohtml(array:any[]){
|
||||||
switch(array[0]){
|
switch(array[0]){
|
||||||
case "img":
|
case "img":
|
||||||
const img=document.createElement("img");
|
const img=document.createElement("img");
|
||||||
|
|
|
@ -12,7 +12,7 @@ class Guild{
|
||||||
headers:Localuser["headers"];
|
headers:Localuser["headers"];
|
||||||
channels:Channel[];
|
channels:Channel[];
|
||||||
channelids:{[key:string]:Channel};
|
channelids:{[key:string]:Channel};
|
||||||
id:SnowFlake<Guild>;
|
snowflake:SnowFlake<Guild>;
|
||||||
properties
|
properties
|
||||||
roles:Role[];
|
roles:Role[];
|
||||||
roleids:Map<SnowFlake<Role>,Role>;
|
roleids:Map<SnowFlake<Role>,Role>;
|
||||||
|
@ -23,6 +23,9 @@ class Guild{
|
||||||
parent_id:string;
|
parent_id:string;
|
||||||
member:Member;
|
member:Member;
|
||||||
html:HTMLElement;
|
html:HTMLElement;
|
||||||
|
get id(){
|
||||||
|
return this.snowflake.id;
|
||||||
|
}
|
||||||
static contextmenu=new Contextmenu("guild menu");
|
static contextmenu=new Contextmenu("guild menu");
|
||||||
static setupcontextmenu(){
|
static setupcontextmenu(){
|
||||||
Guild.contextmenu.addbutton("Copy Guild id",function(){
|
Guild.contextmenu.addbutton("Copy Guild id",function(){
|
||||||
|
@ -71,7 +74,7 @@ class Guild{
|
||||||
const s1=settings.addButton("roles");
|
const s1=settings.addButton("roles");
|
||||||
const permlist=[];
|
const permlist=[];
|
||||||
for(const thing of this.roles){
|
for(const thing of this.roles){
|
||||||
permlist.push([thing.id,thing.permissions]);
|
permlist.push([thing.snowflake,thing.permissions]);
|
||||||
}
|
}
|
||||||
s1.options.push(new RoleList(permlist,this,this.updateRolePermissions.bind(this)));
|
s1.options.push(new RoleList(permlist,this,this.updateRolePermissions.bind(this)));
|
||||||
settings.show();
|
settings.show();
|
||||||
|
@ -84,7 +87,7 @@ class Guild{
|
||||||
this.headers=this.owner.headers;
|
this.headers=this.owner.headers;
|
||||||
this.channels=[];
|
this.channels=[];
|
||||||
this.channelids={};
|
this.channelids={};
|
||||||
this.id=new SnowFlake(json.id,this);
|
this.snowflake=new SnowFlake(json.id,this);
|
||||||
this.properties=json.properties;
|
this.properties=json.properties;
|
||||||
this.roles=[];
|
this.roles=[];
|
||||||
this.roleids=new Map();
|
this.roleids=new Map();
|
||||||
|
@ -93,13 +96,13 @@ class Guild{
|
||||||
for(const roley of json.roles){
|
for(const roley of json.roles){
|
||||||
const roleh=new Role(roley,this);
|
const roleh=new Role(roley,this);
|
||||||
this.roles.push(roleh)
|
this.roles.push(roleh)
|
||||||
this.roleids.set(roleh.id,roleh);
|
this.roleids.set(roleh.snowflake,roleh);
|
||||||
}
|
}
|
||||||
Member.resolve(member,this).then(_=>this.member=_);
|
Member.resolve(member,this).then(_=>this.member=_);
|
||||||
for(const thing of json.channels){
|
for(const thing of json.channels){
|
||||||
const temp=new Channel(thing,this);
|
const temp=new Channel(thing,this);
|
||||||
this.channels.push(temp);
|
this.channels.push(temp);
|
||||||
this.channelids[temp.id.id]=temp;
|
this.channelids[temp.id]=temp;
|
||||||
}
|
}
|
||||||
this.headchannels=[];
|
this.headchannels=[];
|
||||||
for(const thing of this.channels){
|
for(const thing of this.channels){
|
||||||
|
@ -129,7 +132,7 @@ class Guild{
|
||||||
headers:this.headers,
|
headers:this.headers,
|
||||||
body:JSON.stringify({
|
body:JSON.stringify({
|
||||||
"guilds":{
|
"guilds":{
|
||||||
[this.id.id]:{
|
[this.id]:{
|
||||||
"message_notifications": noti
|
"message_notifications": noti
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -169,7 +172,7 @@ class Guild{
|
||||||
full.show();
|
full.show();
|
||||||
}
|
}
|
||||||
async leave(){
|
async leave(){
|
||||||
return fetch(this.info.api.toString()+"/users/@me/guilds/"+this.id,{
|
return fetch(this.info.api.toString()+"/users/@me/guilds/"+this.snowflake,{
|
||||||
method:"DELETE",
|
method:"DELETE",
|
||||||
headers:this.headers
|
headers:this.headers
|
||||||
})
|
})
|
||||||
|
@ -188,7 +191,7 @@ class Guild{
|
||||||
let position=-1;
|
let position=-1;
|
||||||
let build=[];
|
let build=[];
|
||||||
for(const thing of this.headchannels){
|
for(const thing of this.headchannels){
|
||||||
const thisthing={id:thing.id,position:undefined,parent_id:undefined}
|
const thisthing={id:thing.snowflake,position:undefined,parent_id:undefined}
|
||||||
if(thing.position<=position){
|
if(thing.position<=position){
|
||||||
thing.position=(thisthing.position=position+1);
|
thing.position=(thisthing.position=position+1);
|
||||||
}
|
}
|
||||||
|
@ -217,14 +220,14 @@ class Guild{
|
||||||
if(serverbug){
|
if(serverbug){
|
||||||
for(const thing of build){
|
for(const thing of build){
|
||||||
console.log(build,thing)
|
console.log(build,thing)
|
||||||
fetch(this.info.api.toString()+"/v9/guilds/"+this.id+"/channels",{
|
fetch(this.info.api.toString()+"/v9/guilds/"+this.snowflake+"/channels",{
|
||||||
method:"PATCH",
|
method:"PATCH",
|
||||||
headers:this.headers,
|
headers:this.headers,
|
||||||
body:JSON.stringify([thing])
|
body:JSON.stringify([thing])
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
fetch(this.info.api.toString()+"/v9/guilds/"+this.id+"/channels",{
|
fetch(this.info.api.toString()+"/v9/guilds/"+this.snowflake+"/channels",{
|
||||||
method:"PATCH",
|
method:"PATCH",
|
||||||
headers:this.headers,
|
headers:this.headers,
|
||||||
body:JSON.stringify(build)
|
body:JSON.stringify(build)
|
||||||
|
@ -248,7 +251,7 @@ class Guild{
|
||||||
const noti=document.createElement("div");
|
const noti=document.createElement("div");
|
||||||
noti.classList.add("unread");
|
noti.classList.add("unread");
|
||||||
divy.append(noti);
|
divy.append(noti);
|
||||||
this.localuser.guildhtml[this.id.id]=divy;
|
this.localuser.guildhtml.set(this.id,divy);
|
||||||
if(this.properties.icon!=null){
|
if(this.properties.icon!=null){
|
||||||
const img=document.createElement("img");
|
const img=document.createElement("img");
|
||||||
img.classList.add("pfp","servericon");
|
img.classList.add("pfp","servericon");
|
||||||
|
@ -319,7 +322,7 @@ class Guild{
|
||||||
full.show();
|
full.show();
|
||||||
}
|
}
|
||||||
async delete(){
|
async delete(){
|
||||||
return fetch(this.info.api.toString()+"/guilds/"+this.id+"/delete",{
|
return fetch(this.info.api.toString()+"/guilds/"+this.snowflake+"/delete",{
|
||||||
method:"POST",
|
method:"POST",
|
||||||
headers:this.headers,
|
headers:this.headers,
|
||||||
})
|
})
|
||||||
|
@ -362,7 +365,7 @@ class Guild{
|
||||||
const build={read_states:[]};
|
const build={read_states:[]};
|
||||||
for(const thing of this.channels){
|
for(const thing of this.channels){
|
||||||
if(thing.hasunreads){
|
if(thing.hasunreads){
|
||||||
build.read_states.push({channel_id:thing.id,message_id:thing.lastmessageid,read_state_type:0});
|
build.read_states.push({channel_id:thing.snowflake,message_id:thing.lastmessageid,read_state_type:0});
|
||||||
thing.lastreadmessageid=thing.lastmessageid;
|
thing.lastreadmessageid=thing.lastmessageid;
|
||||||
thing.myhtml.classList.remove("cunread");
|
thing.myhtml.classList.remove("cunread");
|
||||||
}
|
}
|
||||||
|
@ -377,7 +380,7 @@ class Guild{
|
||||||
hasRole(r:Role|string){
|
hasRole(r:Role|string){
|
||||||
console.log("this should run");
|
console.log("this should run");
|
||||||
if(r instanceof Role){
|
if(r instanceof Role){
|
||||||
r=r.id.id;
|
r=r.id;
|
||||||
}
|
}
|
||||||
return this.member.hasRole(r);
|
return this.member.hasRole(r);
|
||||||
}
|
}
|
||||||
|
@ -399,7 +402,7 @@ class Guild{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
loadGuild(){
|
loadGuild(){
|
||||||
this.localuser.loadGuild(this.id.id);
|
this.localuser.loadGuild(this.id);
|
||||||
}
|
}
|
||||||
updateChannel(JSON){
|
updateChannel(JSON){
|
||||||
SnowFlake.getSnowFlakeFromID(JSON.id,Channel).getObject().updateChannel(JSON);
|
SnowFlake.getSnowFlakeFromID(JSON.id,Channel).getObject().updateChannel(JSON);
|
||||||
|
@ -495,14 +498,14 @@ class Guild{
|
||||||
this.printServers();
|
this.printServers();
|
||||||
}
|
}
|
||||||
createChannel(name:string,type:number){
|
createChannel(name:string,type:number){
|
||||||
fetch(this.info.api.toString()+"/guilds/"+this.id+"/channels",{
|
fetch(this.info.api.toString()+"/guilds/"+this.snowflake+"/channels",{
|
||||||
method:"POST",
|
method:"POST",
|
||||||
headers:this.headers,
|
headers:this.headers,
|
||||||
body:JSON.stringify({name: name, type: type})
|
body:JSON.stringify({name: name, type: type})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
async createRole(name:string){
|
async createRole(name:string){
|
||||||
const fetched=await fetch(this.info.api.toString()+"/guilds/"+this.id+"roles",{
|
const fetched=await fetch(this.info.api.toString()+"/guilds/"+this.snowflake+"roles",{
|
||||||
method:"POST",
|
method:"POST",
|
||||||
headers:this.headers,
|
headers:this.headers,
|
||||||
body:JSON.stringify({
|
body:JSON.stringify({
|
||||||
|
@ -513,7 +516,7 @@ class Guild{
|
||||||
})
|
})
|
||||||
const json=await fetched.json();
|
const json=await fetched.json();
|
||||||
const role=new Role(json,this);
|
const role=new Role(json,this);
|
||||||
this.roleids[role.id.id]=role;
|
this.roleids.set(role.snowflake,role);
|
||||||
this.roles.push(role);
|
this.roles.push(role);
|
||||||
return role;
|
return role;
|
||||||
}
|
}
|
||||||
|
@ -522,7 +525,7 @@ class Guild{
|
||||||
role.permissions.allow=perms.allow;
|
role.permissions.allow=perms.allow;
|
||||||
role.permissions.deny=perms.deny;
|
role.permissions.deny=perms.deny;
|
||||||
|
|
||||||
await fetch(this.info.api.toString()+"/guilds/"+this.id+"/roles/"+this.id,{
|
await fetch(this.info.api.toString()+"/guilds/"+this.snowflake+"/roles/"+this.snowflake,{
|
||||||
method:"PATCH",
|
method:"PATCH",
|
||||||
headers:this.headers,
|
headers:this.headers,
|
||||||
body:JSON.stringify({
|
body:JSON.stringify({
|
||||||
|
|
|
@ -3,8 +3,6 @@ import {Channel} from "./channel.js";
|
||||||
import {Direct} from "./direct.js";
|
import {Direct} from "./direct.js";
|
||||||
import {Voice} from "./audio.js";
|
import {Voice} from "./audio.js";
|
||||||
import {User} from "./user.js";
|
import {User} from "./user.js";
|
||||||
import {Member} from "./member.js";
|
|
||||||
import {MarkDown} from "./markdown.js";
|
|
||||||
import {Fullscreen} from "./fullscreen.js";
|
import {Fullscreen} from "./fullscreen.js";
|
||||||
import {setTheme, Specialuser} from "./login.js";
|
import {setTheme, Specialuser} from "./login.js";
|
||||||
import { SnowFlake } from "./snowflake.js";
|
import { SnowFlake } from "./snowflake.js";
|
||||||
|
@ -66,12 +64,12 @@ class Localuser{
|
||||||
for(const thing of ready.d.guilds){
|
for(const thing of ready.d.guilds){
|
||||||
const temp=new Guild(thing,this,members[thing.id]);
|
const temp=new Guild(thing,this,members[thing.id]);
|
||||||
this.guilds.push(temp);
|
this.guilds.push(temp);
|
||||||
this.guildids[temp.id.id]=temp;
|
this.guildids[temp.id]=temp;
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
const temp=new Direct(ready.d.private_channels,this);
|
const temp=new Direct(ready.d.private_channels,this);
|
||||||
this.guilds.push(temp);
|
this.guilds.push(temp);
|
||||||
this.guildids[temp.id.id]=temp;
|
this.guildids[temp.id]=temp;
|
||||||
}
|
}
|
||||||
console.log(ready.d.user_guild_settings.entries);
|
console.log(ready.d.user_guild_settings.entries);
|
||||||
|
|
||||||
|
@ -87,7 +85,7 @@ class Localuser{
|
||||||
if(guild===undefined){
|
if(guild===undefined){
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
const guildid=guild.id;
|
const guildid=guild.snowflake;
|
||||||
this.guildids[guildid.id].channelids[thing.channel_id].readStateInfo(thing);
|
this.guildids[guildid.id].channelids[thing.channel_id].readStateInfo(thing);
|
||||||
}
|
}
|
||||||
this.typing=[];
|
this.typing=[];
|
||||||
|
@ -204,7 +202,7 @@ class Localuser{
|
||||||
{
|
{
|
||||||
const guildy=new Guild(temp.d,this,this.user);
|
const guildy=new Guild(temp.d,this,this.user);
|
||||||
this.guilds.push(guildy);
|
this.guilds.push(guildy);
|
||||||
this.guildids[guildy.id.id]=guildy;
|
this.guildids[guildy.id]=guildy;
|
||||||
document.getElementById("servers").insertBefore(guildy.generateGuildIcon(),document.getElementById("bottomseparator"));
|
document.getElementById("servers").insertBefore(guildy.generateGuildIcon(),document.getElementById("bottomseparator"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -265,14 +263,14 @@ class Localuser{
|
||||||
}
|
}
|
||||||
updateChannel(JSON):void{
|
updateChannel(JSON):void{
|
||||||
SnowFlake.getSnowFlakeFromID(JSON.guild_id,Guild).getObject().updateChannel(JSON);
|
SnowFlake.getSnowFlakeFromID(JSON.guild_id,Guild).getObject().updateChannel(JSON);
|
||||||
if(JSON.guild_id===this.lookingguild.id.id){
|
if(JSON.guild_id===this.lookingguild.id){
|
||||||
this.loadGuild(JSON.guild_id);
|
this.loadGuild(JSON.guild_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
createChannel(JSON):void{
|
createChannel(JSON):void{
|
||||||
JSON.guild_id??="@me";
|
JSON.guild_id??="@me";
|
||||||
SnowFlake.getSnowFlakeFromID(JSON.guild_id,Guild).getObject().createChannelpac(JSON);
|
SnowFlake.getSnowFlakeFromID(JSON.guild_id,Guild).getObject().createChannelpac(JSON);
|
||||||
if(JSON.guild_id===this.lookingguild.id.id){
|
if(JSON.guild_id===this.lookingguild.id){
|
||||||
this.loadGuild(JSON.guild_id);
|
this.loadGuild(JSON.guild_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -280,7 +278,7 @@ class Localuser{
|
||||||
JSON.guild_id??="@me";
|
JSON.guild_id??="@me";
|
||||||
this.guildids[JSON.guild_id].delChannel(JSON);
|
this.guildids[JSON.guild_id].delChannel(JSON);
|
||||||
|
|
||||||
if(JSON.guild_id===this.lookingguild.id){
|
if(JSON.guild_id===this.lookingguild.snowflake){
|
||||||
this.loadGuild(JSON.guild_id);
|
this.loadGuild(JSON.guild_id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -497,15 +495,15 @@ class Localuser{
|
||||||
unreads():void{
|
unreads():void{
|
||||||
console.log(this.guildhtml)
|
console.log(this.guildhtml)
|
||||||
for(const thing of this.guilds){
|
for(const thing of this.guilds){
|
||||||
if(thing.id.id==="@me"){continue;}
|
if(thing.id==="@me"){continue;}
|
||||||
thing.unreads(this.guildhtml[thing.id.id]);
|
thing.unreads(this.guildhtml[thing.id]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
typingStart(typing):void{
|
typingStart(typing):void{
|
||||||
if(this.channelfocus.id===typing.d.channel_id){
|
if(this.channelfocus.snowflake===typing.d.channel_id){
|
||||||
const memb=typing.d.member;
|
const memb=typing.d.member;
|
||||||
let name;
|
let name;
|
||||||
if(memb.id===this.user.id){
|
if(memb.id===this.user.snowflake){
|
||||||
console.log("you is typing")
|
console.log("you is typing")
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,42 +69,42 @@ class Member{
|
||||||
let id:SnowFlake<User>;
|
let id:SnowFlake<User>;
|
||||||
if(unkown instanceof User){
|
if(unkown instanceof User){
|
||||||
user=unkown as User;
|
user=unkown as User;
|
||||||
id=user.id;
|
id=user.snowflake;
|
||||||
}else if(typeof unkown===typeof ""){
|
}else if(typeof unkown===typeof ""){
|
||||||
id=new SnowFlake(unkown as string,undefined);
|
id=new SnowFlake(unkown as string,undefined);
|
||||||
}else{
|
}else{
|
||||||
return new Member(unkown,guild);
|
return new Member(unkown,guild);
|
||||||
}
|
}
|
||||||
if(guild.id.id==="@me"){return null}
|
if(guild.id==="@me"){return null}
|
||||||
if(!Member.already[guild.id.id]){
|
if(!Member.already[guild.id]){
|
||||||
Member.already[guild.id.id]={};
|
Member.already[guild.id]={};
|
||||||
}else if(Member.already[guild.id.id][id]){
|
}else if(Member.already[guild.id][id]){
|
||||||
const memb=Member.already[guild.id.id][id]
|
const memb=Member.already[guild.id][id]
|
||||||
if(memb instanceof Promise){
|
if(memb instanceof Promise){
|
||||||
return await memb;
|
return await memb;
|
||||||
}
|
}
|
||||||
return memb;
|
return memb;
|
||||||
}
|
}
|
||||||
const promoise= fetch(guild.info.api.toString()+"/users/"+id+"/profile?with_mutual_guilds=true&with_mutual_friends_count=true&guild_id="+guild.id,{headers:guild.headers}).then(_=>_.json()).then(json=>{
|
const promoise= fetch(guild.info.api.toString()+"/users/"+id+"/profile?with_mutual_guilds=true&with_mutual_friends_count=true&guild_id="+guild.snowflake,{headers:guild.headers}).then(_=>_.json()).then(json=>{
|
||||||
const memb=new Member(json,guild);
|
const memb=new Member(json,guild);
|
||||||
Member.already[guild.id.id][id]=memb;
|
Member.already[guild.id][id]=memb;
|
||||||
console.log("resolved")
|
console.log("resolved")
|
||||||
return memb
|
return memb
|
||||||
})
|
})
|
||||||
Member.already[guild.id.id][id]=promoise;
|
Member.already[guild.id][id]=promoise;
|
||||||
try{
|
try{
|
||||||
return await promoise
|
return await promoise
|
||||||
}catch(_){
|
}catch(_){
|
||||||
|
|
||||||
const memb=new Member(user,guild,true);
|
const memb=new Member(user,guild,true);
|
||||||
Member.already[guild.id.id][id]=memb;
|
Member.already[guild.id][id]=memb;
|
||||||
return memb;
|
return memb;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
hasRole(ID:string){
|
hasRole(ID:string){
|
||||||
console.log(this.roles,ID);
|
console.log(this.roles,ID);
|
||||||
for(const thing of this.roles){
|
for(const thing of this.roles){
|
||||||
if(thing.id.id===ID){
|
if(thing.id===ID){
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -125,7 +125,7 @@ class Member{
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return this.guild.properties.owner_id===this.user.id.id;
|
return this.guild.properties.owner_id===this.user.id;
|
||||||
}
|
}
|
||||||
bind(html:HTMLElement){
|
bind(html:HTMLElement){
|
||||||
if(html.tagName==="SPAN"){
|
if(html.tagName==="SPAN"){
|
||||||
|
|
|
@ -18,7 +18,7 @@ class Message{
|
||||||
mentions:User[];
|
mentions:User[];
|
||||||
mention_roles:Role[];
|
mention_roles:Role[];
|
||||||
attachments:File[];//probably should be its own class tbh, should be Attachments[]
|
attachments:File[];//probably should be its own class tbh, should be Attachments[]
|
||||||
id:SnowFlake<Message>;
|
snowflake:SnowFlake<Message>;
|
||||||
message_reference;
|
message_reference;
|
||||||
type:number;
|
type:number;
|
||||||
timestamp:number;
|
timestamp:number;
|
||||||
|
@ -26,6 +26,9 @@ class Message{
|
||||||
static del:Promise<void>;
|
static del:Promise<void>;
|
||||||
static resolve:Function;
|
static resolve:Function;
|
||||||
div:HTMLDivElement;
|
div:HTMLDivElement;
|
||||||
|
get id(){
|
||||||
|
return this.snowflake.id;
|
||||||
|
}
|
||||||
static setup(){
|
static setup(){
|
||||||
this.del=new Promise(_=>{this.resolve=_});
|
this.del=new Promise(_=>{this.resolve=_});
|
||||||
Message.setupcmenu();
|
Message.setupcmenu();
|
||||||
|
@ -74,7 +77,7 @@ class Message{
|
||||||
this.content=new MarkDown(messagejson[thing],this.channel);
|
this.content=new MarkDown(messagejson[thing],this.channel);
|
||||||
continue;
|
continue;
|
||||||
}else if(thing ==="id"){
|
}else if(thing ==="id"){
|
||||||
this.id=new SnowFlake(messagejson.id,this);
|
this.snowflake=new SnowFlake(messagejson.id,this);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
this[thing]=messagejson[thing];
|
this[thing]=messagejson[thing];
|
||||||
|
@ -98,7 +101,7 @@ class Message{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
canDelete(){
|
canDelete(){
|
||||||
return this.channel.hasPermission("MANAGE_MESSAGES")||this.author.id===this.localuser.user.id;
|
return this.channel.hasPermission("MANAGE_MESSAGES")||this.author.snowflake===this.localuser.user.snowflake;
|
||||||
}
|
}
|
||||||
get channel(){
|
get channel(){
|
||||||
return this.owner;
|
return this.owner;
|
||||||
|
@ -139,14 +142,14 @@ class Message{
|
||||||
return build;
|
return build;
|
||||||
}
|
}
|
||||||
async edit(content){
|
async edit(content){
|
||||||
return await fetch(this.info.api.toString()+"/channels/"+this.channel.id+"/messages/"+this.id.id,{
|
return await fetch(this.info.api.toString()+"/channels/"+this.channel.snowflake+"/messages/"+this.id,{
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
body:JSON.stringify({content:content})
|
body:JSON.stringify({content:content})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
delete(){
|
delete(){
|
||||||
fetch(`${this.info.api.toString()}/channels/${this.channel.id}/messages/${this.id.id}`,{
|
fetch(`${this.info.api.toString()}/channels/${this.channel.snowflake}/messages/${this.id}`,{
|
||||||
headers:this.headers,
|
headers:this.headers,
|
||||||
method:"DELETE",
|
method:"DELETE",
|
||||||
})
|
})
|
||||||
|
@ -156,22 +159,22 @@ class Message{
|
||||||
this.div.innerHTML="";
|
this.div.innerHTML="";
|
||||||
this.div=null;
|
this.div=null;
|
||||||
}
|
}
|
||||||
const prev=this.channel.idToPrev[this.id.id];
|
const prev=this.channel.idToPrev.get(this.snowflake);
|
||||||
const next=this.channel.idToNext[this.id.id];
|
const next=this.channel.idToNext.get(this.snowflake);
|
||||||
this.channel.idToNext[prev]=next;
|
this.channel.idToNext.set(prev,next);
|
||||||
this.channel.idToPrev[next]=prev;
|
this.channel.idToPrev.set(next,prev);
|
||||||
delete this.channel.messageids[this.id.id];
|
this.channel.messageids.delete(this.snowflake);
|
||||||
const regen=this.channel.messageids[prev]
|
const regen=prev.getObject();
|
||||||
if(regen){
|
if(regen){
|
||||||
regen.generateMessage();
|
regen.generateMessage();
|
||||||
}
|
}
|
||||||
if(this.channel.lastmessage===this){
|
if(this.channel.lastmessage===this){
|
||||||
this.channel.lastmessage=this.channel.messageids[prev];
|
this.channel.lastmessage=prev.getObject();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
generateMessage(premessage:Message=null){
|
generateMessage(premessage:Message=null){
|
||||||
if(!premessage){
|
if(!premessage){
|
||||||
premessage=this.channel.messageids[this.channel.idToNext[this.id.id]];
|
premessage=this.channel.idToNext.get(this.snowflake)?.getObject();
|
||||||
}
|
}
|
||||||
const div=this.div;
|
const div=this.div;
|
||||||
if(this===this.channel.replyingto){
|
if(this===this.channel.replyingto){
|
||||||
|
@ -244,7 +247,7 @@ class Message{
|
||||||
const newt=(new Date(this.timestamp).getTime())/1000;
|
const newt=(new Date(this.timestamp).getTime())/1000;
|
||||||
current=(newt-old)>600;
|
current=(newt-old)>600;
|
||||||
}
|
}
|
||||||
const combine=(premessage?.author?.id!=this.author.id)||(current)||this.message_reference
|
const combine=(premessage?.author?.snowflake!=this.author.snowflake)||(current)||this.message_reference
|
||||||
if(combine){
|
if(combine){
|
||||||
const pfp=this.author.buildpfp();
|
const pfp=this.author.buildpfp();
|
||||||
this.author.bind(pfp);
|
this.author.bind(pfp);
|
||||||
|
@ -333,7 +336,7 @@ class Message{
|
||||||
return(div)
|
return(div)
|
||||||
}
|
}
|
||||||
buildhtml(premessage:Message,del:Promise<void>=Message.del){
|
buildhtml(premessage:Message,del:Promise<void>=Message.del){
|
||||||
if(this.div){console.error(`HTML for ${this.id} already exists, aborting`);return;}
|
if(this.div){console.error(`HTML for ${this.snowflake} already exists, aborting`);return;}
|
||||||
//premessage??=messages.lastChild;
|
//premessage??=messages.lastChild;
|
||||||
const div=document.createElement("div");
|
const div=document.createElement("div");
|
||||||
this.div=div;
|
this.div=div;
|
||||||
|
|
|
@ -7,7 +7,7 @@ class Role{
|
||||||
permissions:Permissions;
|
permissions:Permissions;
|
||||||
owner:Guild;
|
owner:Guild;
|
||||||
color:number;
|
color:number;
|
||||||
readonly id:SnowFlake<Role>;
|
readonly snowflake:SnowFlake<Role>;
|
||||||
name:string;
|
name:string;
|
||||||
info:Guild["info"];
|
info:Guild["info"];
|
||||||
hoist:boolean;
|
hoist:boolean;
|
||||||
|
@ -15,12 +15,15 @@ class Role{
|
||||||
mentionable:boolean;
|
mentionable:boolean;
|
||||||
unicode_emoji:string;
|
unicode_emoji:string;
|
||||||
headers:Guild["headers"];
|
headers:Guild["headers"];
|
||||||
|
get id(){
|
||||||
|
return this.snowflake.id;
|
||||||
|
}
|
||||||
constructor(JSON, owner:Guild){
|
constructor(JSON, owner:Guild){
|
||||||
this.headers=owner.headers;
|
this.headers=owner.headers;
|
||||||
this.info=owner.info;
|
this.info=owner.info;
|
||||||
for(const thing of Object.keys(JSON)){
|
for(const thing of Object.keys(JSON)){
|
||||||
if(thing==="id"){
|
if(thing==="id"){
|
||||||
this.id=new SnowFlake(JSON.id,this);
|
this.snowflake=new SnowFlake(JSON.id,this);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
this[thing]=JSON[thing];
|
this[thing]=JSON[thing];
|
||||||
|
|
|
@ -10,13 +10,16 @@ class User{
|
||||||
static userids={};
|
static userids={};
|
||||||
owner:Localuser;
|
owner:Localuser;
|
||||||
hypotheticalpfp:boolean;
|
hypotheticalpfp:boolean;
|
||||||
id:SnowFlake<User>;
|
snowflake:SnowFlake<User>;
|
||||||
avatar:string;
|
avatar:string;
|
||||||
username:string;
|
username:string;
|
||||||
bio:MarkDown;
|
bio:MarkDown;
|
||||||
discriminator:string;
|
discriminator:string;
|
||||||
pronouns:string;
|
pronouns:string;
|
||||||
bot:boolean;
|
bot:boolean;
|
||||||
|
get id(){
|
||||||
|
return this.snowflake.id;
|
||||||
|
}
|
||||||
static contextmenu:Contextmenu=new Contextmenu("User Menu");
|
static contextmenu:Contextmenu=new Contextmenu("User Menu");
|
||||||
static setUpContextMenu(){
|
static setUpContextMenu(){
|
||||||
this.contextmenu.addbutton("Copy user id",function(){
|
this.contextmenu.addbutton("Copy user id",function(){
|
||||||
|
@ -55,7 +58,7 @@ class User{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(thing === "id"){
|
if(thing === "id"){
|
||||||
this.id=new SnowFlake(userjson[thing],this);
|
this.snowflake=new SnowFlake(userjson[thing],this);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
this[thing]=userjson[thing];
|
this[thing]=userjson[thing];
|
||||||
|
@ -72,7 +75,7 @@ class User{
|
||||||
const pfp=document.createElement('img');
|
const pfp=document.createElement('img');
|
||||||
pfp.src=this.getpfpsrc();
|
pfp.src=this.getpfpsrc();
|
||||||
pfp.classList.add("pfp");
|
pfp.classList.add("pfp");
|
||||||
pfp.classList.add("userid:"+this.id.id);
|
pfp.classList.add("userid:"+this.id);
|
||||||
return pfp;
|
return pfp;
|
||||||
}
|
}
|
||||||
userupdate(json){
|
userupdate(json){
|
||||||
|
@ -82,7 +85,7 @@ class User{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
bind(html:HTMLElement,guild:Guild=null){
|
bind(html:HTMLElement,guild:Guild=null){
|
||||||
if(guild&&guild.id.id!=="@me"){
|
if(guild&&guild.id!=="@me"){
|
||||||
Member.resolve(this,guild).then(_=>{
|
Member.resolve(this,guild).then(_=>{
|
||||||
_.bind(html);
|
_.bind(html);
|
||||||
}).catch(_=>{
|
}).catch(_=>{
|
||||||
|
@ -103,7 +106,7 @@ class User{
|
||||||
this.hypotheticalpfp=false;
|
this.hypotheticalpfp=false;
|
||||||
const src=this.getpfpsrc();
|
const src=this.getpfpsrc();
|
||||||
console.log(src)
|
console.log(src)
|
||||||
for(const thing of document.getElementsByClassName("userid:"+this.id.id)){
|
for(const thing of document.getElementsByClassName("userid:"+this.id)){
|
||||||
(thing as HTMLImageElement).src=src;
|
(thing as HTMLImageElement).src=src;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -112,7 +115,7 @@ class User{
|
||||||
return this.avatar;
|
return this.avatar;
|
||||||
}
|
}
|
||||||
if(this.avatar!=null){
|
if(this.avatar!=null){
|
||||||
return this.info.cdn.toString()+"avatars/"+this.id.id+"/"+this.avatar+".png";
|
return this.info.cdn.toString()+"avatars/"+this.id+"/"+this.avatar+".png";
|
||||||
}else{
|
}else{
|
||||||
return this.info.cdn.toString()+"embed/avatars/3.png";
|
return this.info.cdn.toString()+"embed/avatars/3.png";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue