public async Task DeleteCharacterRoleAsync ( IRole discordRole ) { var getExistingRoleResult = await _characterRoles.GetCharacterRoleAsync(discordRole); if (!getExistingRoleResult.IsSuccess) { await _feedback.SendErrorAsync(this.Context, getExistingRoleResult.ErrorReason); return; } var deleteRoleResult = await _characterRoles.DeleteCharacterRoleAsync(getExistingRoleResult.Entity); if (!deleteRoleResult.IsSuccess) { await _feedback.SendErrorAsync(this.Context, deleteRoleResult.ErrorReason); return; } await _feedback.SendConfirmationAsync(this.Context, "Character role deleted."); }
public async Task SetCharacterRoleAsync ( [RequireEntityOwnerOrPermission(typeof(EditCharacter), PermissionTarget.Other)] Character character, IRole discordRole ) { var getRoleResult = await _characterRoles.GetCharacterRoleAsync(discordRole); if (!getRoleResult.IsSuccess) { await _feedback.SendErrorAsync(this.Context, getRoleResult.ErrorReason); return; } var commandInvoker = (IGuildUser)this.Context.User; var role = getRoleResult.Entity; if (role.Access == RoleAccess.Restricted) { if (!commandInvoker.GuildPermissions.ManageRoles) { await _feedback.SendErrorAsync ( this.Context, "That role is restricted, and you must be able to manage roles to use it." ); return; } } var owner = await this.Context.Guild.GetUserAsync((ulong)character.Owner.DiscordID); if (owner is null) { await _feedback.SendErrorAsync(this.Context, "Failed to get the owner as a guild user."); return; } var setRoleResult = await _characterRoles.SetCharacterRoleAsync(owner, character, role); if (!setRoleResult.IsSuccess) { await _feedback.SendErrorAsync(this.Context, setRoleResult.ErrorReason); return; } await _feedback.SendConfirmationAsync(this.Context, "Character role set."); }
public async Task <RuntimeResult> DeleteCharacterRoleAsync ( IRole discordRole ) { var getExistingRoleResult = await _characterRoles.GetCharacterRoleAsync(discordRole); if (!getExistingRoleResult.IsSuccess) { return(getExistingRoleResult.ToRuntimeResult()); } var deleteRoleResult = await _characterRoles.DeleteCharacterRoleAsync(getExistingRoleResult.Entity); if (!deleteRoleResult.IsSuccess) { return(deleteRoleResult.ToRuntimeResult()); } return(RuntimeCommandResult.FromSuccess("Character role deleted.")); }
public async Task <Result <FeedbackMessage> > DeleteCharacterRoleAsync(IRole discordRole) { var getExistingRoleResult = await _characterRoles.GetCharacterRoleAsync ( _context.GuildID.Value, discordRole.ID, this.CancellationToken ); if (!getExistingRoleResult.IsSuccess) { return(Result <FeedbackMessage> .FromError(getExistingRoleResult)); } var deleteRoleResult = await _characterRoles.DeleteCharacterRoleAsync ( getExistingRoleResult.Entity, this.CancellationToken ); return(!deleteRoleResult.IsSuccess ? Result <FeedbackMessage> .FromError(deleteRoleResult) : new FeedbackMessage("Character role deleted.", _feedback.Theme.Secondary)); }
public async Task <RuntimeResult> SetCharacterRoleAsync ( [RequireEntityOwnerOrPermission(typeof(EditCharacter), PermissionTarget.Other)] Character character, IRole discordRole ) { var getRoleResult = await _characterRoles.GetCharacterRoleAsync(discordRole); if (!getRoleResult.IsSuccess) { return(getRoleResult.ToRuntimeResult()); } var commandInvoker = (IGuildUser)this.Context.User; var role = getRoleResult.Entity; if (role.Access == RoleAccess.Restricted) { if (!commandInvoker.GuildPermissions.ManageRoles) { return(RuntimeCommandResult.FromError ( "That role is restricted, and you must be able to manage roles to use it." )); } } var owner = await this.Context.Guild.GetUserAsync((ulong)character.Owner.DiscordID); if (owner is null) { return(RuntimeCommandResult.FromError("Failed to get the owner as a guild user.")); } var setRoleResult = await _characterRoles.SetCharacterRoleAsync(owner, character, role); if (!setRoleResult.IsSuccess) { return(setRoleResult.ToRuntimeResult()); } return(RuntimeCommandResult.FromSuccess("Character role set.")); }
public async Task <Result <FeedbackMessage> > SetCharacterRoleAsync ( [RequireEntityOwner] [AutocompleteProvider("character::owned")] Character character, IRole discordRole ) { var getRoleResult = await _characterRoles.GetCharacterRoleAsync ( _context.GuildID.Value, discordRole.ID, this.CancellationToken ); if (!getRoleResult.IsSuccess) { return(Result <FeedbackMessage> .FromError(getRoleResult)); } // Get a bunch of stuff for permission checking... var getMember = await _guildAPI.GetGuildMemberAsync ( _context.GuildID.Value, _context.User.ID, this.CancellationToken ); if (!getMember.IsSuccess) { return(Result <FeedbackMessage> .FromError(getMember)); } var member = getMember.Entity; var getGuildRoles = await _guildAPI.GetGuildRolesAsync(_context.GuildID.Value, this.CancellationToken); if (!getGuildRoles.IsSuccess) { return(Result <FeedbackMessage> .FromError(getGuildRoles)); } var guildRoles = getGuildRoles.Entity; var everyoneRole = guildRoles.First(r => r.ID == _context.GuildID.Value); var memberRoles = guildRoles.Where(r => member.Roles.Contains(r.ID)).ToList(); // We ignore channel overrides here; the user should have it on a guild level var computedPermissions = DiscordPermissionSet.ComputePermissions ( _context.User.ID, everyoneRole, memberRoles ); var characterRole = getRoleResult.Entity; if (characterRole.Access == RoleAccess.Restricted) { if (!computedPermissions.HasPermission(DiscordPermission.ManageRoles)) { return(new UserError ( "That role is restricted, and you must be able to manage roles to use it." )); } } var setRoleResult = await _characterRoles.SetCharacterRoleAsync ( _context.GuildID.Value, _context.User.ID, character, characterRole, this.CancellationToken ); return(!setRoleResult.IsSuccess ? Result <FeedbackMessage> .FromError(setRoleResult) : new FeedbackMessage("Character role set.", _feedback.Theme.Secondary)); }
/// <summary> /// Drones the given user, creating a randomized sharkdrone character for them and forcing them into that form. /// </summary> /// <param name="guildUser">The user to drone.</param> /// <returns>A creation result which may or may not have succeeded.</returns> public async Task <CreateEntityResult <Character> > DroneUserAsync(IGuildUser guildUser) { var createGeneratedIdentity = await GenerateDroneIdentityAsync(guildUser); if (!createGeneratedIdentity.IsSuccess) { return(CreateEntityResult <Character> .FromError(createGeneratedIdentity)); } var(name, nickname) = createGeneratedIdentity.Entity; var generatedCharacterResult = await _characters.CreateCharacterAsync ( guildUser, name, _content.GetRandomDroneAvatarUri().ToString(), nickname, _content.GetRandomDroneSummary(), _content.GetRandomDroneDescription(), new FemininePronounProvider().Family ); if (!generatedCharacterResult.IsSuccess) { return(generatedCharacterResult); } var character = generatedCharacterResult.Entity; var droneRole = guildUser.Guild.Roles.FirstOrDefault ( r => r.Name.Contains("Drone") || r.Name.Contains("Dronies") ); if (!(droneRole is null)) { var getCharacterRole = await _characterRoles.GetCharacterRoleAsync(droneRole); if (getCharacterRole.IsSuccess) { var characterRole = getCharacterRole.Entity; var setCharacterRole = await _characterRoles.SetCharacterRoleAsync ( guildUser, character, characterRole ); if (!setCharacterRole.IsSuccess) { return(CreateEntityResult <Character> .FromError(setCharacterRole)); } } } var becomeCharacterResult = await _characters.MakeCharacterCurrentAsync(guildUser, character); if (!becomeCharacterResult.IsSuccess) { return(CreateEntityResult <Character> .FromError(becomeCharacterResult)); } return(character); }
/// <summary> /// Drones the given user, creating a randomized sharkdrone character for them and forcing them into that form. /// </summary> /// <param name="guildID">The ID of the guild the user is on.</param> /// <param name="userID">The ID of the user.</param> /// <param name="ct">The cancellation token in use.</param> /// <returns>A creation result which may or may not have succeeded.</returns> public async Task <Result <Character> > DroneUserAsync ( Snowflake guildID, Snowflake userID, CancellationToken ct = default ) { var createGeneratedIdentity = await GenerateDroneIdentityAsync(guildID, userID, ct); if (!createGeneratedIdentity.IsSuccess) { return(Result <Character> .FromError(createGeneratedIdentity)); } var(name, nickname) = createGeneratedIdentity.Entity; var generatedCharacterResult = await _characters.CreateCharacterAsync ( guildID, userID, name, _content.GetRandomDroneAvatarUri().ToString(), nickname, _content.GetRandomDroneSummary(), _content.GetRandomDroneDescription(), new FemininePronounProvider().Family, ct ); if (!generatedCharacterResult.IsSuccess) { return(generatedCharacterResult); } var character = generatedCharacterResult.Entity; var getGuildRoles = await _guildAPI.GetGuildRolesAsync(guildID, ct); if (!getGuildRoles.IsSuccess) { return(Result <Character> .FromError(getGuildRoles)); } var guildRoles = getGuildRoles.Entity; var droneRole = guildRoles.FirstOrDefault ( r => r.Name.Contains("Drone") || r.Name.Contains("Dronies") ); if (droneRole is not null) { var getCharacterRole = await _characterRoles.GetCharacterRoleAsync(guildID, droneRole.ID, ct); if (getCharacterRole.IsSuccess) { var characterRole = getCharacterRole.Entity; var setCharacterRole = await _characterRoles.SetCharacterRoleAsync ( guildID, userID, character, characterRole, ct ); if (!setCharacterRole.IsSuccess) { return(Result <Character> .FromError(setCharacterRole)); } } } var becomeCharacterResult = await _characters.MakeCharacterCurrentAsync(guildID, userID, character, ct); return(!becomeCharacterResult.IsSuccess ? Result <Character> .FromError(becomeCharacterResult) : character); }