fix id and snowflake

This commit is contained in:
MathMan05 2024-07-24 12:53:30 -05:00
parent 5e9405207b
commit 4f80104e2e
17 changed files with 263 additions and 235 deletions

View file

@ -13,7 +13,7 @@ class Channel {
owner;
headers;
name;
id;
snowflake;
parent_id;
parent;
children;
@ -37,6 +37,9 @@ class Channel {
infinite;
idToPrev = new Map();
idToNext = new Map();
get id() {
return this.snowflake.id;
}
static setupcontextmenu() {
this.contextmenu.addbutton("Copy channel id", function () {
console.log(this);
@ -66,7 +69,7 @@ class Channel {
}
sortPerms() {
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;
});
}
@ -108,7 +111,7 @@ class Channel {
this.owner = owner;
this.headers = this.owner.headers;
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 = null;
this.children = [];
@ -160,8 +163,8 @@ class Channel {
return true;
}
for (const thing of member.roles) {
if (this.permission_overwrites.get(thing.id.id)) {
let perm = this.permission_overwrites.get(thing.id.id).getPermission(name);
if (this.permission_overwrites.get(thing.id)) {
let perm = this.permission_overwrites.get(thing.id).getPermission(name);
if (perm) {
return perm === 1;
}
@ -193,7 +196,7 @@ class Channel {
let position = -1;
let build = [];
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) {
thing.position = thisthing.position = position + 1;
}
@ -344,7 +347,7 @@ class Channel {
if (!this.hasunreads) {
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",
headers: this.headers,
body: JSON.stringify({})
@ -367,7 +370,7 @@ class Channel {
const that = Channel.dragged[0];
event.preventDefault();
if (container) {
that.move_id = this.id;
that.move_id = this.snowflake;
if (that.parent) {
that.parent.children.splice(that.parent.children.indexOf(that), 1);
}
@ -412,13 +415,13 @@ class Channel {
return div;
}
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",
headers: this.headers,
body: JSON.stringify({
name: name,
type: type,
parent_id: this.id,
parent_id: this.snowflake,
permission_overwrites: [],
})
});
@ -427,7 +430,7 @@ class Channel {
let name = this.name;
let topic = this.topic;
let nsfw = this.nsfw;
const thisid = this.id;
const thisid = this.snowflake;
const thistype = this.type;
const full = new Fullscreen(["hdiv",
["vdiv",
@ -458,7 +461,7 @@ class Channel {
console.log(full);
}
deleteChannel() {
fetch(this.info.api.toString() + "/channels/" + this.id, {
fetch(this.info.api.toString() + "/channels/" + this.snowflake, {
method: "DELETE",
headers: this.headers
});
@ -501,7 +504,7 @@ class Channel {
return snowflake.getObject();
}
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();
return new Message(json[0], this);
}
@ -526,7 +529,7 @@ class Channel {
}
this.makereplybox();
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;
console.log(this);
document.getElementById("typebox").contentEditable = "" + this.canMessage;
@ -537,7 +540,7 @@ class Channel {
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,
});
const response = await j.json();
@ -548,22 +551,22 @@ class Channel {
for (const thing of response) {
const message = new Message(thing, this);
if (prev) {
this.idToNext.set(message.id, prev.id);
this.idToPrev.set(prev.id, message.id);
this.idToNext.set(message.snowflake, prev.id);
this.idToPrev.set(prev.id, message.snowflake);
}
else {
this.lastmessage = message;
}
prev = message;
if (this.messageids.get(message.id) === undefined) {
this.messageids.set(message.id, message);
if (this.messageids.get(message.snowflake) === undefined) {
this.messageids.set(message.snowflake, message);
}
}
}
delChannel(JSON) {
const build = [];
for (const thing of this.children) {
if (thing.id !== JSON.id) {
if (thing.snowflake !== JSON.id) {
build.push(thing);
}
}
@ -573,7 +576,7 @@ class Channel {
if (this.allthewayup) {
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
}).then((j) => { return j.json(); }).then(response => {
let next;
@ -596,11 +599,11 @@ class Channel {
next = undefined;
console.log("ohno", +i + 1);
}
if (this.messageids.get(messager.id) === undefined) {
this.idToNext.set(messager.id, previd);
this.idToPrev.set(previd, messager.id);
previd = messager.id;
this.messageids.set(messager.id, messager);
if (this.messageids.get(messager.snowflake) === undefined) {
this.idToNext.set(messager.snowflake, previd);
this.idToPrev.set(previd, messager.snowflake);
previd = messager.snowflake;
this.messageids.set(messager.snowflake, messager);
}
else {
console.log("How???");
@ -621,8 +624,8 @@ class Channel {
if (this.messageids.get(this.lastreadmessageid)) {
id = this.lastreadmessageid;
}
else if (this.lastmessage.id) {
id = this.goBackIds(this.lastmessage.id, 50);
else if (this.lastmessage.snowflake) {
id = this.goBackIds(this.lastmessage.snowflake, 50);
console.log("shouldn't");
}
messages.append(this.infinite.getDiv(id.id));
@ -666,7 +669,7 @@ class Channel {
return;
}
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",
headers: this.headers
});
@ -709,7 +712,7 @@ class Channel {
body.message_reference = replyjson;
}
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",
headers: this.headers,
body: JSON.stringify(body)
@ -730,7 +733,7 @@ class Channel {
console.log(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',
body: formData,
headers: { "Authorization": this.headers.Authorization }
@ -742,13 +745,13 @@ class Channel {
return;
}
const messagez = new Message(messagep.d, this);
console.log(this.lastmessageid, messagez.id, ":3");
this.idToNext.set(this.lastmessageid, messagez.id);
this.idToPrev.set(messagez.id, this.lastmessageid);
this.lastmessageid = messagez.id;
this.messageids.set(messagez.id, messagez);
console.log(this.lastmessageid, messagez.snowflake, ":3");
this.idToNext.set(this.lastmessageid, messagez.snowflake);
this.idToPrev.set(messagez.snowflake, this.lastmessageid);
this.lastmessageid = messagez.snowflake;
this.messageids.set(messagez.snowflake, messagez);
if (messagez.author === this.localuser.user) {
this.lastreadmessageid = messagez.id;
this.lastreadmessageid = messagez.snowflake;
if (this.myhtml) {
this.myhtml.classList.remove("cunread");
}
@ -815,25 +818,25 @@ class Channel {
}
}
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",
headers: this.headers,
body: JSON.stringify({
allow: "0",
deny: "0",
id: role.id,
id: role.snowflake,
type: 0
})
});
const perm = new Permissions("0", "0");
this.permission_overwrites.set(role.id.id, perm);
this.permission_overwritesar.push([role.id, perm]);
this.permission_overwrites.set(role.id, perm);
this.permission_overwritesar.push([role.snowflake, perm]);
}
async updateRolePermissions(id, perms) {
const permission = this.permission_overwrites.get(id);
permission.allow = perms.allow;
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",
headers: this.headers,
body: JSON.stringify({

View file

@ -15,7 +15,7 @@ class Direct extends Guild {
this.headers = this.localuser.headers;
this.channels = [];
this.channelids = {};
this.id = new SnowFlake("@me", this);
this.snowflake = new SnowFlake("@me", this);
this.properties = {};
this.roles = [];
this.roleids = new Map();
@ -24,7 +24,7 @@ class Direct extends Guild {
for (const thing of JSON) {
const temp = new Group(thing, this);
this.channels.push(temp);
this.channelids[temp.id.id] = temp;
this.channelids[temp.id] = temp;
}
this.headchannels = this.channels;
}
@ -73,7 +73,7 @@ class Group extends Channel {
this.user = this.localuser.user;
}
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 = null;
this.children = [];
@ -112,17 +112,17 @@ class Group extends Channel {
return;
}
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;
}
messageCreate(messagep) {
const messagez = new Message(messagep.d, this);
this.idToNext.set(this.lastmessageid, messagez.id);
this.idToPrev.set(messagez.id, this.lastmessageid);
this.lastmessageid = messagez.id;
this.messageids.set(messagez.id, messagez);
this.idToNext.set(this.lastmessageid, messagez.snowflake);
this.idToPrev.set(messagez.snowflake, this.lastmessageid);
this.lastmessageid = messagez.snowflake;
this.messageids.set(messagez.snowflake, messagez);
if (messagez.author === this.localuser.user) {
this.lastreadmessageid = messagez.id;
this.lastreadmessageid = messagez.snowflake;
if (this.myhtml) {
this.myhtml.classList.remove("cunread");
}

View file

@ -10,7 +10,7 @@ class Guild {
headers;
channels;
channelids;
id;
snowflake;
properties;
roles;
roleids;
@ -21,6 +21,9 @@ class Guild {
parent_id;
member;
html;
get id() {
return this.snowflake.id;
}
static contextmenu = new Contextmenu("guild menu");
static setupcontextmenu() {
Guild.contextmenu.addbutton("Copy Guild id", function () {
@ -63,7 +66,7 @@ class Guild {
const s1 = settings.addButton("roles");
const permlist = [];
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)));
settings.show();
@ -76,7 +79,7 @@ class Guild {
this.headers = this.owner.headers;
this.channels = [];
this.channelids = {};
this.id = new SnowFlake(json.id, this);
this.snowflake = new SnowFlake(json.id, this);
this.properties = json.properties;
this.roles = [];
this.roleids = new Map();
@ -85,13 +88,13 @@ class Guild {
for (const roley of json.roles) {
const roleh = new Role(roley, this);
this.roles.push(roleh);
this.roleids.set(roleh.id, roleh);
this.roleids.set(roleh.snowflake, roleh);
}
Member.resolve(member, this).then(_ => this.member = _);
for (const thing of json.channels) {
const temp = new Channel(thing, this);
this.channels.push(temp);
this.channelids[temp.id.id] = temp;
this.channelids[temp.id] = temp;
}
this.headchannels = [];
for (const thing of this.channels) {
@ -119,7 +122,7 @@ class Guild {
headers: this.headers,
body: JSON.stringify({
"guilds": {
[this.id.id]: {
[this.id]: {
"message_notifications": noti
}
}
@ -158,7 +161,7 @@ class Guild {
full.show();
}
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",
headers: this.headers
});
@ -177,7 +180,7 @@ class Guild {
let position = -1;
let build = [];
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) {
thing.position = (thisthing.position = position + 1);
}
@ -208,7 +211,7 @@ class Guild {
if (serverbug) {
for (const thing of build) {
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",
headers: this.headers,
body: JSON.stringify([thing])
@ -216,7 +219,7 @@ class Guild {
}
}
else {
fetch(this.info.api.toString() + "/v9/guilds/" + this.id + "/channels", {
fetch(this.info.api.toString() + "/v9/guilds/" + this.snowflake + "/channels", {
method: "PATCH",
headers: this.headers,
body: JSON.stringify(build)
@ -238,7 +241,7 @@ class Guild {
const noti = document.createElement("div");
noti.classList.add("unread");
divy.append(noti);
this.localuser.guildhtml[this.id.id] = divy;
this.localuser.guildhtml.set(this.id, divy);
if (this.properties.icon != null) {
const img = document.createElement("img");
img.classList.add("pfp", "servericon");
@ -308,7 +311,7 @@ class Guild {
full.show();
}
async delete() {
return fetch(this.info.api.toString() + "/guilds/" + this.id + "/delete", {
return fetch(this.info.api.toString() + "/guilds/" + this.snowflake + "/delete", {
method: "POST",
headers: this.headers,
});
@ -355,7 +358,7 @@ class Guild {
const build = { read_states: [] };
for (const thing of this.channels) {
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.myhtml.classList.remove("cunread");
}
@ -370,7 +373,7 @@ class Guild {
hasRole(r) {
console.log("this should run");
if (r instanceof Role) {
r = r.id.id;
r = r.id;
}
return this.member.hasRole(r);
}
@ -392,7 +395,7 @@ class Guild {
}
}
loadGuild() {
this.localuser.loadGuild(this.id.id);
this.localuser.loadGuild(this.id);
}
updateChannel(JSON) {
SnowFlake.getSnowFlakeFromID(JSON.id, Channel).getObject().updateChannel(JSON);
@ -484,14 +487,14 @@ class Guild {
this.printServers();
}
createChannel(name, type) {
fetch(this.info.api.toString() + "/guilds/" + this.id + "/channels", {
fetch(this.info.api.toString() + "/guilds/" + this.snowflake + "/channels", {
method: "POST",
headers: this.headers,
body: JSON.stringify({ name: name, type: type })
});
}
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",
headers: this.headers,
body: JSON.stringify({
@ -502,7 +505,7 @@ class Guild {
});
const json = await fetched.json();
const role = new Role(json, this);
this.roleids[role.id.id] = role;
this.roleids.set(role.snowflake, role);
this.roles.push(role);
return role;
}
@ -510,7 +513,7 @@ class Guild {
const role = this.roleids[id];
role.permissions.allow = perms.allow;
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",
headers: this.headers,
body: JSON.stringify({

View file

@ -60,12 +60,12 @@ class Localuser {
for (const thing of ready.d.guilds) {
const temp = new Guild(thing, this, members[thing.id]);
this.guilds.push(temp);
this.guildids[temp.id.id] = temp;
this.guildids[temp.id] = temp;
}
{
const temp = new Direct(ready.d.private_channels, this);
this.guilds.push(temp);
this.guildids[temp.id.id] = temp;
this.guildids[temp.id] = temp;
}
console.log(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) {
continue;
}
const guildid = guild.id;
const guildid = guild.snowflake;
this.guildids[guildid.id].channelids[thing.channel_id].readStateInfo(thing);
}
this.typing = [];
@ -193,7 +193,7 @@ class Localuser {
{
const guildy = new Guild(temp.d, this, this.user);
this.guilds.push(guildy);
this.guildids[guildy.id.id] = guildy;
this.guildids[guildy.id] = guildy;
document.getElementById("servers").insertBefore(guildy.generateGuildIcon(), document.getElementById("bottomseparator"));
}
}
@ -251,21 +251,21 @@ class Localuser {
}
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);
}
}
createChannel(JSON) {
JSON.guild_id ??= "@me";
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);
}
}
delChannel(JSON) {
JSON.guild_id ??= "@me";
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);
}
}
@ -466,17 +466,17 @@ class Localuser {
unreads() {
console.log(this.guildhtml);
for (const thing of this.guilds) {
if (thing.id.id === "@me") {
if (thing.id === "@me") {
continue;
}
thing.unreads(this.guildhtml[thing.id.id]);
thing.unreads(this.guildhtml[thing.id]);
}
}
typingStart(typing) {
if (this.channelfocus.id === typing.d.channel_id) {
if (this.channelfocus.snowflake === typing.d.channel_id) {
const memb = typing.d.member;
let name;
if (memb.id === this.user.id) {
if (memb.id === this.user.snowflake) {
console.log("you is typing");
return;
}

View file

@ -72,7 +72,7 @@ class Member {
let id;
if (unkown instanceof User) {
user = unkown;
id = user.id;
id = user.snowflake;
}
else if (typeof unkown === typeof "") {
id = new SnowFlake(unkown, undefined);
@ -80,39 +80,39 @@ class Member {
else {
return new Member(unkown, guild);
}
if (guild.id.id === "@me") {
if (guild.id === "@me") {
return null;
}
if (!Member.already[guild.id.id]) {
Member.already[guild.id.id] = {};
if (!Member.already[guild.id]) {
Member.already[guild.id] = {};
}
else if (Member.already[guild.id.id][id]) {
const memb = Member.already[guild.id.id][id];
else if (Member.already[guild.id][id]) {
const memb = Member.already[guild.id][id];
if (memb instanceof Promise) {
return await 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);
Member.already[guild.id.id][id] = memb;
Member.already[guild.id][id] = memb;
console.log("resolved");
return memb;
});
Member.already[guild.id.id][id] = promoise;
Member.already[guild.id][id] = promoise;
try {
return await promoise;
}
catch (_) {
const memb = new Member(user, guild, true);
Member.already[guild.id.id][id] = memb;
Member.already[guild.id][id] = memb;
return memb;
}
}
hasRole(ID) {
console.log(this.roles, ID);
for (const thing of this.roles) {
if (thing.id.id === ID) {
if (thing.id === ID) {
return true;
}
}
@ -133,7 +133,7 @@ class Member {
return true;
}
}
return this.guild.properties.owner_id === this.user.id.id;
return this.guild.properties.owner_id === this.user.id;
}
bind(html) {
if (html.tagName === "SPAN") {

View file

@ -14,7 +14,7 @@ class Message {
mentions;
mention_roles;
attachments; //probably should be its own class tbh, should be Attachments[]
id;
snowflake;
message_reference;
type;
timestamp;
@ -22,6 +22,9 @@ class Message {
static del;
static resolve;
div;
get id() {
return this.snowflake.id;
}
static setup() {
this.del = new Promise(_ => { this.resolve = _; });
Message.setupcmenu();
@ -71,7 +74,7 @@ class Message {
continue;
}
else if (thing === "id") {
this.id = new SnowFlake(messagejson.id, this);
this.snowflake = new SnowFlake(messagejson.id, this);
continue;
}
this[thing] = messagejson[thing];
@ -95,7 +98,7 @@ class Message {
}
}
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() {
return this.owner;
@ -137,14 +140,14 @@ class Message {
return build;
}
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",
headers: this.headers,
body: JSON.stringify({ content: content })
});
}
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,
method: "DELETE",
});
@ -154,22 +157,22 @@ class Message {
this.div.innerHTML = "";
this.div = null;
}
const prev = this.channel.idToPrev[this.id.id];
const next = this.channel.idToNext[this.id.id];
this.channel.idToNext[prev] = next;
this.channel.idToPrev[next] = prev;
delete this.channel.messageids[this.id.id];
const regen = this.channel.messageids[prev];
const prev = this.channel.idToPrev.get(this.snowflake);
const next = this.channel.idToNext.get(this.snowflake);
this.channel.idToNext.set(prev, next);
this.channel.idToPrev.set(next, prev);
this.channel.messageids.delete(this.snowflake);
const regen = prev.getObject();
if (regen) {
regen.generateMessage();
}
if (this.channel.lastmessage === this) {
this.channel.lastmessage = this.channel.messageids[prev];
this.channel.lastmessage = prev.getObject();
}
}
generateMessage(premessage = null) {
if (!premessage) {
premessage = this.channel.messageids[this.channel.idToNext[this.id.id]];
premessage = this.channel.idToNext.get(this.snowflake)?.getObject();
}
const div = this.div;
if (this === this.channel.replyingto) {
@ -240,7 +243,7 @@ class Message {
const newt = (new Date(this.timestamp).getTime()) / 1000;
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) {
const pfp = this.author.buildpfp();
this.author.bind(pfp);
@ -328,7 +331,7 @@ class Message {
}
buildhtml(premessage, del = Message.del) {
if (this.div) {
console.error(`HTML for ${this.id} already exists, aborting`);
console.error(`HTML for ${this.snowflake} already exists, aborting`);
return;
}
//premessage??=messages.lastChild;

View file

@ -5,7 +5,7 @@ class Role {
permissions;
owner;
color;
id;
snowflake;
name;
info;
hoist;
@ -13,12 +13,15 @@ class Role {
mentionable;
unicode_emoji;
headers;
get id() {
return this.snowflake.id;
}
constructor(JSON, owner) {
this.headers = owner.headers;
this.info = owner.info;
for (const thing of Object.keys(JSON)) {
if (thing === "id") {
this.id = new SnowFlake(JSON.id, this);
this.snowflake = new SnowFlake(JSON.id, this);
continue;
}
this[thing] = JSON[thing];

View file

@ -7,13 +7,16 @@ class User {
static userids = {};
owner;
hypotheticalpfp;
id;
snowflake;
avatar;
username;
bio;
discriminator;
pronouns;
bot;
get id() {
return this.snowflake.id;
}
static contextmenu = new Contextmenu("User Menu");
static setUpContextMenu() {
this.contextmenu.addbutton("Copy user id", function () {
@ -54,7 +57,7 @@ class User {
continue;
}
if (thing === "id") {
this.id = new SnowFlake(userjson[thing], this);
this.snowflake = new SnowFlake(userjson[thing], this);
continue;
}
this[thing] = userjson[thing];
@ -72,7 +75,7 @@ class User {
const pfp = document.createElement('img');
pfp.src = this.getpfpsrc();
pfp.classList.add("pfp");
pfp.classList.add("userid:" + this.id.id);
pfp.classList.add("userid:" + this.id);
return pfp;
}
userupdate(json) {
@ -82,7 +85,7 @@ class User {
}
}
bind(html, guild = null) {
if (guild && guild.id.id !== "@me") {
if (guild && guild.id !== "@me") {
Member.resolve(this, guild).then(_ => {
_.bind(html);
}).catch(_ => {
@ -101,7 +104,7 @@ class User {
this.hypotheticalpfp = false;
const src = this.getpfpsrc();
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;
}
}
@ -110,7 +113,7 @@ class User {
return this.avatar;
}
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 {
return this.info.cdn.toString() + "embed/avatars/3.png";

View file

@ -22,7 +22,7 @@ class Channel{
owner:Guild;
headers:Localuser["headers"];
name:string;
id:SnowFlake<Channel>;
snowflake:SnowFlake<Channel>;
parent_id:SnowFlake<Channel>;
parent:Channel;
children:Channel[];
@ -46,6 +46,9 @@ class Channel{
infinite:InfiniteScroller;
idToPrev:Map<SnowFlake<Message>,SnowFlake<Message>>=new Map();
idToNext:Map<SnowFlake<Message>,SnowFlake<Message>>=new Map();
get id(){
return this.snowflake.id;
}
static setupcontextmenu(){
this.contextmenu.addbutton("Copy channel id",function(){
console.log(this)
@ -81,7 +84,7 @@ class Channel{
}
sortPerms(){
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;
})
}
@ -127,7 +130,7 @@ class Channel{
this.owner=owner;
this.headers=this.owner.headers;
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=null;
this.children=[];
@ -175,8 +178,8 @@ class Channel{
return true;
}
for(const thing of member.roles){
if(this.permission_overwrites.get(thing.id.id)){
let perm=this.permission_overwrites.get(thing.id.id).getPermission(name);
if(this.permission_overwrites.get(thing.id)){
let perm=this.permission_overwrites.get(thing.id).getPermission(name);
if(perm){
return perm===1;
}
@ -208,7 +211,7 @@ class Channel{
let position=-1;
let build=[];
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){
thing.position=thisthing.position=position+1;
}
@ -355,7 +358,7 @@ class Channel{
if(!this.hasunreads){
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",
headers:this.headers,
body:JSON.stringify({})
@ -380,7 +383,7 @@ class Channel{
const that=Channel.dragged[0];
event.preventDefault();
if(container){
that.move_id=this.id;
that.move_id=this.snowflake;
if(that.parent){
that.parent.children.splice(that.parent.children.indexOf(that),1);
}
@ -423,13 +426,13 @@ class Channel{
return div;
}
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",
headers:this.headers,
body:JSON.stringify({
name: name,
type: type,
parent_id: this.id,
parent_id: this.snowflake,
permission_overwrites:[],
})
})
@ -438,7 +441,7 @@ class Channel{
let name=this.name;
let topic=this.topic;
let nsfw=this.nsfw;
const thisid=this.id;
const thisid=this.snowflake;
const thistype=this.type;
const full=new Fullscreen(
["hdiv",
@ -471,7 +474,7 @@ class Channel{
console.log(full)
}
deleteChannel(){
fetch(this.info.api.toString()+"/channels/"+this.id,{
fetch(this.info.api.toString()+"/channels/"+this.snowflake,{
method:"DELETE",
headers:this.headers
})
@ -513,7 +516,7 @@ class Channel{
if(snowflake.getObject()){
return snowflake.getObject();
}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();
return new Message(json[0],this);
}
@ -538,7 +541,7 @@ class Channel{
}
this.makereplybox();
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;
console.log(this);
(document.getElementById("typebox") as HTMLInputElement).contentEditable=""+this.canMessage;
@ -546,7 +549,7 @@ class Channel{
lastmessage:Message;
async putmessages(){
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,
});
@ -558,21 +561,21 @@ class Channel{
for(const thing of response){
const message=new Message(thing,this);
if(prev){
this.idToNext.set(message.id,prev.id);
this.idToPrev.set(prev.id,message.id);
this.idToNext.set(message.snowflake,prev.id);
this.idToPrev.set(prev.id,message.snowflake);
}else{
this.lastmessage=message;
}
prev=message;
if(this.messageids.get(message.id)===undefined){
this.messageids.set(message.id,message);
if(this.messageids.get(message.snowflake)===undefined){
this.messageids.set(message.snowflake,message);
}
}
}
delChannel(JSON){
const build=[];
for(const thing of this.children){
if(thing.id!==JSON.id){
if(thing.snowflake!==JSON.id){
build.push(thing)
}
}
@ -583,7 +586,7 @@ class Channel{
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
}).then((j)=>{return j.json()}).then(response=>{
let next:Message;
@ -604,11 +607,11 @@ class Channel{
next=undefined;
console.log("ohno",+i+1);
}
if(this.messageids.get(messager.id)===undefined){
this.idToNext.set(messager.id,previd);
this.idToPrev.set(previd,messager.id);
previd=messager.id;
this.messageids.set(messager.id,messager);
if(this.messageids.get(messager.snowflake)===undefined){
this.idToNext.set(messager.snowflake,previd);
this.idToPrev.set(previd,messager.snowflake);
previd=messager.snowflake;
this.messageids.set(messager.snowflake,messager);
}else{
console.log("How???")
}
@ -627,8 +630,8 @@ class Channel{
let id:SnowFlake<Message>;
if(this.messageids.get(this.lastreadmessageid)){
id=this.lastreadmessageid;
}else if(this.lastmessage.id){
id=this.goBackIds(this.lastmessage.id,50);
}else if(this.lastmessage.snowflake){
id=this.goBackIds(this.lastmessage.snowflake,50);
console.log("shouldn't")
}
messages.append(this.infinite.getDiv(id.id));
@ -668,7 +671,7 @@ class Channel{
return;
}
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",
headers:this.headers
})
@ -708,7 +711,7 @@ class Channel{
body.message_reference=replyjson;
}
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",
headers:this.headers,
body:JSON.stringify(body)
@ -728,7 +731,7 @@ class Channel{
console.log(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',
body: formData,
headers:{"Authorization":this.headers.Authorization}
@ -738,13 +741,13 @@ class Channel{
messageCreate(messagep:any):void{
if(!this.hasPermission("VIEW_CHANNEL")){return}
const messagez=new Message(messagep.d,this);
console.log(this.lastmessageid,messagez.id,":3");
this.idToNext.set(this.lastmessageid,messagez.id);
this.idToPrev.set(messagez.id,this.lastmessageid);
this.lastmessageid=messagez.id;
this.messageids.set(messagez.id,messagez);
console.log(this.lastmessageid,messagez.snowflake,":3");
this.idToNext.set(this.lastmessageid,messagez.snowflake);
this.idToPrev.set(messagez.snowflake,this.lastmessageid);
this.lastmessageid=messagez.snowflake;
this.messageids.set(messagez.snowflake,messagez);
if(messagez.author===this.localuser.user){
this.lastreadmessageid=messagez.id;
this.lastreadmessageid=messagez.snowflake;
if(this.myhtml){
this.myhtml.classList.remove("cunread");
}
@ -806,25 +809,25 @@ class Channel{
}
}
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",
headers:this.headers,
body:JSON.stringify({
allow:"0",
deny:"0",
id:role.id,
id:role.snowflake,
type:0
})
})
const perm=new Permissions("0","0");
this.permission_overwrites.set(role.id.id,perm);
this.permission_overwritesar.push([role.id,perm]);
this.permission_overwrites.set(role.id,perm);
this.permission_overwritesar.push([role.snowflake,perm]);
}
async updateRolePermissions(id:string,perms:Permissions){
const permission=this.permission_overwrites.get(id);
permission.allow=perms.allow;
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",
headers:this.headers,
body:JSON.stringify({

View file

@ -18,7 +18,7 @@ class Direct extends Guild{
this.headers=this.localuser.headers;
this.channels=[];
this.channelids={};
this.id=new SnowFlake("@me",this);
this.snowflake=new SnowFlake("@me",this);
this.properties={};
this.roles=[];
this.roleids=new Map();
@ -27,7 +27,7 @@ class Direct extends Guild{
for(const thing of JSON){
const temp=new Group(thing,this);
this.channels.push(temp);
this.channelids[temp.id.id]=temp;
this.channelids[temp.id]=temp;
}
this.headchannels=this.channels;
}
@ -75,7 +75,7 @@ class Group extends Channel{
this.user=this.localuser.user;
}
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=null;
this.children=[];
@ -114,17 +114,17 @@ class Group extends Channel{
return;
}
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;
}
messageCreate(messagep){
const messagez=new Message(messagep.d,this);
this.idToNext.set(this.lastmessageid,messagez.id);
this.idToPrev.set(messagez.id,this.lastmessageid);
this.lastmessageid=messagez.id;
this.messageids.set(messagez.id,messagez);
this.idToNext.set(this.lastmessageid,messagez.snowflake);
this.idToPrev.set(messagez.snowflake,this.lastmessageid);
this.lastmessageid=messagez.snowflake;
this.messageids.set(messagez.snowflake,messagez);
if(messagez.author===this.localuser.user){
this.lastreadmessageid=messagez.id;
this.lastreadmessageid=messagez.snowflake;
if(this.myhtml){
this.myhtml.classList.remove("cunread");
}

View file

@ -18,7 +18,7 @@ class Fullscreen{
this.html.classList.add("nonimagecenter");
}
}
tohtml(array){
tohtml(array:any[]){
switch(array[0]){
case "img":
const img=document.createElement("img");

View file

@ -12,7 +12,7 @@ class Guild{
headers:Localuser["headers"];
channels:Channel[];
channelids:{[key:string]:Channel};
id:SnowFlake<Guild>;
snowflake:SnowFlake<Guild>;
properties
roles:Role[];
roleids:Map<SnowFlake<Role>,Role>;
@ -23,6 +23,9 @@ class Guild{
parent_id:string;
member:Member;
html:HTMLElement;
get id(){
return this.snowflake.id;
}
static contextmenu=new Contextmenu("guild menu");
static setupcontextmenu(){
Guild.contextmenu.addbutton("Copy Guild id",function(){
@ -71,7 +74,7 @@ class Guild{
const s1=settings.addButton("roles");
const permlist=[];
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)));
settings.show();
@ -84,7 +87,7 @@ class Guild{
this.headers=this.owner.headers;
this.channels=[];
this.channelids={};
this.id=new SnowFlake(json.id,this);
this.snowflake=new SnowFlake(json.id,this);
this.properties=json.properties;
this.roles=[];
this.roleids=new Map();
@ -93,13 +96,13 @@ class Guild{
for(const roley of json.roles){
const roleh=new Role(roley,this);
this.roles.push(roleh)
this.roleids.set(roleh.id,roleh);
this.roleids.set(roleh.snowflake,roleh);
}
Member.resolve(member,this).then(_=>this.member=_);
for(const thing of json.channels){
const temp=new Channel(thing,this);
this.channels.push(temp);
this.channelids[temp.id.id]=temp;
this.channelids[temp.id]=temp;
}
this.headchannels=[];
for(const thing of this.channels){
@ -129,7 +132,7 @@ class Guild{
headers:this.headers,
body:JSON.stringify({
"guilds":{
[this.id.id]:{
[this.id]:{
"message_notifications": noti
}
}
@ -169,7 +172,7 @@ class Guild{
full.show();
}
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",
headers:this.headers
})
@ -188,7 +191,7 @@ class Guild{
let position=-1;
let build=[];
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){
thing.position=(thisthing.position=position+1);
}
@ -217,14 +220,14 @@ class Guild{
if(serverbug){
for(const thing of build){
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",
headers:this.headers,
body:JSON.stringify([thing])
});
}
}else{
fetch(this.info.api.toString()+"/v9/guilds/"+this.id+"/channels",{
fetch(this.info.api.toString()+"/v9/guilds/"+this.snowflake+"/channels",{
method:"PATCH",
headers:this.headers,
body:JSON.stringify(build)
@ -248,7 +251,7 @@ class Guild{
const noti=document.createElement("div");
noti.classList.add("unread");
divy.append(noti);
this.localuser.guildhtml[this.id.id]=divy;
this.localuser.guildhtml.set(this.id,divy);
if(this.properties.icon!=null){
const img=document.createElement("img");
img.classList.add("pfp","servericon");
@ -319,7 +322,7 @@ class Guild{
full.show();
}
async delete(){
return fetch(this.info.api.toString()+"/guilds/"+this.id+"/delete",{
return fetch(this.info.api.toString()+"/guilds/"+this.snowflake+"/delete",{
method:"POST",
headers:this.headers,
})
@ -362,7 +365,7 @@ class Guild{
const build={read_states:[]};
for(const thing of this.channels){
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.myhtml.classList.remove("cunread");
}
@ -377,7 +380,7 @@ class Guild{
hasRole(r:Role|string){
console.log("this should run");
if(r instanceof Role){
r=r.id.id;
r=r.id;
}
return this.member.hasRole(r);
}
@ -399,7 +402,7 @@ class Guild{
}
}
loadGuild(){
this.localuser.loadGuild(this.id.id);
this.localuser.loadGuild(this.id);
}
updateChannel(JSON){
SnowFlake.getSnowFlakeFromID(JSON.id,Channel).getObject().updateChannel(JSON);
@ -495,14 +498,14 @@ class Guild{
this.printServers();
}
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",
headers:this.headers,
body:JSON.stringify({name: name, type: type})
})
}
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",
headers:this.headers,
body:JSON.stringify({
@ -513,7 +516,7 @@ class Guild{
})
const json=await fetched.json();
const role=new Role(json,this);
this.roleids[role.id.id]=role;
this.roleids.set(role.snowflake,role);
this.roles.push(role);
return role;
}
@ -522,7 +525,7 @@ class Guild{
role.permissions.allow=perms.allow;
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",
headers:this.headers,
body:JSON.stringify({

View file

@ -3,8 +3,6 @@ import {Channel} from "./channel.js";
import {Direct} from "./direct.js";
import {Voice} from "./audio.js";
import {User} from "./user.js";
import {Member} from "./member.js";
import {MarkDown} from "./markdown.js";
import {Fullscreen} from "./fullscreen.js";
import {setTheme, Specialuser} from "./login.js";
import { SnowFlake } from "./snowflake.js";
@ -66,12 +64,12 @@ class Localuser{
for(const thing of ready.d.guilds){
const temp=new Guild(thing,this,members[thing.id]);
this.guilds.push(temp);
this.guildids[temp.id.id]=temp;
this.guildids[temp.id]=temp;
}
{
const temp=new Direct(ready.d.private_channels,this);
this.guilds.push(temp);
this.guildids[temp.id.id]=temp;
this.guildids[temp.id]=temp;
}
console.log(ready.d.user_guild_settings.entries);
@ -87,7 +85,7 @@ class Localuser{
if(guild===undefined){
continue
}
const guildid=guild.id;
const guildid=guild.snowflake;
this.guildids[guildid.id].channelids[thing.channel_id].readStateInfo(thing);
}
this.typing=[];
@ -204,7 +202,7 @@ class Localuser{
{
const guildy=new Guild(temp.d,this,this.user);
this.guilds.push(guildy);
this.guildids[guildy.id.id]=guildy;
this.guildids[guildy.id]=guildy;
document.getElementById("servers").insertBefore(guildy.generateGuildIcon(),document.getElementById("bottomseparator"));
}
}
@ -265,14 +263,14 @@ class Localuser{
}
updateChannel(JSON):void{
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);
}
}
createChannel(JSON):void{
JSON.guild_id??="@me";
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);
}
}
@ -280,7 +278,7 @@ class Localuser{
JSON.guild_id??="@me";
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);
}
}
@ -497,15 +495,15 @@ class Localuser{
unreads():void{
console.log(this.guildhtml)
for(const thing of this.guilds){
if(thing.id.id==="@me"){continue;}
thing.unreads(this.guildhtml[thing.id.id]);
if(thing.id==="@me"){continue;}
thing.unreads(this.guildhtml[thing.id]);
}
}
typingStart(typing):void{
if(this.channelfocus.id===typing.d.channel_id){
if(this.channelfocus.snowflake===typing.d.channel_id){
const memb=typing.d.member;
let name;
if(memb.id===this.user.id){
if(memb.id===this.user.snowflake){
console.log("you is typing")
return;
}

View file

@ -69,42 +69,42 @@ class Member{
let id:SnowFlake<User>;
if(unkown instanceof User){
user=unkown as User;
id=user.id;
id=user.snowflake;
}else if(typeof unkown===typeof ""){
id=new SnowFlake(unkown as string,undefined);
}else{
return new Member(unkown,guild);
}
if(guild.id.id==="@me"){return null}
if(!Member.already[guild.id.id]){
Member.already[guild.id.id]={};
}else if(Member.already[guild.id.id][id]){
const memb=Member.already[guild.id.id][id]
if(guild.id==="@me"){return null}
if(!Member.already[guild.id]){
Member.already[guild.id]={};
}else if(Member.already[guild.id][id]){
const memb=Member.already[guild.id][id]
if(memb instanceof Promise){
return await 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);
Member.already[guild.id.id][id]=memb;
Member.already[guild.id][id]=memb;
console.log("resolved")
return memb
})
Member.already[guild.id.id][id]=promoise;
Member.already[guild.id][id]=promoise;
try{
return await promoise
}catch(_){
const memb=new Member(user,guild,true);
Member.already[guild.id.id][id]=memb;
Member.already[guild.id][id]=memb;
return memb;
}
}
hasRole(ID:string){
console.log(this.roles,ID);
for(const thing of this.roles){
if(thing.id.id===ID){
if(thing.id===ID){
return true;
}
}
@ -125,7 +125,7 @@ class Member{
return true;
}
}
return this.guild.properties.owner_id===this.user.id.id;
return this.guild.properties.owner_id===this.user.id;
}
bind(html:HTMLElement){
if(html.tagName==="SPAN"){

View file

@ -18,7 +18,7 @@ class Message{
mentions:User[];
mention_roles:Role[];
attachments:File[];//probably should be its own class tbh, should be Attachments[]
id:SnowFlake<Message>;
snowflake:SnowFlake<Message>;
message_reference;
type:number;
timestamp:number;
@ -26,6 +26,9 @@ class Message{
static del:Promise<void>;
static resolve:Function;
div:HTMLDivElement;
get id(){
return this.snowflake.id;
}
static setup(){
this.del=new Promise(_=>{this.resolve=_});
Message.setupcmenu();
@ -74,7 +77,7 @@ class Message{
this.content=new MarkDown(messagejson[thing],this.channel);
continue;
}else if(thing ==="id"){
this.id=new SnowFlake(messagejson.id,this);
this.snowflake=new SnowFlake(messagejson.id,this);
continue;
}
this[thing]=messagejson[thing];
@ -98,7 +101,7 @@ class Message{
}
}
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(){
return this.owner;
@ -139,14 +142,14 @@ class Message{
return build;
}
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",
headers: this.headers,
body:JSON.stringify({content:content})
});
}
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,
method:"DELETE",
})
@ -156,22 +159,22 @@ class Message{
this.div.innerHTML="";
this.div=null;
}
const prev=this.channel.idToPrev[this.id.id];
const next=this.channel.idToNext[this.id.id];
this.channel.idToNext[prev]=next;
this.channel.idToPrev[next]=prev;
delete this.channel.messageids[this.id.id];
const regen=this.channel.messageids[prev]
const prev=this.channel.idToPrev.get(this.snowflake);
const next=this.channel.idToNext.get(this.snowflake);
this.channel.idToNext.set(prev,next);
this.channel.idToPrev.set(next,prev);
this.channel.messageids.delete(this.snowflake);
const regen=prev.getObject();
if(regen){
regen.generateMessage();
}
if(this.channel.lastmessage===this){
this.channel.lastmessage=this.channel.messageids[prev];
this.channel.lastmessage=prev.getObject();
}
}
generateMessage(premessage:Message=null){
if(!premessage){
premessage=this.channel.messageids[this.channel.idToNext[this.id.id]];
premessage=this.channel.idToNext.get(this.snowflake)?.getObject();
}
const div=this.div;
if(this===this.channel.replyingto){
@ -244,7 +247,7 @@ class Message{
const newt=(new Date(this.timestamp).getTime())/1000;
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){
const pfp=this.author.buildpfp();
this.author.bind(pfp);
@ -333,7 +336,7 @@ class Message{
return(div)
}
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;
const div=document.createElement("div");
this.div=div;

View file

@ -7,7 +7,7 @@ class Role{
permissions:Permissions;
owner:Guild;
color:number;
readonly id:SnowFlake<Role>;
readonly snowflake:SnowFlake<Role>;
name:string;
info:Guild["info"];
hoist:boolean;
@ -15,12 +15,15 @@ class Role{
mentionable:boolean;
unicode_emoji:string;
headers:Guild["headers"];
get id(){
return this.snowflake.id;
}
constructor(JSON, owner:Guild){
this.headers=owner.headers;
this.info=owner.info;
for(const thing of Object.keys(JSON)){
if(thing==="id"){
this.id=new SnowFlake(JSON.id,this);
this.snowflake=new SnowFlake(JSON.id,this);
continue;
}
this[thing]=JSON[thing];

View file

@ -10,13 +10,16 @@ class User{
static userids={};
owner:Localuser;
hypotheticalpfp:boolean;
id:SnowFlake<User>;
snowflake:SnowFlake<User>;
avatar:string;
username:string;
bio:MarkDown;
discriminator:string;
pronouns:string;
bot:boolean;
get id(){
return this.snowflake.id;
}
static contextmenu:Contextmenu=new Contextmenu("User Menu");
static setUpContextMenu(){
this.contextmenu.addbutton("Copy user id",function(){
@ -55,7 +58,7 @@ class User{
continue;
}
if(thing === "id"){
this.id=new SnowFlake(userjson[thing],this);
this.snowflake=new SnowFlake(userjson[thing],this);
continue;
}
this[thing]=userjson[thing];
@ -72,7 +75,7 @@ class User{
const pfp=document.createElement('img');
pfp.src=this.getpfpsrc();
pfp.classList.add("pfp");
pfp.classList.add("userid:"+this.id.id);
pfp.classList.add("userid:"+this.id);
return pfp;
}
userupdate(json){
@ -82,7 +85,7 @@ class User{
}
}
bind(html:HTMLElement,guild:Guild=null){
if(guild&&guild.id.id!=="@me"){
if(guild&&guild.id!=="@me"){
Member.resolve(this,guild).then(_=>{
_.bind(html);
}).catch(_=>{
@ -103,7 +106,7 @@ class User{
this.hypotheticalpfp=false;
const src=this.getpfpsrc();
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;
}
}
@ -112,7 +115,7 @@ class User{
return this.avatar;
}
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{
return this.info.cdn.toString()+"embed/avatars/3.png";
}