support "JOIN 0" command

This commit is contained in:
tali 2024-01-24 12:47:20 -05:00
parent 130f79163d
commit 7d8807318b
1 changed files with 19 additions and 2 deletions

View File

@ -329,7 +329,6 @@ let join t user chan =
let on_msg_join t name =
let* me = require_registered t in
(* TODO: keys parameter *)
(* TODO: "0" parameter means part from all channels *)
let* chan =
try
match name_type name with
@ -392,6 +391,14 @@ let on_msg_part t name reason =
with Not_found ->
Error (notonchannel name)
let on_msg_join_0 t =
(* "JOIN 0" actually means part from all joined channels *)
let* me = require_registered t in
List.iter
(leave t me ~why:(`part None))
(User.channels me);
Ok ()
(* welcome and quit *)
@ -523,6 +530,7 @@ let dispatch t = function
| "PRIVMSG", ([_] | _ :: "" :: _) -> Error notexttosend
| "PRIVMSG", tgt :: msg :: _ -> on_msg_privmsg t tgt msg
| "JOIN", tgt :: _ when tgt <> "" -> on_msg_join t tgt
| "JOIN 0", _ -> (* hack; see split_command_params *) on_msg_join_0 t
| "NAMES", tgt :: _ when tgt <> "" -> on_msg_names t tgt
| "TOPIC", tgt :: args when tgt <> "" -> on_msg_topic t tgt args
| "PART", tgt :: reason when tgt <> "" -> on_msg_part t tgt reason
@ -534,7 +542,16 @@ let dispatch t = function
let split_command_params cmd params =
match cmd, params with
| ("PRIVMSG" | "JOIN" | "NAMES" | "PART"), tgts :: rest
| "JOIN", "0" :: _ ->
["JOIN 0", []]
| "JOIN", tgts :: rest
when String.contains tgts ',' ->
(* TODO: split <keys> argument as well *)
String.split_on_char ',' tgts |>
List.map (fun tgt -> "JOIN", tgt :: rest)
| ("PRIVMSG" | "NAMES" | "PART"), tgts :: rest
when String.contains tgts ',' ->
(* TODO: "JOIN" should be handled specially *)
String.split_on_char ',' tgts |>