mirror of
https://github.com/oliverbooth/VPLink
synced 2024-11-09 23:25:42 +00:00
28 lines
883 B
C#
28 lines
883 B
C#
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)
|
|
{
|
|
string displayName = user switch
|
|
{
|
|
null => throw new ArgumentNullException(nameof(user)),
|
|
IGuildUser member => member.Nickname ?? member.GlobalName ?? member.Username,
|
|
_ => user.GlobalName ?? user.Username
|
|
};
|
|
|
|
return user.IsBot ? $"[{displayName}]" : displayName;
|
|
}
|
|
}
|