Add Evaluate module.
The Evaluate module contains the logic for cheesebot actions.
This commit is contained in:
parent
5b790d3f09
commit
764581f505
20
ocaml/evaluate.ml
Normal file
20
ocaml/evaluate.ml
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
open Str
|
||||||
|
|
||||||
|
|
||||||
|
let is_url url =
|
||||||
|
let regexp = regexp "\\(https?\\://\\)?www\\..+\\..+" in
|
||||||
|
string_match regexp url 0
|
||||||
|
|
||||||
|
|
||||||
|
let is_youtube_url url =
|
||||||
|
let regexp = regexp "\\(https?\\://\\)?\\(www\\.\\)?\\(youtube\\.com\\)\\|\\(youtu\\.be\\)/.+" in
|
||||||
|
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_url str ->
|
||||||
|
SimpleHttp.get_http_title (SimpleHttp.get_body str)
|
||||||
|
| _ -> None
|
|
@ -1,38 +1,14 @@
|
||||||
open Str
|
open Str
|
||||||
|
|
||||||
|
|
||||||
let is_url url =
|
|
||||||
let regexp = regexp "\\(https?\\://\\)?www\\..+\\..+" in
|
|
||||||
string_match regexp url 0
|
|
||||||
|
|
||||||
|
|
||||||
let is_youtube_url url =
|
|
||||||
let regexp = regexp "\\(https?\\://\\)?\\(www\\.\\)?\\(youtube\\.com\\)\\|\\(youtu\\.be\\)/.+" in
|
|
||||||
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 ->
|
|
||||||
(
|
|
||||||
let title = SimpleHttp.get_http_title (SimpleHttp.get_body str) in
|
|
||||||
match title with
|
|
||||||
| Some s -> s
|
|
||||||
| None -> ""
|
|
||||||
)
|
|
||||||
| str when is_url str -> str
|
|
||||||
| _ -> ""
|
|
||||||
|
|
||||||
|
|
||||||
let () =
|
let () =
|
||||||
try
|
try
|
||||||
while true do
|
while true do
|
||||||
print_string "> ";
|
print_string "> ";
|
||||||
let line = read_line () in
|
let line = read_line () in
|
||||||
let answer = evaluate line in
|
match Evaluate.evaluate line with
|
||||||
print_endline answer
|
| Some answer -> print_endline answer
|
||||||
|
| _ -> ()
|
||||||
done
|
done
|
||||||
with
|
with
|
||||||
End_of_file -> print_endline "Bye!";;
|
End_of_file -> print_endline "Bye!";;
|
||||||
|
|
Loading…
Reference in a new issue