This commit is contained in:
jacob
2024-04-07 15:21:52 -05:00
parent 3030c90a37
commit 25d32929d1
4 changed files with 19 additions and 20 deletions

View File

@@ -22,8 +22,7 @@
[url (fn [body headers]
#js { "method" method
"headers" headers
"body" (.stringify js/JSON body )})
]))
"body" (js/JSON.stringify body)}) ]))
(def actions (into {}

View File

@@ -14,27 +14,27 @@
(new js/URLSearchParams query))
(defn- ^:async fetch-application [headers]
(js-await (-> (js/fetch (str base (first (get actions "application/me"))) #js{ "headers" headers })
(.then (fn ^:=> [res] (.json res)))
(.then (fn ^:=> [son] (if-let [id (.-id son)]
id (throw (str "Reason " (.-message son))))))
(.catch (fn ^:=> [e] (throw e))))))
(defn- fetch-application [headers]
(let [url (str base (first (get actions "application/me")))]
(-> (js/fetch url #js{ "headers" headers })
(.then (fn ^:=> [res] (.json res)))
(.then (fn ^:=> [son] (if-let [id (.-id son)]
id
(throw (str "Reason " (.-message son))))))
(.catch (fn ^:=> [e] (throw e))))))
(defn- poster [token, appid]
(let [header #js{ "Content-Type" "application/json"
"Authorization" (str "Bot " token) }]
(defn- poster [token]
(let [header { "Content-Type" "application/json"
"Authorization" (str "Bot " token) }]
(^:async fn [action opts]
(let [[url mkrequest] (get actions action)
appid (js-await (fetch-application header))
options #js{"app_id" appid
"guild_id" (.-guild_id ^js opts)
"command_id" (.-command_id ^js opts)}
options {:app_id appid :guild_id (.-guild_id opts) :command_id (.-command_id opts)}
url (new js/URL (inject url options)) ]
(set! (.-search url) (?params (.-query ^js opts)))
(js/fetch url (mkrequest (.-body ^js opts) header))))))
(set! (.-search url) (?params (.-query opts)))
(js/fetch url (mkrequest (.-body opts) header))))))
(defn- isOk? [^js response]
(defn- isOk? [response]
(.-ok response))

View File

@@ -1,4 +1,4 @@
declare module 'poster';
declare module 'poster.*';
import type { paths } from './discord.d.ts'

View File

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