pdate poster

This commit is contained in:
jacob
2024-01-28 17:39:35 -06:00
parent 2e7b545bff
commit 6cc78c3c45
4 changed files with 13 additions and 6 deletions

View File

@@ -9,7 +9,6 @@
"gen-discord-types": "npx openapi-typescript https://raw.githubusercontent.com/discord/discord-api-spec/main/specs/openapi.json --output ./dts/discord.d.ts",
"repl": "shadow-cljs node-repl"
},
"devDependencies": {
"shadow-cljs": "^2.8.52",
"source-map-support": "^0.5.13"

View File

@@ -14,6 +14,7 @@
:guild/edit ["PATCH" "/applications/{application.id}/guilds/{guild.id}/commands/{command.id}"]
:guild/delete ["DELETE" "/applications/{application.id}/guilds/{guild.id}/commands/{command.id}"]
:guild/put ["PUT" "/applications/{application.id}/guilds/{guild.id}/commands"]
:application/me ["GET" "/applications/@me"]
})
(defn- request-init [v]

View File

@@ -1,5 +1,6 @@
(ns core.poster
(:require [clojure.string :refer [replace]]
[shadow.cljs.modern :refer (js-await)]
[core.actions :refer [actions]]))
(def base "https://discord.com/api/v10")
@@ -13,17 +14,24 @@
(defn- ?params [^js query]
(new js/URLSearchParams query))
(defn fetch-application [headers]
#_(println (str base (actions "application/me")))
(-> (js/fetch (str base (first (actions "application/me"))) #js{ "headers" headers })
(.then (fn [res] (.json res)))
(.then (fn [json] (.-id json)))))
(defn poster [token, appid]
(let [header #js{ "Content-Type" "application/json"
"Authorization" (str "Bot " token) }]
(fn [action opts]
"Authorization" (str "Bot " token) } ]
(js-await [appid (fetch-application header)]
(fn [action opts]
(let [[url mkrequest] (actions action)
options #js{"app_id" appid
"guild_id" (.-guild_id ^js opts)
"command_id" (.-command_id ^js opts)}
url (new js/URL (inject url options))]
(set! (.-search url) (?params (.-query ^js opts)))
(js/fetch url (mkrequest (.-body ^js opts) header))))))
(js/fetch url (mkrequest (.-body ^js opts) header)))))))
(defn isOk? [^js response]
(.-ok response))

View File

@@ -1,7 +1,6 @@
import poster from '../dist/index.js';
const send = poster.client("token", "appid");
const send = await poster.client("MTA2MTQyMTgzNDM0MTQ2MjAzNg.GL15Ob.EJ9SgdMQUhTTTGRhRKNBvVDQkTma7AG3DuLWis");
const req = await send("global/get-all", {