diff --git a/Tools/BiblioTech/Commands/CheckCidCommand.cs b/Tools/BiblioTech/Commands/CheckCidCommand.cs index cd47c7f9..a2314280 100644 --- a/Tools/BiblioTech/Commands/CheckCidCommand.cs +++ b/Tools/BiblioTech/Commands/CheckCidCommand.cs @@ -3,6 +3,8 @@ using System.IO; using System.Linq; using System.Threading.Tasks; using Discord; +using BiblioTech.Rewards; +using System.Data; namespace BiblioTech.Commands { @@ -68,25 +70,17 @@ namespace BiblioTech.Commands private async Task GiveAltruisticRole(CommandContext context, IUser user, string responseMessage) { - var guildUser = context.Command.User as IGuildUser; - if (guildUser != null) + try { - try - { - var role = context.Command.Guild.GetRole(Program.Config.AltruisticRoleId); - if (role != null) - { - await guildUser.AddRoleAsync(role); - await context.Followup($"{responseMessage}\n\nCongratulations! You've been granted the Altruistic Mode role for checking a valid CID!"); - return true; - } - } - catch (Exception ex) - { - await Program.AdminChecker.SendInAdminChannel($"Failed to grant Altruistic Mode role to user {Mention(user)}: {ex.Message}"); - } + await Program.RoleDriver.GiveAltruisticRole(user); + await context.Followup($"{responseMessage}\n\nCongratulations! You've been granted the Altruistic Mode role for checking a valid CID!"); + return true; + } + catch (Exception ex) + { + await Program.AdminChecker.SendInAdminChannel($"Failed to grant Altruistic Mode role to user {Mention(user)}: {ex.Message}"); + return false; } - return false; } } diff --git a/Tools/BiblioTech/LoggingRoleDriver.cs b/Tools/BiblioTech/LoggingRoleDriver.cs index 9275a7a5..f5435523 100644 --- a/Tools/BiblioTech/LoggingRoleDriver.cs +++ b/Tools/BiblioTech/LoggingRoleDriver.cs @@ -1,4 +1,5 @@ using BiblioTech.Rewards; +using Discord; using DiscordRewards; using Logging; using Newtonsoft.Json; @@ -14,6 +15,13 @@ namespace BiblioTech this.log = log; } + public async Task GiveAltruisticRole(IUser user) + { + await Task.CompletedTask; + + log.Log($"Give altruistic role to {user.Id}"); + } + public async Task GiveRewards(GiveRewardsCommand rewards) { await Task.CompletedTask; diff --git a/Tools/BiblioTech/Rewards/RewardController.cs b/Tools/BiblioTech/Rewards/RewardController.cs index c9a19dea..3a20a084 100644 --- a/Tools/BiblioTech/Rewards/RewardController.cs +++ b/Tools/BiblioTech/Rewards/RewardController.cs @@ -1,4 +1,5 @@ -using DiscordRewards; +using Discord; +using DiscordRewards; using Microsoft.AspNetCore.Mvc; namespace BiblioTech.Rewards @@ -6,6 +7,7 @@ namespace BiblioTech.Rewards public interface IDiscordRoleDriver { Task GiveRewards(GiveRewardsCommand rewards); + Task GiveAltruisticRole(IUser user); } [Route("api/[controller]")] diff --git a/Tools/BiblioTech/Rewards/RoleDriver.cs b/Tools/BiblioTech/Rewards/RoleDriver.cs index b3bf7079..fd5cde8e 100644 --- a/Tools/BiblioTech/Rewards/RoleDriver.cs +++ b/Tools/BiblioTech/Rewards/RoleDriver.cs @@ -34,6 +34,18 @@ namespace BiblioTech.Rewards await eventsSender.ProcessChainEvents(rewards.EventsOverview, rewards.Errors); } + public async Task GiveAltruisticRole(IUser user) + { + var guild = GetGuild(); + var role = guild.Roles.SingleOrDefault(r => r.Id == Program.Config.AltruisticRoleId); + if (role == null) return; + + var guildUser = guild.Users.SingleOrDefault(u => u.Id == user.Id); + if (guildUser == null) return; + + await guildUser.AddRoleAsync(role); + } + private async Task ProcessRewards(GiveRewardsCommand rewards) { try