Пример #1
0
        public static Task LogMessageInfo(LogMessage message)
        {
            var messagestr = message.ToString();

            if (message.ToString().StartsWith("Unknown OpCode (8)") ||
                message.ToString().Contains("VOICE_STATE_UPDATE"))
            {
                return(Task.CompletedTask);
            }
            var msg = messagestr.Substring(21, messagestr.Length - 21);

            ColourLog.In2("PassiveBOT", '?', $"{msg}", Color.Chartreuse);
            return(Task.CompletedTask);
        }
Пример #2
0
        private async Task Client_Ready()
        {
            var application = await Client.GetApplicationInfoAsync();

            await ColourLog.In1Run(
                $"Invite: https://discordapp.com/oauth2/authorize?client_id={application.Id}&scope=bot&permissions=2146958591");

            var k = JsonConvert.DeserializeObject <List <string> >(
                File.ReadAllText(Path.Combine(AppContext.BaseDirectory, "setup/keys.json")));

            if (k.Count > 0)
            {
                Keys = k;
            }
        }
Пример #3
0
        public static void CheckExistence()
        {
            bool auto;

            try
            {
                auto = Load().AutoRun;
            }
            catch
            {
                auto = false;
            }
            if (auto)
            {
            }
            else
            {
                ColourLog.In1Run("Run (Y for run, N for setup Config)");

                Console.Write("Y or N: ");
                var res = Console.ReadLine();
                if (res == "N" || res == "n")
                {
                    File.Delete("setup/config/config.json");
                }

                if (!Directory.Exists(Path.Combine(AppContext.BaseDirectory, "setup/config")))
                {
                    Directory.CreateDirectory(Path.Combine(AppContext.BaseDirectory, "setup/config"));
                }
            }


            if (!File.Exists(ConfigPath))
            {
                var cfg = new Config();

                ColourLog.In1Run(
                    @"Please enter a prefix for the bot eg. '+' (do not include the '' outside of the prefix)");
                Console.Write("Prefix: ");
                cfg.Prefix             = Console.ReadLine();
                Configuration.Load.Pre = cfg.Prefix;

                ColourLog.In1Run("Would you like to log debug?");
                Console.Write("Yes or No: ");
                var type = Console.ReadLine();
                if (type != null && (type.StartsWith("y") || type.StartsWith("Y")))
                {
                    type = "Y";
                }
                else
                {
                    type = "N";
                }
                cfg.Debug = type;

                ColourLog.In1Run(
                    @"To enable the twitch commands, please enter a twitch api token, otherwise hit enter to continue");
                Console.Write("Token: ");
                cfg.twitchtoken = Console.ReadLine();

                ColourLog.In1Run(
                    @"After you input your token, a config will be generated at 'setup/config/config.json'");
                Console.Write("Token: ");
                cfg.Token = Console.ReadLine();


                ColourLog.In1Run("Would you like to AutoRun the bot from now on? Y/N");
                var type2 = Console.ReadLine();
                if (type2 != null && (type2.StartsWith("y") || type2.StartsWith("Y")))
                {
                    cfg.AutoRun = true;
                }
                else
                {
                    cfg.AutoRun = false;
                }

                cfg.Save();
            }
            else
            {
                Configuration.Load.Pre = Load().Prefix;
            }
            ColourLog.In1Run("Config Loaded!");
            ColourLog.In1Run($"Prefix: {Load().Prefix}");
            ColourLog.In1Run($"Debug: {Load().Debug}");
            ColourLog.In1Run($"Token Length: {Load().Token.Length} (should be 59)");
            ColourLog.In1Run($"Autorun: {Load().AutoRun}");
        }
