2020-10-22 15:50:47 +00:00
import { Client } from '../models/client.ts'
2020-10-31 12:33:34 +00:00
import { EmojiPayload } from '../types/emoji.ts'
2020-12-25 16:31:53 +00:00
import { EMOJI } from '../types/endpoint.ts'
2020-10-22 15:50:47 +00:00
import { Base } from './base.ts'
2020-10-25 17:03:53 +00:00
import { User } from './user.ts'
2020-10-22 15:50:47 +00:00
2020-10-23 16:11:00 +00:00
export class Emoji extends Base {
2020-12-25 16:31:53 +00:00
id : string | null ;
2020-10-22 15:50:47 +00:00
name : string
2020-10-29 14:43:27 +00:00
roles? : string [ ]
user? : User
2020-10-23 16:11:00 +00:00
requireColons? : boolean
2020-10-22 15:50:47 +00:00
managed? : boolean
animated? : boolean
available? : boolean
2020-10-23 03:19:40 +00:00
2020-12-02 12:29:52 +00:00
get getEmojiString ( ) : string {
2020-10-23 03:19:40 +00:00
if ( this . animated === false ) {
2020-10-23 16:11:00 +00:00
return ` <: ${ this . name } : ${ this . id } > `
2020-10-23 03:19:40 +00:00
} else return ` <a: ${ this . name } : ${ this . id } > `
}
2020-11-08 11:10:33 +00:00
toString ( ) : string {
return this . getEmojiString
}
2020-12-02 12:29:52 +00:00
constructor ( client : Client , data : EmojiPayload ) {
2020-10-25 06:50:32 +00:00
super ( client , data )
2020-10-22 15:50:47 +00:00
this . id = data . id
this . name = data . name
2020-11-08 11:36:30 +00:00
if ( data . user !== undefined ) this . user = new User ( this . client , data . user )
2020-10-22 15:50:47 +00:00
this . roles = data . roles
2020-10-23 16:11:00 +00:00
this . requireColons = data . require_colons
2020-10-22 15:50:47 +00:00
this . managed = data . managed
this . animated = data . animated
this . available = data . available
}
2020-10-29 14:43:27 +00:00
2020-12-25 16:31:53 +00:00
/** Modify the given emoji. Requires the MANAGE_EMOJIS permission. Returns the updated emoji object on success. Fires a Guild Emojis Update Gateway event. */
async edit ( guildID : string , data : ModifyGuildEmojiParams ) {
const res = await this . client . rest . patch ( EMOJI ( guildID , this . id ! ) ) ;
return new Emoji ( this . client , res ) ;
}
/** Delete the given emoji. Requires the MANAGE_EMOJIS permission. Returns `true` on success. Fires a Guild Emojis Update Gateway event. */
async delete ( guildID : string ) : Promise < boolean > {
await this . client . rest . patch ( EMOJI ( guildID , this . id ! ) ) ;
return true ;
}
2020-12-03 05:28:20 +00:00
readFromData ( data : EmojiPayload ) : void {
2020-10-29 14:43:27 +00:00
this . id = data . id ? ? this . id
this . name = data . name ? ? this . name
this . roles = data . roles ? ? this . roles
this . requireColons = data . require_colons ? ? this . requireColons
this . managed = data . managed ? ? this . managed
this . animated = data . animated ? ? this . animated
this . available = data . available ? ? this . available
2020-12-03 04:06:41 +00:00
if ( data . user !== undefined ) this . user = new User ( this . client , data . user )
2020-10-29 14:43:27 +00:00
}
2020-10-22 15:50:47 +00:00
}
2020-12-25 16:31:53 +00:00
/** https://discord.com/developers/docs/resources/emoji#modify-guild-emoji-json-params */
export interface ModifyGuildEmojiParams {
/** Name of the emoji */
name : string ;
/** Roles to which this emoji will be whitelisted */
roles : string [ ] | null ;
}