Refaction all files into component based folders
This commit is contained in:
parent
55e152f4aa
commit
e3adf55742
102 changed files with 816 additions and 709 deletions
70
Geekbot.net/Commands/Utils/Changelog/Changelog.cs
Normal file
70
Geekbot.net/Commands/Utils/Changelog/Changelog.cs
Normal file
|
@ -0,0 +1,70 @@
|
|||
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;
|
||||
using Geekbot.net.Lib.ErrorHandling;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace Geekbot.net.Commands.Utils.Changelog
|
||||
{
|
||||
public class Changelog : ModuleBase
|
||||
{
|
||||
private readonly DiscordSocketClient _client;
|
||||
private readonly IErrorHandler _errorHandler;
|
||||
|
||||
public Changelog(IErrorHandler errorHandler, DiscordSocketClient client)
|
||||
{
|
||||
_errorHandler = errorHandler;
|
||||
_client = client;
|
||||
}
|
||||
|
||||
[Command("changelog", RunMode = RunMode.Async)]
|
||||
[Alias("updates")]
|
||||
[Remarks(CommandCategories.Helpers)]
|
||||
[Summary("Show the latest 5 updates")]
|
||||
public async Task GetChangelog()
|
||||
{
|
||||
try
|
||||
{
|
||||
using (var client = new HttpClient())
|
||||
{
|
||||
client.BaseAddress = new Uri("https://api.github.com");
|
||||
client.DefaultRequestHeaders.TryAddWithoutValidation("User-Agent",
|
||||
"http://developer.github.com/v3/#user-agent-required");
|
||||
var response = await client.GetAsync("/repos/pizzaandcoffee/geekbot.net/commits");
|
||||
response.EnsureSuccessStatusCode();
|
||||
|
||||
var stringResponse = await response.Content.ReadAsStringAsync();
|
||||
var commits = JsonConvert.DeserializeObject<List<CommitDto>>(stringResponse);
|
||||
var eb = new EmbedBuilder();
|
||||
eb.WithColor(new Color(143, 165, 102));
|
||||
eb.WithAuthor(new EmbedAuthorBuilder
|
||||
{
|
||||
IconUrl = _client.CurrentUser.GetAvatarUrl(),
|
||||
Name = "Latest Updates",
|
||||
Url = "https://geekbot.pizzaandcoffee.rocks/updates"
|
||||
});
|
||||
var sb = new StringBuilder();
|
||||
foreach (var commit in commits.Take(10))
|
||||
sb.AppendLine($"- {commit.Commit.Message} ({commit.Commit.AuthorDto.Date:yyyy-MM-dd})");
|
||||
eb.Description = sb.ToString();
|
||||
eb.WithFooter(new EmbedFooterBuilder
|
||||
{
|
||||
Text = $"List generated from github commits on {DateTime.Now:yyyy-MM-dd}"
|
||||
});
|
||||
await ReplyAsync("", false, eb.Build());
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_errorHandler.HandleCommandException(e, Context);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
9
Geekbot.net/Commands/Utils/Changelog/CommitAuthorDto.cs
Normal file
9
Geekbot.net/Commands/Utils/Changelog/CommitAuthorDto.cs
Normal file
|
@ -0,0 +1,9 @@
|
|||
using System;
|
||||
|
||||
namespace Geekbot.net.Commands.Utils.Changelog
|
||||
{
|
||||
internal class CommitAuthorDto
|
||||
{
|
||||
public DateTimeOffset Date { get; set; }
|
||||
}
|
||||
}
|
7
Geekbot.net/Commands/Utils/Changelog/CommitDto.cs
Normal file
7
Geekbot.net/Commands/Utils/Changelog/CommitDto.cs
Normal file
|
@ -0,0 +1,7 @@
|
|||
namespace Geekbot.net.Commands.Utils.Changelog
|
||||
{
|
||||
internal class CommitDto
|
||||
{
|
||||
public CommitInfoDto Commit { get; set; }
|
||||
}
|
||||
}
|
8
Geekbot.net/Commands/Utils/Changelog/CommitInfoDto.cs
Normal file
8
Geekbot.net/Commands/Utils/Changelog/CommitInfoDto.cs
Normal file
|
@ -0,0 +1,8 @@
|
|||
namespace Geekbot.net.Commands.Utils.Changelog
|
||||
{
|
||||
internal class CommitInfoDto
|
||||
{
|
||||
public CommitAuthorDto AuthorDto { get; set; }
|
||||
public string Message { get; set; }
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue