fix: remove url parser and make it optional

This commit is contained in:
Yuzu 2022-07-28 13:26:26 -05:00
parent b26944e237
commit c279972c1b
3 changed files with 22 additions and 70 deletions

View File

@ -4,7 +4,7 @@
"entry": "./mod.ts", "entry": "./mod.ts",
"description": "A brand new bleeding edge non bloated Discord library", "description": "A brand new bleeding edge non bloated Discord library",
"homepage": "https://github.com/oasisjs/biscuit", "homepage": "https://github.com/oasisjs/biscuit",
"version": "0.2.2", "version": "0.2.3",
"releaseType": "patch", "releaseType": "patch",
"unstable": false, "unstable": false,
"unlisted": false, "unlisted": false,

View File

@ -209,11 +209,10 @@ export class Session extends EventEmitter {
return super.emit(event, ...params); return super.emit(event, ...params);
} }
async editProfile(nick?: string, avatarURL?: string | null): Promise<User> { async editProfile(nick?: string, avatar?: string): Promise<User> {
const avatar = avatarURL ? await urlToBase64(avatarURL) : avatarURL;
const user = await this.rest.runMethod<DiscordUser>(this.rest, 'PATCH', Routes.USER(), { const user = await this.rest.runMethod<DiscordUser>(this.rest, 'PATCH', Routes.USER(), {
username: nick, username: nick ?? null,
avatar: avatar, avatar: avatar ?? null,
}); });
return new User(this, user); return new User(this, user);
} }

View File

@ -356,19 +356,7 @@ export interface GuildCreateOptionsRole {
position?: number; position?: number;
permissions?: bigint; permissions?: bigint;
mentionable?: boolean; mentionable?: boolean;
iconURL?: string; icon?: string;
unicodeEmoji?: string | null;
}
export interface GuildCreateOptionsRole {
id: Snowflake;
name?: string;
color?: number;
hoist?: boolean;
position?: number;
permissions?: bigint;
mentionable?: boolean;
iconHash?: bigint;
unicodeEmoji?: string | null; unicodeEmoji?: string | null;
} }
@ -397,21 +385,7 @@ export interface GuildCreateOptions {
channels?: GuildCreateOptionsChannel[]; channels?: GuildCreateOptionsChannel[];
defaultMessageNotifications?: DefaultMessageNotificationLevels; defaultMessageNotifications?: DefaultMessageNotificationLevels;
explicitContentFilter?: ExplicitContentFilterLevels; explicitContentFilter?: ExplicitContentFilterLevels;
iconURL?: string; icon?: string;
roles?: GuildCreateOptionsRole[];
systemChannelFlags?: SystemChannelFlags;
systemChannelId?: Snowflake;
verificationLevel?: VerificationLevels;
}
export interface GuildCreateOptions {
name: string;
afkChannelId?: Snowflake;
afkTimeout?: number;
channels?: GuildCreateOptionsChannel[];
defaultMessageNotifications?: DefaultMessageNotificationLevels;
explicitContentFilter?: ExplicitContentFilterLevels;
iconHash?: bigint;
roles?: GuildCreateOptionsRole[]; roles?: GuildCreateOptionsRole[];
systemChannelFlags?: SystemChannelFlags; systemChannelFlags?: SystemChannelFlags;
systemChannelId?: Snowflake; systemChannelId?: Snowflake;
@ -423,26 +397,15 @@ export interface GuildCreateOptions {
*/ */
export interface GuildEditOptions extends Partial<GuildCreateOptions> { export interface GuildEditOptions extends Partial<GuildCreateOptions> {
ownerId?: Snowflake; ownerId?: Snowflake;
splashURL?: string; splash?: string;
bannerURL?: string; banner?: string;
discoverySplashURL?: string; discoverySplash?: string;
features?: GuildFeatures[]; features?: GuildFeatures[];
rulesChannelId?: Snowflake; rulesChannelId?: Snowflake;
description?: string; description?: string;
premiumProgressBarEnabled?: boolean; premiumProgressBarEnabled?: boolean;
}
export interface GuildEditOptions extends Partial<GuildCreateOptions> {
ownerId?: Snowflake;
splashHash?: bigint;
bannerHash?: bigint;
discoverySplashHash?: bigint;
features?: GuildFeatures[];
rulesChannelId?: Snowflake;
publicUpdatesChannelId?: Snowflake; publicUpdatesChannelId?: Snowflake;
preferredLocale?: string | null; preferredLocale?: string;
description?: string;
premiumProgressBarEnabled?: boolean;
} }
/** /**
@ -978,9 +941,7 @@ export class Guild extends BaseGuild implements Model {
explicit_content_filter: options.explicitContentFilter, explicit_content_filter: options.explicitContentFilter,
system_channel_flags: options.systemChannelFlags, system_channel_flags: options.systemChannelFlags,
verification_level: options.verificationLevel, verification_level: options.verificationLevel,
icon: 'iconURL' in options icon: options.icon,
? options.iconURL && urlToBase64(options.iconURL)
: options.iconHash && Util.iconBigintToHash(options.iconHash),
channels: options.channels?.map((channel) => ({ channels: options.channels?.map((channel) => ({
name: channel.name, name: channel.name,
nsfw: channel.nsfw, nsfw: channel.nsfw,
@ -1001,7 +962,7 @@ export class Guild extends BaseGuild implements Model {
hoist: role.hoist, hoist: role.hoist,
position: role.position, position: role.position,
unicode_emoji: role.unicodeEmoji, unicode_emoji: role.unicodeEmoji,
icon: options.iconURL && urlToBase64(options.iconURL), icon: options.icon,
})), })),
}); });
@ -1012,24 +973,24 @@ export class Guild extends BaseGuild implements Model {
* sets a new splash for the guild. Same as Guild.edit({..., splash: 'splashURL'}) * sets a new splash for the guild. Same as Guild.edit({..., splash: 'splashURL'})
* @see {@link Guild} * @see {@link Guild}
*/ */
setSplash(splashURL: string): Promise<Guild> { setSplash(splash: string): Promise<Guild> {
return this.edit({ splashURL }); return this.edit({ splash });
} }
/** /**
* sets a new banner for the guild. Same as Guild.edit({..., banner: 'bannerURL'}) * sets a new banner for the guild. Same as Guild.edit({..., banner: 'bannerURL'})
* @see {@link Guild} * @see {@link Guild}
*/ */
setBanner(bannerURL: string): Promise<Guild> { setBanner(banner: string): Promise<Guild> {
return this.edit({ bannerURL }); return this.edit({ banner });
} }
/** /**
* Sets a new guild discovery splash image. Same as Guild.edit({..., discoverySplashURL: 'discoverySplashURL'}) * Sets a new guild discovery splash image. Same as Guild.edit({..., discoverySplashURL: 'discoverySplashURL'})
* @see {@link Guild} * @see {@link Guild}
*/ */
setDiscoverySplash(discoverySplashURL: string): Promise<Guild> { setDiscoverySplash(discoverySplash: string): Promise<Guild> {
return this.edit({ discoverySplashURL }); return this.edit({ discoverySplash });
} }
/** /**
@ -1052,19 +1013,11 @@ export class Guild extends BaseGuild implements Model {
explicit_content_filter: options.explicitContentFilter, explicit_content_filter: options.explicitContentFilter,
system_channel_flags: options.systemChannelFlags, system_channel_flags: options.systemChannelFlags,
verification_level: options.verificationLevel, verification_level: options.verificationLevel,
icon: 'iconURL' in options icon: options.icon,
? options.iconURL && urlToBase64(options.iconURL)
: options.iconHash && Util.iconBigintToHash(options.iconHash),
// extra props // extra props
splash: 'splashURL' in options splash: options.splash,
? options.splashURL && urlToBase64(options.splashURL) banner: options.banner,
: options.iconHash && Util.iconBigintToHash(options.iconHash), discovery_splash: options.discoverySplash,
banner: 'bannerURL' in options
? options.bannerURL && urlToBase64(options.bannerURL)
: options.bannerHash && Util.iconBigintToHash(options.bannerHash),
discovery_splash: 'discoverySplashURL' in options
? options.discoverySplashURL && urlToBase64(options.discoverySplashURL)
: options.discoverySplashHash && Util.iconBigintToHash(options.discoverySplashHash),
owner_id: options.ownerId, owner_id: options.ownerId,
rules_channel_id: options.rulesChannelId, rules_channel_id: options.rulesChannelId,
public_updates_channel_id: options.publicUpdatesChannelId, public_updates_channel_id: options.publicUpdatesChannelId,