Beispiel #1
0
 public override void Execute(IrcMessage message, string args)
 {
     message.ReplyChannel(args);
 }
Beispiel #2
0
        /// <summary>
        /// Handles an incoming message, and invokes any matching commands
        /// </summary>
        /// <param name="message">The message to check for commands</param>
        public static void HandleMessage(IrcMessage message)
        {
            //ignore messages from channel
            if (!State.ParseChannel.Value && message.IsChannelMessage) return;

            bool had_prefix = false;
            if (!HandleCommand(message, out had_prefix))
            {
                try
                {
                    // first check for sub notify
                    if (message.From.ToLower() == State.NewSubNotifyUser.Value.ToLower())
                    {
                        if (message.Text.ToString().EndsWith("just subscribed!"))
                        {
                            NewSubCommand.AnnounceNewSubscription(message);
                        }
                    }
                    //ignore commands from reserved names
                    if(message.From == "jtv" || message.From == "jtvnotifier" || message.From.StartsWith("jtv!")) return;

                    //not a command, test for bad words
                    bool isspam = ContainsBadWord(message.Text);
                    bool purgetrigger = ContainsFilteredText(message.Text);
                    if (isspam)
                    {
                        Program.Log("This input matches spamfilter");
                    }
                    if (State.AntiSpamLevel.Value > 0 && GetPrivilegeLevel(message.From) < PrivilegeLevel.Voiced && ( isspam || purgetrigger ))
                    {
                        if (State.AntiSpamLevel.Value == 1)
                        {
                            JTV.Purge(message.From, 30);

                            // Only report if spam link sent
                            if (isspam)
                            {
                                message.ReplyChannel("Please don't use URLs in chat, " + message.From);
                            }

                            Program.Log("Message from " + message.From + " was filtered");
                        }

                    }

                    // Not a bad word, let's check for nuke text
                    if (ContainsNukePhrase(message.Text) && GetPrivilegeLevel(message.From) < PrivilegeLevel.Voiced)
                    {
                        // Determine the nuke time, in minutes
                        int time = State.NukeTime.Value;
                        if (time == 0)
                        {
                            time = 1;
                        }
                        else
                        {
                            time = time * 60;
                        }

                        // nuke this person
                        JTV.Purge(message.From, time);
                        Program.Log("Message from " + message.From + " was nuked");
                    }

                    //process for AI chatterbot
                    string name = State.JtvSettings.Value.Nickname;
                    //remove characters
                    string input = message.Text.Replace(",", "").Replace(".", "").Replace("!", "").Replace("?", "").Trim();
                    int needle = input.IndexOf(name, StringComparison.OrdinalIgnoreCase);
                    if (needle >= 0 && !had_prefix)
                    {
                        try
                        {
                            //rewrite around name
                            string first = input.Substring(0, needle).Trim();
                            string second = input.Substring(needle + name.Length).Trim();
                            bool insert_you = false;
                            if (first.ToLower().EndsWith(" is"))
                            {
                                first = first.Substring(0, first.Length - 2) + "are";
                                insert_you = true;
                            }
                            else if (second.ToLower().StartsWith("is "))
                            {
                                second = "are" + second.Substring(2);
                                insert_you = true;
                            }
                            string rewritten = insert_you ? first + " you " + second : first + " " + second;

                            //trigger alice
                            Program.Log("ALICE input: " + rewritten);
                            string result = Alice.Process(message.From, rewritten, message.Level);
                            if (result.Length > 0 && result.Length < 100 && !result.StartsWith("<br",true,System.Globalization.CultureInfo.CurrentCulture))
                            {
                                message.ReplyAuto(result);
                            }
                            else
                            {
                                Program.Log("Suppressed ALICE output: " + result);
                            }
                        }
                        catch (Exception ex)
                        {
                            //parse failed
                            Program.Log("Failed to prepare input for chatterbox: " + ex.Message);
                        }
                    }
                }
                catch (Exception ex)
                {
                    //ignore exception
                    Program.Log("Exception while handling input: " + ex.Message);
                }
            }
        }
Beispiel #3
0
 public override void Execute(IrcMessage message, string args)
 {
     if(Parent.Limiter.AttemptOperation(message.Level))
     {
         last = DateTime.UtcNow;
         if (args.Length > 0) throw new Exception("Failed to parse your command");
         int count = State.QuoteList.GetCount();
         if (count == 0) throw new Exception("No quotes are currently available");
         int idx = rng.Next(count);
         Quote quote = State.QuoteList[idx];
         string result = "Quote " + ControlCharacter.Bold() + "#" + quote.ID.ToString() + ControlCharacter.Bold() + ": " + quote.Text;
         message.ReplyChannel(result);
     }
 }
