mirror of
https://github.com/sern-handler/tools
synced 2026-06-06 01:16:59 +00:00
progress
This commit is contained in:
@@ -1 +0,0 @@
|
||||
57733
|
||||
@@ -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",
|
||||
|
||||
@@ -8,4 +8,4 @@
|
||||
:builds
|
||||
{:poster {:target :node-library
|
||||
:output-to "dist/index.js"
|
||||
:exports-var core.poster/add}}}
|
||||
:exports-var core.poster/poster}}}
|
||||
|
||||
40
packages/poster/src/core/actions.cljs
Normal file
40
packages/poster/src/core/actions.cljs
Normal 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)]
|
||||
})
|
||||
@@ -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))))))
|
||||
|
||||
6
packages/poster/test/spec.mjs
Normal file
6
packages/poster/test/spec.mjs
Normal file
@@ -0,0 +1,6 @@
|
||||
import poster from '../dist/index.js';
|
||||
|
||||
const client = poster("token", "appid");
|
||||
|
||||
|
||||
const req = await client("global/put", { });
|
||||
Reference in New Issue
Block a user