mirror of
https://github.com/discordeno/discordeno.git
synced 2026-05-31 07:50:07 +00:00
* feat: Add return types to forum channel helpers. * fix: Use Discord-defined property names. Add `flags` property. * feat: Add return types to thread channel helpers. * feat: Add return types to channel helpers. * feat: Add return types to server discovery helpers. * misc!: Consistency: 'remove' -> 'delete'. * misc!: Add `get` keyword to function and file name. * feat: Add return types to emoji helpers. * misc!: Remove unused `bot` parameter. Capitalise 'URL'. * feat: Add return types to guild automod helpers. * feat: Add return types to guild scheduled event helpers. * misc!: Consistency: Rename `emojiURL` to `getEmojiURL`. * feat: Add return types to guild helpers. * misc!: Consistency: Add 'get' keyword to function and file names. * feat: Add return types to invite helpers. * feat: Add return types to integration helpers. * feat: Add return types to application command helpers. * feat: Add return types to followup message helpers. * feat: Add return types to interaction response helpers. * feat: Add return type to `createInvite()`. * feat: Add return types to member helpers. * misc!: Consistency: Add 'get' keyword to function and file names. * feat: Add return types to message helpers. * misc!: Consistency: 'remove' -> 'delete'. * fix: Use `slice()` to prevent unwanted side effects. * feat: Add return types to miscellaneous helpers. * misc!: Consistency: Add 'get' keyword to function and file names. * feat: Add return types to role helpers. * feat: Add return types to oauth helpers. * feat: Add return types to template helpers. * misc!: Consistency: Add 'guild' keyword to name. * feat: Add return types to voice helpers. * fix: Name function correctly. * feat: Add return types to webhook helpers. * misc!: Consistency: Rename `sendWebhook` to `sendWebhookMessage`. * misc: Update exports. * fix: Imports. * fix: Change return collection key type from `string` to `bigint`. Remove redundant code. * misc: Remove `undefined` from `runMethod()` return type. * style: Remove redundant types. * style: Rename endpoint call result variables to `result` and `results`. * misc: Reintroduce `bot` as first parameter. * misc: Adapt tests to changes made to helpers. * fix: Object being transformed twice. * style: Improve naming consistency of remaining files. * misc: `bigint` -> `number`. * style: Remove explicit `undefined` return. * style: Remove `void` operator in favour of generic type. * misc: Add missing `await` keyword. Co-authored-by: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> * style: Make `reason` property optional instead of `undefined`-able. * misc: Write out properties manually instead of using the spread operator. Co-authored-by: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com>
201 lines
5.4 KiB
TypeScript
201 lines
5.4 KiB
TypeScript
import { formatImageURL, hasProperty, iconBigintToHash, iconHashToBigInt, validateLength } from "../mod.ts";
|
|
import { bigintToSnowflake, snowflakeToBigint } from "../util/bigint.ts";
|
|
import { removeTokenPrefix } from "../util/token.ts";
|
|
import { assertEquals, assertNotEquals } from "./deps.ts";
|
|
import { loadBot } from "./mod.ts";
|
|
|
|
Deno.test({
|
|
name: "[token] Remove token prefix when Bot is prefixed.",
|
|
async fn(t) {
|
|
assertEquals("discordeno is best lib", removeTokenPrefix("Bot discordeno is best lib"));
|
|
},
|
|
});
|
|
|
|
Deno.test({
|
|
name: "[token] Remove token prefix when Bot is NOT prefixed.",
|
|
async fn(t) {
|
|
assertEquals("discordeno is best lib", removeTokenPrefix("discordeno is best lib"));
|
|
},
|
|
});
|
|
|
|
Deno.test("[bigint] - Transform a snowflake string to bigint", () => {
|
|
const text = "130136895395987456";
|
|
const big = 130136895395987456n;
|
|
const result = snowflakeToBigint(text);
|
|
|
|
assertEquals(big, result);
|
|
assertNotEquals(text, result);
|
|
});
|
|
|
|
Deno.test("[bigint] - Transform a bigint to a string", () => {
|
|
const text = "130136895395987456";
|
|
const big = 130136895395987456n;
|
|
const result = bigintToSnowflake(big);
|
|
|
|
assertEquals(text, result);
|
|
assertNotEquals(big, result);
|
|
});
|
|
|
|
Deno.test("[emoji] Create an emoji url", async () => {
|
|
const bot = loadBot();
|
|
assertEquals(
|
|
bot.helpers.getEmojiURL(785403373817823272n, false),
|
|
"https://cdn.discordapp.com/emojis/785403373817823272.png",
|
|
);
|
|
assertEquals(
|
|
bot.helpers.getEmojiURL(785403373817823272n, true),
|
|
"https://cdn.discordapp.com/emojis/785403373817823272.gif",
|
|
);
|
|
});
|
|
|
|
Deno.test({
|
|
name: "[guild] format a guild's icon url",
|
|
fn: async () => {
|
|
const bot = loadBot();
|
|
assertEquals(
|
|
bot.helpers.getGuildIconURL(785384884197392384n, 3837424427068676005442449262648382018748n),
|
|
"https://cdn.discordapp.com/icons/785384884197392384/46f50fb412eab14ec455d5cf777154bc.jpg?size=128",
|
|
);
|
|
},
|
|
});
|
|
|
|
Deno.test({
|
|
name: "[guild] format a guild's banner url",
|
|
fn: async () => {
|
|
const bot = loadBot();
|
|
|
|
assertEquals(
|
|
bot.helpers.getGuildBannerURL(613425648685547541n, {
|
|
banner: 3919584870146358272366452115178209474142n,
|
|
}),
|
|
"https://cdn.discordapp.com/banners/613425648685547541/84c4964c115c128fb9100952c3b4f65e.jpg?size=128",
|
|
);
|
|
},
|
|
});
|
|
|
|
Deno.test({
|
|
name: "[guild] format a guild's splash url",
|
|
fn: async () => {
|
|
const bot = loadBot();
|
|
assertEquals(
|
|
bot.helpers.getGuildSplashURL(785384884197392384n, 3837424427068676005442449262648382018748n),
|
|
"https://cdn.discordapp.com/splashes/785384884197392384/46f50fb412eab14ec455d5cf777154bc.jpg?size=128",
|
|
);
|
|
},
|
|
});
|
|
|
|
Deno.test({
|
|
name: "[utils] format image url",
|
|
fn() {
|
|
assertEquals(formatImageURL(`https://skillz.is.pro`), "https://skillz.is.pro.jpg?size=128");
|
|
assertEquals(formatImageURL(`https://skillz.is.pro`, 1024), "https://skillz.is.pro.jpg?size=1024");
|
|
assertEquals(formatImageURL(`https://skillz.is.pro`, 1024, "gif"), "https://skillz.is.pro.gif?size=1024");
|
|
assertEquals(formatImageURL(`https://skillz.is.pro`, undefined, "gif"), "https://skillz.is.pro.gif?size=128");
|
|
},
|
|
});
|
|
|
|
const iconHash = "4bbb271a13f7195031adcc06a2d867ce";
|
|
const iconBigInt = 3843769888406823508519992434416504301518n;
|
|
const a_iconHash = "a_4bbb271a13f7195031adcc06a2d867ce";
|
|
const a_iconBigInt = 3503487521485885045056617826984736090062n;
|
|
|
|
Deno.test({
|
|
name: "[utils] icon hash to bigint",
|
|
fn() {
|
|
assertEquals(iconHashToBigInt(iconHash), iconBigInt);
|
|
},
|
|
});
|
|
|
|
Deno.test({
|
|
name: "[utils] icon bigint to hash",
|
|
fn() {
|
|
assertEquals(iconBigintToHash(iconBigInt), iconHash);
|
|
},
|
|
});
|
|
|
|
Deno.test({
|
|
name: "[utils] icon hash to bigint a_ (animated)",
|
|
fn() {
|
|
assertEquals(iconHashToBigInt(a_iconHash), a_iconBigInt);
|
|
},
|
|
});
|
|
|
|
Deno.test({
|
|
name: "[utils] icon bigint to hash a_ (animated)",
|
|
fn() {
|
|
assertEquals(iconBigintToHash(a_iconBigInt), a_iconHash);
|
|
},
|
|
});
|
|
|
|
Deno.test({
|
|
name: "[utils] Validate length is too low",
|
|
fn() {
|
|
assertEquals(validateLength("test", { min: 5 }), false);
|
|
},
|
|
});
|
|
|
|
Deno.test({
|
|
name: "[utils] Validate length is too high",
|
|
fn() {
|
|
assertEquals(validateLength("test", { max: 3 }), false);
|
|
},
|
|
});
|
|
|
|
Deno.test({
|
|
name: "[utils] Validate length is NOT just right in between.",
|
|
fn() {
|
|
assertEquals(validateLength("test", { min: 5, max: 3 }), false);
|
|
},
|
|
});
|
|
|
|
Deno.test({
|
|
name: "[utils] Validate length is NOT too low",
|
|
fn() {
|
|
assertEquals(validateLength("test", { min: 3 }), true);
|
|
},
|
|
});
|
|
|
|
Deno.test({
|
|
name: "[utils] Validate length is NOT too high",
|
|
fn() {
|
|
assertEquals(validateLength("test", { max: 5 }), true);
|
|
},
|
|
});
|
|
|
|
Deno.test({
|
|
name: "[utils] Validate length is just right in between.",
|
|
fn() {
|
|
assertEquals(validateLength("test", { min: 3, max: 6 }), true);
|
|
},
|
|
});
|
|
|
|
const obj = { prop: "lts372005" };
|
|
|
|
Deno.test({
|
|
name: "[utils] hasProperty does HAVE property",
|
|
fn() {
|
|
assertEquals(hasProperty(obj, "prop"), true);
|
|
},
|
|
});
|
|
|
|
Deno.test({
|
|
name: "[utils] hasProperty does NOT HAVE property",
|
|
fn() {
|
|
assertEquals(hasProperty(obj, "lts372005"), false);
|
|
},
|
|
});
|
|
|
|
Deno.test({
|
|
name: "[member] format a members avatar url",
|
|
fn: async (t) => {
|
|
const bot = loadBot();
|
|
|
|
assertEquals(
|
|
bot.helpers.getAvatarURL(130136895395987456n, "8840", {
|
|
avatar: 4055337350987360625717955448021200177333n,
|
|
}),
|
|
"https://cdn.discordapp.com/avatars/130136895395987456/eae5905ad2d18d7c8deca20478b088b5.jpg?size=128",
|
|
);
|
|
},
|
|
});
|