From 0fb4e1f398ebd56bb7e18bcf1418cbfdcd2201a2 Mon Sep 17 00:00:00 2001 From: meister03 <69507874+meister03@users.noreply.github.com> Date: Tue, 23 Aug 2022 16:30:19 +0200 Subject: [PATCH] Update minimal template (#2314) * Outdate template * don't use `.env.example` * deno fmt Co-authored-by: meister03 Co-authored-by: LTS20050703 <87189679+lts20050703@users.noreply.github.com> Co-authored-by: LTS20050703 --- template/bigbot/src/bot/types/command.ts | 84 ++++++++++++------------ template/minimal/configs.ts | 1 - template/minimal/deps.ts | 4 +- template/minimal/mod.ts | 34 ++++++---- template/minimal/src/utils/helpers.ts | 8 +-- types/shared.ts | 10 +-- 6 files changed, 76 insertions(+), 65 deletions(-) diff --git a/template/bigbot/src/bot/types/command.ts b/template/bigbot/src/bot/types/command.ts index 8d498a2e8..6a15f5d90 100644 --- a/template/bigbot/src/bot/types/command.ts +++ b/template/bigbot/src/bot/types/command.ts @@ -190,41 +190,41 @@ export type ConvertArgumentDefinitionsToArgs< [P in keyof T]: T[P] extends StringOptionalArgumentDefinition // STRING ? { [_ in getName]?: T[P]["choices"] extends readonly { name: string; value: string }[] ? // @ts-ignore ts being dumb - T[P]["choices"][number]["value"] + T[P]["choices"][number]["value"] : string; } : T[P] extends StringArgumentDefinition ? { - [_ in getName]: T[P]["choices"] extends readonly { name: string; value: string }[] ? // @ts-ignore ts being dumb - T[P]["choices"][number]["value"] - : string; - } + [_ in getName]: T[P]["choices"] extends readonly { name: string; value: string }[] ? // @ts-ignore ts being dumb + T[P]["choices"][number]["value"] + : string; + } : // INTEGER T[P] extends IntegerOptionalArgumentDefinition ? { - [_ in getName]?: T[P]["choices"] extends readonly { name: string; value: number }[] ? // @ts-ignore ts being dumb - T[P]["choices"][number]["value"] - : number; - } + [_ in getName]?: T[P]["choices"] extends readonly { name: string; value: number }[] ? // @ts-ignore ts being dumb + T[P]["choices"][number]["value"] + : number; + } : T[P] extends IntegerArgumentDefinition ? { - [_ in getName]: T[P]["choices"] extends readonly { name: string; value: number }[] ? // @ts-ignore ts being dumb - T[P]["choices"][number]["value"] - : number; - } + [_ in getName]: T[P]["choices"] extends readonly { name: string; value: number }[] ? // @ts-ignore ts being dumb + 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; - }; - } + [_ in getName]?: { + user: User; + member: Member; + }; + } : T[P] extends UserArgumentDefinition ? { - [_ in getName]: { - user: User; - member: Member; - }; - } + [_ in getName]: { + user: User; + member: Member; + }; + } : // CHANNEL T[P] extends ChannelOptionalArgumentDefinition ? { [_ in getName]?: Channel } : T[P] extends ChannelArgumentDefinition ? { [_ in getName]: Channel } @@ -233,30 +233,30 @@ export type ConvertArgumentDefinitionsToArgs< : T[P] extends RoleArgumentDefinition ? { [_ in getName]: Role } : // MENTIONABLE T[P] extends MentionableOptionalArgumentDefinition ? { - [_ in getName]?: Role | { - user: User; - member: Member; - }; - } + [_ in getName]?: Role | { + user: User; + member: Member; + }; + } : T[P] extends MentionableArgumentDefinition ? { - [_ in getName]: Role | { - user: User; - member: Member; - }; - } + [_ in getName]: Role | { + user: User; + member: Member; + }; + } : // SUBCOMMAND T[P] extends SubcommandArgumentDefinition ? { - [_ in getName]?: T[P]["options"] extends readonly ArgumentDefinition[] ? // @ts-ignore ignore this for a bit - ConvertArgumentDefinitionsToArgs - : // deno-lint-ignore ban-types - {}; - } + [_ in getName]?: T[P]["options"] extends readonly ArgumentDefinition[] ? // @ts-ignore ignore this for a bit + ConvertArgumentDefinitionsToArgs + : // deno-lint-ignore ban-types + {}; + } : // SUBCOMMAND GROUP T[P] extends SubcommandGroupArgumentDefinition ? { - [_ in getName]?: ConvertArgumentDefinitionsToArgs< - T[P]["options"] - >; - } + [_ in getName]?: ConvertArgumentDefinitionsToArgs< + T[P]["options"] + >; + } : never; }[number] > diff --git a/template/minimal/configs.ts b/template/minimal/configs.ts index f08918bd9..3511ca823 100644 --- a/template/minimal/configs.ts +++ b/template/minimal/configs.ts @@ -1,6 +1,5 @@ import { dotEnvConfig } from "./deps.ts"; dotEnvConfig({ export: true }); - export const BOT_TOKEN = Deno.env.get("BOT_TOKEN") || ""; export const BOT_ID = BigInt(atob(BOT_TOKEN.split(".")[0])); diff --git a/template/minimal/deps.ts b/template/minimal/deps.ts index 593216329..c7559b2b2 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-rc31/mod.ts"; -export * from "https://deno.land/x/discordeno@13.0.0-rc31/plugins/mod.ts"; +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 { 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 d3ba5ee52..f71c7a987 100644 --- a/template/minimal/mod.ts +++ b/template/minimal/mod.ts @@ -1,4 +1,12 @@ -import { ActivityTypes, createBot, enableCachePlugin, enableCacheSweepers, fastFileLoader, startBot } from "./deps.ts"; +import { + ActivityTypes, + createBot, + enableCachePlugin, + enableCacheSweepers, + fastFileLoader, + GatewayIntents, + startBot, +} from "./deps.ts"; import { BOT_ID, BOT_TOKEN } from "./configs.ts"; import { logger } from "./src/utils/logger.ts"; import { events } from "./src/events/mod.ts"; @@ -19,22 +27,26 @@ export const bot = enableCachePlugin( createBot({ token: BOT_TOKEN, botId: BOT_ID, - intents: [], + intents: GatewayIntents.Guilds, events, }), ); +// @ts-nocheck: no-updated-depencdencies enableCacheSweepers(bot); -bot.gateway.presence = { - status: "online", - activities: [ - { - name: "Discordeno is Best Lib", - type: ActivityTypes.Game, - createdAt: Date.now(), - }, - ], +bot.gateway.manager.createShardOptions.makePresence = (shardId: number) => { + return { + shardId: shardId, + status: "online", + activities: [ + { + name: "Discordeno is Best Lib", + type: ActivityTypes.Game, + createdAt: Date.now(), + }, + ], + }; }; await startBot(bot); diff --git a/template/minimal/src/utils/helpers.ts b/template/minimal/src/utils/helpers.ts index 84719c48e..126a5fbb2 100644 --- a/template/minimal/src/utils/helpers.ts +++ b/template/minimal/src/utils/helpers.ts @@ -51,7 +51,7 @@ export async function updateCommands( if (globalCommands.length && (scope === "Global" || scope === undefined)) { log.info( - "Updating Global Commands, this takes up to 1 hour to take effect...", + "Updating Global Commands, changes should apply in short...", ); await bot.helpers.upsertApplicationCommands(globalCommands).catch( log.error, @@ -59,7 +59,7 @@ export async function updateCommands( } if (perGuildCommands.length && (scope === "Guild" || scope === undefined)) { - await bot.guilds.forEach(async (guild) => { + await bot.guilds.forEach(async (guild: Guild) => { await upsertApplicationCommands(bot, perGuildCommands, guild.id); }); } @@ -99,8 +99,8 @@ export async function getGuildFromId( } await getGuild(bot, guildId).then((guild) => { - bot.guilds.set(guildId, guild); - returnValue = guild; + if (guild) bot.guilds.set(guildId, guild); + if (guild) returnValue = guild; }); } diff --git a/types/shared.ts b/types/shared.ts index 7d4c20d92..af5b7c5fc 100644 --- a/types/shared.ts +++ b/types/shared.ts @@ -1388,7 +1388,7 @@ export type CamelCase = S extends `${infer P1}_${infer P2}${in : Lowercase; export type Camelize = { [K in keyof T as CamelCase]: T[K] extends Array ? U extends {} ? Array> - : T[K] + : T[K] : T[K] extends {} ? Camelize : never; }; @@ -1443,8 +1443,8 @@ export type AnythingBut = Exclude< * object identity type */ export type Id = T extends infer U ? { - [K in keyof U]: U[K]; -} + [K in keyof U]: U[K]; + } : never; export type KeysWithUndefined = { @@ -1468,8 +1468,8 @@ type OptionalizeAux = Id< */ export type Optionalize = T extends object ? T extends Array ? number extends T["length"] ? T[number] extends object ? Array> - : T - : Partial + : T + : Partial : OptionalizeAux : T;