Пример #1
0
        // Main loop
        public static Task Start()
        {
            // Begin bot process in its own thread
            new Thread(delegate()
            {
                new RainBorg().RunBotAsync().GetAwaiter().GetResult();
            }).Start();

            // Begin timeout loop in its own thread
            new Thread(delegate()
            {
                UserTimeout();
            }).Start();

            // Get console commands
            string command = "";

            while (command.ToLower() != "exit")
            {
                // Get command
                command = Console.ReadLine();

                if (command.ToLower().StartsWith("dotip"))
                {
                    Waiting = waitTime;
                    Console.WriteLine("Tip sent.");
                }
                else if (command.ToLower().StartsWith("reset"))
                {
                    foreach (KeyValuePair <ulong, List <ulong> > Entry in UserPools)
                    {
                        Entry.Value.Clear();
                    }
                    Greylist.Clear();
                    Console.WriteLine("Pools reset.");
                }
                else if (command.ToLower().StartsWith("loglevel"))
                {
                    logLevel = int.Parse(command.Substring(command.IndexOf(' ')));
                    Config.Save();
                    Console.WriteLine("Log level changed.");
                }
                else if (command.ToLower().StartsWith("say"))
                {
                    foreach (ulong Channel in StatusChannel)
                    {
                        (_client.GetChannel(Channel) as SocketTextChannel).SendMessageAsync(command.Substring(command.IndexOf(' ')));
                    }
                    Console.WriteLine("Sent message.");
                }
                else if (command.ToLower().StartsWith("addoperator"))
                {
                    if (!Operators.ContainsKey(ulong.Parse(command.Substring(command.IndexOf(' ')))))
                    {
                        Operators.Add(ulong.Parse(command.Substring(command.IndexOf(' '))));
                    }
                    Console.WriteLine("Added operator.");
                }
                else if (command.ToLower().StartsWith("removeoperator"))
                {
                    if (Operators.ContainsKey(ulong.Parse(command.Substring(command.IndexOf(' ')))))
                    {
                        Operators.Remove(ulong.Parse(command.Substring(command.IndexOf(' '))));
                    }
                    Console.WriteLine("Removed operator.");
                }
                else if (command.ToLower().StartsWith("test"))
                {
                    Stats.Tip(DateTime.Now, 1, 1, 1000000);
                    Console.WriteLine("Added tip to database.");
                }
                else if (command.ToLower().StartsWith("restart"))
                {
                    Log("RainBorg", "Relaunching bot...");
                    Paused = true;
                    JObject Resuming = new JObject
                    {
                        ["userPools"]    = JToken.FromObject(UserPools),
                        ["greylist"]     = JToken.FromObject(Greylist),
                        ["userMessages"] = JToken.FromObject(UserMessages)
                    };
                    File.WriteAllText(resumeFile, Resuming.ToString());
                    Process.Start("RelaunchUtility.exe", "RainBorg.exe");
                    ConsoleEventCallback(2);
                    Environment.Exit(0);
                }
            }

            // Completed, exit bot
            return(Task.CompletedTask);
        }
Пример #2
0
        // Main loop
        public static Task Start()
        {
            // Begin bot process in its own thread
            new Thread(delegate()
            {
                new RainBorg().RunBotAsync().GetAwaiter().GetResult();
            }).Start();

            // Begin timeout loop in its own thread

            /*new Thread(delegate ()
             * {
             *  UserTimeout();
             * }).Start();*/

            // Get console commands
            string command = "";

            while (command.ToLower() != "exit")
            {
                // Get command
                command = Console.ReadLine();

                if (command.ToLower().StartsWith("dotip"))
                {
                    waitTime = 0;
                    Log(0, "Console", "Tip sent.");
                }
                else if (command.ToLower().StartsWith("reset"))
                {
                    foreach (KeyValuePair <ulong, LimitedList <ulong> > Entry in UserPools)
                    {
                        Entry.Value.Clear();
                    }
                    Greylist.Clear();
                    Log(0, "Console", "Pools reset.");
                }
                else if (command.ToLower().StartsWith("loglevel"))
                {
                    logLevel = int.Parse(command.Substring(command.IndexOf(' ')));
                    Config.Save();
                    Log(0, "Console", "Log level changed.");
                }
                else if (command.ToLower().StartsWith("say"))
                {
                    foreach (ulong Channel in StatusChannel)
                    {
                        (_client.GetChannel(Channel) as SocketTextChannel).SendMessageAsync(command.Substring(command.IndexOf(' ')));
                    }
                    Log(0, "Console", "Sent message.");
                }
                else if (command.ToLower().StartsWith("addoperator"))
                {
                    if (!Operators.ContainsKey(ulong.Parse(command.Substring(command.IndexOf(' ')))))
                    {
                        Operators.Add(ulong.Parse(command.Substring(command.IndexOf(' '))));
                    }
                    Log(0, "Console", "Added operator.");
                }
                else if (command.ToLower().StartsWith("removeoperator"))
                {
                    if (Operators.ContainsKey(ulong.Parse(command.Substring(command.IndexOf(' ')))))
                    {
                        Operators.Remove(ulong.Parse(command.Substring(command.IndexOf(' '))));
                    }
                    Log(0, "Console", "Removed operator.");
                }
                else if (command.ToLower().StartsWith("pause") && !Paused)
                {
                    Paused = true;
                    Log(0, "Console", "Bot paused.");
                }
                else if (command.ToLower().StartsWith("resume") && Paused)
                {
                    Paused = false;
                    Log(0, "Console", "Bot resumed.");
                }
                else if (command.ToLower().StartsWith("restart"))
                {
                    Log(0, "Console", "Relaunching bot.");
                    Relaunch();
                }
            }

            // Completed, exit bot
            return(Task.CompletedTask);
        }