diff --git a/Source/Variable/Worker.ts b/Source/Variable/Worker.ts index 7f2d0bb..cf32f5b 100644 --- a/Source/Variable/Worker.ts +++ b/Source/Variable/Worker.ts @@ -6,7 +6,7 @@ class JSONResponse extends Response { headers: { "content-type": "application/json;charset=UTF-8", }, - }, + } ) { super(JSON.stringify(body), init); } @@ -47,7 +47,7 @@ class JSONResponse extends Response { default: return new JSONResponse( { error: "Unknown Type" }, - { status: 400 }, + { status: 400 } ); } } @@ -62,7 +62,7 @@ class JSONResponse extends Response { export default { async fetch( request: Request, - { DISCORD_PUBLIC_KEY } = Environment.parse(process.env), + { DISCORD_PUBLIC_KEY } = Environment.parse(process.env) ) { if (request.method === "POST") { const isValidRequest = ( @@ -71,7 +71,7 @@ export default { await request.clone().arrayBuffer(), request["headers"].get("x-signature-ed25519") ?? "", request["headers"].get("x-signature-timestamp") ?? "", - DISCORD_PUBLIC_KEY, + DISCORD_PUBLIC_KEY ); if (!isValidRequest) { diff --git a/Target/Type/Environment.d.ts b/Target/Type/Environment.d.ts index 6deb1c5..36a287c 100644 --- a/Target/Type/Environment.d.ts +++ b/Target/Type/Environment.d.ts @@ -5,28 +5,22 @@ export type Type = Zod.infer; export type { Type as default }; import type Zod from "zod"; -export declare const Environment: Zod.ZodObject< - { - DISCORD_APPLICATION_ID: Zod.ZodDefault>; - DISCORD_CLIENT_ID: Zod.ZodDefault>; - DISCORD_CLIENT_SECRET: Zod.ZodDefault>; - DISCORD_PUBLIC_KEY: Zod.ZodDefault>; - DISCORD_TOKENS: Zod.ZodDefault>; - }, - "strip", - 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 Environment: Zod.ZodObject<{ + DISCORD_APPLICATION_ID: Zod.ZodDefault>; + DISCORD_CLIENT_ID: Zod.ZodDefault>; + DISCORD_CLIENT_SECRET: Zod.ZodDefault>; + DISCORD_PUBLIC_KEY: Zod.ZodDefault>; + DISCORD_TOKENS: Zod.ZodDefault>; +}, "strip", 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; +}>; diff --git a/Target/Type/Environment.js b/Target/Type/Environment.js index 24a7c13..283a577 100644 --- a/Target/Type/Environment.js +++ b/Target/Type/Environment.js @@ -1,2 +1 @@ -const { default: t } = await import("../Variable/Environment.js"); -export { t as Environment }; +const{default:t}=await import("../Variable/Environment.js");export{t as Environment}; diff --git a/Target/Variable/Environment.d.ts b/Target/Variable/Environment.d.ts index d3d79fd..82fd6eb 100644 --- a/Target/Variable/Environment.d.ts +++ b/Target/Variable/Environment.d.ts @@ -1,48 +1,28 @@ -export declare const 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 declare const 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 default _default; diff --git a/Target/Variable/Environment.js b/Target/Variable/Environment.js index 2b5c1b2..8cd727b 100644 --- a/Target/Variable/Environment.js +++ b/Target/Variable/Environment.js @@ -1,10 +1 @@ -(await import("dotenv")).config(); -const { string: t } = await import("zod"); -var o = (await import("zod")).object({ - 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 { o as default, t as string }; +(await import("dotenv")).config();const{string:t}=await import("zod");var o=(await import("zod")).object({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{o as default,t as string}; diff --git a/Target/Variable/Worker.d.ts b/Target/Variable/Worker.d.ts index 40f5553..d927f4f 100644 --- a/Target/Variable/Worker.d.ts +++ b/Target/Variable/Worker.d.ts @@ -1,52 +1,31 @@ declare const _default: { - fetch( - request: Request, - { - DISCORD_PUBLIC_KEY, - }?: { - DISCORD_APPLICATION_ID: string; - DISCORD_CLIENT_ID: string; - DISCORD_CLIENT_SECRET: string; - DISCORD_PUBLIC_KEY: string; - DISCORD_TOKENS: string; - }, - ): Promise; + fetch(request: Request, { DISCORD_PUBLIC_KEY }?: { + DISCORD_APPLICATION_ID: string; + DISCORD_CLIENT_ID: string; + DISCORD_CLIENT_SECRET: string; + DISCORD_PUBLIC_KEY: string; + DISCORD_TOKENS: string; + }): Promise; }; export default _default; import type { Request } from "@cloudflare/workers-types"; -export declare const Environment: 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 declare const Environment: 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 Response: typeof import("@cloudflare/workers-types").Response; diff --git a/Target/Variable/Worker.js b/Target/Variable/Worker.js index 584571f..a16a275 100644 --- a/Target/Variable/Worker.js +++ b/Target/Variable/Worker.js @@ -1,56 +1 @@ -class a extends n { - constructor( - t, - s = { headers: { "content-type": "application/json;charset=UTF-8" } }, - ) { - super(JSON.stringify(t), s); - } -} -(await import("itty-router")).Router().post("/discord", async (e) => { - const t = await e.json(); - if (t.type === (await import("discord-interactions")).InteractionType.PING) - return new a({ - type: (await import("discord-interactions")).InteractionResponseType - .PONG, - }); - if ( - t.type === - (await import("discord-interactions")).InteractionType - .APPLICATION_COMMAND - ) - switch (t.data.name.toLowerCase()) { - case "invite": - return new a({ - type: 4, - data: { - content: `https://discord.com/oauth2/authorize?client_id=${ - r.parse(process.env).DISCORD_APPLICATION_ID - }&scope=applications.commands`, - flags: 64, - }, - }); - default: - return new a({ error: "Unknown Type" }, { status: 400 }); - } - return new a({ error: "Unknown Type" }, { status: 400 }); -}), - (await import("itty-router")) - .Router() - .all("*", () => new n("404 | Not Found.", { status: 404 })); -var o = { - async fetch(e, { DISCORD_PUBLIC_KEY: t } = r.parse(process.env)) { - return e.method === "POST" && - !(await import("discord-interactions")).verifyKey( - await e.clone().arrayBuffer(), - e.headers.get("x-signature-ed25519") ?? "", - e.headers.get("x-signature-timestamp") ?? "", - t, - ) - ? (console.error("Invalid Request"), - new n("Bad request signature.", { status: 401 })) - : (await import("itty-router")).Router().handle(e); - }, -}; -const { default: r } = await import("./Environment.js"), - { Response: n } = await import("@cloudflare/workers-types"); -export { r as Environment, n as Response, o as default }; +class a extends n{constructor(t,s={headers:{"content-type":"application/json;charset=UTF-8"}}){super(JSON.stringify(t),s)}}(await import("itty-router")).Router().post("/discord",async e=>{const t=await e.json();if(t.type===(await import("discord-interactions")).InteractionType.PING)return new a({type:(await import("discord-interactions")).InteractionResponseType.PONG});if(t.type===(await import("discord-interactions")).InteractionType.APPLICATION_COMMAND)switch(t.data.name.toLowerCase()){case"invite":return new a({type:4,data:{content:`https://discord.com/oauth2/authorize?client_id=${r.parse(process.env).DISCORD_APPLICATION_ID}&scope=applications.commands`,flags:64}});default:return new a({error:"Unknown Type"},{status:400})}return new a({error:"Unknown Type"},{status:400})}),(await import("itty-router")).Router().all("*",()=>new n("404 | Not Found.",{status:404}));var o={async fetch(e,{DISCORD_PUBLIC_KEY:t}=r.parse(process.env)){return e.method==="POST"&&!(await import("discord-interactions")).verifyKey(await e.clone().arrayBuffer(),e.headers.get("x-signature-ed25519")??"",e.headers.get("x-signature-timestamp")??"",t)?(console.error("Invalid Request"),new n("Bad request signature.",{status:401})):(await import("itty-router")).Router().handle(e)}};const{default:r}=await import("./Environment.js"),{Response:n}=await import("@cloudflare/workers-types");export{r as Environment,n as Response,o as default};