1
0
mirror of https://github.com/oliverbooth/VPLink synced 2024-11-14 04:35:42 +00:00
VPLink/VPLink.Common/Extensions/UserExtensions.cs

28 lines
883 B
C#
Raw Permalink Normal View History

using Discord;
namespace VPLink.Common.Extensions;
/// <summary>
/// Provides extension methods for the <see cref="IUser" /> interface.
/// </summary>
public static class UserExtensions
{
/// <summary>
/// Gets the display name of the user.
/// </summary>
/// <param name="user">The user.</param>
/// <returns>The display name.</returns>
/// <exception cref="ArgumentNullException"><paramref name="user" /> is <c>null</c>.</exception>
public static string GetDisplayName(this IUser user)
{
2023-08-27 17:00:30 +01:00
string displayName = user switch
{
null => throw new ArgumentNullException(nameof(user)),
IGuildUser member => member.Nickname ?? member.GlobalName ?? member.Username,
_ => user.GlobalName ?? user.Username
};
2023-08-27 17:00:30 +01:00
return user.IsBot ? $"[{displayName}]" : displayName;
}
}