-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Vlad Frangu <kingdgrizzle@gmail.com>
- Loading branch information
1 parent
12a096b
commit 8d650a7
Showing
6 changed files
with
101 additions
and
79 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
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,80 @@ | ||
'use strict'; | ||
|
||
const BaseManager = require('./BaseManager'); | ||
const GuildEmoji = require('../structures/GuildEmoji'); | ||
const ReactionEmoji = require('../structures/ReactionEmoji'); | ||
const { parseEmoji } = require('../util/Util'); | ||
|
||
/** | ||
* Holds methods to resolve GuildEmojis and stores their cache. | ||
* @extends {BaseManager} | ||
*/ | ||
class BaseGuildEmojiManager extends BaseManager { | ||
constructor(client, iterable) { | ||
super(client, iterable, GuildEmoji); | ||
} | ||
|
||
/** | ||
* The cache of GuildEmojis | ||
* @type {Collection<Snowflake, GuildEmoji>} | ||
* @name BaseGuildEmojiManager#cache | ||
*/ | ||
|
||
/** | ||
* Data that can be resolved into a GuildEmoji object. This can be: | ||
* * A custom emoji ID | ||
* * A GuildEmoji object | ||
* * A ReactionEmoji object | ||
* @typedef {Snowflake|GuildEmoji|ReactionEmoji} EmojiResolvable | ||
*/ | ||
|
||
/** | ||
* Resolves an EmojiResolvable to an Emoji object. | ||
* @param {EmojiResolvable} emoji The Emoji resolvable to identify | ||
* @returns {?GuildEmoji} | ||
*/ | ||
resolve(emoji) { | ||
if (emoji instanceof ReactionEmoji) return super.resolve(emoji.id); | ||
return super.resolve(emoji); | ||
} | ||
|
||
/** | ||
* Resolves an EmojiResolvable to an Emoji ID string. | ||
* @param {EmojiResolvable} emoji The Emoji resolvable to identify | ||
* @returns {?Snowflake} | ||
*/ | ||
resolveID(emoji) { | ||
if (emoji instanceof ReactionEmoji) return emoji.id; | ||
return super.resolveID(emoji); | ||
} | ||
|
||
/** | ||
* Data that can be resolved to give an emoji identifier. This can be: | ||
* * The unicode representation of an emoji | ||
* * The `<a:name:id>`, `<:name:id>`, `a:name:id` or `name:id` emoji identifier string of an emoji | ||
* * An EmojiResolvable | ||
* @typedef {string|EmojiResolvable} EmojiIdentifierResolvable | ||
*/ | ||
|
||
/** | ||
* Resolves an EmojiResolvable to an emoji identifier. | ||
* @param {EmojiIdentifierResolvable} emoji The emoji resolvable to resolve | ||
* @returns {?string} | ||
*/ | ||
resolveIdentifier(emoji) { | ||
const emojiResolvable = this.resolve(emoji); | ||
if (emojiResolvable) return emojiResolvable.identifier; | ||
if (emoji instanceof ReactionEmoji) return emoji.identifier; | ||
if (typeof emoji === 'string') { | ||
const res = parseEmoji(emoji); | ||
if (res && res.name.length) { | ||
emoji = `${res.animated ? 'a:' : ''}${res.name}${res.id ? `:${res.id}` : ''}`; | ||
} | ||
if (!emoji.includes('%')) return encodeURIComponent(emoji); | ||
return emoji; | ||
} | ||
return null; | ||
} | ||
} | ||
|
||
module.exports = BaseGuildEmojiManager; |
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