text stringlengths 0 601k |
|---|
let string_of_channel = function | ChannelId id -> id | ChannelName name -> name |
let id_of_user session = function | UserId id -> Lwt . return @@ ` Found id | UserName name -> lookupk session users_list ( fun ( x : user_obj ) -> x . name = name ) @@ function | [ ] -> ` User_not_found | [ { id = UserId s ; _ } ] -> ` Found s | [ _ ] -> failwith " Bad result from user id lookup . " | _ :: _ :: _ -> f... |
let id_of_group session = function | GroupId id -> Lwt . return @@ ` Found id | GroupName name -> lookupk session groups_list ( fun ( x : group_obj ) -> x . name = name ) @@ function | [ ] -> ` Channel_not_found | [ { id = GroupId s ; _ } ] -> ` Found s | [ _ ] -> failwith " Bad result from group id lookup . " | _ :: _... |
let id_of_chat session = function | Channel c -> id_of_channel session c | Im i -> Lwt . return @@ ` Found i | User u -> id_of_user session u | Group g -> id_of_group session g |
let name_of_group = function | GroupId _ -> failwith " Need to specify a name " | GroupName name -> name |
let string_of_bool = function | true -> " 1 " | false -> " 0 " |
let string_of_criterion = function | Score -> " score " | Timestamp -> " timestamp " |
let string_of_direction = function | Ascending -> " asc " | Descending -> " desc " |
let string_of_presence = function | Auto -> " auto " | Away -> " away " |
let start_session ( ? base_url = default_base_url ) token = { base_url ; token ; } |
let token_of_string token = start_session token |
let utf8_codepoints text = let explode s = let rec exp i l = if i < 0 then l else exp ( i - 1 ) ( Char . code s . [ i ] :: l ) in exp ( String . length s - 1 ) [ ] in let rec codepoints = function | [ ] -> 0 | x :: xs when x < 0x7F -> 1 + codepoints xs | x :: _ :: xs when x >= 0xC0 && x <= 0xDF -> 1 + codepoints xs | x... |
let topic_of_string text = if utf8_codepoints text <= 250 then Some text else None |
let topic_of_string_exn text = match topic_of_string text with | Some t -> t | None -> failwith " Too long " |
let channel_of_string s = if s . [ 0 ] = ' C ' then ChannelId s else ChannelName s |
let user_of_string s = if s . [ 0 ] = ' U ' then UserId s else UserName s |
let group_of_string s = if s . [ 0 ] = ' G ' then GroupId s else GroupName s |
let conversation_of_string s = if s . [ 0 ] = ' D ' then s else failwith " Not an IM channel " |
let translate_parsing_error = function | Result . Error a -> ` ParseFailure a | Result . Ok a -> ` Success a |
let api_test ? base_url ? foo ? error ( ) = unauthed_endpoint ~ base_url " api . test " |> optionally_add " foo " foo |> optionally_add " error " error |> query >|= function | ` Json_response x -> ` Success x | # api_error as res -> res | _ -> ` Unknown_error |
let auth_test session = endpoint " auth . test " session |> query >|= function | ` Json_response d -> d |> authed_obj_of_yojson |> translate_parsing_error | # parsed_auth_error as res -> res | _ -> ` Unknown_error |
let ( ) |-> m f = match % lwt m with | ` Channel_not_found | # parsed_auth_error as e -> Lwt . return e | ` User_not_found -> Lwt . return ` Unknown_error | ` Found v -> f v |
let ( ) |+> m f = match % lwt m with | ` Channel_not_found -> Lwt . return ` Unknown_error | ` User_not_found | # parsed_auth_error as e -> Lwt . return e | ` Found v -> f v |
let channels_archive session channel = id_of_channel session channel |-> fun channel_id -> endpoint " channels . archive " session |> definitely_add " channel " channel_id |> query >|= function | ` Json_response ( ` Assoc [ ] ) -> ` Success | # parsed_auth_error | # channel_error | # bot_error | # already_archived_erro... |
let channels_create session name = endpoint " channels . create " session |> definitely_add " name " name |> query >|= function | ` Json_response ( ` Assoc [ ( " channel " , d ) ] ) -> d |> channel_obj_of_yojson |> translate_parsing_error | # parsed_auth_error | # bot_error | # name_error | ` User_is_restricted as res ... |
let channels_history session ? latest ? oldest ? count ? inclusive channel = id_of_channel session channel |-> fun channel_id -> endpoint " channels . history " session |> definitely_add " channel " channel_id |> optionally_add " latest " @@ maybe Timestamp . to_string latest |> optionally_add " oldest " @@ maybe Times... |
let channels_info session channel = id_of_channel session channel |-> fun channel_id -> endpoint " channels . info " session |> definitely_add " channel " channel_id |> query >|= function | ` Json_response ( ` Assoc [ ( " channel " , d ) ] ) -> d |> channel_obj_of_yojson |> translate_parsing_error | # parsed_auth_error... |
let channels_invite session channel user = id_of_channel session channel |-> fun channel_id -> id_of_user session user |+> fun user_id -> endpoint " channels . invite " session |> definitely_add " channel " channel_id |> definitely_add " user " user_id |> query >|= function | ` Json_response ( ` Assoc [ ( " channel " ,... |
let channels_join session name = endpoint " channels . join " session |> definitely_add " name " @@ string_of_channel name |> query >|= function | ` Json_response ( ` Assoc [ ( " channel " , d ) ] ) -> d |> channel_obj_of_yojson |> translate_parsing_error | # parsed_auth_error | # channel_error | # name_error | # archi... |
let channels_kick session channel user = id_of_channel session channel |-> fun channel_id -> id_of_user session user |+> fun user_id -> endpoint " channels . kick " session |> definitely_add " channel " channel_id |> definitely_add " user " user_id |> query >|= function | ` Json_response ( ` Assoc [ ] ) -> ` Success | ... |
let channels_leave session channel = id_of_channel session channel |-> fun channel_id -> endpoint " channels . leave " session |> definitely_add " channel " channel_id |> query >|= function | ` Json_response d -> d |> channel_leave_obj_of_yojson |> translate_parsing_error | # parsed_auth_error | # channel_error | # bot... |
let channels_mark session channel ts = id_of_channel session channel |-> fun channel_id -> endpoint " channels . mark " session |> definitely_add " channel " channel_id |> definitely_add " ts " @@ Timestamp . to_string ts |> query >|= function | ` Json_response ( ` Assoc [ ] ) -> ` Success | # parsed_auth_error | # cha... |
let channels_rename session channel name = id_of_channel session channel |-> fun channel_id -> endpoint " channels . rename " session |> definitely_add " channel " channel_id |> definitely_add " name " name |> query >|= function | ` Json_response ( ` Assoc [ ( " channel " , d ) ] ) -> d |> channel_rename_obj_of_yojson ... |
let channels_set_purpose session channel purpose = id_of_channel session channel |-> fun channel_id -> endpoint " channels . setPurpose " session |> definitely_add " channel " channel_id |> definitely_add " purpose " purpose |> query >|= function | ` Json_response ( ` Assoc [ ( " purpose " , ` String d ) ] ) -> ` Succe... |
let channels_set_topic session channel topic = id_of_channel session channel |-> fun channel_id -> endpoint " channels . setTopic " session |> definitely_add " channel " channel_id |> definitely_add " topic " topic |> query >|= function | ` Json_response ( ` Assoc [ ( " topic " , ` String d ) ] ) -> ` Success d | # top... |
let channels_unarchive session channel = id_of_channel session channel |-> fun channel_id -> endpoint " channels . unarchive " session |> definitely_add " channel " channel_id |> query >|= function | ` Json_response ( ` Assoc [ ] ) -> ` Success | # parsed_auth_error | # channel_error | # bot_error | ` Not_archived | ` ... |
let chat_delete session ts chat = id_of_chat session chat |-> fun chat_id -> endpoint " chat . delete " session |> definitely_add " channel " chat_id |> definitely_add " ts " @@ Timestamp . to_string ts |> query >|= function | ` Json_response d -> d |> chat_obj_of_yojson |> translate_parsing_error | # parsed_auth_error... |
let jsonify_attachments attachments = ` List ( List . map ( fun a -> attachment_obj_to_yojson a ) attachments ) |> Yojson . Safe . to_string |
let chat_post_message session chat ? as_user ? link_names ? mrkdwn ? reply_broadcast ? thread_ts ? unfurl_links ? unfurl_media ? username ? parse ? icon_url ? icon_emoji ( ? attachments [ ] ) = text = id_of_chat session chat |-> fun chat_id -> endpoint " chat . postMessage " session |> definitely_add " channel " chat_i... |
let chat_update session ts chat ? as_user ? attachments ? link_names ? parse text = id_of_chat session chat |-> fun chat_id -> endpoint " chat . update " session |> definitely_add " channel " chat_id |> definitely_add " ts " @@ Timestamp . to_string ts |> definitely_add " text " text |> optionally_add " as_user " @@ ma... |
let emoji_list session = endpoint " emoji . list " session |> query >|= function | ` Json_response d -> ( match d |> emoji_list_obj_of_yojson with | Result . Ok x -> ` Success x . emoji | Result . Error x -> ` ParseFailure x ) | # parsed_auth_error as res -> res | _ -> ` Unknown_error |
let files_delete session file = endpoint " files . delete " session |> definitely_add " file " file |> query >|= function | ` Json_response ( ` Assoc [ ] ) -> ` Success | # parsed_auth_error | # bot_error | ` Cant_delete_file | # file_error as res -> res | _ -> ` Unknown_error |
let files_info session ? count ? page file = endpoint " files . info " session |> definitely_add " file " file |> optionally_add " count " @@ maybe string_of_int count |> optionally_add " page " @@ maybe string_of_int page |> query >|= function | ` Json_response d -> d |> files_info_obj_of_yojson |> translate_parsing_e... |
let maybe_with_user session user f = match user with | Some u -> id_of_user session u >>= ( function | ` Found id -> f @@ Some id | _ -> Lwt . return ` User_not_found ) | None -> f None |
let files_list ? user ? ts_from ? ts_to ? types ? count ? page session = maybe_with_user session user @@ fun user_id -> endpoint " files . list " session |> optionally_add " user " user_id |> optionally_add " ts_from " @@ maybe Timestamp . to_string ts_from |> optionally_add " ts_to " @@ maybe Timestamp . to_string ts_... |
let files_upload session ? filetype ? filename ? title ? initial_comment ? channels content = endpoint " files . upload " session |> optionally_add " filetype " filetype |> optionally_add " filename " filename |> optionally_add " title " title |> optionally_add " initial_comment " initial_comment |> optionally_add " ch... |
let groups_archive session group = id_of_group session group |-> fun group_id -> endpoint " groups . archive " session |> definitely_add " channel " group_id |> query >|= function | ` Json_response ( ` Assoc [ ] ) -> ` Success | # parsed_auth_error | # channel_error | # bot_error | # already_archived_error | ` Group_co... |
let groups_close session group = id_of_group session group |-> fun group_id -> endpoint " groups . close " session |> definitely_add " channel " group_id |> query >|= function | ` Json_response d -> d |> chat_close_obj_of_yojson |> translate_parsing_error | # parsed_auth_error | # channel_error as res -> res | _ -> ` U... |
let groups_create session name = endpoint " groups . create " session |> definitely_add " name " @@ name_of_group name |> query >|= function | ` Json_response ( ` Assoc [ ( " group " , d ) ] ) -> d |> group_obj_of_yojson |> translate_parsing_error | # parsed_auth_error | # bot_error | # name_error | # restriction_error... |
let groups_create_child session group = id_of_group session group |-> fun group_id -> endpoint " groups . createChild " session |> definitely_add " channel " group_id |> query >|= function | ` Json_response ( ` Assoc [ ( " group " , d ) ] ) -> d |> group_obj_of_yojson |> translate_parsing_error | # parsed_auth_error | ... |
let groups_history session ? latest ? oldest ? count ? inclusive group = id_of_group session group |-> fun group_id -> endpoint " groups . history " session |> definitely_add " channel " group_id |> optionally_add " latest " @@ maybe Timestamp . to_string latest |> optionally_add " oldest " @@ maybe Timestamp . to_stri... |
let groups_invite session group user = id_of_group session group |-> fun group_id -> id_of_user session user |+> fun user_id -> endpoint " groups . invite " session |> definitely_add " channel " group_id |> definitely_add " user " user_id |> query >|= function | ` Json_response d -> d |> groups_invite_obj_of_yojson |> ... |
let groups_kick session group user = id_of_group session group |-> fun group_id -> id_of_user session user |+> fun user_id -> endpoint " groups . kick " session |> definitely_add " channel " group_id |> definitely_add " user " user_id |> query >|= function | ` Json_response ( ` Assoc [ ] ) -> ` Success | # parsed_auth_... |
let groups_leave session group = id_of_group session group |-> fun group_id -> endpoint " groups . leave " session |> definitely_add " channel " group_id |> query >|= function | ` Json_response ( ` Assoc [ ] ) -> ` Success | # parsed_auth_error | # channel_error | # bot_error | # archive_error | # leave_last_channel_er... |
let groups_mark session group ts = id_of_group session group |-> fun group_id -> endpoint " groups . mark " session |> definitely_add " channel " group_id |> definitely_add " ts " @@ Timestamp . to_string ts |> query >|= function | ` Json_response ( ` Assoc [ ] ) -> ` Success | # parsed_auth_error | # channel_error | #... |
let groups_open session group = id_of_group session group |-> fun group_id -> endpoint " groups . open " session |> definitely_add " channel " group_id |> query >|= function | ` Json_response d -> d |> groups_open_obj_of_yojson |> translate_parsing_error | # parsed_auth_error | # channel_error as res -> res | _ -> ` Un... |
let groups_rename session group name = id_of_group session group |-> fun group_id -> endpoint " groups . rename " session |> definitely_add " channel " group_id |> definitely_add " name " name |> query >|= function | ` Json_response ( ` Assoc [ ( " channel " , d ) ] ) -> d |> groups_rename_obj_of_yojson |> translate_pa... |
let groups_set_purpose session group purpose = id_of_group session group |-> fun group_id -> endpoint " groups . setPurpose " session |> definitely_add " channel " group_id |> definitely_add " purpose " purpose |> query >|= function | ` Json_response ( ` Assoc [ ( " purpose " , ` String d ) ] ) -> ` Success d | # topic... |
let groups_set_topic session group topic = id_of_group session group |-> fun group_id -> endpoint " groups . setTopic " session |> definitely_add " channel " group_id |> definitely_add " topic " topic |> query >|= function | ` Json_response ( ` Assoc [ ( " topic " , ` String d ) ] ) -> ` Success d | # topic_result as r... |
let groups_unarchive session group = id_of_group session group |-> fun group_id -> endpoint " groups . unarchive " session |> definitely_add " channel " group_id |> query >|= function | ` Json_response ( ` Assoc [ ] ) -> ` Success | # parsed_auth_error | # channel_error | # bot_error | ` Not_archived | ` User_is_restri... |
let im_close session channel = endpoint " im . close " session |> definitely_add " channel " channel |> query >|= function | ` Json_response d -> d |> chat_close_obj_of_yojson |> translate_parsing_error | # parsed_auth_error | # channel_error | ` User_does_not_own_channel as res -> res | _ -> ` Unknown_error |
let im_history session ? latest ? oldest ? count ? inclusive channel = endpoint " im . history " session |> definitely_add " channel " channel |> optionally_add " latest " @@ maybe Timestamp . to_string latest |> optionally_add " oldest " @@ maybe Timestamp . to_string oldest |> optionally_add " count " @@ maybe string... |
let im_list session = endpoint " im . list " session |> query >|= function | ` Json_response d -> ( match d |> im_list_obj_of_yojson with | Result . Ok x -> ` Success x . ims | Result . Error x -> ` ParseFailure x ) | # parsed_auth_error as res -> res | _ -> ` Unknown_error |
let im_mark session channel ts = endpoint " im . mark " session |> definitely_add " channel " channel |> definitely_add " ts " @@ Timestamp . to_string ts |> query >|= function | ` Json_response ( ` Assoc [ ] ) -> ` Success | # parsed_auth_error | # channel_error | # not_in_channel_error as res -> res | _ -> ` Unknown_... |
let im_open session user = id_of_user session user |+> fun user_id -> endpoint " im . open " session |> definitely_add " user " user_id |> query >|= function | ` Json_response d -> d |> im_open_obj_of_yojson |> translate_parsing_error | # parsed_auth_error | # user_error | # user_visibility_error as res -> res | _ -> `... |
let oauth_access ? base_url client_id client_secret ? redirect_url code = unauthed_endpoint ~ base_url " oauth . access " |> definitely_add " client_id " client_id |> definitely_add " client_secret " client_secret |> definitely_add " code " code |> optionally_add " redirect_url " redirect_url |> query >|= function | ` ... |
let search method ' session ? sort ? sort_dir ? highlight ? count ? page query_ = endpoint method ' session |> definitely_add " query " @@ query_ |> optionally_add " sort " @@ maybe string_of_criterion sort |> optionally_add " sort_dir " @@ maybe string_of_direction sort_dir |> optionally_add " highlight " @@ maybe str... |
let search_all = search " search . all " |
let search_files = search " search . files " |
let search_messages = search " search . messages " |
let stars_list ? user ? count ? page session = maybe_with_user session user @@ fun user_id -> endpoint " stars . list " session |> optionally_add " user " user_id |> optionally_add " count " @@ maybe string_of_int count |> optionally_add " page " @@ maybe string_of_int page |> query >|= function | ` Json_response d -> ... |
let team_access_logs ? count ? page session = endpoint " team . accessLogs " session |> optionally_add " count " @@ maybe string_of_int count |> optionally_add " page " @@ maybe string_of_int page |> query >|= function | ` Json_response d -> d |> team_access_log_obj_of_yojson |> translate_parsing_error | # parsed_auth_... |
let team_info session = endpoint " team . info " session |> query >|= function | ` Json_response d -> d |> team_obj_of_yojson |> translate_parsing_error | # parsed_auth_error | # bot_error as res -> res | _ -> ` Unknown_error |
let users_get_presence session user = id_of_user session user |+> fun user_id -> endpoint " users . getPresence " session |> definitely_add " user " user_id |> query >|= function | ` Json_response ( ` Assoc [ ( " presence " , ` String d ) ] ) -> ( match d with | " active " -> ` Success Auto | " away " -> ` Success Away... |
let users_info session user = id_of_user session user |+> fun user_id -> endpoint " users . info " session |> definitely_add " user " user_id |> query >|= function | ` Json_response ( ` Assoc [ ( " user " , d ) ] ) -> d |> user_obj_of_yojson |> translate_parsing_error | # parsed_auth_error | # user_error | # user_visib... |
let users_set_active session = endpoint " users . setActive " session |> query >|= function | ` Json_response ( ` Assoc [ ] ) -> ` Success | # bot_error | # parsed_auth_error as res -> res | _ -> ` Unknown_error |
let users_set_presence session presence = endpoint " users . setPresence " session |> definitely_add " presence " @@ string_of_presence presence |> query >|= function | ` Json_response ( ` Assoc [ ] ) -> ` Success | # parsed_auth_error | # presence_error as res -> res | _ -> ` Unknown_error |
let base_url = let doc = " The Slack API base URL " in Cmdliner . Arg . ( value & opt ( some string ) None & info [ " base - url " ] ~ docv " : URL " ~ doc ) |
let token = let doc = " The Slack API access token " in Cmdliner . Arg . ( required & opt ( some string ) None & info [ " t " ; " token " ] ~ docv " : TOKEN " ~ doc ) |
let username = let doc = " Name of the bot in the chat " in Cmdliner . Arg . ( value & opt ( some string ) None & info [ " u " ; " username " ] ~ docv " : USERNAME " ~ doc ) |
let icon_url = let doc = " URL to an image to use as the icon for this message " in Cmdliner . Arg . ( value & opt ( some string ) None & info [ " icon - url " ] ~ docv " : URL " ~ doc ) |
let icon_emoji = let doc = " Emoji to use as the icon for this message . Overrides icon - url " in Cmdliner . Arg . ( value & opt ( some string ) None & info [ " icon - emoji " ] ~ docv " : EMOJI " ~ doc ) |
let channel = let doc = " Name of the channel to post to " in Cmdliner . Arg . ( required & pos 0 ( some string ) None & info [ ] ~ docv " : CHANNEL " ~ doc ) |
let message = let doc = " Message to send " in Cmdliner . Arg . ( required & pos 1 ( some string ) None & info [ ] ~ docv " : MSG " ~ doc ) |
let attachment = let doc = " Attachment text " in Cmdliner . Arg . ( value & opt ( some string ) None & info [ " attachment " ] ~ docv " : MSG " ~ doc ) |
let info = let doc = " Posts messages to Slack " in Cmdliner . Term . info " slack - notify " ~ doc |
let execute base_url token username channel icon_url icon_emoji attachment_text msg = " Your token is " ^ token ^ " , the channel is " ^ channel ^ " and the message is ' " ^ msg ^ " ' . " |> print_endline ; let string_or_bust = function | ` Success _ -> " Message posted " | ` Invalid_auth -> " Invalid token " | ` Chann... |
let execute_t = Cmdliner . Term . ( pure execute $ base_url $ token $ username $ channel $ icon_url $ icon_emoji $ attachment $ message ) |
let ( ) = match Cmdliner . Term . eval ( execute_t , info ) with | ` Error _ -> exit 1 | _ -> exit 0 |
let error file action s = print_string ( " \ nERROR in " ^ file ^ " with " ^ action ^ " : " ^ s ^ " \ n " ) |
let fatal_error file action s = error file action s ; exit ( - 1 ) |
let wrap file e interpret msg = try Some ( interpret e ) with | Errors . Error s -> error file msg s ; None | exc -> fatal_error file msg ( " Exception : " ^ ( Printexc . to_string exc ) ) |
let i0 ( file , e ) = wrap file e ( fun x -> Interp_0 . string_of_value ( Interp_0 . interpret_top_level x ) ) " Interpreter 0 " |
let i1 ( file , e ) = wrap file e ( fun x -> Interp_1 . string_of_value ( Interp_1 . interpret x ) ) " Interpreter 1 " |
let i2 ( file , e ) = wrap file e ( fun x -> Interp_2 . string_of_value ( fst ( Interp_2 . interpret x ) ) ) " Interpreter 2 " |
let i3 ( file , e ) = wrap file e ( fun x -> Interp_3 . string_of_value ( Interp_3 . interpret x ) ) " Interpreter 3 " |
let i4 ( file , e ) = wrap file e ( fun x -> Jargon . string_of_value ( Jargon . interpret x ) ) " Jargon VM " |
let i4x86 ( file , e ) = let _ = Jargon_to_x86 . emit_x86 e in None |
let i2cc ( file , e ) = let _ = print_string ( Interp_2 . string_of_code ( Interp_2 . compile e ) ) in None |
let i3cc ( file , e ) = let _ = print_string ( Interp_3 . string_of_code ( Interp_3 . compile e ) ) in None |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.