geekbot/Geekbot.net/Modules/GuildInfo.cs

50 lines
1.6 KiB
C#
Raw Normal View History

using System;
2017-09-15 22:56:03 +02:00
using System.Linq;
using System.Threading.Tasks;
using Discord;
2017-09-15 22:56:03 +02:00
using Discord.Commands;
using Geekbot.net.Lib;
using StackExchange.Redis;
namespace Geekbot.net.Modules
{
public class GuildInfo : ModuleBase
{
private readonly IDatabase redis;
2017-09-15 22:56:03 +02:00
public GuildInfo(IDatabase redis)
{
this.redis = redis;
}
2017-09-15 22:56:03 +02:00
[Command("serverstats", RunMode = RunMode.Async)]
[Summary("Show some info about the bot.")]
public async Task getInfo()
{
var eb = new EmbedBuilder();
eb.WithAuthor(new EmbedAuthorBuilder()
2017-09-15 22:56:03 +02:00
.WithIconUrl(Context.Guild.IconUrl)
.WithName(Context.Guild.Name));
eb.WithColor(new Color(110, 204, 147));
2017-09-15 22:56:03 +02:00
var created = Context.Guild.CreatedAt;
var age = Math.Floor((DateTime.Now - created).TotalDays);
var messages = redis.HashGet($"{Context.Guild.Id}:Messages", 0.ToString());
2017-09-15 22:56:03 +02:00
var level = LevelCalc.GetLevelAtExperience((int) messages);
eb.AddField("Server Age", $"{created.Day}/{created.Month}/{created.Year} ({age} days)");
eb.AddInlineField("Level", level)
.AddInlineField("Messages", messages);
await ReplyAsync("", false, eb.Build());
}
public static string FirstCharToUpper(string input)
{
2017-09-15 22:56:03 +02:00
if (string.IsNullOrEmpty(input))
throw new ArgumentException("ARGH!");
return input.First().ToString().ToUpper() + input.Substring(1);
}
}
2017-04-25 20:59:38 +02:00
}