public async Task <Response> InvokeAsync(RawCommand command, ILazySocketClient client, ulong channelId, ulong userId) { if (client == null) { throw new ArgumentNullException(nameof(client)); } var channel = await client.TryGetMessageChannelAsync(channelId); var user = await client.TryGetUserAsync(userId); if (channel == null || user == null) { return(Response.None); } if (command == null) { return(Response.None); } if (!CanInvoke(command)) { return(Response.None); } if (command.HasDuplicateOption) { return(await Response.TryCreateCautionAsync(client, "同名のオプションが複数あります。", channelId, userId)); } var usedCommand = new HashSet <CommandOption>(new RefereneEqualsEqualityComparer <CommandOption>()); foreach (var pair in command.Options) { var found = (Options ?? new CommandOption[] { }).FirstOrDefault(option => option.Keys.Contains(pair.name)); if (found == null) { return(await Response.TryCreateCautionAsync(client, Texts.Error.Commands.Options.ContainsNotSupportedOption(pair.name), channelId, userId) ?? Response.None); } if (!usedCommand.Add(found)) { return(await Response.TryCreateCautionAsync(client, "同じ意味のオプションが複数あります。", channelId, userId)); } var result = found.SetValue(pair.name, pair.values); if (!result.HasValue) { return(await Response.TryCreateCautionAsync(client, result.Error ?? $"{pair.name} の値としてサポートしていない形式が使われています。", channelId, userId)); } } return(await InvokeCoreAsync(client, channel, user) ?? Response.None); }
private static async Task <Response> TryCreateAsync(ResponseType type, ILazySocketClient client, string message, ulong channelId, ulong?userIdOfReplyTo = null) { var channel = await client.TryGetMessageChannelAsync(channelId); if (userIdOfReplyTo == null) { return(TryCreate(type, message, channel)); } var replyTo = await client.TryGetUserAsync(userIdOfReplyTo.Value); if (replyTo == null) { return(null); } return(TryCreate(type, message, channel, replyTo)); }