aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Janzen <jacob.a.s.janzen@gmail.com>2024-12-30 20:58:25 -0600
committerJacob Janzen <jacob.a.s.janzen@gmail.com>2024-12-30 20:58:25 -0600
commitf97d1e32bf80f4d9ce2339f526a1e7722387dacc (patch)
treee82cdf279b4114f7052bbabdf4c1a9e5ea83bc5c
parent04b0fa8855b62fac8677300c8ced95852358e44b (diff)
try https for request
-rw-r--r--app.js3
-rw-r--r--command_impls.js26
-rw-r--r--commands.js7
-rw-r--r--package-lock.json7
-rw-r--r--package.json1
5 files changed, 44 insertions, 0 deletions
diff --git a/app.js b/app.js
index 5828b31..794ca0d 100644
--- a/app.js
+++ b/app.js
@@ -37,6 +37,9 @@ function handle_application_command(state, data, channel_id) {
case "blep":
return blep(state);
+ case "catfact":
+ return catfact(state);
+
default:
console.error(`unknown command: ${name}`);
return res.status(400).json({ error: "unknown command" });
diff --git a/command_impls.js b/command_impls.js
index 92bc544..f6508fb 100644
--- a/command_impls.js
+++ b/command_impls.js
@@ -1,6 +1,7 @@
import { InteractionResponseType } from "discord-interactions";
import { Message } from "./message-scheduler.js";
import { ActionRowBuilder, ButtonBuilder, ButtonStyle } from "discord.js";
+import { request } from "https";
function send(state, data) {
return state.res.send({
@@ -45,3 +46,28 @@ Here are the available commands and their descriptions:
export function blep(state) {
return send(state, { content: "≽^•𐃷•^≼" });
}
+
+export function catfact(state) {
+ const options = {
+ hostname: "meowfacts.herokuapp.com",
+ path: "/",
+ port: 443,
+ method: "GET",
+ };
+
+ let body = [];
+
+ const req = request(options, (res) => {
+ res.on("data", (chunk) => body.push(chunk));
+ res.on("end", () => {
+ const data = Buffer.concat(body).toString();
+ resolve(data);
+ console.log(data);
+ });
+ });
+ req.on("error", (e) => {
+ console.log(`https error: ${e}`);
+ reject(e);
+ });
+ req.end();
+}
diff --git a/commands.js b/commands.js
index 97b7265..31f7b34 100644
--- a/commands.js
+++ b/commands.js
@@ -25,6 +25,13 @@ const commands = [
contexts: [0],
},
{
+ name: "catfact",
+ description: "get a cat fact",
+ type: 1,
+ integration_types: [0],
+ contexts: [0],
+ },
+ {
name: "schedule_message",
description: "Register a message to run as a cron job",
type: 1,
diff --git a/package-lock.json b/package-lock.json
index 256eba1..946bcf9 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -13,6 +13,7 @@
"discord.js": "^14.16.3",
"dotenv": "^16.0.3",
"express": "^4.18.2",
+ "https": "^1.0.0",
"node-cron": "^3.0.3",
"uuid": "^11.0.3"
},
@@ -838,6 +839,12 @@
"node": ">= 0.8"
}
},
+ "node_modules/https": {
+ "version": "1.0.0",
+ "resolved": "https://registry.npmjs.org/https/-/https-1.0.0.tgz",
+ "integrity": "sha512-4EC57ddXrkaF0x83Oj8sM6SLQHAWXw90Skqu2M4AEWENZ3F02dFJE/GARA8igO79tcgYqGrD7ae4f5L3um2lgg==",
+ "license": "ISC"
+ },
"node_modules/iconv-lite": {
"version": "0.4.24",
"resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.4.24.tgz",
diff --git a/package.json b/package.json
index 6872a5c..d353335 100644
--- a/package.json
+++ b/package.json
@@ -20,6 +20,7 @@
"discord.js": "^14.16.3",
"dotenv": "^16.0.3",
"express": "^4.18.2",
+ "https": "^1.0.0",
"node-cron": "^3.0.3",
"uuid": "^11.0.3"
},