1
0
Fork 1
mirror of https://github.com/TeamOctolings/Octobot.git synced 2025-04-29 02:29:55 +03:00

Reduce boilerplate in command data checks

Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
This commit is contained in:
Octol1ttle 2023-06-30 13:30:30 +05:00
parent 61e5016f1b
commit b46c366e5e
Signed by: Octol1ttle
GPG key ID: B77C34313AEE1FFF
4 changed files with 39 additions and 27 deletions

View file

@ -1,9 +1,12 @@
using System.Diagnostics.CodeAnalysis;
using System.Net;
using System.Text;
using DiffPlex.DiffBuilder.Model;
using Remora.Discord.API;
using Remora.Discord.API.Abstractions.Objects;
using Remora.Discord.API.Objects;
using Remora.Discord.Commands.Contexts;
using Remora.Discord.Commands.Extensions;
using Remora.Discord.Extensions.Embeds;
using Remora.Discord.Extensions.Formatting;
using Remora.Rest.Core;
@ -141,4 +144,15 @@ public static class Extensions {
var list = source.ToList();
return list.Any() ? list.Max(selector) : default;
}
public static bool TryGetContextIDs(
this ICommandContext context, [NotNullWhen(true)] out Snowflake? guildId,
[NotNullWhen(true)] out Snowflake? channelId, [NotNullWhen(true)] out Snowflake? userId) {
guildId = null;
channelId = null;
userId = null;
return context.TryGetGuildID(out guildId)
&& context.TryGetChannelID(out channelId)
&& context.TryGetUserID(out userId);
}
}