Skip to content

Commit

Permalink
move app.ts to project root directory
Browse files Browse the repository at this point in the history
  • Loading branch information
EthanThatOneKid committed Oct 1, 2023
1 parent 89fce1f commit 6171997
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 27 deletions.
File renamed without changes.
1 change: 0 additions & 1 deletion app/mod.ts

This file was deleted.

53 changes: 27 additions & 26 deletions main.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,31 @@
// Run:
// deno task start
//
// deno task ngrok
//

import { discord, Duration } from "shorter/deps.ts";
import { DiscordAPIClient, verify } from "shorter/lib/discord/mod.ts";
import type { ShorterOptions } from "shorter/lib/shorter/mod.ts";
import { shorter } from "shorter/lib/shorter/mod.ts";
import {
addTTLMessage,
makeTTLMessageListener,
} from "shorter/lib/queues/mod.ts";
import {
APP_SHORTER,
SHORTER_ALIAS,
SHORTER_DESTINATION,
SHORTER_FORCE,
SHORTER_TTL,
} from "shorter/app/mod.ts";
import type { ShorterOptions } from "shorter/lib/shorter/mod.ts";
import { shorter } from "shorter/lib/shorter/mod.ts";
} from "shorter/app.ts";
import {
addTTLMessage,
makeTTLMessageListener,
} from "shorter/lib/queues/mod.ts";
import * as env from "shorter/env.ts";
DISCORD_CLIENT_ID,
DISCORD_PUBLIC_KEY,
DISCORD_ROLE_ID,
DISCORD_TOKEN,
GITHUB_TOKEN,
PORT,
} from "shorter/env.ts";

const INVITE_URL =
`https://discord.com/api/oauth2/authorize?client_id=${env.DISCORD_CLIENT_ID}&scope=applications.commands`;
`https://discord.com/api/oauth2/authorize?client_id=${DISCORD_CLIENT_ID}&scope=applications.commands`;
const APPLICATION_URL =
`https://discord.com/developers/applications/${env.DISCORD_CLIENT_ID}/bot`;
`https://discord.com/developers/applications/${DISCORD_CLIENT_ID}/bot`;

const discordAPI = new DiscordAPIClient();

Expand All @@ -38,11 +39,11 @@ if (import.meta.main) {
export async function main() {
// Set up queue listener.
const kv = await Deno.openKv();
kv.listenQueue(makeTTLMessageListener(env.GITHUB_TOKEN));
kv.listenQueue(makeTTLMessageListener(GITHUB_TOKEN));

// Start the server.
Deno.serve(
{ port: env.PORT, onListen },
{ port: PORT, onListen },
makeHandler(kv),
);
}
Expand All @@ -51,8 +52,8 @@ async function onListen() {
// Overwrite the Discord Application Command.
await discordAPI.registerCommand({
app: APP_SHORTER,
botID: env.DISCORD_CLIENT_ID,
botToken: env.DISCORD_TOKEN,
botID: DISCORD_CLIENT_ID,
botToken: DISCORD_TOKEN,
});

// Log the invite URL.
Expand All @@ -77,7 +78,7 @@ export function makeHandler(kv: Deno.Kv) {
}

// Verify the request.
const { error, body } = await verify(request, env.DISCORD_PUBLIC_KEY);
const { error, body } = await verify(request, DISCORD_PUBLIC_KEY);
if (error !== null) {
return error;
}
Expand All @@ -101,7 +102,7 @@ export function makeHandler(kv: Deno.Kv) {
}

if (
!interaction.member.roles.some((role) => env.DISCORD_ROLE_ID === role)
!interaction.member.roles.some((role) => DISCORD_ROLE_ID === role)
) {
return new Response("Invalid request", { status: 400 });
}
Expand Down Expand Up @@ -143,8 +144,8 @@ export function makeHandler(kv: Deno.Kv) {

// Send the success message.
await discordAPI.editOriginalInteractionResponse({
botID: env.DISCORD_CLIENT_ID,
botToken: env.DISCORD_TOKEN,
botID: DISCORD_CLIENT_ID,
botToken: DISCORD_TOKEN,
interactionToken: interaction.token,
content,
});
Expand All @@ -163,8 +164,8 @@ export function makeHandler(kv: Deno.Kv) {
.catch((error) => {
if (error instanceof Error) {
discordAPI.editOriginalInteractionResponse({
botID: env.DISCORD_CLIENT_ID,
botToken: env.DISCORD_TOKEN,
botID: DISCORD_CLIENT_ID,
botToken: DISCORD_TOKEN,
interactionToken: interaction.token,
content: `Error: ${error.message}`,
});
Expand Down Expand Up @@ -218,7 +219,7 @@ export function makeShorterOptions(
}

return {
githubPAT: env.GITHUB_TOKEN,
githubPAT: GITHUB_TOKEN,
actor: {
tag: member.user.username,
nick: member.nick || undefined,
Expand Down

0 comments on commit 6171997

Please sign in to comment.