Skip to content

Commit

Permalink
[Library -> Extensions] Remove useless user extensions.
Browse files Browse the repository at this point in the history
  • Loading branch information
AnalogFeelings committed Feb 17, 2024
1 parent 9add667 commit b507d99
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 42 deletions.
18 changes: 9 additions & 9 deletions Source/SammBot.Bot/Modules/FunModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ public async Task<RuntimeResult> HugUserAsync([Summary("User", "The user you wan

SocketGuildUser authorGuildUser = (Context.Interaction.User as SocketGuildUser)!;

await RespondAsync($"Warm hugs from **{authorGuildUser.GetUsernameOrNick()}**!\n{chosenKaomoji} <@{targetUser.Id}>",
await RespondAsync($"Warm hugs from **{authorGuildUser.DisplayName}**!\n{chosenKaomoji} <@{targetUser.Id}>",
allowedMentions: Constants.AllowOnlyUsers);

return ExecutionResult.Succesful();
Expand All @@ -138,7 +138,7 @@ await RespondAsync($"Warm hugs from **{authorGuildUser.GetUsernameOrNick()}**!\n
[RequireContext(ContextType.Guild)]
public async Task<RuntimeResult> PatUserAsync([Summary("User", "The user you want to pat.")] SocketGuildUser targetUser)
{
await RespondAsync($"Pats from **{targetUser.GetUsernameOrNick()}**!\n(c・_・)ノ”<@{targetUser.Id}>", allowedMentions: Constants.AllowOnlyUsers);
await RespondAsync($"Pats from **{targetUser.DisplayName}**!\n(c・_・)ノ”<@{targetUser.Id}>", allowedMentions: Constants.AllowOnlyUsers);

return ExecutionResult.Succesful();
}
Expand All @@ -154,7 +154,7 @@ public async Task<RuntimeResult> DoxUserAsync([Summary("User", "The user you wan
int thirdSegment = Random.Shared.Next(0, 256);
int fourthSegment = Random.Shared.Next(0, 256);

await RespondAsync($"**{targetUser.GetUsernameOrNick()}**'s IPv4 address: `{firstSegment}.{secondSegment}.{thirdSegment}.{fourthSegment}`",
await RespondAsync($"**{targetUser.DisplayName}**'s IPv4 address: `{firstSegment}.{secondSegment}.{thirdSegment}.{fourthSegment}`",
allowedMentions: Constants.AllowOnlyUsers);

return ExecutionResult.Succesful();
Expand All @@ -169,8 +169,8 @@ public async Task<RuntimeResult> FirstDegreeMurderAsync([Summary("User", "The us
SocketGuildUser authorUser = (Context.Interaction.User as SocketGuildUser)!;

string chosenMessage = SettingsManager.Instance.LoadedConfig.KillMessages.PickRandom();
chosenMessage = chosenMessage.Replace("{Murderer}", $"**{authorUser.GetUsernameOrNick()}**");
chosenMessage = chosenMessage.Replace("{Victim}", $"**{targetUser.GetUsernameOrNick()}**");
chosenMessage = chosenMessage.Replace("{Murderer}", $"**{authorUser.DisplayName}**");
chosenMessage = chosenMessage.Replace("{Victim}", $"**{targetUser.DisplayName}**");

await RespondAsync(chosenMessage, allowedMentions: Constants.AllowOnlyUsers);

Expand Down Expand Up @@ -246,8 +246,8 @@ public async Task<RuntimeResult> ShipUsersAsync([Summary("FirstUser", "The first
}

// Split usernames into halves, then sanitize them.
string firstUserName = firstUser.GetUsernameOrNick();
string secondUserName = secondUser.GetUsernameOrNick();
string firstUserName = firstUser.DisplayName;
string secondUserName = secondUser.DisplayName;

string nameFirstHalf = string.Empty;
string nameSecondHalf = string.Empty;
Expand Down Expand Up @@ -304,8 +304,8 @@ public async Task<RuntimeResult> ShipUsersAsync([Summary("FirstUser", "The first

// Download their profile pictures and store into memory stream.
// Then, load the emoji file into a stream.
using (MemoryStream firstUserAvatarStream = await DownloadToMemoryStream(firstUser.GetGuildGlobalOrDefaultAvatar(2048)))
using (MemoryStream secondUserAvatarStream = await DownloadToMemoryStream(secondUser.GetGuildGlobalOrDefaultAvatar(2048)))
using (MemoryStream firstUserAvatarStream = await DownloadToMemoryStream(firstUser.GetDisplayAvatarUrl(size: 2048)))
using (MemoryStream secondUserAvatarStream = await DownloadToMemoryStream(secondUser.GetDisplayAvatarUrl(size: 2048)))
using (FileStream emojiStream = File.Open(emojiFilename, FileMode.Open, FileAccess.Read, FileShare.Read))
using (SKSurface surface = SKSurface.Create(imageInfo))
{
Expand Down
3 changes: 2 additions & 1 deletion Source/SammBot.Bot/Modules/InformationModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ public async Task<RuntimeResult> UserInfoAsync([Summary("User", "The user you wa
{
targetUser ??= (Context.Interaction.User as SocketGuildUser)!;

string userAvatar = targetUser.GetAvatarOrDefault(2048);
// Cast to SocketUser to ignore guild-specific avatar.
string userAvatar = (targetUser as SocketUser).GetDisplayAvatarUrl(size: 2048);
string userName = targetUser.GetFullUsername();
string userId = targetUser.Id.ToString();
string userNickname = targetUser.Nickname ?? "None";
Expand Down
2 changes: 1 addition & 1 deletion Source/SammBot.Library/Extensions/EmbedExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static EmbedBuilder BuildDefaultEmbed(this EmbedBuilder builder, ShardedI
builder.WithFooter(x =>
{
x.Text = $"Requested by {context.Interaction.User.GetFullUsername()}";
x.IconUrl = context.Interaction.User.GetGuildGlobalOrDefaultAvatar(256);
x.IconUrl = context.Interaction.User.GetDisplayAvatarUrl();
});
builder.WithCurrentTimestamp();

Expand Down
31 changes: 0 additions & 31 deletions Source/SammBot.Library/Extensions/UserExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,37 +26,6 @@ namespace SammBot.Library.Extensions;
/// </summary>
public static class UserExtensions
{
public static string GetAvatarOrDefault(this SocketUser user, ushort size)
{
return user.GetAvatarUrl(size: size) ?? user.GetDefaultAvatarUrl();
}

public static string GetGuildOrGlobalAvatar(this SocketGuildUser user, ushort size)
{
return user.GetGuildAvatarUrl(size: size) ?? user.GetAvatarUrl(size: size);
}

public static string GetGuildGlobalOrDefaultAvatar(this SocketUser user, ushort size)
{
if (user is SocketGuildUser targetUser)
return targetUser.GetGuildAvatarUrl(size: size) ?? targetUser.GetAvatarOrDefault(size);

return user.GetAvatarOrDefault(size);
}

/// <summary>
/// Gets the user's username, or nickname if available.
/// </summary>
/// <param name="user">The target user.</param>
/// <returns>The user's display name.</returns>
public static string GetUsernameOrNick(this SocketGuildUser user)
{
if (!user.HasPomelo())
return user.Nickname ?? user.Username;

return user.DisplayName;
}

/// <summary>
/// Returns the user's formatted username.
/// </summary>
Expand Down

0 comments on commit b507d99

Please sign in to comment.