2017-09-14 22:11:19 +02:00
|
|
|
|
using System;
|
2017-09-15 22:56:03 +02:00
|
|
|
|
using System.Linq;
|
2017-09-14 22:11:19 +02:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Discord;
|
2017-09-15 22:56:03 +02:00
|
|
|
|
using Discord.Commands;
|
2017-09-14 22:11:19 +02:00
|
|
|
|
using Geekbot.net.Lib;
|
|
|
|
|
using StackExchange.Redis;
|
|
|
|
|
|
2017-10-02 21:57:48 +02:00
|
|
|
|
namespace Geekbot.net.Commands
|
2017-09-14 22:11:19 +02:00
|
|
|
|
{
|
|
|
|
|
public class GuildInfo : ModuleBase
|
|
|
|
|
{
|
2017-10-25 00:58:59 +02:00
|
|
|
|
private readonly IErrorHandler _errorHandler;
|
2017-12-29 01:53:50 +01:00
|
|
|
|
private readonly ILevelCalc _levelCalc;
|
|
|
|
|
private readonly IDatabase _redis;
|
2017-09-15 22:56:03 +02:00
|
|
|
|
|
2017-10-25 00:58:59 +02:00
|
|
|
|
public GuildInfo(IDatabase redis, ILevelCalc levelCalc, IErrorHandler errorHandler)
|
2017-09-14 22:11:19 +02:00
|
|
|
|
{
|
2017-10-25 00:58:59 +02:00
|
|
|
|
_redis = redis;
|
|
|
|
|
_levelCalc = levelCalc;
|
|
|
|
|
_errorHandler = errorHandler;
|
2017-09-14 22:11:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
2017-09-15 22:56:03 +02:00
|
|
|
|
[Command("serverstats", RunMode = RunMode.Async)]
|
2017-10-12 16:34:10 +02:00
|
|
|
|
[Remarks(CommandCategories.Statistics)]
|
2017-09-15 22:56:03 +02:00
|
|
|
|
[Summary("Show some info about the bot.")]
|
2017-09-14 22:11:19 +02:00
|
|
|
|
public async Task getInfo()
|
|
|
|
|
{
|
2017-10-25 00:58:59 +02:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
var eb = new EmbedBuilder();
|
|
|
|
|
eb.WithAuthor(new EmbedAuthorBuilder()
|
|
|
|
|
.WithIconUrl(Context.Guild.IconUrl)
|
|
|
|
|
.WithName(Context.Guild.Name));
|
|
|
|
|
eb.WithColor(new Color(110, 204, 147));
|
|
|
|
|
|
|
|
|
|
var created = Context.Guild.CreatedAt;
|
|
|
|
|
var age = Math.Floor((DateTime.Now - created).TotalDays);
|
|
|
|
|
|
|
|
|
|
var messages = _redis.HashGet($"{Context.Guild.Id}:Messages", 0.ToString());
|
2017-10-26 00:55:04 +02:00
|
|
|
|
var level = _levelCalc.GetLevel((int) messages);
|
2017-10-25 00:58:59 +02:00
|
|
|
|
|
|
|
|
|
eb.AddField("Server Age", $"{created.Day}/{created.Month}/{created.Year} ({age} days)");
|
|
|
|
|
eb.AddInlineField("Level", level)
|
|
|
|
|
.AddInlineField("Messages", messages);
|
|
|
|
|
|
|
|
|
|
await ReplyAsync("", false, eb.Build());
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
_errorHandler.HandleCommandException(e, Context);
|
|
|
|
|
}
|
2017-09-14 22:11:19 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string FirstCharToUpper(string input)
|
|
|
|
|
{
|
2017-09-15 22:56:03 +02:00
|
|
|
|
if (string.IsNullOrEmpty(input))
|
2017-09-14 22:11:19 +02:00
|
|
|
|
throw new ArgumentException("ARGH!");
|
|
|
|
|
return input.First().ToString().ToUpper() + input.Substring(1);
|
|
|
|
|
}
|
|
|
|
|
}
|
2017-04-25 20:59:38 +02:00
|
|
|
|
}
|