feat: feedback modal

This commit is contained in:
goat 2021-09-27 22:29:52 +02:00
parent 6ba5525812
commit 689b8fa847
No known key found for this signature in database
GPG key ID: F18F057873895461
6 changed files with 180 additions and 11 deletions

View file

@ -0,0 +1,61 @@
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using Dalamud.Plugin.Internal.Types;
using Dalamud.Utility;
using Newtonsoft.Json;
namespace Dalamud.Support
{
/// <summary>
/// Class responsible for sending feedback.
/// </summary>
internal static class BugBait
{
private const string BugBaitUrl = "https://dalamud-bugbait.goatsoft.workers.dev/feedback";
/// <summary>
/// Send feedback to Discord.
/// </summary>
/// <param name="plugin">The plugin to send feedback about.</param>
/// <param name="content">The content of the feedback.</param>
/// <param name="reporter">The reporter name.</param>
/// <returns>A <see cref="Task"/> representing the asynchronous operation.</returns>
public static async Task SendFeedback(PluginManifest plugin, string content, string reporter)
{
if (content.IsNullOrWhitespace())
return;
using var client = new HttpClient();
var model = new FeedbackModel
{
Content = content,
Reporter = reporter,
Name = plugin.InternalName,
Version = plugin.AssemblyVersion.ToString(),
};
var postContent = new StringContent(JsonConvert.SerializeObject(model), Encoding.UTF8, "application/json");
var response = await client.PostAsync(BugBaitUrl, postContent);
response.EnsureSuccessStatusCode();
}
private class FeedbackModel
{
[JsonProperty("content")]
public string? Content { get; set; }
[JsonProperty("name")]
public string? Name { get; set; }
[JsonProperty("version")]
public string? Version { get; set; }
[JsonProperty("reporter")]
public string? Reporter { get; set; }
}
}
}

View file

@ -0,0 +1,111 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Dalamud.Configuration;
using Dalamud.Configuration.Internal;
using Dalamud.Interface.Internal;
using Dalamud.Plugin.Internal;
using Dalamud.Plugin.Internal.Types;
using Dalamud.Utility;
using Newtonsoft.Json;
using Serilog;
namespace Dalamud.Support
{
/// <summary>
/// Class responsible for printing troubleshooting information to the log.
/// </summary>
public static class Troubleshooting
{
/// <summary>
/// Log the last exception in a parseable format to serilog.
/// </summary>
/// <param name="exception">The exception to log.</param>
/// <param name="context">Additional context.</param>
public static void LogException(Exception exception, string context)
{
try
{
var payload = new ExceptionPayload
{
Context = context,
When = DateTime.Now,
Info = exception.ToString(),
};
var encodedPayload = Convert.ToBase64String(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(payload)));
Log.Information($"LASTEXCEPTION:{encodedPayload}");
}
catch (Exception ex)
{
Log.Error(ex, "Could not print exception.");
}
}
/// <summary>
/// Log troubleshooting information in a parseable format to Serilog.
/// </summary>
internal static void LogTroubleshooting()
{
var startInfo = Service<DalamudStartInfo>.Get();
var configuration = Service<DalamudConfiguration>.Get();
var interfaceManager = Service<InterfaceManager>.GetNullable();
var pluginManager = Service<PluginManager>.GetNullable();
try
{
var payload = new TroubleshootingPayload
{
LoadedPlugins = pluginManager?.InstalledPlugins?.Select(x => x.Manifest)?.ToArray(),
DalamudVersion = Util.AssemblyVersion,
DalamudGitHash = Util.GetGitHash(),
GameVersion = startInfo.GameVersion.ToString(),
Language = startInfo.Language.ToString(),
DoDalamudTest = configuration.DoDalamudTest,
DoPluginTest = configuration.DoPluginTest,
InterfaceLoaded = interfaceManager?.IsReady ?? false,
ThirdRepo = configuration.ThirdRepoList,
};
var encodedPayload = Convert.ToBase64String(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(payload)));
Log.Information($"TROUBLESHOOTING:{encodedPayload}");
}
catch (Exception ex)
{
Log.Error(ex, "Could not print troubleshooting.");
}
}
private class ExceptionPayload
{
public DateTime When { get; set; }
public string Info { get; set; }
public string Context { get; set; }
}
private class TroubleshootingPayload
{
public PluginManifest[] LoadedPlugins { get; set; }
public string DalamudVersion { get; set; }
public string DalamudGitHash { get; set; }
public string GameVersion { get; set; }
public string Language { get; set; }
public bool DoDalamudTest { get; set; }
public bool DoPluginTest { get; set; }
public bool InterfaceLoaded { get; set; }
public List<ThirdPartyRepoSettings> ThirdRepo { get; set; }
}
}
}