Esempio n. 1
0
        public async Task RunBot()
        {
            try
            {
                BotConfig = new BotConfig();
                var botCResult = BotConfig.LoadCredConfig();
                BotConfig.SaveCredConfig();

                #region 4chan Setup
                ChanData = new ChanDataStore();
                ChanData.Load();
                ChanData.Save();
                ChanThread = new ChanUpdateThread();
                ChanThread.Start();
                #endregion

                #region Discord Client
                //create new discord client and log
                Client = new DiscordSocketClient(new DiscordSocketConfig()
                {
                    MessageCacheSize  = 10,
                    ConnectionTimeout = int.MaxValue,
                    LogLevel          = LogSeverity.Warning,
                    WebSocketProvider = WS4NetProvider.Instance,
                });
                Client.Connected    += OnConnected;
                Client.Disconnected += OnDisconnected;
                Client.Log          += (message) =>
                {
                    Console.WriteLine($"Discord Error:{message.ToString()}");
                    ErrorLog.WriteLog($"Discord Error:{message.ToString()}");
                    return(Task.CompletedTask);
                };
                await Client.LoginAsync(TokenType.Bot, BotConfig.BotInfo.Token);

                await Client.StartAsync();

                #endregion

                //Delay until application quit
                await Task.Delay(-1);

                #region Cleanup
                ChanThread.Stop();
                #endregion

                Console.WriteLine("Exiting");
            }
            catch (Exception ex)
            {
                ErrorLog.WriteError(ex);
                return;
            }
        }