Skip to content

Commit

Permalink
Merge pull request #45 from MJHeijster/feature/ConfigUI
Browse files Browse the repository at this point in the history
Feature/config UI
  • Loading branch information
MJHeijster committed May 22, 2022
2 parents 5cbcf1d + 0ed2cd0 commit d7aba6f
Show file tree
Hide file tree
Showing 21 changed files with 625 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@
// <summary></summary>
// ***********************************************************************
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace StatBot.Settings
{
Expand All @@ -35,15 +31,14 @@ public BotSettings(IConfiguration configuration)
Application = new Application(configuration);
mIRCStats = new MIRCStats(configuration);
Discord = new Discord(configuration);
VerifySettings();
}

/// <summary>
/// Verifies the settings.
/// </summary>
/// <exception cref="System.Exception">Discord bot token missing.</exception>
/// <exception cref="System.Exception">Logging file name missing.</exception>
private void VerifySettings()
public void VerifySettings()
{
if (String.IsNullOrEmpty(Discord.Token))
throw new Exception("Discord bot token missing.");
Expand All @@ -55,17 +50,17 @@ private void VerifySettings()
/// Gets the discord.
/// </summary>
/// <value>The discord.</value>
public Discord Discord { get; }
public Discord Discord { get; set; }
/// <summary>
/// Gets the m irc stats.
/// </summary>
/// <value>The m irc stats.</value>
public MIRCStats mIRCStats { get; }
public MIRCStats mIRCStats { get; set; }
/// <summary>
/// Gets the application.
/// </summary>
/// <value>The application.</value>
public Application Application { get; }
public Application Application { get; set; }
}

/// <summary>
Expand All @@ -92,37 +87,37 @@ public Application(IConfiguration configuration)
/// Gets the name of the logging file.
/// </summary>
/// <value>The name of the logging file.</value>
public string LoggingFileName { get; }
public string LoggingFileName { get; set; }
/// <summary>
/// Gets the notification delay.
/// </summary>
/// <value>The notification delay.</value>
public int NotificationDelay { get; }
public int NotificationDelay { get; set; }
/// <summary>
/// Gets the push over.
/// </summary>
/// <value>The push over.</value>
public PushOver PushOver { get; }
public PushOver PushOver { get; set; }
/// <summary>
/// Gets a value indicating whether [create nicks file automatically].
/// </summary>
/// <value><c>true</c> if [create nicks file automatically]; otherwise, <c>false</c>.</value>
public bool CreateNicksFileAutomatically { get; }
public bool CreateNicksFileAutomatically { get; set; }
/// <summary>
/// Gets a value indicating whether [show discrim].
/// </summary>
/// <value><c>true</c> if [show discrim]; otherwise, <c>false</c>.</value>
public bool ShowDiscrim { get; }
public bool ShowDiscrim { get; set; }
/// <summary>
/// Gets a value indicating whether [show avatar].
/// </summary>
/// <value><c>true</c> if [show avatar]; otherwise, <c>false</c>.</value>
public bool ShowAvatar { get; }
public bool ShowAvatar { get; set; }
/// <summary>
/// Gets the nicks file manual.
/// </summary>
/// <value>The nicks file manual.</value>
public string NicksFileManual { get; }
public string NicksFileManual { get; set; }
}

/// <summary>
Expand All @@ -146,22 +141,22 @@ public Commands(IConfiguration configuration)
/// Gets the prefix.
/// </summary>
/// <value>The prefix.</value>
public string Prefix { get; }
public string Prefix { get; set; }
/// <summary>
/// Gets the exclude.
/// </summary>
/// <value>The exclude.</value>
public string Exclude { get; }
public string Exclude { get; set; }
/// <summary>
/// Gets the include.
/// </summary>
/// <value>The include.</value>
public string Include { get; }
public string Include { get; set; }
/// <summary>
/// Gets the stats.
/// </summary>
/// <value>The stats.</value>
public Stats Stats { get; }
public Stats Stats { get; set; }
}

