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;
|
2018-05-11 00:36:29 +02:00
|
|
|
|
using Geekbot.net.Database;
|
2018-05-03 00:56:06 +02:00
|
|
|
|
using Geekbot.net.Lib.ErrorHandling;
|
2018-05-11 00:36:29 +02:00
|
|
|
|
using Geekbot.net.Lib.Extensions;
|
2018-05-03 00:56:06 +02:00
|
|
|
|
using Geekbot.net.Lib.Levels;
|
2017-09-14 22:11:19 +02:00
|
|
|
|
|
2018-05-03 00:56:06 +02:00
|
|
|
|
namespace Geekbot.net.Commands.User
|
2017-09-14 22:11:19 +02:00
|
|
|
|
{
|
|
|
|
|
public class GuildInfo : ModuleBase
|
|
|
|
|
{
|
2017-10-25 00:58:59 +02:00
|
|
|
|
private readonly IErrorHandler _errorHandler;
|
2018-05-11 00:36:29 +02:00
|
|
|
|
private readonly DatabaseContext _database;
|
2017-12-29 01:53:50 +01:00
|
|
|
|
private readonly ILevelCalc _levelCalc;
|
2017-09-15 22:56:03 +02:00
|
|
|
|
|
2018-05-11 00:36:29 +02:00
|
|
|
|
public GuildInfo(DatabaseContext database, ILevelCalc levelCalc, IErrorHandler errorHandler)
|
2017-09-14 22:11:19 +02:00
|
|
|
|
{
|
2018-05-11 00:36:29 +02:00
|
|
|
|
_database = database;
|
2017-10-25 00:58:59 +02:00
|
|
|
|
_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)]
|
|
|
|
|
[Summary("Show some info about the bot.")]
|
2018-04-30 23:44:19 +02:00
|
|
|
|
public async Task GetInfo()
|
2017-09-14 22:11:19 +02:00
|
|
|
|
{
|
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);
|
|
|
|
|
|
2018-05-11 00:36:29 +02:00
|
|
|
|
var messages = _database.Messages
|
|
|
|
|
.Where(e => e.GuildId == Context.Guild.Id.AsLong())
|
|
|
|
|
.Sum(e => e.MessageCount);
|
2018-05-15 01:18:26 +02:00
|
|
|
|
var level = _levelCalc.GetLevel(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)
|
|
|
|
|
{
|
2018-06-13 22:18:57 +02:00
|
|
|
|
await _errorHandler.HandleCommandException(e, Context);
|
2017-10-25 00:58:59 +02:00
|
|
|
|
}
|
2017-09-14 22:11:19 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-04-25 20:59:38 +02:00
|
|
|
|
}
|