Add Extension Methods

This commit is contained in:
Fennel 2020-04-24 17:20:34 -04:00 committed by Astrid
parent c99784b9dc
commit 949dae6561
4 changed files with 10 additions and 4 deletions

View File

@ -283,7 +283,7 @@ namespace PluralKit.Bot
// Fetch information about the guild early, as we need it for the logger cleanup
GuildConfig cachedGuild = default;
if (msg.Channel.Type == ChannelType.Text) await _cache.GetGuildDataCached(msg.Channel.GuildId);
if (msg.Channel.Type == ChannelType.Text) cachedGuild = await _cache.GetGuildDataCached(msg.Channel.GuildId);
// Pass guild bot/WH messages onto the logger cleanup service, but otherwise ignore
if (msg.Author.IsBot && msg.Channel.Type == ChannelType.Text)

View File

@ -61,7 +61,7 @@ namespace PluralKit.Bot
if (target.System != ctx.System.Id) throw Errors.NotOwnMemberError;
else if (user != null)
{
if (user.AvatarUrl == user.DefaultAvatarUrl) throw Errors.UserHasNoAvatar; //TODO: is this necessary?
if (!user.HasAvatar()) throw Errors.UserHasNoAvatar; //TODO: is this necessary?
target.AvatarUrl = user.GetAvatarUrl(ImageFormat.Png, size: 256);
await _data.SaveMember(target);
@ -131,7 +131,7 @@ namespace PluralKit.Bot
if (user != null)
{
if (user.AvatarUrl == user.DefaultAvatarUrl) throw Errors.UserHasNoAvatar;
if (!user.HasAvatar()) throw Errors.UserHasNoAvatar;
guildData.AvatarUrl = user.GetAvatarUrl(ImageFormat.Png, size: 256);
await _data.SetMemberGuildSettings(target, ctx.Guild.Id, guildData);

View File

@ -144,7 +144,7 @@ namespace PluralKit.Bot
var member = await ctx.MatchUser();
if (member != null)
{
if (member.AvatarUrl == member.DefaultAvatarUrl) throw Errors.UserHasNoAvatar;
if (!member.HasAvatar()) throw Errors.UserHasNoAvatar;
ctx.System.AvatarUrl = member.GetAvatarUrl(ImageFormat.Png, size: 256);
await _data.SaveSystem(ctx.System);

View File

@ -1,4 +1,5 @@
using DSharpPlus;
using DSharpPlus.Entities;
using System.Net.WebSockets;
@ -19,5 +20,10 @@ namespace PluralKit.Bot
}
return true;
}
public static bool HasAvatar(this DiscordUser user)
{
return user.AvatarUrl != user.DefaultAvatarUrl;
}
}
}