-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
specs.clj
74 lines (55 loc) · 2.14 KB
/
specs.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
(ns discljord.specs
(:require [clojure.core.async :as a]
[clojure.spec.alpha :as s]))
;; -------------------------------------------------
;; generic specs
(s/def ::url string?)
(s/def ::token string?)
(s/def ::future any?)
(s/def ::promise any?)
(s/def ::channel (partial satisfies? clojure.core.async.impl.protocols/Channel))
(defn atom-of?
"Takes a spec, and returns a spec for a clojure.lang.Atom
containing a value of that spec."
[s]
(fn [x]
(and (instance? clojure.lang.Atom x)
(s/valid? s @x))))
(s/def ::snowflake string?)
;; -------------------------------------------------
;; discljord.connection specs
(s/def ::shard-id int?)
(s/def ::shard-count pos-int?)
(s/def ::gateway (s/keys :req [::url ::shard-count]))
(s/def ::session-id (s/nilable string?))
(s/def ::seq (s/nilable int?))
(s/def ::buffer-size number?)
(s/def ::disconnect boolean?)
(s/def ::shard-state (s/keys :req-un [::session-id ::seq
::buffer-size ::disconnect]))
(s/def ::connection any?)
;; -------------------------------------------------
;; discljord.messaging specs
(s/def ::major-variable-type #{::guild-id ::channel-id ::webhook-id})
(s/def ::major-variable-value ::snowflake)
(s/def ::major-variable (s/keys :req [::major-variable-type
::major-variable-value]))
(s/def ::action keyword?)
(s/def ::endpoint (s/keys :req [::action]
:opt [::major-variable]))
(s/def ::rate number?)
(s/def ::remaining number?)
(s/def ::reset number?)
(s/def ::global boolean?)
(s/def ::rate-limit (s/keys :req [::rate ::remaining ::reset]
:opt [::global]))
(s/def ::endpoint-specific-rate-limits (s/map-of ::endpoint ::rate-limit))
(s/def ::global-rate-limit ::rate-limit)
(s/def ::rate-limits (s/keys :req [::endpoint-specific-rate-limits]
:opt [::global-rate-limit]))
(s/def ::process (s/keys :req [::rate-limits
::channel
::token]))
(s/def ::message (s/and string?
#(< (count %) 2000)))
(s/def ::channel-id ::snowflake)