mirror of
https://github.com/logos-storage/logos-storage-nim-cs-dist-tests.git
synced 2026-05-28 20:19:40 +00:00
Fixes giving of altruistic role
This commit is contained in:
parent
e19311cef9
commit
37f037c7b0
@ -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<bool> 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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -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]")]
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user