mirror of https://github.com/nealey/irc-bot
Start at channels
This commit is contained in:
parent
167105c661
commit
68428d8347
27
channel.ml
27
channel.ml
|
@ -1,14 +1,18 @@
|
||||||
type t = {name: string}
|
module String_map =
|
||||||
|
Map.Make (struct
|
||||||
|
type t = string
|
||||||
|
let compare = compare
|
||||||
|
end)
|
||||||
|
|
||||||
let modes = "t"
|
type client = Iobuf.t * Irc.nuhost
|
||||||
|
|
||||||
let by_name = Hashtbl.create 25
|
type t = {name: string;
|
||||||
|
modes: string ref;
|
||||||
|
clients: client String_map.t}
|
||||||
|
|
||||||
let lookup name =
|
let modes = "aimnqpsrtklb"
|
||||||
Hashtbl.find by_name name
|
|
||||||
|
|
||||||
let create name =
|
let channels = String_map.empty
|
||||||
{name = name}
|
|
||||||
|
|
||||||
let is_channel_name name =
|
let is_channel_name name =
|
||||||
match name.[0] with
|
match name.[0] with
|
||||||
|
@ -16,4 +20,11 @@ let is_channel_name name =
|
||||||
true
|
true
|
||||||
| _ ->
|
| _ ->
|
||||||
false
|
false
|
||||||
|
|
||||||
|
let has_mode chan mode =
|
||||||
|
String.contains !(chan.modes) mode
|
||||||
|
|
||||||
|
let handle_command iobuf (nick, username, hostname) cmd =
|
||||||
|
match (Command.as_tuple cmd) with
|
||||||
|
| _ ->
|
||||||
|
()
|
||||||
|
|
|
@ -1,8 +1,12 @@
|
||||||
type t
|
type t
|
||||||
|
|
||||||
|
(* Channels handle:
|
||||||
|
|
||||||
|
MODE, JOIN, PART, TOPIC, NAMES, LIST, INVITE, KICK, PRIVMSG, NOTICE
|
||||||
|
*)
|
||||||
|
|
||||||
val modes : string
|
val modes : string
|
||||||
|
|
||||||
val lookup : string -> t
|
val handle_command : Iobuf.t -> Irc.nuhost -> Command.t -> unit
|
||||||
val create : string -> t
|
|
||||||
val is_channel_name : string -> bool
|
val is_channel_name : string -> bool
|
||||||
|
|
||||||
|
|
|
@ -26,8 +26,8 @@ let error num args text =
|
||||||
let uhost cli =
|
let uhost cli =
|
||||||
(!(cli.nick) ^ "!" ^ cli.username ^ "@" ^ (Iobuf.addr cli.iobuf))
|
(!(cli.nick) ^ "!" ^ cli.username ^ "@" ^ (Iobuf.addr cli.iobuf))
|
||||||
|
|
||||||
let close cli =
|
let kill cli message =
|
||||||
Iobuf.close cli.iobuf
|
Iobuf.close cli.iobuf ("Killed: " ^ message)
|
||||||
|
|
||||||
let write_command cli cmd =
|
let write_command cli cmd =
|
||||||
Iobuf.write cli.iobuf cmd
|
Iobuf.write cli.iobuf cmd
|
||||||
|
|
2
irc.ml
2
irc.ml
|
@ -1,3 +1,5 @@
|
||||||
|
type nuhost = (string * string * string)
|
||||||
|
|
||||||
let name = ref "irc.test"
|
let name = ref "irc.test"
|
||||||
let version = "0.1"
|
let version = "0.1"
|
||||||
let start_time = Unix.gettimeofday ()
|
let start_time = Unix.gettimeofday ()
|
||||||
|
|
3
irc.mli
3
irc.mli
|
@ -1,3 +1,6 @@
|
||||||
|
(** (Nickname, username, hostname) tuple *)
|
||||||
|
type nuhost = (string * string * string)
|
||||||
|
|
||||||
val name : string ref
|
val name : string ref
|
||||||
val version : string
|
val version : string
|
||||||
val start_time : float
|
val start_time : float
|
||||||
|
|
2
tests.ml
2
tests.ml
|
@ -340,7 +340,7 @@ let do_login nick =
|
||||||
Recv (":testserver.test 001 " ^ nick ^ " :Welcome to IRC.\r\n");
|
Recv (":testserver.test 001 " ^ nick ^ " :Welcome to IRC.\r\n");
|
||||||
Recv (":testserver.test 002 " ^ nick ^ " :I am testserver.test Running version " ^ Irc.version ^ "\r\n");
|
Recv (":testserver.test 002 " ^ nick ^ " :I am testserver.test Running version " ^ Irc.version ^ "\r\n");
|
||||||
Recv (":testserver.test 003 " ^ nick ^ " :This server was created " ^ (string_of_float Irc.start_time) ^ "\r\n");
|
Recv (":testserver.test 003 " ^ nick ^ " :This server was created " ^ (string_of_float Irc.start_time) ^ "\r\n");
|
||||||
Recv (":testserver.test 004 " ^ nick ^ " :testserver.test 0.1 l t\r\n");
|
Recv (":testserver.test 004 " ^ nick ^ " :testserver.test 0.1 l aimnqpsrtklb\r\n");
|
||||||
]
|
]
|
||||||
|
|
||||||
let regression_tests =
|
let regression_tests =
|
||||||
|
|
Loading…
Reference in New Issue