geekbot/Geekbot.net/Modules/UserInfo.cs

56 lines
1.8 KiB
C#
Raw Normal View History

2017-04-12 21:49:04 +02:00
using System;
using System.Threading.Tasks;
using Discord;
using Discord.Commands;
2017-04-14 21:36:01 +02:00
using Geekbot.net.Lib;
2017-04-12 21:49:04 +02:00
namespace Geekbot.net.Modules
{
public class UserInfo : ModuleBase
{
private readonly IRedisClient redis;
public UserInfo(IRedisClient redisClient)
{
redis = redisClient;
}
2017-04-17 16:58:48 +02:00
[Alias("stats")]
2017-04-12 21:49:04 +02:00
[Command("user"), Summary("Get information about this user")]
public async Task User([Summary("The (optional) user to get info for")] IUser user = null)
{
var userInfo = user ?? Context.Message.Author;
var age = Math.Floor((DateTime.Now - userInfo.CreatedAt).TotalDays);
2017-04-17 16:58:48 +02:00
var key = Context.Guild.Id + "-" + userInfo.Id;
var messages = (int)redis.Client.StringGet(key + "-messages");
2017-04-21 22:51:30 +02:00
var level = LevelCalc.GetLevelAtExperience(messages);
2017-04-14 21:36:01 +02:00
var eb = new EmbedBuilder();
eb.WithAuthor(new EmbedAuthorBuilder()
.WithIconUrl(userInfo.GetAvatarUrl())
.WithName(userInfo.Username));
2017-04-19 19:54:29 +02:00
eb.WithColor(new Color(221, 255, 119));
eb.AddField("Discordian Since", $"{userInfo.CreatedAt.Day}/{userInfo.CreatedAt.Month}/{userInfo.CreatedAt.Year} ({age} days)");
2017-04-19 19:23:22 +02:00
eb.AddInlineField("Level", level)
.AddInlineField("Messages Sent", messages);
var karma = redis.Client.StringGet(key + "-karma");
if (!karma.IsNullOrEmpty)
2017-04-17 16:58:48 +02:00
{
eb.AddField("Karma", karma);
2017-04-17 16:58:48 +02:00
}
var correctRolls = redis.Client.StringGet($"{Context.Guild.Id}-{Context.User.Id}-correctRolls");
if (!correctRolls.IsNullOrEmpty)
{
eb.AddField("Guessed Rolls", correctRolls);
}
await ReplyAsync("", false, eb.Build());
2017-04-12 21:49:04 +02:00
}
2017-04-13 00:03:03 +02:00
2017-04-21 22:51:30 +02:00
2017-04-12 21:49:04 +02:00
}
}