diff --git a/egg.json b/egg.json index 080b13e..c583a8d 100644 --- a/egg.json +++ b/egg.json @@ -1,27 +1,27 @@ { - "$schema": "https://x.nest.land/eggs@0.3.10/src/schema.json", - "name": "biscuit", - "entry": "./mod.ts", - "description": "A brand new bleeding edge non bloated Discord library", - "homepage": "https://github.com/oasisjs/biscuit", - "version": "0.2.0", - "releaseType": "minor", - "unstable": false, - "unlisted": false, - "files": [ - "./packages/**/*", - "./mod.ts", - "LICENSE", - "README.md" - ], - "ignore": [ - "npm", - "build.ts", - "scripts.ts", - ".git" - ], - "checkFormat": true, - "checkTests": false, - "checkInstallation": false, - "check": true + "$schema": "https://x.nest.land/eggs@0.3.10/src/schema.json", + "name": "biscuit", + "entry": "./mod.ts", + "description": "A brand new bleeding edge non bloated Discord library", + "homepage": "https://github.com/oasisjs/biscuit", + "version": "0.2.0", + "releaseType": "minor", + "unstable": false, + "unlisted": false, + "files": [ + "./packages/**/*", + "./mod.ts", + "LICENSE", + "README.md" + ], + "ignore": [ + "npm", + "build.ts", + "scripts.ts", + ".git" + ], + "checkFormat": true, + "checkTests": false, + "checkInstallation": false, + "check": true } diff --git a/packages/biscuit/Session.ts b/packages/biscuit/Session.ts index eb90f31..76f37c2 100644 --- a/packages/biscuit/Session.ts +++ b/packages/biscuit/Session.ts @@ -241,20 +241,19 @@ export class Session extends EventEmitter { application_id: this.applicationId, details: activity.details, state: activity.state, - emoji: activity.emoji || { - name: activity.emoji!.name, - id: activity.emoji!.id, - animated: activity.emoji!.animated, + emoji: activity.emoji && { + name: activity.emoji.name, + id: activity.emoji.id, + animated: activity.emoji.animated, }, party: activity.party, - assets: activity.assets - ? { + assets: activity.assets && + { large_image: activity.assets.largeImage, large_text: activity.assets.largeText, small_image: activity.assets.smallImage, small_text: activity.assets.smallText, - } - : undefined, + }, secrets: activity.secrets, instance: activity.instance, flags: activity.flags, diff --git a/packages/biscuit/structures/Embed.ts b/packages/biscuit/structures/Embed.ts index fc06763..2e0c867 100644 --- a/packages/biscuit/structures/Embed.ts +++ b/packages/biscuit/structures/Embed.ts @@ -55,16 +55,16 @@ export function embed(data: Embed): DiscordEmbed { url: data.url, color: data.color, description: data.description, - author: { - name: data.author?.name!, - url: data.author?.url, - icon_url: data.author?.iconURL, - proxy_icon_url: data.author?.proxyIconURL, + author: data.author && { + name: data.author.name, + url: data.author.url, + icon_url: data.author.iconURL, + proxy_icon_url: data.author.proxyIconURL, }, - footer: data.footer || { - text: data.footer!.text, - icon_url: data.footer!.iconURL, - proxy_icon_url: data.footer!.proxyIconURL, + footer: data.footer && { + text: data.footer.text, + icon_url: data.footer.iconURL, + proxy_icon_url: data.footer.proxyIconURL, }, fields: data.fields?.map((f) => { return { @@ -73,11 +73,11 @@ export function embed(data: Embed): DiscordEmbed { inline: f.inline, }; }), - thumbnail: data.thumbnail || { - url: data.thumbnail!.url, - proxy_url: data.thumbnail!.proxyURL, - width: data.thumbnail!.width, - height: data.thumbnail!.height, + thumbnail: data.thumbnail && { + url: data.thumbnail.url, + proxy_url: data.thumbnail.proxyURL, + width: data.thumbnail.width, + height: data.thumbnail.height, }, video: { url: data.video?.url, @@ -85,11 +85,11 @@ export function embed(data: Embed): DiscordEmbed { width: data.video?.width, height: data.video?.height, }, - image: data.image || { - url: data.image!.url, - proxy_url: data.image!.proxyURL, - width: data.image!.width, - height: data.image!.height, + image: data.image && { + url: data.image.url, + proxy_url: data.image.proxyURL, + width: data.image.width, + height: data.image.height, }, provider: { url: data.provider?.url, diff --git a/packages/biscuit/structures/Invite.ts b/packages/biscuit/structures/Invite.ts index 759f8aa..ce7824f 100644 --- a/packages/biscuit/structures/Invite.ts +++ b/packages/biscuit/structures/Invite.ts @@ -74,9 +74,8 @@ export function NewInviteCreate(session: Session, invite: DiscordInviteCreate): maxUses: invite.max_uses, targetType: invite.target_type, targetUser: invite.target_user ? new User(session, invite.target_user) : undefined, - targetApplication: invite.target_application - ? new Application(session, invite.target_application as DiscordApplication) - : undefined, + targetApplication: invite.target_application && + new Application(session, invite.target_application as DiscordApplication), temporary: invite.temporary, uses: invite.uses, }; diff --git a/packages/biscuit/structures/Webhook.ts b/packages/biscuit/structures/Webhook.ts index 9e098f0..1d38dd1 100644 --- a/packages/biscuit/structures/Webhook.ts +++ b/packages/biscuit/structures/Webhook.ts @@ -155,11 +155,11 @@ export class Webhook implements Model { embeds: options?.embeds, file: options?.files, components: options?.components, - allowed_mentions: options?.allowedMentions || { - parse: options?.allowedMentions!.parse, - replied_user: options?.allowedMentions!.repliedUser, - users: options?.allowedMentions!.users, - roles: options?.allowedMentions!.roles, + allowed_mentions: options?.allowedMentions && { + parse: options?.allowedMentions.parse, + replied_user: options?.allowedMentions.repliedUser, + users: options?.allowedMentions.users, + roles: options?.allowedMentions.roles, }, attachments: options?.attachments?.map((attachment) => { return { diff --git a/packages/biscuit/structures/guilds.ts b/packages/biscuit/structures/guilds.ts index f4ff740..71dbd54 100644 --- a/packages/biscuit/structures/guilds.ts +++ b/packages/biscuit/structures/guilds.ts @@ -682,8 +682,8 @@ export class Guild extends BaseGuild implements Model { system_channel_flags: options.systemChannelFlags, verification_level: options.verificationLevel, icon: "iconURL" in options - ? options.iconURL || urlToBase64(options.iconURL!) - : options.iconHash || Util.iconBigintToHash(options.iconHash!), + ? options.iconURL && urlToBase64(options.iconURL) + : options.iconHash && Util.iconBigintToHash(options.iconHash), channels: options.channels?.map((channel) => ({ name: channel.name, nsfw: channel.nsfw, @@ -704,7 +704,7 @@ export class Guild extends BaseGuild implements Model { hoist: role.hoist, position: role.position, unicode_emoji: role.unicodeEmoji, - icon: options.iconURL || urlToBase64(options.iconURL!), + icon: options.iconURL && urlToBase64(options.iconURL), })), }); @@ -745,18 +745,18 @@ export class Guild extends BaseGuild implements Model { system_channel_flags: options.systemChannelFlags, verification_level: options.verificationLevel, icon: "iconURL" in options - ? options.iconURL || urlToBase64(options.iconURL!) - : options.iconHash || Util.iconBigintToHash(options.iconHash!), + ? options.iconURL && urlToBase64(options.iconURL) + : options.iconHash && Util.iconBigintToHash(options.iconHash), // extra props splash: "splashURL" in options - ? options.splashURL || urlToBase64(options.splashURL!) - : options.splashHash || Util.iconBigintToHash(options.iconHash!), + ? options.splashURL && urlToBase64(options.splashURL) + : options.iconHash && Util.iconBigintToHash(options.iconHash), banner: "bannerURL" in options - ? options.bannerURL || urlToBase64(options.bannerURL!) - : options.bannerHash || Util.iconBigintToHash(options.bannerHash!), + ? 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!), + ? options.discoverySplashURL && urlToBase64(options.discoverySplashURL) + : options.discoverySplashHash && Util.iconBigintToHash(options.discoverySplashHash), owner_id: options.ownerId, rules_channel_id: options.rulesChannelId, public_updates_channel_id: options.publicUpdatesChannelId, diff --git a/packages/biscuit/structures/interactions/BaseInteraction.ts b/packages/biscuit/structures/interactions/BaseInteraction.ts index 95a7ce7..3cba34c 100644 --- a/packages/biscuit/structures/interactions/BaseInteraction.ts +++ b/packages/biscuit/structures/interactions/BaseInteraction.ts @@ -133,11 +133,11 @@ export abstract class BaseInteraction implements Model { embeds: options.embeds, file: options.files, components: options.components, - allowed_mentions: options.allowedMentions || { - parse: options.allowedMentions!.parse, - replied_user: options.allowedMentions!.repliedUser, - users: options.allowedMentions!.users, - roles: options.allowedMentions!.roles, + allowed_mentions: options.allowedMentions && { + parse: options.allowedMentions.parse, + replied_user: options.allowedMentions.repliedUser, + users: options.allowedMentions.users, + roles: options.allowedMentions.roles, }, attachments: options.attachments?.map((attachment) => { return {