Skip to content

Commit

Permalink
Add "utils avatar-url" command for linking to avatars
Browse files Browse the repository at this point in the history
  • Loading branch information
selfdocumentingcode committed Sep 7, 2024
1 parent 1ecdc2e commit a73e0a8
Showing 1 changed file with 15 additions and 2 deletions.
17 changes: 15 additions & 2 deletions Kattbot/CommandModules/UtilsModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public Task GetEmojiCode(CommandContext ctx, DiscordEmoji emoji)

if (isUnicodeEmoji)
{
var unicodeEncoding = new UnicodeEncoding(true, false);
var unicodeEncoding = new UnicodeEncoding(bigEndian: true, byteOrderMark: false);

byte[] bytes = unicodeEncoding.GetBytes(emoji.Name);

Expand All @@ -35,7 +35,7 @@ public Task GetEmojiCode(CommandContext ctx, DiscordEmoji emoji)

for (var i = 0; i < sb.Length; i += 4)
{
formattedSb.Append($"\\u{bytesAsString.Substring(i, 4)}");
formattedSb.Append($"\\u{bytesAsString.Substring(i, length: 4)}");
}

var result = formattedSb.ToString();
Expand All @@ -62,4 +62,17 @@ public Task GetRoleId(CommandContext ctx, string roleName)
? ctx.RespondAsync(result.ErrorMessage)
: ctx.RespondAsync($"Role {roleName} has id {discordRole.Id}");
}

[Command("avatar-url")]
public Task GetAvatarUrl(CommandContext ctx, DiscordMember member)
{
string memberAvatarUrl = member.AvatarUrl;
string memberGuildAvatarUrl = member.GuildAvatarUrl;

var response = $"User avatar: {memberAvatarUrl}";
if (!string.IsNullOrEmpty(memberGuildAvatarUrl))
response += $"\nServer avatar: {memberGuildAvatarUrl}";

return ctx.RespondAsync(response);
}
}

0 comments on commit a73e0a8

Please sign in to comment.