Beispiel #1
0
 public override void Execute(IrcMessage message, string args)
 {
     string[] arg = args.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
     if (arg.Length != 2) throw new Exception("Expected two arguments, got " + arg.Length.ToString());
     IPAddress ip = null;
     if (!IPAddress.TryParse(arg[1], out ip)) throw new Exception("Failed to parse '" + arg[1] + "' as an IP address");
     Account acct = State.AccountList.Lookup(ip);
     switch (arg[0].ToLower())
     {
         case "add":
             if (acct != null) throw new Exception("An account already exists for IP " + ip.ToString());
             acct = Account.Generate(ip);
             string result = acct.GetToken().ToXML();
             State.AccountList.Add(acct);
             message.ReplyPrivate(result);
             break;
         case "get":
             if (acct == null) throw new Exception("No account exists for IP " + ip.ToString());
             string reply = acct.GetToken().ToXML();
             message.ReplyPrivate(reply);
             break;
         case "del":
             if (acct == null) throw new Exception("No account exists for IP " + ip.ToString());
             State.AccountList.Remove(acct);
             message.ReplyPrivate("The account for IP " + ip.ToString() + " was removed");
             break;
     }
 }
Beispiel #2
0
 public override void Execute(IrcMessage message, string args)
 {
     User user = State.UserList.Lookup(message.From);
     if (user == null) throw new Exception("User not known");
     bool enabled;
     if (args.ToLower() == "on") enabled = true;
     else if (args.ToLower() == "off") enabled = false;
     else throw new Exception("Argument expected: on or off");
     user.Meta.Elevation = enabled;
     State.MetaUserList.MarkChanged(user.Meta);
     message.ReplyPrivate("Developer commands are now " + (user.Meta.Elevation ? "enabled" : "disabled") + " for " + message.From);
 }
Beispiel #3
0
 public override void Execute(IrcMessage message, string args)
 {
     int space = args.IndexOf(' ');
     if (space == -1) space = args.Length;
     string name = args.Substring(0, space);
     string val = args.Substring(space).Trim();
     if (name.Length == 0) throw new Exception("No property name specified");
     switch (name.ToLower())
     {
         case "sd":
             if (val.Length != 0)
             {
                 int ms = int.Parse(val);
                 if(ms <= 0) throw new Exception("Invalid value for property");
                 State.SendDelay.Value = ms;
             }
             message.ReplyPrivate("State.SendDelay == " + State.SendDelay.Value.ToString());
             break;
         case "pc":
             if(val.Length != 0) State.ParseChannel.Value = bool.Parse(val);
             message.ReplyPrivate("State.ParseChannel == " + State.ParseChannel.Value.ToString());
             break;
         case "wt":
             if (val.Length != 0)
             {
                 int wt = int.Parse(val);
                 if(wt <= 1) throw new Exception("Invalid value for property");
                 State.WarningThreshold.Value = wt;
             }
             message.ReplyPrivate("State.WarningThreshold == " + State.WarningThreshold.Value.ToString());
             break;
     #if QNETBOT
         case "cc":
             if (val.Length != 0) State.ControlCharacters.Value = bool.Parse(val);
             message.ReplyPrivate("State.ControlCharacters == " + State.ControlCharacters.Value.ToString());
             break;
         case "qe":
             if (val.Length != 0) State.UseQEnforce.Value = bool.Parse(val);
             message.ReplyPrivate("State.UseQEnforce == " + State.UseQEnforce.Value.ToString());
             break;
         case "qb":
             if (val.Length != 0) State.UseQuietBan.Value = bool.Parse(val);
             message.ReplyPrivate("State.UseQuietBan == " + State.UseQuietBan.Value.ToString());
             break;
     #endif
         default:
             throw new Exception("Unknown property name: " + name);
     }
 }
Beispiel #4
0
        public override void Execute(IrcMessage message, string args)
        {
            if (Limiter.AttemptOperation(message.Level))
            {
                PrivilegeLevel privilege = CommandHandler.GetPrivilegeLevel(message.From);
                string priv;
                switch (privilege)
                {
                    case PrivilegeLevel.Developer:
                    case PrivilegeLevel.OnChannel:
                    case PrivilegeLevel.Operator:
                    case PrivilegeLevel.Subscriber:
                        priv = " " + privilege.ToString();
                        break;

                    default:
                        priv = "n " + privilege.ToString();
                        break;

                }
                message.ReplyPrivate("'sup " + message.From + ", you are a" + priv);
            }
        }
Beispiel #5
0
        public override void Execute(IrcMessage message, string args)
        {
            if (Limiter.AttemptOperation(message.Level))
            {
                bool silent = false;
                if (args == "<silent>")
                {
                    args = DefaultChannel;
                    silent = true;
                }
                string stream = args.Length == 0 ? DefaultChannel : args;
                string uri = "https://api.twitch.tv/kraken/streams/" + stream;
                if (Uri.IsWellFormedUriString(uri, UriKind.Absolute))
                {
                    if (cache.ContainsKey(stream))
                    {
                        Cache item = cache[stream];
                        if (item == null)
                        {
                            //already pending
                            return;
                        }
                        else if ((DateTime.UtcNow - item.retrieved).TotalMinutes <= 1.0)
                        {
                            //in cache
                            if (!silent)
                            {
                                item.Report(message);
                            }
                            return;
                        }
                    }

                    //add new request
                    if (cache.ContainsKey(stream)) cache.Remove(stream);
                    cache.Add(stream, null);
                    AsyncExec async = new AsyncExec();
                    async.request = WebRequest.Create(uri);
                    async.message = message;
                    async.stream = stream;
                    async.silent = silent;
                    async.Execute();
                }
                else if (!silent)
                {
                    message.ReplyPrivate("The stream you specified is invalid");
                }
            }
        }
Beispiel #6
0
        public override void Execute(IrcMessage message, string args)
        {
            if (Parent.Limiter.AttemptOperation(message.Level))
            {
                //look up by word
                string[] words = args.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
                if (words.Length != 0)
                {
                    string reply = "";
                    int count = 0;
                    Quote quote = null;
                    foreach (Quote needle in State.QuoteList.GetItems())
                    {
                        int found = 0;
                        foreach (string word in words)
                        {
                            if (!needle.Text.Contains(word)) break;
                            found++;
                        }
                        if (found == words.Length)
                        {
                            quote = needle;

                            //print quote
                            string text = ControlCharacter.Enabled ? quote.Text : ControlCharacter.Strip(quote.Text);
                            reply += "Quote " + ControlCharacter.Bold() + "#" + quote.ID.ToString() + ControlCharacter.Bold() + ": " + text + "\n";
                            count++;
                        }
                    }
                    if (quote == null)
                    {
                        //not found
                        message.ReplyAuto("no quote found containing the word(s): " + args);
                    }
                    else if (count > 3)
                    {
                        //too many matches
                        message.ReplyAuto("more than 3 quotes matched your criteria, please be more exclusive in your criteria");
                    }
                    else
                    {
                        //print found quotes
                        message.ReplyAuto(reply);
                    }
                }
                else
                {
                    //no words
                    message.ReplyPrivate("When using 'quote find', specify one or more words to search");
                }
            }
        }
