Exemple #1
0
        /// <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();
        }
Exemple #2
0
        /// <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()}.");
            }
        }