image url formatter

This commit is contained in:
Skillz4Killz
2021-11-01 01:27:11 +00:00
committed by GitHub
parent 430b47ece6
commit 6b728afc29
9 changed files with 74 additions and 10 deletions
-1
View File
@@ -10,7 +10,6 @@ export function guildBannerURL(
banner?: string | bigint;
size?: DiscordImageSize;
format?: DiscordImageFormat;
animated?: boolean;
}
) {
return options.banner
-1
View File
@@ -10,7 +10,6 @@ export function guildIconURL(
icon?: string | bigint;
size?: DiscordImageSize;
format?: DiscordImageFormat;
animated?: boolean;
}
) {
return options.icon
-1
View File
@@ -10,7 +10,6 @@ export function guildSplashURL(
splash?: string | bigint;
size?: DiscordImageSize;
format?: DiscordImageFormat;
animated?: boolean;
}
) {
return options.splash
-1
View File
@@ -11,7 +11,6 @@ export function avatarURL(
avatar?: string | bigint;
size?: DiscordImageSize;
format?: DiscordImageFormat;
animated?: boolean;
}
) {
return options.avatar
+3 -3
View File
@@ -1,5 +1,5 @@
import type { Bot } from "../bot.ts";
import type { GuildMember, GuildMemberWithUser } from "../types/members/guild_member.ts";
import type { GuildMember } from "../types/members/guild_member.ts";
import type { DiscordPremiumTypes } from "../types/users/premium_types.ts";
import type { User } from "../types/users/user.ts";
import type { DiscordUserFlags } from "../types/users/user_flags.ts";
@@ -9,7 +9,7 @@ export interface DiscordenoUser {
id: bigint;
username: string;
discriminator: number;
avatar: bigint | null;
avatar?: bigint;
bot?: boolean;
system?: boolean;
locale?: string;
@@ -26,7 +26,7 @@ export function transformUser(bot: Bot, payload: SnakeCasedPropertiesDeep<User>)
id: bot.transformers.snowflake(payload.id || ""),
username: payload.username,
discriminator: Number(payload.discriminator),
avatar: payload.avatar ? bot.utils.iconHashToBigInt(payload.avatar) : null,
avatar: payload.avatar ? bot.utils.iconHashToBigInt(payload.avatar) : undefined,
bot: payload.bot,
system: payload.system,
locale: payload.locale,
-1
View File
@@ -10,7 +10,6 @@ import type { MessageComponents } from "../types/messages/components/message_com
import type { DiscordImageFormat } from "../types/misc/image_format.ts";
import type { DiscordImageSize } from "../types/misc/image_size.ts";
import { CONTEXT_MENU_COMMANDS_NAME_REGEX, SLASH_COMMANDS_NAME_REGEX } from "./constants.ts";
import { validateLength } from "./validate_length.ts";
import { isSelectMenu } from "../helpers/type_guards/is_select_menu.ts";
import { ApplicationCommandTypes } from "../types/interactions/commands/application_command_types.ts";
import { Bot } from "../bot.ts";
+5
View File
@@ -0,0 +1,5 @@
import { Bot } from "../../../src/bot.ts";
export async function avatarURL(bot: Bot, t: Deno.TestContext) {
}
+54 -2
View File
@@ -59,8 +59,6 @@ Deno.test("[Bot] - Starting Tests", async (t) => {
await startBot(bot);
// bot.rest.debug = console.log;
// Delay the execution to allow READY events to be processed
await delayUntil(10000, () => Boolean(startedAt));
console.log("Bot online");
@@ -90,6 +88,48 @@ Deno.test("[Bot] - Starting Tests", async (t) => {
throw new Error(`The guild seemed to be created but it was not cached. ${guild.id.toString()}`);
}
await Promise.all([
t.step({
name: "[guild] format a guild's icon url",
fn: async (t) => {
assertEquals(bot.helpers.guildIconURL(guild.id, { icon: guild.icon }), undefined);
assertEquals(
bot.helpers.guildIconURL(785384884197392384n, {
icon: 3837424427068676005442449262648382018748n,
}),
"https://cdn.discordapp.com/icons/785384884197392384/46f50fb412eab14ec455d5cf777154bc.jpg?size=128"
);
},
...sanitizeMode,
}),
t.step({
name: "[guild] format a guild's banner url",
fn: async (t) => {
assertEquals(bot.helpers.guildBannerURL(guild.id, { banner: guild.banner }), undefined);
assertEquals(
bot.helpers.guildBannerURL(613425648685547541n, {
banner: 3919584870146358272366452115178209474142n,
}),
"https://cdn.discordapp.com/banners/613425648685547541/84c4964c115c128fb9100952c3b4f65e.jpg?size=128"
);
},
...sanitizeMode,
}),
t.step({
name: "[guild] format a guild's splash url",
fn: async (t) => {
assertEquals(bot.helpers.guildSplashURL(guild.id, { splash: guild.splash }), undefined);
assertEquals(
bot.helpers.guildSplashURL(785384884197392384n, {
splash: 3837424427068676005442449262648382018748n,
}),
"https://cdn.discordapp.com/splashes/785384884197392384/46f50fb412eab14ec455d5cf777154bc.jpg?size=128"
);
},
...sanitizeMode,
}),
]);
// CHANNEL TESTS GROUPED
await t.step("Channel related tests", async (t) => {
const channel = await bot.helpers.createChannel(guild.id, { name: "Discordeno-test" });
@@ -418,6 +458,18 @@ Deno.test("[Bot] - Starting Tests", async (t) => {
},
...sanitizeMode,
}),
t.step({
name: "[member] format a members avatar url",
fn: async (t) => {
assertEquals(
bot.helpers.avatarURL(130136895395987456n, 8840, {
avatar: 4055337350987360625717955448021200177333n,
}),
"https://cdn.discordapp.com/avatars/130136895395987456/eae5905ad2d18d7c8deca20478b088b5.jpg?size=128"
);
},
...sanitizeMode,
}),
]);
});
+12
View File
@@ -0,0 +1,12 @@
import { formatImageURL } from "../../src/util/utils.ts";
import { assertEquals } from "../deps.ts";
Deno.test({
name: "[utils] format image url",
fn() {
assertEquals(formatImageURL(`https://skillz.com`), "https://skillz.com.jpg?size=128");
assertEquals(formatImageURL(`https://skillz.com`, 1024), "https://skillz.com.jpg?size=1024");
assertEquals(formatImageURL(`https://skillz.com`, 1024, "gif"), "https://skillz.com.gif?size=1024");
assertEquals(formatImageURL(`https://skillz.com`, undefined, "gif"), "https://skillz.com.jpg?size=128");
},
});