remove snowflake instances
This commit is contained in:
parent
004beb4955
commit
e66b6c0883
16 changed files with 97 additions and 149 deletions
|
@ -9,13 +9,12 @@ import { RoleList } from "./role.js";
|
||||||
import { InfiniteScroller } from "./infiniteScroller.js";
|
import { InfiniteScroller } from "./infiniteScroller.js";
|
||||||
import { SnowFlake } from "./snowflake.js";
|
import { SnowFlake } from "./snowflake.js";
|
||||||
import { MarkDown } from "./markdown.js";
|
import { MarkDown } from "./markdown.js";
|
||||||
class Channel {
|
class Channel extends SnowFlake {
|
||||||
editing;
|
editing;
|
||||||
type;
|
type;
|
||||||
owner;
|
owner;
|
||||||
headers;
|
headers;
|
||||||
name;
|
name;
|
||||||
snowflake;
|
|
||||||
parent_id;
|
parent_id;
|
||||||
parent;
|
parent;
|
||||||
children;
|
children;
|
||||||
|
@ -39,9 +38,6 @@ class Channel {
|
||||||
idToPrev = new Map();
|
idToPrev = new Map();
|
||||||
idToNext = new Map();
|
idToNext = new Map();
|
||||||
messages = new Map();
|
messages = 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);
|
||||||
|
@ -155,23 +151,22 @@ class Channel {
|
||||||
}
|
}
|
||||||
setUpInfiniteScroller() {
|
setUpInfiniteScroller() {
|
||||||
this.infinite = new InfiniteScroller((async (id, offset) => {
|
this.infinite = new InfiniteScroller((async (id, offset) => {
|
||||||
const snowflake = id;
|
|
||||||
if (offset === 1) {
|
if (offset === 1) {
|
||||||
if (this.idToPrev.has(snowflake)) {
|
if (this.idToPrev.has(id)) {
|
||||||
return this.idToPrev.get(snowflake);
|
return this.idToPrev.get(id);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
await this.grabBefore(id);
|
await this.grabBefore(id);
|
||||||
return this.idToPrev.get(snowflake);
|
return this.idToPrev.get(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (this.idToNext.has(snowflake)) {
|
if (this.idToNext.has(id)) {
|
||||||
return this.idToNext.get(snowflake);
|
return this.idToNext.get(id);
|
||||||
}
|
}
|
||||||
else if (this.lastmessage?.id !== id) {
|
else if (this.lastmessage?.id !== id) {
|
||||||
await this.grabAfter(id);
|
await this.grabAfter(id);
|
||||||
return this.idToNext.get(snowflake);
|
return this.idToNext.get(id);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
console.log("at bottom");
|
console.log("at bottom");
|
||||||
|
@ -207,7 +202,8 @@ class Channel {
|
||||||
return false;
|
return false;
|
||||||
}), this.readbottom.bind(this));
|
}), this.readbottom.bind(this));
|
||||||
}
|
}
|
||||||
constructor(json, owner) {
|
constructor(json, owner, id = json === -1 ? undefined : json.id) {
|
||||||
|
super(id);
|
||||||
if (json === -1) {
|
if (json === -1) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -216,7 +212,6 @@ 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.snowflake = new SnowFlake(json.id);
|
|
||||||
if (json.parent_id) {
|
if (json.parent_id) {
|
||||||
this.parent_id = json.parent_id;
|
this.parent_id = json.parent_id;
|
||||||
}
|
}
|
||||||
|
@ -491,7 +486,7 @@ class Channel {
|
||||||
if (!this.hasunreads) {
|
if (!this.hasunreads) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fetch(this.info.api + "/channels/" + this.snowflake + "/messages/" + this.lastmessageid + "/ack", {
|
fetch(this.info.api + "/channels/" + this.id + "/messages/" + this.lastmessageid + "/ack", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
body: JSON.stringify({})
|
body: JSON.stringify({})
|
||||||
|
@ -578,7 +573,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.snowflake;
|
const thisid = this.id;
|
||||||
const thistype = this.type;
|
const thistype = this.type;
|
||||||
const full = new Dialog(["hdiv",
|
const full = new Dialog(["hdiv",
|
||||||
["vdiv",
|
["vdiv",
|
||||||
|
@ -614,7 +609,7 @@ class Channel {
|
||||||
console.log(full);
|
console.log(full);
|
||||||
}
|
}
|
||||||
deleteChannel() {
|
deleteChannel() {
|
||||||
fetch(this.info.api + "/channels/" + this.snowflake, {
|
fetch(this.info.api + "/channels/" + this.id, {
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
headers: this.headers
|
headers: this.headers
|
||||||
});
|
});
|
||||||
|
@ -661,7 +656,7 @@ class Channel {
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const gety = await fetch(this.info.api + "/channels/" + this.snowflake + "/messages?limit=1&around=" + id, { headers: this.headers });
|
const gety = await fetch(this.info.api + "/channels/" + this.id + "/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);
|
||||||
}
|
}
|
||||||
|
@ -684,7 +679,7 @@ class Channel {
|
||||||
this.guild.prevchannel = this;
|
this.guild.prevchannel = this;
|
||||||
this.localuser.channelfocus = this;
|
this.localuser.channelfocus = this;
|
||||||
const prom = this.infinite.delete();
|
const prom = this.infinite.delete();
|
||||||
history.pushState(null, "", "/channels/" + this.guild_id + "/" + this.snowflake);
|
history.pushState(null, "", "/channels/" + this.guild_id + "/" + this.id);
|
||||||
this.localuser.pageTitle("#" + this.name);
|
this.localuser.pageTitle("#" + this.name);
|
||||||
const channelTopic = document.getElementById("channelTopic");
|
const channelTopic = document.getElementById("channelTopic");
|
||||||
if (this.topic) {
|
if (this.topic) {
|
||||||
|
@ -737,7 +732,7 @@ class Channel {
|
||||||
if (this.lastreadmessageid && this.messages.has(this.lastreadmessageid)) {
|
if (this.lastreadmessageid && this.messages.has(this.lastreadmessageid)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const j = await fetch(this.info.api + "/channels/" + this.snowflake + "/messages?limit=100", {
|
const j = await fetch(this.info.api + "/channels/" + this.id + "/messages?limit=100", {
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
});
|
});
|
||||||
const response = await j.json();
|
const response = await j.json();
|
||||||
|
@ -846,11 +841,6 @@ class Channel {
|
||||||
throw new Error("please don't call this, no one has implemented it :P");
|
throw new Error("please don't call this, no one has implemented it :P");
|
||||||
}
|
}
|
||||||
async buildmessages() {
|
async buildmessages() {
|
||||||
/*
|
|
||||||
if(((!this.lastmessage)||(!this.lastmessage.snowflake)||(!this.goBackIds(this.lastmessage.snowflake,50,false)))&&this.lastreadmessageid){
|
|
||||||
await this.grabAfter(this.lastreadmessageid.id);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
this.infinitefocus = false;
|
this.infinitefocus = false;
|
||||||
this.tryfocusinfinate();
|
this.tryfocusinfinate();
|
||||||
}
|
}
|
||||||
|
@ -968,7 +958,7 @@ class Channel {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.typing = Date.now() + 6000;
|
this.typing = Date.now() + 6000;
|
||||||
fetch(this.info.api + "/channels/" + this.snowflake + "/typing", {
|
fetch(this.info.api + "/channels/" + this.id + "/typing", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: this.headers
|
headers: this.headers
|
||||||
});
|
});
|
||||||
|
@ -1009,7 +999,7 @@ class Channel {
|
||||||
if (replyjson) {
|
if (replyjson) {
|
||||||
body.message_reference = replyjson;
|
body.message_reference = replyjson;
|
||||||
}
|
}
|
||||||
return await fetch(this.info.api + "/channels/" + this.snowflake + "/messages", {
|
return await fetch(this.info.api + "/channels/" + this.id + "/messages", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
body: JSON.stringify(body)
|
body: JSON.stringify(body)
|
||||||
|
@ -1029,7 +1019,7 @@ class Channel {
|
||||||
for (const i in attachments) {
|
for (const i in attachments) {
|
||||||
formData.append("files[" + i + "]", attachments[i]);
|
formData.append("files[" + i + "]", attachments[i]);
|
||||||
}
|
}
|
||||||
return await fetch(this.info.api + "/channels/" + this.snowflake + "/messages", {
|
return await fetch(this.info.api + "/channels/" + this.id + "/messages", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: formData,
|
body: formData,
|
||||||
headers: { Authorization: this.headers.Authorization }
|
headers: { Authorization: this.headers.Authorization }
|
||||||
|
@ -1121,7 +1111,7 @@ class Channel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async addRoleToPerms(role) {
|
async addRoleToPerms(role) {
|
||||||
await fetch(this.info.api + "/channels/" + this.snowflake + "/permissions/" + role.snowflake, {
|
await fetch(this.info.api + "/channels/" + this.id + "/permissions/" + role.id, {
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
|
@ -1140,7 +1130,7 @@ class Channel {
|
||||||
if (permission) {
|
if (permission) {
|
||||||
permission.allow = perms.allow;
|
permission.allow = perms.allow;
|
||||||
permission.deny = perms.deny;
|
permission.deny = perms.deny;
|
||||||
await fetch(this.info.api + "/channels/" + this.snowflake + "/permissions/" + id, {
|
await fetch(this.info.api + "/channels/" + this.id + "/permissions/" + id, {
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
|
|
|
@ -2,7 +2,6 @@ import { Guild } from "./guild.js";
|
||||||
import { Channel } from "./channel.js";
|
import { Channel } from "./channel.js";
|
||||||
import { Message } from "./message.js";
|
import { Message } from "./message.js";
|
||||||
import { User } from "./user.js";
|
import { User } from "./user.js";
|
||||||
import { SnowFlake } from "./snowflake.js";
|
|
||||||
import { Permissions } from "./permissions.js";
|
import { Permissions } from "./permissions.js";
|
||||||
class Direct extends Guild {
|
class Direct extends Guild {
|
||||||
constructor(json, owner) {
|
constructor(json, owner) {
|
||||||
|
@ -15,7 +14,6 @@ class Direct extends Guild {
|
||||||
this.headers = this.localuser.headers;
|
this.headers = this.localuser.headers;
|
||||||
this.channels = [];
|
this.channels = [];
|
||||||
this.channelids = {};
|
this.channelids = {};
|
||||||
this.snowflake = new SnowFlake("@me");
|
|
||||||
this.properties = {};
|
this.properties = {};
|
||||||
this.roles = [];
|
this.roles = [];
|
||||||
this.roleids = new Map();
|
this.roleids = new Map();
|
||||||
|
@ -77,7 +75,7 @@ dmPermissions.setPermission("USE_VAD", 1);
|
||||||
class Group extends Channel {
|
class Group extends Channel {
|
||||||
user;
|
user;
|
||||||
constructor(json, owner) {
|
constructor(json, owner) {
|
||||||
super(-1, owner);
|
super(-1, owner, json.id);
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
this.headers = this.guild.headers;
|
this.headers = this.guild.headers;
|
||||||
this.name = json.recipients[0]?.username;
|
this.name = json.recipients[0]?.username;
|
||||||
|
@ -88,7 +86,6 @@ 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.snowflake = new SnowFlake(json.id);
|
|
||||||
this.parent_id = null;
|
this.parent_id = null;
|
||||||
this.parent = null;
|
this.parent = null;
|
||||||
this.children = [];
|
this.children = [];
|
||||||
|
@ -100,7 +97,7 @@ class Group extends Channel {
|
||||||
if (this.lastmessageid) {
|
if (this.lastmessageid) {
|
||||||
this.position = Number((BigInt(this.lastmessageid) >> 22n) + 1420070400000n);
|
this.position = Number((BigInt(this.lastmessageid) >> 22n) + 1420070400000n);
|
||||||
}
|
}
|
||||||
this.position = -Math.max(this.position, this.snowflake.getUnixTime());
|
this.position = -Math.max(this.position, this.getUnixTime());
|
||||||
}
|
}
|
||||||
createguildHTML() {
|
createguildHTML() {
|
||||||
const div = document.createElement("div");
|
const div = document.createElement("div");
|
||||||
|
|
|
@ -6,12 +6,11 @@ import { Member } from "./member.js";
|
||||||
import { Settings } from "./settings.js";
|
import { Settings } from "./settings.js";
|
||||||
import { SnowFlake } from "./snowflake.js";
|
import { SnowFlake } from "./snowflake.js";
|
||||||
import { User } from "./user.js";
|
import { User } from "./user.js";
|
||||||
class Guild {
|
class Guild extends SnowFlake {
|
||||||
owner;
|
owner;
|
||||||
headers;
|
headers;
|
||||||
channels;
|
channels;
|
||||||
channelids;
|
channelids;
|
||||||
snowflake;
|
|
||||||
properties;
|
properties;
|
||||||
roles;
|
roles;
|
||||||
roleids;
|
roleids;
|
||||||
|
@ -23,9 +22,6 @@ class Guild {
|
||||||
member;
|
member;
|
||||||
html;
|
html;
|
||||||
emojis;
|
emojis;
|
||||||
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 () {
|
||||||
|
@ -78,18 +74,19 @@ class Guild {
|
||||||
settings.show();
|
settings.show();
|
||||||
}
|
}
|
||||||
constructor(json, owner, member) {
|
constructor(json, owner, member) {
|
||||||
if (json === -1 || member === null) {
|
if (json === -1) {
|
||||||
|
super("@me");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (json.stickers.length) {
|
if (json.stickers.length) {
|
||||||
console.log(json.stickers, ":3");
|
console.log(json.stickers, ":3");
|
||||||
}
|
}
|
||||||
|
super(json.id);
|
||||||
this.emojis = json.emojis;
|
this.emojis = json.emojis;
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
this.headers = this.owner.headers;
|
this.headers = this.owner.headers;
|
||||||
this.channels = [];
|
this.channels = [];
|
||||||
this.channelids = {};
|
this.channelids = {};
|
||||||
this.snowflake = new SnowFlake(json.id);
|
|
||||||
this.properties = json.properties;
|
this.properties = json.properties;
|
||||||
this.roles = [];
|
this.roles = [];
|
||||||
this.roleids = new Map();
|
this.roleids = new Map();
|
||||||
|
@ -192,7 +189,7 @@ class Guild {
|
||||||
full.show();
|
full.show();
|
||||||
}
|
}
|
||||||
async leave() {
|
async leave() {
|
||||||
return fetch(this.info.api + "/users/@me/guilds/" + this.snowflake, {
|
return fetch(this.info.api + "/users/@me/guilds/" + this.id, {
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
headers: this.headers
|
headers: this.headers
|
||||||
});
|
});
|
||||||
|
@ -340,7 +337,7 @@ class Guild {
|
||||||
full.show();
|
full.show();
|
||||||
}
|
}
|
||||||
async delete() {
|
async delete() {
|
||||||
return fetch(this.info.api + "/guilds/" + this.snowflake + "/delete", {
|
return fetch(this.info.api + "/guilds/" + this.id + "/delete", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
});
|
});
|
||||||
|
@ -528,7 +525,7 @@ class Guild {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
async createRole(name) {
|
async createRole(name) {
|
||||||
const fetched = await fetch(this.info.api + "/guilds/" + this.snowflake + "roles", {
|
const fetched = await fetch(this.info.api + "/guilds/" + this.id + "roles", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
|
@ -547,7 +544,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 + "/guilds/" + this.snowflake + "/roles/" + this.snowflake, {
|
await fetch(this.info.api + "/guilds/" + this.id + "/roles/" + role.id, {
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
|
|
|
@ -95,8 +95,7 @@ class Localuser {
|
||||||
if (guild === undefined) {
|
if (guild === undefined) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const guildid = guild.snowflake;
|
guild.channelids[thing.channel_id].readStateInfo(thing);
|
||||||
this.guildids.get(guildid.id).channelids[thing.channel_id].readStateInfo(thing);
|
|
||||||
}
|
}
|
||||||
for (const thing of ready.d.relationships) {
|
for (const thing of ready.d.relationships) {
|
||||||
const user = new User(thing.user, this);
|
const user = new User(thing.user, this);
|
||||||
|
|
|
@ -6,7 +6,7 @@ import { Embed } from "./embed.js";
|
||||||
import { File } from "./file.js";
|
import { File } from "./file.js";
|
||||||
import { SnowFlake } from "./snowflake.js";
|
import { SnowFlake } from "./snowflake.js";
|
||||||
import { Emoji } from "./emoji.js";
|
import { Emoji } from "./emoji.js";
|
||||||
class Message {
|
class Message extends SnowFlake {
|
||||||
static contextmenu = new Contextmenu("message menu");
|
static contextmenu = new Contextmenu("message menu");
|
||||||
owner;
|
owner;
|
||||||
headers;
|
headers;
|
||||||
|
@ -15,7 +15,6 @@ 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[]
|
||||||
snowflake;
|
|
||||||
message_reference;
|
message_reference;
|
||||||
type;
|
type;
|
||||||
timestamp;
|
timestamp;
|
||||||
|
@ -38,9 +37,6 @@ class Message {
|
||||||
div;
|
div;
|
||||||
member;
|
member;
|
||||||
reactions;
|
reactions;
|
||||||
get id() {
|
|
||||||
return this.snowflake.id;
|
|
||||||
}
|
|
||||||
static setup() {
|
static setup() {
|
||||||
this.del = new Promise(_ => {
|
this.del = new Promise(_ => {
|
||||||
this.resolve = _;
|
this.resolve = _;
|
||||||
|
@ -77,6 +73,7 @@ class Message {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
constructor(messagejson, owner) {
|
constructor(messagejson, owner) {
|
||||||
|
super(messagejson.id);
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
this.headers = this.owner.headers;
|
this.headers = this.owner.headers;
|
||||||
this.giveData(messagejson);
|
this.giveData(messagejson);
|
||||||
|
@ -117,7 +114,6 @@ class Message {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else if (thing === "id") {
|
else if (thing === "id") {
|
||||||
this.snowflake = new SnowFlake(messagejson.id);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else if (thing === "member") {
|
else if (thing === "member") {
|
||||||
|
@ -160,7 +156,7 @@ class Message {
|
||||||
func();
|
func();
|
||||||
}
|
}
|
||||||
canDelete() {
|
canDelete() {
|
||||||
return this.channel.hasPermission("MANAGE_MESSAGES") || this.author.snowflake === this.localuser.user.snowflake;
|
return this.channel.hasPermission("MANAGE_MESSAGES") || this.author === this.localuser.user;
|
||||||
}
|
}
|
||||||
get channel() {
|
get channel() {
|
||||||
return this.owner;
|
return this.owner;
|
||||||
|
@ -208,14 +204,14 @@ class Message {
|
||||||
return build;
|
return build;
|
||||||
}
|
}
|
||||||
async edit(content) {
|
async edit(content) {
|
||||||
return await fetch(this.info.api + "/channels/" + this.channel.snowflake + "/messages/" + this.id, {
|
return await fetch(this.info.api + "/channels/" + this.channel.id + "/messages/" + this.id, {
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
body: JSON.stringify({ content })
|
body: JSON.stringify({ content })
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
delete() {
|
delete() {
|
||||||
fetch(`${this.info.api}/channels/${this.channel.snowflake}/messages/${this.id}`, {
|
fetch(`${this.info.api}/channels/${this.channel.id}/messages/${this.id}`, {
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
});
|
});
|
||||||
|
@ -387,7 +383,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?.snowflake != this.author.snowflake) || (current) || this.message_reference;
|
const combine = (premessage?.author != this.author) || (current) || this.message_reference;
|
||||||
if (combine) {
|
if (combine) {
|
||||||
const pfp = this.author.buildpfp();
|
const pfp = this.author.buildpfp();
|
||||||
this.author.bind(pfp, this.guild, false);
|
this.author.bind(pfp, this.guild, false);
|
||||||
|
@ -574,7 +570,7 @@ class Message {
|
||||||
}
|
}
|
||||||
buildhtml(premessage) {
|
buildhtml(premessage) {
|
||||||
if (this.div) {
|
if (this.div) {
|
||||||
console.error(`HTML for ${this.snowflake} already exists, aborting`);
|
console.error(`HTML for ${this.id} already exists, aborting`);
|
||||||
return this.div;
|
return this.div;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
import { Permissions } from "./permissions.js";
|
import { Permissions } from "./permissions.js";
|
||||||
import { SnowFlake } from "./snowflake.js";
|
import { SnowFlake } from "./snowflake.js";
|
||||||
class Role {
|
class Role extends SnowFlake {
|
||||||
permissions;
|
permissions;
|
||||||
owner;
|
owner;
|
||||||
color;
|
color;
|
||||||
snowflake;
|
|
||||||
name;
|
name;
|
||||||
info;
|
info;
|
||||||
hoist;
|
hoist;
|
||||||
|
@ -12,15 +11,12 @@ class Role {
|
||||||
mentionable;
|
mentionable;
|
||||||
unicode_emoji;
|
unicode_emoji;
|
||||||
headers;
|
headers;
|
||||||
get id() {
|
|
||||||
return this.snowflake.id;
|
|
||||||
}
|
|
||||||
constructor(json, owner) {
|
constructor(json, owner) {
|
||||||
|
super(json.id);
|
||||||
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.snowflake = new SnowFlake(json.id);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
this[thing] = json[thing];
|
this[thing] = json[thing];
|
||||||
|
|
|
@ -4,11 +4,14 @@ class SnowFlake {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
getUnixTime() {
|
getUnixTime() {
|
||||||
|
return SnowFlake.stringToUnixTime(this.id);
|
||||||
|
}
|
||||||
|
static stringToUnixTime(str) {
|
||||||
try {
|
try {
|
||||||
return Number((BigInt(this.id) >> 22n) + 1420070400000n);
|
return Number((BigInt(str) >> 22n) + 1420070400000n);
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
console.error(`The ID is corrupted, it's ${this.id} when it should be some number.`);
|
console.error(`The ID is corrupted, it's ${str} when it should be some number.`);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,10 +3,9 @@ import { Member } from "./member.js";
|
||||||
import { MarkDown } from "./markdown.js";
|
import { MarkDown } from "./markdown.js";
|
||||||
import { Contextmenu } from "./contextmenu.js";
|
import { Contextmenu } from "./contextmenu.js";
|
||||||
import { SnowFlake } from "./snowflake.js";
|
import { SnowFlake } from "./snowflake.js";
|
||||||
class User {
|
class User extends SnowFlake {
|
||||||
owner;
|
owner;
|
||||||
hypotheticalpfp;
|
hypotheticalpfp;
|
||||||
snowflake;
|
|
||||||
avatar;
|
avatar;
|
||||||
username;
|
username;
|
||||||
nickname = null;
|
nickname = null;
|
||||||
|
@ -62,9 +61,6 @@ class User {
|
||||||
return "offline";
|
return "offline";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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 () {
|
||||||
|
@ -141,6 +137,7 @@ class User {
|
||||||
return this.owner;
|
return this.owner;
|
||||||
}
|
}
|
||||||
constructor(userjson, owner, dontclone = false) {
|
constructor(userjson, owner, dontclone = false) {
|
||||||
|
super(userjson.id);
|
||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
if (!owner) {
|
if (!owner) {
|
||||||
console.error("missing localuser");
|
console.error("missing localuser");
|
||||||
|
@ -152,7 +149,6 @@ class User {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (thing === "id") {
|
if (thing === "id") {
|
||||||
this.snowflake = new SnowFlake(userjson[thing]);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
this[thing] = userjson[thing];
|
this[thing] = userjson[thing];
|
||||||
|
|
|
@ -18,13 +18,12 @@ declare global {
|
||||||
image?: string|null|undefined
|
image?: string|null|undefined
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
class Channel{
|
class Channel extends SnowFlake{
|
||||||
editing:Message|null;
|
editing:Message|null;
|
||||||
type:number;
|
type:number;
|
||||||
owner:Guild;
|
owner:Guild;
|
||||||
headers:Localuser["headers"];
|
headers:Localuser["headers"];
|
||||||
name:string;
|
name:string;
|
||||||
snowflake:SnowFlake;
|
|
||||||
parent_id?:string;
|
parent_id?:string;
|
||||||
parent:Channel|null;
|
parent:Channel|null;
|
||||||
children:Channel[];
|
children:Channel[];
|
||||||
|
@ -48,9 +47,6 @@ class Channel{
|
||||||
idToPrev:Map<string,string>=new Map();
|
idToPrev:Map<string,string>=new Map();
|
||||||
idToNext:Map<string,string>=new Map();
|
idToNext:Map<string,string>=new Map();
|
||||||
messages:Map<string,Message>=new Map();
|
messages:Map<string,Message>=new Map();
|
||||||
get id(){
|
|
||||||
return this.snowflake.id;
|
|
||||||
}
|
|
||||||
static setupcontextmenu(){
|
static setupcontextmenu(){
|
||||||
this.contextmenu.addbutton("Copy channel id",function(this:Channel){
|
this.contextmenu.addbutton("Copy channel id",function(this:Channel){
|
||||||
console.log(this);
|
console.log(this);
|
||||||
|
@ -171,20 +167,19 @@ class Channel{
|
||||||
}
|
}
|
||||||
setUpInfiniteScroller(){
|
setUpInfiniteScroller(){
|
||||||
this.infinite=new InfiniteScroller((async (id:string,offset:number):Promise<string|undefined>=>{
|
this.infinite=new InfiniteScroller((async (id:string,offset:number):Promise<string|undefined>=>{
|
||||||
const snowflake=id;
|
|
||||||
if(offset===1){
|
if(offset===1){
|
||||||
if(this.idToPrev.has(snowflake)){
|
if(this.idToPrev.has(id)){
|
||||||
return this.idToPrev.get(snowflake);
|
return this.idToPrev.get(id);
|
||||||
}else{
|
}else{
|
||||||
await this.grabBefore(id);
|
await this.grabBefore(id);
|
||||||
return this.idToPrev.get(snowflake);
|
return this.idToPrev.get(id);
|
||||||
}
|
}
|
||||||
}else{
|
}else{
|
||||||
if(this.idToNext.has(snowflake)){
|
if(this.idToNext.has(id)){
|
||||||
return this.idToNext.get(snowflake);
|
return this.idToNext.get(id);
|
||||||
}else if(this.lastmessage?.id!==id){
|
}else if(this.lastmessage?.id!==id){
|
||||||
await this.grabAfter(id);
|
await this.grabAfter(id);
|
||||||
return this.idToNext.get(snowflake);
|
return this.idToNext.get(id);
|
||||||
}else{
|
}else{
|
||||||
console.log("at bottom");
|
console.log("at bottom");
|
||||||
}
|
}
|
||||||
|
@ -219,7 +214,8 @@ class Channel{
|
||||||
this.readbottom.bind(this)
|
this.readbottom.bind(this)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
constructor(json:channeljson|-1,owner:Guild){
|
constructor(json:channeljson|-1,owner:Guild,id:string=json===-1?undefined:json.id){
|
||||||
|
super(id);
|
||||||
if(json===-1){
|
if(json===-1){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -228,7 +224,6 @@ 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.snowflake=new SnowFlake(json.id);
|
|
||||||
if(json.parent_id){
|
if(json.parent_id){
|
||||||
this.parent_id=json.parent_id;
|
this.parent_id=json.parent_id;
|
||||||
}
|
}
|
||||||
|
@ -500,7 +495,7 @@ class Channel{
|
||||||
if(!this.hasunreads){
|
if(!this.hasunreads){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fetch(this.info.api+"/channels/"+this.snowflake+"/messages/"+this.lastmessageid+"/ack",{
|
fetch(this.info.api+"/channels/"+this.id+"/messages/"+this.lastmessageid+"/ack",{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
body: JSON.stringify({})
|
body: JSON.stringify({})
|
||||||
|
@ -586,7 +581,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.snowflake;
|
const thisid=this.id;
|
||||||
const thistype=this.type;
|
const thistype=this.type;
|
||||||
const full=new Dialog(
|
const full=new Dialog(
|
||||||
["hdiv",
|
["hdiv",
|
||||||
|
@ -625,7 +620,7 @@ class Channel{
|
||||||
console.log(full);
|
console.log(full);
|
||||||
}
|
}
|
||||||
deleteChannel(){
|
deleteChannel(){
|
||||||
fetch(this.info.api+"/channels/"+this.snowflake,{
|
fetch(this.info.api+"/channels/"+this.id,{
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
headers: this.headers
|
headers: this.headers
|
||||||
});
|
});
|
||||||
|
@ -669,7 +664,7 @@ class Channel{
|
||||||
if(message){
|
if(message){
|
||||||
return message;
|
return message;
|
||||||
}else{
|
}else{
|
||||||
const gety=await fetch(this.info.api+"/channels/"+this.snowflake+"/messages?limit=1&around="+id,{headers: this.headers});
|
const gety=await fetch(this.info.api+"/channels/"+this.id+"/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);
|
||||||
}
|
}
|
||||||
|
@ -692,7 +687,7 @@ class Channel{
|
||||||
this.guild.prevchannel=this;
|
this.guild.prevchannel=this;
|
||||||
this.localuser.channelfocus=this;
|
this.localuser.channelfocus=this;
|
||||||
const prom=this.infinite.delete();
|
const prom=this.infinite.delete();
|
||||||
history.pushState(null, "","/channels/"+this.guild_id+"/"+this.snowflake);
|
history.pushState(null, "","/channels/"+this.guild_id+"/"+this.id);
|
||||||
|
|
||||||
this.localuser.pageTitle("#"+this.name);
|
this.localuser.pageTitle("#"+this.name);
|
||||||
const channelTopic=document.getElementById("channelTopic") as HTMLSpanElement;
|
const channelTopic=document.getElementById("channelTopic") as HTMLSpanElement;
|
||||||
|
@ -746,7 +741,7 @@ class Channel{
|
||||||
if(this.lastreadmessageid&&this.messages.has(this.lastreadmessageid)){
|
if(this.lastreadmessageid&&this.messages.has(this.lastreadmessageid)){
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const j=await fetch(this.info.api+"/channels/"+this.snowflake+"/messages?limit=100",{
|
const j=await fetch(this.info.api+"/channels/"+this.id+"/messages?limit=100",{
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -856,11 +851,6 @@ class Channel{
|
||||||
throw new Error("please don't call this, no one has implemented it :P");
|
throw new Error("please don't call this, no one has implemented it :P");
|
||||||
}
|
}
|
||||||
async buildmessages(){
|
async buildmessages(){
|
||||||
/*
|
|
||||||
if(((!this.lastmessage)||(!this.lastmessage.snowflake)||(!this.goBackIds(this.lastmessage.snowflake,50,false)))&&this.lastreadmessageid){
|
|
||||||
await this.grabAfter(this.lastreadmessageid.id);
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
this.infinitefocus=false;
|
this.infinitefocus=false;
|
||||||
this.tryfocusinfinate();
|
this.tryfocusinfinate();
|
||||||
}
|
}
|
||||||
|
@ -973,7 +963,7 @@ class Channel{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.typing=Date.now()+6000;
|
this.typing=Date.now()+6000;
|
||||||
fetch(this.info.api+"/channels/"+this.snowflake+"/typing",{
|
fetch(this.info.api+"/channels/"+this.id+"/typing",{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: this.headers
|
headers: this.headers
|
||||||
});
|
});
|
||||||
|
@ -1015,7 +1005,7 @@ class Channel{
|
||||||
if(replyjson){
|
if(replyjson){
|
||||||
body.message_reference=replyjson;
|
body.message_reference=replyjson;
|
||||||
}
|
}
|
||||||
return await fetch(this.info.api+"/channels/"+this.snowflake+"/messages",{
|
return await fetch(this.info.api+"/channels/"+this.id+"/messages",{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
body: JSON.stringify(body)
|
body: JSON.stringify(body)
|
||||||
|
@ -1034,7 +1024,7 @@ class Channel{
|
||||||
for(const i in attachments){
|
for(const i in attachments){
|
||||||
formData.append("files["+i+"]",attachments[i]);
|
formData.append("files["+i+"]",attachments[i]);
|
||||||
}
|
}
|
||||||
return await fetch(this.info.api+"/channels/"+this.snowflake+"/messages", {
|
return await fetch(this.info.api+"/channels/"+this.id+"/messages", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: formData,
|
body: formData,
|
||||||
headers: {Authorization: this.headers.Authorization}
|
headers: {Authorization: this.headers.Authorization}
|
||||||
|
@ -1125,7 +1115,7 @@ class Channel{
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
async addRoleToPerms(role:Role){
|
async addRoleToPerms(role:Role){
|
||||||
await fetch(this.info.api+"/channels/"+this.snowflake+"/permissions/"+role.snowflake,{
|
await fetch(this.info.api+"/channels/"+this.id+"/permissions/"+role.id,{
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
|
@ -1144,7 +1134,7 @@ class Channel{
|
||||||
if(permission){
|
if(permission){
|
||||||
permission.allow=perms.allow;
|
permission.allow=perms.allow;
|
||||||
permission.deny=perms.deny;
|
permission.deny=perms.deny;
|
||||||
await fetch(this.info.api+"/channels/"+this.snowflake+"/permissions/"+id,{
|
await fetch(this.info.api+"/channels/"+this.id+"/permissions/"+id,{
|
||||||
method: "PUT",
|
method: "PUT",
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
|
|
|
@ -4,7 +4,6 @@ import{ Message }from"./message.js";
|
||||||
import{ Localuser }from"./localuser.js";
|
import{ Localuser }from"./localuser.js";
|
||||||
import{User}from"./user.js";
|
import{User}from"./user.js";
|
||||||
import{ Member }from"./member.js";
|
import{ Member }from"./member.js";
|
||||||
import{ SnowFlake }from"./snowflake.js";
|
|
||||||
import{ dirrectjson, memberjson }from"./jsontypes.js";
|
import{ dirrectjson, memberjson }from"./jsontypes.js";
|
||||||
import{ Permissions }from"./permissions.js";
|
import{ Permissions }from"./permissions.js";
|
||||||
|
|
||||||
|
@ -19,7 +18,6 @@ class Direct extends Guild{
|
||||||
this.headers=this.localuser.headers;
|
this.headers=this.localuser.headers;
|
||||||
this.channels=[];
|
this.channels=[];
|
||||||
this.channelids={};
|
this.channelids={};
|
||||||
this.snowflake=new SnowFlake("@me");
|
|
||||||
this.properties={};
|
this.properties={};
|
||||||
this.roles=[];
|
this.roles=[];
|
||||||
this.roleids=new Map();
|
this.roleids=new Map();
|
||||||
|
@ -84,7 +82,7 @@ dmPermissions.setPermission("USE_VAD",1);
|
||||||
class Group extends Channel{
|
class Group extends Channel{
|
||||||
user:User;
|
user:User;
|
||||||
constructor(json:dirrectjson,owner:Direct){
|
constructor(json:dirrectjson,owner:Direct){
|
||||||
super(-1,owner);
|
super(-1,owner,json.id);
|
||||||
this.owner=owner;
|
this.owner=owner;
|
||||||
this.headers=this.guild.headers;
|
this.headers=this.guild.headers;
|
||||||
this.name=json.recipients[0]?.username;
|
this.name=json.recipients[0]?.username;
|
||||||
|
@ -94,7 +92,6 @@ 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.snowflake=new SnowFlake(json.id);
|
|
||||||
this.parent_id=null;
|
this.parent_id=null;
|
||||||
this.parent=null;
|
this.parent=null;
|
||||||
this.children=[];
|
this.children=[];
|
||||||
|
@ -106,7 +103,8 @@ class Group extends Channel{
|
||||||
if(this.lastmessageid){
|
if(this.lastmessageid){
|
||||||
this.position=Number((BigInt(this.lastmessageid)>>22n)+1420070400000n);
|
this.position=Number((BigInt(this.lastmessageid)>>22n)+1420070400000n);
|
||||||
}
|
}
|
||||||
this.position=-Math.max(this.position,this.snowflake.getUnixTime());
|
|
||||||
|
this.position=-Math.max(this.position,this.getUnixTime());
|
||||||
}
|
}
|
||||||
createguildHTML(){
|
createguildHTML(){
|
||||||
const div=document.createElement("div");
|
const div=document.createElement("div");
|
||||||
|
|
|
@ -10,12 +10,11 @@ import{ SnowFlake }from"./snowflake.js";
|
||||||
import{ channeljson, guildjson, emojijson, memberjson }from"./jsontypes.js";
|
import{ channeljson, guildjson, emojijson, memberjson }from"./jsontypes.js";
|
||||||
import{ User }from"./user.js";
|
import{ User }from"./user.js";
|
||||||
import{ Message }from"./message.js";
|
import{ Message }from"./message.js";
|
||||||
class Guild{
|
class Guild extends SnowFlake{
|
||||||
owner:Localuser;
|
owner:Localuser;
|
||||||
headers:Localuser["headers"];
|
headers:Localuser["headers"];
|
||||||
channels:Channel[];
|
channels:Channel[];
|
||||||
channelids:{[key:string]:Channel};
|
channelids:{[key:string]:Channel};
|
||||||
snowflake:SnowFlake;
|
|
||||||
properties;
|
properties;
|
||||||
roles:Role[];
|
roles:Role[];
|
||||||
roleids:Map<string,Role>;
|
roleids:Map<string,Role>;
|
||||||
|
@ -27,9 +26,6 @@ class Guild{
|
||||||
member:Member;
|
member:Member;
|
||||||
html:HTMLElement;
|
html:HTMLElement;
|
||||||
emojis:emojijson[];
|
emojis:emojijson[];
|
||||||
get id(){
|
|
||||||
return this.snowflake.id;
|
|
||||||
}
|
|
||||||
static contextmenu=new Contextmenu<Guild,undefined>("guild menu");
|
static contextmenu=new Contextmenu<Guild,undefined>("guild menu");
|
||||||
static setupcontextmenu(){
|
static setupcontextmenu(){
|
||||||
Guild.contextmenu.addbutton("Copy Guild id",function(this:Guild){
|
Guild.contextmenu.addbutton("Copy Guild id",function(this:Guild){
|
||||||
|
@ -87,20 +83,20 @@ class Guild{
|
||||||
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();
|
||||||
}
|
}
|
||||||
constructor(json:guildjson|-1,owner:Localuser,member:memberjson|User|null){
|
constructor(json:guildjson|-1,owner:Localuser,member:memberjson|User){
|
||||||
if(json===-1||member===null){
|
if(json===-1){
|
||||||
|
super("@me");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if(json.stickers.length){
|
if(json.stickers.length){
|
||||||
console.log(json.stickers,":3");
|
console.log(json.stickers,":3");
|
||||||
}
|
}
|
||||||
|
super(json.id);
|
||||||
this.emojis = json.emojis;
|
this.emojis = json.emojis;
|
||||||
this.owner=owner;
|
this.owner=owner;
|
||||||
this.headers=this.owner.headers;
|
this.headers=this.owner.headers;
|
||||||
this.channels=[];
|
this.channels=[];
|
||||||
this.channelids={};
|
this.channelids={};
|
||||||
this.snowflake=new SnowFlake(json.id);
|
|
||||||
this.properties=json.properties;
|
this.properties=json.properties;
|
||||||
this.roles=[];
|
this.roles=[];
|
||||||
this.roleids=new Map();
|
this.roleids=new Map();
|
||||||
|
@ -203,7 +199,7 @@ class Guild{
|
||||||
full.show();
|
full.show();
|
||||||
}
|
}
|
||||||
async leave(){
|
async leave(){
|
||||||
return fetch(this.info.api+"/users/@me/guilds/"+this.snowflake,{
|
return fetch(this.info.api+"/users/@me/guilds/"+this.id,{
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
headers: this.headers
|
headers: this.headers
|
||||||
});
|
});
|
||||||
|
@ -351,7 +347,7 @@ class Guild{
|
||||||
full.show();
|
full.show();
|
||||||
}
|
}
|
||||||
async delete(){
|
async delete(){
|
||||||
return fetch(this.info.api+"/guilds/"+this.snowflake+"/delete",{
|
return fetch(this.info.api+"/guilds/"+this.id+"/delete",{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
});
|
});
|
||||||
|
@ -543,7 +539,7 @@ class Guild{
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
async createRole(name:string){
|
async createRole(name:string){
|
||||||
const fetched=await fetch(this.info.api+"/guilds/"+this.snowflake+"roles",{
|
const fetched=await fetch(this.info.api+"/guilds/"+this.id+"roles",{
|
||||||
method: "POST",
|
method: "POST",
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
|
@ -563,7 +559,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+"/guilds/"+this.snowflake+"/roles/"+this.snowflake,{
|
await fetch(this.info.api+"/guilds/"+this.id+"/roles/"+role.id,{
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
|
|
|
@ -106,8 +106,7 @@ class Localuser{
|
||||||
if(guild===undefined){
|
if(guild===undefined){
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const guildid=guild.snowflake;
|
guild.channelids[thing.channel_id].readStateInfo(thing);
|
||||||
(this.guildids.get(guildid.id) as Guild).channelids[thing.channel_id].readStateInfo(thing);
|
|
||||||
}
|
}
|
||||||
for(const thing of ready.d.relationships){
|
for(const thing of ready.d.relationships){
|
||||||
const user=new User(thing.user,this);
|
const user=new User(thing.user,this);
|
||||||
|
|
|
@ -11,7 +11,7 @@ import{ SnowFlake }from"./snowflake.js";
|
||||||
import{ memberjson, messagejson }from"./jsontypes.js";
|
import{ memberjson, messagejson }from"./jsontypes.js";
|
||||||
import{Emoji}from"./emoji.js";
|
import{Emoji}from"./emoji.js";
|
||||||
|
|
||||||
class Message{
|
class Message extends SnowFlake{
|
||||||
static contextmenu=new Contextmenu<Message,undefined>("message menu");
|
static contextmenu=new Contextmenu<Message,undefined>("message menu");
|
||||||
owner:Channel;
|
owner:Channel;
|
||||||
headers:Localuser["headers"];
|
headers:Localuser["headers"];
|
||||||
|
@ -20,7 +20,6 @@ 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[]
|
||||||
snowflake:SnowFlake;
|
|
||||||
message_reference;
|
message_reference;
|
||||||
type:number;
|
type:number;
|
||||||
timestamp:number;
|
timestamp:number;
|
||||||
|
@ -43,9 +42,6 @@ class Message{
|
||||||
div:HTMLDivElement|undefined;
|
div:HTMLDivElement|undefined;
|
||||||
member:Member|undefined;
|
member:Member|undefined;
|
||||||
reactions:messagejson["reactions"];
|
reactions:messagejson["reactions"];
|
||||||
get id(){
|
|
||||||
return this.snowflake.id;
|
|
||||||
}
|
|
||||||
static setup(){
|
static setup(){
|
||||||
this.del=new Promise(_=>{
|
this.del=new Promise(_=>{
|
||||||
this.resolve=_;
|
this.resolve=_;
|
||||||
|
@ -82,6 +78,7 @@ class Message{
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
constructor(messagejson:messagejson,owner:Channel){
|
constructor(messagejson:messagejson,owner:Channel){
|
||||||
|
super(messagejson.id);
|
||||||
this.owner=owner;
|
this.owner=owner;
|
||||||
this.headers=this.owner.headers;
|
this.headers=this.owner.headers;
|
||||||
this.giveData(messagejson);
|
this.giveData(messagejson);
|
||||||
|
@ -119,7 +116,6 @@ 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.snowflake=new SnowFlake(messagejson.id);
|
|
||||||
continue;
|
continue;
|
||||||
}else if(thing==="member"){
|
}else if(thing==="member"){
|
||||||
Member.new(messagejson.member as memberjson,this.guild).then(_=>{
|
Member.new(messagejson.member as memberjson,this.guild).then(_=>{
|
||||||
|
@ -161,7 +157,7 @@ class Message{
|
||||||
func();
|
func();
|
||||||
}
|
}
|
||||||
canDelete(){
|
canDelete(){
|
||||||
return this.channel.hasPermission("MANAGE_MESSAGES")||this.author.snowflake===this.localuser.user.snowflake;
|
return this.channel.hasPermission("MANAGE_MESSAGES")||this.author===this.localuser.user;
|
||||||
}
|
}
|
||||||
get channel(){
|
get channel(){
|
||||||
return this.owner;
|
return this.owner;
|
||||||
|
@ -206,14 +202,14 @@ class Message{
|
||||||
return build;
|
return build;
|
||||||
}
|
}
|
||||||
async edit(content){
|
async edit(content){
|
||||||
return await fetch(this.info.api+"/channels/"+this.channel.snowflake+"/messages/"+this.id,{
|
return await fetch(this.info.api+"/channels/"+this.channel.id+"/messages/"+this.id,{
|
||||||
method: "PATCH",
|
method: "PATCH",
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
body: JSON.stringify({content})
|
body: JSON.stringify({content})
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
delete(){
|
delete(){
|
||||||
fetch(`${this.info.api}/channels/${this.channel.snowflake}/messages/${this.id}`,{
|
fetch(`${this.info.api}/channels/${this.channel.id}/messages/${this.id}`,{
|
||||||
headers: this.headers,
|
headers: this.headers,
|
||||||
method: "DELETE",
|
method: "DELETE",
|
||||||
});
|
});
|
||||||
|
@ -381,7 +377,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?.snowflake!=this.author.snowflake)||(current)||this.message_reference;
|
const combine=(premessage?.author!=this.author)||(current)||this.message_reference;
|
||||||
if(combine){
|
if(combine){
|
||||||
const pfp=this.author.buildpfp();
|
const pfp=this.author.buildpfp();
|
||||||
this.author.bind(pfp,this.guild,false);
|
this.author.bind(pfp,this.guild,false);
|
||||||
|
@ -567,7 +563,7 @@ class Message{
|
||||||
}
|
}
|
||||||
buildhtml(premessage?:Message|undefined):HTMLElement{
|
buildhtml(premessage?:Message|undefined):HTMLElement{
|
||||||
if(this.div){
|
if(this.div){
|
||||||
console.error(`HTML for ${this.snowflake} already exists, aborting`);return this.div;
|
console.error(`HTML for ${this.id} already exists, aborting`);return this.div;
|
||||||
}
|
}
|
||||||
try{
|
try{
|
||||||
const div=document.createElement("div");
|
const div=document.createElement("div");
|
||||||
|
|
|
@ -4,11 +4,10 @@ import{Localuser}from"./localuser.js";
|
||||||
import{Guild}from"./guild.js";
|
import{Guild}from"./guild.js";
|
||||||
import{ SnowFlake }from"./snowflake.js";
|
import{ SnowFlake }from"./snowflake.js";
|
||||||
import{ rolesjson }from"./jsontypes.js";
|
import{ rolesjson }from"./jsontypes.js";
|
||||||
class Role{
|
class Role extends SnowFlake{
|
||||||
permissions:Permissions;
|
permissions:Permissions;
|
||||||
owner:Guild;
|
owner:Guild;
|
||||||
color:number;
|
color:number;
|
||||||
readonly snowflake:SnowFlake;
|
|
||||||
name:string;
|
name:string;
|
||||||
info:Guild["info"];
|
info:Guild["info"];
|
||||||
hoist:boolean;
|
hoist:boolean;
|
||||||
|
@ -16,15 +15,12 @@ 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:rolesjson, owner:Guild){
|
constructor(json:rolesjson, owner:Guild){
|
||||||
|
super(json.id);
|
||||||
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.snowflake=new SnowFlake(json.id);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
this[thing]=json[thing];
|
this[thing]=json[thing];
|
||||||
|
|
|
@ -1,13 +1,16 @@
|
||||||
class SnowFlake{
|
abstract class SnowFlake{
|
||||||
public readonly id:string;
|
public readonly id:string;
|
||||||
constructor(id:string){
|
constructor(id:string){
|
||||||
this.id=id;
|
this.id=id;
|
||||||
}
|
}
|
||||||
getUnixTime():number{
|
getUnixTime():number{
|
||||||
|
return SnowFlake.stringToUnixTime(this.id);
|
||||||
|
}
|
||||||
|
static stringToUnixTime(str:string){
|
||||||
try{
|
try{
|
||||||
return Number((BigInt(this.id)>>22n)+1420070400000n);
|
return Number((BigInt(str)>>22n)+1420070400000n);
|
||||||
}catch{
|
}catch{
|
||||||
console.error(`The ID is corrupted, it's ${this.id} when it should be some number.`);
|
console.error(`The ID is corrupted, it's ${str} when it should be some number.`);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,10 +7,9 @@ import{Guild}from"./guild.js";
|
||||||
import{ SnowFlake }from"./snowflake.js";
|
import{ SnowFlake }from"./snowflake.js";
|
||||||
import{ presencejson, userjson }from"./jsontypes.js";
|
import{ presencejson, userjson }from"./jsontypes.js";
|
||||||
|
|
||||||
class User{
|
class User extends SnowFlake{
|
||||||
owner:Localuser;
|
owner:Localuser;
|
||||||
hypotheticalpfp:boolean;
|
hypotheticalpfp:boolean;
|
||||||
snowflake:SnowFlake;
|
|
||||||
avatar:string|null;
|
avatar:string|null;
|
||||||
username:string;
|
username:string;
|
||||||
nickname:string|null=null;
|
nickname:string|null=null;
|
||||||
|
@ -64,9 +63,6 @@ class User{
|
||||||
return"offline";
|
return"offline";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
get id(){
|
|
||||||
return this.snowflake.id;
|
|
||||||
}
|
|
||||||
static contextmenu=new Contextmenu<User,Member|undefined>("User Menu");
|
static contextmenu=new Contextmenu<User,Member|undefined>("User Menu");
|
||||||
static setUpContextMenu(){
|
static setUpContextMenu(){
|
||||||
this.contextmenu.addbutton("Copy user id",function(this:User){
|
this.contextmenu.addbutton("Copy user id",function(this:User){
|
||||||
|
@ -142,6 +138,7 @@ class User{
|
||||||
return this.owner;
|
return this.owner;
|
||||||
}
|
}
|
||||||
constructor(userjson:userjson,owner:Localuser,dontclone=false){
|
constructor(userjson:userjson,owner:Localuser,dontclone=false){
|
||||||
|
super(userjson.id);
|
||||||
this.owner=owner;
|
this.owner=owner;
|
||||||
if(!owner){
|
if(!owner){
|
||||||
console.error("missing localuser");
|
console.error("missing localuser");
|
||||||
|
@ -153,7 +150,6 @@ class User{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if(thing === "id"){
|
if(thing === "id"){
|
||||||
this.snowflake=new SnowFlake(userjson[thing]);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
this[thing]=userjson[thing];
|
this[thing]=userjson[thing];
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue