Beispiel #1
0
        private void searchQuotes(TSPlayer player, string searchterm)
        {
            List <int> quoteresults = new List <int>();

            for (int i = 0; i < quotelist.Count; i++)
            {
                if (quotelist[i].qquote.ToLower().Contains(searchterm.ToLower()))
                {
                    quoteresults.Add(i);
                }
            }

            if (quoteresults.Count < 1)
            {
                player.SendInfoMessage("No quotes matched your search.");
            }
            else if (quoteresults.Count > 1)
            {
                string outputresults = string.Join(", ", quoteresults.Select(p => (p + 1).ToString()));
                player.SendInfoMessage("Multiple quotes matched your search: " + outputresults);
            }
            else
            {
                QuoteClass readQuote = quotelist[quoteresults[0]];
                if (!readQuote.qdeleted)
                {
                    player.SendMessage("[" + readQuote.qtime + "] Quote #" + (quoteresults[0] + 1).ToString() + " by " + readQuote.qauthor + ": " + readQuote.qquote, Color.LawnGreen);
                }
                else
                {
                    player.SendErrorMessage("No quotes matched your search.");
                }
            }
        }
Beispiel #2
0
        private void DoQuotes(CommandArgs args)
        {
            if (args.Parameters.Count < 1)
            {
                args.Player.SendErrorMessage("Invalid syntax:");
                args.Player.SendErrorMessage("{0}quote read <quote #>", (args.Silent ? TShock.Config.CommandSilentSpecifier : TShock.Config.CommandSpecifier));
                args.Player.SendErrorMessage("{0}quote search <words>", (args.Silent ? TShock.Config.CommandSilentSpecifier : TShock.Config.CommandSpecifier));
                args.Player.SendErrorMessage("{0}quote total", (args.Silent ? TShock.Config.CommandSilentSpecifier : TShock.Config.CommandSpecifier));
                args.Player.SendErrorMessage("{0}quote random", (args.Silent ? TShock.Config.CommandSilentSpecifier : TShock.Config.CommandSpecifier));
                if (args.Player.Group.HasPermission("quotes.mod"))
                {
                    args.Player.SendErrorMessage("{0}quote add <quote>", (args.Silent ? TShock.Config.CommandSilentSpecifier : TShock.Config.CommandSpecifier));
                    args.Player.SendErrorMessage("{0}quote <del/show> <quote #>", (args.Silent ? TShock.Config.CommandSilentSpecifier : TShock.Config.CommandSpecifier));
                }
                if (args.Player.Group.HasPermission("quotes.purge"))
                {
                    args.Player.SendErrorMessage("{0}quote purge", (args.Silent ? TShock.Config.CommandSilentSpecifier : TShock.Config.CommandSpecifier));
                }

                return;
            }
            else if (args.Parameters.Count == 1)
            {
                if (args.Parameters[0].ToLower() == "total")
                {
                    int count = 0;

                    foreach (QuoteClass quote in quotelist)
                    {
                        if (!quote.qdeleted)
                        {
                            count++;
                        }
                    }

                    args.Player.SendMessage("There " + (count == 1 ? "is" : "are") + " " + count + " quote" + (count == 1 ? "" : "s") + " in total.", Color.LawnGreen);
                }
                else if (args.Parameters[0].ToLower() == "random")
                {
                    if (quotelist.Count == 0)
                    {
                        args.Player.SendErrorMessage("There are no quotes to view!");
                        return;
                    }

                    Random random  = new Random();
                    int    randnum = random.Next(0, quotelist.Count);

                    while (quotelist[randnum].qdeleted)
                    {
                        randnum = random.Next(0, quotelist.Count);
                    }

                    QuoteClass readQuote = quotelist[randnum];

                    args.Player.SendMessage("[" + readQuote.qtime + "] Quote #" + (randnum + 1).ToString() + " by " + readQuote.qauthor + ": " + readQuote.qquote, Color.LawnGreen);
                }
                else if (args.Parameters[0].ToLower() == "purge" && args.Player.Group.HasPermission("quotes.purge"))
                {
                    args.Player.SendInfoMessage("Warning: This will permanently remove all deleted quotes. This will also alter the quote numbers. To continue, type {0}quote purge confirm.", (args.Silent ? TShock.Config.CommandSilentSpecifier : TShock.Config.CommandSpecifier));
                }
                else
                {
                    args.Player.SendErrorMessage("Invalid syntax:");
                    args.Player.SendErrorMessage("{0}quote read <quote #>", (args.Silent ? TShock.Config.CommandSilentSpecifier : TShock.Config.CommandSpecifier));
                    args.Player.SendErrorMessage("{0}quote search <words>", (args.Silent ? TShock.Config.CommandSilentSpecifier : TShock.Config.CommandSpecifier));
                    args.Player.SendErrorMessage("{0}quote total", (args.Silent ? TShock.Config.CommandSilentSpecifier : TShock.Config.CommandSpecifier));
                    args.Player.SendErrorMessage("{0}quote random", (args.Silent ? TShock.Config.CommandSilentSpecifier : TShock.Config.CommandSpecifier));
                    if (args.Player.Group.HasPermission("quotes.mod"))
                    {
                        args.Player.SendErrorMessage("{0}quote add <quote>", (args.Silent ? TShock.Config.CommandSilentSpecifier : TShock.Config.CommandSpecifier));
                        args.Player.SendErrorMessage("{0}quote <del/show> <quote #>", (args.Silent ? TShock.Config.CommandSilentSpecifier : TShock.Config.CommandSpecifier));
                    }
                    if (args.Player.Group.HasPermission("quotes.purge"))
                    {
                        args.Player.SendErrorMessage("{0}quote purge", (args.Silent ? TShock.Config.CommandSilentSpecifier : TShock.Config.CommandSpecifier));
                    }
                    return;
                }
            }
            else if (args.Parameters.Count == 2)
            {
                if (args.Parameters[0].ToLower() == "read")
                {
                    int  quotenum = -1;
                    bool parsed   = false;
                    parsed = Int32.TryParse(args.Parameters[1], out quotenum);
                    if (!parsed)
                    {
                        args.Player.SendErrorMessage("Invalid quote number!");
                        return;
                    }
                    else if (quotenum > quotelist.Count || quotenum < 1)
                    {
                        args.Player.SendErrorMessage("Invalid quote number!");
                        return;
                    }
                    else
                    {
                        quotenum--;
                        QuoteClass readQuote = quotelist[quotenum];
                        if (readQuote.qdeleted && !args.Player.Group.HasPermission("quotes.mod"))
                        {
                            args.Player.SendErrorMessage("This quote has been deleted!");
                            return;
                        }
                        else if (!readQuote.qdeleted)
                        {
                            args.Player.SendMessage("[" + readQuote.qtime + "] Quote #" + (quotenum + 1).ToString() + " by " + readQuote.qauthor + ": " + readQuote.qquote, Color.LawnGreen);
                        }
                        else
                        {
                            args.Player.SendMessage("[Deleted][" + readQuote.qtime + "] Quote #" + (quotenum + 1).ToString() + " by " + readQuote.qauthor + ": " + readQuote.qquote, Color.DarkOrange);
                        }
                    }
                }
                else if (args.Parameters[0].ToLower() == "del")
                {
                    int  quotenum = -1;
                    bool parsed   = false;
                    parsed = Int32.TryParse(args.Parameters[1], out quotenum);
                    if (!parsed)
                    {
                        args.Player.SendErrorMessage("Invalid quote number!");
                        return;
                    }
                    else if (quotenum > quotelist.Count || quotenum < 1)
                    {
                        args.Player.SendErrorMessage("Invalid quote number!");
                        return;
                    }
                    else
                    {
                        if (quotelist[quotenum - 1].qauthor != args.Player.User.Name && !args.Player.Group.HasPermission("quotes.mod"))
                        {
                            args.Player.SendErrorMessage("You do not have permission to delete other users' quotes!");
                            return;
                        }

                        if (quotelist[quotenum - 1].qdeleted)
                        {
                            args.Player.SendErrorMessage("This quote has already been deleted!");
                            return;
                        }
                        quotelist[quotenum - 1].qdeleted = true;

                        delQuote(quotenum, true);

                        args.Player.SendSuccessMessage("Successfully deleted quote #{0}!", quotenum);
                    }
                }
                else if (args.Parameters[0].ToLower() == "search")
                {
                    searchQuotes(args.Player, args.Parameters[1]);
                }
                else if (args.Parameters[0].ToLower() == "show")
                {
                    if (!args.Player.Group.HasPermission("quotes.mod"))
                    {
                        args.Player.SendErrorMessage("You do not have permission to show deleted quotes.");
                        return;
                    }

                    int  quotenum = -1;
                    bool parsed   = false;
                    parsed = Int32.TryParse(args.Parameters[1], out quotenum);
                    if (!parsed)
                    {
                        args.Player.SendErrorMessage("Invalid quote number!");
                        return;
                    }
                    else if (quotenum > quotelist.Count || quotenum < 1)
                    {
                        args.Player.SendErrorMessage("Invalid quote number!");
                        return;
                    }
                    else
                    {
                        QuoteClass quote = quotelist[quotenum - 1];

                        if (quote.qdeleted)
                        {
                            quote.qdeleted = false;
                            delQuote(quotenum, false);
                            args.Player.SendSuccessMessage("Restored quote #" + quotenum.ToString());
                        }
                        else
                        {
                            args.Player.SendErrorMessage("This quote is not deleted!");
                        }
                    }
                }
                else if (args.Parameters[0].ToLower() == "purge" && args.Parameters[1].ToLower() == "confirm" && args.Player.Group.HasPermission("quotes.purge"))
                {
                    purgeQuotes();
                    args.Player.SendSuccessMessage("Quotes successfully purged.");
                }
                else
                {
                    args.Player.SendErrorMessage("Invalid syntax:");
                    args.Player.SendErrorMessage("{0}quote read <quote #>", (args.Silent ? TShock.Config.CommandSilentSpecifier : TShock.Config.CommandSpecifier));
                    args.Player.SendErrorMessage("{0}quote search <words>", (args.Silent ? TShock.Config.CommandSilentSpecifier : TShock.Config.CommandSpecifier));
                    args.Player.SendErrorMessage("{0}quote total", (args.Silent ? TShock.Config.CommandSilentSpecifier : TShock.Config.CommandSpecifier));
                    args.Player.SendErrorMessage("{0}quote random", (args.Silent ? TShock.Config.CommandSilentSpecifier : TShock.Config.CommandSpecifier));
                    if (args.Player.Group.HasPermission("quotes.mod"))
                    {
                        args.Player.SendErrorMessage("{0}quote add <quote>", (args.Silent ? TShock.Config.CommandSilentSpecifier : TShock.Config.CommandSpecifier));
                        args.Player.SendErrorMessage("{0}quote <del/show> <quote #>", (args.Silent ? TShock.Config.CommandSilentSpecifier : TShock.Config.CommandSpecifier));
                    }
                    if (args.Player.Group.HasPermission("quotes.purge"))
                    {
                        args.Player.SendErrorMessage("{0}quote purge", (args.Silent ? TShock.Config.CommandSilentSpecifier : TShock.Config.CommandSpecifier));
                    }
                    return;
                }
            }
            else
            {
                if (args.Parameters[0].ToLower() == "add")
                {
                    if (!args.Player.Group.HasPermission("quotes.add") && !args.Player.Group.HasPermission("quotes.mod"))
                    {
                        args.Player.SendErrorMessage("You do not have permission to add quotes.");
                        return;
                    }

                    string quote = string.Join(" ", args.Parameters);
                    quote = quote.Replace("add ", "");

                    QuoteClass newQuote = new QuoteClass(quotelist.Count + 1, args.Player.User.Name, DateTime.Now.ToString(), quote, false);

                    quotelist.Add(newQuote);
                    addQuote(quotelist.Count, newQuote);

                    args.Player.SendSuccessMessage("You have added quote #{0}!", newQuote.qid);
                    if (!args.Silent)
                    {
                        TSPlayer.All.SendMessage("{0} has added a new quote! Use {2}quote read {1} to view it!".SFormat(args.Player.Name, newQuote.qid, TShock.Config.CommandSpecifier), Color.LawnGreen);
                    }
                }
                else if (args.Parameters[0].ToLower() == "search")
                {
                    string searchterms = string.Join(" ", args.Parameters);
                    searchterms = searchterms.Replace("search ", "");
                    searchQuotes(args.Player, searchterms);
                }
            }
        }
Beispiel #3
0
 private bool addQuote(int newID, QuoteClass newquote)
 {
     db.Query("INSERT INTO Quotes (ID, Deleted, Author, Date, Quote) VALUES (@0, @1, @2, @3, @4)", newID, 0, newquote.qauthor, newquote.qtime, newquote.qquote);
     return(true);
 }