-
-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7db55da
commit 9f3e698
Showing
10 changed files
with
268 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import type { EmojiPayload } from "../../../types/mod.ts"; | ||
import type { EmojiPayloadWithGuildID } from "../../types/emoji.ts"; | ||
import { Emoji } from "../structures/emojis/mod.ts"; | ||
import { BaseManager } from "./base.ts"; | ||
|
||
export class EmojisManager extends BaseManager<EmojiPayloadWithGuildID, Emoji> { | ||
_fill(emojis: EmojiPayloadWithGuildID[]) { | ||
for (const emoji of emojis) { | ||
this.set(emoji.id!, emoji); | ||
} | ||
} | ||
|
||
async _fetch( | ||
guildID: string, | ||
id: string, | ||
): Promise<EmojiPayloadWithGuildID | undefined> { | ||
try { | ||
const resp: EmojiPayload | undefined = await this.client.rest.get( | ||
`/guilds/${guildID}/emojis/${id}`, | ||
); | ||
if (!resp) return; | ||
const result = { | ||
...resp, | ||
guild_id: guildID, | ||
}; | ||
this.set(id, result); | ||
return result; | ||
} catch (_err) { | ||
return; | ||
} | ||
} | ||
async _fetchAll( | ||
guildID: string, | ||
): Promise<EmojiPayloadWithGuildID[] | undefined> { | ||
try { | ||
const resp: EmojiPayload[] | undefined = await this.client.rest.get( | ||
`/guilds/${guildID}/emojis`, | ||
); | ||
if (!resp) return; | ||
return resp.map((emoji) => { | ||
const withGuildID = { | ||
...emoji, | ||
guild_id: guildID, | ||
}; | ||
this.set(emoji.id!, withGuildID); | ||
return withGuildID; | ||
}); | ||
} catch (_err) { | ||
return; | ||
} | ||
} | ||
|
||
get( | ||
id: string, | ||
) { | ||
const cached = this._get(id); | ||
if (!cached) return; | ||
return new Emoji(this.client, cached, cached.guild_id); | ||
} | ||
async fetch( | ||
guildID: string, | ||
id: string, | ||
) { | ||
try { | ||
const payload = await this._fetch(guildID, id); | ||
if (!payload) return; | ||
return new Emoji(this.client, payload, payload.guild_id); | ||
} catch (_err) { | ||
return; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
import type { EmojiPayload } from "../../../types/mod.ts"; | ||
import type { EmojiPayloadWithGuildID } from "../../types/emoji.ts"; | ||
import type { Client } from "../client/mod.ts"; | ||
import { Emoji } from "../structures/emojis/mod.ts"; | ||
import { BaseChildManager } from "./baseChild.ts"; | ||
import type { EmojisManager } from "./emojis.ts"; | ||
|
||
export class GuildEmojisManager | ||
extends BaseChildManager<EmojiPayloadWithGuildID, Emoji> { | ||
guildID: string; | ||
|
||
constructor(client: Client, parent: EmojisManager, guildID: string) { | ||
super(client, parent); | ||
this.guildID = guildID; | ||
} | ||
|
||
_fill(payloads: EmojiPayload[]) { | ||
for (const payload of payloads) { | ||
this.set(payload.id!, { | ||
...payload, | ||
guild_id: this.guildID, | ||
}); | ||
} | ||
} | ||
|
||
_get(key: string): EmojiPayloadWithGuildID | undefined { | ||
const emoji = this.parent._get(key); | ||
if (!emoji) return; | ||
if (emoji.guild_id !== this.guildID) return; | ||
return emoji; | ||
} | ||
|
||
async _fetchAll(): Promise<EmojiPayloadWithGuildID[] | undefined> { | ||
try { | ||
const resp: EmojiPayload[] | undefined = await this.client.rest | ||
.get( | ||
`/guilds/${this.guildID}/emojis`, | ||
); | ||
if (!resp) return; | ||
const emojis = resp.map((r) => ({ ...r, guild_id: this.guildID })); | ||
this._fill(emojis); | ||
return emojis; | ||
} catch (_err) { | ||
return; | ||
} | ||
} | ||
|
||
async _fetch(id: string): Promise<EmojiPayloadWithGuildID | undefined> { | ||
try { | ||
const resp: EmojiPayload | undefined = await this.client.rest | ||
.get( | ||
`/guilds/${this.guildID}/emojis/${id}`, | ||
); | ||
if (!resp) return; | ||
const emoji = { | ||
...resp, | ||
guild_id: this.guildID, | ||
}; | ||
this.set(id, emoji); | ||
return emoji; | ||
} catch (_err) { | ||
return; | ||
} | ||
} | ||
|
||
get( | ||
id: string, | ||
) { | ||
const cached = this._get(id); | ||
if (!cached) return; | ||
return new Emoji(this.client, cached, cached.guild_id); | ||
} | ||
|
||
async fetchAll(): Promise<Emoji[] | undefined> { | ||
try { | ||
const emojis = await this._fetchAll(); | ||
if (!emojis) return; | ||
return emojis.map((r) => new Emoji(this.client, r, this.guildID)); | ||
} catch (_err) { | ||
return; | ||
} | ||
} | ||
|
||
async fetch( | ||
id: string, | ||
) { | ||
try { | ||
const payload = await this._fetch(id); | ||
if (!payload) return; | ||
return new Emoji(this.client, payload, this.guildID); | ||
} catch (_err) { | ||
return; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,54 @@ | ||
import type { GuildForumChannelPayload } from "../../../../types/mod.ts"; | ||
import { Mixin } from "../../../deps.ts"; | ||
import type { GuildForumTag } from "../../../types/forum.ts"; | ||
import { Emoji } from "../emojis/mod.ts"; | ||
import { GuildTextBasedChannel } from "./guildTextBasedChannel.ts"; | ||
import { GuildThreadAvailableChannel } from "./guildThreadAvailableChannel.ts"; | ||
|
||
export class GuildForumChannel extends Mixin( | ||
GuildThreadAvailableChannel<GuildForumChannelPayload>, | ||
GuildTextBasedChannel<GuildForumChannelPayload>, | ||
) { | ||
// get defaultReactionEmoji(): Emoji { | ||
// TODO: add emoji | ||
// } | ||
get defaultReactionEmoji(): Emoji | undefined { | ||
if (this.payload.default_reaction_emoji) { | ||
if (this.payload.default_reaction_emoji.emoji_id !== null) { | ||
return this.client.emojis.get( | ||
this.payload.default_reaction_emoji.emoji_id, | ||
); | ||
} else if (this.payload.default_reaction_emoji.emoji_name !== null) { | ||
return new Emoji(this.client, { | ||
id: null, | ||
name: this.payload.default_reaction_emoji.emoji_name, | ||
}); | ||
} | ||
} | ||
return undefined; | ||
} | ||
get defaultSortOrder() { | ||
return this.payload.default_auto_archive_duration; | ||
} | ||
get defaultForumLayout() { | ||
return this.payload.default_auto_archive_duration; | ||
} | ||
get availableTags(): GuildForumTag { | ||
let result: Emoji; | ||
|
||
if (this.payload.available_tags.emoji_id !== null) { | ||
result = this.client.emojis.get( | ||
this.payload.available_tags.emoji_id, | ||
)!; | ||
} else if (this.payload.available_tags.emoji_name !== null) { | ||
result = new Emoji(this.client, { | ||
id: null, | ||
name: this.payload.available_tags.emoji_name, | ||
}); | ||
} | ||
|
||
return { | ||
id: this.payload.available_tags.id, | ||
name: this.payload.available_tags.name, | ||
moderated: this.payload.available_tags.moderated, | ||
// TODO: add emoji | ||
emoji: result!, | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,15 @@ | ||
export * from "./channel.ts"; | ||
export * from "./DMBasedChannel.ts"; | ||
export * from "./DMChannel.ts"; | ||
export * from "./groupDMChannel.ts"; | ||
export * from "./guildAnnouncementChannel.ts"; | ||
export * from "./guildCategory.ts"; | ||
export * from "./guildChannel.ts"; | ||
export * from "./guildForumChannel.ts"; | ||
export * from "./guildStageChannel.ts"; | ||
export * from "./guildTextBasedChannel.ts"; | ||
export * from "./guildTextChannel.ts"; | ||
export * from "./guildThreadAvailableChannel.ts"; | ||
export * from "./guildVoiceBasedChannel.ts"; | ||
export * from "./guildVoiceChannel.ts"; | ||
export * from "./textChannel.ts"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import { EmojiPayload } from "../../../../types/mod.ts"; | ||
import type { Client } from "../../client/mod.ts"; | ||
import { User } from "../users/mod.ts"; | ||
|
||
export class Emoji { | ||
client: Client; | ||
payload: EmojiPayload; | ||
guildID?: string; | ||
|
||
constructor(client: Client, payload: EmojiPayload, guildID?: string) { | ||
this.client = client; | ||
this.payload = payload; | ||
this.guildID = guildID; | ||
} | ||
|
||
get id() { | ||
return this.payload.id; | ||
} | ||
get name() { | ||
return this.payload.name; | ||
} | ||
get roles() { | ||
return this.payload.roles?.map((id) => this.client.roles.get(id)); | ||
} | ||
get user() { | ||
return this.payload.user !== undefined | ||
? new User(this.client, this.payload.user) | ||
: undefined; | ||
} | ||
get requireColons() { | ||
return this.payload.require_colons; | ||
} | ||
get managed() { | ||
return this.payload.managed; | ||
} | ||
get animated() { | ||
return this.payload.animated; | ||
} | ||
get available() { | ||
return this.payload.available; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import type { EmojiPayload } from "../../types/mod.ts"; | ||
|
||
export interface EmojiPayloadWithGuildID extends EmojiPayload { | ||
guild_id: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
// TODO: uncomment Emoji import when it's ready | ||
import type { Emoji } from "../src/structures/emojis/mod.ts"; | ||
|
||
export interface GuildForumTag { | ||
id: string; | ||
name: string; | ||
moderated: boolean; | ||
// emoji: Emoji | ||
emoji: Emoji; | ||
} |