Beispiel #1
0
 /// <summary>
 /// Converts an action to a string for the settings file
 /// </summary>
 /// <param name="action">The action for the settings string</param>
 /// <returns>The specific action</returns>
 public static string ActionToString(CommandResponse.ResponseAction action)
 {
     var message = "";
     switch (action)
     {
         case (CommandResponse.ResponseAction.None):
             message = "none";
             break;
         case (CommandResponse.ResponseAction.Ban):
             message = "ban";
             break;
         case (CommandResponse.ResponseAction.Purge):
             message = "purge";
             break;
         case (CommandResponse.ResponseAction.Timeout):
             message = "timeout";
             break;
         case (CommandResponse.ResponseAction.Warning):
             message = "warning";
             break;
     }
     return message;
 }
Beispiel #2
0
        /// <summary>
        /// Checks for censored phrases
        /// </summary>
        /// <param name="user">The sender's username</param>
        /// <param name="message">The message</param>
        /// <param name="isMod">Is the sender a moderator</param>
        /// <returns>The appropriate command response</returns>
        private static CommandResponse CensorCheck(string user, string message, bool isMod)
        {
            //Mods do not get censored
            if (isMod)
            {
                return(null);
            }

            //Sort through the censored keys
            foreach (var key in Censored.Keys)
            {
                //Determine whether the message contains the phrase
                if (!message.ToUpper().Trim().Contains(key.ToUpper().Trim()))
                {
                    continue;
                }

                //Sort by response type
                if (Censored[key].Action == CommandResponse.ResponseAction.Warning)
                {
                    if (Warned.ContainsKey(user))
                    {
                        //If the user has had only 1 warning
                        if (Warned[user] == 1)
                        {
                            //Increment warning number
                            Warned[user]++;

                            //Send the timeout response
                            if (string.IsNullOrEmpty(Censored[key].Message))
                            {
                                var responseMessage = string.Format(LastWarning, user);
                                var response        = new CommandResponse(responseMessage, CommandResponse.ResponseAction.Timeout);
                                return(response);
                            }
                            return(Censored[key]);
                        }

                        //If the user has had 2 warnings
                        if (Warned[user] == 2)
                        {
                            //Reset warning number
                            Warned.Remove(user);

                            //Send the ban
                            if (string.IsNullOrEmpty(Censored[key].Message))
                            {
                                var responseMessage = string.Format(BanWarning, user);
                                var response        = new CommandResponse(responseMessage, CommandResponse.ResponseAction.Ban);
                                return(response);
                            }
                            return(Censored[key]);
                        }
                    }
                    else
                    {
                        //Add to warning list
                        Warned.Add(user, 1);

                        if (string.IsNullOrEmpty(Censored[key].Message))
                        {
                            //Send the warning response
                            var responseMessage = string.Format(FirstWarning, user);
                            var response        = new CommandResponse(responseMessage, CommandResponse.ResponseAction.Purge);
                            return(response);
                        }
                        return(Censored[key]);
                    }
                }
                else if (Censored[key].Action == CommandResponse.ResponseAction.Ban)
                {
                    //Send the ban message if not defined
                    if (string.IsNullOrEmpty(Censored[key].Message))
                    {
                        var responseMessage = string.Format(_banMessages[Randomizer.Next(0, _banMessages.Length - 1)],
                                                            user);
                        var response = new CommandResponse(responseMessage, Censored[key].Action);
                        return(response);
                    }
                    return(Censored[key]);
                }
                else if (Censored[key].Action == CommandResponse.ResponseAction.Purge)
                {
                    if (string.IsNullOrEmpty(Censored[key].Message))
                    {
                        //Send the purge message
                        var responseMessage =
                            string.Format(_purgeMessages[Randomizer.Next(0, _purgeMessages.Length - 1)], user);
                        var response = new CommandResponse(responseMessage, Censored[key].Action);
                        return(response);
                    }
                    return(Censored[key]);
                }
                else if (Censored[key].Action == CommandResponse.ResponseAction.Timeout)
                {
                    if (string.IsNullOrEmpty(Censored[key].Message))
                    {
                        //Timeout message
                        var responseMessage =
                            string.Format(_timeoutMessages[Randomizer.Next(0, _timeoutMessages.Length - 1)], user);
                        var response = new CommandResponse(responseMessage, Censored[key].Action);
                        return(response);
                    }
                    return(Censored[key]);
                }
            }

            //No censored words were detected
            return(null);
        }
