diff --git a/DiscordAlert/DiscordAlert.cs b/DiscordAlert/DiscordAlert.cs index b618d83..2319ecf 100644 --- a/DiscordAlert/DiscordAlert.cs +++ b/DiscordAlert/DiscordAlert.cs @@ -41,6 +41,18 @@ public string DiscordWebhookURL { } } + public bool DiscordEmbeds { + get { + return Settings.Default.DiscordEmbeds; + } + set { + Logger.Debug($"Set discord embeds={value}"); + Settings.Default.DiscordEmbeds = value; + CoreUtil.SaveSettings(Settings.Default); + RaisePropertyChanged(); + } + } + public event PropertyChangedEventHandler PropertyChanged; protected void RaisePropertyChanged([CallerMemberName] string propertyName = null) { this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); diff --git a/DiscordAlert/DiscordAlert.csproj b/DiscordAlert/DiscordAlert.csproj index 40e66be..61cd03d 100644 --- a/DiscordAlert/DiscordAlert.csproj +++ b/DiscordAlert/DiscordAlert.csproj @@ -20,6 +20,19 @@ + + + True + True + Settings.Settings + + + + + SettingsSingleFileGenerator + Settings.Designer.cs + + diff --git a/DiscordAlert/DiscordWebhook/DiscordHelper.cs b/DiscordAlert/DiscordWebhook/DiscordHelper.cs index 68f1269..d15cd80 100644 --- a/DiscordAlert/DiscordWebhook/DiscordHelper.cs +++ b/DiscordAlert/DiscordWebhook/DiscordHelper.cs @@ -64,9 +64,11 @@ public async Task SendMessage(MessageType type, string message, ISequenceEntity embed.ImageUrl = $"attachment://{Helpers.File.GetFileName(attachedFilename)}"; var embeds = new List { embed.Build() }; await client.SendFileAsync(attachedFilename, text: message, embeds: embeds); - } else { + } else if (client.UseEmbeds || exception != null) { var embeds = new List { embed.Build() }; await client.SendMessageAsync(text: message, embeds: embeds); + } else { + await client.SendMessageAsync(text: message, embeds: null); } } diff --git a/DiscordAlert/DiscordWebhook/DiscordWebhookClient.cs b/DiscordAlert/DiscordWebhook/DiscordWebhookClient.cs index e5f78b8..9f44a14 100644 --- a/DiscordAlert/DiscordWebhook/DiscordWebhookClient.cs +++ b/DiscordAlert/DiscordWebhook/DiscordWebhookClient.cs @@ -8,8 +8,14 @@ namespace NINA.DiscordAlert.DiscordWebhook { [ExcludeFromCodeCoverage(Justification = "This class is a passthrough to the actual discord client")] public class DiscordWebhookClient : IDiscordWebhookClient { - public DiscordWebhookClient(string url) { + private bool useEmbeds; + + public bool UseEmbeds => useEmbeds; + + public DiscordWebhookClient(string url, bool embeds) { Logger.Debug($"URL={url}"); + Logger.Debug($"Embeds={embeds}"); + this.useEmbeds = embeds; try { _discordWebhookClient = new Discord.Webhook.DiscordWebhookClient(url); } diff --git a/DiscordAlert/DiscordWebhook/DiscordWebhookClientFactory.cs b/DiscordAlert/DiscordWebhook/DiscordWebhookClientFactory.cs index c9209aa..8481519 100644 --- a/DiscordAlert/DiscordWebhook/DiscordWebhookClientFactory.cs +++ b/DiscordAlert/DiscordWebhook/DiscordWebhookClientFactory.cs @@ -5,7 +5,7 @@ namespace NINA.DiscordAlert.DiscordWebhook { [ExcludeFromCodeCoverage] public class DiscordWebhookClientFactory : IDiscordWebhookClientFactory { public IDiscordWebhookClient Create() { - return new DiscordWebhookClient(Properties.Settings.Default.DiscordWebhookURL); + return new DiscordWebhookClient(Properties.Settings.Default.DiscordWebhookURL, Properties.Settings.Default.DiscordEmbeds); } } } diff --git a/DiscordAlert/DiscordWebhook/IDiscordWebhookClient.cs b/DiscordAlert/DiscordWebhook/IDiscordWebhookClient.cs index df7cf68..d4a7182 100644 --- a/DiscordAlert/DiscordWebhook/IDiscordWebhookClient.cs +++ b/DiscordAlert/DiscordWebhook/IDiscordWebhookClient.cs @@ -6,6 +6,8 @@ namespace NINA.DiscordAlert.DiscordWebhook { public interface IDiscordWebhookClient : IDisposable { + bool UseEmbeds { get; } + Task SendMessageAsync(string text = null, bool isTTS = false, IEnumerable embeds = null, string username = null, string avatarUrl = null, RequestOptions options = null, AllowedMentions allowedMentions = null, MessageComponent components = null, MessageFlags flags = MessageFlags.None, ulong? threadId = null); Task SendFileAsync(string filename, string text = null, IEnumerable embeds = null); diff --git a/DiscordAlert/Options.xaml b/DiscordAlert/Options.xaml index e432bb4..d4f3ecd 100644 --- a/DiscordAlert/Options.xaml +++ b/DiscordAlert/Options.xaml @@ -6,9 +6,15 @@ - - - - + + + + + + + + + + \ No newline at end of file diff --git a/DiscordAlert/Properties/Settings.Designer.cs b/DiscordAlert/Properties/Settings.Designer.cs index c8e87e1..98331de 100644 --- a/DiscordAlert/Properties/Settings.Designer.cs +++ b/DiscordAlert/Properties/Settings.Designer.cs @@ -12,7 +12,7 @@ namespace NINA.DiscordAlert.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.7.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.8.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); @@ -46,5 +46,17 @@ public bool UpdateSettings { this["UpdateSettings"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("False")] + public bool DiscordEmbeds { + get { + return ((bool)(this["DiscordEmbeds"])); + } + set { + this["DiscordEmbeds"] = value; + } + } } } diff --git a/DiscordAlert/Properties/Settings.Settings b/DiscordAlert/Properties/Settings.Settings index 6d9a3cb..185bd8c 100644 --- a/DiscordAlert/Properties/Settings.Settings +++ b/DiscordAlert/Properties/Settings.Settings @@ -1,5 +1,5 @@  - + @@ -8,5 +8,8 @@ True + + False + \ No newline at end of file diff --git a/DiscordAlert/app.config b/DiscordAlert/app.config index df79187..40aeb9d 100644 --- a/DiscordAlert/app.config +++ b/DiscordAlert/app.config @@ -84,10 +84,24 @@ + + + + + + True + + + False + + + + + True