Can't be a bot without an avatar command
This commit is contained in:
parent
a83d56f1b7
commit
6e00f9b700
|
@ -7,6 +7,7 @@ using DeukBot4.MessageHandlers.CommandHandler.RequestStructure;
|
||||||
using DeukBot4.MessageHandlers.Permissions;
|
using DeukBot4.MessageHandlers.Permissions;
|
||||||
using DeukBot4.Utilities;
|
using DeukBot4.Utilities;
|
||||||
using Discord;
|
using Discord;
|
||||||
|
using Discord.WebSocket;
|
||||||
|
|
||||||
namespace DeukBot4.MessageHandlers.CommandHandler
|
namespace DeukBot4.MessageHandlers.CommandHandler
|
||||||
{
|
{
|
||||||
|
@ -94,5 +95,51 @@ namespace DeukBot4.MessageHandlers.CommandHandler
|
||||||
await request.OriginalMessage.Channel.SendFileAsync(await CatPicHandler.GetCatPicture(), "cat_pic.png");
|
await request.OriginalMessage.Channel.SendFileAsync(await CatPicHandler.GetCatPicture(), "cat_pic.png");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[Command("avatar", PermissionLevel.Everyone)]
|
||||||
|
[CommandHelp("Gets a users avatar", "Gets a users avatar. Returns avatar of user using the command")]
|
||||||
|
[CommandParameters(ParameterMatcher.ParameterType.User)]
|
||||||
|
public async Task GetAvatar(CommandRequest request)
|
||||||
|
{
|
||||||
|
SocketUser user = null;
|
||||||
|
if (request.Parameters.Length > 0)
|
||||||
|
{
|
||||||
|
var guild = (request.OriginalMessage.Channel as IGuildChannel)?.Guild;
|
||||||
|
if (guild != null)
|
||||||
|
{
|
||||||
|
user = (SocketUser) await request.Parameters[0].AsDiscordUser(guild);
|
||||||
|
}
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
var userId = request.Parameters[0].AsUlong();
|
||||||
|
if (userId.HasValue)
|
||||||
|
{
|
||||||
|
user = Program.Client.GetUser(userId.Value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
user = request.OriginalMessage.Author;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (user == null)
|
||||||
|
{
|
||||||
|
await request.SendMessageAsync("Can't find that user");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var eb = new EmbedBuilder
|
||||||
|
{
|
||||||
|
Author = new EmbedAuthorBuilder
|
||||||
|
{
|
||||||
|
Name = $"{user.Username}#{user.Discriminator}",
|
||||||
|
IconUrl = user.GetAvatarUrl()
|
||||||
|
},
|
||||||
|
ImageUrl = user.GetAvatarUrl(ImageFormat.Auto, 256),
|
||||||
|
Timestamp = request.OriginalMessage.CreatedAt,
|
||||||
|
Color = Color.Gold
|
||||||
|
};
|
||||||
|
await request.SendMessageAsync("", embed: eb.Build());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue