mirror of
https://github.com/stoatchat/javascript-client-sdk.git
synced 2026-07-19 17:13:31 -04:00
chore: fix lint and formatting errors
This commit is contained in:
+6
-7
@@ -1,4 +1,4 @@
|
||||
import { Accessor, batch, createSignal, Setter } from "solid-js";
|
||||
import { Accessor, Setter, batch, createSignal } from "solid-js";
|
||||
|
||||
import { AsyncEventEmitter } from "@vladfrangu/async_event_emitter";
|
||||
import type { DataLogin, RevoltConfig } from "revolt-api";
|
||||
@@ -271,9 +271,8 @@ export class Client extends AsyncEventEmitter<Events> {
|
||||
}
|
||||
});
|
||||
|
||||
this.events.on(
|
||||
"event",
|
||||
(event) => handleEventV1(this, event, this.#setReady),
|
||||
this.events.on("event", (event) =>
|
||||
handleEventV1(this, event, this.#setReady),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -397,9 +396,9 @@ export class Client extends AsyncEventEmitter<Events> {
|
||||
*/
|
||||
proxyFile(url: string): string | undefined {
|
||||
if (this.configuration?.features.january.enabled) {
|
||||
return `${this.configuration.features.january.url}/proxy?url=${
|
||||
encodeURIComponent(url)
|
||||
}`;
|
||||
return `${this.configuration.features.january.url}/proxy?url=${encodeURIComponent(
|
||||
url,
|
||||
)}`;
|
||||
} else {
|
||||
return url;
|
||||
}
|
||||
|
||||
+47
-44
@@ -98,8 +98,8 @@ export class Channel {
|
||||
return this.type === "SavedMessages"
|
||||
? this.user?.username
|
||||
: this.type === "DirectMessage"
|
||||
? this.recipient?.username
|
||||
: this.name;
|
||||
? this.recipient?.username
|
||||
: this.name;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -135,7 +135,7 @@ export class Channel {
|
||||
*/
|
||||
get typing() {
|
||||
return [...this.typingIds.values()].map(
|
||||
(id) => this.#collection.client.users.get(id)!
|
||||
(id) => this.#collection.client.users.get(id)!,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -161,7 +161,7 @@ export class Channel {
|
||||
get recipient() {
|
||||
return this.type === "DirectMessage"
|
||||
? this.recipients?.find(
|
||||
(user) => user?.id !== this.#collection.client.user!.id
|
||||
(user) => user?.id !== this.#collection.client.user!.id,
|
||||
)
|
||||
: undefined;
|
||||
}
|
||||
@@ -178,7 +178,7 @@ export class Channel {
|
||||
*/
|
||||
get user() {
|
||||
return this.#collection.client.users.get(
|
||||
this.#collection.getUnderlyingObject(this.id).userId!
|
||||
this.#collection.getUnderlyingObject(this.id).userId!,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -194,7 +194,7 @@ export class Channel {
|
||||
*/
|
||||
get owner() {
|
||||
return this.#collection.client.users.get(
|
||||
this.#collection.getUnderlyingObject(this.id).ownerId!
|
||||
this.#collection.getUnderlyingObject(this.id).ownerId!,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -210,7 +210,7 @@ export class Channel {
|
||||
*/
|
||||
get server() {
|
||||
return this.#collection.client.servers.get(
|
||||
this.#collection.getUnderlyingObject(this.id).serverId!
|
||||
this.#collection.getUnderlyingObject(this.id).serverId!,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -329,12 +329,12 @@ export class Channel {
|
||||
(role) =>
|
||||
bitwiseAndEq(
|
||||
this.rolePermissions?.[role]?.d ?? 0,
|
||||
Permission.ViewChannel
|
||||
Permission.ViewChannel,
|
||||
) ||
|
||||
bitwiseAndEq(
|
||||
this.server?.roles.get(role)?.permissions.d ?? 0,
|
||||
Permission.ViewChannel
|
||||
)
|
||||
Permission.ViewChannel,
|
||||
),
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -354,7 +354,7 @@ export class Channel {
|
||||
havePermission(...permission: (keyof typeof Permission)[]) {
|
||||
return bitwiseAndEq(
|
||||
this.permission,
|
||||
...permission.map((x) => Permission[x])
|
||||
...permission.map((x) => Permission[x]),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -366,7 +366,7 @@ export class Channel {
|
||||
orPermission(...permission: (keyof typeof Permission)[]) {
|
||||
return (
|
||||
permission.findIndex((x) =>
|
||||
bitwiseAndEq(this.permission, Permission[x])
|
||||
bitwiseAndEq(this.permission, Permission[x]),
|
||||
) !== -1
|
||||
);
|
||||
}
|
||||
@@ -378,13 +378,13 @@ export class Channel {
|
||||
*/
|
||||
async fetchMembers() {
|
||||
const members = await this.#collection.client.api.get(
|
||||
`/channels/${this.id as ""}/members`
|
||||
`/channels/${this.id as ""}/members`,
|
||||
);
|
||||
|
||||
return batch(() =>
|
||||
members.map((user) =>
|
||||
this.#collection.client.users.getOrCreate(user._id, user)
|
||||
)
|
||||
this.#collection.client.users.getOrCreate(user._id, user),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -395,13 +395,16 @@ export class Channel {
|
||||
*/
|
||||
async fetchWebhooks() {
|
||||
const webhooks = await this.#collection.client.api.get(
|
||||
`/channels/${this.id as ""}/webhooks`
|
||||
`/channels/${this.id as ""}/webhooks`,
|
||||
);
|
||||
|
||||
return batch(() =>
|
||||
webhooks.map((webhook) =>
|
||||
this.#collection.client.channelWebhooks.getOrCreate(webhook.id, webhook)
|
||||
)
|
||||
this.#collection.client.channelWebhooks.getOrCreate(
|
||||
webhook.id,
|
||||
webhook,
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -438,7 +441,7 @@ export class Channel {
|
||||
*/
|
||||
async addMember(user_id: string) {
|
||||
return await this.#collection.client.api.put(
|
||||
`/channels/${this.id as ""}/recipients/${user_id as ""}`
|
||||
`/channels/${this.id as ""}/recipients/${user_id as ""}`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -449,7 +452,7 @@ export class Channel {
|
||||
*/
|
||||
async removeMember(user_id: string) {
|
||||
return await this.#collection.client.api.delete(
|
||||
`/channels/${this.id as ""}/recipients/${user_id as ""}`
|
||||
`/channels/${this.id as ""}/recipients/${user_id as ""}`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -461,7 +464,7 @@ export class Channel {
|
||||
*/
|
||||
async sendMessage(
|
||||
data: string | DataMessageSend,
|
||||
idempotencyKey: string = ulid()
|
||||
idempotencyKey: string = ulid(),
|
||||
) {
|
||||
const msg: DataMessageSend =
|
||||
typeof data === "string" ? { content: data } : data;
|
||||
@@ -480,13 +483,13 @@ export class Channel {
|
||||
headers: {
|
||||
"Idempotency-Key": idempotencyKey,
|
||||
},
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
return this.#collection.client.messages.getOrCreate(
|
||||
message._id,
|
||||
message,
|
||||
true
|
||||
true,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -498,7 +501,7 @@ export class Channel {
|
||||
*/
|
||||
async fetchMessage(messageId: string) {
|
||||
const message = await this.#collection.client.api.get(
|
||||
`/channels/${this.id as ""}/messages/${messageId as ""}`
|
||||
`/channels/${this.id as ""}/messages/${messageId as ""}`,
|
||||
);
|
||||
|
||||
return this.#collection.client.messages.getOrCreate(message._id, message);
|
||||
@@ -517,15 +520,15 @@ export class Channel {
|
||||
path: "/channels/{target}/messages";
|
||||
})["params"],
|
||||
"include_users"
|
||||
>
|
||||
>,
|
||||
) {
|
||||
const messages = (await this.#collection.client.api.get(
|
||||
`/channels/${this.id as ""}/messages`,
|
||||
{ ...params }
|
||||
{ ...params },
|
||||
)) as ApiMessage[];
|
||||
|
||||
return messages.map((message) =>
|
||||
this.#collection.client.messages.getOrCreate(message._id, message)
|
||||
this.#collection.client.messages.getOrCreate(message._id, message),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -542,22 +545,22 @@ export class Channel {
|
||||
path: "/channels/{target}/messages";
|
||||
})["params"],
|
||||
"include_users"
|
||||
>
|
||||
>,
|
||||
) {
|
||||
const data = (await this.#collection.client.api.get(
|
||||
`/channels/${this.id as ""}/messages`,
|
||||
{ ...params, include_users: true }
|
||||
{ ...params, include_users: true },
|
||||
)) as { messages: ApiMessage[]; users: ApiUser[]; members?: ApiMember[] };
|
||||
|
||||
return batch(() => ({
|
||||
messages: data.messages.map((message) =>
|
||||
this.#collection.client.messages.getOrCreate(message._id, message)
|
||||
this.#collection.client.messages.getOrCreate(message._id, message),
|
||||
),
|
||||
users: data.users.map((user) =>
|
||||
this.#collection.client.users.getOrCreate(user._id, user)
|
||||
this.#collection.client.users.getOrCreate(user._id, user),
|
||||
),
|
||||
members: data.members?.map((member) =>
|
||||
this.#collection.client.serverMembers.getOrCreate(member._id, member)
|
||||
this.#collection.client.serverMembers.getOrCreate(member._id, member),
|
||||
),
|
||||
}));
|
||||
}
|
||||
@@ -571,13 +574,13 @@ export class Channel {
|
||||
async search(params: Omit<DataMessageSearch, "include_users">) {
|
||||
const messages = (await this.#collection.client.api.post(
|
||||
`/channels/${this.id as ""}/search`,
|
||||
params
|
||||
params,
|
||||
)) as ApiMessage[];
|
||||
|
||||
return batch(() =>
|
||||
messages.map((message) =>
|
||||
this.#collection.client.messages.getOrCreate(message._id, message)
|
||||
)
|
||||
this.#collection.client.messages.getOrCreate(message._id, message),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -593,18 +596,18 @@ export class Channel {
|
||||
{
|
||||
...params,
|
||||
include_users: true,
|
||||
}
|
||||
},
|
||||
)) as { messages: ApiMessage[]; users: ApiUser[]; members?: ApiMember[] };
|
||||
|
||||
return batch(() => ({
|
||||
messages: data.messages.map((message) =>
|
||||
this.#collection.client.messages.getOrCreate(message._id, message)
|
||||
this.#collection.client.messages.getOrCreate(message._id, message),
|
||||
),
|
||||
users: data.users.map((user) =>
|
||||
this.#collection.client.users.getOrCreate(user._id, user)
|
||||
this.#collection.client.users.getOrCreate(user._id, user),
|
||||
),
|
||||
members: data.members?.map((member) =>
|
||||
this.#collection.client.serverMembers.getOrCreate(member._id, member)
|
||||
this.#collection.client.serverMembers.getOrCreate(member._id, member),
|
||||
),
|
||||
}));
|
||||
}
|
||||
@@ -619,7 +622,7 @@ export class Channel {
|
||||
`/channels/${this.id as ""}/messages/bulk`,
|
||||
{
|
||||
ids,
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -630,7 +633,7 @@ export class Channel {
|
||||
*/
|
||||
async createInvite() {
|
||||
return await this.#collection.client.api.post(
|
||||
`/channels/${this.id as ""}/invites`
|
||||
`/channels/${this.id as ""}/invites`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -650,7 +653,7 @@ export class Channel {
|
||||
message?: Message | string,
|
||||
skipRateLimiter?: boolean,
|
||||
skipRequest?: boolean,
|
||||
skipNextMarking?: boolean
|
||||
skipNextMarking?: boolean,
|
||||
) {
|
||||
if (!message && this.#manuallyMarked) {
|
||||
this.#manuallyMarked = false;
|
||||
@@ -687,7 +690,7 @@ export class Channel {
|
||||
const performAck = () => {
|
||||
this.#ackLimit = undefined;
|
||||
this.#collection.client.api.put(
|
||||
`/channels/${this.id}/ack/${lastMessageId as ""}`
|
||||
`/channels/${this.id}/ack/${lastMessageId as ""}`,
|
||||
);
|
||||
};
|
||||
|
||||
@@ -715,7 +718,7 @@ export class Channel {
|
||||
async setPermissions(role_id = "default", permissions: Override) {
|
||||
return await this.#collection.client.api.put(
|
||||
`/channels/${this.id as ""}/permissions/${role_id as ""}`,
|
||||
{ permissions }
|
||||
{ permissions },
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -60,7 +60,7 @@ export class ChannelWebhook {
|
||||
*/
|
||||
get channel() {
|
||||
return this.#collection.client.channels.get(
|
||||
this.#collection.getUnderlyingObject(this.id).channelId
|
||||
this.#collection.getUnderlyingObject(this.id).channelId,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -75,17 +75,18 @@ export class ChannelWebhook {
|
||||
* Edit this webhook
|
||||
* TODO: not in production
|
||||
*/
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
async edit(data: any /*: DataEditWebhook*/) {
|
||||
const webhook = await this.#collection.client.api.patch(
|
||||
// @ts-expect-error not in prod
|
||||
`/webhooks/${this.id as ""}/${this.token as ""}`,
|
||||
data
|
||||
data,
|
||||
);
|
||||
|
||||
this.#collection.updateUnderlyingObject(
|
||||
this.id,
|
||||
// @ts-expect-error not in prod
|
||||
hydrate("channelWebhook", webhook, this.#collection.client)
|
||||
hydrate("channelWebhook", webhook, this.#collection.client),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -96,7 +97,7 @@ export class ChannelWebhook {
|
||||
async delete() {
|
||||
await this.#collection.client.api.delete(
|
||||
// @ts-expect-error not in prod
|
||||
`/webhooks/${this.id}/${this.token}`
|
||||
`/webhooks/${this.id}/${this.token}`,
|
||||
);
|
||||
|
||||
this.#collection.delete(this.id);
|
||||
|
||||
@@ -53,7 +53,7 @@ export class Emoji {
|
||||
*/
|
||||
get creator() {
|
||||
return this.#collection.client.users.get(
|
||||
this.#collection.getUnderlyingObject(this.id).creatorId
|
||||
this.#collection.getUnderlyingObject(this.id).creatorId,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -45,7 +45,7 @@ export class File {
|
||||
*/
|
||||
constructor(
|
||||
client: Client,
|
||||
file: Pick<API.File, "_id" | "tag" | "metadata"> & Partial<API.File>
|
||||
file: Pick<API.File, "_id" | "tag" | "metadata"> & Partial<API.File>,
|
||||
) {
|
||||
this.#client = client;
|
||||
this.id = file._id;
|
||||
|
||||
+2
-2
@@ -90,7 +90,7 @@ export class MFATicket {
|
||||
constructor(
|
||||
client: Client,
|
||||
ticket: TicketType,
|
||||
mutate: SetStoreFunction<MultiFactorStatus>
|
||||
mutate: SetStoreFunction<MultiFactorStatus>,
|
||||
) {
|
||||
this.#client = client;
|
||||
this.#ticket = ticket;
|
||||
@@ -139,7 +139,7 @@ export class MFATicket {
|
||||
headers: {
|
||||
"X-MFA-Ticket": this.token,
|
||||
},
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
this.#mutate("recovery_active", true);
|
||||
|
||||
+14
-12
@@ -72,7 +72,7 @@ export class Message {
|
||||
*/
|
||||
get channel() {
|
||||
return this.#collection.client.channels.get(
|
||||
this.#collection.getUnderlyingObject(this.id).channelId
|
||||
this.#collection.getUnderlyingObject(this.id).channelId,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -105,7 +105,7 @@ export class Message {
|
||||
*/
|
||||
get author() {
|
||||
return this.#collection.client.users.get(
|
||||
this.#collection.getUnderlyingObject(this.id).authorId!
|
||||
this.#collection.getUnderlyingObject(this.id).authorId!,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -208,7 +208,9 @@ export class Message {
|
||||
|
||||
return (
|
||||
this.masquerade?.name ??
|
||||
(webhook ? webhook.name : this.member?.nickname ?? this.author?.username)
|
||||
(webhook
|
||||
? webhook.name
|
||||
: (this.member?.nickname ?? this.author?.username))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -229,7 +231,7 @@ export class Message {
|
||||
this.masqueradeAvatarURL ??
|
||||
(webhook
|
||||
? webhook.avatarURL
|
||||
: this.member?.avatarURL ?? this.author?.avatarURL)
|
||||
: (this.member?.avatarURL ?? this.author?.avatarURL))
|
||||
);
|
||||
}
|
||||
|
||||
@@ -244,8 +246,8 @@ export class Message {
|
||||
(webhook
|
||||
? webhook.avatarURL
|
||||
: this.member
|
||||
? this.member?.animatedAvatarURL
|
||||
: this.author?.animatedAvatarURL)
|
||||
? this.member?.animatedAvatarURL
|
||||
: this.author?.animatedAvatarURL)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -271,7 +273,7 @@ export class Message {
|
||||
async edit(data: DataEditMessage) {
|
||||
return await this.#collection.client.api.patch(
|
||||
`/channels/${this.channelId as ""}/messages/${this.id as ""}`,
|
||||
data
|
||||
data,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -280,7 +282,7 @@ export class Message {
|
||||
*/
|
||||
async delete() {
|
||||
return await this.#collection.client.api.delete(
|
||||
`/channels/${this.channelId as ""}/messages/${this.id as ""}`
|
||||
`/channels/${this.channelId as ""}/messages/${this.id as ""}`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -300,7 +302,7 @@ export class Message {
|
||||
| (Omit<DataMessageSend, "nonce"> & {
|
||||
nonce?: string;
|
||||
}),
|
||||
mention = true
|
||||
mention = true,
|
||||
) {
|
||||
const obj = typeof data === "string" ? { content: data } : data;
|
||||
return this.channel?.sendMessage({
|
||||
@@ -314,7 +316,7 @@ export class Message {
|
||||
*/
|
||||
async clearReactions() {
|
||||
return await this.#collection.client.api.delete(
|
||||
`/channels/${this.channelId as ""}/messages/${this.id as ""}/reactions`
|
||||
`/channels/${this.channelId as ""}/messages/${this.id as ""}/reactions`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -326,7 +328,7 @@ export class Message {
|
||||
return await this.#collection.client.api.put(
|
||||
`/channels/${this.channelId as ""}/messages/${this.id as ""}/reactions/${
|
||||
emoji as ""
|
||||
}`
|
||||
}`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -338,7 +340,7 @@ export class Message {
|
||||
return await this.#collection.client.api.delete(
|
||||
`/channels/${this.channelId as ""}/messages/${this.id as ""}/reactions/${
|
||||
emoji as ""
|
||||
}`
|
||||
}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ export class ImageEmbed extends MessageEmbed {
|
||||
*/
|
||||
constructor(
|
||||
client: Client,
|
||||
embed: Omit<API.Embed & { type: "Image" }, "type">
|
||||
embed: Omit<API.Embed & { type: "Image" }, "type">,
|
||||
) {
|
||||
super(client, "Image");
|
||||
|
||||
@@ -93,7 +93,7 @@ export class VideoEmbed extends MessageEmbed {
|
||||
*/
|
||||
constructor(
|
||||
client: Client,
|
||||
embed: Omit<API.Embed & { type: "Video" }, "type">
|
||||
embed: Omit<API.Embed & { type: "Video" }, "type">,
|
||||
) {
|
||||
super(client, "Video");
|
||||
|
||||
@@ -132,7 +132,7 @@ export class WebsiteEmbed extends MessageEmbed {
|
||||
*/
|
||||
constructor(
|
||||
client: Client,
|
||||
embed: Omit<API.Embed & { type: "Website" }, "type">
|
||||
embed: Omit<API.Embed & { type: "Website" }, "type">,
|
||||
) {
|
||||
super(client, "Website");
|
||||
|
||||
@@ -179,7 +179,7 @@ export class WebsiteEmbed extends MessageEmbed {
|
||||
return `https://open.spotify.com/embed/${this.specialContent.content_type}/${this.specialContent.id}`;
|
||||
case "Soundcloud":
|
||||
return `https://w.soundcloud.com/player/?url=${encodeURIComponent(
|
||||
this.url!
|
||||
this.url!,
|
||||
)}&color=%23FF7F50&auto_play=false&hide_related=false&show_comments=true&show_user=true&show_reposts=false&show_teaser=true&visual=true`;
|
||||
case "Bandcamp": {
|
||||
return `https://bandcamp.com/EmbeddedPlayer/${this.specialContent.content_type.toLowerCase()}=${
|
||||
@@ -211,7 +211,7 @@ export class TextEmbed extends MessageEmbed {
|
||||
*/
|
||||
constructor(
|
||||
client: Client,
|
||||
embed: Omit<API.Embed & { type: "Text" }, "type">
|
||||
embed: Omit<API.Embed & { type: "Text" }, "type">,
|
||||
) {
|
||||
super(client, "Text");
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ export class ServerPublicInvite extends PublicChannelInvite {
|
||||
return this.client!.servers.getOrCreate(
|
||||
invite.server._id,
|
||||
invite.server,
|
||||
true
|
||||
true,
|
||||
);
|
||||
});
|
||||
} else {
|
||||
|
||||
+44
-44
@@ -77,7 +77,7 @@ export class Server {
|
||||
*/
|
||||
get owner() {
|
||||
return this.#collection.client.users.get(
|
||||
this.#collection.getUnderlyingObject(this.id).ownerId
|
||||
this.#collection.getUnderlyingObject(this.id).ownerId,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -222,7 +222,7 @@ export class Server {
|
||||
|
||||
if (uncategorised.size > 0) {
|
||||
const channels = [...uncategorised].map(
|
||||
(key) => this.#collection.client.channels.get(key)!
|
||||
(key) => this.#collection.client.channels.get(key)!,
|
||||
);
|
||||
|
||||
if (defaultCategory) {
|
||||
@@ -275,7 +275,7 @@ export class Server {
|
||||
*/
|
||||
get mentions() {
|
||||
const arr = this.channels.map((channel) =>
|
||||
Array.from(channel.mentions?.values() ?? [])
|
||||
Array.from(channel.mentions?.values() ?? []),
|
||||
);
|
||||
|
||||
return ([] as string[]).concat(...arr);
|
||||
@@ -327,7 +327,7 @@ export class Server {
|
||||
havePermission(...permission: (keyof typeof Permission)[]) {
|
||||
return bitwiseAndEq(
|
||||
this.permission,
|
||||
...permission.map((x) => Permission[x])
|
||||
...permission.map((x) => Permission[x]),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -339,7 +339,7 @@ export class Server {
|
||||
orPermission(...permission: (keyof typeof Permission)[]) {
|
||||
return (
|
||||
permission.findIndex((x) =>
|
||||
bitwiseAndEq(this.permission, Permission[x])
|
||||
bitwiseAndEq(this.permission, Permission[x]),
|
||||
) !== -1
|
||||
);
|
||||
}
|
||||
@@ -364,7 +364,7 @@ export class Server {
|
||||
async createChannel(data: DataCreateServerChannel) {
|
||||
const channel = await this.#collection.client.api.post(
|
||||
`/servers/${this.id as ""}/channels`,
|
||||
data
|
||||
data,
|
||||
);
|
||||
|
||||
return this.#collection.client.channels.getOrCreate(channel._id, channel);
|
||||
@@ -381,11 +381,11 @@ export class Server {
|
||||
"server",
|
||||
await this.#collection.client.api.patch(
|
||||
`/servers/${this.id as ""}`,
|
||||
data
|
||||
data,
|
||||
),
|
||||
this.#collection.client,
|
||||
false
|
||||
)
|
||||
false,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -396,14 +396,14 @@ export class Server {
|
||||
$delete(leaveEvent?: boolean) {
|
||||
batch(() => {
|
||||
const server = this.#collection.client.servers.getUnderlyingObject(
|
||||
this.id
|
||||
this.id,
|
||||
);
|
||||
|
||||
// Avoid race conditions
|
||||
if (server.id) {
|
||||
this.#collection.client.emit(
|
||||
leaveEvent ? "serverLeave" : "serverDelete",
|
||||
server
|
||||
server,
|
||||
);
|
||||
|
||||
for (const channel of this.channelIds) {
|
||||
@@ -448,18 +448,18 @@ export class Server {
|
||||
*/
|
||||
async banUser(
|
||||
user: string | User | ServerMember,
|
||||
options: DataBanCreate = {}
|
||||
options: DataBanCreate = {},
|
||||
) {
|
||||
const userId =
|
||||
user instanceof User
|
||||
? user.id
|
||||
: user instanceof ServerMember
|
||||
? user.id.user
|
||||
: user;
|
||||
? user.id.user
|
||||
: user;
|
||||
|
||||
const ban = await this.#collection.client.api.put(
|
||||
`/servers/${this.id as ""}/bans/${userId as ""}`,
|
||||
options
|
||||
options,
|
||||
);
|
||||
|
||||
return new ServerBan(this.#collection.client, ban);
|
||||
@@ -475,9 +475,9 @@ export class Server {
|
||||
typeof user === "string"
|
||||
? user
|
||||
: user instanceof User
|
||||
? user.id
|
||||
: user.id.user
|
||||
}`
|
||||
? user.id
|
||||
: user.id.user
|
||||
}`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -488,7 +488,7 @@ export class Server {
|
||||
async unbanUser(user: string | User) {
|
||||
const userId = user instanceof User ? user.id : user;
|
||||
return await this.#collection.client.api.delete(
|
||||
`/servers/${this.id as ""}/bans/${userId}`
|
||||
`/servers/${this.id as ""}/bans/${userId}`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -498,11 +498,11 @@ export class Server {
|
||||
*/
|
||||
async fetchInvites() {
|
||||
const invites = await this.#collection.client.api.get(
|
||||
`/servers/${this.id as ""}/invites`
|
||||
`/servers/${this.id as ""}/invites`,
|
||||
);
|
||||
|
||||
return invites.map((invite) =>
|
||||
ChannelInvite.from(this.#collection.client, invite)
|
||||
ChannelInvite.from(this.#collection.client, invite),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -512,17 +512,17 @@ export class Server {
|
||||
*/
|
||||
async fetchBans() {
|
||||
const { users, bans } = await this.#collection.client.api.get(
|
||||
`/servers/${this.id as ""}/bans`
|
||||
`/servers/${this.id as ""}/bans`,
|
||||
);
|
||||
|
||||
const userDict = users.reduce(
|
||||
(d, c) => ({ ...d, [c._id]: c }),
|
||||
{} as Record<string, BannedUser>
|
||||
{} as Record<string, BannedUser>,
|
||||
);
|
||||
|
||||
return bans.map(
|
||||
(ban) =>
|
||||
new ServerBan(this.#collection.client, ban, userDict[ban._id.user])
|
||||
new ServerBan(this.#collection.client, ban, userDict[ban._id.user]),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -534,7 +534,7 @@ export class Server {
|
||||
async setPermissions(roleId = "default", permissions: Override | number) {
|
||||
return await this.#collection.client.api.put(
|
||||
`/servers/${this.id as ""}/permissions/${roleId as ""}`,
|
||||
{ permissions: permissions as Override }
|
||||
{ permissions: permissions as Override },
|
||||
);
|
||||
}
|
||||
|
||||
@@ -547,7 +547,7 @@ export class Server {
|
||||
`/servers/${this.id as ""}/roles`,
|
||||
{
|
||||
name,
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
@@ -559,7 +559,7 @@ export class Server {
|
||||
async editRole(roleId: string, data: DataEditRole) {
|
||||
return await this.#collection.client.api.patch(
|
||||
`/servers/${this.id as ""}/roles/${roleId as ""}`,
|
||||
data
|
||||
data,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -569,7 +569,7 @@ export class Server {
|
||||
*/
|
||||
async deleteRole(roleId: string) {
|
||||
return await this.#collection.client.api.delete(
|
||||
`/servers/${this.id as ""}/roles/${roleId as ""}`
|
||||
`/servers/${this.id as ""}/roles/${roleId as ""}`,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -600,7 +600,7 @@ export class Server {
|
||||
|
||||
const data = await this.#collection.client.api.get(
|
||||
`/servers/${this.id as ""}/members`,
|
||||
{ exclude_offline: excludeOffline }
|
||||
{ exclude_offline: excludeOffline },
|
||||
);
|
||||
|
||||
batch(() => {
|
||||
@@ -611,7 +611,7 @@ export class Server {
|
||||
this.#collection.client.users.getOrCreate(user._id, user);
|
||||
this.#collection.client.serverMembers.getOrCreate(
|
||||
data.members[i]._id,
|
||||
data.members[i]
|
||||
data.members[i],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -619,11 +619,11 @@ export class Server {
|
||||
for (let i = 0; i < data.users.length; i++) {
|
||||
this.#collection.client.users.getOrCreate(
|
||||
data.users[i]._id,
|
||||
data.users[i]
|
||||
data.users[i],
|
||||
);
|
||||
this.#collection.client.serverMembers.getOrCreate(
|
||||
data.members[i]._id,
|
||||
data.members[i]
|
||||
data.members[i],
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -644,15 +644,15 @@ export class Server {
|
||||
async fetchMembers() {
|
||||
const data = (await this.#collection.client.api.get(
|
||||
// @ts-expect-error TODO weird typing issue
|
||||
`/servers/${this.id as ""}/members`
|
||||
`/servers/${this.id as ""}/members`,
|
||||
)) as AllMemberResponse;
|
||||
|
||||
return batch(() => ({
|
||||
members: data.members.map((member) =>
|
||||
this.#collection.client.serverMembers.getOrCreate(member._id, member)
|
||||
this.#collection.client.serverMembers.getOrCreate(member._id, member),
|
||||
),
|
||||
users: data.users.map((user) =>
|
||||
this.#collection.client.users.getOrCreate(user._id, user)
|
||||
this.#collection.client.users.getOrCreate(user._id, user),
|
||||
),
|
||||
}));
|
||||
}
|
||||
@@ -667,16 +667,16 @@ export class Server {
|
||||
`/servers/${
|
||||
this.id as ""
|
||||
}/members_experimental_query?experimental_api=true&query=${encodeURIComponent(
|
||||
query
|
||||
)}` as never
|
||||
query,
|
||||
)}` as never,
|
||||
)) as AllMemberResponse;
|
||||
|
||||
return batch(() => ({
|
||||
members: data.members.map((member) =>
|
||||
this.#collection.client.serverMembers.getOrCreate(member._id, member)
|
||||
this.#collection.client.serverMembers.getOrCreate(member._id, member),
|
||||
),
|
||||
users: data.users.map((user) =>
|
||||
this.#collection.client.users.getOrCreate(user._id, user)
|
||||
this.#collection.client.users.getOrCreate(user._id, user),
|
||||
),
|
||||
}));
|
||||
}
|
||||
@@ -688,7 +688,7 @@ export class Server {
|
||||
*/
|
||||
async createEmoji(
|
||||
autumnId: string,
|
||||
options: Omit<DataCreateEmoji, "parent">
|
||||
options: Omit<DataCreateEmoji, "parent">,
|
||||
) {
|
||||
const emoji = await this.#collection.client.api.put(
|
||||
`/custom/emoji/${autumnId as ""}`,
|
||||
@@ -698,7 +698,7 @@ export class Server {
|
||||
id: this.id,
|
||||
},
|
||||
...options,
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
return this.#collection.client.emojis.getOrCreate(emoji._id, emoji, true);
|
||||
@@ -710,13 +710,13 @@ export class Server {
|
||||
*/
|
||||
async fetchEmojis() {
|
||||
const emojis = await this.#collection.client.api.get(
|
||||
`/servers/${this.id as ""}/emojis`
|
||||
`/servers/${this.id as ""}/emojis`,
|
||||
);
|
||||
|
||||
return batch(() =>
|
||||
emojis.map((emoji) =>
|
||||
this.#collection.client.emojis.getOrCreate(emoji._id, emoji)
|
||||
)
|
||||
this.#collection.client.emojis.getOrCreate(emoji._id, emoji),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ export class ServerBan {
|
||||
*/
|
||||
async pardon() {
|
||||
await this.client.api.delete(
|
||||
`/servers/${this.id.server as ""}/bans/${this.id.user as ""}`
|
||||
`/servers/${this.id.server as ""}/bans/${this.id.user as ""}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -183,7 +183,7 @@ export class ServerMember {
|
||||
) {
|
||||
return bitwiseAndEq(
|
||||
this.getPermissions(target),
|
||||
...permission.map((x) => Permission[x])
|
||||
...permission.map((x) => Permission[x]),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -224,7 +224,7 @@ export class ServerMember {
|
||||
async edit(data: DataMemberEdit) {
|
||||
await this.#collection.client.api.patch(
|
||||
`/servers/${this.id.server as ""}/members/${this.id.user as ""}`,
|
||||
data
|
||||
data,
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ export class TextSystemMessage extends SystemMessage {
|
||||
*/
|
||||
constructor(
|
||||
client: Client,
|
||||
systemMessage: API.SystemMessage & { type: "text" }
|
||||
systemMessage: API.SystemMessage & { type: "text" },
|
||||
) {
|
||||
super(client, systemMessage.type);
|
||||
this.content = systemMessage.content;
|
||||
@@ -92,7 +92,7 @@ export class UserSystemMessage extends SystemMessage {
|
||||
| "user_left"
|
||||
| "user_kicked"
|
||||
| "user_banned";
|
||||
}
|
||||
},
|
||||
) {
|
||||
super(client, systemMessage.type);
|
||||
this.userId = systemMessage.id;
|
||||
@@ -121,7 +121,7 @@ export class UserModeratedSystemMessage extends UserSystemMessage {
|
||||
client: Client,
|
||||
systemMessage: API.SystemMessage & {
|
||||
type: "user_added" | "user_remove";
|
||||
}
|
||||
},
|
||||
) {
|
||||
super(client, systemMessage);
|
||||
this.byId = systemMessage.by;
|
||||
@@ -154,7 +154,7 @@ export class ChannelEditSystemMessage extends SystemMessage {
|
||||
| "channel_renamed"
|
||||
| "channel_description_changed"
|
||||
| "channel_icon_changed";
|
||||
}
|
||||
},
|
||||
) {
|
||||
super(client, systemMessage.type);
|
||||
this.byId = systemMessage.by;
|
||||
@@ -183,7 +183,7 @@ export class ChannelRenamedSystemMessage extends ChannelEditSystemMessage {
|
||||
client: Client,
|
||||
systemMessage: API.SystemMessage & {
|
||||
type: "channel_renamed";
|
||||
}
|
||||
},
|
||||
) {
|
||||
super(client, systemMessage);
|
||||
this.name = systemMessage.name;
|
||||
@@ -206,7 +206,7 @@ export class ChannelOwnershipChangeSystemMessage extends SystemMessage {
|
||||
client: Client,
|
||||
systemMessage: API.SystemMessage & {
|
||||
type: "channel_ownership_changed";
|
||||
}
|
||||
},
|
||||
) {
|
||||
super(client, systemMessage.type);
|
||||
this.fromId = systemMessage.from;
|
||||
|
||||
+11
-11
@@ -161,7 +161,7 @@ export class User {
|
||||
* Presence
|
||||
*/
|
||||
get presence() {
|
||||
return this.online ? this.status?.presence ?? "Online" : "Invisible";
|
||||
return this.online ? (this.status?.presence ?? "Online") : "Invisible";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -171,8 +171,8 @@ export class User {
|
||||
*/
|
||||
statusMessage(translate: (presence: Presence) => string = (a) => a) {
|
||||
return this.online
|
||||
? this.status?.text ??
|
||||
(this.presence === "Focus" ? translate("Focus") : undefined)
|
||||
? (this.status?.text ??
|
||||
(this.presence === "Focus" ? translate("Focus") : undefined))
|
||||
: undefined;
|
||||
}
|
||||
|
||||
@@ -197,10 +197,10 @@ export class User {
|
||||
this.#collection.client.channels.find(
|
||||
(channel) =>
|
||||
(channel.type === "Group" || channel.type === "DirectMessage") &&
|
||||
channel.recipientIds.has(this.id)
|
||||
channel.recipientIds.has(this.id),
|
||||
) ||
|
||||
this.#collection.client.serverMembers.find(
|
||||
(member) => member.id.user === this.id
|
||||
(member) => member.id.user === this.id,
|
||||
)
|
||||
) {
|
||||
if (this.#collection.client.user?.bot || this.bot) {
|
||||
@@ -222,7 +222,7 @@ export class User {
|
||||
`/users/${
|
||||
this.id === this.#collection.client.user?.id ? "@me" : this.id
|
||||
}`,
|
||||
data
|
||||
data,
|
||||
);
|
||||
}
|
||||
|
||||
@@ -244,7 +244,7 @@ export class User {
|
||||
*/
|
||||
async openDM() {
|
||||
let dm = [...this.#collection.client.channels.values()].find(
|
||||
(x) => x.type === "DirectMessage" && x.recipient == this
|
||||
(x) => x.type === "DirectMessage" && x.recipient == this,
|
||||
);
|
||||
|
||||
if (dm) {
|
||||
@@ -252,12 +252,12 @@ export class User {
|
||||
this.#collection.client.channels.updateUnderlyingObject(
|
||||
dm.id,
|
||||
"active",
|
||||
true
|
||||
true,
|
||||
);
|
||||
}
|
||||
} else {
|
||||
const data = await this.#collection.client.api.get(
|
||||
`/users/${this.id as ""}/dm`
|
||||
`/users/${this.id as ""}/dm`,
|
||||
);
|
||||
|
||||
dm = this.#collection.client.channels.getOrCreate(data._id, data)!;
|
||||
@@ -305,7 +305,7 @@ export class User {
|
||||
async fetchProfile() {
|
||||
return new UserProfile(
|
||||
this.#collection.client,
|
||||
await this.#collection.client.api.get(`/users/${this.id as ""}/profile`)
|
||||
await this.#collection.client.api.get(`/users/${this.id as ""}/profile`),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -315,7 +315,7 @@ export class User {
|
||||
*/
|
||||
async fetchMutual() {
|
||||
return await this.#collection.client.api.get(
|
||||
`/users/${this.id as ""}/mutual`
|
||||
`/users/${this.id as ""}/mutual`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,7 +89,7 @@ export class AccountCollection {
|
||||
confirmPasswordReset(
|
||||
token: string,
|
||||
newPassword: string,
|
||||
removeSessions: boolean
|
||||
removeSessions: boolean,
|
||||
) {
|
||||
return this.client.api.patch("/auth/account/reset_password", {
|
||||
token,
|
||||
|
||||
@@ -32,7 +32,7 @@ export class BotCollection extends ClassCollection<Bot, HydratedBot> {
|
||||
const data = (await this.client.api.get("/bots/@me")) as OwnedBotsResponse;
|
||||
return batch(() => {
|
||||
data.users.forEach((user) =>
|
||||
this.client.users.getOrCreate(user._id, user)
|
||||
this.client.users.getOrCreate(user._id, user),
|
||||
);
|
||||
return data.bots.map((bot) => this.getOrCreate(bot._id, bot));
|
||||
});
|
||||
|
||||
@@ -44,7 +44,7 @@ export class ChannelCollection extends ClassCollection<
|
||||
} else {
|
||||
const instance = new Channel(this, id);
|
||||
this.create(id, "channel", instance, this.client, data);
|
||||
isNew && this.client.emit("channelCreate", instance);
|
||||
if (isNew) this.client.emit("channelCreate", instance);
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ export class ChannelWebhookCollection extends ClassCollection<
|
||||
if (webhook) return webhook;
|
||||
const data = await this.client.api.get(
|
||||
// @ts-expect-error not in prod
|
||||
`/webhooks/${id as ""}/${token as ""}`
|
||||
`/webhooks/${id as ""}/${token as ""}`,
|
||||
);
|
||||
// @ts-expect-error not in prod
|
||||
return this.getOrCreate(data.id, data);
|
||||
|
||||
@@ -59,7 +59,7 @@ export abstract class Collection<T> {
|
||||
* @param cb Callback for each pair
|
||||
*/
|
||||
abstract forEach(
|
||||
cb: (value: T, key: string, map: ReactiveMap<string, T>) => void
|
||||
cb: (value: T, key: string, map: ReactiveMap<string, T>) => void,
|
||||
): void;
|
||||
|
||||
/**
|
||||
@@ -169,7 +169,7 @@ export abstract class StoreCollection<T, V> extends Collection<T> {
|
||||
type: keyof Hydrators,
|
||||
instance: T,
|
||||
context: unknown,
|
||||
data?: unknown
|
||||
data?: unknown,
|
||||
) {
|
||||
this.#storage.hydrate(id, type, context, data);
|
||||
this.#objects.set(id, instance);
|
||||
|
||||
@@ -31,7 +31,7 @@ export class EmojiCollection extends ClassCollection<Emoji, HydratedEmoji> {
|
||||
} else {
|
||||
const instance = new Emoji(this, id);
|
||||
this.create(id, "emoji", instance, this.client, data);
|
||||
isNew && this.client.emit("emojiCreate", instance);
|
||||
if (isNew) this.client.emit("emojiCreate", instance);
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ export class MessageCollection extends ClassCollection<
|
||||
if (message && !this.isPartial(messageId)) return message;
|
||||
|
||||
const data = await this.client.api.get(
|
||||
`/channels/${channelId as ""}/messages/${messageId as ""}`
|
||||
`/channels/${channelId as ""}/messages/${messageId as ""}`,
|
||||
);
|
||||
|
||||
return this.getOrCreate(data._id, data, false);
|
||||
@@ -39,7 +39,7 @@ export class MessageCollection extends ClassCollection<
|
||||
} else {
|
||||
const instance = new Message(this, id);
|
||||
this.create(id, "message", instance, this.client, data);
|
||||
isNew && this.client.emit("messageCreate", instance);
|
||||
if (isNew) this.client.emit("messageCreate", instance);
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ export class ServerCollection extends ClassCollection<Server, HydratedServer> {
|
||||
} else {
|
||||
const instance = new Server(this, id);
|
||||
this.create(id, "server", instance, this.client, data);
|
||||
isNew && this.client.emit("serverCreate", instance);
|
||||
if (isNew) this.client.emit("serverCreate", instance);
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
@@ -78,7 +78,7 @@ export class ServerCollection extends ClassCollection<Server, HydratedServer> {
|
||||
async createServer(data: DataCreateServer) {
|
||||
const { server, channels } = await this.client.api.post(
|
||||
`/servers/create`,
|
||||
data
|
||||
data,
|
||||
);
|
||||
|
||||
return batch(() => {
|
||||
|
||||
@@ -51,7 +51,7 @@ export class ServerMemberCollection extends ClassCollection<
|
||||
`/servers/${serverId as ""}/members/${userId as ""}`,
|
||||
{
|
||||
roles: false,
|
||||
}
|
||||
},
|
||||
// TODO: fix typings in revolt-api
|
||||
)) as API.Member;
|
||||
|
||||
@@ -73,7 +73,7 @@ export class ServerMemberCollection extends ClassCollection<
|
||||
"serverMember",
|
||||
instance,
|
||||
this.client,
|
||||
data
|
||||
data,
|
||||
);
|
||||
return instance;
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ export class SessionCollection extends ClassCollection<
|
||||
async fetch(): Promise<Session[]> {
|
||||
const data = await this.client.api.get("/auth/session/all");
|
||||
return batch(() =>
|
||||
data.map((session) => this.getOrCreate(session._id, session))
|
||||
data.map((session) => this.getOrCreate(session._id, session)),
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Accessor, createSignal, Setter } from "solid-js";
|
||||
import { Accessor, Setter, createSignal } from "solid-js";
|
||||
|
||||
import { AsyncEventEmitter } from "@vladfrangu/async_event_emitter";
|
||||
import { Error } from "revolt-api";
|
||||
@@ -56,10 +56,9 @@ type Events<T extends AvailableProtocols, P extends EventProtocol<T>> = {
|
||||
/**
|
||||
* Simple wrapper around the Revolt websocket service.
|
||||
*/
|
||||
export class EventClient<T extends AvailableProtocols>
|
||||
extends AsyncEventEmitter<
|
||||
Events<T, EventProtocol<T>>
|
||||
> {
|
||||
export class EventClient<
|
||||
T extends AvailableProtocols,
|
||||
> extends AsyncEventEmitter<Events<T, EventProtocol<T>>> {
|
||||
readonly options: EventClientOptions;
|
||||
|
||||
#protocolVersion: T;
|
||||
@@ -77,7 +76,7 @@ export class EventClient<T extends AvailableProtocols>
|
||||
#connectTimeoutReference: number | undefined;
|
||||
|
||||
#lastError: // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
{ type: "socket"; data: any } | { type: "revolt"; data: Error } | undefined;
|
||||
{ type: "socket"; data: any } | { type: "revolt"; data: Error } | undefined;
|
||||
|
||||
/**
|
||||
* Create a new event client.
|
||||
@@ -195,7 +194,7 @@ export class EventClient<T extends AvailableProtocols>
|
||||
* @param event Event
|
||||
*/
|
||||
send(event: EventProtocol<T>["client"]) {
|
||||
this.options.debug && console.debug("[C->S]", event);
|
||||
if (this.options.debug) console.debug("[C->S]", event);
|
||||
if (!this.#socket) throw "Socket closed, trying to send.";
|
||||
this.#socket.send(JSON.stringify(event));
|
||||
}
|
||||
@@ -205,7 +204,7 @@ export class EventClient<T extends AvailableProtocols>
|
||||
* @param event Event
|
||||
*/
|
||||
handle(event: EventProtocol<T>["server"]) {
|
||||
this.options.debug && console.debug("[S->C]", event);
|
||||
if (this.options.debug) console.debug("[S->C]", event);
|
||||
switch (event.type) {
|
||||
case "Ping":
|
||||
this.send({
|
||||
@@ -216,7 +215,7 @@ export class EventClient<T extends AvailableProtocols>
|
||||
case "Pong":
|
||||
clearTimeout(this.#pongTimeoutReference);
|
||||
this.#setPing(+new Date() - event.data);
|
||||
this.options.debug && console.debug(`[ping] ${this.ping()}ms`);
|
||||
if (this.options.debug) console.debug(`[ping] ${this.ping()}ms`);
|
||||
return;
|
||||
case "Error":
|
||||
this.#lastError = {
|
||||
|
||||
+22
-22
@@ -188,7 +188,7 @@ type ReadyData = {
|
||||
export async function handleEvent(
|
||||
client: Client,
|
||||
event: ServerMessage,
|
||||
setReady: Setter<boolean>
|
||||
setReady: Setter<boolean>,
|
||||
) {
|
||||
if (client.options.debug) {
|
||||
console.debug("[S->C]", event);
|
||||
@@ -255,7 +255,7 @@ export async function handleEvent(
|
||||
client.channels.updateUnderlyingObject(
|
||||
event.channel,
|
||||
"lastMessageId",
|
||||
event._id
|
||||
event._id,
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -274,7 +274,7 @@ export async function handleEvent(
|
||||
"message",
|
||||
{ ...event.data, channel: event.channel },
|
||||
client,
|
||||
false
|
||||
false,
|
||||
),
|
||||
editedAt: new Date(),
|
||||
});
|
||||
@@ -294,14 +294,14 @@ export async function handleEvent(
|
||||
client.messages.updateUnderlyingObject(event.id, "embeds", (embeds) => [
|
||||
...(embeds ?? []),
|
||||
...(event.append.embeds?.map((embed) =>
|
||||
MessageEmbed.from(client, embed)
|
||||
MessageEmbed.from(client, embed),
|
||||
) ?? []),
|
||||
]);
|
||||
|
||||
client.messages.updateUnderlyingObject(
|
||||
event.id,
|
||||
"channelId",
|
||||
event.channel
|
||||
event.channel,
|
||||
);
|
||||
|
||||
client.emit("messageUpdate", message, previousMessage);
|
||||
@@ -331,8 +331,8 @@ export async function handleEvent(
|
||||
return undefined!;
|
||||
})
|
||||
.filter((x) => x),
|
||||
client.channels.get(event.channel)
|
||||
)
|
||||
client.channels.get(event.channel),
|
||||
),
|
||||
);
|
||||
break;
|
||||
}
|
||||
@@ -352,7 +352,7 @@ export async function handleEvent(
|
||||
"messageReactionAdd",
|
||||
message,
|
||||
event.user_id,
|
||||
event.emoji_id
|
||||
event.emoji_id,
|
||||
);
|
||||
}
|
||||
break;
|
||||
@@ -371,7 +371,7 @@ export async function handleEvent(
|
||||
"messageReactionRemove",
|
||||
message,
|
||||
event.user_id,
|
||||
event.emoji_id
|
||||
event.emoji_id,
|
||||
);
|
||||
}
|
||||
break;
|
||||
@@ -446,7 +446,7 @@ export async function handleEvent(
|
||||
client.emit(
|
||||
"channelGroupJoin",
|
||||
channel,
|
||||
await client.users.fetch(event.user)
|
||||
await client.users.fetch(event.user),
|
||||
);
|
||||
}
|
||||
break;
|
||||
@@ -463,7 +463,7 @@ export async function handleEvent(
|
||||
client.emit(
|
||||
"channelGroupLeave",
|
||||
channel,
|
||||
client.users.getOrPartial(event.user)!
|
||||
client.users.getOrPartial(event.user)!,
|
||||
);
|
||||
}
|
||||
break;
|
||||
@@ -480,7 +480,7 @@ export async function handleEvent(
|
||||
client.emit(
|
||||
"channelStartTyping",
|
||||
channel,
|
||||
client.users.getOrPartial(event.user)!
|
||||
client.users.getOrPartial(event.user)!,
|
||||
);
|
||||
}
|
||||
break;
|
||||
@@ -497,7 +497,7 @@ export async function handleEvent(
|
||||
client.emit(
|
||||
"channelStopTyping",
|
||||
channel,
|
||||
client.users.getOrPartial(event.user)!
|
||||
client.users.getOrPartial(event.user)!,
|
||||
);
|
||||
}
|
||||
break;
|
||||
@@ -612,7 +612,7 @@ export async function handleEvent(
|
||||
client.serverMembers.getOrCreate(id, {
|
||||
_id: id,
|
||||
joined_at: new Date().toUTCString(),
|
||||
})
|
||||
}),
|
||||
);
|
||||
}
|
||||
break;
|
||||
@@ -622,7 +622,7 @@ export async function handleEvent(
|
||||
if (member) {
|
||||
const previousMember = {
|
||||
...client.serverMembers.getUnderlyingObject(
|
||||
event.id.server + event.id.user
|
||||
event.id.server + event.id.user,
|
||||
),
|
||||
};
|
||||
|
||||
@@ -649,7 +649,7 @@ export async function handleEvent(
|
||||
|
||||
client.serverMembers.updateUnderlyingObject(
|
||||
event.id.server + event.id.user,
|
||||
changes as never
|
||||
changes as never,
|
||||
);
|
||||
|
||||
client.emit("serverMemberUpdate", member, previousMember);
|
||||
@@ -664,7 +664,7 @@ export async function handleEvent(
|
||||
type: "ServerDelete",
|
||||
id: event.id,
|
||||
},
|
||||
setReady
|
||||
setReady,
|
||||
);
|
||||
|
||||
return;
|
||||
@@ -677,7 +677,7 @@ export async function handleEvent(
|
||||
|
||||
if (client.serverMembers.getOrPartial(id)) {
|
||||
const member = client.serverMembers.getUnderlyingObject(
|
||||
id.server + id.user
|
||||
id.server + id.user,
|
||||
);
|
||||
|
||||
client.emit("serverMemberLeave", member);
|
||||
@@ -733,7 +733,7 @@ export async function handleEvent(
|
||||
relationship: event.user.relationship!,
|
||||
},
|
||||
},
|
||||
setReady
|
||||
setReady,
|
||||
);
|
||||
break;
|
||||
}
|
||||
@@ -747,7 +747,7 @@ export async function handleEvent(
|
||||
online: event.online,
|
||||
},
|
||||
},
|
||||
setReady
|
||||
setReady,
|
||||
);
|
||||
break;
|
||||
}
|
||||
@@ -767,7 +767,7 @@ export async function handleEvent(
|
||||
.filter((message) => message.authorId === event.user_id)
|
||||
.map((message) => message.id),
|
||||
},
|
||||
setReady
|
||||
setReady,
|
||||
);
|
||||
|
||||
handleEvent(
|
||||
@@ -784,7 +784,7 @@ export async function handleEvent(
|
||||
},
|
||||
clear: ["Avatar", "StatusPresence", "StatusText"],
|
||||
},
|
||||
setReady
|
||||
setReady,
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -55,19 +55,20 @@ export type Hydrate<Input, Output> = {
|
||||
function hydrateInternal<Input extends object, Output>(
|
||||
hydration: Hydrate<Input, Output>,
|
||||
input: Input,
|
||||
context: unknown
|
||||
context: unknown,
|
||||
): Output {
|
||||
return (Object.keys(input) as (keyof Input)[]).reduce((acc, key) => {
|
||||
let targetKey, value;
|
||||
try {
|
||||
targetKey = hydration.keyMapping[key] ?? key;
|
||||
value = hydration.functions[targetKey as keyof Output](input, context);
|
||||
} catch (err) {
|
||||
if (key === "partial")
|
||||
} catch {
|
||||
if (key === "partial") {
|
||||
return {
|
||||
...acc,
|
||||
partial: input["partial" as never],
|
||||
};
|
||||
}
|
||||
if (key === "type") return acc;
|
||||
console.debug(`Skipping key ${String(key)} during hydration!`);
|
||||
return acc;
|
||||
@@ -112,11 +113,11 @@ export function hydrate<T extends keyof Hydrators>(
|
||||
type: T,
|
||||
input: Partial<ExtractInput<Hydrators[T]>>,
|
||||
context: unknown,
|
||||
initial?: boolean
|
||||
initial?: boolean,
|
||||
) {
|
||||
return hydrateInternal(
|
||||
hydrators[type] as never,
|
||||
initial ? { ...hydrators[type].initialHydration(), ...input } : input,
|
||||
context
|
||||
context,
|
||||
) as ExtractOutput<Hydrators[T]>;
|
||||
}
|
||||
|
||||
@@ -52,7 +52,7 @@ export const serverHydration: Hydrate<ApiServer, HydratedServer> = {
|
||||
systemMessages: (server) => server.system_messages ?? {},
|
||||
roles: (server) =>
|
||||
new ReactiveMap(
|
||||
Object.keys(server.roles!).map((id) => [id, server.roles![id]])
|
||||
Object.keys(server.roles!).map((id) => [id, server.roles![id]]),
|
||||
),
|
||||
defaultPermissions: (server) => server.default_permissions,
|
||||
icon: (server, ctx) => new File(ctx as Client, server.icon!),
|
||||
|
||||
+2
-3
@@ -5,9 +5,8 @@ export type Merge<T extends object> = {
|
||||
[k in NonCommonKeys<T>]?: PickTypeOf<T, k>;
|
||||
};
|
||||
|
||||
type PickTypeOf<T, K extends string | number | symbol> = K extends AllKeys<T>
|
||||
? PickType<T, K>
|
||||
: never;
|
||||
type PickTypeOf<T, K extends string | number | symbol> =
|
||||
K extends AllKeys<T> ? PickType<T, K> : never;
|
||||
|
||||
// eslint-disable-next-line
|
||||
type PickType<T, K extends AllKeys<T>> = T extends { [k in K]?: any }
|
||||
|
||||
@@ -63,7 +63,7 @@ export function calculatePermission(
|
||||
);
|
||||
|
||||
for (const permission of permissions) {
|
||||
perm = (perm | BigInt(permission.a)) & (~BigInt(permission.d));
|
||||
perm = (perm | BigInt(permission.a)) & ~BigInt(permission.d);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,14 +119,13 @@ export function calculatePermission(
|
||||
if (!member) return 0;
|
||||
|
||||
// 5. Calculate server base permissions.
|
||||
let perm = BigInt(
|
||||
calculatePermission(client, server, options),
|
||||
);
|
||||
let perm = BigInt(calculatePermission(client, server, options));
|
||||
|
||||
// 6. Apply default allows and denies for channel.
|
||||
if (target.defaultPermissions) {
|
||||
perm = (perm | BigInt(target.defaultPermissions.a)) &
|
||||
(~BigInt(target.defaultPermissions.d));
|
||||
perm =
|
||||
(perm | BigInt(target.defaultPermissions.a)) &
|
||||
~BigInt(target.defaultPermissions.d);
|
||||
}
|
||||
|
||||
// 7. If user has roles, iterate in order.
|
||||
@@ -137,7 +136,7 @@ export function calculatePermission(
|
||||
for (const id of roles) {
|
||||
const override = target.rolePermissions[id];
|
||||
if (override) {
|
||||
perm = (perm & BigInt(override.a)) & (~BigInt(override.d));
|
||||
perm = perm & BigInt(override.a) & ~BigInt(override.d);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user