11import logger from '../../logwrapper' ;
22import accountAccess from "../../common/account-access" ;
3- import { ApiClient , HelixChatAnnouncementColor , HelixChatChatter , HelixSendChatAnnouncementParams , HelixSentChatMessage , HelixUpdateChatSettingsParams } from "@twurple/api" ;
3+ import {
4+ ApiClient ,
5+ HelixChatAnnouncementColor ,
6+ HelixChatChatter ,
7+ HelixSendChatAnnouncementParams ,
8+ HelixSentChatMessage ,
9+ HelixUpdateChatSettingsParams ,
10+ HelixUserEmote
11+ } from "@twurple/api" ;
412
513interface ResultWithError < TResult , TError > {
614 success : boolean ;
@@ -321,4 +329,36 @@ export class TwitchChatApi {
321329 return null ;
322330 }
323331 }
332+
333+ /**
334+ * Gets all emotes that can be used on Twitch by the specified Firebot account.
335+ *
336+ * @param account Either `streamer` or `bot`
337+ * @returns An array of {@link HelixUserEmote} containing all the emotes the user can use on Twitch, or null if the request failed
338+ */
339+ async getAllUserEmotes ( account : "streamer" | "bot" = "streamer" ) : Promise < HelixUserEmote [ ] > {
340+ const streamerUserId = accountAccess . getAccounts ( ) . streamer . userId ;
341+ let userId = streamerUserId ;
342+ let client = this . _streamerClient ;
343+
344+ if ( account === "bot" ) {
345+ const bot = accountAccess . getAccounts ( ) . bot ;
346+ if ( bot . loggedIn !== true ) {
347+ return [ ] ;
348+ }
349+
350+ userId = bot . userId ;
351+ client = this . _botClient ;
352+ }
353+
354+ try {
355+ const emotes = await client . chat . getUserEmotesPaginated ( userId , streamerUserId ) . getAll ( ) ;
356+
357+ // Filter out any duplicates that may come back from the API
358+ return emotes . filter ( ( emote , index , arr ) => arr . findIndex ( e => emote . id === e . id ) === index ) ;
359+ } catch ( error ) {
360+ logger . error ( `Error getting all user emotes for ${ account } ` , error . message ) ;
361+ return null ;
362+ }
363+ }
324364}
0 commit comments