summary refs log tree commit diff
path: root/src/util
diff options
context:
space:
mode:
authorMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2023-02-21 11:56:56 +1100
committerMadeline <46743919+MaddyUnderStars@users.noreply.github.com>2023-02-21 12:01:49 +1100
commiteee98516dd09516f1c1cf891526339420807d50c (patch)
tree8d60f6717eac0416bcb73421ca71c31bdc1fff68 /src/util
parentClose #954 (diff)
downloadserver-eee98516dd09516f1c1cf891526339420807d50c.tar.xz
Fix gateway encoding Date objects as {} when using erlpack. Fixes NaN/NaN/NaN timestamps in desktop client
Diffstat (limited to 'src/util')
-rw-r--r--src/util/util/JSON.ts15
-rw-r--r--src/util/util/index.ts1
2 files changed, 16 insertions, 0 deletions
diff --git a/src/util/util/JSON.ts b/src/util/util/JSON.ts
new file mode 100644
index 00000000..b092eb88
--- /dev/null
+++ b/src/util/util/JSON.ts
@@ -0,0 +1,15 @@
+// Discord.com sends ISO strings with +00:00 extension, not Z
+// This causes issues with Python bot libs
+const JSONReplacer = function (
+	this: { [key: string]: unknown },
+	key: string,
+	value: unknown,
+) {
+	if (this[key] instanceof Date) {
+		return (this[key] as Date).toISOString().replace("Z", "+00:00");
+	}
+
+	return value;
+};
+
+export { JSONReplacer };
diff --git a/src/util/util/index.ts b/src/util/util/index.ts
index 543a49a9..6eb686d0 100644
--- a/src/util/util/index.ts
+++ b/src/util/util/index.ts
@@ -40,3 +40,4 @@ export * from "./TraverseDirectory";
 export * from "./InvisibleCharacters";
 export * from "./Sentry";
 export * from "./WebAuthn";
+export * from "./JSON";