/// <summary>
Expand All @@ -185,22 +180,23 @@ public Discord(IConfiguration configuration)
/// Gets the token.
/// </summary>
/// <value>The token.</value>
public string Token { get; }
public string Token { get; set; }
/// <summary>
/// Gets the debug channel identifier.
/// </summary>
/// <value>The debug channel identifier.</value>
public string DebugChannelId { get; }
public string DebugChannelId { get; set; }
/// <summary>
/// Gets or sets a value indicating whether [log to debug channel].
/// </summary>
/// <value><c>true</c> if [log to debug channel]; otherwise, <c>false</c>.</value>
[JsonIgnore]
public bool LogToDebugChannel { get; set; }
/// <summary>
/// Gets the commands.
/// </summary>
/// <value>The commands.</value>
public Commands Commands { get; }
public Commands Commands { get; set; }
}

/// <summary>
Expand All @@ -227,37 +223,38 @@ public MIRCStats(IConfiguration configuration)
/// Gets the path.
/// </summary>
/// <value>The path.</value>
public string Path { get; }
public string Path { get; set; }
/// <summary>
/// Gets the nicks file.
/// </summary>
/// <value>The nicks file.</value>
public string NicksFile { get; }
public string NicksFile { get; set; }
/// <summary>
/// Gets the nick section.
/// </summary>
/// <value>The nick section.</value>
public string NickSection { get; }
public string NickSection { get; set; }
/// <summary>
/// Gets how often it should launch mIRCStats in minutes.
/// </summary>
/// <value>The value of how often it should launch mIRCStats in minutes.</value>
public int LaunchEveryMinutes { get; }
public int LaunchEveryMinutes { get; set; }
/// <summary>
/// Gets the generator file.
/// </summary>
/// <value>The generator file.</value>
public string GeneratorFile { get; }
public string GeneratorFile { get; set; }
/// <summary>
/// Gets a value indicating whether [wait until completed].
/// </summary>
/// <value><c>true</c> if [wait until completed]; otherwise, <c>false</c>.</value>
public bool WaitUntilCompleted { get; }
public bool WaitUntilCompleted { get; set; }
/// <summary>
/// Gets a value indicating whether to [use the internal timer].
/// </summary>
/// <value><c>true</c> if [use the internal timer]; otherwise, <c>false</c>.</value>
public bool UseInternalTimer { get; }
[JsonIgnore]
public bool UseInternalTimer { get; set; }
}

/// <summary>
Expand All @@ -281,17 +278,19 @@ public PushOver(IConfiguration configuration)
/// Gets the API key.
/// </summary>
/// <value>The API key.</value>
public string ApiKey { get; }
public string ApiKey { get; set; }
/// <summary>
/// Gets the user key.
/// </summary>
/// <value>The user key.</value>
public string UserKey { get; }
public string UserKey { get; set; }
/// <summary>
/// Gets a value indicating whether [use pushover].
/// </summary>
/// <value><c>true</c> if [use pushover]; otherwise, <c>false</c>.</value>
public bool UsePushover { get; }

[JsonIgnore]
public bool UsePushover { get; set; }
}


Expand All @@ -315,11 +314,11 @@ public Stats(IConfiguration configuration)
/// Gets the command.
/// </summary>
/// <value>The command.</value>
public string Command { get; }
public string Command { get; set; }
/// <summary>
/// Gets the URL.
/// </summary>
/// <value>The URL.</value>
public string Url { get; }
public string Url { get; set; }
}
}
16 changes: 16 additions & 0 deletions SharedCode/SharedCode.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="6.0.1" />
<PackageReference Include="Microsoft.Extensions.Configuration.Abstractions" Version="6.0.0" />
<PackageReference Include="Microsoft.Extensions.Hosting" Version="6.0.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
</ItemGroup>

