discord-html-transcripts-fix 1.7.1 → 1.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -150,7 +150,13 @@ async function render(_a) {
150
150
  // Non-blocking inline JSON: type="application/json" so the parser doesn't pause
151
151
  (0, jsx_runtime_1.jsx)("script", { id: "dht-data", type: "application/json", dangerouslySetInnerHTML: { __html: (0, utils_1.safeJsonForScript)(globalData) } }),
152
152
  (0, jsx_runtime_1.jsx)("script", { dangerouslySetInnerHTML: { __html: 'try{globalThis.$discordMessage=JSON.parse(document.getElementById("dht-data").textContent);}catch(e){globalThis.$discordMessage={};}' } }),
153
- !options.hydrate && (0, jsx_runtime_1.jsx)("script", { type: "module", src: `https://cdn.jsdelivr.net/npm/@skyra/discord-components-core@${discordComponentsVersion}/+esm`, crossOrigin: "anonymous" }),
153
+ // Always load the @skyra/discord-components-core ES module, even
154
+ // when `hydrate: true` is requested. Lit SSR does not reliably
155
+ // expand every <discord-*> custom element to plain HTML, and the
156
+ // browser-side definitions are also needed to hydrate the SSR'd
157
+ // markup (re-render with state, click handlers, etc.). Without
158
+ // this tag the page is just static unstyled custom elements.
159
+ (0, jsx_runtime_1.jsx)("script", { type: "module", src: `https://cdn.jsdelivr.net/npm/@skyra/discord-components-core@${discordComponentsVersion}/+esm`, crossOrigin: "anonymous" }),
154
160
  ] }),
