Sets up showing of chain events in discord bot

This commit is contained in:
benbierens 2024-04-08 13:55:39 +02:00
parent 9f7e95c515
commit 0b2dcef57e
No known key found for this signature in database
GPG Key ID: 877D2C2E09A22F3A
3 changed files with 23 additions and 4 deletions

View File

@ -4,6 +4,7 @@
{
public RewardUsersCommand[] Rewards { get; set; } = Array.Empty<RewardUsersCommand>();
public MarketAverage[] Averages { get; set; } = Array.Empty<MarketAverage>();
public string[] EventsOverview { get; set; } = Array.Empty<string>();
}
public class RewardUsersCommand

View File

@ -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;

View File

@ -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<Dictionary<ulong, IGuildUser>> LoadAllUsers(SocketGuild guild)