public void ParseChat(ChatEventArgs chatArgs) { if (!chatArgs.Text.StartsWith(Config.CommandTrigger)) return; //get everything except commandTrigger var cmdText = string.Concat(chatArgs.Text.Skip(Config.CommandTrigger.Length)); var args = cmdText.Split(' '); var command = args[0]; //get all but first args = args.Skip(1).ToArray(); //dispatch command with all necessary data if (Commands.ContainsKey(command)) { Commands[command].Action(new CommandArgs { SenderNick = chatArgs.SenderNick, SenderTrip = chatArgs.SenderTrip, SenderPermissionLevel = Config.Permissions .First((permission) => permission.Tripcode == chatArgs.SenderTrip) .Level, Args = args, FullText = cmdText, Bot = this }); } else { Client.SendChat($"Command \"{command}\" not found."); } }
public ChatClient(string url, string nick, string channel) { webSocket = new WebSocket(url); webSocket.OnOpen += (sender, e) => webSocket.Send("{\"cmd\":\"join\",\"channel\":\"" + channel + "\",\"nick\":\"" + nick + "\"}"); webSocket.OnMessage += (sender, args) => { var data = JsonConvert.DeserializeObject<Dictionary<string, object>>(args.Data); if ((data["cmd"] as string == "chat") && (data["nick"] as string != nick)) { System.Diagnostics.Debug.WriteLine(args.Data); var chatArgs = new ChatEventArgs(); chatArgs.Text = data["text"] as string; chatArgs.SenderNick = data["nick"] as string; chatArgs.SenderTrip = data["trip"] as string; //Console.WriteLine($"({data["trip"]}) {data["nick"]}: {data["text"]}"); OnChat?.Invoke(this, chatArgs); } }; webSocket.Connect(); }