mirror of
https://github.com/TeamOctolings/Octobot.git
synced 2025-04-29 02:29:55 +03:00
Remora.Discord part 4 out of ∞ (well that was painful)
Signed-off-by: Octol1ttle <l1ttleofficial@outlook.com>
This commit is contained in:
parent
67a15f3822
commit
f7dd09d43e
8 changed files with 231 additions and 13 deletions
|
@ -4,7 +4,10 @@ using DiffPlex.DiffBuilder.Model;
|
|||
using Microsoft.Extensions.Configuration;
|
||||
using Remora.Discord.API;
|
||||
using Remora.Discord.API.Abstractions.Objects;
|
||||
using Remora.Discord.API.Abstractions.Rest;
|
||||
using Remora.Discord.API.Objects;
|
||||
using Remora.Discord.Caching;
|
||||
using Remora.Discord.Caching.Services;
|
||||
using Remora.Discord.Extensions.Embeds;
|
||||
using Remora.Discord.Extensions.Formatting;
|
||||
using Remora.Rest.Core;
|
||||
|
@ -41,6 +44,16 @@ public static class Extensions {
|
|||
return value is not null ? CultureInfoCache[value] : CultureInfoCache["en"];
|
||||
}
|
||||
|
||||
public static async Task<Result<IUser>> TryGetUserAsync(
|
||||
this Snowflake userId, CacheService cacheService, IDiscordRestUserAPI userApi, CancellationToken ct) {
|
||||
var cachedUserResult = await cacheService.TryGetValueAsync<IUser>(
|
||||
new KeyHelpers.UserCacheKey(userId), ct);
|
||||
|
||||
if (cachedUserResult.IsDefined(out var cachedUser)) return Result<IUser>.FromSuccess(cachedUser);
|
||||
|
||||
return await userApi.GetUserAsync(userId, ct);
|
||||
}
|
||||
|
||||
public static EmbedBuilder WithUserFooter(this EmbedBuilder builder, IUser user) {
|
||||
var avatarUrlResult = CDN.GetUserAvatarUrl(user, imageSize: 256);
|
||||
var avatarUrl = avatarUrlResult.IsSuccess
|
||||
|
@ -81,6 +94,14 @@ public static class Extensions {
|
|||
return builder.WithFooter(new EmbedFooter(guild.Name, iconUrl));
|
||||
}
|
||||
|
||||
public static EmbedBuilder WithEventCover(
|
||||
this EmbedBuilder builder, Snowflake eventId, Optional<IImageHash?> imageHashOptional) {
|
||||
if (!imageHashOptional.IsDefined(out var imageHash)) return builder;
|
||||
|
||||
var iconUrlResult = CDN.GetGuildScheduledEventCoverUrl(eventId, imageHash, imageSize: 1024);
|
||||
return iconUrlResult.IsDefined(out var iconUrl) ? builder.WithImageUrl(iconUrl.AbsoluteUri) : builder;
|
||||
}
|
||||
|
||||
public static string SanitizeForBlockCode(this string s) {
|
||||
return s.Replace("```", "```");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue