This commit is contained in:
Jacob Nguyen
2023-11-07 19:36:32 -06:00
parent 41b90e7ac5
commit 524b5ab318
6 changed files with 63 additions and 11 deletions

View File

@@ -1 +0,0 @@
57733

View File

@@ -4,7 +4,10 @@
"description": "",
"main": "dist/index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"test": "echo \"Error: no test specified\" && exit 1",
"build:debug": "shadow-cljs compile poster",
"build:release": "shadow-cljs release poster",
"repl": "shadow-cljs node-repl"
},
"devDependencies": {
"shadow-cljs": "^2.8.52",

View File

@@ -8,4 +8,4 @@
:builds
{:poster {:target :node-library
:output-to "dist/index.js"
:exports-var core.poster/add}}}
:exports-var core.poster/poster}}}

View File

@@ -0,0 +1,40 @@
(ns core.actions
(:require [cljs.spec.alpha :as s]))
(defn create-validator [schema]
{ :valid #(s/valid? schema %)
:explain #(s/explain schema %) })
#_(s/def ::http-verb (s/enum "POST" "PATCH" "PUT" "GET"))
(s/def :global/put some?)
(def routes {
; :GlobalGetAll "/applications/{application.id}/commands"
; :GlobalGet "/applications/{application.id}/commands/commands/{command.id}"
; :GlobalPost "/applications/{application.id}/commands"
; :GlobalEdit "/applications/{application.id}/commands/{command.id}"
; :GlobalDelete "/applications/{application.id}/commands/{command.id}"
:global/put #js["GET" "/applications/{application.id}/commands"]
; :GuildGetAll "/applications/{application.id}/guilds/{guild.id}/commands"
; :GuildPost "/applications/{application.id}/guilds/{guild.id}/commands"
; :GuildGet "/applications/{application.id}/guilds/{guild.id}/commands/{command.id}"
; :GuildEdit "/applications/{application.id}/guilds/{guild.id}/commands/{command.id}"
; :GuildDelete "/applications/{application.id}/guilds/{guild.id}/commands/{command.id}"
; :GuildPut "/applications/{application.id}/guilds/{guild.id}/commands"
})
(defn parseurl
[appid]
)
(defn request-init [spec]
(fn [body]
#js { "method" (first (routes 'spec))
"body" body }))
(def validators {
"global/put" [(request-init :global/put)
(create-validator :global/put)]
})

View File

@@ -1,16 +1,20 @@
(ns core.poster)
(ns core.poster
(:use [core.actions :only [validators]]))
(def base-url (new js/URL "https://discord.com/api/v10/applications/"))
(def excluded-keys #{ "command" "absPath" })
(def excluded-keys #js { "command" "absPath" })
(defn make-global [appid token]
"makes a url which posts to global"
(new js/URL (str appid "/commands") base-url))
(defn poster [ appid token]
(let [global-url (make-global appid token)]
#js {
}))
(defn poster [token, appid]
(let [header #js{ "Content-Type" "application/json"
"Authorization" (str "Bot " token) }]
(fn [action body]
(let [ [request-init validator] (validators action)
{ is-valid? :valid explain :explain } validator]
(if (is-valid? body)
(js/fetch base-url (request-init body))
(explain body))))))

View File

@@ -0,0 +1,6 @@
import poster from '../dist/index.js';
const client = poster("token", "appid");
const req = await client("global/put", { });