/// <inheritdoc /> public override async ValueTask <Result <Roleplay> > TryParseAsync(string value, CancellationToken ct = default) { value = value.Trim(); if (!_context.GuildID.HasValue) { throw new InvalidOperationException(); } if (string.Equals(value, "current", StringComparison.OrdinalIgnoreCase)) { return(await _roleplays.GetActiveRoleplayAsync(_context.ChannelID)); } if (!value.Contains(':')) { return(await _roleplays.GetBestMatchingRoleplayAsync ( _context.ChannelID, _context.GuildID.Value, _context.User.ID, value )); } var parts = value.Split(':'); if (parts.Length != 2) { return(new UserError ( "When searching a specific user, the name must be in the form \"@someone:name\"." )); } var rawUser = parts[0]; if (!Snowflake.TryParse(rawUser.Unmention(), out var parsedUser)) { return(new UserError ( "I couldn't parse whatever you gave me as a user-scoped roleplay search. Try again?" )); } var rawName = parts[1]; return(await _roleplays.GetBestMatchingRoleplayAsync ( _context.ChannelID, _context.GuildID.Value, parsedUser, rawName )); }
/// <inheritdoc /> public async ValueTask <Result> CheckAsync(RequireActiveRoleplayAttribute attribute, CancellationToken ct = default) { var result = await _roleplayService.GetActiveRoleplayAsync(_context.ChannelID); if (!result.IsSuccess) { return(Result.FromError(result)); } if (!attribute.RequireOwner) { return(Result.FromSuccess()); } var roleplay = result.Entity; return(roleplay.Owner.DiscordID != _context.User.ID ? new UserError("Only the roleplay owner can do that.") : Result.FromSuccess()); }
public async Task <RuntimeResult> ShowRoleplayAsync() { if (!(this.Context.Channel is ITextChannel textChannel)) { return(RuntimeCommandResult.FromError("This channel isn't a text channel.")); } var getCurrentRoleplayResult = await _discordRoleplays.GetActiveRoleplayAsync(textChannel); if (!getCurrentRoleplayResult.IsSuccess) { return(getCurrentRoleplayResult.ToRuntimeResult()); } var roleplay = getCurrentRoleplayResult.Entity; var eb = await CreateRoleplayInfoEmbedAsync(roleplay); await _feedback.SendEmbedAsync(this.Context.Channel, eb); return(RuntimeCommandResult.FromSuccess()); }
public async Task ShowRoleplayAsync() { if (!(this.Context.Channel is ITextChannel textChannel)) { return; } var getCurrentRoleplayResult = await _discordRoleplays.GetActiveRoleplayAsync(textChannel); if (!getCurrentRoleplayResult.IsSuccess) { await _feedback.SendErrorAsync(this.Context, getCurrentRoleplayResult.ErrorReason); return; } var roleplay = getCurrentRoleplayResult.Entity; var eb = await CreateRoleplayInfoEmbedAsync(roleplay); await _feedback.SendEmbedAsync(this.Context.Channel, eb); }
public async Task <IResult> ShowRoleplayAsync ( [AutocompleteProvider("roleplay::any")] Roleplay?roleplay = null ) { if (roleplay is null) { var getCurrentRoleplayResult = await _discordRoleplays.GetActiveRoleplayAsync(_context.ChannelID); if (!getCurrentRoleplayResult.IsSuccess) { return(getCurrentRoleplayResult); } roleplay = getCurrentRoleplayResult.Entity; } var eb = CreateRoleplayInfoEmbed(roleplay); return(await _feedback.SendContextualEmbedAsync(eb)); }