From 5fe4e4e82264011383f425e9136005cb3d6ffd6b Mon Sep 17 00:00:00 2001 From: Skillz Date: Wed, 12 Feb 2020 13:37:28 -0500 Subject: [PATCH] finished role and emojis --- structures/guild.ts | 3 ++- structures/role.ts | 11 +++++++++-- types/emoji.ts | 16 ++++++++++++++++ types/guild.ts | 31 ++++++++++++++++++++++++------- 4 files changed, 51 insertions(+), 10 deletions(-) create mode 100644 types/emoji.ts diff --git a/structures/guild.ts b/structures/guild.ts index f64b93a81..66f78ee4f 100644 --- a/structures/guild.ts +++ b/structures/guild.ts @@ -2,12 +2,13 @@ import Client from '../module/client' import { endpoints } from '../constants/discord' import { formatImageURL } from '../utils/cdn' import { Guild, CreateGuildPayload, ChannelTypes, Permissions, PrunePayload } from '../types/guild' +import { create_role } from './role' export const createGuild = (data: CreateGuildPayload, client: Client) => { const guild: Guild = { ...data, roles: new Map(data.roles.map(r => [r.id, create_role(r)])), - emojis: new Map(data.emojis.map(e => [e.id, create_emoji(e)])), + emojis: new Map(data.emojis.map(e => [e.id, e])), joined_at: Date.parse(data.joined_at), voice_states: new Map(data.voice_states.map(vs => [vs.id, create_voice_state(vs)])), members: new Map(data.members.map(m => [m.id, create_member(m)])), diff --git a/structures/role.ts b/structures/role.ts index e10ad2b2e..4c05dd72a 100644 --- a/structures/role.ts +++ b/structures/role.ts @@ -1,3 +1,10 @@ -export const createRole = (data: unknown) => { - console.log(data) +import { Role, Role_Data } from "../types/role" + +export const create_role = (data: Role_Data) => { + const role: Role = { + ...data, + mention: () => `<@&${data.id}>` + } + + return role } diff --git a/types/emoji.ts b/types/emoji.ts new file mode 100644 index 000000000..9240e7cda --- /dev/null +++ b/types/emoji.ts @@ -0,0 +1,16 @@ +export interface Emoji { + /** emoji id. It will be null for default discord emojis. */ + id: string | null + /** The name of the emoji. (can be null only in reaction emoji objects when the custom emoji doesnt exist anymore) */ + name: string | null + /** array of role ids roles this emoji is whitelisted to */ + roles?: string[] + /** User that created this emoji */ + user?: User + /** whether this emoji must be wrapped in colons */ + require_colons?: boolean + /** whether this emoji is managed */ + managed?: boolean + /** whether this emoji is animated */ + animated?: boolean +} diff --git a/types/guild.ts b/types/guild.ts index 1ab02b598..dbd00bee6 100644 --- a/types/guild.ts +++ b/types/guild.ts @@ -1,3 +1,6 @@ +import { Role } from './role' +import { Emoji } from './discord' + export interface CreateGuildPayload { /** The guild id */ id: string @@ -26,7 +29,7 @@ export interface CreateGuildPayload { /** The custom guild emojis */ emojis: Emoji[] /** Enabled guild features */ - features: GuildFeatures[] + features: Guild_Features[] /** Required MFA level for the guild */ mfa_level: number /** The id of the channel to which system mesages are sent */ @@ -188,17 +191,31 @@ export interface Guild { /** Remove the ban for a user. REquires BAN_MEMBERS permission */ unban(id: string): Promise /** Modify a guilds settings. Requires the MANAGE_GUILD permission. */ - edit(options: Guild_Edit_Options): Promise - /** Get all the invites for this guild. Requires MANAGE_GUILD permission */ - get_invites(): Promise + edit(options: Guild_Edit_Options): Promise + /** Get all the invites for this guild. Requires MANAGE_GUILD permission */ + get_invites(): Promise /** Leave a guild */ leave(): Promise /** Returns a list of voice region objects for the guild. Unlike the similar /voice route, this returns VIP servers when the guild is VIP-enabled. */ - get_voice_regions(): Promise - /** Returns a list of guild webhooks objects. Requires the MANAGE_WEBHOOKs permission. */ - get_webhooks(): Promise + get_voice_regions(): Promise + /** Returns a list of guild webhooks objects. Requires the MANAGE_WEBHOOKs permission. */ + get_webhooks(): Promise } +export type Guild_Features = + | `INVITE_SPLASH` + | `VIP_REGIONS` + | `VANITY_URL` + | `VERIFIED` + | `PARTNERED` + | `PUBLIC` + | `COMMERCE` + | `NEWS` + | `DISCOVERABLE` + | `FEATURABLE` + | `ANIMATED_ICON` + | `BANNER` + export interface Voice_Region { /** unique ID for the region */ id: string