|
|
|
@ -19,6 +19,7 @@
|
|
|
|
|
import type { Channel, Message } from "discord-types/general";
|
|
|
|
|
|
|
|
|
|
import Logger from "../utils/logger";
|
|
|
|
|
import { MessageStore } from "../webpack/common";
|
|
|
|
|
|
|
|
|
|
const MessageEventsLogger = new Logger("MessageEvents", "#e5c890");
|
|
|
|
|
|
|
|
|
@ -41,7 +42,7 @@ export interface MessageExtra {
|
|
|
|
|
stickerIds?: string[];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export type SendListener = (channelId: string, messageObj: MessageObject, extra: MessageExtra) => void | { cancel: boolean };
|
|
|
|
|
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>();
|
|
|
|
@ -54,7 +55,9 @@ export function _handlePreSend(channelId: string, messageObj: MessageObject, ext
|
|
|
|
|
if (result && result.cancel === true) {
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
} catch (e) { MessageEventsLogger.error("MessageSendHandler: Listener encountered an unknown error\n", e); }
|
|
|
|
|
} catch (e) {
|
|
|
|
|
MessageEventsLogger.error("MessageSendHandler: Listener encountered an unknown error\n", e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
@ -63,7 +66,9 @@ export function _handlePreEdit(channelId: string, messageId: string, messageObj:
|
|
|
|
|
for (const listener of editListeners) {
|
|
|
|
|
try {
|
|
|
|
|
listener(channelId, messageId, messageObj);
|
|
|
|
|
} catch (e) { MessageEventsLogger.error("MessageEditHandler: Listener encountered an unknown error\n", e); }
|
|
|
|
|
} catch (e) {
|
|
|
|
|
MessageEventsLogger.error("MessageEditHandler: Listener encountered an unknown error\n", e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -95,10 +100,14 @@ type ClickListener = (message: Message, channel: Channel, event: MouseEvent) =>
|
|
|
|
|
const listeners = new Set<ClickListener>();
|
|
|
|
|
|
|
|
|
|
export function _handleClick(message: Message, channel: Channel, event: MouseEvent) {
|
|
|
|
|
// message object may be outdated, so (try to) fetch latest one
|
|
|
|
|
message = MessageStore.getMessage(channel.id, message.id) ?? message;
|
|
|
|
|
for (const listener of listeners) {
|
|
|
|
|
try {
|
|
|
|
|
listener(message, channel, event);
|
|
|
|
|
} catch (e) { MessageEventsLogger.error("MessageClickHandler: Listener encountered an unknown error\n", e); }
|
|
|
|
|
} catch (e) {
|
|
|
|
|
MessageEventsLogger.error("MessageClickHandler: Listener encountered an unknown error\n", e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|