rid of contains all

This commit is contained in:
MathMan05
2025-11-25 23:34:20 -06:00
parent b3de3ddd9c
commit 9871ce0028
3 changed files with 3 additions and 24 deletions
+3 -3
View File
@@ -280,7 +280,7 @@ export class Channel extends BaseClass {
if (!ur.channel.recipients) continue;
const re = ur.channel.recipients.map((r) => r.user_id);
if (re.length === channelRecipients.length) {
if (re.containsAll(channelRecipients)) {
if (channelRecipients.every((_) => re.includes(_))) {
if (channel == null) {
channel = ur.channel;
await ur.assign({ closed: false }).save();
@@ -429,7 +429,7 @@ export class Channel extends BaseClass {
}
async getUserPermissions(opts: { user_id?: string; user?: User; member?: Member; guild?: Guild }): Promise<Permissions> {
if(this.isDm()) this.owner_id == (opts.user_id ?? opts.user?.id) ? Permissions.ALL : Permissions.DEFAULT_DM_PERMISSIONS;
if (this.isDm()) return this.owner_id == (opts.user_id ?? opts.user?.id) ? Permissions.ALL : Permissions.DEFAULT_DM_PERMISSIONS;
let guild = opts.guild;
if (!guild) {
if (this.guild) guild = this.guild;
@@ -470,7 +470,7 @@ export class Channel extends BaseClass {
position: true,
},
},
loadEagerRelations: false
loadEagerRelations: false,
})
).roles
).sort((a, b) => a.position - b.position); // ascending by position
-12
View File
@@ -5,18 +5,6 @@ import { describe, it } from "node:test";
import assert from "node:assert/strict";
describe("Array extensions", () => {
it("containsAll", () => {
const arr = [1, 2, 3, 4, 5];
assert(arr.containsAll([1, 2]));
assert(!arr.containsAll([1, 6]));
assert(arr.containsAll([]));
assert([].containsAll([]));
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
assert(![].containsAll([1]));
});
it("partition", () => {
const arr = [1, 2, 3, 4, 5];
const [even, odd] = arr.partition((n) => n % 2 === 0);
-9
View File
@@ -18,7 +18,6 @@
declare global {
interface Array<T> {
containsAll(target: T[]): boolean;
partition(filter: (elem: T) => boolean): [T[], T[]];
forEachAsync(callback: (elem: T, index: number, array: T[]) => Promise<void>): Promise<void>;
filterAsync(callback: (elem: T, index: number, array: T[]) => Promise<boolean>): Promise<T[]>;
@@ -28,10 +27,6 @@ declare global {
}
}
export function arrayContainsAll<T>(arr: T[], target: T[]) {
return target.every((v) => arr.includes(v));
}
/* https://stackoverflow.com/a/50636286 */
export function arrayPartition<T>(array: T[], filter: (elem: T) => boolean): [T[], T[]] {
const pass: T[] = [],
@@ -86,10 +81,6 @@ export function arrayIntersect<T>(this: T[], other: T[]): T[] {
}
// register extensions
if (!Array.prototype.containsAll)
Array.prototype.containsAll = function <T>(this: T[], target: T[]) {
return arrayContainsAll(this, target);
};
if (!Array.prototype.partition)
Array.prototype.partition = function <T>(this: T[], filter: (elem: T) => boolean) {
return arrayPartition(this, filter);