using Discord; using DiscordRewards; using Microsoft.AspNetCore.Mvc; namespace BiblioTech.Rewards { /// /// We like callbacks in this interface because we're trying to batch role-modifying operations, /// So that we're not poking the server lots of times very quickly. /// public interface IDiscordRoleDriver { Task RunRoleGiver(Func action); Task IterateUsersWithRoles(Func onUserWithRole, params ulong[] rolesToIterate); Task IterateUsersWithRoles(Func onUserWithRole, Func whenDone, params ulong[] rolesToIterate); } public interface IRoleGiver { Task GiveAltruisticRole(ulong userId); Task GiveActiveP2pParticipant(ulong userId); Task RemoveActiveP2pParticipant(ulong userId); Task GiveActiveHost(ulong userId); Task RemoveActiveHost(ulong userId); Task GiveActiveClient(ulong userId); Task RemoveActiveClient(ulong userId); } [Route("api/[controller]")] [ApiController] public class RewardController : ControllerBase { [HttpGet] public string Ping() { return "Pong"; } [HttpPost] public async Task Give(EventsAndErrors cmd) { Program.Dispatcher.Add(() => { Program.ChainActivityHandler.ProcessChainActivity(cmd.ActiveChainAddresses).Wait(); }); Program.Dispatcher.Add(() => { Program.EventsSender.ProcessChainEvents(cmd.EventsOverview, cmd.Errors).Wait(); }); await Task.CompletedTask; return "OK"; } } }