Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions DiscordAlert/DiscordAlert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
13 changes: 13 additions & 0 deletions DiscordAlert/DiscordAlert.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,19 @@
<Reference Include="System.Printing" />
<Reference Include="System.Windows" />
</ItemGroup>
<ItemGroup>
<Compile Update="Properties\Settings.Designer.cs">
<DesignTimeSharedInput>True</DesignTimeSharedInput>
<AutoGen>True</AutoGen>
<DependentUpon>Settings.Settings</DependentUpon>
</Compile>
</ItemGroup>
<ItemGroup>
<None Update="Properties\Settings.Settings">
<Generator>SettingsSingleFileGenerator</Generator>
<LastGenOutput>Settings.Designer.cs</LastGenOutput>
</None>
</ItemGroup>
<PropertyGroup />
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec IgnoreExitCode="true" Command="if $(ConfigurationName) == Debug (&#xD;&#xA; &#xD;&#xA; &#xD;&#xA;&#xD;&#xA;if not exist &quot;%25localappdata%25\NINA\Plugins&quot; (&#xD;&#xA; echo &quot;Creating Plugins %25localappdata%25\NINA\Plugins folder&quot;&#xD;&#xA; mkdir &quot;%25localappdata%25\NINA\Plugins&quot;&#xD;&#xA;)&#xD;&#xA;&#xD;&#xA;if not exist &quot;%25localappdata%25\NINA\Plugins\3.0.0&quot; (&#xD;&#xA; echo &quot;Creating $(PlatformName) Plugins Version folder&quot;&#xD;&#xA; mkdir &quot;%25localappdata%25\NINA\Plugins&quot;&#xD;&#xA;)&#xD;&#xA;&#xD;&#xA;if exist &quot;%25localappdata%25\NINA\Plugins\3.0.0\$(TargetName)&quot; (&#xD;&#xA; echo &quot; folder cleanup&quot;&#xD;&#xA; rmdir &quot;%25localappdata%25\NINA\Plugins\3.0.0\$(TargetName)&quot; /S /Q&#xD;&#xA;)&#xD;&#xA;&#xD;&#xA;if not exist &quot;%25localappdata%25\NINA\Plugins\3.0.0\$(TargetName)&quot; (&#xD;&#xA; echo &quot;Creating %25localappdata%25\NINA\Plugins\3.0.0\$(TargetName) folder&quot;&#xD;&#xA; mkdir &quot;%25localappdata%25\NINA\Plugins\3.0.0\$(TargetName)&#xD;&#xA;)&#xD;&#xA;echo &quot;Copying $(TargetDir)$(TargetFileName)&quot;&#xD;&#xA;copy &quot;$(TargetDir)$(TargetFileName)&quot; &quot;%25localappdata%25\NINA\Plugins\3.0.0\$(TargetName)\$(TargetFileName)&quot; /Y&#xD;&#xA;&#xD;&#xA;echo &quot;Copying $(TargetDir)Discord.Net.Core.dll&quot;&#xD;&#xA;copy &quot;$(TargetDir)Discord.Net.Core.dll&quot; &quot;%25localappdata%25\NINA\Plugins\3.0.0\$(TargetName)\Discord.Net.Core.dll&quot; /Y&#xD;&#xA;&#xD;&#xA;echo &quot;Copying $(TargetDir)Discord.Net.Webhook.dll&quot;&#xD;&#xA;copy &quot;$(TargetDir)Discord.Net.Webhook.dll&quot; &quot;%25localappdata%25\NINA\Plugins\3.0.0\$(TargetName)\Discord.Net.Webhook.dll&quot; /Y&#xD;&#xA;&#xD;&#xA;echo &quot;Copying $(TargetDir)Discord.Net.Rest.dll&quot;&#xD;&#xA;copy &quot;$(TargetDir)Discord.Net.Rest.dll&quot; &quot;%25localappdata%25\NINA\Plugins\3.0.0\$(TargetName)\Discord.Net.Rest.dll&quot; /Y&#xD;&#xA;&#xD;&#xA;)" />
Expand Down
4 changes: 3 additions & 1 deletion DiscordAlert/DiscordWebhook/DiscordHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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> { embed.Build() };
await client.SendFileAsync(attachedFilename, text: message, embeds: embeds);
} else {
} else if (client.UseEmbeds || exception != null) {
var embeds = new List<Embed> { embed.Build() };
await client.SendMessageAsync(text: message, embeds: embeds);
} else {
await client.SendMessageAsync(text: message, embeds: null);
}
}

