예제 #1
0
        /// <summary>
        /// Interprets commands
        /// </summary>
        /// <param name="command">The full message</param>
        /// <param name="sender">The full sender</param>
        /// <param name="recipient">The full recipient</param>
        private static void InterpretCommand(string command, IrcUser sender, IrcClient client)
        {
            command = command.TrimStart(ProgramSettings.settings.CommandPrefix); //simply removes the prefix

            if (command.StartsWith ("slap"))
            {
                if (ProgramSettings.settings.SlapEnabled)
                {
                    string[] splitCommand = command.Split (new char[] { ' ' }, 2);
                    if (splitCommand.Length > 1)
                    {
                        var listCopy = UsersList;
                        bool foundUser = false;
                        try
                        {
                            foreach (IrcUserAndSeen user in listCopy)
                            {
                                if (user.User.Nick.ToLower () == splitCommand [1].ToLower ().Trim ())
                                {
                                    if (user.User.Nick == client.User.Nick)
                                        client.SendRawMessage ("PRIVMSG {0} :What'd I do? :(", client.Channels [0].Name);
                                    else
                                        client.SendRawMessage ("PRIVMSG {0} :" + "\x01" + "ACTION slaps {1} with a giant fish.\x01", client.Channels [0].Name, user.User.Nick);
                                    foundUser = true;
                                    break;
                                }
                            }
                            if (!foundUser)
                                client.SendRawMessage ("PRIVMSG {0} :User not found!");
                        }
                        catch{}
                    } else
                        client.SendRawMessage ("PRIVMSG {0} :Slap who?", client.Channels [0].Name);
                }
            }
            if (command.StartsWith("removeuser"))
            {
                string[] split = command.Split(new char[]{' '}, 2);
                Console.ForegroundColor = ConsoleColor.Yellow;
                if (split.Length > 1)
                {
                    bool removed = false;
                    for(int i = 0; i < ProgramSettings.settings.UsersAllowedToDisable.Count; i++)
                    {
                        if (ProgramSettings.settings.UsersAllowedToDisable[i] == split[1].ToLower())
                        {
                            ProgramSettings.settings.UsersAllowedToDisable.RemoveAt(i);
                            removed = true;
                        }
                    }
                    if (removed)
                    {
                        Console.WriteLine("Removed user \"{0}\" successfully!", split[1].ToLower());
                        client.SendRawMessage("PRIVMSG {0} :Removed user \"{1}\" successfully!", client.Channels[0].Name, split[1].ToLower());
                    }
                    else
                    {
                        Console.WriteLine("User doesn't exist!");
                        client.SendRawMessage("PRIVMSG {0} :That user never existed in the database!", client.Channels[0].Name);
                    }
                }
                else
                {
                    Console.WriteLine("Remove who?");
                }
                Console.ForegroundColor = ConsoleColor.White;
            }
            if (command.StartsWith("adduser"))
            {
                string[] split = command.Split(new char[]{' '}, 2);
                Console.ForegroundColor = ConsoleColor.Yellow;
                if (split.Length > 1)
                {
                    ProgramSettings.settings.UsersAllowedToDisable.Add(split[1].ToLower());
                    Console.WriteLine("Added user \"{0}\" to the VIP list", split[1].ToLower());
                    client.SendRawMessage("PRIVMSG {0} :Added user \"{1}\" to the VIP list.?", client.Channels[0].Name, split[1].ToLower());
                }
                else
                {
                    Console.WriteLine("Who?");
                    client.SendRawMessage("PRIVMSG {0} :Add who?", client.Channels[0].Name);
                }
                Console.ForegroundColor = ConsoleColor.White;
            }
            if (command.StartsWith("disableseen"))
            {
                foreach (string user in ProgramSettings.settings.UsersAllowedToDisable)
                {
                    if (user.ToLower() == sender.Nick.ToLower())
                    {
                        ProgramSettings.settings.SeenEnabled = false;

                        Console.ForegroundColor = ConsoleColor.Yellow;
                        Console.WriteLine ("Seen Command Disabled");
                        Console.ForegroundColor = ConsoleColor.White;
                        client.SendRawMessage ("PRIVMSG {0} :Disabled seen command!", client.Channels[0].Name);
                    }
                }
            }
            if (command.StartsWith("enableseen"))
            {
                foreach (string user in ProgramSettings.settings.UsersAllowedToDisable)
                {
                    if (user.ToLower() == sender.Nick.ToLower())
                    {
                        ProgramSettings.settings.SeenEnabled = true;

                        Console.ForegroundColor = ConsoleColor.Yellow;
                        Console.WriteLine ("Seen Command Enabled");
                        Console.ForegroundColor = ConsoleColor.White;
                        client.SendRawMessage ("PRIVMSG {0} :Enabled seen command!", client.Channels[0].Name);
                    }
                }
            }
            if (command.StartsWith ("enableurlparse"))
            {
                foreach (string user in ProgramSettings.settings.UsersAllowedToDisable)
                {
                    if (user.ToLower () == sender.Nick.ToLower ())
                    {
                        ProgramSettings.settings.UrlParsingEnabled = true;

                        Console.ForegroundColor = ConsoleColor.Yellow;
                        Console.WriteLine ("URL Parsing Enabled");
                        Console.ForegroundColor = ConsoleColor.White;
                        client.SendRawMessage ("PRIVMSG {0} :Enabling URL parsing!", client.Channels[0].Name);
                    }
                }
            }
            if (command.StartsWith ("disableurlparse"))
            {
                foreach (string user in ProgramSettings.settings.UsersAllowedToDisable)
                {
                    if (user.ToLower () == sender.Nick.ToLower ())
                    {
                        ProgramSettings.settings.UrlParsingEnabled = false;

                        Console.ForegroundColor = ConsoleColor.Yellow;
                        Console.WriteLine ("URL Parsing Disabled");
                        Console.ForegroundColor = ConsoleColor.White;
                        client.SendRawMessage ("PRIVMSG {0} :Disabling URL parsing!", client.Channels[0].Name);
                    }
                }
            }
            if (command.StartsWith ("nick") || command.StartsWith ("name"))
            {
                string[] splitCommand = command.Split (new char[]{ ' ' }, 2);
                if (splitCommand.Length > 1)
                {
                    foreach (string user in ProgramSettings.settings.UsersAllowedToDisable)
                    {
                        if (user.ToLower () == sender.Nick.ToLower ())
                        {
                            string cleanNick = CleanInput (splitCommand [1]);
                            client.Nick (cleanNick);
                            ProgramSettings.settings.LastUsedNick = client.User.Nick;
                        }
                    }
                }
            }
            if(command.StartsWith("motto") || command.StartsWith("slogan"))
            {
                client.SendRawMessage("PRIVMSG {0} :Luigibot does what Reta don't \u00a9", client.Channels[0].Name);
            }
            if(command.StartsWith("version"))
            {
                #if __MONOCS__
                client.SendRawMessage("PRIVMSG {0} :Luigibot v{1} - http://www.github.com/Luigifan/Luigibot - Running under Mono", client.Channels[0].Name, ProgramVersion.ToString());
                #else
                client.SendRawMessage("PRIVMSG {0} :Luigibot v{1} - http://www.github.com/Luigifan/Luigibot", client.Channels[0].Name, ProgramVersion.ToString());
                #endif
            }
            if(command.StartsWith("changeprefix"))
            {
                string[] splitCommand = command.Split(new char[] { ' ' }, 2);
                if (splitCommand.Length > 1)
                {
                    foreach (string user in ProgramSettings.settings.UsersAllowedToDisable)
                    {
                        if(user.ToLower() == sender.Nick.ToLower())
                        {
                            if (splitCommand[1].Length == 1)
                            {
                                if (splitCommand[1] == "/")
                                {
                                    client.SendRawMessage("PRIVMSG {0} :oi u cheeky c**t ill bash ur ead in i swear on me mum", client.Channels[0].Name);
                                    return;
                                }
                                try
                                {
                                    char newPrefix = char.Parse(splitCommand[1]);
                                    ProgramSettings.settings.CommandPrefix = newPrefix;

                                    Console.ForegroundColor = ConsoleColor.Yellow;
                                    Console.WriteLine("Command prefix changed to '{0}' successfully!", newPrefix.ToString());
                                    Console.ForegroundColor = ConsoleColor.White;

                                    client.SendRawMessage("PRIVMSG {0} :Command prefix changed to '{1}' successfully!", client.Channels[0].Name, newPrefix.ToString());
                                    return;
                                }
                                catch (Exception ex)
                                {
                                    client.SendRawMessage("PRIVMSG {0} :Uh-oh! Luigibot encountered an error. Email Luigifan @ [email protected]",
                                        client.Channels[0].Name);

                                    Console.ForegroundColor = ConsoleColor.Red;
                                    Console.WriteLine("UH OH BIG ERROR\nUH OH BIG ERROR");
                                    Console.ForegroundColor = ConsoleColor.White;
                                    Console.WriteLine(ex.Message + "\n");
                                }
                            }
                            else
                            {
                                client.SendRawMessage("PRIVMSG {0} :The prefix must be a single character!", client.Channels[0].Name);
                            }
                        }
                    }
                }
                else
                    client.SendRawMessage("PRIVMSG {0} :What character will prefix my commands?", client.Channels[0].Name);
            }
            if(command.StartsWith("kick"))
            {
                //0: command
                //1: user
                //2: reason
                string[] splitCommand = command.Split(new char[] { ' ' }, 3);
                foreach (string user in ProgramSettings.settings.UsersAllowedToDisable)
                {
                    if(user.ToLower() == sender.Nick.ToLower())
                    {
                        try
                        {
                            if (splitCommand.Length > 2)
                            {
                                client.KickUser(client.Channels[0].Name, splitCommand[1], splitCommand[2]);
                            }
                            else
                                client.KickUser(client.Channels[0].Name, splitCommand[1]);
                        }
                        catch (Exception ex)
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine("ERROR: {0}", ex.Message);
                            Console.ForegroundColor = ConsoleColor.White;
                        }
                    }
                }
            }
            if(command.StartsWith("getmodes"))
            {
                client.SendMessage("Modes: " + client.User.Mode, client.Channels[0].Name);
            }
            if (command.StartsWith ("ann"))
            {
                string[] splitCommand = command.Split (new char[]{ ' ' }, 2);
                if (splitCommand.Length > 1)
                {
                    foreach (var nick in ProgramSettings.settings.UsersAllowedToDisable)
                    {
                        if (sender.Nick.ToLower () == nick)
                        {
                            if (splitCommand [1] == "test")
                            {
                                if (ProgramSettings.settings.WelcomeMessage.Contains ("/me"))
                                {
                                    client.SendAction (String.Format (ProgramSettings.settings.WelcomeMessage.Substring (4), sender.Nick), client.Channels [0].Name);
                                } else
                                {
                                    client.SendRawMessage ("PRIVMSG {0} :{1}",
                                        client.Channels [0].Name,
                                        String.Format (ProgramSettings.settings.WelcomeMessage, sender.Nick));
                                }
                            }
                            else
                            {
                                if(splitCommand[1].Contains("{") && splitCommand[1].Contains("}"))
                                {
                                    string[] tester = splitCommand[1].Split(new char[] { '{', '}' }, 3);
                                    foreach(string x in tester)
                                    {
                                        int xf = -1;
                                        bool parsed = false;
                                        try
                                        {
                                            xf = int.Parse(x.ToString());
                                            parsed = true;
                                        }
                                        catch{parsed = false;}

                                        if (parsed)
                                        {
                                            if (xf > 0 || xf < 0)
                                            {
                                                client.SendRawMessage("PRIVMSG {0} :ERROR: Index numbers can't be bigger than 0 or less than 0. MUST BE 0!", client.Channels[0].Name);
                                                return;
                                            }
                                        }
                                    }
                                }
                                ProgramSettings.settings.WelcomeMessage = splitCommand [1];
                                client.SendRawMessage ("PRIVMSG {0} :Welcome message set!", client.Channels [0].Name);
                                Console.ForegroundColor = ConsoleColor.Yellow;
                                Console.WriteLine ("New welcome message set: " + splitCommand [1]);
                                Console.ForegroundColor = ConsoleColor.White;
                            }
                        }
                    }
                }
                else
                {
                    client.SendRawMessage ("PRIVMSG {0} :What message do I set?", client.Channels[0].Name);
                }
            }
            if (command.StartsWith ("enableslap"))
            {
                foreach (var nick in ProgramSettings.settings.UsersAllowedToDisable)
                {
                    if (sender.Nick.ToLower () == nick)
                    {
                        ProgramSettings.settings.SlapEnabled = true;

                        Console.ForegroundColor = ConsoleColor.Yellow;
                        Console.WriteLine ("Enabling slap");
                        Console.ForegroundColor = ConsoleColor.White;

                        break;
                    }
                }
            }
            if (command.StartsWith ("enablewelcome"))
            {
                foreach (var nick in ProgramSettings.settings.UsersAllowedToDisable)
                {
                    if (sender.Nick.ToLower () == nick)
                    {
                        ProgramSettings.settings.WelcomeUserEnabled = true;

                        Console.ForegroundColor = ConsoleColor.Yellow;
                        Console.WriteLine ("Enabling welcome messages");
                        Console.ForegroundColor = ConsoleColor.White;

                        break;
                    }
                }
            }
            if (command.StartsWith ("disablewelcome"))
            {
                foreach (var nick in ProgramSettings.settings.UsersAllowedToDisable)
                {
                    if (sender.Nick.ToLower () == nick)
                    {
                        ProgramSettings.settings.WelcomeUserEnabled = false;

                        Console.ForegroundColor = ConsoleColor.Yellow;
                        Console.WriteLine ("Disabling welcome messages");
                        Console.ForegroundColor = ConsoleColor.White;

                        break;
                    }
                }
            }
            if (command.StartsWith ("disableslap"))
            {
                foreach (var nick in ProgramSettings.settings.UsersAllowedToDisable)
                {
                    if (sender.Nick.ToLower () == nick)
                    {
                        ProgramSettings.settings.SlapEnabled = false;

                        Console.ForegroundColor = ConsoleColor.Yellow;
                        Console.WriteLine ("Disabling slap");
                        Console.ForegroundColor = ConsoleColor.White;

                        break;
                    }
                }
            }
            if (command.StartsWith ("eightball") || command.StartsWith ("8ball") || command.StartsWith ("fortune"))
            {
                if (ProgramSettings.settings.EightballEnabled)
                {
                    int ranMessage = random.Next (EightballMessages.Length - 1);
                    if (command.ToLower ().Contains ("waluigibot1337") || command.ToLower ().Contains ("waluigibot") || command.ToLower ().Contains ("waluigi bot"))
                        client.SendRawMessage ("PRIVMSG {0} :Waluigibot is a tool and will never come to fruition.", client.Channels [0].Name);
                    else if (command.ToLower ().Contains ("bot") && !command.ToLower ().Contains ("luigi"))
                        client.SendRawMessage ("PRIVMSG {0} :Your bot is inadequate for the job.", client.Channels [0].Name);
                    else
                        client.SendRawMessage ("PRIVMSG {0} :{1}", client.Channels [0].Name, EightballMessages [ranMessage]);
                }
            }
            if (command.StartsWith ("status"))
            {
                client.SendRawMessage ("PRIVMSG {0} :Slap Enabled: {1}. Eight Ball Enabled: {2}. Welcome Enabled: {3}. Command Prefix: {4}. URL Parsing: {5}",
                    client.Channels [0].Name,
                    ProgramSettings.settings.SlapEnabled,
                    ProgramSettings.settings.EightballEnabled,
                    ProgramSettings.settings.WelcomeUserEnabled,
                    ProgramSettings.settings.CommandPrefix.ToString(),
                    ProgramSettings.settings.UrlParsingEnabled);
            }
            if (command.StartsWith ("lastfm"))
            {
                #if __MONOCS__
                client.SendRawMessage("PRIVMSG {0} :The Last.FM API we use isn't available on Mono.", client.Channels[0].Name);
                #elif __MSCS__
                string[] split = command.Split (new char[] { ' ' }, 2);
                if (split.Length > 1)
                {
                    client.SendRawMessage("PRIVMSG {0} :Sending LastFM request, this may take a few seconds..", client.Channels[0].Name);
                    try
                    {
                        var lastfmClient = new LastfmClient ("4de0532fe30150ee7a553e160fbbe0e0", "0686c5e41f20d2dc80b64958f2df0f0c");
                        var response = lastfmClient.User.GetRecentScrobbles (split [1].ToString ().Trim (), null, 0, 1);
                        LastTrack lastTrack = response.Result.Content [0];
                        client.SendRawMessage ("PRIVMSG {0} :{1} last listened to {2} by {3}.", client.Channels [0].Name, split [1].Trim (), lastTrack.Name, lastTrack.ArtistName);
                    }
                    catch (ArgumentOutOfRangeException iex)
                    {
                        client.SendRawMessage ("PRIVMSG {0} :That user doesn't exist or hasn't scrobbled anything yet!",
                            client.Channels [0].Name);
                    }
                    catch (Exception ex)
                    {
                        client.SendRawMessage ("PRIVMSG {0} :Uh-oh! Luigibot encountered an error. Email Luigifan @ [email protected]",
                            client.Channels [0].Name);

                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine ("UH OH BIG ERROR\nUH OH BIG ERROR");
                        Console.ForegroundColor = ConsoleColor.White;
                        Console.WriteLine (ex.Message + "\n");
                    }
                }
                #endif
            }
            if (command.StartsWith ("enable8ball") || command.StartsWith ("enableeightball"))
            {
                foreach (var nick in ProgramSettings.settings.UsersAllowedToDisable)
                {
                    if (sender.Nick.ToLower () == nick)
                    {
                        ProgramSettings.settings.EightballEnabled = true;

                        Console.ForegroundColor = ConsoleColor.Yellow;
                        Console.WriteLine ("Enabling eight ball");
                        Console.ForegroundColor = ConsoleColor.White;

                        break;
                    }
                }
            }
            if (command.StartsWith ("disable8ball") || command.StartsWith ("disableeightball"))
            {
                foreach (var nick in ProgramSettings.settings.UsersAllowedToDisable)
                {
                    if (sender.Nick.ToLower () == nick)
                    {
                        ProgramSettings.settings.EightballEnabled = false;

                        Console.ForegroundColor = ConsoleColor.Yellow;
                        Console.WriteLine ("Disabling eight ball");
                        Console.ForegroundColor = ConsoleColor.White;

                        break;
                    }
                }
            }
            if (command.StartsWith ("selfdestruct"))
            {
                foreach (var nick in ProgramSettings.settings.UsersAllowedToDisable)
                {
                    if (sender.Nick.ToLower () == nick)
                    {
                        ExitSafely ();
                        break;
                    }
                }
            }
            if (command.StartsWith ("42"))
            {
                client.SendRawMessage ("PRIVMSG {0} :The Answer to Life, the Universe, and Everything.", client.Channels [0].Name);
            }
            if (command.StartsWith ("commands"))
            {
                client.SendRawMessage ("PRIVMSG {0} :You can find a list of my commands here: https://github.com/Luigifan/Luigibot/wiki/Luigibot-Commands", client.Channels [0].Name);
            }
            if (command.StartsWith ("seen"))
            {
                string[] splitCommand = command.Split (new char[] { ' ' }, 2);
                if (splitCommand.Length > 1)
                {
                    if (splitCommand [1].ToLower () == "knux" || splitCommand [1].ToLower () == "knuckles" || splitCommand [1].ToLower () == "knuckles96")
                    {
                        client.SendRawMessage ("PRIVMSG {0} :Never.", client.Channels [0].Name);
                        return;
                    }
                    var UsersListCopy = UsersList;
                    var UserDatabaseCopy = UsersSeenDatabase.UsersSeenDatabase;
                    //First, check to see if the user is on now
                    bool foundInOnline = false;
                    foreach (IrcUserAndSeen user in UsersListCopy)
                    {
                        if (user.User.Nick.ToLower () == splitCommand [1].ToLower ().Trim ())
                        {
                            foundInOnline = true;
                            if (user.User.Nick == client.User.Nick)
                                client.SendRawMessage ("PRIVMSG {0} :I'm always online c:", client.Channels [0].Name);
                            else
                                client.SendRawMessage ("PRIVMSG {0} :That user is online now!", client.Channels [0].Name);
                            foundInOnline = true;
                            break;
                        }
                    }
                    //Then, we'll check the database
                    bool foundInDatabase = false;
                    List<IrcUserAndSeen> removeLater = new List<IrcUserAndSeen>();
                    if (!foundInOnline)
                    {
                        foreach (IrcUserAndSeen user in UserDatabaseCopy)
                        {
                            if (user.User.Nick == null)
                            {
                                Console.WriteLine("Adding null entry to be removed later");
                                removeLater.Add(user);
                            }
                            else
                            {
                                if (user.User.Nick.ToLower() == splitCommand[1].ToLower().Trim())
                                {
                                    foundInDatabase = true;
                                    client.SendRawMessage("PRIVMSG {0} :{1} was last seen at {2} (EST)", client.Channels[0].Name, user.User.Nick, user.LastSeen.ToString());
                                    break;
                                }
                            }
                        }
                        if (!foundInDatabase && !foundInOnline)
                            client.SendRawMessage ("PRIVMSG {0} :I'm not sure :(", client.Channels [0].Name);
                    }
                } else
                    client.SendRawMessage ("PRIVMSG {0} :Last seen who?", client.Channels [0].Name);
            }
        }