From 31ed61075e6aaafc9b0a6fa7a590c9d8b5a6b8f3 Mon Sep 17 00:00:00 2001
From: Toastie <toastie@toastiet0ast.com>
Date: Mon, 9 Sep 2024 13:24:23 +1200
Subject: [PATCH] Some packages updated, and small cleanup

---
 ellie-menu.ps1                                | 191 ++++++++++++++++++
 src/EllieBot/Bot.cs                           |   4 +-
 .../Db/Extensions/GuildConfigExtensions.cs    |  12 +-
 src/EllieBot/EllieBot.csproj                  |   4 +-
 4 files changed, 203 insertions(+), 8 deletions(-)
 create mode 100644 ellie-menu.ps1

diff --git a/ellie-menu.ps1 b/ellie-menu.ps1
new file mode 100644
index 0000000..59e869b
--- /dev/null
+++ b/ellie-menu.ps1
@@ -0,0 +1,191 @@
+param (
+  [switch]$testing,
+  [switch]$release,
+  [switch]$output_test,
+  [switch]$build,
+  [switch]$help
+)
+
+$script_version = "1.0.0-public"
+
+Write-Output ""
+Write-Host "███████╗██╗     ██╗     ██╗███████╗██████╗  ██████╗ ████████╗" -ForegroundColor DarkCyan
+Write-Host "██╔════╝██║     ██║     ██║██╔════╝██╔══██╗██╔═══██╗╚══██╔══╝" -ForegroundColor DarkCyan
+Write-Host "█████╗  ██║     ██║     ██║█████╗  ██████╔╝██║   ██║   ██║   " -ForegroundColor DarkCyan
+Write-Host "██╔══╝  ██║     ██║     ██║██╔══╝  ██╔══██╗██║   ██║   ██║   " -ForegroundColor DarkCyan
+Write-Host "███████╗███████╗███████╗██║███████╗██████╔╝╚██████╔╝   ██║   " -ForegroundColor DarkCyan
+Write-Host "╚══════╝╚══════╝╚══════╝╚═╝╚══════╝╚═════╝  ╚═════╝    ╚═╝   " -ForegroundColor DarkCyan
+Write-Output ""
+# If you remove this copyright header I will bonk
+Write-Output "Copyright © 2024 Toastie_t0ast & EllieBotDevs"
+Write-Output ""
+Write-Host "Current script version is v$script_version" -ForegroundColor DarkCyan
+Write-Output ""
+
+if ($release) {
+  if ($args.Length -eq 0) {
+    Write-Host "Please provide a version string." -ForegroundColor Red
+
+    Write-Output ""
+    Write-Host "Script failed." -ForegroundColor Red
+    Write-Host "Please read the Error above for more information" -ForegroundColor Gray
+    Write-Output ""
+  }
+  else {
+    $version = $args[0]
+    Write-Output ""
+    Write-Host "Publishing EllieBot v$version" -Foregroundcolor Green
+    Write-Output ""
+
+    Write-Output ""
+    dotnet publish -c Release -r linux-x64 --self-contained -o elliebot-linux-x64  src/EllieBot/EllieBot.csproj
+    Write-Output ""
+    dotnet publish -c Release -r linux-arm64 --self-contained -o elliebot-linux-arm64  src/EllieBot/EllieBot.csproj
+    Write-Output ""
+    dotnet publish -c Release -r win-x64 --self-contained -o elliebot-windows-x64  src/EllieBot/EllieBot.csproj
+    Write-Output ""
+    dotnet publish -c Release -r win-arm64 --self-contained -o elliebot-windows-arm64  src/EllieBot/EllieBot.csproj
+    Write-Output ""
+    dotnet publish -c Release -r osx-x64 --self-contained -o elliebot-osx-x64  src/EllieBot/EllieBot.csproj
+    Write-Output ""
+    dotnet publish -c Release -r osx-arm64 --self-contained -o elliebot-osx-arm64  src/EllieBot/EllieBot.csproj
+
+    Write-Output ""
+    Write-Output "Preparing the Windows installer build."
+    Write-Output ""
+
+    dotnet clean
+    dotnet restore -f --no-cache -v n
+    dotnet publish -c Release --self-contained --runtime win-x64 /p:Version="$version" src/EllieBot
+
+    Write-Output ""
+    Write-Output "Setting environemt variable"
+    Write-Output ""
+
+    $env:ELLIEBOT_INSTALL_VERSION = $version
+
+    Write-Output ""
+    Write-Output "Compiling installer file"
+    Write-Output ""
+
+    iscc.exe /O+ .\exe_builder.iss
+
+    Write-Output ""
+    Write-Output "Compressing windows build files"
+    Write-Output ""
+
+    Compress-Archive -Path elliebot-windows-x64/ "$version-windows-x64-build.zip"
+    Compress-Archive -Path elliebot-windows-arm64/ "$version-windows-arm64-build.zip"
+
+    Write-Output ""
+    Write-Output "Moving the installer file to the directory this script is in"
+    Write-Output ""
+
+    Move-Item ellie-installers/$version/ellie-setup-$version.exe ellie-setup-$version.exe
+
+    Write-Output ""
+    Write-Output "Script finished successfully"
+    Write-Output ""
+    Write-Output "If you wish to build the linux or MacOS builds please run"
+    Write-Output "package.sh in wsl if you are on Windows or in bash (or whatever terminal you use) on linux"
+    Write-Output ""
+    Write-Output "If you have any suggestions on how to make this script better please make a suggestion"
+    Write-Output "in our discord @ https://discord.gg/etQdZxSyEH and in the 📚・suggestions channel"
+    Write-Output ""
+  }
+}
+
+if ($testing) {
+  if ($args.Length -eq 0) {
+    Write-Host "Please provide a version string." -ForegroundColor Red
+
+    Write-Output ""
+    Write-Host "Script failed." -ForegroundColor Red
+    Write-Host "Please read the Error above for more information" -ForegroundColor Gray
+    Write-Output ""
+  }
+  else {
+    $version = $args[0]
+    Write-Output ""
+    Write-Output "Running tests for EllieBot v$version"
+    Write-Output ""
+    dotnet test
+
+    Write-Output ""
+    Write-Output "Script finished successfully"
+    Write-Output ""
+    Write-Output "If you have any suggestions on how to make this script better please make a suggestion"
+    Write-Output "in our discord @ https://discord.gg/etQdZxSyEH and in the 📚・suggestions channel"
+    Write-Output ""
+  }
+}
+
+if ($output_test) {
+
+  Write-Output ""
+  Write-Output "Compiling a test build of EllieBot"
+  Write-Output ""
+  dotnet publish -c Release -o output/ src/EllieBot/
+
+  Write-Output ""
+  Write-Output "copying creds_example.yml to creds.yml"
+  Write-Output ""
+  Set-Location output
+
+  Copy-Item creds_example.yml creds.yml
+
+  Set-Location ..
+
+  Write-Output ""
+  Write-Output "Script finished successfully"
+  Write-Output ""
+  Write-Output "If you have any suggestions on how to make this script better please make a suggestion"
+  Write-Output "in our discord @ https://discord.gg/etQdZxSyEH and in the 📚・suggestions channel"
+  Write-Output ""
+}
+
+if ($build) {
+
+  Write-Output ""
+  Write-Output "Restoring EllieBot"
+  Write-Output ""
+  dotnet restore
+
+  Write-Output ""
+  Write-Output "Building EllieBot"
+  Write-Output ""
+  dotnet build --no-restore -c Release
+
+  Write-Output ""
+  Write-Output "Script finished successfully"
+  Write-Output ""
+  Write-Output "If you have any suggestions on how to make this script better please make a suggestion"
+  Write-Output "in our discord @ https://discord.gg/etQdZxSyEH and in the 📚・suggestions channel"
+  Write-Output ""
+}
+
+if ($help) {
+  Write-Output ""
+  Write-Output "Here is a list of switches for this script."
+  Write-Output ""
+  
+  Write-Host "Release parameter" -ForegroundColor Green
+  Write-Output "-release"
+  Write-Output ""
+
+  Write-Host "Testing parameter" -ForegroundColor Blue
+  Write-Output "-testing"
+  Write-Output ""
+
+  Write-Host "Output test parameter" -ForegroundColor Yellow
+  Write-Output "-output_test"
+  Write-Output ""
+
+  Write-Host "Build parameter" -ForegroundColor DarkCyan
+  Write-Output "-build"
+  Write-Output ""
+
+  Write-Host "Here is an example" -ForegroundColor Gray
+  Write-Host "build.ps1 -build" -ForegroundColor Gray
+  Write-Output ""
+}
\ No newline at end of file
diff --git a/src/EllieBot/Bot.cs b/src/EllieBot/Bot.cs
index 3ea8ffa..a549e65 100644
--- a/src/EllieBot/Bot.cs
+++ b/src/EllieBot/Bot.cs
@@ -88,7 +88,7 @@ public sealed class Bot : IBot
 
 
     public IReadOnlyList<ulong> GetCurrentGuildIds()