Expand Down
8 changes: 7 additions & 1 deletion DiscordAlert/DiscordWebhook/DiscordWebhookClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion DiscordAlert/DiscordWebhook/DiscordWebhookClientFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
2 changes: 2 additions & 0 deletions DiscordAlert/DiscordWebhook/IDiscordWebhookClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
namespace NINA.DiscordAlert.DiscordWebhook {
public interface IDiscordWebhookClient : IDisposable
{
bool UseEmbeds { get; }

Task SendMessageAsync(string text = null, bool isTTS = false, IEnumerable<Embed> 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<Embed> embeds = null);
Expand Down
14 changes: 10 additions & 4 deletions DiscordAlert/Options.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,15 @@
<!-- In order for this datatemplate to be picked correctly, the key has to follow the naming convention of <IPlugin.Name>_Options -->
<!-- Furthermore the Resource Dictionary has to be exported via code behind export attributes -->
<DataTemplate x:Key="Discord Alert_Options">
<DockPanel LastChildFill="True" Margin="0,5,0,0">
<TextBlock DockPanel.Dock="Left" VerticalAlignment="Center" Text="Discord Webhook URL" />
<TextBox DockPanel.Dock="Left" VerticalAlignment="Center" MinWidth="50" Margin="5,0,0,0" Text="{Binding DiscordWebhookURL}" />
</DockPanel>
<StackPanel Orientation="Vertical">
<DockPanel LastChildFill="True">
<TextBlock DockPanel.Dock="Left" VerticalAlignment="Center" Text="Discord Webhook URL" />
<TextBox DockPanel.Dock="Left" VerticalAlignment="Center" MinWidth="50" Margin="5,0,0,0" Text="{Binding DiscordWebhookURL}" />
</DockPanel>
<StackPanel Orientation="Horizontal">
<TextBlock Text="Use message embeds" />
<CheckBox MinWidth="80" HorizontalAlignment="Left" VerticalAlignment="Center" IsChecked="{Binding DiscordEmbeds}" ToolTip="(Image and error embeds wi8ll always be sent even if this is deactivated)"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</ResourceDictionary>
14 changes: 13 additions & 1 deletion DiscordAlert/Properties/Settings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion DiscordAlert/Properties/Settings.Settings
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="DrewMcdermott.NINA.DiscordAlert.Properties" GeneratedClassName="Settings">
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" GeneratedClassNamespace="NINA.DiscordAlert.Properties" GeneratedClassName="Settings">
<Profiles />
<Settings>
<Setting Name="DiscordWebhookURL" Type="System.String" Scope="User">
Expand All @@ -8,5 +8,8 @@
<Setting Name="UpdateSettings" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="DiscordEmbeds" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
</Settings>
</SettingsFile>
14 changes: 14 additions & 0 deletions DiscordAlert/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -84,10 +84,24 @@
</assemblyBinding>
</runtime>
<userSettings>
<NINA.DiscordAlert.Properties.Settings>
<setting name="DiscordWebhookURL" serializeAs="String">
<value />
</setting>
<setting name="UpdateSettings" serializeAs="String">
<value>True</value>
</setting>
<setting name="DiscordEmbeds" serializeAs="String">
<value>False</value>
</setting>
</NINA.DiscordAlert.Properties.Settings>
<DrewMcdermott.NINA.DiscordAlert.Properties.Settings>
<setting name="DiscordWebhookURL" serializeAs="String">
<value />
</setting>
<setting name="DiscordEmbeds" serializeAs="String">
<value />
</setting>
<setting name="UpdateSettings" serializeAs="String">
<value>True</value>
</setting>
Expand Down