예제 #1
0
    /// <summary>
    ///     Hosted service implementing the lifetime of the bot
    /// </summary>
    /// <param name="loggerFactory">Logfactory used</param>
    /// <param name="runner">The botrunner used</param>
    public BotService(
        ILoggerFactory loggerFactory,
        IBotRunner runner
        )
    {
        _logger        = loggerFactory.CreateLogger <BotService>();
        _loggerFactory = loggerFactory;
        _botRunner     = runner;

        _logger.LogInformation("Initialize BotService..");

        // Todo: Decouple the Discord service to able to use in other chats
        _discordClient = new DiscordClient(new DiscordConfiguration
        {
            Token     = Environment.GetEnvironmentVariable("DISCORD_TOKEN"),
            TokenType = TokenType.Bot
        });

        var botChannel = Environment.GetEnvironmentVariable("DISCORD_BOTCHANNEL");

        if (ulong.TryParse(botChannel, out var channelId))
        {
            _botChannel = channelId;
        }

        _discordClient.MessageCreated += OnMessageCreated;
    }