Skip to content

Commit

Permalink
Command to refetch shiggies
Browse files Browse the repository at this point in the history
  • Loading branch information
lillithkt committed Sep 15, 2023
1 parent 4741b13 commit dcbdd7d
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/commands/getShiggies.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { SlashCommandBuilder } from "discord.js";
import { PrefixCommand, SlashCommand } from "../commands";
import changePfp from "../pfp";
import authenticatedRequest from "../utils/authenticatedRequest";

export default new PrefixCommand({
name: "getShiggies",
description: "refetches shiggies",
usage: "getShiggies",
callback: async (msg) => {
try {
await authenticatedRequest("/api/v0/getShiggies");
msg.reply("Fetching shiggies...");
} catch (e) {
msg.reply("Failed to request!");
}
},
});
27 changes: 27 additions & 0 deletions src/utils/authenticatedRequest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
export default async function authenticatedRequest(
path: string,
method: "GET" | "POST" | "PUT" | "DELETE" = "GET",
body?: any
) {
const options: RequestInit = {
method,
};

if (body) {
options.body = JSON.stringify(body);
options.headers = {
"Content-Type": "application/json",
};
}

if (!process.env.SHARED_KEY) {
console.warn("No shared key set, skipping authentication");
} else {
options.headers = {
...options.headers,
Authorization: process.env.SHARED_KEY,
};
}

return await fetch(`http://app:4321/${path}`, options);
}

0 comments on commit dcbdd7d

Please sign in to comment.