Skip to content

Commit 37f037c

Browse files
committed
Fixes giving of altruistic role
1 parent e19311c commit 37f037c

File tree

4 files changed

+34
-18
lines changed

4 files changed

+34
-18
lines changed

Tools/BiblioTech/Commands/CheckCidCommand.cs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
using System.Linq;
44
using System.Threading.Tasks;
55
using Discord;
6+
using BiblioTech.Rewards;
7+
using System.Data;
68

79
namespace BiblioTech.Commands
810
{
@@ -68,25 +70,17 @@ private async Task CheckAltruisticRole(CommandContext context, IUser user, strin
6870

6971
private async Task<bool> GiveAltruisticRole(CommandContext context, IUser user, string responseMessage)
7072
{
71-
var guildUser = context.Command.User as IGuildUser;
72-
if (guildUser != null)
73+
try
7374
{
74-
try
75-
{
76-
var role = context.Command.Guild.GetRole(Program.Config.AltruisticRoleId);
77-
if (role != null)
78-
{
79-
await guildUser.AddRoleAsync(role);
80-
await context.Followup($"{responseMessage}\n\nCongratulations! You've been granted the Altruistic Mode role for checking a valid CID!");
81-
return true;
82-
}
83-
}
84-
catch (Exception ex)
85-
{
86-
await Program.AdminChecker.SendInAdminChannel($"Failed to grant Altruistic Mode role to user {Mention(user)}: {ex.Message}");
87-
}
75+
await Program.RoleDriver.GiveAltruisticRole(user);
76+
await context.Followup($"{responseMessage}\n\nCongratulations! You've been granted the Altruistic Mode role for checking a valid CID!");
77+
return true;
78+
}
79+
catch (Exception ex)
80+
{
81+
await Program.AdminChecker.SendInAdminChannel($"Failed to grant Altruistic Mode role to user {Mention(user)}: {ex.Message}");
82+
return false;
8883
}
89-
return false;
9084
}
9185
}
9286

Tools/BiblioTech/LoggingRoleDriver.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using BiblioTech.Rewards;
2+
using Discord;
23
using DiscordRewards;
34
using Logging;
45
using Newtonsoft.Json;
@@ -14,6 +15,13 @@ public LoggingRoleDriver(ILog log)
1415
this.log = log;
1516
}
1617

18+
public async Task GiveAltruisticRole(IUser user)
19+
{
20+
await Task.CompletedTask;
21+
22+
log.Log($"Give altruistic role to {user.Id}");
23+
}
24+
1725
public async Task GiveRewards(GiveRewardsCommand rewards)
1826
{
1927
await Task.CompletedTask;

Tools/BiblioTech/Rewards/RewardController.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
using DiscordRewards;
1+
using Discord;
2+
using DiscordRewards;
23
using Microsoft.AspNetCore.Mvc;
34

45
namespace BiblioTech.Rewards
56
{
67
public interface IDiscordRoleDriver
78
{
89
Task GiveRewards(GiveRewardsCommand rewards);
10+
Task GiveAltruisticRole(IUser user);
911
}
1012

1113
[Route("api/[controller]")]

Tools/BiblioTech/Rewards/RoleDriver.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,18 @@ public async Task GiveRewards(GiveRewardsCommand rewards)
3434
await eventsSender.ProcessChainEvents(rewards.EventsOverview, rewards.Errors);
3535
}
3636

37+
public async Task GiveAltruisticRole(IUser user)
38+
{
39+
var guild = GetGuild();
40+
var role = guild.Roles.SingleOrDefault(r => r.Id == Program.Config.AltruisticRoleId);
41+
if (role == null) return;
42+
43+
var guildUser = guild.Users.SingleOrDefault(u => u.Id == user.Id);
44+
if (guildUser == null) return;
45+
46+
await guildUser.AddRoleAsync(role);
47+
}
48+
3749
private async Task ProcessRewards(GiveRewardsCommand rewards)
3850
{
3951
try

0 commit comments

Comments
 (0)