Added User command

This commit is contained in:
Deukhoofd 2018-10-08 17:14:46 +02:00
parent 65094f39b2
commit b331bf5223
No known key found for this signature in database
GPG Key ID: B4C087AC81641654
1 changed files with 74 additions and 1 deletions

View File

@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Web;
@ -156,7 +157,7 @@ namespace DeukBot4.MessageHandlers.CommandHandler
if (user == null)
{
await request.SendMessageAsync("Can't find that user");
await request.SendSimpleEmbed("Avatar", "Can't find that user");
return;
}
var eb = new EmbedBuilder
@ -172,5 +173,77 @@ namespace DeukBot4.MessageHandlers.CommandHandler
};
await request.SendMessageAsync("", embed: eb.Build());
}
[Command("user", PermissionLevel.Everyone)]
[CommandHelp("Gets a users avatar", "Gets a users avatar. Returns avatar of user using the command if no user was specified.")]
[CommandParameters(ParameterMatcher.ParameterType.User)]
public async Task GetUser(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.SendSimpleEmbed("Avatar", "Can't find that user");
return;
}
var eb = EmbedFactory.GetStandardEmbedBuilder();
eb.Title = $"{user.Username}#{user.Discriminator}";
eb.Description = $"<@!{user.Id}>";
eb.ThumbnailUrl = user.GetAvatarUrl();
IGuildUser guildUser = null;
if (request.OriginalMessage.Channel is IGuildChannel guildChannel)
{
guildUser = await guildChannel.Guild.GetUserAsync(user.Id);
}
if (guildUser?.Nickname != null)
eb.AddField("Nickname", guildUser.Nickname, true);
eb.AddField("Status", user.Status, true);
eb.AddField("User Id", user.Id, true);
eb.AddField("Is Bot", user.IsBot, true);
eb.AddField("Joined Discord At", user.CreatedAt.ToString("D"), true);
if (guildUser != null)
{
if (guildUser.JoinedAt.HasValue)
eb.AddField("Joined Server At", guildUser.JoinedAt.Value.ToString("D"), true);
var roles = guildUser.RoleIds;
var sb = new StringBuilder();
foreach (var roleId in roles)
{
if (roleId == guildUser.GuildId)
continue;
sb.Append($"<@&{roleId}> ");
}
if (sb.Length > 0)
eb.AddField("Roles", sb.ToString(), false);
}
await request.SendMessageAsync("", embed: eb.Build());
}
}
}