diff options
author | Vendicated <vendicated@riseup.net> | 2022-08-31 22:08:05 +0200 |
---|---|---|
committer | Vendicated <vendicated@riseup.net> | 2022-08-31 22:08:05 +0200 |
commit | f60ccb766f30e7518bc348013b72f071f86ecbc6 (patch) | |
tree | 5c1cdb5dfc1bbdc620f034308534eb19e0bcb881 /src/api/MessageEvents.ts | |
parent | bac8a648b6012e221fd2150062d2080b9ed0d702 (diff) | |
download | Vencord-f60ccb766f30e7518bc348013b72f071f86ecbc6.tar.gz Vencord-f60ccb766f30e7518bc348013b72f071f86ecbc6.tar.bz2 Vencord-f60ccb766f30e7518bc348013b72f071f86ecbc6.zip |
Add Plugin.start, make Settings actually start/stop plugins
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) { |