diff --git a/src/classes/Server.ts b/src/classes/Server.ts index 29a0d2ea..543604f0 100644 --- a/src/classes/Server.ts +++ b/src/classes/Server.ts @@ -2,6 +2,7 @@ import type { Category, DataBanCreate, DataCreateChannel, + DataCreateEmoji, DataEditRole, DataEditServer, Override, @@ -14,6 +15,8 @@ import { bitwiseAndEq, calculatePermission } from "../permissions/calculator"; import { Permission } from "../permissions/definitions"; import { Channel } from "./Channel"; +import { ChannelInvite } from "./Invite"; +import { ServerBan } from "./ServerBan"; /** * Server Class @@ -359,7 +362,10 @@ export class Server { * @param user User * @param options Ban options */ - async banUser(user: string | User | ServerMember, options?: DataBanCreate) { + async banUser( + user: string | User | ServerMember, + options: DataBanCreate = {} + ) { const userId = user instanceof User ? user.id @@ -367,10 +373,12 @@ export class Server { ? user.id.user : user; - return await this.#collection.client.api.put( - `/servers/${this.id as ""}/bans/${userId}`, + const ban = await this.#collection.client.api.put( + `/servers/${this.id as ""}/bans/${userId as ""}`, options ); + + return new ServerBan(this.#collection.client, ban); } /** @@ -406,9 +414,13 @@ export class Server { * @returns An array of the server's invites */ async fetchInvites() { - return await this.#collection.client.api.get( + const invites = await this.#collection.client.api.get( `/servers/${this.id as ""}/invites` ); + + return invites.map((invite) => + ChannelInvite.from(this.#collection.client, invite) + ); } /** @@ -416,9 +428,15 @@ export class Server { * @returns An array of the server's bans. */ async fetchBans() { - return await this.#collection.client.api.get( + const { users, bans } = await this.#collection.client.api.get( `/servers/${this.id as ""}/bans` ); + + users.forEach((user) => + this.#collection.client.users.getOrCreate(user._id, user) + ); + + return bans.map((ban) => new ServerBan(this.#collection.client, ban)); } /** @@ -546,13 +564,40 @@ export class Server { }; } + /** + * Create an emoji on the server + * @param autumnId Autumn Id + * @param options Options + */ + async createEmoji( + autumnId: string, + options: Omit + ) { + const emoji = await this.#collection.client.api.put( + `/custom/emoji/${autumnId as ""}`, + { + parent: { + type: "Server", + id: this.id, + }, + ...options, + } + ); + + return this.#collection.client.emojis.getOrCreate(emoji._id, emoji, true); + } + /** * Fetch a server's emoji * @returns List of server emoji */ async fetchEmojis() { - return await this.#collection.client.api.get( + const emojis = await this.#collection.client.api.get( `/servers/${this.id as ""}/emojis` ); + + return emojis.map((emoji) => + this.#collection.client.emojis.getOrCreate(emoji._id, emoji) + ); } } diff --git a/src/classes/index.ts b/src/classes/index.ts index 1725b72d..395409c7 100644 --- a/src/classes/index.ts +++ b/src/classes/index.ts @@ -3,9 +3,12 @@ export * from "./Channel"; export * from "./ChannelUnread"; export * from "./Emoji"; export * from "./File"; +export * from "./Invite"; export * from "./Message"; export * from "./MessageEmbed"; export * from "./PublicBot"; +export * from "./PublicInvite"; export * from "./Server"; +export * from "./ServerBan"; export * from "./ServerMember"; export * from "./User"; diff --git a/src/collections/ServerCollection.ts b/src/collections/ServerCollection.ts index 70201155..3e750d25 100644 --- a/src/collections/ServerCollection.ts +++ b/src/collections/ServerCollection.ts @@ -8,6 +8,8 @@ import { ClassCollection } from "."; export class ServerCollection extends ClassCollection { /** * Fetch server by ID + * + * This will not fetch channels! * @param id Id * @returns Server */