mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-01 20:46:08 +00:00
fix: the function was being misused
This commit is contained in:
parent
9066f510e3
commit
603865917b
@ -1,7 +1,7 @@
|
||||
import type { APIAttachment, RESTAPIAttachment } from '../types';
|
||||
import { randomBytes } from 'node:crypto';
|
||||
import path from 'node:path';
|
||||
import { type UsingClient, throwError, type RawFile } from '..';
|
||||
import type { UsingClient, RawFile } from '..';
|
||||
import type { ImageResolvable, ObjectToLower } from '../common';
|
||||
import { Base } from '../structures/extra/Base';
|
||||
import { promises } from 'node:fs';
|
||||
@ -183,14 +183,14 @@ export async function resolveAttachmentData(
|
||||
}> {
|
||||
if (data instanceof AttachmentBuilder) {
|
||||
if (!data.data.resolvable)
|
||||
return throwError('The attachment type has been expressed as attachment but cannot be resolved as one.');
|
||||
throw new Error('The attachment type has been expressed as attachment but cannot be resolved as one.');
|
||||
return { data: data.data.resolvable! };
|
||||
}
|
||||
|
||||
switch (type) {
|
||||
case 'url': {
|
||||
if (!/^https?:\/\//.test(data as string))
|
||||
return throwError(
|
||||
throw new Error(
|
||||
`The attachment type has been expressed as ${type.toUpperCase()} but cannot be resolved as one.`,
|
||||
);
|
||||
const res = await fetch(data as string);
|
||||
@ -200,7 +200,7 @@ export async function resolveAttachmentData(
|
||||
const file = path.resolve(data as string);
|
||||
const stats = await promises.stat(file);
|
||||
if (!stats.isFile())
|
||||
return throwError(
|
||||
throw new Error(
|
||||
`The attachment type has been expressed as ${type.toUpperCase()} but cannot be resolved as one.`,
|
||||
);
|
||||
return { data: await promises.readFile(file) };
|
||||
@ -213,12 +213,10 @@ export async function resolveAttachmentData(
|
||||
for await (const resource of data as unknown as AsyncIterable<ArrayBuffer>) buffers.push(Buffer.from(resource));
|
||||
return { data: Buffer.concat(buffers) };
|
||||
}
|
||||
return throwError(
|
||||
`The attachment type has been expressed as ${type.toUpperCase()} but cannot be resolved as one.`,
|
||||
);
|
||||
throw new Error(`The attachment type has been expressed as ${type.toUpperCase()} but cannot be resolved as one.`);
|
||||
}
|
||||
default: {
|
||||
return throwError(`The attachment type has been expressed as ${type} but cannot be resolved as one.`);
|
||||
throw new Error(`The attachment type has been expressed as ${type} but cannot be resolved as one.`);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -244,7 +242,7 @@ export async function resolveImage(image: ImageResolvable): Promise<string> {
|
||||
data: { type, resolvable },
|
||||
} = image;
|
||||
if (type && resolvable) return resolveBase64((await resolveAttachmentData(resolvable, type)).data as Buffer);
|
||||
return throwError(
|
||||
throw new Error(
|
||||
`The attachment type has been expressed as ${(type ?? 'Attachment').toUpperCase()} but cannot be resolved as one.`,
|
||||
);
|
||||
}
|
||||
|
@ -1,6 +1,5 @@
|
||||
import { type APIPollMedia, PollLayoutType, type RESTAPIPollCreate } from '../types';
|
||||
import type { DeepPartial, EmojiResolvable, RestOrArray } from '../common';
|
||||
import { throwError } from '..';
|
||||
import { resolvePartialEmoji } from '../structures/extra/functions';
|
||||
|
||||
export class PollBuilder {
|
||||
@ -45,7 +44,7 @@ export class PollBuilder {
|
||||
private resolvedPollMedia(data: PollMedia) {
|
||||
if (!data.emoji) return { text: data.text };
|
||||
const resolve = resolvePartialEmoji(data.emoji);
|
||||
if (!resolve) return throwError('Invalid Emoji');
|
||||
if (!resolve) throw new Error('Invalid Emoji');
|
||||
return { text: data.text, emoji: resolve };
|
||||
}
|
||||
}
|
||||
|
@ -12,7 +12,6 @@ import {
|
||||
ComponentType,
|
||||
SelectMenuDefaultValueType,
|
||||
} from '../types';
|
||||
import { throwError } from '..';
|
||||
import type { EmojiResolvable, RestOrArray, ToClass } from '../common';
|
||||
import type {
|
||||
ChannelSelectMenuInteraction,
|
||||
@ -368,7 +367,7 @@ export class StringSelectOption {
|
||||
*/
|
||||
setEmoji(emoji: EmojiResolvable) {
|
||||
const resolve = resolvePartialEmoji(emoji);
|
||||
if (!resolve) return throwError('Invalid Emoji');
|
||||
if (!resolve) throw new Error('Invalid Emoji');
|
||||
this.data.emoji = resolve as APIMessageComponentEmoji;
|
||||
return this;
|
||||
}
|
||||
|
@ -28,10 +28,6 @@ export * from './structures';
|
||||
export * from './client';
|
||||
///
|
||||
|
||||
export function throwError(msg: string): never {
|
||||
throw new Error(msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an event with the specified data and run function.
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user