diff --git a/src/api/routes/channels/#channel_id/messages/#message_id/reactions.ts b/src/api/routes/channels/#channel_id/messages/#message_id/reactions.ts
index fe2a2509..63c41cd7 100644
--- a/src/api/routes/channels/#channel_id/messages/#message_id/reactions.ts
+++ b/src/api/routes/channels/#channel_id/messages/#message_id/reactions.ts
@@ -29,6 +29,7 @@ import {
MessageReactionRemoveEmojiEvent,
MessageReactionRemoveEvent,
User,
+ arrayRemove,
} from "@spacebar/util";
import { Request, Response, Router } from "express";
import { HTTPError } from "lambert-server";
@@ -112,7 +113,7 @@ router.delete(
const already_added = message.reactions.find((x) => (x.emoji.id === emoji.id && emoji.id) || x.emoji.name === emoji.name);
if (!already_added) throw new HTTPError("Reaction not found", 404);
- message.reactions.remove(already_added);
+ arrayRemove(message.reactions, already_added);
await Promise.all([
message.save(),
@@ -283,7 +284,7 @@ router.delete(
already_added.count--;
- if (already_added.count <= 0) message.reactions.remove(already_added);
+ if (already_added.count <= 0) arrayRemove(message.reactions, already_added);
else already_added.user_ids.splice(already_added.user_ids.indexOf(user_id), 1);
await message.save();
@@ -340,7 +341,7 @@ router.delete(
already_added.count--;
- if (already_added.count <= 0) message.reactions.remove(already_added);
+ if (already_added.count <= 0) arrayRemove(message.reactions, already_added);
else already_added.user_ids.splice(already_added.user_ids.indexOf(user_id), 1);
await message.save();
diff --git a/src/util/entities/Guild.ts b/src/util/entities/Guild.ts
index 0b09f859..92d4925a 100644
--- a/src/util/entities/Guild.ts
+++ b/src/util/entities/Guild.ts
@@ -30,7 +30,7 @@ import { Template } from "./Template";
import { User } from "./User";
import { VoiceState } from "./VoiceState";
import { Webhook } from "./Webhook";
-
+import { arrayRemove } from "@spacebar/util";
// TODO: application_command_count, application_command_counts: {1: 0, 2: 0, 3: 0}
// TODO: guild_scheduled_events
// TODO: stage_instances
@@ -420,7 +420,7 @@ export class Guild extends BaseClass {
if (typeof insertPoint == "string") position = guild.channel_ordering.indexOf(insertPoint) + 1;
else position = insertPoint;
- guild.channel_ordering.remove(channel_id);
+ arrayRemove(guild.channel_ordering, channel_id);
guild.channel_ordering.splice(position, 0, channel_id);
await Guild.update({ id: guild_id }, { channel_ordering: guild.channel_ordering });
diff --git a/src/util/util/extensions/Array.test.ts b/src/util/util/extensions/Array.test.ts
index 6b15f5d5..8952c901 100644
--- a/src/util/util/extensions/Array.test.ts
+++ b/src/util/util/extensions/Array.test.ts
@@ -5,11 +5,5 @@ import { describe, it } from "node:test";
import assert from "node:assert/strict";
describe("Array extensions", () => {
- it("remove", () => {
- const arr = [1, 2, 3, 4, 5];
- arr.remove(3);
- assert.deepEqual(arr, [1, 2, 4, 5]);
- arr.remove(6);
- assert.deepEqual(arr, [1, 2, 4, 5]);
- });
+ //
});
diff --git a/src/util/util/extensions/Array.ts b/src/util/util/extensions/Array.ts
index b58b1c03..bbd86164 100644
--- a/src/util/util/extensions/Array.ts
+++ b/src/util/util/extensions/Array.ts
@@ -18,10 +18,12 @@
declare global {
interface Array<T> {
- remove(item: T): void;
+ /**
+ * @deprecated never use, idk why but I can't get rid of this without errors
+ */
+ remove(h: T): never;
}
}
-
/* https://stackoverflow.com/a/50636286 */
export function arrayPartition<T>(array: T[], filter: (elem: T) => boolean): [T[], T[]] {
const pass: T[] = [],
@@ -30,16 +32,11 @@ export function arrayPartition<T>(array: T[], filter: (elem: T) => boolean): [T[
return [pass, fail];
}
-export function arrayRemove<T>(this: T[], item: T): void {
- const index = this.indexOf(item);
+export function arrayRemove<T>(array: T[], item: T): void {
+ const index = array.indexOf(item);
if (index > -1) {
- this.splice(index, 1);
+ array.splice(index, 1);
}
}
// register extensions
-
-if (!Array.prototype.remove)
- Array.prototype.remove = function <T>(this: T[], item: T) {
- return arrayRemove.call(this, item);
- };
|