irc-bot/irc.ml

66 lines
1.4 KiB
OCaml
Raw Normal View History

2008-03-19 16:19:24 -06:00
type nuhost = (string * string * string)
let name = ref "irc.test"
let version = "0.1"
2008-03-18 22:50:23 -06:00
let start_time = Unix.gettimeofday ()
let dbg msg a =
prerr_endline ("[" ^ msg ^ "]");
a
2009-03-03 17:56:07 -07:00
let is_channel str =
2009-03-03 19:48:22 -07:00
if str == "" then
false
else
match str.[0] with
| '#' | '+' | '&' -> true
| _ -> false
2009-03-03 17:56:07 -07:00
let string_map f s =
let l = String.length s in
if l = 0 then
s
else
let r = String.create l in
for i = 0 to l - 1 do
String.unsafe_set r i (f (String.unsafe_get s i))
done;
r
let lowercase_char c =
if (c >= 'A' && c <= '^') then
Char.unsafe_chr(Char.code c + 32)
else
c
let uppercase_char c =
if (c >= 'a' && c <= '~') then
Char.unsafe_chr(Char.code c - 32)
else
c
let uppercase s = string_map uppercase_char s
let lowercase s = string_map lowercase_char s
let truncate s len =
let slen = String.length s in
if len >= slen then
s
else
Str.string_before s (min slen len)
2008-05-09 08:01:11 -06:00
2010-12-10 17:03:24 -07:00
let nuhost_re = Str.regexp "\\(.*\\)!\\(.*\\)@\\(.*\\)"
let nuhost_of_string str =
if Str.string_match nuhost_re str 0 then
(Str.matched_group 1 str,
Str.matched_group 2 str,
Str.matched_group 3 str)
else
raise Not_found
let string_of_nuhost (nick, user, host) =
nick ^ "!" ^ user ^ "@" ^ host
2008-05-09 08:01:11 -06:00
let nick (nick, user, host) = nick
let user (nick, user, host) = user
let host (nick, user, host) = host