-        => Client.Guilds.Select(x => x.Id).ToList().ToList();
+        => Client.Guilds.Select(x => x.Id).ToList().AsReadOnly();
 
     private void AddServices()
     {
@@ -99,7 +99,7 @@ public sealed class Bot : IBot
         using (var uow = _db.GetDbContext())
         {
             uow.EnsureUserCreated(bot.Id, bot.Username, bot.Discriminator, bot.AvatarId);
-            AllGuildConfigs = uow.Set<GuildConfig>().GetAllGuildConfigs(startingGuildIdList).ToImmutableArray();
+            AllGuildConfigs = uow.GuildConfigs.GetAllGuildConfigs(startingGuildIdList);
         }
 
         // var svcs = new StandardKernel(new NinjectSettings()
diff --git a/src/EllieBot/Db/Extensions/GuildConfigExtensions.cs b/src/EllieBot/Db/Extensions/GuildConfigExtensions.cs
index 842fe4e..1c5a27d 100644
--- a/src/EllieBot/Db/Extensions/GuildConfigExtensions.cs
+++ b/src/EllieBot/Db/Extensions/GuildConfigExtensions.cs
@@ -47,14 +47,18 @@ public static class GuildConfigExtensions
             .Include(gc => gc.CommandCooldowns)
             .Include(gc => gc.FollowedStreams)
             .Include(gc => gc.StreamRole)
+            .Include(gc => gc.DelMsgOnCmdChannels)
             .Include(gc => gc.XpSettings)
-            .ThenInclude(x => x.ExclusionList)
-            .Include(gc => gc.DelMsgOnCmdChannels);
+                .ThenInclude(x => x.ExclusionList);
 
-    public static IEnumerable<GuildConfig> GetAllGuildConfigs(
+    public static IReadOnlyCollection<GuildConfig> GetAllGuildConfigs(
         this DbSet<GuildConfig> configs,
         IReadOnlyList<ulong> availableGuilds)
-        => configs.IncludeEverything().AsNoTracking().Where(x => availableGuilds.Contains(x.GuildId)).ToList();
+        => configs.IncludeEverything()
+                  .AsNoTracking()
+                  .Where(x => availableGuilds.Contains(x.GuildId))
+                  .ToList()
+                  .AsReadOnly();
 
     /// <summary>
     ///     Gets and creates if it doesn't exist a config for a guild.
diff --git a/src/EllieBot/EllieBot.csproj b/src/EllieBot/EllieBot.csproj
index b67381c..3b250e8 100644
--- a/src/EllieBot/EllieBot.csproj
+++ b/src/EllieBot/EllieBot.csproj
@@ -81,7 +81,7 @@
 
 
     <!-- Db-related packages -->
-    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.4" />
+    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.8" />
     <PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.4">
       <PrivateAssets>all</PrivateAssets>
       <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
@@ -89,7 +89,7 @@
 
     <PackageReference Include="linq2db.EntityFrameworkCore" Version="8.1.0" />
 
-    <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.4" />
+    <PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.8" />
     <PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="8.0.4" />
     <PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.2" />