From 76f2c7b0ddb9274fbab22100f1d9f205eeb6896b Mon Sep 17 00:00:00 2001 From: Nikola Hristov Date: Sun, 17 Dec 2023 07:58:18 +0200 Subject: [PATCH] squash! --- Source/Configuration/PM2.ts | 4 +- Source/Option/DISCORD.ts | 4 +- Target/Application/Discord.js | 11 +++- Target/Configuration/PM2.d.ts | 16 ++--- Target/Configuration/PM2.js | 13 +++- Target/Index.js | 3 +- Target/Library/Environment.d.ts | 102 +++++++++++++++++++++++--------- Target/Library/Environment.js | 11 +++- Target/Option/DISCORD.d.ts | 16 ++--- Target/Option/DISCORD.js | 71 +++++++++++++++++++++- 10 files changed, 200 insertions(+), 51 deletions(-) diff --git a/Source/Configuration/PM2.ts b/Source/Configuration/PM2.ts index 310a747..6131120 100644 --- a/Source/Configuration/PM2.ts +++ b/Source/Configuration/PM2.ts @@ -6,7 +6,7 @@ export type Ecosystem = { apps: Apps; }; -export default { +export default ({ apps: [ { name: "discord", @@ -16,4 +16,4 @@ export default { force: true, }, ], -} satisfies Ecosystem; +} satisfies Ecosystem); diff --git a/Source/Option/DISCORD.ts b/Source/Option/DISCORD.ts index 29bb432..ce466e3 100644 --- a/Source/Option/DISCORD.ts +++ b/Source/Option/DISCORD.ts @@ -45,7 +45,7 @@ export const Clients: Client[] = [ if (!DISCORD_PUBLIC_KEY) { throw new Error( - "The DISCORD_TOKEN environment variable is required." + "The DISCORD_TOKEN environment variable is required.", ); } @@ -72,7 +72,7 @@ export const Clients: Client[] = [ async function registerGlobalCommands() { await registerCommands( - `https://discord.com/api/v10/applications/${applicationId}/commands` + `https://discord.com/api/v10/applications/${applicationId}/commands`, ); } diff --git a/Target/Application/Discord.js b/Target/Application/Discord.js index c83a6c5..50f08a3 100644 --- a/Target/Application/Discord.js +++ b/Target/Application/Discord.js @@ -1 +1,10 @@ -for(const{token:n,options:t,events:e}of(await import("../Option/DISCORD.js")).default){if(!t)continue;const o=new(await import("discord.js")).Client(t);for(const[i,a]of e??[])o.on(i,a);o.login(n)}var f={};export{f as default}; +for (const { token: n, options: t, events: e } of ( + await import("../Option/DISCORD.js") +).default) { + if (!t) continue; + const o = new (await import("discord.js")).Client(t); + for (const [i, a] of e ?? []) o.on(i, a); + o.login(n); +} +var f = {}; +export { f as default }; diff --git a/Target/Configuration/PM2.d.ts b/Target/Configuration/PM2.d.ts index b776a87..c520467 100644 --- a/Target/Configuration/PM2.d.ts +++ b/Target/Configuration/PM2.d.ts @@ -1,15 +1,15 @@ import type { StartOptions } from "pm2"; export type Apps = StartOptions[]; export type Ecosystem = { - apps: Apps; + apps: Apps; }; declare const _default: { - apps: { - name: string; - script: string; - watch: true; - autorestart: true; - force: true; - }[]; + apps: { + name: string; + script: string; + watch: true; + autorestart: true; + force: true; + }[]; }; export default _default; diff --git a/Target/Configuration/PM2.js b/Target/Configuration/PM2.js index a85592b..7a84d7c 100644 --- a/Target/Configuration/PM2.js +++ b/Target/Configuration/PM2.js @@ -1 +1,12 @@ -var t={apps:[{name:"discord",script:"./Target/apps/discord.js",watch:!0,autorestart:!0,force:!0}]};export{t as default}; +var t = { + apps: [ + { + name: "discord", + script: "./Target/apps/discord.js", + watch: !0, + autorestart: !0, + force: !0, + }, + ], +}; +export { t as default }; diff --git a/Target/Index.js b/Target/Index.js index f5c7538..9e25d5a 100644 --- a/Target/Index.js +++ b/Target/Index.js @@ -1 +1,2 @@ -import{default as a}from"./Application/Discord.js";export{a as Discord}; +import { default as a } from "./Application/Discord.js"; +export { a as Discord }; diff --git a/Target/Library/Environment.d.ts b/Target/Library/Environment.d.ts index d703780..3ff5b65 100644 --- a/Target/Library/Environment.d.ts +++ b/Target/Library/Environment.d.ts @@ -1,28 +1,76 @@ -export declare const object: (shape: T, params?: import("zod").RawCreateParams) => import("zod").ZodObject, { [k in keyof import("zod").baseObjectOutputType]: undefined extends import("zod").baseObjectOutputType[k] ? never : k; }[keyof T]>]: import("zod").objectUtil.addQuestionMarks, { [k_2 in keyof import("zod").baseObjectOutputType]: undefined extends import("zod").baseObjectOutputType[k_2] ? never : k_2; }[keyof T]>[k_1]; }, { [k_2 in keyof import("zod").baseObjectInputType]: import("zod").baseObjectInputType[k_2]; }>, string: (params?: ({ - errorMap?: import("zod").ZodErrorMap | undefined; - invalid_type_error?: string | undefined; - required_error?: string | undefined; - description?: string | undefined; -} & { - coerce?: true | undefined; -}) | undefined) => import("zod").ZodString; -declare const _default: import("zod").ZodObject<{ - DISCORD_APPLICATION_ID: import("zod").ZodDefault>; - DISCORD_CLIENT_ID: import("zod").ZodDefault>; - DISCORD_CLIENT_SECRET: import("zod").ZodDefault>; - DISCORD_PUBLIC_KEY: import("zod").ZodDefault>; - DISCORD_TOKENS: import("zod").ZodDefault>; -}, "strip", import("zod").ZodTypeAny, { - DISCORD_APPLICATION_ID: string; - DISCORD_CLIENT_ID: string; - DISCORD_CLIENT_SECRET: string; - DISCORD_PUBLIC_KEY: string; - DISCORD_TOKENS: string; -}, { - DISCORD_APPLICATION_ID?: string | undefined; - DISCORD_CLIENT_ID?: string | undefined; - DISCORD_CLIENT_SECRET?: string | undefined; - DISCORD_PUBLIC_KEY?: string | undefined; - DISCORD_TOKENS?: string | undefined; -}>; +export declare const object: ( + shape: T, + params?: import("zod").RawCreateParams, + ) => import("zod").ZodObject< + T, + "strip", + import("zod").ZodTypeAny, + { + [k_1 in keyof import("zod").objectUtil.addQuestionMarks< + import("zod").baseObjectOutputType, + { + [k in keyof import("zod").baseObjectOutputType]: undefined extends import("zod").baseObjectOutputType[k] + ? never + : k; + }[keyof T] + >]: import("zod").objectUtil.addQuestionMarks< + import("zod").baseObjectOutputType, + { + [k_2 in keyof import("zod").baseObjectOutputType]: undefined extends import("zod").baseObjectOutputType[k_2] + ? never + : k_2; + }[keyof T] + >[k_1]; + }, + { + [k_2 in keyof import("zod").baseObjectInputType]: import("zod").baseObjectInputType[k_2]; + } + >, + string: ( + params?: + | ({ + errorMap?: import("zod").ZodErrorMap | undefined; + invalid_type_error?: string | undefined; + required_error?: string | undefined; + description?: string | undefined; + } & { + coerce?: true | undefined; + }) + | undefined, + ) => import("zod").ZodString; +declare const _default: import("zod").ZodObject< + { + DISCORD_APPLICATION_ID: import("zod").ZodDefault< + import("zod").ZodOptional + >; + DISCORD_CLIENT_ID: import("zod").ZodDefault< + import("zod").ZodOptional + >; + DISCORD_CLIENT_SECRET: import("zod").ZodDefault< + import("zod").ZodOptional + >; + DISCORD_PUBLIC_KEY: import("zod").ZodDefault< + import("zod").ZodOptional + >; + DISCORD_TOKENS: import("zod").ZodDefault< + import("zod").ZodOptional + >; + }, + "strip", + import("zod").ZodTypeAny, + { + DISCORD_APPLICATION_ID: string; + DISCORD_CLIENT_ID: string; + DISCORD_CLIENT_SECRET: string; + DISCORD_PUBLIC_KEY: string; + DISCORD_TOKENS: string; + }, + { + DISCORD_APPLICATION_ID?: string | undefined; + DISCORD_CLIENT_ID?: string | undefined; + DISCORD_CLIENT_SECRET?: string | undefined; + DISCORD_PUBLIC_KEY?: string | undefined; + DISCORD_TOKENS?: string | undefined; + } +>; export default _default; diff --git a/Target/Library/Environment.js b/Target/Library/Environment.js index 5ae12b5..f762203 100644 --- a/Target/Library/Environment.js +++ b/Target/Library/Environment.js @@ -1 +1,10 @@ -(await import("dotenv")).config();const{object:o,string:t}=await import("zod");var a=o({DISCORD_APPLICATION_ID:t().optional().default(""),DISCORD_CLIENT_ID:t().optional().default(""),DISCORD_CLIENT_SECRET:t().optional().default(""),DISCORD_PUBLIC_KEY:t().optional().default(""),DISCORD_TOKENS:t().optional().default("")});export{a as default,o as object,t as string}; +(await import("dotenv")).config(); +const { object: o, string: t } = await import("zod"); +var a = o({ + DISCORD_APPLICATION_ID: t().optional().default(""), + DISCORD_CLIENT_ID: t().optional().default(""), + DISCORD_CLIENT_SECRET: t().optional().default(""), + DISCORD_PUBLIC_KEY: t().optional().default(""), + DISCORD_TOKENS: t().optional().default(""), +}); +export { a as default, o as object, t as string }; diff --git a/Target/Option/DISCORD.d.ts b/Target/Option/DISCORD.d.ts index 9cb2e62..c6feb34 100644 --- a/Target/Option/DISCORD.d.ts +++ b/Target/Option/DISCORD.d.ts @@ -1,14 +1,16 @@ -export declare const DISCORD_APPLICATION_ID: string, DISCORD_PUBLIC_KEY: string, DISCORD_TOKENS: string; +export declare const DISCORD_APPLICATION_ID: string, + DISCORD_PUBLIC_KEY: string, + DISCORD_TOKENS: string; export declare const Tokens: string[]; export type Client = { - events?: Map Promise>; - options?: ClientOptions; - token?: string; - preflight?: (...args: string[]) => Promise; + events?: Map Promise>; + options?: ClientOptions; + token?: string; + preflight?: (...args: string[]) => Promise; }; export type Flight = { - routes: []; - preflight: () => Promise; + routes: []; + preflight: () => Promise; }; export declare const Clients: Client[]; declare const _default: Client[]; diff --git a/Target/Option/DISCORD.js b/Target/Option/DISCORD.js index 7a9cf73..55edb48 100644 --- a/Target/Option/DISCORD.js +++ b/Target/Option/DISCORD.js @@ -1 +1,70 @@ -import{GatewayIntentBits as s}from"discord.js";const{DISCORD_APPLICATION_ID:l,DISCORD_PUBLIC_KEY:c,DISCORD_TOKENS:i}=(await import("../Library/Environment.js")).default.parse(process.env),g=i.indexOf(",")!==-1?i.split(","):[i],m=[{token:"",events:new Map([["message",async t=>{console.log(t)}]]),options:{intents:[s.GuildMembers,s.GuildMessages,s.Guilds,s.MessageContent]},preflight:async t=>{const e=l;if(!c)throw new Error("The DISCORD_TOKEN environment variable is required.");async function o(a){const n=await fetch(a,{headers:{"Content-Type":"application/json",Authorization:`Bot ${t}`},method:"PUT",body:JSON.stringify([AWW_COMMAND,INVITE_COMMAND])});if(n.ok)console.log("Registered all commands");else{console.error("Error registering commands");const p=await n.text();console.error(p)}return n}async function r(){await o(`https://discord.com/api/v10/applications/${e}/commands`)}await r()}}];var f=m.map((t,e)=>{const o=g[e];return o?t.token=o:console.log(`No token for client: ${e}`),t});export{m as Clients,l as DISCORD_APPLICATION_ID,c as DISCORD_PUBLIC_KEY,i as DISCORD_TOKENS,g as Tokens,f as default}; +import { GatewayIntentBits as s } from "discord.js"; +const { + DISCORD_APPLICATION_ID: l, + DISCORD_PUBLIC_KEY: c, + DISCORD_TOKENS: i, + } = (await import("../Library/Environment.js")).default.parse(process.env), + g = i.indexOf(",") !== -1 ? i.split(",") : [i], + m = [ + { + token: "", + events: new Map([ + [ + "message", + async (t) => { + console.log(t); + }, + ], + ]), + options: { + intents: [ + s.GuildMembers, + s.GuildMessages, + s.Guilds, + s.MessageContent, + ], + }, + preflight: async (t) => { + const e = l; + if (!c) + throw new Error( + "The DISCORD_TOKEN environment variable is required.", + ); + async function o(a) { + const n = await fetch(a, { + headers: { + "Content-Type": "application/json", + Authorization: `Bot ${t}`, + }, + method: "PUT", + body: JSON.stringify([AWW_COMMAND, INVITE_COMMAND]), + }); + if (n.ok) console.log("Registered all commands"); + else { + console.error("Error registering commands"); + const p = await n.text(); + console.error(p); + } + return n; + } + async function r() { + await o( + `https://discord.com/api/v10/applications/${e}/commands`, + ); + } + await r(); + }, + }, + ]; +var f = m.map((t, e) => { + const o = g[e]; + return o ? (t.token = o) : console.log(`No token for client: ${e}`), t; +}); +export { + m as Clients, + l as DISCORD_APPLICATION_ID, + c as DISCORD_PUBLIC_KEY, + i as DISCORD_TOKENS, + g as Tokens, + f as default, +};