Sets up showing of chain events in discord bot
This commit is contained in:
parent
9f7e95c515
commit
0b2dcef57e
|
@ -4,6 +4,7 @@
|
||||||
{
|
{
|
||||||
public RewardUsersCommand[] Rewards { get; set; } = Array.Empty<RewardUsersCommand>();
|
public RewardUsersCommand[] Rewards { get; set; } = Array.Empty<RewardUsersCommand>();
|
||||||
public MarketAverage[] Averages { get; set; } = Array.Empty<MarketAverage>();
|
public MarketAverage[] Averages { get; set; } = Array.Empty<MarketAverage>();
|
||||||
|
public string[] EventsOverview { get; set; } = Array.Empty<string>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public class RewardUsersCommand
|
public class RewardUsersCommand
|
||||||
|
|
|
@ -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.")]
|
[Uniform("rewards-channel-name", "rc", "REWARDSCHANNELNAME", false, "Name of the Discord server channel where participation rewards will be announced.")]
|
||||||
public string RewardsChannelName { get; set; } = "";
|
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.")]
|
[Uniform("reward-api-port", "rp", "REWARDAPIPORT", false, "TCP listen port for the reward API.")]
|
||||||
public int RewardApiPort { get; set; } = 31080;
|
public int RewardApiPort { get; set; } = 31080;
|
||||||
|
|
||||||
|
|
|
@ -9,16 +9,15 @@ namespace BiblioTech.Rewards
|
||||||
{
|
{
|
||||||
private readonly DiscordSocketClient client;
|
private readonly DiscordSocketClient client;
|
||||||
private readonly SocketTextChannel? rewardsChannel;
|
private readonly SocketTextChannel? rewardsChannel;
|
||||||
|
private readonly SocketTextChannel? eventsChannel;
|
||||||
private readonly RewardRepo repo = new RewardRepo();
|
private readonly RewardRepo repo = new RewardRepo();
|
||||||
|
|
||||||
public RoleDriver(DiscordSocketClient client)
|
public RoleDriver(DiscordSocketClient client)
|
||||||
{
|
{
|
||||||
this.client = client;
|
this.client = client;
|
||||||
|
|
||||||
if (!string.IsNullOrEmpty(Program.Config.RewardsChannelName))
|
rewardsChannel = GetChannel(Program.Config.RewardsChannelName);
|
||||||
{
|
eventsChannel = GetChannel(Program.Config.ChainEventsChannelName);
|
||||||
rewardsChannel = GetGuild().TextChannels.SingleOrDefault(c => c.Name == Program.Config.RewardsChannelName);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task GiveRewards(GiveRewardsCommand rewards)
|
public async Task GiveRewards(GiveRewardsCommand rewards)
|
||||||
|
@ -34,6 +33,22 @@ namespace BiblioTech.Rewards
|
||||||
rewardsChannel);
|
rewardsChannel);
|
||||||
|
|
||||||
await context.ProcessGiveRewardsCommand(LookUpUsers(rewards));
|
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)
|
private async Task<Dictionary<ulong, IGuildUser>> LoadAllUsers(SocketGuild guild)
|
||||||
|
|
Loading…
Reference in New Issue