From 035af34a3179f814f9ec64e1855085176cf8a358 Mon Sep 17 00:00:00 2001 From: "Tristan B. Velloza Kildaire" Date: Sat, 5 Nov 2022 20:42:31 +0200 Subject: [PATCH] - Implemented `leaveChannel(string[])` and `leaveChannel(string)` --- source/birchwood/client.d | 64 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/source/birchwood/client.d b/source/birchwood/client.d index 00963c7..2e038f0 100644 --- a/source/birchwood/client.d +++ b/source/birchwood/client.d @@ -28,7 +28,8 @@ public class BirchwoodException : Exception { INVALID_CONN_INFO, ALREADY_CONNECTED, - CONNECT_ERROR + CONNECT_ERROR, + EMPTY_PARAMS } private ErrorType errType; @@ -275,6 +276,67 @@ public final class Client : Thread sendMessage("JOIN "~channel); } + /** + * Parts from a list of channel(s) in one go + * + * Params: + * channels = the list of channels to part from + * Throws: + * BirchwoodException if the list is empty + */ + public void leaveChannel(string[] channels) + { + // TODO: Add check for valid and non-empty channel names + + /* If single channel */ + if(channels.length == 1) + { + /* Leave the channel */ + leaveChannel(channels[0]); + } + /* If multiple channels */ + else if(channels.length > 1) + { + string channelLine = channels[0]; + for(ulong i = 1; i < channels.length; i++) + { + string currentChannel = channels[i]; + + if(i == channels.length-1) + { + channelLine~=currentChannel; + } + else + { + channelLine~=currentChannel~","; + } + } + + /* Leave multiple channels */ + sendMessage("PART "~channelLine); + } + /* If no channels provided at all (error) */ + else + { + throw new BirchwoodException(BirchwoodException.ErrorType.EMPTY_PARAMS); + } + + } + + /** + * Part from a single channel + * + * Params: + * channel = the channel to leave + */ + public void leaveChannel(string channel) + { + // TODO: Add check for valid and non-empty channel names + + /* Leave the channel */ + sendMessage("PART "~channel); + } + /** * Sends a direct message to the intended recipients *