Beispiel #1
0
        /// <summary>
        /// Starts the <see cref="CoinBot"/>.
        /// </summary>
        /// <param name="provider">The <see cref="IServiceProvider"/>.</param>
        /// <returns></returns>
        private static async Task Run(IServiceProvider provider)
        {
            //set up a task completion source so we can quit on CTRL+C
            TaskCompletionSource <bool> exitSource = new TaskCompletionSource <bool>();

            Console.CancelKeyPress += (sender, eventArgs) =>
            {
                eventArgs.Cancel = true;
                exitSource.SetResult(true);
            };

            CurrencyManager coinManager   = provider.GetRequiredService <CurrencyManager>();
            MarketManager   marketManager = provider.GetRequiredService <MarketManager>();
            DiscordBot      bot           = provider.GetRequiredService <DiscordBot>();

            // Initialize the bot
            DiscordBotSettings botConfig = provider.GetRequiredService <IOptions <DiscordBotSettings> >().Value;
            await bot.LoginAsync(TokenType.Bot, botConfig.Token);

            // Start the bot & coinSource
            await bot.StartAsync();

            coinManager.Start();
            marketManager.Start();

            // Keep the application alive until the exitSource task is completed.
            await exitSource.Task;

            // Stop the bot & coinSource
            await bot.LogoutAsync();

            coinManager.Stop();
            marketManager.Stop();
        }
Beispiel #2
0
        private DiscordBotSettings GetTokenFromConsole()
        {
            Console.WriteLine("\nToken has not yet been saved.");
            Console.Write("Please enter the bot's token: ");
            var token = Console.ReadLine();

            DiscordBotSettings settings = new DiscordBotSettings {
                Token = token, Game = "https://github.com/JoyfulReaper"
            };

            _discordBotSettingsRepository.AddAsync(settings);

            return(settings);
        }
Beispiel #3
0
        /// <summary>
        ///     Starts the <see cref="CoinBot" />.
        /// </summary>
        /// <param name="provider">The <see cref="IServiceProvider" />.</param>
        /// <returns></returns>
        private static async Task RunAsync(IServiceProvider provider)
        {
            ILoggerFactory loggerFactory = provider.GetRequiredService <ILoggerFactory>();

            loggerFactory.AddSerilog();

            //set up a task completion source so we can quit on CTRL+C
            TaskCompletionSource <bool> exitSource = new();

            Console.CancelKeyPress += (_, eventArgs) =>
            {
                eventArgs.Cancel = true;
                exitSource.SetResult(result: true);
            };
            await provider.AddCommandsAsync();

            MarketManager marketManager = provider.GetRequiredService <MarketManager>();
            DiscordBot    bot           = provider.GetRequiredService <DiscordBot>();

            // Initialize the bot
            DiscordBotSettings botConfig = provider.GetRequiredService <IOptions <DiscordBotSettings> >()
                                           .Value;
            await bot.LoginAsync(tokenType : TokenType.Bot, token : botConfig.Token);

            // Start the bot & coinSource
            await bot.StartAsync();

            marketManager.Start();

            // Keep the application alive until the exitSource task is completed.
            await exitSource.Task;

            // Stop the bot & coinSource
            await bot.LogoutAsync();

            marketManager.Stop();
        }