diff --git a/.vscode/settings.json b/.vscode/settings.json index c349671..bbecf8a 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -34,6 +34,8 @@ "release", "build", "docs", - "media" + "media", + "configs", + "leaderboards" ] } diff --git a/Metadata/README.md b/Metadata/README.md index 9767fcd..fa4d057 100644 --- a/Metadata/README.md +++ b/Metadata/README.md @@ -35,6 +35,12 @@ See the [current roadmap](https://github.com/nwesterhausen/valheim-discordconnec ## Changelog +### Version 2.1.3 + +Fixes: + +- Extra JSON data was getting sent to Discord when some LiteDB lookups were happening + ### Version 2.1.2 Mistlands update. diff --git a/Metadata/manifest.json b/Metadata/manifest.json index 5e877ac..6493b16 100644 --- a/Metadata/manifest.json +++ b/Metadata/manifest.json @@ -1,6 +1,6 @@ { "name": "DiscordConnector", - "version_number": "2.1.2", + "version_number": "2.1.3", "website_url": "https://discordconnector.valheim.nwest.games/", "description": "Connects your Valheim server to a Discord webhook. Works for both dedicated and client-hosted servers.", "dependencies": ["denikson-BepInExPack_Valheim-5.4.1901"] diff --git a/Metadata/thunderstore.toml b/Metadata/thunderstore.toml index 4e3dc43..02a53e1 100644 --- a/Metadata/thunderstore.toml +++ b/Metadata/thunderstore.toml @@ -4,7 +4,7 @@ schemaVersion = "0.0.1" [package] namespace = "nwesterhausen" name = "DiscordConnector" -versionNumber = "2.1.2" +versionNumber = "2.1.3" description = "Connects your Valheim server to a Discord webhook. Works for both dedicated and client-hosted servers." websiteUrl = "https://discordconnector.valheim.nwest.games/" containsNsfwContent = false diff --git a/README.md b/README.md index fd9ab0a..f1c4fd7 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ [![Build](https://github.com/nwesterhausen/valheim-discordconnector/actions/workflows/dotnet.yml/badge.svg)](https://github.com/nwesterhausen/valheim-discordconnector/actions/workflows/dotnet.yml) [![Publish](https://github.com/nwesterhausen/valheim-discordconnector/actions/workflows/publish.yml/badge.svg)](https://github.com/nwesterhausen/valheim-discordconnector/actions/workflows/publish.yml) [![GitHub release (latest by date)](https://img.shields.io/github/v/release/nwesterhausen/valheim-discordconnector?label=Github%20Release&style=flat&labelColor=%2332393F)](https://github.com/nwesterhausen/valheim-discordconnector/releases/latest) -[![Thunderstore.io](https://img.shields.io/badge/Thunderstore.io-2.1.2-%23375a7f?style=flat&labelColor=%2332393F)](https://valheim.thunderstore.io/package/nwesterhausen/DiscordConnector/) +[![Thunderstore.io](https://img.shields.io/badge/Thunderstore.io-2.1.3-%23375a7f?style=flat&labelColor=%2332393F)](https://valheim.thunderstore.io/package/nwesterhausen/DiscordConnector/) [![NexusMods](https://img.shields.io/badge/NexusMods-2.0.6-%23D98F40?style=flat&labelColor=%2332393F)](https://www.nexusmods.com/valheim/mods/1551/) Connect your Valheim server to Discord. ([See website for installation or configuration instructions](https://discordconnector.valheim.nwest.games/)). This plugin is largely based on [valheim-discord-notifier](https://github.com/aequasi/valheim-discord-notifier), but this plugin supports randomized messages, muting players, and Discord message embeds. diff --git a/docs/changelog.md b/docs/changelog.md index 65608fd..c75fd91 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -2,6 +2,12 @@ A full changelog of changes, dating all the way back to the first release. +## Version 2.1.3 + +Fixes: + +- Extra JSON data was getting sent to Discord when some LiteDB lookups were happening + ## Version 2.1.2 Mistlands update. diff --git a/src/Config/PluginConfig.cs b/src/Config/PluginConfig.cs index 7604de9..f38a24b 100644 --- a/src/Config/PluginConfig.cs +++ b/src/Config/PluginConfig.cs @@ -15,6 +15,7 @@ internal class PluginConfig private VariableConfig variableConfig; private LeaderBoardConfig leaderBoardConfig; public readonly string configPath; + const string ConfigJsonFilename = "config-dump.json"; /// /// Valid extensions for the config files, plus a reference for main. @@ -273,9 +274,9 @@ public void DumpConfigAsJson() System.Threading.Tasks.Task.Run(() => { - string configDump = Path.Combine(configPath, "config-debug.json"); + string configDump = Path.Combine(configPath, ConfigJsonFilename); File.WriteAllText(configDump, jsonString); - Plugin.StaticLogger.LogDebug("Dumped configuration files to JSON for debugging (if needed)."); + Plugin.StaticLogger.LogDebug($"Dumped configuration files to {ConfigJsonFilename}"); }); } } diff --git a/src/Config/TogglesConfig.cs b/src/Config/TogglesConfig.cs index 2d97bd4..d054b36 100644 --- a/src/Config/TogglesConfig.cs +++ b/src/Config/TogglesConfig.cs @@ -296,7 +296,7 @@ public string ConfigAsJson() jsonString += $"\"debugEventChanges\":\"{DebugEveryEventChange}\","; jsonString += $"\"debugDatabaseMethods\":\"{DebugDatabaseMethods}\","; jsonString += $"\"debugHttpRequestResponses\":\"{DebugHttpRequestResponse}\""; - jsonString += "},"; + jsonString += "}"; jsonString += "}"; return jsonString; diff --git a/src/DiscordApi.cs b/src/DiscordApi.cs index 0b7c6bf..b41e627 100644 --- a/src/DiscordApi.cs +++ b/src/DiscordApi.cs @@ -53,16 +53,21 @@ public static void SendMessage(string message) /// Discord fields as defined in the API, as Tuples (field name, value) public static void SendMessageWithFields(string content = null, List> fields = null) { - + // Guard against null/empty calls if (string.IsNullOrEmpty(content) && fields == null) { content = "Uh-oh! An unexpectedly empty message was sent!"; } + // Begin the payload object string payloadString = "{"; + // If we have fields at all, put them as embedded fields if (fields != null) { + // Fields go under embed as array payloadString += "\"embeds\":[{\"fields\":["; + + // Convert the fields into JSON Strings List fieldStrings = new List(); foreach (Tuple t in fields) { @@ -72,19 +77,29 @@ public static void SendMessageWithFields(string content = null, List { + // We have to write the data to the request Stream dataStream = request.GetRequestStream(); dataStream.Write(byteArray, 0, byteArray.Length); dataStream.Close(); + // Wait for a response to the web request WebResponse response = request.GetResponse(); if (Plugin.StaticConfig.DebugHttpRequestResponse) { diff --git a/src/PluginInfo.cs b/src/PluginInfo.cs index 88f0db6..1aaf3a6 100644 --- a/src/PluginInfo.cs +++ b/src/PluginInfo.cs @@ -17,7 +17,7 @@ internal static class PluginInfo { public const string PLUGIN_ID = "games.nwest.valheim.discordconnector"; public const string PLUGIN_NAME = "Valheim Discord Connector"; - public const string PLUGIN_VERSION = "2.1.2"; + public const string PLUGIN_VERSION = "2.1.3"; public const string PLUGIN_REPO_SHORT = "github: nwesterhausen/valheim-discordconnector"; public const string PLUGIN_AUTHOR = "Nicholas Westerhausen"; public const string SHORT_PLUGIN_ID = "discordconnector"; diff --git a/src/Records/Database.cs b/src/Records/Database.cs index 1496460..4b238ae 100644 --- a/src/Records/Database.cs +++ b/src/Records/Database.cs @@ -362,11 +362,6 @@ private List AllTimeOnlineRecordsGrouped() results.Add(new CountResult(player.CharacterName, (int)onlineTime.TotalSeconds)); } - Task.Run(() => - { - DiscordApi.SendMessage(JsonConvert.SerializeObject(results)); - }); - return results; } @@ -531,11 +526,6 @@ private List TimeOnlineRecordsWhereDate(System.DateTime startDate, results.Add(new CountResult(player.CharacterName, (int)onlineTime.TotalSeconds)); } - Task.Run(() => - { - DiscordApi.SendMessage(JsonConvert.SerializeObject(results)); - }); - return results; }