Spoiler posts in spoiler tags

This commit is contained in:
Tarrgon
2025-06-07 14:39:03 -04:00
parent ac63e6f647
commit de3fb0ec28
3 changed files with 32 additions and 12 deletions
+1 -1
View File
@@ -5,9 +5,9 @@ export * from './ban-utils';
export * from './channel-utils';
export * from './commands';
export * from './e621-utils';
export * from './event-log-utils';
export * from './file-utils';
export * from './interaction-utils';
export * from './event-log-utils';
export * from './message-utils';
export * from './ms-to-human';
export * from './note-utils';
+17
View File
@@ -3,6 +3,8 @@ import { LoggedMessage } from '../types';
export const ARRAY_SEPARATOR = '$';
const spoilerRegex = new RegExp('\\|\\|((?:[\\S]| )+?)\\|\\|', 'gi');
export function serializeMessage(message: Message): string[] {
const attachments = message.attachments.map(a => `${a.name}:${a.id}`);
const stickers = message.stickers.map(s => `${s.name}:${s.id}`);
@@ -40,4 +42,19 @@ export function isEdited(loggedMessage: LoggedMessage, newMessage: Message) {
const { addedStickers, removedStickers } = getModifiedStickers(loggedMessage, newMessage);
return addedStickers.length > 0 || removedStickers.length > 0;
}
export function isInSpoilerTags(content: string, index: number): boolean {
if (!content.includes('||')) return false;
let match: RegExpExecArray | null;
while ((match = spoilerRegex.exec(content)) != null) {
if (index >= match.index && index <= spoilerRegex.lastIndex) {
spoilerRegex.lastIndex = 0;
return true;
}
}
spoilerRegex.lastIndex = 0;
return false;
}