aboutsummaryrefslogtreecommitdiff
path: root/src/api/MessageEvents.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/api/MessageEvents.ts')
-rw-r--r--src/api/MessageEvents.ts24
1 files changed, 16 insertions, 8 deletions
diff --git a/src/api/MessageEvents.ts b/src/api/MessageEvents.ts
index 90e8c73..8411c9a 100644
--- a/src/api/MessageEvents.ts
+++ b/src/api/MessageEvents.ts
@@ -37,25 +37,33 @@ export interface MessageObject {
validNonShortcutEmojis: Emoji[];
}
-export type SendListener = (channelId: string, messageObj: MessageObject, extra: any) => void;
+export interface MessageExtra {
+ stickerIds?: string[];
+}
+
+export type SendListener = (channelId: string, messageObj: MessageObject, extra: MessageExtra) => void | { cancel: boolean };
export type EditListener = (channelId: string, messageId: string, messageObj: MessageObject) => void;
const sendListeners = new Set<SendListener>();
const editListeners = new Set<EditListener>();
-export function _handlePreSend(channelId: string, messageObj: MessageObject, extra: any) {
+export function _handlePreSend(channelId: string, messageObj: MessageObject, extra: MessageExtra) {
for (const listener of sendListeners) {
try {
- listener(channelId, messageObj, extra);
- } catch (e) { MessageEventsLogger.error(`MessageSendHandler: Listener encoutered an unknown error. (${e})`); }
+ const result = listener(channelId, messageObj, extra);
+ if (result && result.cancel === true) {
+ return true;
+ }
+ } catch (e) { MessageEventsLogger.error("MessageSendHandler: Listener encountered an unknown error\n", e); }
}
+ return false;
}
-export function _handlePreEdit(channeld: string, messageId: string, messageObj: MessageObject) {
+export function _handlePreEdit(channelId: string, messageId: string, messageObj: MessageObject) {
for (const listener of editListeners) {
try {
- listener(channeld, messageId, messageObj);
- } catch (e) { MessageEventsLogger.error(`MessageEditHandler: Listener encoutered an unknown error. (${e})`); }
+ listener(channelId, messageId, messageObj);
+ } catch (e) { MessageEventsLogger.error("MessageEditHandler: Listener encountered an unknown error\n", e); }
}
}
@@ -90,7 +98,7 @@ export function _handleClick(message: Message, channel: Channel, event: MouseEve
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 encountered an unknown error\n", e); }
}
}