/// <summary> /// Called when the server tells us someone has been muted. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> /// <exception cref="NotImplementedException"></exception> public static void OnMuteEndTimeReceived(object sender, MuteEndTimeEventArgs e) { if (!OnlineManager.OnlineUsers.ContainsKey(e.UserId)) { return; } OnlineManager.OnlineUsers[e.UserId].OnlineUser.MuteEndTime = e.EndTime; // Purge the chat of a user's messages. lock (Dialog.ChannelMessageContainers) { foreach (var container in Dialog.ChannelMessageContainers.Values) { container.PurgeUserMessages(e.UserId); } } // If the mute is for the current user, then display a message in chat. if (e.UserId != OnlineManager.Self.OnlineUser.Id || Dialog.ActiveChannel == null) { return; } MuteTimeLeft = e.EndTime - (long)TimeHelper.GetUnixTimestampMilliseconds(); if (TimeHelper.GetUnixTimestampMilliseconds() > e.EndTime) { return; } QuaverBot.SendMutedMessage(); }
/// <summary> /// Sends a chat message to the server. /// </summary> public static void SendMessage(ChatChannel chan, ChatMessage message) { // Add the message to the chat channel. // Find the channel the message is for. var channel = JoinedChatChannels.Find(x => x.Name == chan.Name); // Make sure the sender is actual valid. message.Sender = OnlineManager.Self; message.Time = TimeHelper.GetUnixTimestampMilliseconds(); // Handle forward slash commands (client sided) and not send to the server. if (message.Message.StartsWith("/")) { HandleClientSideCommands(message); return; } // Check if the sender is muted. if (OnlineManager.Self.IsMuted) { QuaverBot.SendMutedMessage(); return; } // Add the message to the appropriate channel. channel.Messages.Add(message); // Add the message to the container. Dialog.ChannelMessageContainers[channel].AddMessage(channel, message); // Send the message to the server. OnlineManager.Client.SendMessage(chan.Name, message.Message); // If the channel is private, check if the message receiver is muted. if (!chan.IsPrivate) { return; } // Get the user if they're online. var receiver = OnlineManager.OnlineUsers.Values.ToList().Find(x => x.OnlineUser.Username == chan.Name); // Don't bother sending the message if they're not online. if (receiver == null) { QuaverBot.SendMessage(chan, "This user is not online."); return; } // If the user is muted, then let the user know this. if (receiver.IsMuted) { QuaverBot.SendMessage(chan, $"Oops! {receiver.OnlineUser.Username} is muted for another: {receiver.GetMuteTimeLeftString()}."); } }
/// <summary> /// Handles all client sided commands (Messages that start with "/") /// </summary> /// <param name="message"></param> private static void HandleClientSideCommands(ChatMessage message) { // The args for the message. var args = message.Message.Split(' '); var command = ""; var commandSplit = args[0].Split('/'); if (commandSplit.Length > 1) { command = commandSplit[1]; } if (string.IsNullOrEmpty(command)) { return; } switch (command) { // Send help commands. case "help": QuaverBot.ExecuteHelpCommand(); break; // Get online users. case "online": QuaverBot.ExecuteOnlineCommand(); break; // open up a private chat for a user case "chat": QuaverBot.ExecuteChatCommand(args); break; // User wants to join a chat cnalle. case "join": QuaverBot.ExecuteJoinCommand(args.ToList()); break; // Spectates a user case "spectate": QuaverBot.ExecuteSpectateCommand(args.ToList()); break; case "stopspectating": QuaverBot.ExecuteStopSpectatingCommand(); break; } }