Beispiel #3
0
        /// <summary>
        /// Checks for censored phrases
        /// </summary>
        /// <param name="user">The sender's username</param>
        /// <param name="message">The message</param>
        /// <param name="isMod">Is the sender a moderator</param>
        /// <returns>The appropriate command response</returns>
        private static CommandResponse CensorCheck(string user, string message, bool isMod)
        {
            //Mods do not get censored
            if (isMod) return null;

            //Sort through the censored keys
            foreach (var key in Censored.Keys)
            {
                //Determine whether the message contains the phrase
                if (!message.ToUpper().Trim().Contains(key.ToUpper().Trim())) continue;

                //Sort by response type
                if (Censored[key].Action == CommandResponse.ResponseAction.Warning)
                {
                    if (Warned.ContainsKey(user))
                    {
                        //If the user has had only 1 warning
                        if (Warned[user] == 1)
                        {
                            //Increment warning number
                            Warned[user]++;

                            //Send the timeout response
                            if (string.IsNullOrEmpty(Censored[key].Message))
                            {
                                var responseMessage = string.Format(LastWarning, user);
                                var response = new CommandResponse(responseMessage, CommandResponse.ResponseAction.Timeout);
                                return response;
                            }
                            return Censored[key];
                        }

                        //If the user has had 2 warnings
                        if (Warned[user] == 2)
                        {
                            //Reset warning number
                            Warned.Remove(user);

                            //Send the ban
                            if (string.IsNullOrEmpty(Censored[key].Message))
                            {
                                var responseMessage = string.Format(BanWarning, user);
                                var response = new CommandResponse(responseMessage, CommandResponse.ResponseAction.Ban);
                                return response;
                            }
                            return Censored[key];
                        }
                    }
                    else
                    {
                        //Add to warning list
                        Warned.Add(user, 1);

                        if (string.IsNullOrEmpty(Censored[key].Message))
                        {
                            //Send the warning response
                            var responseMessage = string.Format(FirstWarning, user);
                            var response = new CommandResponse(responseMessage, CommandResponse.ResponseAction.Purge);
                            return response;
                        }
                        return Censored[key];
                    }
                }
                else if (Censored[key].Action == CommandResponse.ResponseAction.Ban)
                {
                    //Send the ban message if not defined
                    if (string.IsNullOrEmpty(Censored[key].Message))
                    {
                        var responseMessage = string.Format(_banMessages[Randomizer.Next(0, _banMessages.Length - 1)],
                                                            user);
                        var response = new CommandResponse(responseMessage, Censored[key].Action);
                        return response;
                    }
                    return Censored[key];
                }
                else if(Censored[key].Action == CommandResponse.ResponseAction.Purge)
                {
                    if (string.IsNullOrEmpty(Censored[key].Message))
                    {
                        //Send the purge message
                        var responseMessage =
                            string.Format(_purgeMessages[Randomizer.Next(0, _purgeMessages.Length - 1)], user);
                        var response = new CommandResponse(responseMessage, Censored[key].Action);
                        return response;
                    }
                    return Censored[key];
                }
                else if(Censored[key].Action == CommandResponse.ResponseAction.Timeout)
                {
                    if (string.IsNullOrEmpty(Censored[key].Message))
                    {
                        //Timeout message
                        var responseMessage =
                            string.Format(_timeoutMessages[Randomizer.Next(0, _timeoutMessages.Length - 1)], user);
                        var response = new CommandResponse(responseMessage, Censored[key].Action);
                        return response;
                    }
                    return Censored[key];
                }
            }

            //No censored words were detected
            return null;
        }
Beispiel #4
0
        /// <summary>
        /// Responds to the response from the commands/censor
        /// </summary>
        /// <param name="response">The response to respond as</param>
        /// <param name="user">Name of the response user</param>
        private void Respond(CommandResponse response, string user)
        {
            //Check to see if there was any response
            if (response == null) return;

            //Check for response message
            if(!string.IsNullOrWhiteSpace(response.Message))
            {
                //Sends the required message
                SendMessage(response.Message);
            }

            //Create an action response only if you have moderator
            if(response.Action != CommandResponse.ResponseAction.None)
            {
                //Make sure it has the permissions
                if (Commands.RequiresMod && !_hasMod) return;

                //Message containing action info
                var message = "";
                //Contains event name for event handling
                var eventName = "";
                switch(response.Action)
                {
                    case(CommandResponse.ResponseAction.Timeout):
                        eventName = "Timed out " + user;
                        message = "/timeout " + user;
                        break;
                    case (CommandResponse.ResponseAction.Purge):
                        eventName = "Purged " + user;
                        message = "/timeout " + user + " 1";
                        break;
                    case (CommandResponse.ResponseAction.Ban):
                        eventName = "Banned " + user;
                        message = "/ban " + user;
                        break;
                }

                //Send the response message
                if(!string.IsNullOrWhiteSpace(message))
                {
                    SendMessage(message);
                    HandleEvent(eventName, EventListItem.DefaultColor);
                }
            }
        }