diff --git a/Target/Index.d.ts b/Target/Index.d.ts new file mode 100644 index 0000000..03a8186 --- /dev/null +++ b/Target/Index.d.ts @@ -0,0 +1,11 @@ +import { Request } from "@cloudflare/workers-types"; +declare const _default: { + fetch(request: Request, _env?: { + DISCORD_APPLICATION_ID: string; + DISCORD_CLIENT_ID: string; + DISCORD_CLIENT_SECRET: string; + DISCORD_PUBLIC_KEY: string; + DISCORD_TOKENS: string; + }): Promise; +}; +export default _default; diff --git a/Target/Index.js b/Target/Index.js new file mode 100644 index 0000000..ca9acf6 --- /dev/null +++ b/Target/Index.js @@ -0,0 +1 @@ +import{Response as r}from"@cloudflare/workers-types";import{InteractionResponseType as p,InteractionType as a,verifyKey as c}from"discord-interactions";import{Router as u}from"itty-router";import i from"./Library/Environment.js";class s extends r{constructor(n,t={headers:{"content-type":"application/json;charset=UTF-8"}}){super(JSON.stringify(n),t)}}const o=u();o.post("/discord",async(e,n)=>{const t=await e.json();if(t.type===a.PING)return new s({type:p.PONG});if(t.type===a.APPLICATION_COMMAND)switch(t.data.name.toLowerCase()){case"invite":return new s({type:4,data:{content:`https://discord.com/oauth2/authorize?client_id=${n.DISCORD_APPLICATION_ID}&scope=applications.commands`,flags:64}});default:return new s({error:"Unknown Type"},{status:400})}return new s({error:"Unknown Type"},{status:400})}),o.all("*",()=>new r("404 | Not Found.",{status:404}));var I={async fetch(e,n=i){return e.method==="POST"&&!c(await e.clone().arrayBuffer(),e.headers.get("x-signature-ed25519")??"",e.headers.get("x-signature-timestamp")??"",n.DISCORD_PUBLIC_KEY)?(console.error("Invalid Request"),new r("Bad request signature.",{status:401})):o.handle(e,i)}};export{I as default}; diff --git a/Target/Library/Environment.d.ts b/Target/Library/Environment.d.ts new file mode 100644 index 0000000..7dfc0d4 --- /dev/null +++ b/Target/Library/Environment.d.ts @@ -0,0 +1,8 @@ +declare const _default: { + DISCORD_APPLICATION_ID: string; + DISCORD_CLIENT_ID: string; + DISCORD_CLIENT_SECRET: string; + DISCORD_PUBLIC_KEY: string; + DISCORD_TOKENS: string; +}; +export default _default; diff --git a/Target/Library/Environment.js b/Target/Library/Environment.js new file mode 100644 index 0000000..df36d2d --- /dev/null +++ b/Target/Library/Environment.js @@ -0,0 +1 @@ +import{config as r}from"dotenv";import{z as t}from"zod";r();var e=t.object({DISCORD_APPLICATION_ID:t.string().default(""),DISCORD_CLIENT_ID:t.string().default(""),DISCORD_CLIENT_SECRET:t.string().default(""),DISCORD_PUBLIC_KEY:t.string().default(""),DISCORD_TOKENS:t.string().default("")}).parse(process.env);export{e as default};