155
161
  (0, jsx_runtime_1.jsxs)("body", { style: { margin: 0, minHeight: '100vh' }, children: [
156
162
  (0, jsx_runtime_1.jsx)(transcript_1.default, Object.assign({ messages, channel, callbacks }, options, renderContext)),
@@ -138,9 +138,17 @@ async function DiscordMessage({ message, context }) {
138
138
  // no longer render a separate "/cmd opt:val by user" line.
139
139
  const slashData = buildSlashCommandData(message);
140
140
 
141
+ // FIX: pass timestamp as ISO string. React would otherwise stringify a
142
+ // Date via toString() (locale-dependent like "Tue May 26 2026 …"),
143
+ // which skyra's <discord-message> often fails to parse — falling back
144
+ // to new Date() == transcript creation time. ISO is round-trip safe.
145
+ const createdAtIso = message.createdAt instanceof Date
146
+ ? message.createdAt.toISOString()
147
+ : (typeof message.createdAt === 'string' ? message.createdAt : undefined);
148
+
141
149
  return ((0, jsx_runtime_1.jsxs)("discord-message", {
142
150
  id: `m-${message.id}`,
143
- timestamp: message.createdAt,
151
+ timestamp: createdAtIso,
144
152
  edited: message.editedAt !== null,
145
153
  server: (isCrossGuildReply || isCrosspost || isCrossposted) ? true : undefined,
146
154
  highlight: message.mentions.everyone || pinned,
@@ -18,11 +18,16 @@ async function SystemMessage({ message, context }) {
18
18
  const color = message.member?.roles?.color?.hexColor;
19
19
  const authorId = author?.id;
20
20
  const ctx = context || {};
21
+ // FIX: pass message.createdAt as ISO string so skyra renders the original
22
+ // timestamp instead of falling back to "now" (= transcript creation time).
23
+ const ts = message.createdAt instanceof Date
24
+ ? message.createdAt.toISOString()
25
+ : (typeof message.createdAt === 'string' ? message.createdAt : undefined);
21
26
 
22
27
  switch (message.type) {
23
28
  case discord_js_1.MessageType.RecipientAdd:
24
29
  case discord_js_1.MessageType.UserJoin:
25
- return ((0, jsx_runtime_1.jsx)("discord-system-message", { id: `m-${message.id}`, type: "join", children: (0, jsx_runtime_1.jsx)(JoinMessage, { member: message.member, fallbackUser: author, seed: message.id, context: ctx }) }, message.id));
30
+ return ((0, jsx_runtime_1.jsx)("discord-system-message", { id: `m-${message.id}`, timestamp: ts, type: "join", children: (0, jsx_runtime_1.jsx)(JoinMessage, { member: message.member, fallbackUser: author, seed: message.id, context: ctx }) }, message.id));
26
31
 
27
32
  case discord_js_1.MessageType.ChannelPinnedMessage: {
28
33
  const refId = message.reference?.messageId;
@@ -36,7 +41,7 @@ async function SystemMessage({ message, context }) {
36
41
  ? (0, jsx_runtime_1.jsx)("i", { "data-goto": refId, className: "dht-jump", role: "button", tabIndex: 0, children: linkLabel })
37
42
  : (0, jsx_runtime_1.jsx)("strong", { children: linkLabel });
38
43
  const parts = template.includes('{message}') ? template.split('{message}') : null;
39
- return ((0, jsx_runtime_1.jsxs)("discord-system-message", { id: `m-${message.id}`, type: "pin", children: parts
44
+ return ((0, jsx_runtime_1.jsxs)("discord-system-message", { id: `m-${message.id}`, timestamp: ts, type: "pin", children: parts
40
45
  ? [
41
46
  (0, jsx_runtime_1.jsx)(Highlight, { color, userId: authorId, children: authorName }),
42
47
  ' ',
@@ -57,7 +62,7 @@ async function SystemMessage({ message, context }) {
57
62
  case discord_js_1.MessageType.GuildBoostTier1:
58
63
  case discord_js_1.MessageType.GuildBoostTier2:
59
64
  case discord_js_1.MessageType.GuildBoostTier3:
60
- return ((0, jsx_runtime_1.jsxs)("discord-system-message", { id: `m-${message.id}`, type: "boost", children: [
65
+ return ((0, jsx_runtime_1.jsxs)("discord-system-message", { id: `m-${message.id}`, timestamp: ts, type: "boost", children: [
61
66
  (0, jsx_runtime_1.jsx)(Highlight, { color, userId: authorId, children: authorName }),
62
67
  ' ',
63
68
  (0, jsx_runtime_1.jsx)("span", { "data-i18n": "boosted", children: t(ctx, 'boosted', 'boosted the server!') }),
@@ -67,7 +72,7 @@ async function SystemMessage({ message, context }) {
67
72
  case discord_js_1.MessageType.ThreadCreated: {
68
73
  const refId = message.reference?.messageId;
69
74
  const label = message.content || 'New thread';
70
- return ((0, jsx_runtime_1.jsxs)("discord-system-message", { id: `m-${message.id}`, type: "thread", children: [
75
+ return ((0, jsx_runtime_1.jsxs)("discord-system-message", { id: `m-${message.id}`, timestamp: ts, type: "thread", children: [
71
76
  (0, jsx_runtime_1.jsx)(Highlight, { color, userId: authorId, children: authorName }),
72
77
  ' ',
73
78
  (0, jsx_runtime_1.jsx)("span", { "data-i18n": "threadStarted", children: t(ctx, 'threadStarted', 'started a thread:') }),
@@ -79,7 +84,7 @@ async function SystemMessage({ message, context }) {
79
84
  }
80
85
 
81
86
  case discord_js_1.MessageType.ChannelNameChange:
82
- return ((0, jsx_runtime_1.jsxs)("discord-system-message", { id: `m-${message.id}`, type: "edit", children: [
87
+ return ((0, jsx_runtime_1.jsxs)("discord-system-message", { id: `m-${message.id}`, timestamp: ts, type: "edit", children: [
83
88
  (0, jsx_runtime_1.jsx)(Highlight, { color, userId: authorId, children: authorName }),
84
89
  ' ',
85
90
  (0, jsx_runtime_1.jsx)("span", { "data-i18n": "changedChannelName", children: t(ctx, 'changedChannelName', 'changed the channel name:') }),
@@ -88,7 +93,7 @@ async function SystemMessage({ message, context }) {
88
93
  ] }, message.id));
89
94
 
90
95
  case discord_js_1.MessageType.ChannelIconChange:
91
- return ((0, jsx_runtime_1.jsxs)("discord-system-message", { id: `m-${message.id}`, type: "edit", children: [
96
+ return ((0, jsx_runtime_1.jsxs)("discord-system-message", { id: `m-${message.id}`, timestamp: ts, type: "edit", children: [
92
97
  (0, jsx_runtime_1.jsx)(Highlight, { color, userId: authorId, children: authorName }),
93
98
  ' ',
94
99
  (0, jsx_runtime_1.jsx)("span", { "data-i18n": "changedChannelIcon", children: t(ctx, 'changedChannelIcon', 'changed the channel icon.') }),
@@ -97,7 +102,7 @@ async function SystemMessage({ message, context }) {
97
102
  case discord_js_1.MessageType.ChatInputCommand:
98
103
  case discord_js_1.MessageType.ContextMenuCommand: {
99
104
  const cmd = message.interaction?.commandName ? '/' + message.interaction.commandName : 'a command';
100
- return ((0, jsx_runtime_1.jsxs)("discord-system-message", { id: `m-${message.id}`, type: "call", children: [
105
+ return ((0, jsx_runtime_1.jsxs)("discord-system-message", { id: `m-${message.id}`, timestamp: ts, type: "call", children: [
101
106
  (0, jsx_runtime_1.jsx)(Highlight, { color, userId: authorId, children: authorName }),
102
107
  ' ',
103
108
  (0, jsx_runtime_1.jsx)("span", { "data-i18n": "usedCommand", children: t(ctx, 'usedCommand', 'used') }),
@@ -107,7 +112,7 @@ async function SystemMessage({ message, context }) {
107
112
  }
108
113
 
109
114
  case discord_js_1.MessageType.Call:
110
- return ((0, jsx_runtime_1.jsxs)("discord-system-message", { id: `m-${message.id}`, type: "call", children: [
115
+ return ((0, jsx_runtime_1.jsxs)("discord-system-message", { id: `m-${message.id}`, timestamp: ts, type: "call", children: [
111
116
  (0, jsx_runtime_1.jsx)(Highlight, { color, userId: authorId, children: authorName }),
112
117
  ' ',
113
118
  (0, jsx_runtime_1.jsx)("span", { "data-i18n": "startedCall", children: t(ctx, 'startedCall', 'started a call.') }),
@@ -116,7 +121,7 @@ async function SystemMessage({ message, context }) {
116
121
  case discord_js_1.MessageType.ChannelFollowAdd: {
117
122
  const followText = t(ctx, 'addedFollow', 'added {target} to follow this channel.');
118
123
  const parts = followText.split('{target}');
119
- return ((0, jsx_runtime_1.jsxs)("discord-system-message", { id: `m-${message.id}`, type: "edit", children: [
124
+ return ((0, jsx_runtime_1.jsxs)("discord-system-message", { id: `m-${message.id}`, timestamp: ts, type: "edit", children: [
120
125
  (0, jsx_runtime_1.jsx)(Highlight, { color, userId: authorId, children: authorName }),
121
126
  ' ',
122
127
  parts[0],
@@ -126,7 +131,7 @@ async function SystemMessage({ message, context }) {
126
131
  }
127
132
 
128
133
  case discord_js_1.MessageType.RecipientRemove:
129
- return ((0, jsx_runtime_1.jsxs)("discord-system-message", { id: `m-${message.id}`, type: "leave", children: [
134
+ return ((0, jsx_runtime_1.jsxs)("discord-system-message", { id: `m-${message.id}`, timestamp: ts, type: "leave", children: [
130
135
  (0, jsx_runtime_1.jsx)(Highlight, { color, userId: authorId, children: authorName }),
131
136
  ' ',
132
137
  (0, jsx_runtime_1.jsx)("span", { "data-i18n": "left", children: t(ctx, 'left', 'left.') }),
@@ -141,7 +146,7 @@ async function SystemMessage({ message, context }) {
141
146
  const action = fields.find((f) => /action_type|action/i.test(f.name))?.value || '';
142
147
  const blocked = e?.description || '';
143
148
  const channelId = fields.find((f) => /channel/i.test(f.name))?.value;
144
- return ((0, jsx_runtime_1.jsxs)("discord-system-message", { id: `m-${message.id}`, type: "boost", children: [
149
+ return ((0, jsx_runtime_1.jsxs)("discord-system-message", { id: `m-${message.id}`, timestamp: ts, type: "boost", children: [
145
150
  (0, jsx_runtime_1.jsx)("span", { "data-i18n": "autoModBlocked", children: t(ctx, 'autoModBlocked', 'AutoMod blocked a message.') }),
146
151
  ruleName && (0, jsx_runtime_1.jsxs)("span", { className: "dht-automod-rule", children: [' · Rule: ', (0, jsx_runtime_1.jsx)("strong", { children: ruleName })] }),
147
152
  action && (0, jsx_runtime_1.jsxs)("span", { className: "dht-automod-rule", children: [' · Action: ', action] }),
@@ -151,34 +156,34 @@ async function SystemMessage({ message, context }) {
151
156
  ] }, message.id));
152
157
  }
153
158
  case discord_js_1.MessageType.StageStart:
154
- return ((0, jsx_runtime_1.jsxs)("discord-system-message", { id: `m-${message.id}`, type: "call", children: [
159
+ return ((0, jsx_runtime_1.jsxs)("discord-system-message", { id: `m-${message.id}`, timestamp: ts, type: "call", children: [
155
160
  (0, jsx_runtime_1.jsx)(Highlight, { color, userId: authorId, children: authorName }),
156
161
  ' started a stage: ',
157
162
  (0, jsx_runtime_1.jsx)("strong", { children: message.content || '' })
158
163
  ] }, message.id));
159
164
  case discord_js_1.MessageType.StageEnd:
160
- return ((0, jsx_runtime_1.jsxs)("discord-system-message", { id: `m-${message.id}`, type: "leave", children: [
165
+ return ((0, jsx_runtime_1.jsxs)("discord-system-message", { id: `m-${message.id}`, timestamp: ts, type: "leave", children: [
161
166
  (0, jsx_runtime_1.jsx)(Highlight, { color, userId: authorId, children: authorName }),
162
167
  ' ended the stage.'
163
168
  ] }, message.id));
164
169
  case discord_js_1.MessageType.StageSpeaker:
165
- return ((0, jsx_runtime_1.jsxs)("discord-system-message", { id: `m-${message.id}`, type: "call", children: [
170
+ return ((0, jsx_runtime_1.jsxs)("discord-system-message", { id: `m-${message.id}`, timestamp: ts, type: "call", children: [
166
171
  (0, jsx_runtime_1.jsx)(Highlight, { color, userId: authorId, children: authorName }),
167
172
  ' is now a speaker.'
168
173
  ] }, message.id));
169
174
  case discord_js_1.MessageType.StageRaiseHand:
170
- return ((0, jsx_runtime_1.jsxs)("discord-system-message", { id: `m-${message.id}`, type: "call", children: [
175
+ return ((0, jsx_runtime_1.jsxs)("discord-system-message", { id: `m-${message.id}`, timestamp: ts, type: "call", children: [
171
176
  (0, jsx_runtime_1.jsx)(Highlight, { color, userId: authorId, children: authorName }),
172
177
  ' requested to speak.'
173
178
  ] }, message.id));
174
179
  case discord_js_1.MessageType.StageTopic:
175
- return ((0, jsx_runtime_1.jsxs)("discord-system-message", { id: `m-${message.id}`, type: "edit", children: [
180
+ return ((0, jsx_runtime_1.jsxs)("discord-system-message", { id: `m-${message.id}`, timestamp: ts, type: "edit", children: [
176
181
  (0, jsx_runtime_1.jsx)(Highlight, { color, userId: authorId, children: authorName }),
177
182
  ' changed the stage topic: ',
178
183
  (0, jsx_runtime_1.jsx)("strong", { children: message.content || '' })
179
184
  ] }, message.id));
180
185
  case discord_js_1.MessageType.GuildApplicationPremiumSubscription:
181
- return ((0, jsx_runtime_1.jsxs)("discord-system-message", { id: `m-${message.id}`, type: "boost", children: [
186
+ return ((0, jsx_runtime_1.jsxs)("discord-system-message", { id: `m-${message.id}`, timestamp: ts, type: "boost", children: [
182
187
  (0, jsx_runtime_1.jsx)(Highlight, { color, userId: authorId, children: authorName }),
183
188
  ' subscribed ',
184
189
  (0, jsx_runtime_1.jsx)("strong", { children: message.applicationId ? `app ${message.applicationId}` : 'an app' }),
@@ -187,7 +192,7 @@ async function SystemMessage({ message, context }) {
187
192
 
188
193
  case discord_js_1.MessageType.RoleSubscriptionPurchase: {
189
194
  const roleName = message.roleSubscriptionData?.tierName || message.content || 'a role';
190
- return ((0, jsx_runtime_1.jsxs)("discord-system-message", { id: `m-${message.id}`, type: "boost", children: [
195
+ return ((0, jsx_runtime_1.jsxs)("discord-system-message", { id: `m-${message.id}`, timestamp: ts, type: "boost", children: [
191
196
  (0, jsx_runtime_1.jsx)(Highlight, { color, userId: authorId, children: authorName }),
192
197
  ' ',
193
198
  t(ctx, 'roleSubPurchased', 'subscribed to {role}!').replace('{role}', roleName),
@@ -198,10 +203,10 @@ async function SystemMessage({ message, context }) {
198
203
  case discord_js_1.MessageType.GuildIncidentReportFalseAlarm:
199
204
  case discord_js_1.MessageType.GuildIncidentAlertModeEnabled:
200
205
  case discord_js_1.MessageType.GuildIncidentAlertModeDisabled:
201
- return ((0, jsx_runtime_1.jsx)("discord-system-message", { id: `m-${message.id}`, type: "boost", children: (0, jsx_runtime_1.jsx)("span", { "data-i18n": "serverAlert", children: t(ctx, 'serverAlert', 'Server safety alert.') }) }, message.id));
206
+ return ((0, jsx_runtime_1.jsx)("discord-system-message", { id: `m-${message.id}`, timestamp: ts, type: "boost", children: (0, jsx_runtime_1.jsx)("span", { "data-i18n": "serverAlert", children: t(ctx, 'serverAlert', 'Server safety alert.') }) }, message.id));
202
207
 
203
208
  case discord_js_1.MessageType.PollResult:
204
- return ((0, jsx_runtime_1.jsx)("discord-system-message", { id: `m-${message.id}`, type: "edit", children: (0, jsx_runtime_1.jsx)("span", { "data-i18n": "pollEnded", children: t(ctx, 'pollEnded', 'A poll ended.') }) }, message.id));
209
+ return ((0, jsx_runtime_1.jsx)("discord-system-message", { id: `m-${message.id}`, timestamp: ts, type: "edit", children: (0, jsx_runtime_1.jsx)("span", { "data-i18n": "pollEnded", children: t(ctx, 'pollEnded', 'A poll ended.') }) }, message.id));
205
210
 
206
211
  // These render through the normal pipeline
207
212
  case discord_js_1.MessageType.Default:
@@ -52,21 +52,24 @@ async function DiscordMessages(_a) {
52
52
  ] }));
53
53
  }
54
54
 
55
- // Legacy "Exported X message(s). Powered by …" line. The new stats footer
56
- // (see renderStatsFooter in generator/index.js) already shows the message
57
- // count, so this line is suppressed by default and only renders when:
58
- // - options.statsFooter === false (caller opted out of the new footer), or
59
- // - options.footerText is explicitly set to a string, or
60
- // - options.poweredBy === true (caller wants the credit link).
55
+ // Legacy "Exported X message(s). Powered by …" footer line.
56
+ //
57
+ // The new stats footer (see renderStatsFooter in generator/index.js) already
58
+ // shows the message count and more. To prevent two footers stacking on the
59
+ // same transcript, the legacy footer is now mutually exclusive with the
60
+ // stats footer: it ONLY renders when the caller has explicitly disabled the
61
+ // stats footer via `statsFooter: false` (or `{ enabled: false }`). Setting
62
+ // `footerText` or `poweredBy` alone is no longer enough — that used to
63
+ // produce a duplicate footer because the stats footer kept rendering.
61
64
  function renderLegacyFooter(messages, options) {
62
65
  const statsDisabled = options.statsFooter === false ||
63
66
  (options.statsFooter && options.statsFooter.enabled === false);
67
+ if (!statsDisabled) return null;
64
68
  const customText = (typeof options.footerText === 'string' && options.footerText.length > 0)
65
69
  ? options.footerText.replaceAll('{number}', messages.length.toString()).replaceAll('{s}', messages.length > 1 ? 's' : '')
66
70
  : null;
67
71
  const wantsPowered = !!options.poweredBy;
68
- // Default render only if stats footer is off AND no custom text was set.
69
- const defaultText = statsDisabled && !customText
72
+ const defaultText = !customText
70
73
  ? `Exported ${messages.length} message${messages.length > 1 ? 's' : ''}.`
71
74
  : null;
72
75
  const shown = customText || defaultText;
@@ -97,9 +97,15 @@ async function buildAllContext(messages, channel) {
97
97
  : (displayHex && displayHex !== '#000000' ? displayHex : null);
98
98
 
99
99
  // legacy profile (used by <discord-mention>)
100
+ //
101
+ // forceStatic: Discord CDN returns HTTP 415 for `.gif` on some animated
102
+ // avatar hashes (commonly bot avatars whose animation was removed but
103
+ // whose hash still carries the `a_` prefix). The static variant (.webp
104
+ // or .png) always works, so render avatars as static in transcripts.
105
+ // Avatars in a historical archive don't gain much from being animated.
100
106
  profiles[id] = {
101
107
  author: member?.nickname ?? author.displayName ?? author.username,
102
- avatar: member?.displayAvatarURL?.({ size: 64 }) ?? author.displayAvatarURL?.({ size: 64 }),
108
+ avatar: member?.displayAvatarURL?.({ size: 64, forceStatic: true }) ?? author.displayAvatarURL?.({ size: 64, forceStatic: true }),
103
109
  roleColor: effectiveColor,
104
110
  roleIcon: member?.roles?.icon?.iconURL?.() ?? undefined,
105
111
  roleName: member?.roles?.hoist?.name ?? undefined,
@@ -124,7 +130,7 @@ async function buildAllContext(messages, channel) {
124
130
  username: author.username,
125
131
  displayName: member?.nickname || author.displayName || author.username,
126
132
  globalName: author.globalName || null,
127
- avatar: member?.displayAvatarURL?.({ size: 128 }) || author.displayAvatarURL?.({ size: 128 }) || null,
133
+ avatar: member?.displayAvatarURL?.({ size: 128, forceStatic: true }) || author.displayAvatarURL?.({ size: 128, forceStatic: true }) || null,
128
134
  bannerColor: effectiveColor,
129
135
  bot: !!author.bot,
130
136
  system: !!author.system,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "discord-html-transcripts-fix",
3
- "version": "1.7.1",
3
+ "version": "1.8.2",
4
4
  "description": "A nicely formatted html transcript generator for discord.js. Bugfix fork with support for the latest discord.js and Components v2.",
5
5
  "main": "dist/index.js",
6
6
  "types": "./dist/index.d.ts",