Пример #1
0
 public static async Task Reset(SocketMessage message, string[] arg, string msg)
 {
     if (RoleUtils.IsUserBotAdmin(message.Author.Id))
     {
         try
         {
             ConfigUtils.SetDefaults();
             ConfigUtils.Save(@"resources\config\config.json");
             await message.Channel.SendMessageAsync($":white_check_mark: `The configuration has been reset`");
         }
         catch
         {
             await message.Channel.SendMessageAsync($":no_entry: `Could not reload the configuration :/`");
         }
     }
     else
     {
         await message.Channel.SendMessageAsync($":no_entry: `Your KD is too low to execute this command...`");
     }
 }
Пример #2
0
        static async Task BotMain()
        {
            Logger.WriteLine("Welcome to DankBot !");

            if (!Directory.Exists(@"resources\config\"))
            {
                Directory.CreateDirectory(@"resources\config\");
            }
            if (!Directory.Exists(@"cache"))
            {
                Directory.CreateDirectory(@"cache");
            }

            if (!File.Exists(@"resources\config\config.json"))
            {
                Logger.Write("Generating configuration... ");
                try
                {
                    ConfigUtils.SetDefaults();
                    ConfigUtils.Save(@"resources\config\config.json");
                    Logger.OK();
                }
                catch
                {
                    Logger.FAILED();
                    Panic("Could not generate configuration file !");
                }
            }
            Logger.Write("Loading configuration...    ");
            try
            {
                ConfigUtils.Load(@"resources\config\config.json");
                Logger.OK();
            }
            catch (Exception ex)
            {
                Logger.FAILED();
                Panic(ex.Message);
            }

            Logger.Write("Starting discord client...  ");
            try
            {
                await client.LoginAsync(ConfigUtils.Configuration.TokenType, ConfigUtils.Configuration.BotToken);

                await client.StartAsync();

                await client.SetStatusAsync(UserStatus.Online);

                await client.SetGameAsync(ConfigUtils.Configuration.Playing);

                Logger.OK();
            }
            catch (Exception ex)
            {
                Logger.FAILED();
                Panic(ex.Message);
            }
            Logger.Write("Loading resources...        ");
            try
            {
                ResourceCache.Load();
                Logger.OK();
            }
            catch (Exception ex)
            {
                Logger.FAILED();
                Panic(ex.Message);
            }

            Logger.Write("Starting message handler... ");
            try
            {
                CommandManager.LoadCommands();
                client.MessageReceived += CommandManager.MessageReceived;
                Logger.OK();
            }
            catch (Exception ex)
            {
                Logger.FAILED();
                Panic(ex.Message);
            }

            Logger.Write("Enabling audio player...    ");
            try
            {
                Playlist.Enable();
                Logger.OK();
            }
            catch (Exception ex)
            {
                Logger.FAILED();
                Panic(ex.Message);
            }

            Logger.WriteLine("Ready.", ConsoleColor.Green);

            while (true)
            {
                Thread.Sleep(1000);
            }
        }