public async Task <ActionResult <DSharpPlus.Entities.DiscordGuild> > GetAsync(string userId) { var userResult = await _discordBotService.GetUserByDiscordId(userId); if (userResult == null) { return(NotFound()); } var guildResult = await _discordBotService.GetGuild(userResult.Id); return((guildResult != null) ? Ok(guildResult.Roles) : (ActionResult)NotFound()); }
public async Task <ActionResult <DSharpPlus.Entities.DiscordGuild> > PutAsync(string userId, DiscordAppRole appRole) { var user = await _discordBotService.GetUserByDiscordId(userId); if (user == null) { return(NotFound()); } var guildMember = await _discordBotService.GetGuild(user.Id); if (guildMember == null) { return(NotFound()); } var projectsResult = _userService.GetProjectsByByDiscordId(userId); if (projectsResult.IsFailure) { return(NotFound()); } var guild = await _discordBotService.GetGuild(); if (guild == null) { return(NotFound()); } var roleName = $"{appRole.AppName} {appRole.SubRole}"; var role = guild.Roles.FirstOrDefault(x => x.Value.Name.Equals(roleName, StringComparison.OrdinalIgnoreCase)).Value; if (role == null) { role = await guild.CreateRoleAsync(roleName, null, new DiscordColor(appRole.Color), null, true); } return((guildMember != null) ? Ok(guildMember.Roles) : (ActionResult)NotFound()); }
private async Task <string> GetRole(string role) { var guild = await _discordBotService.GetGuild(); var discordRole = guild.Roles.FirstOrDefault(x => x.Value.Name.Equals(role, StringComparison.OrdinalIgnoreCase)).Value; if (discordRole == null) { return("Not found"); } var numberOfMembers = guild.Members.Count( x => x.Value.Roles.Any( x => x.Equals(discordRole))); var dateRoleCreated = discordRole.CreationTimestamp.ToString(); var mentionable = discordRole.IsMentionable; return($"Member count: {numberOfMembers}" + Environment.NewLine + $"Date created: {dateRoleCreated}" + Environment.NewLine + $"Mentionable: {mentionable}"); }