diff options
Diffstat (limited to 'src/api/MessageEvents.ts')
-rw-r--r-- | src/api/MessageEvents.ts | 36 |
1 files changed, 24 insertions, 12 deletions
diff --git a/src/api/MessageEvents.ts b/src/api/MessageEvents.ts index 9ee54a6..65b4f45 100644 --- a/src/api/MessageEvents.ts +++ b/src/api/MessageEvents.ts @@ -3,10 +3,10 @@ import Logger from '../utils/logger'; const MessageEventsLogger = new Logger("MessageEvents", "#e5c890"); -interface Emoji { +export interface Emoji { require_colons: boolean, originalName: string, - animated: boolean + animated: boolean; guildId: string, name: string, url: string, @@ -15,11 +15,11 @@ interface Emoji { interface MessageObject { content: string, - validNonShortcutEmojis: Emoji[] + validNonShortcutEmojis: Emoji[]; } -type SendListener = (channelId: string, messageObj: MessageObject, extra: any) => void; -type EditListener = (channelId: string, messageId: string, messageObj: MessageObject) => void; +export type SendListener = (channelId: string, messageObj: MessageObject, extra: any) => void; +export type EditListener = (channelId: string, messageId: string, messageObj: MessageObject) => void; const sendListeners = new Set<SendListener>(); const editListeners = new Set<EditListener>(); @@ -28,7 +28,7 @@ export function _handlePreSend(channelId: string, messageObj: MessageObject, ext for (const listener of sendListeners) { try { listener(channelId, messageObj, extra); - } catch (e) { MessageEventsLogger.error(`MessageSendHandler: Listener encoutered an unknown error. (${e})`) } + } catch (e) { MessageEventsLogger.error(`MessageSendHandler: Listener encoutered an unknown error. (${e})`); } } } @@ -36,20 +36,31 @@ export function _handlePreEdit(channeld: string, messageId: string, messageObj: for (const listener of editListeners) { try { listener(channeld, messageId, messageObj); - } catch (e) { MessageEventsLogger.error(`MessageEditHandler: Listener encoutered an unknown error. (${e})`) } + } catch (e) { MessageEventsLogger.error(`MessageEditHandler: Listener encoutered an unknown error. (${e})`); } } } /** * Note: This event fires off before a message is sent, allowing you to edit the message. */ -export function addPreSendListener(listener: SendListener) { sendListeners.add(listener) } +export function addPreSendListener(listener: SendListener) { + sendListeners.add(listener); + return listener; +} /** * Note: This event fires off before a message's edit is applied, allowing you to further edit the message. */ -export function addPreEditListener(listener: EditListener) { editListeners.add(listener) } -export function removePreSendListener(listener: SendListener) { sendListeners.delete(listener) } -export function removePreEditListener(listener: EditListener) { editListeners.delete(listener) } +export function addPreEditListener(listener: EditListener) { + editListeners.add(listener); + return listener; +} +export function removePreSendListener(listener: SendListener) { + return sendListeners.delete(listener); +} +export function removePreEditListener(listener: EditListener) { + return editListeners.delete(listener); +} + // Message clicks type ClickListener = (message: Message, channel: Channel, event: MouseEvent) => void; @@ -60,12 +71,13 @@ export function _handleClick(message, channel, event) { for (const listener of listeners) { try { listener(message, channel, event); - } catch (e) { MessageEventsLogger.error(`MessageClickHandler: Listener encoutered an unknown error. (${e})`) } + } catch (e) { MessageEventsLogger.error(`MessageClickHandler: Listener encoutered an unknown error. (${e})`); } } } export function addClickListener(listener: ClickListener) { listeners.add(listener); + return listener; } export function removeClickListener(listener: ClickListener) { |