aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdelyn Breelove <[email protected]>2019-02-19 08:45:12 -0700
committerAdelyn Breelove <[email protected]>2019-02-19 08:45:12 -0700
commit3d3943ce13a3379969a1478f10e6741162813744 (patch)
tree3451bf7a5917e68b1bddb8d48765fdc495d39b0a
parentChange channel.t to use more flexible variant (diff)
downloaddisml-3d3943ce13a3379969a1478f10e6741162813744.tar.xz
disml-3d3943ce13a3379969a1478f10e6741162813744.zip
add cache helper methods
-rw-r--r--lib/cache.ml33
-rw-r--r--lib/cache.mli44
2 files changed, 75 insertions, 2 deletions
diff --git a/lib/cache.ml b/lib/cache.ml
index db1f4e2..96ca42a 100644
--- a/lib/cache.ml
+++ b/lib/cache.ml
@@ -35,4 +35,35 @@ let create () =
let cache =
let m = Mvar.create () in
Mvar.set m (create ());
- m \ No newline at end of file
+ m
+
+let guild cache = GuildMap.find cache.guilds
+
+let text_channel cache = ChannelMap.find cache.text_channels
+
+let voice_channel cache = ChannelMap.find cache.voice_channels
+
+let category cache = ChannelMap.find cache.categories
+
+let dm cache = ChannelMap.find cache.private_channels
+
+let group cache = ChannelMap.find cache.groups
+
+let channel cache id =
+ let check = ChannelMap.find in
+ match check cache.text_channels id with
+ | Some c -> Some (`GuildText c)
+ | None -> (
+ match check cache.voice_channels id with
+ | Some c -> Some (`GuildVoice c)
+ | None -> (
+ match check cache.categories id with
+ | Some c -> Some (`Category c)
+ | None -> (
+ match check cache.private_channels id with
+ | Some c -> Some (`Private c)
+ | None -> (
+ match check cache.groups id with
+ | Some c -> Some (`Group c)
+ | None -> None
+ )))) \ No newline at end of file
diff --git a/lib/cache.mli b/lib/cache.mli
index 1909303..24a8a1b 100644
--- a/lib/cache.mli
+++ b/lib/cache.mli
@@ -34,4 +34,46 @@ val cache : t Mvar.Read_write.t
val create :
(* ?max_messages:int -> *)
unit ->
- t \ No newline at end of file
+ t
+
+(** Equivalent to {!GuildMap.find} on cache.guilds. *)
+val guild :
+ t ->
+ Guild_id_t.t ->
+ Guild_t.t option
+
+(** Equivalent to {!ChannelMap.find} on cache.text_channels. *)
+val text_channel :
+ t ->
+ Channel_id_t.t ->
+ Channel_t.guild_text option
+
+(** Equivalent to {!ChannelMap.find} on cache.voice_channels. *)
+val voice_channel :
+ t ->
+ Channel_id_t.t ->
+ Channel_t.guild_voice option
+
+(** Equivalent to {!ChannelMap.find} on cache.categories. *)
+val category :
+ t ->
+ Channel_id_t.t ->
+ Channel_t.category option
+
+(** Equivalent to {!ChannelMap.find} on cache.private_channels. *)
+val dm :
+ t ->
+ Channel_id_t.t ->
+ Channel_t.dm option
+
+(** Equivalent to {!ChannelMap.find} on cache.groups. *)
+val group :
+ t ->
+ Channel_id_t.t ->
+ Channel_t.group option
+
+(** Helper method that scans all channel stores and returns a {!Channel.t} holding the channel. *)
+val channel :
+ t ->
+ Channel_id_t.t ->
+ Channel_t.t option \ No newline at end of file