Skip to content

Commit d44bdbb

Browse files
committed
feat: forwarded and sticker support for interserverchat
1 parent eed8500 commit d44bdbb

File tree

1 file changed

+46
-3
lines changed

1 file changed

+46
-3
lines changed

src/utils/interServerChat.ts

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,32 @@ export class InterServerChat {
148148
);
149149

150150
let content = message.content;
151-
if (message.reference && message.reference.messageId) {
151+
152+
const messageSnapshots = message.messageSnapshots;
153+
const isForwarded = messageSnapshots && messageSnapshots.size > 0;
154+
155+
if (isForwarded) {
156+
const snapshot = messageSnapshots.first();
157+
const forwardedContent = snapshot?.content || "";
158+
159+
let forwardPreview = forwardedContent;
160+
if (!forwardPreview) {
161+
if (snapshot?.attachments && snapshot.attachments.size > 0)
162+
forwardPreview = "*[Attachment]*";
163+
else if (snapshot?.embeds && snapshot.embeds.length > 0)
164+
forwardPreview = "*[Embed]*";
165+
else if (snapshot?.stickers && snapshot.stickers.size > 0)
166+
forwardPreview = "*[Sticker]*";
167+
else forwardPreview = "*[Unknown]*";
168+
}
169+
170+
if (forwardPreview.length > 360) {
171+
forwardPreview = forwardPreview.substring(0, 360) + "...";
172+
}
173+
forwardPreview = forwardPreview.replace(/\n/g, " ");
174+
175+
content = `> 📨 **Forwarded message:** ${forwardPreview}\n${content}`;
176+
} else if (message.reference && message.reference.messageId) {
152177
try {
153178
const refMessage = await message.channel.messages.fetch(
154179
message.reference.messageId,
@@ -163,12 +188,15 @@ export class InterServerChat {
163188
const firstLine = lines[0] ?? "";
164189
if (firstLine.startsWith("> ↩️ ")) {
165190
refContent = lines.slice(1).join("\n").trimStart();
191+
} else if (firstLine.startsWith("> 📨 ")) {
192+
refContent = lines.slice(1).join("\n").trimStart();
166193
}
167194
}
168195

169196
if (!refContent) {
170197
if (refMessage.attachments.size > 0) refContent = "*[Attachment]*";
171198
else if (refMessage.embeds.length > 0) refContent = "*[Embed]*";
199+
else if (refMessage.stickers.size > 0) refContent = "*[Sticker]*";
172200
else refContent = "*[Unknown]*";
173201
}
174202

@@ -179,15 +207,30 @@ export class InterServerChat {
179207

180208
content = `> ↩️ **${refAuthor}:** ${refContent}\n${content}`;
181209
} catch (error) {
182-
content = `> *[Forwarded message])*\n${content}`;
210+
content = `> ↩️ *[Reply to unknown message]*\n${content}`;
183211
}
184212
}
185213

186214
const displayName =
187215
message.member?.displayName || message.author.username;
188216

217+
let stickerText = "";
218+
if (message.stickers.size > 0) {
219+
const stickerNames = message.stickers.map((s) => s.name).join(", ");
220+
stickerText = `*[Sticker: ${stickerNames}]*`;
221+
}
222+
223+
let finalContent = content;
224+
if (!content && files.length === 0 && stickerText) {
225+
finalContent = stickerText;
226+
} else if (stickerText) {
227+
finalContent = content ? `${content}\n${stickerText}` : stickerText;
228+
} else if (!content && files.length === 0) {
229+
finalContent = "*[Empty message]*";
230+
}
231+
189232
await webhook.send({
190-
content: content || (files.length > 0 ? "" : "*[Sticker]*"),
233+
content: finalContent || "",
191234
username: `${displayName}${message.guild.name}`,
192235
avatarURL: message.author.displayAvatarURL(),
193236
files: files,

0 commit comments

Comments
 (0)