2017-11-11 19:31:31 +01:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Net.Http;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Discord;
|
|
|
|
|
using Discord.Commands;
|
|
|
|
|
using Discord.WebSocket;
|
|
|
|
|
using Geekbot.net.Lib;
|
2018-05-03 00:56:06 +02:00
|
|
|
|
using Geekbot.net.Lib.ErrorHandling;
|
2017-11-11 19:31:31 +01:00
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
|
2018-05-03 00:56:06 +02:00
|
|
|
|
namespace Geekbot.net.Commands.Utils.Changelog
|
2017-11-11 19:31:31 +01:00
|
|
|
|
{
|
|
|
|
|
public class Changelog : ModuleBase
|
|
|
|
|
{
|
|
|
|
|
private readonly DiscordSocketClient _client;
|
2017-12-29 01:53:50 +01:00
|
|
|
|
private readonly IErrorHandler _errorHandler;
|
|
|
|
|
|
2017-11-11 19:31:31 +01:00
|
|
|
|
public Changelog(IErrorHandler errorHandler, DiscordSocketClient client)
|
|
|
|
|
{
|
|
|
|
|
_errorHandler = errorHandler;
|
|
|
|
|
_client = client;
|
|
|
|
|
}
|
2017-12-29 01:53:50 +01:00
|
|
|
|
|
2017-11-11 19:31:31 +01:00
|
|
|
|
[Command("changelog", RunMode = RunMode.Async)]
|
|
|
|
|
[Alias("updates")]
|
|
|
|
|
[Remarks(CommandCategories.Helpers)]
|
|
|
|
|
[Summary("Show the latest 5 updates")]
|
2018-04-30 23:44:19 +02:00
|
|
|
|
public async Task GetChangelog()
|
2017-11-11 19:31:31 +01:00
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
using (var client = new HttpClient())
|
|
|
|
|
{
|
|
|
|
|
client.BaseAddress = new Uri("https://api.github.com");
|
2017-12-29 01:53:50 +01:00
|
|
|
|
client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent",
|
|
|
|
|
"http://developer.github.com/v3/#user-agent-required");
|
2017-11-11 19:31:31 +01:00
|
|
|
|
var response = await client.GetAsync("/repos/pizzaandcoffee/geekbot.net/commits");
|
|
|
|
|
response.EnsureSuccessStatusCode();
|
|
|
|
|
|
|
|
|
|
var stringResponse = await response.Content.ReadAsStringAsync();
|
2018-04-30 23:44:19 +02:00
|
|
|
|
var commits = JsonConvert.DeserializeObject<List<CommitDto>>(stringResponse);
|
2017-11-11 19:31:31 +01:00
|
|
|
|
var eb = new EmbedBuilder();
|
|
|
|
|
eb.WithColor(new Color(143, 165, 102));
|
2017-12-29 01:53:50 +01:00
|
|
|
|
eb.WithAuthor(new EmbedAuthorBuilder
|
2017-11-11 19:31:31 +01:00
|
|
|
|
{
|
|
|
|
|
IconUrl = _client.CurrentUser.GetAvatarUrl(),
|
|
|
|
|
Name = "Latest Updates",
|
|
|
|
|
Url = "https://geekbot.pizzaandcoffee.rocks/updates"
|
|
|
|
|
});
|
|
|
|
|
var sb = new StringBuilder();
|
|
|
|
|
foreach (var commit in commits.Take(10))
|
2018-05-04 00:55:32 +02:00
|
|
|
|
sb.AppendLine($"- {commit.Commit.Message} ({commit.Commit.Author.Date:yyyy-MM-dd})");
|
2017-11-11 19:31:31 +01:00
|
|
|
|
eb.Description = sb.ToString();
|
2017-12-29 01:53:50 +01:00
|
|
|
|
eb.WithFooter(new EmbedFooterBuilder
|
2017-11-11 19:31:31 +01:00
|
|
|
|
{
|
|
|
|
|
Text = $"List generated from github commits on {DateTime.Now:yyyy-MM-dd}"
|
|
|
|
|
});
|
|
|
|
|
await ReplyAsync("", false, eb.Build());
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch (Exception e)
|
|
|
|
|
{
|
|
|
|
|
_errorHandler.HandleCommandException(e, Context);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|