public async Task <RuntimeResult> SetCharacterDescriptionAsync ( [RequireEntityOwnerOrPermission(typeof(EditCharacter), PermissionTarget.Other)] Character character, string?newCharacterDescription = null ) { if (newCharacterDescription is null) { if (!this.Context.Message.Attachments.Any()) { return(RuntimeCommandResult.FromError ( "You need to attach a plaintext document or provide an in-message description." )); } var newDescription = this.Context.Message.Attachments.First(); var getAttachmentStreamResult = await _discord.GetAttachmentStreamAsync(newDescription); if (!getAttachmentStreamResult.IsSuccess) { return(getAttachmentStreamResult.ToRuntimeResult()); } using var sr = new StreamReader(getAttachmentStreamResult.Entity); newCharacterDescription = await sr.ReadToEndAsync(); } var setDescriptionResult = await _characters.SetCharacterDescriptionAsync ( character, newCharacterDescription ); if (!setDescriptionResult.IsSuccess) { return(setDescriptionResult.ToRuntimeResult()); } return(RuntimeCommandResult.FromSuccess("Character description set.")); }
public async Task SetCharacterDescriptionAsync ( [RequireEntityOwnerOrPermission(typeof(EditCharacter), PermissionTarget.Other)] Character character, string?newCharacterDescription = null ) { if (newCharacterDescription is null) { if (!this.Context.Message.Attachments.Any()) { await _feedback.SendErrorAsync(this.Context, "You need to attach a plaintext document or provide an in-message description."); return; } var newDescription = this.Context.Message.Attachments.First(); var getAttachmentStreamResult = await _discord.GetAttachmentStreamAsync(newDescription); if (!getAttachmentStreamResult.IsSuccess) { await _feedback.SendErrorAsync(this.Context, getAttachmentStreamResult.ErrorReason); return; } using var sr = new StreamReader(getAttachmentStreamResult.Entity); newCharacterDescription = await sr.ReadToEndAsync(); } var setDescriptionResult = await _characters.SetCharacterDescriptionAsync(character, newCharacterDescription); if (!setDescriptionResult.IsSuccess) { await _feedback.SendErrorAsync(this.Context, setDescriptionResult.ErrorReason); return; } await _feedback.SendConfirmationAsync(this.Context, "Character description set."); }