public async Task Handle(PublishRichToGuildChannel message, IMessageHandlerContext context)
    {
        int?color = null;

        if (_env.IsDevelopment())
        {
            color = 14177041;
        }

        try
        {
            await _discordClient.ChannelMessagePost(message.ChannelId, new DiscordClient.RichEmbed(message.Title, message.Description, color));
        }
        catch (HttpRequestException hre) when(hre.StatusCode == HttpStatusCode.Forbidden)
        {
            // Scenarios:
            // - Setup a subscription in a channel without giving the bot permissions (fplbot role needs access)
            _logger.LogWarning("Unauthorized to post to Discord channel {channel}", message.ChannelId);
        }
        catch (HttpRequestException hre) when(hre.StatusCode == HttpStatusCode.NotFound)
        {
            // Scenarios:
            // - Deleted channel?
            _logger.LogWarning("Discord channel {channel} not found", message.ChannelId);
        }
    }
Exemple #2
0
    public async Task Handle(FixtureRemovedFromGameweek message, IMessageHandlerContext context)
    {
        _logger.LogInformation("Fixture removed from gameweek {Message}", message);
        var subs = await _guildRepo.GetAllGuildSubscriptions();

        foreach (var sub in subs)
        {
            if (sub.Subscriptions.ContainsSubscriptionFor(EventSubscription.FixtureRemovedFromGameweek))
            {
                var options = new SendOptions();
                options.RequireImmediateDispatch();
                options.RouteToThisEndpoint();
                var formattedMsg = new PublishRichToGuildChannel(sub.GuildId,
                                                                 sub.ChannelId,
                                                                 $"❌ Fixture off!",
                                                                 $"{message.RemovedFixture.Home.Name}-{message.RemovedFixture.Away.Name}" +
                                                                 $" has been removed from gameweek {message.Gameweek}!");
                await context.Send(formattedMsg, options);
            }
        }
    }