mirror of
https://github.com/stoatchat/javascript-client-sdk.git
synced 2026-07-20 20:16:06 -04:00
refactor: hide collection from other objects
This commit is contained in:
+67
-65
@@ -1,5 +1,4 @@
|
||||
import type {
|
||||
Channel as ApiChannel,
|
||||
Member as ApiMember,
|
||||
Message as ApiMessage,
|
||||
User as ApiUser,
|
||||
@@ -20,7 +19,7 @@ import { Permission } from "../permissions/definitions";
|
||||
* Channel Class
|
||||
*/
|
||||
export class Channel {
|
||||
readonly collection: ChannelCollection;
|
||||
readonly #collection: ChannelCollection;
|
||||
readonly id: string;
|
||||
|
||||
/**
|
||||
@@ -28,8 +27,8 @@ export class Channel {
|
||||
* @param collection Collection
|
||||
* @param id Channel Id
|
||||
*/
|
||||
constructor(collection: ChannelCollection, id: string, data?: ApiChannel) {
|
||||
this.collection = collection;
|
||||
constructor(collection: ChannelCollection, id: string) {
|
||||
this.#collection = collection;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@@ -44,7 +43,7 @@ export class Channel {
|
||||
* Channel type
|
||||
*/
|
||||
get type() {
|
||||
return this.collection.getUnderlyingObject(this.id).channelType;
|
||||
return this.#collection.getUnderlyingObject(this.id).channelType;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -62,42 +61,42 @@ export class Channel {
|
||||
* URL to this channel
|
||||
*/
|
||||
get url() {
|
||||
return this.collection.client.configuration?.app + this.path;
|
||||
return this.#collection.client.configuration?.app + this.path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Channel name
|
||||
*/
|
||||
get name() {
|
||||
return this.collection.getUnderlyingObject(this.id).name;
|
||||
return this.#collection.getUnderlyingObject(this.id).name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Channel description
|
||||
*/
|
||||
get description() {
|
||||
return this.collection.getUnderlyingObject(this.id).description;
|
||||
return this.#collection.getUnderlyingObject(this.id).description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Channel icon
|
||||
*/
|
||||
get icon() {
|
||||
return this.collection.getUnderlyingObject(this.id).icon;
|
||||
return this.#collection.getUnderlyingObject(this.id).icon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the conversation is active
|
||||
*/
|
||||
get active() {
|
||||
return this.collection.getUnderlyingObject(this.id).active;
|
||||
return this.#collection.getUnderlyingObject(this.id).active;
|
||||
}
|
||||
|
||||
/**
|
||||
* User ids of people currently typing in channel
|
||||
*/
|
||||
get typingIds() {
|
||||
return this.collection.getUnderlyingObject(this.id).recipientIds;
|
||||
return this.#collection.getUnderlyingObject(this.id).recipientIds;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -105,15 +104,15 @@ export class Channel {
|
||||
*/
|
||||
get typing() {
|
||||
return [
|
||||
...this.collection.getUnderlyingObject(this.id).typingIds.values(),
|
||||
].map((id) => this.collection.client.users.get(id)!);
|
||||
...this.#collection.getUnderlyingObject(this.id).typingIds.values(),
|
||||
].map((id) => this.#collection.client.users.get(id)!);
|
||||
}
|
||||
|
||||
/**
|
||||
* User ids of recipients of the group
|
||||
*/
|
||||
get recipientIds() {
|
||||
return this.collection.getUnderlyingObject(this.id).recipientIds;
|
||||
return this.#collection.getUnderlyingObject(this.id).recipientIds;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -121,8 +120,8 @@ export class Channel {
|
||||
*/
|
||||
get recipients() {
|
||||
return [
|
||||
...this.collection.getUnderlyingObject(this.id).recipientIds.values(),
|
||||
].map((id) => this.collection.client.users.get(id)!);
|
||||
...this.#collection.getUnderlyingObject(this.id).recipientIds.values(),
|
||||
].map((id) => this.#collection.client.users.get(id)!);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -131,7 +130,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;
|
||||
}
|
||||
@@ -140,15 +139,15 @@ export class Channel {
|
||||
* User ID
|
||||
*/
|
||||
get userId() {
|
||||
return this.collection.getUnderlyingObject(this.id).userId!;
|
||||
return this.#collection.getUnderlyingObject(this.id).userId!;
|
||||
}
|
||||
|
||||
/**
|
||||
* User this channel belongs to
|
||||
*/
|
||||
get user() {
|
||||
return this.collection.client.users.get(
|
||||
this.collection.getUnderlyingObject(this.id).userId!
|
||||
return this.#collection.client.users.get(
|
||||
this.#collection.getUnderlyingObject(this.id).userId!
|
||||
);
|
||||
}
|
||||
|
||||
@@ -156,15 +155,15 @@ export class Channel {
|
||||
* Owner ID
|
||||
*/
|
||||
get ownerId() {
|
||||
return this.collection.getUnderlyingObject(this.id).ownerId!;
|
||||
return this.#collection.getUnderlyingObject(this.id).ownerId!;
|
||||
}
|
||||
|
||||
/**
|
||||
* Owner of the group
|
||||
*/
|
||||
get owner() {
|
||||
return this.collection.client.users.get(
|
||||
this.collection.getUnderlyingObject(this.id).ownerId!
|
||||
return this.#collection.client.users.get(
|
||||
this.#collection.getUnderlyingObject(this.id).ownerId!
|
||||
);
|
||||
}
|
||||
|
||||
@@ -172,15 +171,15 @@ export class Channel {
|
||||
* Server ID
|
||||
*/
|
||||
get serverId() {
|
||||
return this.collection.getUnderlyingObject(this.id).serverId!;
|
||||
return this.#collection.getUnderlyingObject(this.id).serverId!;
|
||||
}
|
||||
|
||||
/**
|
||||
* Server this channel is in
|
||||
*/
|
||||
get server() {
|
||||
return this.collection.client.servers.get(
|
||||
this.collection.getUnderlyingObject(this.id).serverId!
|
||||
return this.#collection.client.servers.get(
|
||||
this.#collection.getUnderlyingObject(this.id).serverId!
|
||||
);
|
||||
}
|
||||
|
||||
@@ -188,35 +187,35 @@ export class Channel {
|
||||
* Permissions allowed for users in this group
|
||||
*/
|
||||
get permissions() {
|
||||
return this.collection.getUnderlyingObject(this.id).permissions;
|
||||
return this.#collection.getUnderlyingObject(this.id).permissions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default permissions for this server channel
|
||||
*/
|
||||
get defaultPermissions() {
|
||||
return this.collection.getUnderlyingObject(this.id).defaultPermissions;
|
||||
return this.#collection.getUnderlyingObject(this.id).defaultPermissions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Role permissions for this server channel
|
||||
*/
|
||||
get rolePermissions() {
|
||||
return this.collection.getUnderlyingObject(this.id).rolePermissions;
|
||||
return this.#collection.getUnderlyingObject(this.id).rolePermissions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this channel is marked as mature
|
||||
*/
|
||||
get mature() {
|
||||
return this.collection.getUnderlyingObject(this.id).nsfw;
|
||||
return this.#collection.getUnderlyingObject(this.id).nsfw;
|
||||
}
|
||||
|
||||
/**
|
||||
* ID of the last message sent in this channel
|
||||
*/
|
||||
get lastMessageId() {
|
||||
return this.collection.getUnderlyingObject(this.id).lastMessageId;
|
||||
return this.#collection.getUnderlyingObject(this.id).lastMessageId;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -249,7 +248,7 @@ export class Channel {
|
||||
* URL to the channel icon
|
||||
*/
|
||||
get iconURL() {
|
||||
return this.collection.client.createFileURL(
|
||||
return this.#collection.client.createFileURL(
|
||||
this.icon ?? this.recipient?.avatar,
|
||||
{
|
||||
max_side: 256,
|
||||
@@ -261,7 +260,7 @@ export class Channel {
|
||||
* URL to a small variant of the channel icon
|
||||
*/
|
||||
get smallIconURL() {
|
||||
return this.collection.client.createFileURL(
|
||||
return this.#collection.client.createFileURL(
|
||||
this.icon ?? this.recipient?.avatar,
|
||||
{
|
||||
max_side: 64,
|
||||
@@ -273,7 +272,7 @@ export class Channel {
|
||||
* URL to the animated channel icon
|
||||
*/
|
||||
get animatedIconURL() {
|
||||
return this.collection.client.createFileURL(
|
||||
return this.#collection.client.createFileURL(
|
||||
this.icon ?? this.recipient?.avatar,
|
||||
{ max_side: 256 },
|
||||
true
|
||||
@@ -284,7 +283,7 @@ export class Channel {
|
||||
* Permission the currently authenticated user has against this channel
|
||||
*/
|
||||
get permission() {
|
||||
return calculatePermission(this.collection.client, this);
|
||||
return calculatePermission(this.#collection.client, this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -305,12 +304,12 @@ export class Channel {
|
||||
* @returns An array of the channel's members.
|
||||
*/
|
||||
async fetchMembers() {
|
||||
const members = await this.collection.client.api.get(
|
||||
const members = await this.#collection.client.api.get(
|
||||
`/channels/${this.id as ""}/members`
|
||||
);
|
||||
|
||||
return members.map((user) =>
|
||||
this.collection.client.users.getOrCreate(user._id, user)
|
||||
this.#collection.client.users.getOrCreate(user._id, user)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -319,7 +318,7 @@ export class Channel {
|
||||
* @param data Edit data
|
||||
*/
|
||||
async edit(data: DataEditChannel) {
|
||||
await this.collection.client.api.patch(`/channels/${this.id as ""}`, data);
|
||||
await this.#collection.client.api.patch(`/channels/${this.id as ""}`, data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -330,16 +329,16 @@ export class Channel {
|
||||
*/
|
||||
async delete(leave_silently?: boolean, noRequest?: boolean) {
|
||||
if (!noRequest)
|
||||
await this.collection.client.api.delete(`/channels/${this.id as ""}`, {
|
||||
await this.#collection.client.api.delete(`/channels/${this.id as ""}`, {
|
||||
leave_silently,
|
||||
});
|
||||
|
||||
if (this.type === "DirectMessage") {
|
||||
this.collection.updateUnderlyingObject(this.id, "active", false);
|
||||
this.#collection.updateUnderlyingObject(this.id, "active", false);
|
||||
return;
|
||||
}
|
||||
|
||||
this.collection.client.channels.delete(this.id);
|
||||
this.#collection.client.channels.delete(this.id);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -347,7 +346,7 @@ export class Channel {
|
||||
* @param user_id ID of the target user
|
||||
*/
|
||||
async addMember(user_id: string) {
|
||||
return await this.collection.client.api.put(
|
||||
return await this.#collection.client.api.put(
|
||||
`/channels/${this.id as ""}/recipients/${user_id as ""}`
|
||||
);
|
||||
}
|
||||
@@ -357,7 +356,7 @@ export class Channel {
|
||||
* @param user_id ID of the target user
|
||||
*/
|
||||
async removeMember(user_id: string) {
|
||||
return await this.collection.client.api.delete(
|
||||
return await this.#collection.client.api.delete(
|
||||
`/channels/${this.id as ""}/recipients/${user_id as ""}`
|
||||
);
|
||||
}
|
||||
@@ -373,7 +372,7 @@ export class Channel {
|
||||
const msg: DataMessageSend =
|
||||
typeof data === "string" ? { content: data } : data;
|
||||
|
||||
const message = await this.collection.client.api.post(
|
||||
const message = await this.#collection.client.api.post(
|
||||
`/channels/${this.id as ""}/messages`,
|
||||
msg,
|
||||
{
|
||||
@@ -383,7 +382,7 @@ export class Channel {
|
||||
}
|
||||
);
|
||||
|
||||
return this.collection.client.messages.getOrCreate(
|
||||
return this.#collection.client.messages.getOrCreate(
|
||||
message._id,
|
||||
message,
|
||||
true
|
||||
@@ -396,11 +395,11 @@ export class Channel {
|
||||
* @returns The message
|
||||
*/
|
||||
async fetchMessage(messageId: string) {
|
||||
const message = await this.collection.client.api.get(
|
||||
const message = await this.#collection.client.api.get(
|
||||
`/channels/${this.id as ""}/messages/${messageId as ""}`
|
||||
);
|
||||
|
||||
return this.collection.client.messages.getOrCreate(message._id, message);
|
||||
return this.#collection.client.messages.getOrCreate(message._id, message);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -417,13 +416,13 @@ export class Channel {
|
||||
"include_users"
|
||||
>
|
||||
) {
|
||||
const messages = (await this.collection.client.api.get(
|
||||
const messages = (await this.#collection.client.api.get(
|
||||
`/channels/${this.id as ""}/messages`,
|
||||
{ ...params }
|
||||
)) as ApiMessage[];
|
||||
|
||||
return messages.map((message) =>
|
||||
this.collection.client.messages.getOrCreate(message._id, message)
|
||||
this.#collection.client.messages.getOrCreate(message._id, message)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -441,20 +440,20 @@ export class Channel {
|
||||
"include_users"
|
||||
>
|
||||
) {
|
||||
const data = (await this.collection.client.api.get(
|
||||
const data = (await this.#collection.client.api.get(
|
||||
`/channels/${this.id as ""}/messages`,
|
||||
{ ...params, include_users: true }
|
||||
)) as { messages: ApiMessage[]; users: ApiUser[]; members?: ApiMember[] };
|
||||
|
||||
return {
|
||||
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)
|
||||
),
|
||||
};
|
||||
}
|
||||
@@ -465,13 +464,13 @@ export class Channel {
|
||||
* @returns The messages
|
||||
*/
|
||||
async search(params: Omit<OptionsMessageSearch, "include_users">) {
|
||||
const messages = (await this.collection.client.api.post(
|
||||
const messages = (await this.#collection.client.api.post(
|
||||
`/channels/${this.id as ""}/search`,
|
||||
params
|
||||
)) as ApiMessage[];
|
||||
|
||||
return messages.map((message) =>
|
||||
this.collection.client.messages.getOrCreate(message._id, message)
|
||||
this.#collection.client.messages.getOrCreate(message._id, message)
|
||||
);
|
||||
}
|
||||
|
||||
@@ -481,7 +480,7 @@ export class Channel {
|
||||
* @returns The messages
|
||||
*/
|
||||
async searchWithUsers(params: Omit<OptionsMessageSearch, "include_users">) {
|
||||
const data = (await this.collection.client.api.post(
|
||||
const data = (await this.#collection.client.api.post(
|
||||
`/channels/${this.id as ""}/search`,
|
||||
{
|
||||
...params,
|
||||
@@ -491,19 +490,19 @@ export class Channel {
|
||||
|
||||
return {
|
||||
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)
|
||||
),
|
||||
};
|
||||
}
|
||||
|
||||
async deleteMessages(ids: string[]) {
|
||||
await this.collection.client.api.delete(
|
||||
await this.#collection.client.api.delete(
|
||||
`/channels/${this.id as ""}/messages/bulk`,
|
||||
{
|
||||
data: { ids },
|
||||
@@ -516,7 +515,7 @@ export class Channel {
|
||||
* @returns Newly created invite code
|
||||
*/
|
||||
async createInvite() {
|
||||
return await this.collection.client.api.post(
|
||||
return await this.#collection.client.api.post(
|
||||
`/channels/${this.id as ""}/invites`
|
||||
);
|
||||
}
|
||||
@@ -537,7 +536,7 @@ export class Channel {
|
||||
|
||||
const performAck = () => {
|
||||
this.#ackLimit = undefined;
|
||||
this.collection.client.api.put(`/channels/${this.id}/ack/${id as ""}`);
|
||||
this.#collection.client.api.put(`/channels/${this.id}/ack/${id as ""}`);
|
||||
};
|
||||
|
||||
// TODO: !this.collection.client.options.ackRateLimiter
|
||||
@@ -562,7 +561,7 @@ export class Channel {
|
||||
* @param permissions Permission value
|
||||
*/
|
||||
async setPermissions(role_id = "default", permissions: Override) {
|
||||
return await this.collection.client.api.put(
|
||||
return await this.#collection.client.api.put(
|
||||
`/channels/${this.id as ""}/permissions/${role_id as ""}`,
|
||||
{ permissions }
|
||||
);
|
||||
@@ -572,7 +571,7 @@ export class Channel {
|
||||
* Start typing in this channel
|
||||
*/
|
||||
startTyping() {
|
||||
this.collection.client.events.send({
|
||||
this.#collection.client.events.send({
|
||||
type: "BeginTyping",
|
||||
channel: this.id,
|
||||
});
|
||||
@@ -582,6 +581,9 @@ export class Channel {
|
||||
* Stop typing in this channel
|
||||
*/
|
||||
stopTyping() {
|
||||
this.collection.client.events.send({ type: "EndTyping", channel: this.id });
|
||||
this.#collection.client.events.send({
|
||||
type: "EndTyping",
|
||||
channel: this.id,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
+9
-10
@@ -1,4 +1,3 @@
|
||||
import type { Emoji as ApiEmoji } from "revolt-api";
|
||||
import { decodeTime } from "ulid";
|
||||
|
||||
import { EmojiCollection } from "../collections";
|
||||
@@ -7,7 +6,7 @@ import { EmojiCollection } from "../collections";
|
||||
* Emoji Class
|
||||
*/
|
||||
export class Emoji {
|
||||
readonly collection: EmojiCollection;
|
||||
readonly #collection: EmojiCollection;
|
||||
readonly id: string;
|
||||
|
||||
/**
|
||||
@@ -15,8 +14,8 @@ export class Emoji {
|
||||
* @param collection Collection
|
||||
* @param id Emoji Id
|
||||
*/
|
||||
constructor(collection: EmojiCollection, id: string, data?: ApiEmoji) {
|
||||
this.collection = collection;
|
||||
constructor(collection: EmojiCollection, id: string) {
|
||||
this.#collection = collection;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@@ -31,15 +30,15 @@ export class Emoji {
|
||||
* Information about the parent of this emoji
|
||||
*/
|
||||
get parent() {
|
||||
return this.collection.getUnderlyingObject(this.id).parent;
|
||||
return this.#collection.getUnderlyingObject(this.id).parent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creator of the emoji
|
||||
*/
|
||||
get creator() {
|
||||
return this.collection.client.users.get(
|
||||
this.collection.getUnderlyingObject(this.id).creatorId
|
||||
return this.#collection.client.users.get(
|
||||
this.#collection.getUnderlyingObject(this.id).creatorId
|
||||
);
|
||||
}
|
||||
|
||||
@@ -47,20 +46,20 @@ export class Emoji {
|
||||
* Name
|
||||
*/
|
||||
get name() {
|
||||
return this.collection.getUnderlyingObject(this.id).name;
|
||||
return this.#collection.getUnderlyingObject(this.id).name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the emoji is animated
|
||||
*/
|
||||
get animated() {
|
||||
return this.collection.getUnderlyingObject(this.id).animated;
|
||||
return this.#collection.getUnderlyingObject(this.id).animated;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the emoji is marked as mature
|
||||
*/
|
||||
get mature() {
|
||||
return this.collection.getUnderlyingObject(this.id).nsfw;
|
||||
return this.#collection.getUnderlyingObject(this.id).nsfw;
|
||||
}
|
||||
}
|
||||
|
||||
+28
-28
@@ -7,7 +7,7 @@ import { MessageCollection } from "../collections";
|
||||
* Message Class
|
||||
*/
|
||||
export class Message {
|
||||
readonly collection: MessageCollection;
|
||||
readonly #collection: MessageCollection;
|
||||
readonly id: string;
|
||||
|
||||
/**
|
||||
@@ -16,7 +16,7 @@ export class Message {
|
||||
* @param id Message Id
|
||||
*/
|
||||
constructor(collection: MessageCollection, id: string) {
|
||||
this.collection = collection;
|
||||
this.#collection = collection;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@@ -38,29 +38,29 @@ export class Message {
|
||||
* URL to this message
|
||||
*/
|
||||
get url() {
|
||||
return this.collection.client.configuration?.app + this.path;
|
||||
return this.#collection.client.configuration?.app + this.path;
|
||||
}
|
||||
|
||||
/**
|
||||
* Nonce value
|
||||
*/
|
||||
get nonce() {
|
||||
return this.collection.getUnderlyingObject(this.id).nonce;
|
||||
return this.#collection.getUnderlyingObject(this.id).nonce;
|
||||
}
|
||||
|
||||
/**
|
||||
* Id of channel this message was sent in
|
||||
*/
|
||||
get channelId() {
|
||||
return this.collection.getUnderlyingObject(this.id).channelId;
|
||||
return this.#collection.getUnderlyingObject(this.id).channelId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Channel this message was sent in
|
||||
*/
|
||||
get channel() {
|
||||
return this.collection.client.channels.get(
|
||||
this.collection.getUnderlyingObject(this.id).channelId
|
||||
return this.#collection.client.channels.get(
|
||||
this.#collection.getUnderlyingObject(this.id).channelId
|
||||
);
|
||||
}
|
||||
|
||||
@@ -75,7 +75,7 @@ export class Message {
|
||||
* Member this message was sent by
|
||||
*/
|
||||
get member() {
|
||||
return this.collection.client.serverMembers.getByKey({
|
||||
return this.#collection.client.serverMembers.getByKey({
|
||||
server: this.channel!.serverId,
|
||||
user: this.authorId!,
|
||||
});
|
||||
@@ -85,15 +85,15 @@ export class Message {
|
||||
* Id of user this message was sent by
|
||||
*/
|
||||
get authorId() {
|
||||
return this.collection.getUnderlyingObject(this.id).authorId;
|
||||
return this.#collection.getUnderlyingObject(this.id).authorId;
|
||||
}
|
||||
|
||||
/**
|
||||
* User this message was sent by
|
||||
*/
|
||||
get author() {
|
||||
return this.collection.client.users.get(
|
||||
this.collection.getUnderlyingObject(this.id).authorId!
|
||||
return this.#collection.client.users.get(
|
||||
this.#collection.getUnderlyingObject(this.id).authorId!
|
||||
);
|
||||
}
|
||||
|
||||
@@ -101,70 +101,70 @@ export class Message {
|
||||
* Content
|
||||
*/
|
||||
get content() {
|
||||
return this.collection.getUnderlyingObject(this.id).content;
|
||||
return this.#collection.getUnderlyingObject(this.id).content;
|
||||
}
|
||||
|
||||
/**
|
||||
* System message content
|
||||
*/
|
||||
get systemMessage() {
|
||||
return this.collection.getUnderlyingObject(this.id).systemMessage;
|
||||
return this.#collection.getUnderlyingObject(this.id).systemMessage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Attachments
|
||||
*/
|
||||
get attachments() {
|
||||
return this.collection.getUnderlyingObject(this.id).attachments;
|
||||
return this.#collection.getUnderlyingObject(this.id).attachments;
|
||||
}
|
||||
|
||||
/**
|
||||
* Time at which this message was edited
|
||||
*/
|
||||
get editedAt() {
|
||||
return this.collection.getUnderlyingObject(this.id).editedAt;
|
||||
return this.#collection.getUnderlyingObject(this.id).editedAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Embeds
|
||||
*/
|
||||
get embeds() {
|
||||
return this.collection.getUnderlyingObject(this.id).embeds;
|
||||
return this.#collection.getUnderlyingObject(this.id).embeds;
|
||||
}
|
||||
|
||||
/**
|
||||
* IDs of users this message mentions
|
||||
*/
|
||||
get mentionIds() {
|
||||
return this.collection.getUnderlyingObject(this.id).mentionIds;
|
||||
return this.#collection.getUnderlyingObject(this.id).mentionIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* IDs of messages this message replies to
|
||||
*/
|
||||
get replyIds() {
|
||||
return this.collection.getUnderlyingObject(this.id).replyIds;
|
||||
return this.#collection.getUnderlyingObject(this.id).replyIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reactions
|
||||
*/
|
||||
get reactions() {
|
||||
return this.collection.getUnderlyingObject(this.id).reactions;
|
||||
return this.#collection.getUnderlyingObject(this.id).reactions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Interactions
|
||||
*/
|
||||
get interactions() {
|
||||
return this.collection.getUnderlyingObject(this.id).interactions;
|
||||
return this.#collection.getUnderlyingObject(this.id).interactions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Masquerade
|
||||
*/
|
||||
get masquerade() {
|
||||
return this.collection.getUnderlyingObject(this.id).masquerade;
|
||||
return this.#collection.getUnderlyingObject(this.id).masquerade;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -211,7 +211,7 @@ export class Message {
|
||||
*/
|
||||
get masqueradeAvatarURL() {
|
||||
const avatar = this.masquerade?.avatar;
|
||||
return avatar ? this.collection.client.proxyFile(avatar) : undefined;
|
||||
return avatar ? this.#collection.client.proxyFile(avatar) : undefined;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -222,7 +222,7 @@ export class Message {
|
||||
if (!system) return { type: "none" };
|
||||
|
||||
const { type } = system;
|
||||
const get = (id: string) => this.collection.client.users.get(id);
|
||||
const get = (id: string) => this.#collection.client.users.get(id);
|
||||
switch (system.type) {
|
||||
case "text":
|
||||
return system;
|
||||
@@ -254,7 +254,7 @@ export class Message {
|
||||
* @param data Message edit route data
|
||||
*/
|
||||
async edit(data: DataEditMessage) {
|
||||
return await this.collection.client.api.patch(
|
||||
return await this.#collection.client.api.patch(
|
||||
`/channels/${this.channelId as ""}/messages/${this.id as ""}`,
|
||||
data
|
||||
);
|
||||
@@ -264,7 +264,7 @@ export class Message {
|
||||
* Delete a message
|
||||
*/
|
||||
async delete() {
|
||||
return await this.collection.client.api.delete(
|
||||
return await this.#collection.client.api.delete(
|
||||
`/channels/${this.channelId as ""}/messages/${this.id as ""}`
|
||||
);
|
||||
}
|
||||
@@ -298,7 +298,7 @@ export class Message {
|
||||
* Clear all reactions from this message
|
||||
*/
|
||||
async clearReactions() {
|
||||
return await this.collection.client.api.delete(
|
||||
return await this.#collection.client.api.delete(
|
||||
`/channels/${this.channelId as ""}/messages/${this.id as ""}/reactions`
|
||||
);
|
||||
}
|
||||
@@ -308,7 +308,7 @@ export class Message {
|
||||
* @param emoji Unicode or emoji ID
|
||||
*/
|
||||
async react(emoji: string) {
|
||||
return await this.collection.client.api.put(
|
||||
return await this.#collection.client.api.put(
|
||||
`/channels/${this.channelId as ""}/messages/${this.id as ""}/reactions/${
|
||||
emoji as ""
|
||||
}`
|
||||
@@ -320,7 +320,7 @@ export class Message {
|
||||
* @param emoji Unicode or emoji ID
|
||||
*/
|
||||
async unreact(emoji: string) {
|
||||
return await this.collection.client.api.delete(
|
||||
return await this.#collection.client.api.delete(
|
||||
`/channels/${this.channelId as ""}/messages/${this.id as ""}/reactions/${
|
||||
emoji as ""
|
||||
}`
|
||||
|
||||
+30
-28
@@ -11,7 +11,7 @@ import { Channel } from "./Channel";
|
||||
* Server Class
|
||||
*/
|
||||
export class Server {
|
||||
readonly collection: ServerCollection;
|
||||
readonly #collection: ServerCollection;
|
||||
readonly id: string;
|
||||
|
||||
/**
|
||||
@@ -20,7 +20,7 @@ export class Server {
|
||||
* @param id Id
|
||||
*/
|
||||
constructor(collection: ServerCollection, id: string) {
|
||||
this.collection = collection;
|
||||
this.#collection = collection;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@@ -35,15 +35,15 @@ export class Server {
|
||||
* Owner's user ID
|
||||
*/
|
||||
get ownerId() {
|
||||
return this.collection.getUnderlyingObject(this.id).ownerId;
|
||||
return this.#collection.getUnderlyingObject(this.id).ownerId;
|
||||
}
|
||||
|
||||
/**
|
||||
* Owner
|
||||
*/
|
||||
get owner() {
|
||||
return this.collection.client.users.get(
|
||||
this.collection.getUnderlyingObject(this.id).ownerId
|
||||
return this.#collection.client.users.get(
|
||||
this.#collection.getUnderlyingObject(this.id).ownerId
|
||||
);
|
||||
}
|
||||
|
||||
@@ -51,43 +51,45 @@ export class Server {
|
||||
* Name
|
||||
*/
|
||||
get name() {
|
||||
return this.collection.getUnderlyingObject(this.id).name;
|
||||
return this.#collection.getUnderlyingObject(this.id).name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Description
|
||||
*/
|
||||
get description() {
|
||||
return this.collection.getUnderlyingObject(this.id).description;
|
||||
return this.#collection.getUnderlyingObject(this.id).description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Icon
|
||||
*/
|
||||
get icon() {
|
||||
return this.collection.getUnderlyingObject(this.id).icon;
|
||||
return this.#collection.getUnderlyingObject(this.id).icon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Banner
|
||||
*/
|
||||
get banner() {
|
||||
return this.collection.getUnderlyingObject(this.id).banner;
|
||||
return this.#collection.getUnderlyingObject(this.id).banner;
|
||||
}
|
||||
|
||||
/**
|
||||
* Channel IDs
|
||||
*/
|
||||
get channelIds() {
|
||||
return this.collection.getUnderlyingObject(this.id).channelIds;
|
||||
return this.#collection.getUnderlyingObject(this.id).channelIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Channels
|
||||
*/
|
||||
get channels() {
|
||||
return [...this.collection.getUnderlyingObject(this.id).channelIds.values()]
|
||||
.map((id) => this.collection.client.channels.get(id)!)
|
||||
return [
|
||||
...this.#collection.getUnderlyingObject(this.id).channelIds.values(),
|
||||
]
|
||||
.map((id) => this.#collection.client.channels.get(id)!)
|
||||
.filter((x) => x);
|
||||
}
|
||||
|
||||
@@ -95,56 +97,56 @@ export class Server {
|
||||
* Categories
|
||||
*/
|
||||
get categories() {
|
||||
return this.collection.getUnderlyingObject(this.id).categories;
|
||||
return this.#collection.getUnderlyingObject(this.id).categories;
|
||||
}
|
||||
|
||||
/**
|
||||
* System message channels
|
||||
*/
|
||||
get systemMessages() {
|
||||
return this.collection.getUnderlyingObject(this.id).systemMessages;
|
||||
return this.#collection.getUnderlyingObject(this.id).systemMessages;
|
||||
}
|
||||
|
||||
/**
|
||||
* Roles
|
||||
*/
|
||||
get roles() {
|
||||
return this.collection.getUnderlyingObject(this.id).roles;
|
||||
return this.#collection.getUnderlyingObject(this.id).roles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Default permissions
|
||||
*/
|
||||
get defaultPermissions() {
|
||||
return this.collection.getUnderlyingObject(this.id).defaultPermissions;
|
||||
return this.#collection.getUnderlyingObject(this.id).defaultPermissions;
|
||||
}
|
||||
|
||||
/**
|
||||
* Server flags
|
||||
*/
|
||||
get flags() {
|
||||
return this.collection.getUnderlyingObject(this.id).flags;
|
||||
return this.#collection.getUnderlyingObject(this.id).flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether analytics are enabled for this server
|
||||
*/
|
||||
get analytics() {
|
||||
return this.collection.getUnderlyingObject(this.id).analytics;
|
||||
return this.#collection.getUnderlyingObject(this.id).analytics;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this server is publicly discoverable
|
||||
*/
|
||||
get discoverable() {
|
||||
return this.collection.getUnderlyingObject(this.id).discoverable;
|
||||
return this.#collection.getUnderlyingObject(this.id).discoverable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this server is marked as mature
|
||||
*/
|
||||
get mature() {
|
||||
return this.collection.getUnderlyingObject(this.id).nsfw;
|
||||
return this.#collection.getUnderlyingObject(this.id).nsfw;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -165,7 +167,7 @@ export class Server {
|
||||
const channels = [];
|
||||
for (const key of category.channels) {
|
||||
if (uncategorised.delete(key)) {
|
||||
channels.push(this.collection.client.channels.get(key)!);
|
||||
channels.push(this.#collection.client.channels.get(key)!);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -186,7 +188,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) {
|
||||
@@ -237,14 +239,14 @@ export class Server {
|
||||
* URL to the server's icon
|
||||
*/
|
||||
get iconURL() {
|
||||
return this.collection.client.createFileURL(this.icon, { max_side: 256 });
|
||||
return this.#collection.client.createFileURL(this.icon, { max_side: 256 });
|
||||
}
|
||||
|
||||
/**
|
||||
* URL to the server's animated icon
|
||||
*/
|
||||
get animatedIconURL() {
|
||||
return this.collection.client.createFileURL(
|
||||
return this.#collection.client.createFileURL(
|
||||
this.icon,
|
||||
{ max_side: 256 },
|
||||
true
|
||||
@@ -255,7 +257,7 @@ export class Server {
|
||||
* URL to the server's banner
|
||||
*/
|
||||
get bannerURL() {
|
||||
return this.collection.client.createFileURL(this.banner, {
|
||||
return this.#collection.client.createFileURL(this.banner, {
|
||||
max_side: 256,
|
||||
});
|
||||
}
|
||||
@@ -264,9 +266,9 @@ export class Server {
|
||||
* Own member object for this server
|
||||
*/
|
||||
get member() {
|
||||
return this.collection.client.serverMembers.getByKey({
|
||||
return this.#collection.client.serverMembers.getByKey({
|
||||
server: this.id,
|
||||
user: this.collection.client.user!.id,
|
||||
user: this.#collection.client.user!.id,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -274,7 +276,7 @@ export class Server {
|
||||
* Permission the currently authenticated user has against this server
|
||||
*/
|
||||
get permission() {
|
||||
return calculatePermission(this.collection.client, this);
|
||||
return calculatePermission(this.#collection.client, this);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+12
-12
@@ -20,7 +20,7 @@ function key(key: MemberCompositeKey) {
|
||||
* Server Member Class
|
||||
*/
|
||||
export class ServerMember {
|
||||
readonly collection: ServerMemberCollection;
|
||||
readonly #collection: ServerMemberCollection;
|
||||
readonly id: MemberCompositeKey;
|
||||
|
||||
/**
|
||||
@@ -29,7 +29,7 @@ export class ServerMember {
|
||||
* @param id Id
|
||||
*/
|
||||
constructor(collection: ServerMemberCollection, id: MemberCompositeKey) {
|
||||
this.collection = collection;
|
||||
this.#collection = collection;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@@ -37,49 +37,49 @@ export class ServerMember {
|
||||
* Server this member belongs to
|
||||
*/
|
||||
get server() {
|
||||
return this.collection.client.servers.get(this.id.server);
|
||||
return this.#collection.client.servers.get(this.id.server);
|
||||
}
|
||||
|
||||
/**
|
||||
* User corresponding to this member
|
||||
*/
|
||||
get user() {
|
||||
return this.collection.client.users.get(this.id.user);
|
||||
return this.#collection.client.users.get(this.id.user);
|
||||
}
|
||||
|
||||
/**
|
||||
* When this user joined the server
|
||||
*/
|
||||
get joinedAt() {
|
||||
return this.collection.getUnderlyingObject(key(this.id)).joinedAt;
|
||||
return this.#collection.getUnderlyingObject(key(this.id)).joinedAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Nickname
|
||||
*/
|
||||
get nickname() {
|
||||
return this.collection.getUnderlyingObject(key(this.id)).nickname;
|
||||
return this.#collection.getUnderlyingObject(key(this.id)).nickname;
|
||||
}
|
||||
|
||||
/**
|
||||
* Avatar
|
||||
*/
|
||||
get avatar() {
|
||||
return this.collection.getUnderlyingObject(key(this.id)).avatar;
|
||||
return this.#collection.getUnderlyingObject(key(this.id)).avatar;
|
||||
}
|
||||
|
||||
/**
|
||||
* List of role IDs
|
||||
*/
|
||||
get roles() {
|
||||
return this.collection.getUnderlyingObject(key(this.id)).roles;
|
||||
return this.#collection.getUnderlyingObject(key(this.id)).roles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Time at which timeout expires
|
||||
*/
|
||||
get timeout() {
|
||||
return this.collection.getUnderlyingObject(key(this.id)).timeout;
|
||||
return this.#collection.getUnderlyingObject(key(this.id)).timeout;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -144,7 +144,7 @@ export class ServerMember {
|
||||
* @returns Permissions that this member has
|
||||
*/
|
||||
getPermissions(target: Server | Channel) {
|
||||
return calculatePermission(this.collection.client, target, {
|
||||
return calculatePermission(this.#collection.client, target, {
|
||||
member: this,
|
||||
});
|
||||
}
|
||||
@@ -179,7 +179,7 @@ export class ServerMember {
|
||||
*/
|
||||
get avatarURL() {
|
||||
return (
|
||||
this.collection.client.createFileURL(this.avatar, { max_side: 256 }) ??
|
||||
this.#collection.client.createFileURL(this.avatar, { max_side: 256 }) ??
|
||||
this.user?.avatarURL
|
||||
);
|
||||
}
|
||||
@@ -189,7 +189,7 @@ export class ServerMember {
|
||||
*/
|
||||
get animatedAvatarURL() {
|
||||
return (
|
||||
this.collection.client.createFileURL(
|
||||
this.#collection.client.createFileURL(
|
||||
this.avatar,
|
||||
{ max_side: 256 },
|
||||
true
|
||||
|
||||
+21
-19
@@ -7,7 +7,7 @@ import { U32_MAX, UserPermission } from "../permissions/definitions";
|
||||
* User Class
|
||||
*/
|
||||
export class User {
|
||||
readonly collection: UserCollection;
|
||||
readonly #collection: UserCollection;
|
||||
readonly id: string;
|
||||
|
||||
/**
|
||||
@@ -16,7 +16,7 @@ export class User {
|
||||
* @param id Id
|
||||
*/
|
||||
constructor(collection: UserCollection, id: string) {
|
||||
this.collection = collection;
|
||||
this.#collection = collection;
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
@@ -31,70 +31,72 @@ export class User {
|
||||
* Username
|
||||
*/
|
||||
get username() {
|
||||
return this.collection.getUnderlyingObject(this.id).username;
|
||||
return this.#collection.getUnderlyingObject(this.id).username;
|
||||
}
|
||||
|
||||
/**
|
||||
* Avatar
|
||||
*/
|
||||
get avatar() {
|
||||
return this.collection.getUnderlyingObject(this.id).avatar;
|
||||
return this.#collection.getUnderlyingObject(this.id).avatar;
|
||||
}
|
||||
|
||||
/**
|
||||
* Badges
|
||||
*/
|
||||
get badges() {
|
||||
return this.collection.getUnderlyingObject(this.id).badges;
|
||||
return this.#collection.getUnderlyingObject(this.id).badges;
|
||||
}
|
||||
|
||||
/**
|
||||
* User Status
|
||||
*/
|
||||
get status() {
|
||||
return this.collection.getUnderlyingObject(this.id).status;
|
||||
return this.#collection.getUnderlyingObject(this.id).status;
|
||||
}
|
||||
|
||||
/**
|
||||
* Relationship with user
|
||||
*/
|
||||
get relationship() {
|
||||
return this.collection.getUnderlyingObject(this.id).relationship;
|
||||
return this.#collection.getUnderlyingObject(this.id).relationship;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the user is online
|
||||
*/
|
||||
get online() {
|
||||
return this.collection.getUnderlyingObject(this.id).online;
|
||||
return this.#collection.getUnderlyingObject(this.id).online;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the user is privileged
|
||||
*/
|
||||
get privileged() {
|
||||
return this.collection.getUnderlyingObject(this.id).privileged;
|
||||
return this.#collection.getUnderlyingObject(this.id).privileged;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flags
|
||||
*/
|
||||
get flags() {
|
||||
return this.collection.getUnderlyingObject(this.id).flags;
|
||||
return this.#collection.getUnderlyingObject(this.id).flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Bot information
|
||||
*/
|
||||
get bot() {
|
||||
return this.collection.getUnderlyingObject(this.id).bot;
|
||||
return this.#collection.getUnderlyingObject(this.id).bot;
|
||||
}
|
||||
|
||||
/**
|
||||
* URL to the user's default avatar
|
||||
*/
|
||||
get defaultAvatarURL() {
|
||||
return `${this.collection.client.baseURL}/users/${this.id}/default_avatar`;
|
||||
return `${this.#collection.client.options.baseURL}/users/${
|
||||
this.id
|
||||
}/default_avatar`;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -102,7 +104,7 @@ export class User {
|
||||
*/
|
||||
get avatarURL() {
|
||||
return (
|
||||
this.collection.client.createFileURL(this.avatar, { max_side: 256 }) ??
|
||||
this.#collection.client.createFileURL(this.avatar, { max_side: 256 }) ??
|
||||
this.defaultAvatarURL
|
||||
);
|
||||
}
|
||||
@@ -112,7 +114,7 @@ export class User {
|
||||
*/
|
||||
get animatedAvatarURL() {
|
||||
return (
|
||||
this.collection.client.createFileURL(
|
||||
this.#collection.client.createFileURL(
|
||||
this.avatar,
|
||||
{ max_side: 256 },
|
||||
true
|
||||
@@ -138,18 +140,18 @@ export class User {
|
||||
}
|
||||
|
||||
if (
|
||||
this.collection.client.channels
|
||||
this.#collection.client.channels
|
||||
.toList()
|
||||
.find(
|
||||
(channel) =>
|
||||
(channel.type === "Group" || channel.type === "DirectMessage") &&
|
||||
channel.recipientIds?.includes(this.collection.client.user!.id)
|
||||
channel.recipientIds.has(this.#collection.client.user!.id)
|
||||
) ||
|
||||
this.collection.client.serverMembers
|
||||
this.#collection.client.serverMembers
|
||||
.toList()
|
||||
.find((member) => member.id.user === this.collection.client.user!.id)
|
||||
.find((member) => member.id.user === this.#collection.client.user!.id)
|
||||
) {
|
||||
if (this.collection.client.user?.bot || this.bot) {
|
||||
if (this.#collection.client.user?.bot || this.bot) {
|
||||
permissions |= UserPermission.SendMessage;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user