aboutsummaryrefslogtreecommitdiff
path: root/lib/models/guild/guild.ml
blob: b1e8bfe73272a5bdd35770068393ef207e935585 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
open Core
open Async

include Guild_t
include Impl.Guild(Guild_t)

let get_member ~(id:User_id_t.t) guild =
    match List.find ~f:(fun m -> m.user.id = id) guild.members with
    | Some m -> Deferred.Or_error.return m
    | None ->
        let `User_id id = id in
        Http.get_member (get_id guild) id

let get_channel ~(id:Channel_id_t.t) guild =
    let `Channel_id id = id in
    match List.find ~f:(fun c -> Channel_t.get_id c = id) guild.channels with
    | Some c -> Deferred.Or_error.return c
    | None -> Http.get_channel id

(* TODO add HTTP fallback *)
let get_role ~(id:Role_id.t) guild =
    List.find ~f:(fun r -> r.id = id) guild.roles