From b9766c6cb688513fcc16711795bc0b5737bce8cf Mon Sep 17 00:00:00 2001 From: Awesome Stickz Date: Sat, 8 Oct 2022 03:11:11 +0530 Subject: [PATCH] Update all templates' dd version, readme, added example env/config (#2500) * Update bigbot template to v16, update readme, added .env.example for an example env * Update minimal template to dd v16, update readme * Update minimal template readme for consistency * Update beginner template to v16, update readme * Added config.json file, readme to nodejs template * Fix kwik db stuff in beginner template * deno fmt * Update template readme * Fix bigbot template raw event ignoring GUILD_CREATE instead of GUILD_LOADED_DD * deno fmt * fix deno fmt again * Use .env file instead of config.json in nodejs template * fix: kwik's version in beginner template * Apply suggestions from code review Co-authored-by: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> * Update template/README.md Co-authored-by: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> --- packages/embeds/mod.ts | 4 +- template/README.md | 2 +- template/beginner/README.md | 2 + template/beginner/configs.ts | 2 +- template/beginner/deps.ts | 2 +- template/beginner/src/database/mod.ts | 12 +- template/beginner/src/utils/updateCommands.ts | 6 +- template/bigbot/.env.example | 4 + template/bigbot/README.md | 2 + template/bigbot/package-lock.json | 84 ++++++++---- template/bigbot/package.json | 2 +- template/bigbot/src/bot/events/raw.ts | 6 +- .../src/bot/utils/slash/createCommand.ts | 124 +++++++++--------- .../src/bot/utils/slash/updateCommands.ts | 10 +- template/minimal/README.md | 6 + template/minimal/deps.ts | 4 +- template/minimal/mod.ts | 2 +- template/minimal/src/utils/helpers.ts | 32 ++--- template/nodejs/.env.example | 1 + template/nodejs/README.md | 13 ++ template/nodejs/index.js | 4 +- template/nodejs/package.json | 3 +- 22 files changed, 190 insertions(+), 137 deletions(-) create mode 100644 template/bigbot/.env.example create mode 100644 template/nodejs/.env.example create mode 100644 template/nodejs/README.md diff --git a/packages/embeds/mod.ts b/packages/embeds/mod.ts index 157bdf1f3..e46d5f89b 100644 --- a/packages/embeds/mod.ts +++ b/packages/embeds/mod.ts @@ -91,8 +91,8 @@ export class Embeds extends Array { this.getLastEmbed().color = color.toLowerCase() === `random` // Random color ? Math.floor(Math.random() * (0xffffff + 1)) - // Convert the hex to a acceptable color for discord - : parseInt(color.replace("#", ""), 16); + : // Convert the hex to a acceptable color for discord + parseInt(color.replace("#", ""), 16); return this; } diff --git a/template/README.md b/template/README.md index a1ef72598..db4460cca 100644 --- a/template/README.md +++ b/template/README.md @@ -3,7 +3,7 @@ ![Log Image](https://i.imgur.com/09skKfz.png) This repo is meant as a template which you can use to create a Discord bot very easily using the -[Discordeno library (`v13`)](https://github.com/discordeno/discordeno). +[Discordeno library](https://github.com/discordeno/discordeno). [Website/Guide](https://discordeno.mod.land/) diff --git a/template/beginner/README.md b/template/beginner/README.md index 3530449c8..1b47675a8 100644 --- a/template/beginner/README.md +++ b/template/beginner/README.md @@ -2,6 +2,8 @@ This template is designed for the beginner developer to start coding discord bots. +Make sure to install the latest version when you use it. + ## Setup - [Click here](https://github.com/discordeno/template/generate) to make your own copy. diff --git a/template/beginner/configs.ts b/template/beginner/configs.ts index b9ce9098d..cb1ac6091 100644 --- a/template/beginner/configs.ts +++ b/template/beginner/configs.ts @@ -1,7 +1,7 @@ import { dotEnvConfig } from "./deps.ts"; // Get the .env file that the user should have created, and get the token -const env = dotEnvConfig({ export: true, path: "./.env.example" }); +const env = dotEnvConfig({ export: true, path: "./.env" }); const token = env.BOT_TOKEN || ""; export interface Config { diff --git a/template/beginner/deps.ts b/template/beginner/deps.ts index dae8a0e14..bca3819cd 100644 --- a/template/beginner/deps.ts +++ b/template/beginner/deps.ts @@ -6,4 +6,4 @@ export * from "https://deno.land/std@0.117.0/fmt/colors.ts"; // Get data from .env files export { config as dotEnvConfig } from "https://deno.land/x/dotenv@v3.1.0/mod.ts"; // Database, thx Tri! -export * from "https://deno.land/x/kwik@1.3.1/mod.ts"; +export { decode as KwikDecode, encode as KwikEncode, Kwik } from "https://deno.land/x/kwik@v1.3.1/mod.ts"; diff --git a/template/beginner/src/database/mod.ts b/template/beginner/src/database/mod.ts index 0948a5a0e..1d452806b 100644 --- a/template/beginner/src/database/mod.ts +++ b/template/beginner/src/database/mod.ts @@ -1,4 +1,4 @@ -import { decode, encode, Kwik } from "../../deps.ts"; +import { Kwik, KwikDecode, KwikEncode } from "../../deps.ts"; import { logger } from "../utils/logger.ts"; const log = logger({ name: "DB Manager" }); @@ -12,19 +12,17 @@ kwik.msgpackExtensionCodec.register({ type: 0, encode: (object: unknown): Uint8Array | null => { if (typeof object === "bigint") { - if ( - object <= Number.MAX_SAFE_INTEGER && object >= Number.MIN_SAFE_INTEGER - ) { - return encode(parseInt(object.toString(), 10), {}); + if (object <= Number.MAX_SAFE_INTEGER && object >= Number.MIN_SAFE_INTEGER) { + return KwikEncode(parseInt(object.toString(), 10), {}); } else { - return encode(object.toString(), {}); + return KwikEncode(object.toString(), {}); } } else { return null; } }, decode: (data: Uint8Array) => { - return BigInt(decode(data, {}) as string); + return BigInt(KwikDecode(data, {}) as string); }, }); diff --git a/template/beginner/src/utils/updateCommands.ts b/template/beginner/src/utils/updateCommands.ts index 161441c68..7b206e271 100644 --- a/template/beginner/src/utils/updateCommands.ts +++ b/template/beginner/src/utils/updateCommands.ts @@ -2,18 +2,18 @@ import { Bot } from "../../bot.ts"; import { configs } from "../../configs.ts"; export async function updateApplicationCommands() { - await Bot.helpers.upsertApplicationCommands( + await Bot.helpers.upsertGlobalApplicationCommands( Bot.commands // ONLY GLOBAL COMMANDS .filter((command) => !command.devOnly) .array(), ); - await Bot.helpers.upsertApplicationCommands( + await Bot.helpers.upsertGuildApplicationCommands( + configs.devGuildId, Bot.commands // ONLY GLOBAL COMMANDS .filter((command) => !!command.devOnly) .array(), - configs.devGuildId, ); } diff --git a/template/bigbot/.env.example b/template/bigbot/.env.example new file mode 100644 index 000000000..4aeeec32a --- /dev/null +++ b/template/bigbot/.env.example @@ -0,0 +1,4 @@ +# For Prisma use. Remember to remove the `[` and `]` +DATABASE_URL=postgres://[username]:[password]@[host]:[port]/[db] + +# For other configs, update src/configs.ts \ No newline at end of file diff --git a/template/bigbot/README.md b/template/bigbot/README.md index 548dbe041..6912fed8c 100644 --- a/template/bigbot/README.md +++ b/template/bigbot/README.md @@ -6,6 +6,8 @@ This template is designed for bots that aim or are already in millions of Discor currently Deno & Bun are not ready to run something at such a scale. The general idea of this template can be modified for any other runtime if this improves in the future. +Make sure to install the latest version when you use it. + ## Setup 1. Run a find all for `// SETUP-DD-TEMP:` and follow all instructions and delete the comments as you finish them. diff --git a/template/bigbot/package-lock.json b/template/bigbot/package-lock.json index 01ab9e8aa..7d1b5a400 100644 --- a/template/bigbot/package-lock.json +++ b/template/bigbot/package-lock.json @@ -11,7 +11,7 @@ "@influxdata/influxdb-client": "^1.29.0", "@prisma/client": "^3.15.2", "colorette": "^2.0.19", - "discordeno": "^13.0.0-rc51", + "discordeno": "^16.0.1", "express": "^4.18.1", "fastify": "^4.5.3", "nanoid": "^4.0.0", @@ -41,9 +41,9 @@ } }, "node_modules/@deno/shim-deno": { - "version": "0.3.1", - "resolved": "https://registry.npmjs.org/@deno/shim-deno/-/shim-deno-0.3.1.tgz", - "integrity": "sha512-Ph5l6JT+8cvxbJWTZqqAJzlfTL1cBPHZOZ6dm0s32yARR4t+/xTujab5hDJTfXqoSe/y1VCp0PJqQyQPHmFmoA==", + "version": "0.9.0", + "resolved": "https://registry.npmjs.org/@deno/shim-deno/-/shim-deno-0.9.0.tgz", + "integrity": "sha512-iP+qdI4Oy/Mw9yv40TqdjNKL+stpKDo8drki2cKisTXgZf+GoIdMhIuODxSypRyv6wxIuHNx7ZiKE3Sl3kAHuw==", "dependencies": { "@deno/shim-deno-test": "^0.3.2", "which": "^2.0.2" @@ -461,6 +461,17 @@ "node": ">=8" } }, + "node_modules/busboy": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/busboy/-/busboy-1.6.0.tgz", + "integrity": "sha512-8SFQbg/0hQ9xy3UNTB0YEnsNBbWfhf7RtnzpL7TkBiTBRfrQ9Fxcnz7VJsleJpyp6rVLvXiuORqjlHi5q+PYuA==", + "dependencies": { + "streamsearch": "^1.1.0" + }, + "engines": { + "node": ">=10.16.0" + } + }, "node_modules/bytes": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", @@ -590,13 +601,13 @@ } }, "node_modules/discordeno": { - "version": "13.0.0-rc51", - "resolved": "https://registry.npmjs.org/discordeno/-/discordeno-13.0.0-rc51.tgz", - "integrity": "sha512-AxJbZdOsahnxbNS9PPgOXg98OlBl7S5PcFSqvPC+ej1g48j8aHyFNbMF9I4HH1m1NN5dNmNtsWtLgAbwXNMdNA==", + "version": "16.0.1", + "resolved": "https://registry.npmjs.org/discordeno/-/discordeno-16.0.1.tgz", + "integrity": "sha512-crfphZ4YIZ0HmwbjPlCQ99tUy9kCdO+p/f0ikdzndK5gzRV1PJXuLVz1yXF13Bl1rxWDGBRMckdqf6Z2i5K8XQ==", "dependencies": { - "@deno/shim-deno": "~0.3.0", + "@deno/shim-deno": "~0.9.0", "@deno/shim-timers": "~0.1.0", - "undici": "^4.12.1", + "undici": "^5.8.0", "ws": "^8.4.0" } }, @@ -1571,6 +1582,14 @@ "node": ">= 0.8" } }, + "node_modules/streamsearch": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-1.1.0.tgz", + "integrity": "sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg==", + "engines": { + "node": ">=10.0.0" + } + }, "node_modules/supports-color": { "version": "5.5.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", @@ -1709,9 +1728,12 @@ "dev": true }, "node_modules/undici": { - "version": "4.16.0", - "resolved": "https://registry.npmjs.org/undici/-/undici-4.16.0.tgz", - "integrity": "sha512-tkZSECUYi+/T1i4u+4+lwZmQgLXd4BLGlrc7KZPcLIW7Jpq99+Xpc30ONv7nS6F5UNOxp/HBZSSL9MafUrvJbw==", + "version": "5.11.0", + "resolved": "https://registry.npmjs.org/undici/-/undici-5.11.0.tgz", + "integrity": "sha512-oWjWJHzFet0Ow4YZBkyiJwiK5vWqEYoH7BINzJAJOLedZ++JpAlCbUktW2GQ2DS2FpKmxD/JMtWUUWl1BtghGw==", + "dependencies": { + "busboy": "^1.6.0" + }, "engines": { "node": ">=12.18" } @@ -1816,9 +1838,9 @@ } }, "@deno/shim-deno": { - "version": "0.3.1", - "resolved": "https://registry.npmjs.org/@deno/shim-deno/-/shim-deno-0.3.1.tgz", - "integrity": "sha512-Ph5l6JT+8cvxbJWTZqqAJzlfTL1cBPHZOZ6dm0s32yARR4t+/xTujab5hDJTfXqoSe/y1VCp0PJqQyQPHmFmoA==", + "version": "0.9.0", + "resolved": "https://registry.npmjs.org/@deno/shim-deno/-/shim-deno-0.9.0.tgz", + "integrity": "sha512-iP+qdI4Oy/Mw9yv40TqdjNKL+stpKDo8drki2cKisTXgZf+GoIdMhIuODxSypRyv6wxIuHNx7ZiKE3Sl3kAHuw==", "requires": { "@deno/shim-deno-test": "^0.3.2", "which": "^2.0.2" @@ -2171,6 +2193,14 @@ "fill-range": "^7.0.1" } }, + "busboy": { + "version": "1.6.0", + "resolved": "https://registry.npmjs.org/busboy/-/busboy-1.6.0.tgz", + "integrity": "sha512-8SFQbg/0hQ9xy3UNTB0YEnsNBbWfhf7RtnzpL7TkBiTBRfrQ9Fxcnz7VJsleJpyp6rVLvXiuORqjlHi5q+PYuA==", + "requires": { + "streamsearch": "^1.1.0" + } + }, "bytes": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/bytes/-/bytes-3.1.2.tgz", @@ -2264,13 +2294,13 @@ "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==" }, "discordeno": { - "version": "13.0.0-rc51", - "resolved": "https://registry.npmjs.org/discordeno/-/discordeno-13.0.0-rc51.tgz", - "integrity": "sha512-AxJbZdOsahnxbNS9PPgOXg98OlBl7S5PcFSqvPC+ej1g48j8aHyFNbMF9I4HH1m1NN5dNmNtsWtLgAbwXNMdNA==", + "version": "16.0.1", + "resolved": "https://registry.npmjs.org/discordeno/-/discordeno-16.0.1.tgz", + "integrity": "sha512-crfphZ4YIZ0HmwbjPlCQ99tUy9kCdO+p/f0ikdzndK5gzRV1PJXuLVz1yXF13Bl1rxWDGBRMckdqf6Z2i5K8XQ==", "requires": { - "@deno/shim-deno": "~0.3.0", + "@deno/shim-deno": "~0.9.0", "@deno/shim-timers": "~0.1.0", - "undici": "^4.12.1", + "undici": "^5.8.0", "ws": "^8.4.0" } }, @@ -3003,6 +3033,11 @@ "resolved": "https://registry.npmjs.org/statuses/-/statuses-2.0.1.tgz", "integrity": "sha512-RwNA9Z/7PrK06rYLIzFMlaF+l73iwpzsqRIFgbMLbTcLD6cOao82TaWefPXQvB2fOC4AjuYSEndS7N/mTCbkdQ==" }, + "streamsearch": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/streamsearch/-/streamsearch-1.1.0.tgz", + "integrity": "sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg==" + }, "supports-color": { "version": "5.5.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", @@ -3094,9 +3129,12 @@ "dev": true }, "undici": { - "version": "4.16.0", - "resolved": "https://registry.npmjs.org/undici/-/undici-4.16.0.tgz", - "integrity": "sha512-tkZSECUYi+/T1i4u+4+lwZmQgLXd4BLGlrc7KZPcLIW7Jpq99+Xpc30ONv7nS6F5UNOxp/HBZSSL9MafUrvJbw==" + "version": "5.11.0", + "resolved": "https://registry.npmjs.org/undici/-/undici-5.11.0.tgz", + "integrity": "sha512-oWjWJHzFet0Ow4YZBkyiJwiK5vWqEYoH7BINzJAJOLedZ++JpAlCbUktW2GQ2DS2FpKmxD/JMtWUUWl1BtghGw==", + "requires": { + "busboy": "^1.6.0" + } }, "unpipe": { "version": "1.0.0", diff --git a/template/bigbot/package.json b/template/bigbot/package.json index b347c3f86..471057525 100644 --- a/template/bigbot/package.json +++ b/template/bigbot/package.json @@ -20,7 +20,7 @@ "@influxdata/influxdb-client": "^1.29.0", "@prisma/client": "^3.15.2", "colorette": "^2.0.19", - "discordeno": "^13.0.0-rc51", + "discordeno": "^16.0.1", "express": "^4.18.1", "fastify": "^4.5.3", "nanoid": "^4.0.0", diff --git a/template/bigbot/src/bot/events/raw.ts b/template/bigbot/src/bot/events/raw.ts index c1c08971f..4c66d69aa 100644 --- a/template/bigbot/src/bot/events/raw.ts +++ b/template/bigbot/src/bot/events/raw.ts @@ -18,12 +18,12 @@ export function setRawEvent() { (data.t && ["GUILD_UPDATE", "GUILD_CREATE"].includes(data.t) // deno-lint-ignore no-explicit-any ? (data.d as any)?.id - // deno-lint-ignore no-explicit-any - : (data.d as any)?.guild_id) ?? "", + : // deno-lint-ignore no-explicit-any + (data.d as any)?.guild_id) ?? "", ); // The GUILD_CREATE event came from a shard loaded event so ignore it - if (["READY", "GUILD_CREATE", null].includes(data.t)) return; + if (["READY", "GUILD_LOADED_DD", null].includes(data.t)) return; // console.log({ id, v: await usesLatestCommandVersion(id) }) diff --git a/template/bigbot/src/bot/utils/slash/createCommand.ts b/template/bigbot/src/bot/utils/slash/createCommand.ts index 5f5a12cd0..6adb2efa9 100644 --- a/template/bigbot/src/bot/utils/slash/createCommand.ts +++ b/template/bigbot/src/bot/utils/slash/createCommand.ts @@ -156,78 +156,78 @@ export type ConvertArgumentDefinitionsToArgs // STRING - ? { + ? { + // @ts-ignore TODO: fix this some day + [_ in getName]?: T[P]["choices"] extends readonly { name: string; value: string }[] // @ts-ignore + ? T[P]["choices"][number]["value"] + : string; + } + : T[P] extends StringArgumentDefinition ? { // @ts-ignore TODO: fix this some day - [_ in getName]?: T[P]["choices"] extends readonly { name: string; value: string }[] // @ts-ignore - ? T[P]["choices"][number]["value"] + [_ in getName]: T[P]["choices"] extends readonly { name: string; value: string }[] // @ts-ignore + ? T[P]["choices"][number]["value"] : string; } - : T[P] extends StringArgumentDefinition ? { - // @ts-ignore TODO: fix this some day - [_ in getName]: T[P]["choices"] extends readonly { name: string; value: string }[] // @ts-ignore - ? T[P]["choices"][number]["value"] - : string; - } - // INTEGER - : T[P] extends IntegerOptionalArgumentDefinition ? { - [_ in getName]?: T[P]["choices"] extends readonly { name: string; value: number }[] // @ts-ignore - ? T[P]["choices"][number]["value"] - : number; - } + : // INTEGER + T[P] extends IntegerOptionalArgumentDefinition ? { + [_ in getName]?: T[P]["choices"] extends readonly { name: string; value: number }[] // @ts-ignore + ? T[P]["choices"][number]["value"] + : number; + } : T[P] extends IntegerArgumentDefinition ? { - [_ in getName]: T[P]["choices"] extends readonly { name: string; value: number }[] // @ts-ignore - ? T[P]["choices"][number]["value"] - : number; - } - // BOOLEAN - : T[P] extends BooleanOptionalArgumentDefinition ? { [_ in getName]?: boolean } + [_ in getName]: T[P]["choices"] extends readonly { name: string; value: number }[] // @ts-ignore + ? T[P]["choices"][number]["value"] + : number; + } + : // BOOLEAN + T[P] extends BooleanOptionalArgumentDefinition ? { [_ in getName]?: boolean } : T[P] extends BooleanArgumentDefinition ? { [_ in getName]: boolean } - // USER - : T[P] extends UserOptionalArgumentDefinition ? { - [_ in getName]?: { - user: User; - member: Member; - }; - } + : // USER + T[P] extends UserOptionalArgumentDefinition ? { + [_ in getName]?: { + user: User; + member: Member; + }; + } : T[P] extends UserArgumentDefinition ? { - [_ in getName]: { + [_ in getName]: { + user: User; + member: Member; + }; + } + : // CHANNEL + T[P] extends ChannelOptionalArgumentDefinition ? { [_ in getName]?: Channel } + : T[P] extends ChannelArgumentDefinition ? { [_ in getName]: Channel } + : // ROLE + T[P] extends RoleOptionalArgumentDefinition ? { [_ in getName]?: Role } + : T[P] extends RoleArgumentDefinition ? { [_ in getName]: Role } + : // MENTIONABLE + T[P] extends MentionableOptionalArgumentDefinition ? { + [_ in getName]?: + | Role + | { user: User; member: Member; }; - } - // CHANNEL - : T[P] extends ChannelOptionalArgumentDefinition ? { [_ in getName]?: Channel } - : T[P] extends ChannelArgumentDefinition ? { [_ in getName]: Channel } - // ROLE - : T[P] extends RoleOptionalArgumentDefinition ? { [_ in getName]?: Role } - : T[P] extends RoleArgumentDefinition ? { [_ in getName]: Role } - // MENTIONABLE - : T[P] extends MentionableOptionalArgumentDefinition ? { - [_ in getName]?: - | Role - | { - user: User; - member: Member; - }; - } + } : T[P] extends MentionableArgumentDefinition ? { - [_ in getName]: - | Role - | { - user: User; - member: Member; - }; - } - // SUBCOMMAND - : T[P] extends SubcommandArgumentDefinition ? { - [_ in getName]?: T[P]["options"] extends readonly ArgumentDefinition[] // @ts-ignore somehow this check does not work - ? ConvertArgumentDefinitionsToArgs - : {}; - } - // SUBCOMMANDGROUP - : T[P] extends SubcommandGroupArgumentDefinition ? { - [_ in getName]?: ConvertArgumentDefinitionsToArgs; - } + [_ in getName]: + | Role + | { + user: User; + member: Member; + }; + } + : // SUBCOMMAND + T[P] extends SubcommandArgumentDefinition ? { + [_ in getName]?: T[P]["options"] extends readonly ArgumentDefinition[] // @ts-ignore somehow this check does not work + ? ConvertArgumentDefinitionsToArgs + : {}; + } + : // SUBCOMMANDGROUP + T[P] extends SubcommandGroupArgumentDefinition ? { + [_ in getName]?: ConvertArgumentDefinitionsToArgs; + } : never; }[number] > diff --git a/template/bigbot/src/bot/utils/slash/updateCommands.ts b/template/bigbot/src/bot/utils/slash/updateCommands.ts index c3422bb7d..9e59c3976 100644 --- a/template/bigbot/src/bot/utils/slash/updateCommands.ts +++ b/template/bigbot/src/bot/utils/slash/updateCommands.ts @@ -13,8 +13,9 @@ export async function updateDevCommands(bot: Bot) { if (!cmds.length) return; - // DEV RELATED COMMANDS - await bot.helpers.upsertApplicationCommands( + // DEV RELATED COMMANDS, USE upsertGlobalApplicationCommands TO UPDATE GLOBALLY + await bot.helpers.upsertGuildApplicationCommands( + bot.transformers.snowflake(DEV_SERVER_ID), cmds.map(([name, command]) => { const translatedName = translate(DEV_SERVER_ID, command.name); const translatedDescription = command.description ? translate(DEV_SERVER_ID, command.description) : ""; @@ -34,7 +35,6 @@ export async function updateDevCommands(bot: Bot) { : undefined, }; }), - bot.transformers.snowflake(DEV_SERVER_ID), ); } @@ -74,7 +74,8 @@ export async function updateGuildCommands(bot: Bot, guildId: bigint) { await updateCommandVersion(guildId); // GUILD RELATED COMMANDS - await bot.helpers.upsertApplicationCommands( + await bot.helpers.upsertGuildApplicationCommands( + guildId, Object.entries(COMMANDS) // ONLY GUILD COMMANDS .filter(([_name, command]) => !command.global && !command.dev) @@ -98,7 +99,6 @@ export async function updateGuildCommands(bot: Bot, guildId: bigint) { options: command.options ? createOptions(guildId, command.options, command.name) : undefined, }; }), - guildId, ); } diff --git a/template/minimal/README.md b/template/minimal/README.md index d06f807d1..fbbd7b058 100644 --- a/template/minimal/README.md +++ b/template/minimal/README.md @@ -2,6 +2,12 @@ Just the minimum to get a working bot using interactions. +Make sure to install the latest version when you use it. + ## Setup Just rename `.env.example` to `.env` and fill it with your bot token. + +## Run Bot + +- deno run -A mod.ts diff --git a/template/minimal/deps.ts b/template/minimal/deps.ts index c7559b2b2..47848d736 100644 --- a/template/minimal/deps.ts +++ b/template/minimal/deps.ts @@ -1,4 +1,4 @@ -export * from "https://deno.land/x/discordeno@13.0.0-rc45/mod.ts"; -export * from "https://deno.land/x/discordeno@13.0.0-rc45/plugins/mod.ts"; +export * from "https://deno.land/x/discordeno@16.0.1/mod.ts"; +export * from "https://deno.land/x/discordeno@16.0.1/plugins/mod.ts"; export { config as dotEnvConfig } from "https://deno.land/x/dotenv@v3.1.0/mod.ts"; export * from "https://deno.land/std@0.117.0/fmt/colors.ts"; diff --git a/template/minimal/mod.ts b/template/minimal/mod.ts index f71c7a987..ee76c7390 100644 --- a/template/minimal/mod.ts +++ b/template/minimal/mod.ts @@ -41,7 +41,7 @@ bot.gateway.manager.createShardOptions.makePresence = (shardId: number) => { status: "online", activities: [ { - name: "Discordeno is Best Lib", + name: "Discordeno is the Best Lib", type: ActivityTypes.Game, createdAt: Date.now(), }, diff --git a/template/minimal/src/utils/helpers.ts b/template/minimal/src/utils/helpers.ts index 126a5fbb2..dc519efb7 100644 --- a/template/minimal/src/utils/helpers.ts +++ b/template/minimal/src/utils/helpers.ts @@ -6,7 +6,7 @@ import { Guild, hasProperty, MakeRequired, - upsertApplicationCommands, + upsertGuildApplicationCommands, } from "../../deps.ts"; import { logger } from "./logger.ts"; import { commands } from "../commands/mod.ts"; @@ -15,10 +15,7 @@ import { subCommand, subCommandGroup } from "../commands/mod.ts"; const log = logger({ name: "Helpers" }); /** This function will update all commands, or the defined scope */ -export async function updateCommands( - bot: BotWithCache, - scope?: "Guild" | "Global", -) { +export async function updateCommands(bot: BotWithCache, scope?: "Guild" | "Global") { const globalCommands: MakeRequired[] = []; const perGuildCommands: MakeRequired[] = []; @@ -50,17 +47,13 @@ export async function updateCommands( } if (globalCommands.length && (scope === "Global" || scope === undefined)) { - log.info( - "Updating Global Commands, changes should apply in short...", - ); - await bot.helpers.upsertApplicationCommands(globalCommands).catch( - log.error, - ); + log.info("Updating Global Commands, changes should apply in short..."); + await bot.helpers.upsertGlobalApplicationCommands(globalCommands).catch(log.error); } if (perGuildCommands.length && (scope === "Guild" || scope === undefined)) { await bot.guilds.forEach(async (guild: Guild) => { - await upsertApplicationCommands(bot, perGuildCommands, guild.id); + await upsertGuildApplicationCommands(bot, guild.id, perGuildCommands); }); } } @@ -83,14 +76,11 @@ export async function updateGuildCommands(bot: Bot, guild: Guild) { } if (perGuildCommands.length) { - await upsertApplicationCommands(bot, perGuildCommands, guild.id); + await upsertGuildApplicationCommands(bot, guild.id, perGuildCommands); } } -export async function getGuildFromId( - bot: BotWithCache, - guildId: bigint, -): Promise { +export async function getGuildFromId(bot: BotWithCache, guildId: bigint): Promise { let returnValue: Guild = {} as Guild; if (guildId !== 0n) { @@ -129,14 +119,10 @@ export function humanizeMilliseconds(milliseconds: number) { return `${dayString}${hourString}${minuteString}${secondString}`; } -export function isSubCommand( - data: subCommand | subCommandGroup, -): data is subCommand { +export function isSubCommand(data: subCommand | subCommandGroup): data is subCommand { return !hasProperty(data, "subCommands"); } -export function isSubCommandGroup( - data: subCommand | subCommandGroup, -): data is subCommandGroup { +export function isSubCommandGroup(data: subCommand | subCommandGroup): data is subCommandGroup { return hasProperty(data, "subCommands"); } diff --git a/template/nodejs/.env.example b/template/nodejs/.env.example new file mode 100644 index 000000000..f74c6612b --- /dev/null +++ b/template/nodejs/.env.example @@ -0,0 +1 @@ +TOKEN= \ No newline at end of file diff --git a/template/nodejs/README.md b/template/nodejs/README.md new file mode 100644 index 000000000..90839fca1 --- /dev/null +++ b/template/nodejs/README.md @@ -0,0 +1,13 @@ +# Nodejs Bot Template + +This template is a minimal template that uses [discordeno.js](https://www.npmjs.com/package/discordeno.js), a wrapper +around discordeno, which brings up a djs-like interface but also includes the core Features (Cross Ratelimit, Zero +Downtime Restart, Resharding...) + +## Setup + +Rename `.env.example` to `.env` and fill your bot token there. + +## Run Bot + +- node index.js diff --git a/template/nodejs/index.js b/template/nodejs/index.js index 247e5c114..de3ce073c 100644 --- a/template/nodejs/index.js +++ b/template/nodejs/index.js @@ -1,3 +1,5 @@ +require('dotenv').config(); + const Discord = require("discordeno.js"); // Ideally you should switch this to .env but for a template a config json is enough @@ -10,7 +12,7 @@ const events = new EventManager({}); const baseBot = Discord.createBot({ events: events.load({}), intents: Discord.Intents.Guilds | Discord.Intents.GuildMessages | Discord.Intents.MessageContent, - token: config.token, + token: process.env.TOKEN, }); const client = Discord.enableCachePlugin(baseBot, {}); diff --git a/template/nodejs/package.json b/template/nodejs/package.json index b4af40020..2a4e41316 100644 --- a/template/nodejs/package.json +++ b/template/nodejs/package.json @@ -10,6 +10,7 @@ "author": "", "license": "ISC", "dependencies": { - "discordeno.js": "github:meister03/discordeno.js" + "discordeno.js": "github:meister03/discordeno.js", + "dotenv": "^16.0.3" } }