Пример #4
0
        public async Task Start()
        {
            Console.Title = $"PassiveBOT v{Load.Version}";
            Console.WriteLine(
                "██████╗  █████╗ ███████╗███████╗██╗██╗   ██╗███████╗██████╗  ██████╗ ████████╗\n" +
                "██╔══██╗██╔══██╗██╔════╝██╔════╝██║██║   ██║██╔════╝██╔══██╗██╔═══██╗╚══██╔══╝\n" +
                "██████╔╝███████║███████╗███████╗██║██║   ██║█████╗  ██████╔╝██║   ██║   ██║   \n" +
                "██╔═══╝ ██╔══██║╚════██║╚════██║██║╚██╗ ██╔╝██╔══╝  ██╔══██╗██║   ██║   ██║   \n" +
                "██║     ██║  ██║███████║███████║██║ ╚████╔╝ ███████╗██████╔╝╚██████╔╝   ██║   \n" +
                "╚═╝     ╚═╝  ╚═╝╚══════╝╚══════╝╚═╝  ╚═══╝  ╚══════╝╚═════╝  ╚═════╝    ╚═╝   \n" +
                "/--------------------------------------------------------------------------\\ \n" +
                "| Designed by PassiveModding - PassiveNation.com  ||   Status: Connected   | \n" +
                "\\--------------------------------------------------------------------------/ \n");

            if (!Directory.Exists(Path.Combine(AppContext.BaseDirectory, "setup/")))
            {
                Directory.CreateDirectory(Path.Combine(AppContext.BaseDirectory, "setup/"));
            }
            if (!Directory.Exists(Path.Combine(AppContext.BaseDirectory, "setup/config/")))
            {
                Directory.CreateDirectory(Path.Combine(AppContext.BaseDirectory, "setup/config/"));
            }
            if (!Directory.Exists(Path.Combine(AppContext.BaseDirectory, "setup/server/")))
            {
                Directory.CreateDirectory(Path.Combine(AppContext.BaseDirectory, "setup/server/"));
            }
            if (!File.Exists(Path.Combine(AppContext.BaseDirectory, "setup/config/home.json")))
            {
                File.Create(Path.Combine(AppContext.BaseDirectory, "setup/config/home.json")).Dispose();
            }
            Config.CheckExistence();
            var prefix = Config.Load().Prefix;
            var debug  = Config.Load().Debug.ToUpper();
            var token  = Config.Load().Token;

            var ll = LogSeverity.Info;

            switch (debug)
            {
            case "Y":
                ll = LogSeverity.Debug;
                break;

            case "N":
                ll = LogSeverity.Info;
                break;

            default:
                await ColourLog.In1Run($"Error Loading Debug Config, Set to default (Entry = {debug})");

                break;
            }


            Client = new DiscordSocketClient(new DiscordSocketConfig
            {
                LogLevel         = ll,
                MessageCacheSize = 500
            });

            try
            {
                await Client.LoginAsync(TokenType.Bot, token);

                await Client.StartAsync();
            }
            catch (Exception e)
            {
                await ColourLog.In1Run("Token was rejected by Discord (Invalid Token or Connection Error)\n" +
                                       $"{e}");
            }

            var serviceProvider = ConfigureServices();

            _handler = new CommandHandler(serviceProvider);
            // ReSharper disable once ObjectCreationAsStatement
            new EventHandler(serviceProvider);
            await _handler.ConfigureAsync();

            //checks if the user wants to log debug info or not
            if (ll == LogSeverity.Debug)
            {
                Client.Log += LogDebug;
            }
            else
            {
                Client.Log += LogMessageInfo;
            }

            Client.Ready += Client_Ready;

            //setgame loop
            await Task.Delay(5000);

            string[] gametitle =
            {
                $"{prefix}help / Heap: {GetHeapSize()}MB",
                $"{prefix}help / {Load.Gamesite}",
                $"{prefix}help / v{Load.Version}"
            };
            while (true)
            {
                var rnd    = new Random();
                var result = rnd.Next(0, gametitle.Length);
                await Client.SetGameAsync($"{gametitle[result]}");

                await ColourLog.In3("PassiveBOT", 'B', "SetGame", 'R', $"{gametitle[result]}",
                                    Color.GreenYellow);

                await Task.Delay(3600000);
            }
            // ReSharper disable once FunctionNeverReturns
        }
Пример #5
0
 public static Task LogDebug(LogMessage msg)
 {
     ColourLog.Debug(msg.ToString());
     return(Task.CompletedTask);
 }