From bd203c5dae28705249f437ca982aef29e06d4434 Mon Sep 17 00:00:00 2001 From: Dave Ross Date: Tue, 12 Nov 2024 08:21:06 +0000 Subject: [PATCH 1/3] Update .gitignore --- .gitignore | 1 + DiscordBotPlugin/DiscordBotPlugin.csproj | 212 ----------------------- 2 files changed, 1 insertion(+), 212 deletions(-) delete mode 100644 DiscordBotPlugin/DiscordBotPlugin.csproj diff --git a/.gitignore b/.gitignore index d9b96aa..0f43315 100644 --- a/.gitignore +++ b/.gitignore @@ -339,3 +339,4 @@ ASALocalRun/ # BeatPulse healthcheck temp database healthchecksdb #/DiscordBotPlugin/DiscordBotPlugin.csproj +/DiscordBotPlugin/DiscordBotPlugin.csproj diff --git a/DiscordBotPlugin/DiscordBotPlugin.csproj b/DiscordBotPlugin/DiscordBotPlugin.csproj deleted file mode 100644 index 049a054..0000000 --- a/DiscordBotPlugin/DiscordBotPlugin.csproj +++ /dev/null @@ -1,212 +0,0 @@ - - - net8.0-windows - Library - SAK - SAK - SAK - SAK - false - true - true - - - Always - - - true - bin\CI_Build\ - MinimumRecommendedRules.ruleset - - - true - bin\Nightly\ - MinimumRecommendedRules.ruleset - - - - H:\AMPDatastore\Instances\Minecraft01\Plugins\FileManagerPlugin\FileManagerPlugin.dll - false - compile - - - H:\AMPDatastore\Instances\Minecraft01\Plugins\LocalFileBackupPlugin\LocalFileBackupPlugin.dll - false - compile - - - H:\AMPDatastore\Instances\Minecraft01\ModuleShared.dll - true - compile - - - - - - $(OutputPath)\Discord.Net.Commands.dll - true - - - - $(OutputPath)\Discord.Net.Core.dll - true - - - - $(OutputPath)\Discord.Net.Interactions.dll - true - - - - $(OutputPath)\Discord.Net.Rest.dll - true - - - - $(OutputPath)\Discord.Net.Webhook.dll - true - - - - $(OutputPath)\Discord.Net.WebSocket.dll - true - - - - $(OutputPath)\DiscordBotPlugin.dll - true - - - - $(OutputPath)\DotNetZip.dll - true - - - - $(OutputPath)\mHttp.dll - true - - - - $(OutputPath)\Microsoft.Bcl.AsyncInterfaces.dll - true - - - - $(OutputPath)\Microsoft.Build.Framework.dll - true - - - - $(OutputPath)\Microsoft.Build.Utilities.Core.dll - true - - - - $(OutputPath)\Microsoft.Extensions.DependencyInjection.Abstractions.dll - true - - - - $(OutputPath)\Mono.Posix.dll - true - - - - $(OutputPath)\Newtonsoft.Json.dll - true - - - - $(OutputPath)\System.Interactive.Async.dll - true - - - - $(OutputPath)\System.Linq.Async.dll - true - - - - $(OutputPath)\System.Reactive.dll - true - - - - $(OutputPath)\Unity.Abstractions.dll - true - - - - - - - - - - - - - - - - - - - - - - - - all - runtime; build; native; contentfiles; analyzers; buildtransitive - - - - - - - - - - - - - - - - - - true - - - - true - - - - - - - - - - - - $(MSBuildThisFileDirectory)bin\$(Configuration)\$(TargetFramework) - - - - - - - - - - - - - - - - \ No newline at end of file From 10c1d1c2ecb9cb1d132d636fc4f4e00d51712fd4 Mon Sep 17 00:00:00 2001 From: Dave Ross Date: Tue, 12 Nov 2024 08:21:19 +0000 Subject: [PATCH 2/3] Add {IPAddress} variable for server connection URL --- DiscordBotPlugin/Helpers.cs | 22 ++++++++++++++++++++++ DiscordBotPlugin/InfoPanel.cs | 8 +++++++- DiscordBotPlugin/Settings.cs | 8 ++++---- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/DiscordBotPlugin/Helpers.cs b/DiscordBotPlugin/Helpers.cs index 4c075da..53c1c4c 100644 --- a/DiscordBotPlugin/Helpers.cs +++ b/DiscordBotPlugin/Helpers.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Net.Http; using System.Threading.Tasks; using static DiscordBotPlugin.PluginMain; @@ -326,5 +327,26 @@ public List SplitOutputIntoCodeBlocks(List messages) return outputStrings; } + + public async Task GetExternalIpAddressAsync() + { + using (HttpClient client = new HttpClient()) + { + try + { + // Use a service that returns the IP address in plain text + HttpResponseMessage response = await client.GetAsync("https://api.ipify.org"); + response.EnsureSuccessStatusCode(); + + string ipAddress = await response.Content.ReadAsStringAsync(); + return ipAddress; + } + catch (Exception ex) + { + log.Error("Error fetching IP: " + ex.Message); + return null; + } + } + } } } diff --git a/DiscordBotPlugin/InfoPanel.cs b/DiscordBotPlugin/InfoPanel.cs index 16b29ba..939cd66 100644 --- a/DiscordBotPlugin/InfoPanel.cs +++ b/DiscordBotPlugin/InfoPanel.cs @@ -96,7 +96,13 @@ public async Task GetServerInfo(bool updateExisting, SocketSlashCommand msg, boo } embed.AddField("Server Name", "```" + settings?.MainSettings?.ServerDisplayName + "```", false); - embed.AddField("Server IP", "```" + settings?.MainSettings?.ServerConnectionURL + "```", false); + string connectionURL = settings.MainSettings.ServerConnectionURL; + if (connectionURL.ToLower().Contains("{ipaddress}")) + { + string ipAddress = await helper.GetExternalIpAddressAsync(); + connectionURL = connectionURL.ToLower().Replace("{ipaddress}", ipAddress); + } + embed.AddField("Server IP", "```" + connectionURL + "```", false); if (!string.IsNullOrEmpty(settings?.MainSettings?.ServerPassword)) { diff --git a/DiscordBotPlugin/Settings.cs b/DiscordBotPlugin/Settings.cs index 77d164c..415b7f2 100644 --- a/DiscordBotPlugin/Settings.cs +++ b/DiscordBotPlugin/Settings.cs @@ -23,7 +23,7 @@ public class DiscordBotSettings : SettingSectionStore [WebSetting("Server Display Name", "Displayed in the bot info panel", false, Subcategory: "Server Info:page_info:2")] public string ServerDisplayName = ""; - [WebSetting("Server Connection URL", "Displayed in bot info panel", false, Subcategory: "Server Info:page_info:2")] + [WebSetting("Server Connection URL", "Displayed in bot info panel. Use {IPAddress} variable to show your external IP address.", false, Subcategory: "Server Info:page_info:2")] public string ServerConnectionURL = ""; [WebSetting("Server Password", "Displayed in bot info panel", false, Subcategory: "Server Info:page_info:2")] @@ -143,7 +143,7 @@ public class DiscordBotSettings : SettingSectionStore } public DiscordBotSettings MainSettings = new DiscordBotSettings(); - + [Description("Discord Bot:smart_toy")] [SettingsGroupName("Discord Bot")] [Serializable] @@ -191,7 +191,7 @@ public class DiscordBotColoursSettings : SettingSectionStore public class DiscordBotGameSpecificSettings : SettingSectionStore { [WebSetting("Valheim Join Code", "Look for Valheim join code and display it in the info panel (restart the server after enabling)", false, Subcategory: "Game Specific:sports_esports:6")] - public bool ValheimJoinCode = false; + public bool ValheimJoinCode = false; } public DiscordBotGameSpecificSettings GameSpecificSettings = new DiscordBotGameSpecificSettings(); @@ -204,7 +204,7 @@ public class DiscordBotAboutSettings : SettingSectionStore [WebSetting("Support", "For support, or to submit issues and feature requests visit the [GitHub](https://github.com/winglessraven/AMP-Discord-Bot) page.", false, Subcategory: "About:info:8")] public int? AboutMessage = null; - [WebSetting("Donations", "If you appreciate my work, donations are gratefully received! Visit my [Sponsor](https://github.com/sponsors/winglessraven) page.", false, Subcategory: "About:info:8")] + [WebSetting("Donations", "If you appreciate my work, donations are gratefully received! Visit my [Sponsor](https://github.com/sponsors/winglessraven) page.", false, Subcategory: "About:info:8")] public int? DonationsMessage = null; [WebSetting("AMP Discord Bot", "Created by winglessraven", false, Subcategory: "About:info:8")] From 82516694d92260a22c1804bd29203fb20e20cf06 Mon Sep 17 00:00:00 2001 From: Dave Ross Date: Tue, 12 Nov 2024 09:49:41 +0000 Subject: [PATCH 3/3] Rename public IP variable for clarity --- DiscordBotPlugin/InfoPanel.cs | 4 ++-- DiscordBotPlugin/Settings.cs | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/DiscordBotPlugin/InfoPanel.cs b/DiscordBotPlugin/InfoPanel.cs index 939cd66..3ac420e 100644 --- a/DiscordBotPlugin/InfoPanel.cs +++ b/DiscordBotPlugin/InfoPanel.cs @@ -97,10 +97,10 @@ public async Task GetServerInfo(bool updateExisting, SocketSlashCommand msg, boo embed.AddField("Server Name", "```" + settings?.MainSettings?.ServerDisplayName + "```", false); string connectionURL = settings.MainSettings.ServerConnectionURL; - if (connectionURL.ToLower().Contains("{ipaddress}")) + if (connectionURL.ToLower().Contains("{publicip}")) { string ipAddress = await helper.GetExternalIpAddressAsync(); - connectionURL = connectionURL.ToLower().Replace("{ipaddress}", ipAddress); + connectionURL = connectionURL.ToLower().Replace("{publicip}", ipAddress); } embed.AddField("Server IP", "```" + connectionURL + "```", false); diff --git a/DiscordBotPlugin/Settings.cs b/DiscordBotPlugin/Settings.cs index 415b7f2..0aefc1b 100644 --- a/DiscordBotPlugin/Settings.cs +++ b/DiscordBotPlugin/Settings.cs @@ -23,7 +23,7 @@ public class DiscordBotSettings : SettingSectionStore [WebSetting("Server Display Name", "Displayed in the bot info panel", false, Subcategory: "Server Info:page_info:2")] public string ServerDisplayName = ""; - [WebSetting("Server Connection URL", "Displayed in bot info panel. Use {IPAddress} variable to show your external IP address.", false, Subcategory: "Server Info:page_info:2")] + [WebSetting("Server Connection URL", "Displayed in bot info panel. Use {PublicIP} variable to show your external IP address.", false, Subcategory: "Server Info:page_info:2")] public string ServerConnectionURL = ""; [WebSetting("Server Password", "Displayed in bot info panel", false, Subcategory: "Server Info:page_info:2")]