Example #1
0
        private async Task MainAsync()
        {
            Console.Title = "Syncord";

            Console.WriteLine($"Syncord Plugin Version >>{Assembly.GetExecutingAssembly().GetName().Version}<<");

            if (!Directory.Exists("logs"))
            {
                Directory.CreateDirectory("logs");
            }

            //Instantiate Logger
            _logger = new LoggerConfiguration()
                      .WriteTo.Console()
                      .WriteTo.File("logs/log.txt",
                                    rollingInterval: RollingInterval.Hour,
                                    rollOnFileSizeLimit: true,
                                    retainedFileCountLimit: 24)
                      .CreateLogger();

            //Load Discord Bot Configs
            LoadConfigs();

            random = new Random();

            PresenceString = BotConfig.DiscordActivity.Name;

            _logger.Information($"Loaded Translation: {TranslationConfig.Translation.Language}.");

            //Instantiate EasyHost
            TcpServer = new SimpleTcpServer("0.0.0.0", BotConfig.Port);
            TcpServer.Settings.StreamBufferSize = 16384;

            await SetupDiscordClient();

            //Adding Singletons of the Bot & EasyHost
            _service = new ServiceCollection()
                       .AddSingleton(this)
                       .AddSingleton(TcpServer)
                       .BuildServiceProvider();

            LoadCommands();

            //Fire and forget
            new Task(async() => await UpdatePresence()).Start();

            //Instatiate CommunicationHandler
            CommunicationHandler = new CommunicationHandler(TcpServer, this, _logger);

            await CommunicationHandler.CreateChannelEmbedQueues();

            await Task.Delay(-1);
        }