From f09a6976b27743322b6cf760c677340ddd428ec0 Mon Sep 17 00:00:00 2001 From: MathMan05 Date: Wed, 26 Nov 2025 15:55:47 -0600 Subject: [PATCH] remove remove --- .../messages/#message_id/reactions.ts | 7 ++++--- src/util/entities/Guild.ts | 4 ++-- src/util/util/extensions/Array.test.ts | 8 +------- src/util/util/extensions/Array.ts | 17 +++++++---------- 4 files changed, 14 insertions(+), 22 deletions(-) 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 fe2a25098..63c41cd7e 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 0b09f8594..92d4925a3 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 6b15f5d55..8952c9016 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 b58b1c03a..bbd861643 100644 --- a/src/util/util/extensions/Array.ts +++ b/src/util/util/extensions/Array.ts @@ -18,10 +18,12 @@ declare global { interface Array { - 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(array: T[], filter: (elem: T) => boolean): [T[], T[]] { const pass: T[] = [], @@ -30,16 +32,11 @@ export function arrayPartition(array: T[], filter: (elem: T) => boolean): [T[ return [pass, fail]; } -export function arrayRemove(this: T[], item: T): void { - const index = this.indexOf(item); +export function arrayRemove(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 (this: T[], item: T) { - return arrayRemove.call(this, item); - };