mirror of
https://github.com/spacebarchat/server.git
synced 2026-07-29 11:49:24 +00:00
remove remove
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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 });
|
||||
|
||||
@@ -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]);
|
||||
});
|
||||
//
|
||||
});
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user