From 0b2dcef57e05331600ec5d42121950aa0d2d6980 Mon Sep 17 00:00:00 2001 From: benbierens Date: Mon, 8 Apr 2024 13:55:39 +0200 Subject: [PATCH] Sets up showing of chain events in discord bot --- .../DiscordRewards/GiveRewardsCommand.cs | 1 + Tools/BiblioTech/Configuration.cs | 3 +++ Tools/BiblioTech/Rewards/RoleDriver.cs | 23 +++++++++++++++---- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/Framework/DiscordRewards/GiveRewardsCommand.cs b/Framework/DiscordRewards/GiveRewardsCommand.cs index 0fd7a0f..9617633 100644 --- a/Framework/DiscordRewards/GiveRewardsCommand.cs +++ b/Framework/DiscordRewards/GiveRewardsCommand.cs @@ -4,6 +4,7 @@ { public RewardUsersCommand[] Rewards { get; set; } = Array.Empty(); public MarketAverage[] Averages { get; set; } = Array.Empty(); + public string[] EventsOverview { get; set; } = Array.Empty(); } public class RewardUsersCommand diff --git a/Tools/BiblioTech/Configuration.cs b/Tools/BiblioTech/Configuration.cs index 2183a54..37e1cc3 100644 --- a/Tools/BiblioTech/Configuration.cs +++ b/Tools/BiblioTech/Configuration.cs @@ -22,6 +22,9 @@ namespace BiblioTech [Uniform("rewards-channel-name", "rc", "REWARDSCHANNELNAME", false, "Name of the Discord server channel where participation rewards will be announced.")] public string RewardsChannelName { get; set; } = ""; + [Uniform("chain-events-channel-name", "cc", "CHAINEVENTSCHANNELNAME", false, "Name of the Discord server channel where chain events will be posted.")] + public string ChainEventsChannelName { get; set; } = ""; + [Uniform("reward-api-port", "rp", "REWARDAPIPORT", false, "TCP listen port for the reward API.")] public int RewardApiPort { get; set; } = 31080; diff --git a/Tools/BiblioTech/Rewards/RoleDriver.cs b/Tools/BiblioTech/Rewards/RoleDriver.cs index 182dbf8..2afff6e 100644 --- a/Tools/BiblioTech/Rewards/RoleDriver.cs +++ b/Tools/BiblioTech/Rewards/RoleDriver.cs @@ -9,16 +9,15 @@ namespace BiblioTech.Rewards { private readonly DiscordSocketClient client; private readonly SocketTextChannel? rewardsChannel; + private readonly SocketTextChannel? eventsChannel; private readonly RewardRepo repo = new RewardRepo(); public RoleDriver(DiscordSocketClient client) { this.client = client; - if (!string.IsNullOrEmpty(Program.Config.RewardsChannelName)) - { - rewardsChannel = GetGuild().TextChannels.SingleOrDefault(c => c.Name == Program.Config.RewardsChannelName); - } + rewardsChannel = GetChannel(Program.Config.RewardsChannelName); + eventsChannel = GetChannel(Program.Config.ChainEventsChannelName); } public async Task GiveRewards(GiveRewardsCommand rewards) @@ -34,6 +33,22 @@ namespace BiblioTech.Rewards rewardsChannel); await context.ProcessGiveRewardsCommand(LookUpUsers(rewards)); + await ProcessChainEvents(rewards.EventsOverview); + } + + private SocketTextChannel? GetChannel(string name) + { + if (string.IsNullOrEmpty(name)) return null; + return GetGuild().TextChannels.SingleOrDefault(c => c.Name == name); + } + + private async Task ProcessChainEvents(string[] eventsOverview) + { + if (eventsChannel == null || eventsOverview == null || !eventsOverview.Any()) return; + foreach (var e in eventsOverview) + { + await eventsChannel.SendMessageAsync(e); + } } private async Task> LoadAllUsers(SocketGuild guild)