ff69981a5c
Use ocamlbuild command to build cheesebot.
51 lines
1.2 KiB
OCaml
51 lines
1.2 KiB
OCaml
open Str
|
|
open String
|
|
open Printf
|
|
|
|
(*open SimpleHttp*)
|
|
|
|
open Ssl
|
|
open Http_client.Convenience
|
|
open Https_client
|
|
open Nethtml
|
|
open Netchannels;;
|
|
|
|
Ssl.init();
|
|
Http_client.Convenience.configure_pipeline
|
|
(fun p ->
|
|
let ctx = Ssl.create_context Ssl.TLSv1 Ssl.Client_context in
|
|
let tct = Https_client.https_transport_channel_type ctx in
|
|
p # configure_transport Http_client.https_cb_id tct
|
|
)
|
|
|
|
|
|
let is_url url =
|
|
let regexp = Str.regexp "\\(https?\\://\\)?www\\..+\\..+" in
|
|
Str.string_match regexp url 0
|
|
|
|
|
|
let is_youtube_url url =
|
|
let regexp = Str.regexp "\\(https?\\://\\)?\\(www\\.\\)?\\(youtube\\.com\\)\\|\\(youtu\\.be\\)/.+" in
|
|
Str.string_match regexp url 0
|
|
|
|
|
|
(* Maybe have a list of functions and
|
|
* iter on all the items in the list *)
|
|
let evaluate str =
|
|
match str with
|
|
| str when is_youtube_url str -> SimpleHttp.get_http_title (SimpleHttp.get_body str); str
|
|
| str when is_url str -> SimpleHttp.get_http_title (SimpleHttp.get_body str); str
|
|
| _ -> str
|
|
|
|
|
|
let () =
|
|
try
|
|
while true do
|
|
print_string "> ";
|
|
let line = read_line () in
|
|
let answer = evaluate line in
|
|
print_endline answer
|
|
done
|
|
with
|
|
End_of_file -> print_endline "Bye!";;
|