</Project>
12 changes: 12 additions & 0 deletions StatBot.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ VisualStudioVersion = 17.2.32505.173
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StatBot", "StatBot\StatBot.csproj", "{C9196A7D-BEB3-478D-A9C1-1AE4983832EC}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "StatBotConfiguration", "StatBotConfiguration\StatBotConfiguration.csproj", "{E83EBF79-C9B8-4F5B-84B8-404DEEF3EE1B}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharedCode", "SharedCode\SharedCode.csproj", "{111192B7-68D9-4051-8A6F-BDDF40C9686F}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -15,6 +19,14 @@ Global
{C9196A7D-BEB3-478D-A9C1-1AE4983832EC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C9196A7D-BEB3-478D-A9C1-1AE4983832EC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C9196A7D-BEB3-478D-A9C1-1AE4983832EC}.Release|Any CPU.Build.0 = Release|Any CPU
{E83EBF79-C9B8-4F5B-84B8-404DEEF3EE1B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E83EBF79-C9B8-4F5B-84B8-404DEEF3EE1B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E83EBF79-C9B8-4F5B-84B8-404DEEF3EE1B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E83EBF79-C9B8-4F5B-84B8-404DEEF3EE1B}.Release|Any CPU.Build.0 = Release|Any CPU
{111192B7-68D9-4051-8A6F-BDDF40C9686F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{111192B7-68D9-4051-8A6F-BDDF40C9686F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{111192B7-68D9-4051-8A6F-BDDF40C9686F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{111192B7-68D9-4051-8A6F-BDDF40C9686F}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
3 changes: 3 additions & 0 deletions StatBot/StatBot.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SharedCode\SharedCode.csproj" />
</ItemGroup>
<ItemGroup>
<None Update="appsettings.dev.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
Expand Down
1 change: 1 addition & 0 deletions StatBot/Worker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public void DoWork()
{
DatabaseHandler.CreateDatabase();
_botSettings = new BotSettings(_configuration);
_botSettings.VerifySettings();
_client = new DiscordSocketClient();
_logHandler = new LogHandler(_botSettings);
_connectionHandler = new ConnectionHandler(_client, _logHandler, _botSettings);
Expand Down
2 changes: 1 addition & 1 deletion StatBot/appsettings.dev.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
// channelid
// channelname
// single
"LoggingFileName": "channelid",
"LoggingFileName": "single",
"NotificationDelay": 30000,
"PushOver": {
//Leave values empty if you don't want to use it.
Expand Down
1 change: 1 addition & 0 deletions StatBot/mIRCStatsGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public mIRCStatsGenerator(IConfiguration configuration)
public void DoWork()
{
_botSettings = new BotSettings(_configuration);
_botSettings.VerifySettings();
mIRCStatsHandler mircStatsHandler = new mIRCStatsHandler(_botSettings);
_ = mircStatsHandler.GenerateStatsAsync();
}
Expand Down
17 changes: 17 additions & 0 deletions StatBotConfiguration/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Application x:Class="StatBotConfiguration.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:StatBotConfiguration"
StartupUri="MainWindow.xaml">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<!-- MahApps.Metro resource dictionaries. Make sure that all file names are Case Sensitive! -->
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
<!-- Theme setting -->
<ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Themes/Dark.Purple.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
</Application>
17 changes: 17 additions & 0 deletions StatBotConfiguration/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;

namespace StatBotConfiguration
{
/// <summary>
/// Interaction logic for App.xaml
/// </summary>
public partial class App : Application
{
}
}
10 changes: 10 additions & 0 deletions StatBotConfiguration/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
using System.Windows;

[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]
24 changes: 24 additions & 0 deletions StatBotConfiguration/ComboboxValue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace StatBotConfiguration
{
public class ComboboxValue
{
public string ID { get; set; }
public string Name { get; set; }
public ComboboxValue(string iD, string name)
{
ID = iD;
Name = name;
}
public ComboboxValue(string name)
{
ID = name;
Name = name;
}
}
}
Binary file added StatBotConfiguration/GitHub.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit d7aba6f

Please sign in to comment.