diff options
author | Luca Matei Pintilie <lucafulger@gmail.com> | 2021-09-18 18:38:27 +0000 |
---|---|---|
committer | Luca Matei Pintilie <lucafulger@gmail.com> | 2021-09-18 18:38:27 +0000 |
commit | d25b6fec207df8429552a6cfd11a758dff588a60 (patch) | |
tree | 289a1f6f8f47e66b749e8cf4a2953ca9199b7146 | |
parent | 6c618ff06a8db397507373cd3490c30611c60c03 (diff) | |
download | speedrunbot-slash-d25b6fec207df8429552a6cfd11a758dff588a60.tar speedrunbot-slash-d25b6fec207df8429552a6cfd11a758dff588a60.tar.gz speedrunbot-slash-d25b6fec207df8429552a6cfd11a758dff588a60.tar.bz2 speedrunbot-slash-d25b6fec207df8429552a6cfd11a758dff588a60.tar.lz speedrunbot-slash-d25b6fec207df8429552a6cfd11a758dff588a60.tar.xz speedrunbot-slash-d25b6fec207df8429552a6cfd11a758dff588a60.tar.zst speedrunbot-slash-d25b6fec207df8429552a6cfd11a758dff588a60.zip |
Remove fancy website stuff and rename command to pending-count
-rwxr-xr-x | src/client.ts | 6 | ||||
-rw-r--r-- | src/deps_harmony.ts | 4 | ||||
-rw-r--r-- | src/pages/api/discord/token.ts | 31 | ||||
-rw-r--r-- | src/pages/index.tsx | 16 | ||||
-rw-r--r-- | src/pages/login.tsx | 49 | ||||
-rw-r--r-- | src/routes.gen.ts | 12 | ||||
-rwxr-xr-x | src/srcom/pendingCount.ts (renamed from src/srcom/pendingQueue.ts) | 4 | ||||
-rw-r--r-- | src/srcom/slashCommands.ts | 13 |
8 files changed, 29 insertions, 106 deletions
diff --git a/src/client.ts b/src/client.ts index b79a337..7a26ff9 100755 --- a/src/client.ts +++ b/src/client.ts @@ -4,7 +4,7 @@ import { commands } from "./srcom/slashCommands.ts"; import "https://deno.land/x/dot_env@0.2.0/load.ts"; import { SpeedrunCom } from "./srcom/slashCommands.ts"; -import { Client, event, Intents } from "./deps_harmony.ts"; +import { Client, event } from "./deps_harmony.ts"; export class SpeedRunBot extends Client { @event() @@ -12,7 +12,7 @@ export class SpeedRunBot extends Client { console.log("Started!"); this.interactions.loadModule(new SpeedrunCom()); // this.deleteCommands(Deno.env.get("TEST_SERVER")); - //this.register(); + // this.register(); } register() { @@ -33,7 +33,7 @@ export class SpeedRunBot extends Client { if (import.meta.main) { const client = new SpeedRunBot({ - intents: Intents.NonPrivileged, + intents: [], token: Deno.env.get("TOKEN"), }); client.connect(); diff --git a/src/deps_harmony.ts b/src/deps_harmony.ts index 93a54ac..b2d9a18 100644 --- a/src/deps_harmony.ts +++ b/src/deps_harmony.ts @@ -1,2 +1,2 @@ -export * from "https://code.harmony.rocks/502c47385ed66e571e5108e07ed5ac3c18fd6264/mod.ts"; -export * from "https://code.harmony.rocks/502c47385ed66e571e5108e07ed5ac3c18fd6264/src/utils/encoding.ts"; +export * from "https://code.harmony.rocks/5cb3d8e6494831b7e9141206171ad6671bccca09/mod.ts"; +export * from "https://code.harmony.rocks/5cb3d8e6494831b7e9141206171ad6671bccca09/src/utils/encoding.ts"; diff --git a/src/pages/api/discord/token.ts b/src/pages/api/discord/token.ts deleted file mode 100644 index 3a83ad6..0000000 --- a/src/pages/api/discord/token.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { DISCORD_URL } from "../../../utils.ts"; -import { client } from "./interactions.ts"; - -export default async (req: Request): Promise<Response> => { - try { - const { code } = await req.json(); - const body = new URLSearchParams({ - client_id: client.getID(), - client_secret: Deno.env.get("CLIENT_SECRET")!, - grant_type: "authorization_code", - code, - prompt: "consent", - redirect_uri: encodeURIComponent(req.url), - }); - const res = await fetch(`${DISCORD_URL}/oauth2/token`, { - headers: { - "Content-Type": "application/x-www-form-urlencoded", - }, - body: body.toString(), - method: "POST", - }); - const data = await res.json(); - console.log(body.toString()); - return new Response(JSON.stringify(data)); - } catch (err) { - console.log(err); - return new Response( - JSON.stringify({ code: 400, message: "Invalid request" }), - ); - } -}; diff --git a/src/pages/index.tsx b/src/pages/index.tsx index 17ceb6d..7e905fc 100644 --- a/src/pages/index.tsx +++ b/src/pages/index.tsx @@ -1,5 +1,5 @@ /** @jsx h */ -import { h, IS_BROWSER, useData, useEffect, useState } from "../deps.ts"; +import { h, useEffect, useState } from "../deps.ts"; import { DISCORD_URL } from "../utils.ts"; export default function Home() { @@ -15,11 +15,15 @@ export default function Home() { <p> This is the home page of speedrun.bot </p> - <a - href={`${DISCORD_URL}/authorize?client_id=${id}&scope=applications.commands`} - > - Click here to invite the bot! - </a> + {id + ? ( + <a + href={`${DISCORD_URL}/authorize?client_id=${id}&scope=applications.commands`} + > + Click here to invite the bot! + </a> + ) + : "Loading..."} </div> ); } diff --git a/src/pages/login.tsx b/src/pages/login.tsx deleted file mode 100644 index 848af6f..0000000 --- a/src/pages/login.tsx +++ /dev/null @@ -1,49 +0,0 @@ -/** @jsx h */ -import { h, IS_BROWSER, useEffect, useState } from "../deps.ts"; -import { DISCORD_URL } from "../utils.ts"; - -export default function Login() { - const [state, setState] = useState(""); - const [id, setId] = useState(""); - useEffect(() => { - fetch("/api/discord/bot_info").then((res) => res.json()).then((data) => - setId(data.id) - ); - }, [setId]); - useEffect(() => { - const url = new URL(location.href); - const code = url.searchParams.get("code"); - if (code) { - fetch("/api/discord/token", { - method: "POST", - body: JSON.stringify({ code }), - headers: { - "Content-Type": "application/json", - }, - }).then((res) => res.json()).then(setState); - } - }, [setState]); - return ( - <div> - <h1>Speedrun.bot</h1> - <p> - Press the button below to login - </p> - <span>{JSON.stringify(state, null, 4)}</span> - {IS_BROWSER - ? ( - <a - href={`${DISCORD_URL}/oauth2/authorize?${new URLSearchParams({ - response_type: "code", - client_id: id, - scope: "guilds", - redirect_uri: encodeURI(`${location.origin}${location.pathname}`), - })}`} - > - Click me! - </a> - ) - : "Can't get the link"} - </div> - ); -} diff --git a/src/routes.gen.ts b/src/routes.gen.ts index 235378c..9735e49 100644 --- a/src/routes.gen.ts +++ b/src/routes.gen.ts @@ -3,18 +3,14 @@ // To update this file, run `fresh routes`. import * as $0 from "./pages/index.tsx"; -import * as $1 from "./pages/api/discord/token.ts"; -import * as $2 from "./pages/api/discord/interactions.ts"; -import * as $3 from "./pages/api/discord/bot_info.ts"; -import * as $4 from "./pages/login.tsx"; +import * as $1 from "./pages/api/discord/interactions.ts"; +import * as $2 from "./pages/api/discord/bot_info.ts"; const routes = { pages: { "./pages/index.tsx": $0, - "./pages/api/discord/token.ts": $1, - "./pages/api/discord/interactions.ts": $2, - "./pages/api/discord/bot_info.ts": $3, - "./pages/login.tsx": $4, + "./pages/api/discord/interactions.ts": $1, + "./pages/api/discord/bot_info.ts": $2, }, baseUrl: import.meta.url, }; diff --git a/src/srcom/pendingQueue.ts b/src/srcom/pendingCount.ts index 77270a3..31a5e93 100755 --- a/src/srcom/pendingQueue.ts +++ b/src/srcom/pendingCount.ts @@ -4,7 +4,7 @@ import { getAll, getGame, SRC_API } from "./utils.ts"; import type { Opts } from "./utils.ts"; import type { SpeedrunCom } from "./types.d.ts"; -export async function pendingQueue( +export async function pendingCount( games: string[] = [], { id = false, outputType = "markdown" }: Opts = {}, ): Promise<string> { @@ -43,5 +43,5 @@ export async function pendingQueue( } if (import.meta.main) { - console.log(await pendingQueue(Deno.args, { outputType: "terminal" })); + console.log(await pendingCount(Deno.args, { outputType: "terminal" })); } diff --git a/src/srcom/slashCommands.ts b/src/srcom/slashCommands.ts index 22701b8..c8b1c04 100644 --- a/src/srcom/slashCommands.ts +++ b/src/srcom/slashCommands.ts @@ -17,7 +17,7 @@ import { whois } from "./whois.ts"; import { worldRecords } from "./worldrecords.ts"; import { categoriesPlayed } from "./categoriesPlayed.ts"; import { pending } from "./pending.ts"; -import { pendingQueue } from "./pendingQueue.ts"; +import { pendingCount } from "./pendingCount.ts"; const srcUser: ApplicationCommandOption = { name: "username", @@ -185,9 +185,12 @@ async function sendCommand( func: (i: ApplicationCommandInteraction) => Promise<string>, { defer = true }: { defer?: boolean } = {}, ) { - if (defer) i.defer(); + if (defer) await i.defer(); const [title, ...description] = (await func(i)).split("\n"); if (description.length > 10) { + await i.reply( + "This message will be sent into many small and hidden chunks to prevent spam.", + ); const chunks = splitIntoChunks(description, 10); for (let ii = 0; ii < chunks.length; ii++) { await i.send({ @@ -284,12 +287,12 @@ export class SpeedrunCom extends ApplicationCommandsModule { ); } - @slash("pending-queue") - async pendingQueue(i: ApplicationCommandInteraction) { + @slash("pending-count") + async pendingCount(i: ApplicationCommandInteraction) { await sendCommand( i, (i) => - pendingQueue([ + pendingCount([ i.option("game"), i.option("game2"), ], { outputType: "markdown" }), |