Beispiel #7
0
        public override void Execute(IrcMessage message, string args)
        {
            string[] arg = args.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);

            /* If ranks are disabled, show the options for the channel moderator */
            if (arg.Length < 2 && message.Level >= PrivilegeLevel.Operator && !SC2Ranks.IsEnabled)
            {
                throw new Exception("Usage: !rank <enabled> <true/false>: Toggles the availability of the 'rank' command");
            }

            /* see if we are toggling the availability of the command */
            if (arg.Length == 2)
            {
                if ((arg[0].ToLower() == "enabled" || arg[0].ToLower() == "enable") && message.Level >= PrivilegeLevel.Operator)
                {
                    string toggle = arg[1].ToString().ToLower();
                    bool flag = true;
                    if (toggle == "false" || toggle == "0" || toggle == "off")
                    {
                        flag = false;
                    }

                    if (SC2Ranks.ApiKey == String.Empty)
                    {
                        SC2Ranks.IsEnabled = false;
                        throw new Exception("SC2Ranks ApiKey must be set in internal configuration.");
                    }

                    SC2Ranks.IsEnabled = flag;
                    message.ReplyPrivate("Rank lookup has been " + (SC2Ranks.IsEnabled ? "en" : "dis") + "abled");
                    return;
                }
            }

            /* Regular rank command logic */
            if (Limiter.AttemptOperation(message.Level) && SC2Ranks.IsEnabled)
            {
                if (arg.Length != 2 && arg.Length != 3) throw new Exception("Usage: !rank <name> <region>");
                string region = null;
                string name = arg[1];

                /* Continue with rank lookup */
                for (int i = 0; i < 2 && region == null; i++)
                {
                    switch (arg[i].ToLower())
                    {
                        case "eu":
                        case "europe":
                            region = "eu";
                            break;
                        case "na":
                        case "us":
                        case "usa":
                        case "northamerica":
                        case "america":
                            region = "us";
                            break;
                        case "kr":
                        case "kor":
                        case "korea":
                            region = "kr";
                            break;
                        case "tw":
                        case "taiwan":
                            region = "tw";
                            break;
                        case "sea":
                        case "asia":
                            region = "sea";
                            break;
                        case "ru":
                        case "russia":
                            region = "ru";
                            break;
                        case "la":
                        case "latinamerica":
                        case "southamerica":
                            region = "la";
                            break;
                        default:
                            if (i == 0) name = arg[0];
                            else throw new Exception("Region not recognized");
                            break;
                    }
                }
                string key = region + "!" + name;
                int bracket = 1;
                if (arg.Length == 3)
                {
                    if (arg[2].ToLower() == "all")
                    {
                        bracket = 0;
                    }
                    else
                    {
                        bracket = (int)(arg[2][0] - '0');
                        if (bracket < 1 || bracket > 4) throw new Exception("Failed to parse bracket");
                    }
                }
                Cache.Entry results = Cache.GetCache(key.ToLower());
                if (results == null)
                {
                    new SearchRequest(message, name, region, bracket);
                }
                else
                {
                    results.Write(message, bracket);
                }
            }
        }
Beispiel #8
0
        public override void Execute(IrcMessage message, string args)
        {
            string[] arg = args.Split(new char[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            if (arg.Length < 2)
            {
                throw new Exception("Not enough parameters, expected 'trigger add <keyword> <text>' or 'trigger del <keyword>'");
            }
            if (arg[0].ToLower() == "add")
            {
                string keyword = arg[1].ToLower();
                foreach (char c in keyword)
                {
                    if (!char.IsLetter(c)) throw new Exception("Trigger keyword may only contain letters");
                }
                string text = null;
                for (int i = 2; i < arg.Length; i++) text = (text == null) ? arg[i] : text + " " + arg[i];
                if (text == null)
                {
                    throw new Exception("Cannot add a trigger with no text");
                }
                string result = Add(keyword, text) ? "Replaced" : "Added";
                result += " trigger '" + keyword + "'";
                message.ReplyPrivate(result);
            }
            else if (arg[0].ToLower() == "del")
            {
                string keyword = arg[1].ToLower();
                if (Remove(keyword))
                {
                    message.ReplyPrivate("Removed trigger '" + keyword + "'");
                }
                else
                {
                    message.ReplyPrivate("Trigger '" + keyword + "' could not be deleted");
                }
            }
            else if (arg[0].ToLower() == "protect")
            {
                if (message.Level == PrivilegeLevel.Developer)
                {
                    if (arg.Length < 2)
                    {
                        throw new Exception("Not enough parameters for protect.");
                    }
                    else if (arg.Length == 2 )
                    {
                        message.ReplyPrivate(GetProtect(arg[1].ToLower()));
                    }
                    else
                    {
                        string keyword = arg[1].ToLower();
                        string val = arg[2].ToString().ToLower();
                        if (val.Length > 0)
                        {
                            bool flag = true;
                            if (val == "false" || val == "0" || val == "disabled")
                            {
                                flag = false;
                            }

                            if (Protect(keyword, flag))
                            {
                                message.ReplyPrivate("Trigger '" + keyword + "' is " + (!flag ? "no longer " : "") + "protected ");
                            }
                        }
                    }

                }
            }
        }
Beispiel #9
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;
                    }
            }
        }