Beispiel #4
0
        public override void Execute(IrcMessage message, string args)
        {
            if(args.Length == 0)
            {
                //defaults to listing the warnings of the caller
                args = "list";
            }

            //cut off the part of the message that represents the sub-command
            int space = args.IndexOf(' ');
            string command = space == -1 ? args : args.Substring(0, space);
            string rest = space == -1 ? "" : args.Substring(space + 1);
            command = command.ToLower(); // puts subcommand to lowercase
            switch(command)
            {
                case "list":
                    {
                        //name of user to look up
                        space = rest.IndexOf(' ');
                        string lookUp = space == -1 ? rest : rest.Substring(0, space).Trim();
                        if (lookUp.Length == 0) lookUp = message.From;
                        if (lookUp == message.From)
                        {
                            //list <self> is allowed always
                        }
                        else if (CommandHandler.GetPrivilegeLevel(message.From) < read)
                        {
                            throw new Exception("Access denied");
                        }

                        //get warnings
                        User target = State.UserList.Lookup(lookUp);
                        if (target == null) throw new Exception("The target user '" + lookUp + "' was not found");
                        List<Warning> _warnlist = target.Meta.Warnings;
                        if (_warnlist.Count == 0)
                        {
                            message.ReplyPrivate("No warning entries found for '" + lookUp + "'");
                        }
                        else
                        {
                            message.ReplyPrivate("+++++ List of warnings for user: "******" +++++");
                            foreach (Warning wrn in _warnlist)
                            {
                                message.ReplyPrivate("#" + wrn.ID + ", created at " + wrn.Created.ToString() + ": " + ControlCharacter.Color(IrcColor.Purple) + wrn.Reason + ControlCharacter.ColorRestore() + " by " + wrn.IssuedBy);
                            }
                            message.ReplyPrivate("+++++ End of list +++++");
                        }
                    }
                    break;
                default:
                case "add":
                    {
                        //if default command, re-add command to rest
                        if (command != "add") rest = command + " " + rest;

                        //check privilege
                        if (CommandHandler.GetPrivilegeLevel(message.From) < edit)
                        {
                            throw new Exception("Access denied");
                        }

                        //get current warnings
                        space = rest.IndexOf(' ');
                        string toWarn = space == -1 ? rest : rest.Substring(0, space);
                        rest = space == -1 ? "Violation of the rules" : rest.Substring(space + 1);
                        User target = State.UserList.Lookup(toWarn);
                        if (target == null) throw new Exception("The target user '" + toWarn + "' was not found");
                        List<Warning> warnings = target.Meta.Warnings;

                        //check if already warned in past 5s, also get next highest ID
                        int maxid = 0;
                        foreach (Warning tst in warnings)
                        {
                            if (maxid < tst.ID) maxid = tst.ID;
                            if (DateTime.UtcNow.Subtract(tst.Created).CompareTo(new TimeSpan(0, 0, 5)) < 0)
                            {
                                message.ReplyPrivate("This user has already been warned in the last 5 seconds, your warning was omitted.");
                                return;
                            }
                        }

                        //add new warning
                        Warning warnNew = new Warning();
                        warnNew.ID = maxid + 1;
                        warnNew.Reason = rest;
                        warnNew.IssuedBy = message.From;
                        warnNew.Created = DateTime.UtcNow;
                        warnings.Add(warnNew);
                        State.MetaUserList.MarkChanged(target.Meta);

                        //tempban
                        if (warnings.Count >= State.WarningThreshold.Value)
                        {
                            HostMask mask = BanSystem.CreateBanMask(toWarn);
                            if (mask == null)
                            {
                                throw new Exception("Name '" + toWarn + "' not found");
                            }

                            BanSystem.PerformBan(mask.Mask, "15m", "You have been warned " + warnings.Count.ToString() + " times", "<warnings>");
                        }
                        else
                        {
                            message.ReplyChannel("A warning was issued to " + ControlCharacter.Bold() + toWarn + ControlCharacter.Bold() + " by " + message.From + " Reason: " + ControlCharacter.Bold() + warnNew.Reason);
                        }
                    }
                    break;
                case "del":
                    {
                        if (CommandHandler.GetPrivilegeLevel(message.From) < edit)
                        {
                            throw new Exception("Access denied");
                        }

                        //split arguments
                        space = rest.IndexOf(' ');
                        if(space <= 0) throw new Exception("Expected two arguments: <user> <id>");
                        string userarg = rest.Substring(0, space);
                        string idarg = rest.Substring(space + 1).Trim();

                        //look up warning list for user
                        User target = State.UserList.Lookup(userarg);
                        if (target == null) throw new Exception("The target user '" + userarg + "' was not found");
                        List<Warning> warnings = target.Meta.Warnings;

                        //look for warning with ID
                        int id = -1;
                        Warning warn = null;
                        if (int.TryParse(idarg, out id))
                        {
                            foreach (Warning needle in warnings)
                            {
                                if (needle.ID == id)
                                {
                                    warn = needle;
                                    break;
                                }
                            }
                        }
                        if (warn == null)
                        {
                            //not found
                            message.ReplyAuto("No warning for '" + userarg + "' with ID '" + idarg + "' was found");
                        }
                        else
                        {
                            //remove warning
                            warnings.Remove(warn);
                            message.ReplyAuto("Removed warning for '" + userarg + "' with ID '" + idarg + "'");
                            State.MetaUserList.MarkChanged(target.Meta);
                        }
                        break;
                    }
            }
        }