Added User command
This commit is contained in:
parent
65094f39b2
commit
b331bf5223
|
@ -2,6 +2,7 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net;
|
using System.Net;
|
||||||
|
using System.Text;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using System.Web;
|
using System.Web;
|
||||||
|
@ -156,7 +157,7 @@ namespace DeukBot4.MessageHandlers.CommandHandler
|
||||||
|
|
||||||
if (user == null)
|
if (user == null)
|
||||||
{
|
{
|
||||||
await request.SendMessageAsync("Can't find that user");
|
await request.SendSimpleEmbed("Avatar", "Can't find that user");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
var eb = new EmbedBuilder
|
var eb = new EmbedBuilder
|
||||||
|
@ -172,5 +173,77 @@ namespace DeukBot4.MessageHandlers.CommandHandler
|
||||||
};
|
};
|
||||||
await request.SendMessageAsync("", embed: eb.Build());
|
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue