2023-08-27 16:50:17 +01:00
|
|
|
|
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
|
2023-08-27 16:50:17 +01:00
|
|
|
|
{
|
|
|
|
|
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;
|
2023-08-27 16:50:17 +01:00
|
|
|
|
}
|
|
|
|
|
}
|