diff --git a/SquadForger/App.config b/SquadForger/App.config
index 45dbf1a..aa001be 100644
--- a/SquadForger/App.config
+++ b/SquadForger/App.config
@@ -3,9 +3,10 @@
-
-
+
+
+
diff --git a/SquadForger/Components/BindabalePasswordBox.xaml b/SquadForger/Components/BindabalePasswordBox.xaml
new file mode 100644
index 0000000..b970269
--- /dev/null
+++ b/SquadForger/Components/BindabalePasswordBox.xaml
@@ -0,0 +1,10 @@
+
+
+
diff --git a/SquadForger/Components/BindabalePasswordBox.xaml.cs b/SquadForger/Components/BindabalePasswordBox.xaml.cs
new file mode 100644
index 0000000..9564aa2
--- /dev/null
+++ b/SquadForger/Components/BindabalePasswordBox.xaml.cs
@@ -0,0 +1,27 @@
+using System.Windows;
+using System.Windows.Controls;
+
+namespace SquadForger.Components
+{
+ public partial class BindabalePasswordBox : UserControl
+ {
+ public static readonly DependencyProperty PasswordProperty = DependencyProperty.Register(
+ "Password", typeof(string), typeof(BindabalePasswordBox), new PropertyMetadata("Discord Webhook ID"));
+
+ public string Password
+ {
+ get { return (string)GetValue(PasswordProperty); }
+ set { SetValue(PasswordProperty, value); }
+ }
+
+ public BindabalePasswordBox()
+ {
+ InitializeComponent();
+ }
+
+ private void PasswordBox_OnPasswordChanged(object sender, RoutedEventArgs e)
+ {
+ Password=passwordBox.Password;
+ }
+ }
+}
\ No newline at end of file
diff --git a/SquadForger/SquadForger.csproj b/SquadForger/SquadForger.csproj
index f55dbcb..94e1aed 100644
--- a/SquadForger/SquadForger.csproj
+++ b/SquadForger/SquadForger.csproj
@@ -242,6 +242,9 @@
MSBuild:Compile
Designer
+
+ BindabalePasswordBox.xaml
+
@@ -262,6 +265,7 @@
SquadView.xaml
+
MSBuild:Compile
Designer
@@ -301,9 +305,7 @@
Resources.Designer.cs
-
- Always
-
+
SettingsSingleFileGenerator
Settings.Designer.cs
diff --git a/SquadForger/View/DiscordView.xaml b/SquadForger/View/DiscordView.xaml
index d0fc61d..cd63069 100644
--- a/SquadForger/View/DiscordView.xaml
+++ b/SquadForger/View/DiscordView.xaml
@@ -4,6 +4,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:SquadForger.View"
+ xmlns:components = "clr-namespace:SquadForger.Components"
xmlns:vm="clr-namespace:SquadForger.ViewModel"
mc:Ignorable="d"
Background="Transparent"
@@ -73,6 +74,7 @@
+
@@ -93,13 +95,26 @@
Margin="0,0,10,0"
Background="#e3c57e"
Foreground="black"/>
-
+
+
-
+
+
+
+
+
+
+
diff --git a/SquadForger/ViewModel/DiscordVM.cs b/SquadForger/ViewModel/DiscordVM.cs
index 056735f..ef463c5 100644
--- a/SquadForger/ViewModel/DiscordVM.cs
+++ b/SquadForger/ViewModel/DiscordVM.cs
@@ -6,8 +6,11 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
+using System.IO;
using System.Linq;
+using System.Text.RegularExpressions;
using System.Windows;
+using System.Xml;
using SquadForger.Model;
using SquadForger.Services;
@@ -23,12 +26,14 @@ public string TextToSend
}
public RelayCommand PostToDiscordCommand { get; private set; }
public RelayCommand UpdatePreviewCommand { get; private set; }
+ public RelayCommand UpdateWebhookIDCommand { get; private set; }
public List Teams { get; private set; } = new List();
+ public string WebhookID { get; set; } = "";
public DiscordVM()
{
PostToDiscordCommand = new RelayCommand(PostToDiscord);
UpdatePreviewCommand = new RelayCommand(UpdatePreview);
-
+ UpdateWebhookIDCommand = new RelayCommand(UpdateWebhookID);
ServiceLocator.Instance.EventAggregator.Subscribe(OnTeamsUpdated);
}
private void OnTeamsUpdated(TeamsUpdatedEvent eventArgs)
@@ -48,6 +53,51 @@ private void UpdatePreview()
TextToSend = stringBuilder.ToString();
}
+
+ private void UpdateWebhookID()
+ {
+ if (string.IsNullOrEmpty(WebhookID))
+ {
+ MessageBox.Show("Webhook ID is empty!", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
+ return;
+ }
+
+ string discordWebhookPattern = @"^https:\/\/discord\.com\/api\/webhooks\/\d+\/[A-Za-z0-9_-]+$";
+ if (!Regex.IsMatch(WebhookID, discordWebhookPattern))
+ {
+ MessageBox.Show("Invalid Webhook ID format. Please provide a valid Discord Webhook URL.", "Warning", MessageBoxButton.OK, MessageBoxImage.Warning);
+ return;
+ }
+ UpdateWebhookInConfig(WebhookID);
+ }
+
+ private void UpdateWebhookInConfig( string newWebhookID)
+ {
+ string configFilePath = AppDomain.CurrentDomain.SetupInformation.ConfigurationFile;
+
+ // Step 1: Load the app.config file
+ XmlDocument xmlDoc = new XmlDocument();
+ xmlDoc.Load(configFilePath);
+
+ // Find the 'dev_webhook' node
+ XmlNode webhookNode = xmlDoc.SelectSingleNode("//appSettings/add[@key='dev_webhook']");
+
+ if (webhookNode != null)
+ {
+ // Update the webhook ID value
+ webhookNode.Attributes["value"].Value = newWebhookID;
+
+ // Save the updated config file
+ xmlDoc.Save(configFilePath);
+ ConfigurationManager.RefreshSection("appSettings");
+ MessageBox.Show("Webhook ID updated successfully in app.config!", "Success", MessageBoxButton.OK, MessageBoxImage.Information);
+ }
+ else
+ {
+ MessageBox.Show("Webhook ID key not found in app.config.", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
+ }
+ }
+
private async void PostToDiscord()
{
if (TextToSend.Equals(""))