char-slop/city-role-bot
discord auto role applicator bot for charlotte polycule city
git clone https://git.t4t.associates/char-slop/city-role-bot
dae4431
main
1const CUSTOM_EMOJI = / ^<a?:([^:]+):(\d+)>$ / 2const UNICODE_EMOJI = 3/ ^\p{Extended_Pictographic}[\u{1F3FB}-\u{1F3FF}]?(?:\u200D\p{Extended_Pictographic}[\u{1F3FB}-\u{1F3FF}]?)*$ / u 4 5// discord sends some unicode emoji with and some without a variation 6// selector, so we strip it on both sides to keep comparisons stable 7const stripVariation = ( emoji :string ) :string => emoji . replace ( / \uFE0F / g , '' ) 8 9/** Normalizes a unicode emoji or a `<a:name:id>` mention to the `name:id` / 10* unicode form the reactions API expects. Returns undefined for anything else. */ 11export function normalizeEmoji ( input :string ) :string | undefined { 12const trimmed = input . trim () 13const custom = CUSTOM_EMOJI . exec ( trimmed ) 14if ( custom !== null ) return ` ${ custom [ 1 ]} : ${ custom [ 2 ]} ` 15const unicode = stripVariation ( trimmed ) 16return UNICODE_EMOJI . test ( unicode ) ?unicode :undefined 17} 18 19/** Reaction key for an event emoji, matching `normalizeEmoji` output. */ 20export function reactionKey ( emoji :{ id :string | null ; name :string | null }) :string | undefined { 21if ( emoji . name === null ) return undefined 22return emoji . id === null ?stripVariation ( emoji . name ) :` ${ emoji . name } : ${ emoji . id } ` 23}