geekbot/Geekbot.net/Commands/Utils/Info.cs

73 lines
2.7 KiB
C#
Raw Normal View History

using System;
using System.Diagnostics;
using System.Linq;
using System.Threading.Tasks;
using Discord;
using Discord.Commands;
using Discord.WebSocket;
using Geekbot.net.Lib;
using Geekbot.net.Lib.ErrorHandling;
2018-05-17 22:06:58 +02:00
using Geekbot.net.Lib.Extensions;
namespace Geekbot.net.Commands.Utils
{
public class Info : ModuleBase
{
private readonly DiscordSocketClient _client;
private readonly CommandService _commands;
2017-12-29 01:53:50 +01:00
private readonly IErrorHandler _errorHandler;
2017-09-15 22:56:03 +02:00
public Info(IErrorHandler errorHandler, DiscordSocketClient client, CommandService commands)
{
_errorHandler = errorHandler;
_client = client;
_commands = commands;
}
2017-09-15 22:56:03 +02:00
[Command("info", RunMode = RunMode.Async)]
[Summary("Get Information about the bot")]
public async Task BotInfo()
{
try
{
var eb = new EmbedBuilder();
2017-12-29 01:53:50 +01:00
var appInfo = await _client.GetApplicationInfoAsync();
eb.WithAuthor(new EmbedAuthorBuilder()
.WithIconUrl(appInfo.IconUrl)
2018-05-06 03:24:09 +02:00
.WithName($"{Constants.Name} V{Constants.BotVersion()}"));
2017-12-29 01:53:50 +01:00
var uptime = DateTime.Now.Subtract(Process.GetCurrentProcess().StartTime);
eb.AddInlineField("Bot Name", _client.CurrentUser.Username);
eb.AddInlineField("Bot Owner", $"{appInfo.Owner.Username}#{appInfo.Owner.Discriminator}");
eb.AddInlineField("Library", $"Discord.NET {Constants.LibraryVersion()}");
eb.AddInlineField("Uptime", $"{uptime.Days}D {uptime.Hours}H {uptime.Minutes}M {uptime.Seconds}S");
eb.AddInlineField("Servers", Context.Client.GetGuildsAsync().Result.Count);
eb.AddInlineField("Total Commands", _commands.Commands.Count());
eb.AddField("Website", "https://geekbot.pizzaandcoffee.rocks/");
await ReplyAsync("", false, eb.Build());
}
catch (Exception e)
{
2017-12-29 01:53:50 +01:00
_errorHandler.HandleCommandException(e, Context);
}
}
2017-12-29 01:53:50 +01:00
[Command("uptime", RunMode = RunMode.Async)]
[Summary("Get the Bot Uptime")]
public async Task BotUptime()
{
try
{
2017-12-29 01:53:50 +01:00
var uptime = DateTime.Now.Subtract(Process.GetCurrentProcess().StartTime);
await ReplyAsync($"{uptime.Days}D {uptime.Hours}H {uptime.Minutes}M {uptime.Seconds}S");
}
catch (Exception e)
{
2017-12-29 01:53:50 +01:00
_errorHandler.HandleCommandException(e, Context);
}
}
}
}