Compare commits
11 Commits
v1.0.7-pre
...
v1.0.8-pre
| Author | SHA1 | Date | |
|---|---|---|---|
| d689eee7fa | |||
| f6442af30c | |||
| b98f57fcf8 | |||
| 77aad985fa | |||
|
|
f8ebf76f92 | ||
| 6da9828e5c | |||
| 3ba45790e7 | |||
| e440e97948 | |||
|
|
938c73c810 | ||
| a8520c8c96 | |||
| debdc58646 |
13
.idea/.idea.SethDiscordBot/.idea/.gitignore
generated
vendored
13
.idea/.idea.SethDiscordBot/.idea/.gitignore
generated
vendored
@@ -1,13 +0,0 @@
|
|||||||
# Default ignored files
|
|
||||||
/shelf/
|
|
||||||
/workspace.xml
|
|
||||||
# Rider ignored files
|
|
||||||
/projectSettingsUpdater.xml
|
|
||||||
/contentModel.xml
|
|
||||||
/.idea.SethDiscordBot.iml
|
|
||||||
/modules.xml
|
|
||||||
# Editor-based HTTP Client requests
|
|
||||||
/httpRequests/
|
|
||||||
# Datasource local storage ignored files
|
|
||||||
/dataSources/
|
|
||||||
/dataSources.local.xml
|
|
||||||
1
.idea/.idea.SethDiscordBot/.idea/.name
generated
1
.idea/.idea.SethDiscordBot/.idea/.name
generated
@@ -1 +0,0 @@
|
|||||||
SethDiscordBot
|
|
||||||
4
.idea/.idea.SethDiscordBot/.idea/encodings.xml
generated
4
.idea/.idea.SethDiscordBot/.idea/encodings.xml
generated
@@ -1,4 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="Encoding" addBOMForNewFiles="with BOM under Windows, with no BOM otherwise" />
|
|
||||||
</project>
|
|
||||||
8
.idea/.idea.SethDiscordBot/.idea/indexLayout.xml
generated
8
.idea/.idea.SethDiscordBot/.idea/indexLayout.xml
generated
@@ -1,8 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="UserContentModel">
|
|
||||||
<attachedFolders />
|
|
||||||
<explicitIncludes />
|
|
||||||
<explicitExcludes />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
6
.idea/.idea.SethDiscordBot/.idea/projectSettingsUpdater.xml
generated
Normal file
6
.idea/.idea.SethDiscordBot/.idea/projectSettingsUpdater.xml
generated
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="RiderProjectSettingsUpdater">
|
||||||
|
<option name="vcsConfiguration" value="2" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
6
.idea/.idea.SethDiscordBot/.idea/vcs.xml
generated
6
.idea/.idea.SethDiscordBot/.idea/vcs.xml
generated
@@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<project version="4">
|
|
||||||
<component name="VcsDirectoryMappings">
|
|
||||||
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
|
||||||
</component>
|
|
||||||
</project>
|
|
||||||
107
.idea/.idea.SethDiscordBot/.idea/workspace.xml
generated
Normal file
107
.idea/.idea.SethDiscordBot/.idea/workspace.xml
generated
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="AutoGeneratedRunConfigurationManager">
|
||||||
|
<projectFile>DiscordBot/DiscordBot.csproj</projectFile>
|
||||||
|
<projectFile pubXmlPath="DiscordBot/Properties/PublishProfiles/WindowsBuild.pubxml">DiscordBot/DiscordBot.csproj</projectFile>
|
||||||
|
</component>
|
||||||
|
<component name="AutoImportSettings">
|
||||||
|
<option name="autoReloadType" value="SELECTIVE" />
|
||||||
|
</component>
|
||||||
|
<component name="ChangeListManager">
|
||||||
|
<list default="true" id="ab173b07-aba1-4bb8-94c1-ae9846bbdb0a" name="Changes" comment="">
|
||||||
|
<change afterPath="$PROJECT_DIR$/Roles/AddRole.cs" afterDir="false" />
|
||||||
|
<change afterPath="$PROJECT_DIR$/Roles/Internals/RoleManagement.cs" afterDir="false" />
|
||||||
|
<change afterPath="$PROJECT_DIR$/Roles/Roles.csproj" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/BUILDS/net6.0/CMD_Utils.dll" beforeDir="false" afterPath="$PROJECT_DIR$/BUILDS/net6.0/CMD_Utils.dll" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/BUILDS/net6.0/Music Commands.dll" beforeDir="false" afterPath="$PROJECT_DIR$/BUILDS/net6.0/Music Commands.dll" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/BUILDS/net6.0/PluginManager.dll" beforeDir="false" afterPath="$PROJECT_DIR$/BUILDS/net6.0/PluginManager.dll" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/CMD_LevelingSystem/Level.cs" beforeDir="false" afterPath="$PROJECT_DIR$/CMD_LevelingSystem/Level.cs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/CMD_Utils/Echo.cs" beforeDir="false" afterPath="$PROJECT_DIR$/CMD_Utils/Echo.cs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/CMD_Utils/FlipCoin.cs" beforeDir="false" afterPath="$PROJECT_DIR$/CMD_Utils/FlipCoin.cs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/CMD_Utils/Poll.cs" beforeDir="false" afterPath="$PROJECT_DIR$/CMD_Utils/Poll.cs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/CMD_Utils/Random.cs" beforeDir="false" afterPath="$PROJECT_DIR$/CMD_Utils/Random.cs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/DiscordBot/Discord/Commands/Help.cs" beforeDir="false" afterPath="$PROJECT_DIR$/DiscordBot/Discord/Commands/Help.cs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/DiscordBot/Discord/Commands/Restart.cs" beforeDir="false" afterPath="$PROJECT_DIR$/DiscordBot/Discord/Commands/Restart.cs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/DiscordBot/Discord/Commands/Settings.cs" beforeDir="false" afterPath="$PROJECT_DIR$/DiscordBot/Discord/Commands/Settings.cs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/DiscordBot/Discord/Core/Boot.cs" beforeDir="false" afterPath="$PROJECT_DIR$/DiscordBot/Discord/Core/Boot.cs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/DiscordBot/Discord/Core/CommandHandler.cs" beforeDir="false" afterPath="$PROJECT_DIR$/DiscordBot/Discord/Core/CommandHandler.cs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/DiscordBot/DiscordBot.csproj" beforeDir="false" afterPath="$PROJECT_DIR$/DiscordBot/DiscordBot.csproj" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/DiscordBot/Program.cs" beforeDir="false" afterPath="$PROJECT_DIR$/DiscordBot/Program.cs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/MusicCommands/Leave.cs" beforeDir="false" afterPath="$PROJECT_DIR$/MusicCommands/Leave.cs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/MusicCommands/MusicPlayer.cs" beforeDir="false" afterPath="$PROJECT_DIR$/MusicCommands/MusicPlayer.cs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/MusicCommands/Pause.cs" beforeDir="false" afterPath="$PROJECT_DIR$/MusicCommands/Pause.cs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/MusicCommands/Play.cs" beforeDir="false" afterPath="$PROJECT_DIR$/MusicCommands/Play.cs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/MusicCommands/Skip.cs" beforeDir="false" afterPath="$PROJECT_DIR$/MusicCommands/Skip.cs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/MusicCommands/queue.cs" beforeDir="false" afterPath="$PROJECT_DIR$/MusicCommands/queue.cs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/PluginManager/Config.cs" beforeDir="false" afterPath="$PROJECT_DIR$/PluginManager/Config.cs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/PluginManager/Interfaces/DBCommand.cs" beforeDir="false" afterPath="$PROJECT_DIR$/PluginManager/Interfaces/DBCommand.cs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/PluginManager/Items/Command.cs" beforeDir="false" afterPath="$PROJECT_DIR$/PluginManager/Items/Command.cs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/PluginManager/Items/ConsoleCommandsHandler.cs" beforeDir="false" afterPath="$PROJECT_DIR$/PluginManager/Items/ConsoleCommandsHandler.cs" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/SethDiscordBot.sln" beforeDir="false" afterPath="$PROJECT_DIR$/SethDiscordBot.sln" afterDir="false" />
|
||||||
|
</list>
|
||||||
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
|
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||||
|
<option name="LAST_RESOLUTION" value="IGNORE" />
|
||||||
|
</component>
|
||||||
|
<component name="MarkdownSettingsMigration">
|
||||||
|
<option name="stateVersion" value="1" />
|
||||||
|
</component>
|
||||||
|
<component name="ProjectId" id="2CUQteUHoNWL2Ok4DVEh1GfFaXk" />
|
||||||
|
<component name="ProjectViewState">
|
||||||
|
<option name="hideEmptyMiddlePackages" value="true" />
|
||||||
|
<option name="showLibraryContents" value="true" />
|
||||||
|
</component>
|
||||||
|
<component name="PropertiesComponent"><![CDATA[{
|
||||||
|
"keyToString": {
|
||||||
|
"ASKED_SHARE_PROJECT_CONFIGURATION_FILES": "true",
|
||||||
|
"RunOnceActivity.OpenProjectViewOnStart": "true",
|
||||||
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||||
|
"WebServerToolWindowFactoryState": "false",
|
||||||
|
"node.js.detected.package.eslint": "true",
|
||||||
|
"node.js.detected.package.tslint": "true",
|
||||||
|
"node.js.selected.package.eslint": "(autodetect)",
|
||||||
|
"node.js.selected.package.tslint": "(autodetect)",
|
||||||
|
"nodejs_package_manager_path": "npm",
|
||||||
|
"settings.editor.selected.configurable": "preferences.pluginManager",
|
||||||
|
"vue.rearranger.settings.migration": "true"
|
||||||
|
}
|
||||||
|
}]]></component>
|
||||||
|
<component name="RunManager">
|
||||||
|
<configuration name="DiscordBot: WindowsBuild" type="DotNetMsBuildPublish" factoryName="Publish to IIS">
|
||||||
|
<riderPublish publish_profile="WindowsBuild.pubxml" pubxml_path="$PROJECT_DIR$/DiscordBot/Properties/PublishProfiles/WindowsBuild.pubxml" uuid_high="612037599008934041" uuid_low="-9069359786678974134" />
|
||||||
|
<method v="2" />
|
||||||
|
</configuration>
|
||||||
|
</component>
|
||||||
|
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
||||||
|
<component name="TaskManager">
|
||||||
|
<task active="true" id="Default" summary="Default task">
|
||||||
|
<changelist id="ab173b07-aba1-4bb8-94c1-ae9846bbdb0a" name="Changes" comment="" />
|
||||||
|
<created>1658854902538</created>
|
||||||
|
<option name="number" value="Default" />
|
||||||
|
<option name="presentableId" value="Default" />
|
||||||
|
<updated>1658854902538</updated>
|
||||||
|
<workItem from="1658854908500" duration="1731000" />
|
||||||
|
</task>
|
||||||
|
<servers />
|
||||||
|
</component>
|
||||||
|
<component name="TypeScriptGeneratedFilesManager">
|
||||||
|
<option name="version" value="3" />
|
||||||
|
</component>
|
||||||
|
<component name="UnityCheckinConfiguration" checkUnsavedScenes="true" />
|
||||||
|
<component name="UnityUnitTestConfiguration" currentTestLauncher="NUnit" />
|
||||||
|
<component name="Vcs.Log.Tabs.Properties">
|
||||||
|
<option name="TAB_STATES">
|
||||||
|
<map>
|
||||||
|
<entry key="MAIN">
|
||||||
|
<value>
|
||||||
|
<State />
|
||||||
|
</value>
|
||||||
|
</entry>
|
||||||
|
</map>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
<component name="VcsManagerConfiguration">
|
||||||
|
<option name="CLEAR_INITIAL_COMMIT_MESSAGE" value="true" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
Binary file not shown.
Binary file not shown.
@@ -8,7 +8,7 @@
|
|||||||
<StartupObject />
|
<StartupObject />
|
||||||
<SignAssembly>False</SignAssembly>
|
<SignAssembly>False</SignAssembly>
|
||||||
<IsPublishable>True</IsPublishable>
|
<IsPublishable>True</IsPublishable>
|
||||||
<AssemblyVersion>1.0.0.2</AssemblyVersion>
|
<AssemblyVersion>1.0.0.3</AssemblyVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||||
|
|||||||
@@ -6,6 +6,8 @@ using System.Reflection;
|
|||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
using Discord;
|
||||||
|
|
||||||
using DiscordBot.Discord.Core;
|
using DiscordBot.Discord.Core;
|
||||||
|
|
||||||
using PluginManager;
|
using PluginManager;
|
||||||
@@ -19,6 +21,7 @@ public class Program
|
|||||||
{
|
{
|
||||||
private static bool loadPluginsOnStartup;
|
private static bool loadPluginsOnStartup;
|
||||||
private static bool listPluginsAtStartup;
|
private static bool listPluginsAtStartup;
|
||||||
|
private static ConsoleCommandsHandler consoleCommandsHandler;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The main entry point for the application.
|
/// The main entry point for the application.
|
||||||
@@ -33,6 +36,7 @@ public class Program
|
|||||||
Directory.CreateDirectory("./Data/Plugins/Events");
|
Directory.CreateDirectory("./Data/Plugins/Events");
|
||||||
PreLoadComponents().Wait();
|
PreLoadComponents().Wait();
|
||||||
|
|
||||||
|
|
||||||
if (!Config.ContainsKey("ServerID"))
|
if (!Config.ContainsKey("ServerID"))
|
||||||
{
|
{
|
||||||
do
|
do
|
||||||
@@ -105,23 +109,25 @@ public class Program
|
|||||||
/// <param name="discordbooter">The discord booter used to start the application</param>
|
/// <param name="discordbooter">The discord booter used to start the application</param>
|
||||||
private static void NoGUI(Boot discordbooter)
|
private static void NoGUI(Boot discordbooter)
|
||||||
{
|
{
|
||||||
var consoleCommandsHandler = new ConsoleCommandsHandler(discordbooter.client);
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
Console.WriteLine();
|
Console.WriteLine();
|
||||||
consoleCommandsHandler.HandleCommand("lp");
|
ConsoleCommandsHandler.ExecuteCommad("lp").Wait();
|
||||||
#else
|
#else
|
||||||
if (loadPluginsOnStartup) consoleCommandsHandler.HandleCommand("lp");
|
if (loadPluginsOnStartup) consoleCommandsHandler.HandleCommand("lp");
|
||||||
if (listPluginsAtStartup) consoleCommandsHandler.HandleCommand("listplugs");
|
if (listPluginsAtStartup) consoleCommandsHandler.HandleCommand("listplugs");
|
||||||
#endif
|
#endif
|
||||||
Config.SaveConfig();
|
Config.SaveConfig(SaveType.NORMAL).Wait();
|
||||||
|
|
||||||
while (true)
|
while (true)
|
||||||
{
|
{
|
||||||
//Console_Utilities.WriteColorText("&rSethBot (&yDEBUG&r) &c> ", false);
|
|
||||||
var cmd = Console.ReadLine();
|
var cmd = Console.ReadLine();
|
||||||
if (!consoleCommandsHandler.HandleCommand(cmd!,
|
if (!consoleCommandsHandler.HandleCommand(cmd!
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
false
|
, false
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
) && cmd.Length > 0)
|
) && cmd.Length > 0)
|
||||||
Console.WriteLine("Failed to run command " + cmd);
|
Console.WriteLine("Failed to run command " + cmd);
|
||||||
}
|
}
|
||||||
@@ -146,6 +152,14 @@ public class Program
|
|||||||
|
|
||||||
Console_Utilities.WriteColorText("&rRemember to close the bot using the ShutDown command (&ysd&r) or some settings won't be saved\n");
|
Console_Utilities.WriteColorText("&rRemember to close the bot using the ShutDown command (&ysd&r) or some settings won't be saved\n");
|
||||||
Console.ForegroundColor = ConsoleColor.White;
|
Console.ForegroundColor = ConsoleColor.White;
|
||||||
|
|
||||||
|
if (Config.ContainsKey("LaunchMessage"))
|
||||||
|
{
|
||||||
|
Console_Utilities.WriteColorText(Config.GetValue<string>("LaunchMessage"));
|
||||||
|
Config.RemoveKey("LaunchMessage");
|
||||||
|
}
|
||||||
|
|
||||||
|
Console_Utilities.WriteColorText("Please note that the bot saves a backup save file every time you are using the shudown command (&ysd&c)");
|
||||||
Console.WriteLine($"============================ LOG ============================");
|
Console.WriteLine($"============================ LOG ============================");
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -164,7 +178,6 @@ public class Program
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
var prefix = Config.GetValue<string>("prefix");
|
var prefix = Config.GetValue<string>("prefix");
|
||||||
|
|
||||||
var discordbooter = new Boot(token, prefix);
|
var discordbooter = new Boot(token, prefix);
|
||||||
await discordbooter.Awake();
|
await discordbooter.Awake();
|
||||||
return discordbooter;
|
return discordbooter;
|
||||||
@@ -199,6 +212,7 @@ public class Program
|
|||||||
/// <param name="args">The arguments</param>
|
/// <param name="args">The arguments</param>
|
||||||
private static async Task HandleInput(string[] args)
|
private static async Task HandleInput(string[] args)
|
||||||
{
|
{
|
||||||
|
|
||||||
var len = args.Length;
|
var len = args.Length;
|
||||||
|
|
||||||
if (len == 3 && args[0] == "/download")
|
if (len == 3 && args[0] == "/download")
|
||||||
@@ -211,6 +225,23 @@ public class Program
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (len > 0 && args[0] == "/test")
|
||||||
|
{
|
||||||
|
int p = 1;
|
||||||
|
bool allowed = true;
|
||||||
|
Console.CancelKeyPress += (sender, e) => allowed = false;
|
||||||
|
Console_Utilities.ProgressBar bar = new(ProgressBarType.NO_END);// { NoColor = false, Color = ConsoleColor.DarkRed };
|
||||||
|
Console.WriteLine("Press Ctrl + C to stop.");
|
||||||
|
while (p <= int.MaxValue - 1 && allowed)
|
||||||
|
{
|
||||||
|
bar.Update(100 / p);
|
||||||
|
await Task.Delay(100);
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (len > 0 && (args.Contains("--cmd") || args.Contains("--args") || args.Contains("--nomessage")))
|
if (len > 0 && (args.Contains("--cmd") || args.Contains("--args") || args.Contains("--nomessage")))
|
||||||
{
|
{
|
||||||
if (args.Contains("lp") || args.Contains("loadplugins"))
|
if (args.Contains("lp") || args.Contains("loadplugins"))
|
||||||
@@ -222,11 +253,43 @@ public class Program
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
var b = await StartNoGUI();
|
||||||
|
consoleCommandsHandler = new ConsoleCommandsHandler(b.client);
|
||||||
|
|
||||||
|
if (len > 0 && args[0] == "/remplug")
|
||||||
|
{
|
||||||
|
|
||||||
|
string plugName = Functions.MergeStrings(args, 1);
|
||||||
|
Console.WriteLine("Starting to remove " + plugName);
|
||||||
|
await ConsoleCommandsHandler.ExecuteCommad("remplug " + plugName);
|
||||||
|
loadPluginsOnStartup = true;
|
||||||
|
len = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
if (len == 0 || (args[0] != "--exec" && args[0] != "--execute"))
|
if (len == 0 || (args[0] != "--exec" && args[0] != "--execute"))
|
||||||
{
|
{
|
||||||
var b = await StartNoGUI();
|
|
||||||
|
|
||||||
Thread mainThread = new Thread(() => NoGUI(b));
|
Thread mainThread = new Thread(() =>
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
NoGUI(b);
|
||||||
|
}
|
||||||
|
catch (IOException ex)
|
||||||
|
{
|
||||||
|
if (ex.Message == "No process is on the other end of the pipe." || (uint)ex.HResult == 0x800700E9)
|
||||||
|
{
|
||||||
|
if (!Config.ContainsKey("LaunchMessage"))
|
||||||
|
Config.AddValueToVariables("LaunchMessage", "An error occured while closing the bot last time. Please consider closing the bot using the &rsd&c method !\nThere is a risk of losing all data or corruption of the save file, which in some cases requires to reinstall the bot !", false);
|
||||||
|
Functions.WriteErrFile(ex.ToString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
mainThread.Start();
|
mainThread.Start();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -360,6 +423,6 @@ public class Program
|
|||||||
|
|
||||||
Console_Utilities.Initialize();
|
Console_Utilities.Initialize();
|
||||||
|
|
||||||
Config.SaveConfig();
|
Config.SaveConfig(SaveType.NORMAL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
<Project Sdk="Microsoft.NET.Sdk">
|
|
||||||
|
|
||||||
<PropertyGroup>
|
|
||||||
<OutputType>Exe</OutputType>
|
|
||||||
<TargetFramework>net6.0</TargetFramework>
|
|
||||||
<ImplicitUsings>enable</ImplicitUsings>
|
|
||||||
<Nullable>enable</Nullable>
|
|
||||||
</PropertyGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<ProjectReference Include="..\PluginManager\PluginManager.csproj" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
</Project>
|
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
using PluginManager.Online.Updates;
|
|
||||||
|
|
||||||
try
|
|
||||||
{
|
|
||||||
bool requireUpdate = await PluginUpdater.CheckForUpdates("DiscordBotConsoleLauncher");
|
|
||||||
if (requireUpdate)
|
|
||||||
{
|
|
||||||
var update = await PluginUpdater.DownloadUpdateInfo("DiscordBotConsoleLauncher");
|
|
||||||
if (update == Update.Empty)
|
|
||||||
return;
|
|
||||||
|
|
||||||
Console.WriteLine("Found an update: ");
|
|
||||||
Console.WriteLine(update.ToString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
catch (Exception ex)
|
|
||||||
{
|
|
||||||
Console.WriteLine("An exception was thrown. ");
|
|
||||||
Console.WriteLine(ex.Message);
|
|
||||||
Environment.Exit(-2);
|
|
||||||
}
|
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
using AngleSharp.Dom;
|
using AngleSharp.Dom;
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
@@ -11,20 +12,20 @@ namespace MusicCommands
|
|||||||
internal class AudioFile
|
internal class AudioFile
|
||||||
{
|
{
|
||||||
internal string Name { get; set; }
|
internal string Name { get; set; }
|
||||||
internal string Url { get; set; }
|
internal string Url { get; set; }
|
||||||
|
|
||||||
internal AudioFile(string name, string url)
|
internal AudioFile(string name, string url)
|
||||||
{
|
{
|
||||||
Name = name;
|
Name = name;
|
||||||
Url = url;
|
Url = url;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal async Task DownloadAudioFile()
|
internal async Task DownloadAudioFile()
|
||||||
{
|
{
|
||||||
Process proc = new Process();
|
Process proc = new Process();
|
||||||
proc.StartInfo.FileName = "MusicDownloader.exe";
|
proc.StartInfo.FileName = "MusicDownloader";
|
||||||
proc.StartInfo.Arguments = $"{Url},{Name}";
|
proc.StartInfo.Arguments = $"{Url},{Name}";
|
||||||
proc.StartInfo.UseShellExecute = false;
|
proc.StartInfo.UseShellExecute = false;
|
||||||
proc.StartInfo.RedirectStandardOutput = true;
|
proc.StartInfo.RedirectStandardOutput = true;
|
||||||
|
|
||||||
proc.Start();
|
proc.Start();
|
||||||
|
|||||||
@@ -13,8 +13,7 @@ namespace PluginManager
|
|||||||
{
|
{
|
||||||
public Dictionary<string, object>? ApplicationVariables { get; init; }
|
public Dictionary<string, object>? ApplicationVariables { get; init; }
|
||||||
public List<string>? ProtectedKeyWords { get; init; }
|
public List<string>? ProtectedKeyWords { get; init; }
|
||||||
|
public Dictionary<string, string>? PluginVersions { get; init; }
|
||||||
public Dictionary<string, string> PluginVersions { get; init; }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Config
|
public static class Config
|
||||||
@@ -59,9 +58,8 @@ namespace PluginManager
|
|||||||
public static bool Contains(string pluginName)
|
public static bool Contains(string pluginName)
|
||||||
{
|
{
|
||||||
foreach (var tuple in InstalledPlugins)
|
foreach (var tuple in InstalledPlugins)
|
||||||
{
|
if (tuple.Item1 == pluginName)
|
||||||
if (tuple.Item1 == pluginName) return true;
|
return true;
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -79,18 +77,18 @@ namespace PluginManager
|
|||||||
|
|
||||||
private static AppConfig? appConfig { get; set; }
|
private static AppConfig? appConfig { get; set; }
|
||||||
|
|
||||||
public static string GetPluginVersion(string pluginName) => appConfig.PluginVersions[pluginName];
|
public static string GetPluginVersion(string pluginName) => appConfig!.PluginVersions![pluginName];
|
||||||
public static void SetPluginVersion(string pluginName, string newVersion)
|
public static void SetPluginVersion(string pluginName, string newVersion)
|
||||||
{
|
{
|
||||||
if (appConfig.PluginVersions.ContainsKey(pluginName))
|
if (appConfig!.PluginVersions!.ContainsKey(pluginName))
|
||||||
appConfig.PluginVersions[pluginName] = newVersion;
|
appConfig.PluginVersions[pluginName] = newVersion;
|
||||||
else appConfig.PluginVersions.Add(pluginName, newVersion);
|
else appConfig.PluginVersions.Add(pluginName, newVersion);
|
||||||
|
|
||||||
// SaveConfig();
|
// SaveConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void RemovePluginVersion(string pluginName) => appConfig.PluginVersions.Remove(pluginName);
|
public static void RemovePluginVersion(string pluginName) => appConfig!.PluginVersions!.Remove(pluginName);
|
||||||
public static bool PluginVersionsContainsKey(string pluginName) => appConfig.PluginVersions.ContainsKey(pluginName);
|
public static bool PluginVersionsContainsKey(string pluginName) => appConfig!.PluginVersions!.ContainsKey(pluginName);
|
||||||
|
|
||||||
public static void AddValueToVariables<T>(string key, T value, bool isProtected)
|
public static void AddValueToVariables<T>(string key, T value, bool isProtected)
|
||||||
{
|
{
|
||||||
@@ -103,7 +101,7 @@ namespace PluginManager
|
|||||||
if (isProtected && key != "Version")
|
if (isProtected && key != "Version")
|
||||||
appConfig.ProtectedKeyWords!.Add(key);
|
appConfig.ProtectedKeyWords!.Add(key);
|
||||||
|
|
||||||
SaveConfig();
|
SaveConfig(SaveType.NORMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Type GetVariableType(string value)
|
public static Type GetVariableType(string value)
|
||||||
@@ -171,7 +169,7 @@ namespace PluginManager
|
|||||||
throw new Exception("Key is protected");
|
throw new Exception("Key is protected");
|
||||||
|
|
||||||
appConfig.ApplicationVariables[key] = JsonSerializer.SerializeToElement(value);
|
appConfig.ApplicationVariables[key] = JsonSerializer.SerializeToElement(value);
|
||||||
SaveConfig();
|
SaveConfig(SaveType.NORMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void RemoveKey(string key)
|
public static void RemoveKey(string key)
|
||||||
@@ -180,13 +178,24 @@ namespace PluginManager
|
|||||||
throw new Exception("Key is protected");
|
throw new Exception("Key is protected");
|
||||||
appConfig!.ApplicationVariables!.Remove(key);
|
appConfig!.ApplicationVariables!.Remove(key);
|
||||||
appConfig.ProtectedKeyWords!.Remove(key);
|
appConfig.ProtectedKeyWords!.Remove(key);
|
||||||
SaveConfig();
|
SaveConfig(SaveType.NORMAL);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async void SaveConfig()
|
public static async Task SaveConfig(SaveType type)
|
||||||
{
|
{
|
||||||
string path = Functions.dataFolder + "config.json";
|
if (type == SaveType.NORMAL)
|
||||||
await Functions.SaveToJsonFile<AppConfig>(path, appConfig!);
|
{
|
||||||
|
string path = Functions.dataFolder + "config.json";
|
||||||
|
await Functions.SaveToJsonFile<AppConfig>(path, appConfig!);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (type == SaveType.BACKUP)
|
||||||
|
{
|
||||||
|
string path = Functions.dataFolder + "config.json.bak";
|
||||||
|
await Functions.SaveToJsonFile<AppConfig>(path, appConfig!);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static async Task LoadConfig()
|
public static async Task LoadConfig()
|
||||||
@@ -194,11 +203,24 @@ namespace PluginManager
|
|||||||
string path = Functions.dataFolder + "config.json";
|
string path = Functions.dataFolder + "config.json";
|
||||||
if (File.Exists(path))
|
if (File.Exists(path))
|
||||||
{
|
{
|
||||||
appConfig = await Functions.ConvertFromJson<AppConfig>(path);
|
try
|
||||||
|
{
|
||||||
|
appConfig = await Functions.ConvertFromJson<AppConfig>(path);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
File.Delete(path);
|
||||||
|
Console.WriteLine("An error occured while loading the settings. Importing from backup file...");
|
||||||
|
path = Functions.dataFolder + "config.json.bak";
|
||||||
|
appConfig = await Functions.ConvertFromJson<AppConfig>(path);
|
||||||
|
Functions.WriteErrFile(ex.Message);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Functions.WriteLogFile($"Loaded {appConfig.ApplicationVariables!.Keys.Count} application variables.\nLoaded {appConfig.ProtectedKeyWords!.Count} readonly variables.");
|
Functions.WriteLogFile($"Loaded {appConfig.ApplicationVariables!.Keys.Count} application variables.\nLoaded {appConfig.ProtectedKeyWords!.Count} readonly variables.");
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
else
|
appConfig = new() { ApplicationVariables = new Dictionary<string, object>(), ProtectedKeyWords = new List<string>(), PluginVersions = new Dictionary<string, string>() };
|
||||||
appConfig = new() { ApplicationVariables = new Dictionary<string, object>(), ProtectedKeyWords = new List<string>(), PluginVersions = new Dictionary<string, string>() };
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool ContainsValue<T>(T value) => appConfig!.ApplicationVariables!.ContainsValue(value!);
|
public static bool ContainsValue<T>(T value) => appConfig!.ApplicationVariables!.ContainsValue(value!);
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Diagnostics;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
@@ -81,30 +82,48 @@ public class ConsoleCommandsHandler
|
|||||||
if (pluginsLoaded)
|
if (pluginsLoaded)
|
||||||
return;
|
return;
|
||||||
var loader = new PluginLoader(client!);
|
var loader = new PluginLoader(client!);
|
||||||
|
ConsoleColor cc = Console.ForegroundColor;
|
||||||
loader.onCMDLoad += (name, typeName, success, exception) =>
|
loader.onCMDLoad += (name, typeName, success, exception) =>
|
||||||
{
|
{
|
||||||
Console.ForegroundColor = ConsoleColor.Green;
|
|
||||||
if (name == null || name.Length < 2)
|
if (name == null || name.Length < 2)
|
||||||
name = typeName;
|
name = typeName;
|
||||||
if (success)
|
if (success)
|
||||||
|
{
|
||||||
|
Console.ForegroundColor = ConsoleColor.Green;
|
||||||
Console.WriteLine("[CMD] Successfully loaded command : " + name);
|
Console.WriteLine("[CMD] Successfully loaded command : " + name);
|
||||||
|
}
|
||||||
|
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
|
|
||||||
Console.WriteLine("[CMD] Failed to load command : " + name + " because " + exception!.Message);
|
Console.WriteLine("[CMD] Failed to load command : " + name + " because " + exception!.Message);
|
||||||
Console.ForegroundColor = ConsoleColor.Red;
|
}
|
||||||
|
Console.ForegroundColor = cc;
|
||||||
};
|
};
|
||||||
loader.onEVELoad += (name, typeName, success, exception) =>
|
loader.onEVELoad += (name, typeName, success, exception) =>
|
||||||
{
|
{
|
||||||
if (name == null || name.Length < 2)
|
if (name == null || name.Length < 2)
|
||||||
name = typeName;
|
name = typeName;
|
||||||
Console.ForegroundColor = ConsoleColor.Green;
|
|
||||||
if (success)
|
if (success)
|
||||||
|
{
|
||||||
|
Console.ForegroundColor = ConsoleColor.Green;
|
||||||
Console.WriteLine("[EVENT] Successfully loaded event : " + name);
|
Console.WriteLine("[EVENT] Successfully loaded event : " + name);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
Console.WriteLine("[EVENT] Failed to load event : " + name + " because " + exception!.Message);
|
Console.WriteLine("[EVENT] Failed to load event : " + name + " because " + exception!.Message);
|
||||||
Console.ForegroundColor = ConsoleColor.Red;
|
}
|
||||||
|
Console.ForegroundColor = cc;
|
||||||
};
|
};
|
||||||
|
|
||||||
loader.LoadPlugins();
|
loader.LoadPlugins();
|
||||||
|
Console.ForegroundColor = cc;
|
||||||
pluginsLoaded = true;
|
pluginsLoaded = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -168,6 +187,7 @@ public class ConsoleCommandsHandler
|
|||||||
continue;
|
continue;
|
||||||
var split = line.Split(',');
|
var split = line.Split(',');
|
||||||
Console.WriteLine($"\nDownloading item: {split[1]}");
|
Console.WriteLine($"\nDownloading item: {split[1]}");
|
||||||
|
if (File.Exists("./" + split[1])) File.Delete("./" + split[1]);
|
||||||
await ServerCom.DownloadFileAsync(split[0], "./" + split[1]);
|
await ServerCom.DownloadFileAsync(split[0], "./" + split[1]);
|
||||||
Console.WriteLine();
|
Console.WriteLine();
|
||||||
|
|
||||||
@@ -176,7 +196,7 @@ public class ConsoleCommandsHandler
|
|||||||
Console.WriteLine($"Extracting {split[1]}");
|
Console.WriteLine($"Extracting {split[1]}");
|
||||||
var proc = 0f;
|
var proc = 0f;
|
||||||
var isExtracting = true;
|
var isExtracting = true;
|
||||||
var bar = new Console_Utilities.ProgressBar { Max = 100f, Color = ConsoleColor.Green };
|
var bar = new Console_Utilities.ProgressBar(ProgressBarType.NORMAL) { Max = 100f, Color = ConsoleColor.Green };
|
||||||
|
|
||||||
IProgress<float> extractProgress = new Progress<float>(value => { proc = value; });
|
IProgress<float> extractProgress = new Progress<float>(value => { proc = value; });
|
||||||
new Thread(new Task(() =>
|
new Thread(new Task(() =>
|
||||||
@@ -205,7 +225,7 @@ public class ConsoleCommandsHandler
|
|||||||
}
|
}
|
||||||
VersionString? ver = await VersionString.GetVersionOfPackageFromWeb(name);
|
VersionString? ver = await VersionString.GetVersionOfPackageFromWeb(name);
|
||||||
if (ver is null) throw new Exception("Incorrect version");
|
if (ver is null) throw new Exception("Incorrect version");
|
||||||
Config.SetPluginVersion(name, $"{ver.PackageID}.{ver.PackageMainVersion}.{ver.PackageCheckVersion}");
|
Config.SetPluginVersion(name, $"{ver.PackageVersionID}.{ver.PackageMainVersion}.{ver.PackageCheckVersion}");
|
||||||
// Console.WriteLine();
|
// Console.WriteLine();
|
||||||
|
|
||||||
isDownloading = false;
|
isDownloading = false;
|
||||||
@@ -253,16 +273,30 @@ public class ConsoleCommandsHandler
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
AddCommand("sd", "Shuts down the discord bot", () =>
|
AddCommand("sd", "Shuts down the discord bot", async () =>
|
||||||
{
|
{
|
||||||
if (client is null)
|
if (client is null)
|
||||||
return;
|
return;
|
||||||
client.StopAsync();
|
bool run = true;
|
||||||
client.DisposeAsync();
|
var t = new Thread(() =>
|
||||||
Config.SaveConfig();
|
{
|
||||||
Console.WriteLine("Bot is closing in 2 seconds ! Please wait to save data !");
|
Console_Utilities.ProgressBar bar = new Console_Utilities.ProgressBar(ProgressBarType.NO_END);
|
||||||
Thread.Sleep(2000);
|
while (run)
|
||||||
|
{
|
||||||
|
bar.Update(1);
|
||||||
|
Thread.Sleep(50);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
t.Start();
|
||||||
|
await Config.SaveConfig(SaveType.NORMAL);
|
||||||
|
await Config.SaveConfig(SaveType.BACKUP);
|
||||||
|
await Task.Delay(4000);
|
||||||
|
run = false;
|
||||||
|
Console.WriteLine();
|
||||||
|
await client.StopAsync();
|
||||||
|
await client.DisposeAsync();
|
||||||
Environment.Exit(0);
|
Environment.Exit(0);
|
||||||
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -294,6 +328,99 @@ public class ConsoleCommandsHandler
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
AddCommand("remplug", "Remove a plugin", "remplug [plugName]", async args =>
|
||||||
|
{
|
||||||
|
|
||||||
|
if (args.Length <= 1) return;
|
||||||
|
|
||||||
|
isDownloading = true;
|
||||||
|
string plugName = Functions.MergeStrings(args, 1);
|
||||||
|
if (pluginsLoaded)
|
||||||
|
{
|
||||||
|
if (Functions.GetOperatingSystem() == Others.OperatingSystem.WINDOWS)
|
||||||
|
{
|
||||||
|
Process.Start("DiscordBot.exe", $"/remplug {plugName}");
|
||||||
|
await Task.Delay(100);
|
||||||
|
Environment.Exit(0);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Process.Start("./DiscordBot", $"/remplug {plugName}");
|
||||||
|
await Task.Delay(100);
|
||||||
|
Environment.Exit(0);
|
||||||
|
}
|
||||||
|
isDownloading = false;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
string location = "./Data/Plugins/";
|
||||||
|
|
||||||
|
location = Config.PluginConfig.GetPluginType(plugName) switch
|
||||||
|
{
|
||||||
|
PluginType.Command => location + "Commands/" + plugName + "." + PluginLoader.pluginCMDExtension,
|
||||||
|
PluginType.Event => location + "Events/" + plugName + "." + PluginLoader.pluginEVEExtension,
|
||||||
|
PluginType.Unknown => "./",
|
||||||
|
_ => throw new NotImplementedException("Plugin type incorrect")
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!File.Exists(location))
|
||||||
|
{
|
||||||
|
Console.WriteLine("The plugin does not exist");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
File.Delete(location);
|
||||||
|
if (Config.PluginConfig.Contains(plugName))
|
||||||
|
{
|
||||||
|
var tuple = Config.PluginConfig.InstalledPlugins.Where(t => t.Item1 == plugName).FirstOrDefault();
|
||||||
|
Console.WriteLine("Found: " + tuple.ToString());
|
||||||
|
Config.PluginConfig.InstalledPlugins.Remove(tuple);
|
||||||
|
Config.RemovePluginVersion(plugName);
|
||||||
|
await Config.SaveConfig(SaveType.NORMAL);
|
||||||
|
}
|
||||||
|
Console.WriteLine("Removed the plugin DLL. Checking for other files ...");
|
||||||
|
|
||||||
|
var info = await manager.GetPluginLinkByName(plugName);
|
||||||
|
if (info[2] != string.Empty)
|
||||||
|
{
|
||||||
|
var lines = await ServerCom.ReadTextFromURL(info[2]);
|
||||||
|
foreach (var line in lines)
|
||||||
|
{
|
||||||
|
if (!(line.Length > 0 && line.Contains(",")))
|
||||||
|
continue;
|
||||||
|
var split = line.Split(',');
|
||||||
|
if (File.Exists("./" + split[1]))
|
||||||
|
File.Delete("./" + split[1]);
|
||||||
|
|
||||||
|
|
||||||
|
Console.WriteLine("Removed: " + split[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
if (Directory.Exists(plugName))
|
||||||
|
Directory.Delete(plugName, true);
|
||||||
|
}
|
||||||
|
isDownloading = false;
|
||||||
|
Console.WriteLine(plugName + " has been successfully deleted !");
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
AddCommand("reload", "Reload the bot with all plugins", () =>
|
||||||
|
{
|
||||||
|
if (Functions.GetOperatingSystem() == Others.OperatingSystem.WINDOWS)
|
||||||
|
{
|
||||||
|
Process.Start("DiscordBot.exe", $"lp");
|
||||||
|
HandleCommand("sd");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
Process.Start("./DiscordBot", $"lp");
|
||||||
|
HandleCommand("sd");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
//Sort the commands by name
|
//Sort the commands by name
|
||||||
commandList.Sort((x, y) => x.CommandName.CompareTo(y.CommandName));
|
commandList.Sort((x, y) => x.CommandName.CompareTo(y.CommandName));
|
||||||
}
|
}
|
||||||
@@ -325,9 +452,10 @@ public class ConsoleCommandsHandler
|
|||||||
return commandList.FirstOrDefault(t => t.CommandName == command);
|
return commandList.FirstOrDefault(t => t.CommandName == command);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static async Task ExecuteCommad(string command)
|
public static async Task ExecuteCommad(string command)
|
||||||
{
|
{
|
||||||
var args = command.Split(' ');
|
var args = command.Split(' ');
|
||||||
|
// Console.WriteLine(command);
|
||||||
foreach (var item in commandList.ToList())
|
foreach (var item in commandList.ToList())
|
||||||
if (item.CommandName == args[0])
|
if (item.CommandName == args[0])
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -69,7 +69,7 @@ public class PluginLoader
|
|||||||
{
|
{
|
||||||
string name = new FileInfo(file).Name.Split('.')[0];
|
string name = new FileInfo(file).Name.Split('.')[0];
|
||||||
if (!Config.PluginVersionsContainsKey(name))
|
if (!Config.PluginVersionsContainsKey(name))
|
||||||
Config.SetPluginVersion(name, (await VersionString.GetVersionOfPackageFromWeb(name))?.PackageID + ".0.0");
|
Config.SetPluginVersion(name, (await VersionString.GetVersionOfPackageFromWeb(name))?.PackageVersionID + ".0.0");
|
||||||
|
|
||||||
if (await PluginUpdater.CheckForUpdates(name))
|
if (await PluginUpdater.CheckForUpdates(name))
|
||||||
await PluginUpdater.Download(name);
|
await PluginUpdater.Download(name);
|
||||||
@@ -84,7 +84,7 @@ public class PluginLoader
|
|||||||
{
|
{
|
||||||
string name = new FileInfo(file).Name.Split('.')[0];
|
string name = new FileInfo(file).Name.Split('.')[0];
|
||||||
if (!Config.PluginVersionsContainsKey(name))
|
if (!Config.PluginVersionsContainsKey(name))
|
||||||
Config.SetPluginVersion(name, (await VersionString.GetVersionOfPackageFromWeb(name))?.PackageID + ".0.0");
|
Config.SetPluginVersion(name, (await VersionString.GetVersionOfPackageFromWeb(name))?.PackageVersionID + ".0.0");
|
||||||
|
|
||||||
if (await PluginUpdater.CheckForUpdates(name))
|
if (await PluginUpdater.CheckForUpdates(name))
|
||||||
await PluginUpdater.Download(name);
|
await PluginUpdater.Download(name);
|
||||||
@@ -94,7 +94,7 @@ public class PluginLoader
|
|||||||
|
|
||||||
|
|
||||||
//Save the new config file (after the updates)
|
//Save the new config file (after the updates)
|
||||||
Config.SaveConfig();
|
await Config.SaveConfig(SaveType.NORMAL);
|
||||||
|
|
||||||
|
|
||||||
//Load all plugins
|
//Load all plugins
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ namespace PluginManager.Online.Helpers
|
|||||||
{
|
{
|
||||||
public class VersionString
|
public class VersionString
|
||||||
{
|
{
|
||||||
public int PackageID;
|
public int PackageVersionID;
|
||||||
public int PackageMainVersion;
|
public int PackageMainVersion;
|
||||||
public int PackageCheckVersion;
|
public int PackageCheckVersion;
|
||||||
|
|
||||||
@@ -18,7 +18,7 @@ namespace PluginManager.Online.Helpers
|
|||||||
string[] data = version.Split('.');
|
string[] data = version.Split('.');
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
PackageID = int.Parse(data[0]);
|
PackageVersionID = int.Parse(data[0]);
|
||||||
PackageMainVersion = int.Parse(data[1]);
|
PackageMainVersion = int.Parse(data[1]);
|
||||||
PackageCheckVersion = int.Parse(data[2]);
|
PackageCheckVersion = int.Parse(data[2]);
|
||||||
}
|
}
|
||||||
@@ -28,20 +28,25 @@ namespace PluginManager.Online.Helpers
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#region operators
|
||||||
public static bool operator >(VersionString s1, VersionString s2)
|
public static bool operator >(VersionString s1, VersionString s2)
|
||||||
{
|
{
|
||||||
if (s1.PackageID != s2.PackageID) throw new Exception("Can not compare two different paks");
|
if (s1.PackageVersionID > s2.PackageVersionID) return true;
|
||||||
if (s1.PackageMainVersion > s2.PackageMainVersion) return true;
|
if (s1.PackageVersionID == s2.PackageVersionID)
|
||||||
if (s1.PackageMainVersion == s2.PackageMainVersion && s1.PackageCheckVersion > s2.PackageCheckVersion) return true;
|
{
|
||||||
|
if (s1.PackageMainVersion > s2.PackageMainVersion) return true;
|
||||||
|
if (s1.PackageMainVersion == s2.PackageMainVersion && s1.PackageCheckVersion > s2.PackageCheckVersion) return true;
|
||||||
|
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static bool operator <(VersionString s1, VersionString s2) => !(s1 > s2) && s1 != s2;
|
public static bool operator <(VersionString s1, VersionString s2) => !(s1 > s2) && s1 != s2;
|
||||||
|
|
||||||
public static bool operator ==(VersionString s1, VersionString s2)
|
public static bool operator ==(VersionString s1, VersionString s2)
|
||||||
{
|
{
|
||||||
if (s1.PackageID == s2.PackageID && s1.PackageMainVersion == s2.PackageMainVersion && s1.PackageCheckVersion == s2.PackageCheckVersion) return true;
|
if (s1.PackageVersionID == s2.PackageVersionID && s1.PackageMainVersion == s2.PackageMainVersion && s1.PackageCheckVersion == s2.PackageCheckVersion) return true;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,14 +55,18 @@ namespace PluginManager.Online.Helpers
|
|||||||
public static bool operator <=(VersionString s1, VersionString s2) => (s1 < s2 || s1 == s2);
|
public static bool operator <=(VersionString s1, VersionString s2) => (s1 < s2 || s1 == s2);
|
||||||
public static bool operator >=(VersionString s1, VersionString s2) => (s1 > s2 || s1 == s2);
|
public static bool operator >=(VersionString s1, VersionString s2) => (s1 > s2 || s1 == s2);
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
{
|
{
|
||||||
return "{PackageID: " + PackageID + ", PackageVersion: " + PackageMainVersion + ", PackageCheckVersion: " + PackageCheckVersion + "}";
|
return "{PackageID: " + PackageVersionID + ", PackageVersion: " + PackageMainVersion + ", PackageCheckVersion: " + PackageCheckVersion + "}";
|
||||||
}
|
}
|
||||||
|
|
||||||
public string ToShortString()
|
public string ToShortString()
|
||||||
{
|
{
|
||||||
return $"{PackageID}.{PackageMainVersion}.{PackageCheckVersion}";
|
if (PackageVersionID == 0 && PackageCheckVersion == 0 && PackageMainVersion == 0)
|
||||||
|
return "Unknown";
|
||||||
|
return $"{PackageVersionID}.{PackageMainVersion}.{PackageCheckVersion}";
|
||||||
}
|
}
|
||||||
|
|
||||||
public static VersionString? GetVersionOfPackage(string pakName)
|
public static VersionString? GetVersionOfPackage(string pakName)
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
using PluginManager.Online.Helpers;
|
||||||
using PluginManager.Others;
|
using PluginManager.Others;
|
||||||
|
|
||||||
using OperatingSystem = PluginManager.Others.OperatingSystem;
|
using OperatingSystem = PluginManager.Others.OperatingSystem;
|
||||||
|
|
||||||
namespace PluginManager.Online;
|
namespace PluginManager.Online;
|
||||||
@@ -30,14 +33,14 @@ public class PluginsManager
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var list = await ServerCom.ReadTextFromURL(PluginsLink);
|
var list = await ServerCom.ReadTextFromURL(PluginsLink);
|
||||||
var lines = list.ToArray();
|
var lines = list.ToArray();
|
||||||
|
|
||||||
var data = new List<string[]>();
|
var data = new List<string[]>();
|
||||||
var op = Functions.GetOperatingSystem();
|
var op = Functions.GetOperatingSystem();
|
||||||
|
|
||||||
var len = lines.Length;
|
var len = lines.Length;
|
||||||
string[] titles = { "Name", "Description", "Plugin Type", "Libraries", "Installed" };
|
string[] titles = { "Name", "Description", "Type", "Version", "Installed" };
|
||||||
data.Add(new[] { "-", "-", "-", "-", "-" });
|
data.Add(new[] { "-", "-", "-", "-", "-" });
|
||||||
data.Add(titles);
|
data.Add(titles);
|
||||||
data.Add(new[] { "-", "-", "-", "-", "-" });
|
data.Add(new[] { "-", "-", "-", "-", "-" });
|
||||||
@@ -54,11 +57,7 @@ public class PluginsManager
|
|||||||
display[0] = content[0];
|
display[0] = content[0];
|
||||||
display[1] = content[1];
|
display[1] = content[1];
|
||||||
display[2] = content[2];
|
display[2] = content[2];
|
||||||
if (content.Length == 6 && (content[5] != null || content[5].Length > 2))
|
display[3] = (await VersionString.GetVersionOfPackageFromWeb(content[0]) ?? new VersionString("0.0.0")).ToShortString();
|
||||||
display[3] = ((await ServerCom.ReadTextFromURL(content[5])).Count + 1).ToString();
|
|
||||||
|
|
||||||
else
|
|
||||||
display[3] = "1";
|
|
||||||
if (Config.PluginConfig.Contains(content[0]) || Config.PluginConfig.Contains(content[0]))
|
if (Config.PluginConfig.Contains(content[0]) || Config.PluginConfig.Contains(content[0]))
|
||||||
display[4] = "✓";
|
display[4] = "✓";
|
||||||
else
|
else
|
||||||
@@ -73,8 +72,7 @@ public class PluginsManager
|
|||||||
display[0] = content[0];
|
display[0] = content[0];
|
||||||
display[1] = content[1];
|
display[1] = content[1];
|
||||||
display[2] = content[2];
|
display[2] = content[2];
|
||||||
if (content.Length == 6 && (content[5] != null || content[5].Length > 2))
|
display[3] = (await VersionString.GetVersionOfPackageFromWeb(content[0]) ?? new VersionString("0.0.0")).ToShortString();
|
||||||
display[3] = ((await ServerCom.ReadTextFromURL(content[5])).Count + 1).ToString();
|
|
||||||
if (Config.PluginConfig.Contains(content[0]) || Config.PluginConfig.Contains(content[0]))
|
if (Config.PluginConfig.Contains(content[0]) || Config.PluginConfig.Contains(content[0]))
|
||||||
display[4] = "✓";
|
display[4] = "✓";
|
||||||
else
|
else
|
||||||
@@ -86,7 +84,7 @@ public class PluginsManager
|
|||||||
|
|
||||||
data.Add(new[] { "-", "-", "-", "-", "-" });
|
data.Add(new[] { "-", "-", "-", "-", "-" });
|
||||||
|
|
||||||
Console_Utilities.FormatAndAlignTable(data);
|
Console_Utilities.FormatAndAlignTable(data, TableFormat.CENTER_EACH_COLUMN_BASED);
|
||||||
}
|
}
|
||||||
catch (Exception exception)
|
catch (Exception exception)
|
||||||
{
|
{
|
||||||
@@ -104,9 +102,9 @@ public class PluginsManager
|
|||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var list = await ServerCom.ReadTextFromURL(PluginsLink);
|
var list = await ServerCom.ReadTextFromURL(PluginsLink);
|
||||||
var lines = list.ToArray();
|
var lines = list.ToArray();
|
||||||
var len = lines.Length;
|
var len = lines.Length;
|
||||||
for (var i = 0; i < len; i++)
|
for (var i = 0; i < len; i++)
|
||||||
{
|
{
|
||||||
var contents = lines[i].Split(',');
|
var contents = lines[i].Split(',');
|
||||||
|
|||||||
@@ -51,10 +51,10 @@ namespace PluginManager.Online
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static async Task DownloadFileAsync(string URL, string location)
|
public static async Task DownloadFileAsync(string URL, string location)
|
||||||
{
|
{
|
||||||
bool isDownloading = true;
|
bool isDownloading = true;
|
||||||
float c_progress = 0;
|
float c_progress = 0;
|
||||||
|
|
||||||
Console_Utilities.ProgressBar pbar = new Console_Utilities.ProgressBar { Max = 100f, NoColor = true };
|
Console_Utilities.ProgressBar pbar = new Console_Utilities.ProgressBar(ProgressBarType.NORMAL) { Max = 100f, NoColor = true };
|
||||||
|
|
||||||
IProgress<float> progress = new Progress<float>(percent => { c_progress = percent; });
|
IProgress<float> progress = new Progress<float>(percent => { c_progress = percent; });
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using Discord;
|
using Discord;
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
namespace PluginManager.Others
|
namespace PluginManager.Others
|
||||||
{
|
{
|
||||||
@@ -32,16 +32,58 @@ namespace PluginManager.Others
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class ProgressBar
|
public class ProgressBar
|
||||||
{
|
{
|
||||||
public float Max { get; init; }
|
public ProgressBar(ProgressBarType type)
|
||||||
public ConsoleColor Color { get; init; }
|
{
|
||||||
public bool NoColor { get; init; }
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float Max { get; init; }
|
||||||
|
public ConsoleColor Color { get; init; }
|
||||||
|
public bool NoColor { get; init; }
|
||||||
|
public ProgressBarType type { get; set; }
|
||||||
|
|
||||||
public void Update(float progress, double speed = -1, string? unit = null)
|
private int BarLength = 32;
|
||||||
|
private int position = 1;
|
||||||
|
private bool positive = true;
|
||||||
|
|
||||||
|
public void Update(float progress)
|
||||||
|
{
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case ProgressBarType.NORMAL:
|
||||||
|
UpdateNormal(progress);
|
||||||
|
return;
|
||||||
|
case ProgressBarType.NO_END:
|
||||||
|
if (progress <= 99.9f)
|
||||||
|
UpdateNoEnd();
|
||||||
|
return;
|
||||||
|
default:
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateNoEnd()
|
||||||
{
|
{
|
||||||
Console.CursorLeft = 0;
|
Console.CursorLeft = 0;
|
||||||
Console.Write("[");
|
Console.Write("[");
|
||||||
Console.CursorLeft = 32;
|
for (int i = 1; i <= position; i++)
|
||||||
|
Console.Write(" ");
|
||||||
|
Console.Write("<==()==>");
|
||||||
|
position += positive ? 1 : -1;
|
||||||
|
for (int i = position; i <= BarLength - 1 - (positive ? 0 : 2); i++)
|
||||||
|
Console.Write(" ");
|
||||||
|
Console.Write("]");
|
||||||
|
|
||||||
|
|
||||||
|
if (position == BarLength - 1 || position == 1)
|
||||||
|
positive = !positive;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UpdateNormal(float progress)
|
||||||
|
{
|
||||||
|
Console.CursorLeft = 0;
|
||||||
|
Console.Write("[");
|
||||||
|
Console.CursorLeft = BarLength;
|
||||||
Console.Write("]");
|
Console.Write("]");
|
||||||
Console.CursorLeft = 1;
|
Console.CursorLeft = 1;
|
||||||
float onechunk = 30.0f / Max;
|
float onechunk = 30.0f / Max;
|
||||||
@@ -51,28 +93,23 @@ namespace PluginManager.Others
|
|||||||
for (int i = 0; i < onechunk * progress; i++)
|
for (int i = 0; i < onechunk * progress; i++)
|
||||||
{
|
{
|
||||||
Console.BackgroundColor = NoColor ? ConsoleColor.Black : this.Color;
|
Console.BackgroundColor = NoColor ? ConsoleColor.Black : this.Color;
|
||||||
Console.CursorLeft = position++;
|
Console.CursorLeft = position++;
|
||||||
Console.Write("#");
|
Console.Write("#");
|
||||||
}
|
}
|
||||||
|
|
||||||
for (int i = position; i <= 31; i++)
|
for (int i = position; i < BarLength; i++)
|
||||||
{
|
{
|
||||||
Console.BackgroundColor = NoColor ? ConsoleColor.Black : ConsoleColor.DarkGray;
|
Console.BackgroundColor = NoColor ? ConsoleColor.Black : ConsoleColor.DarkGray;
|
||||||
Console.CursorLeft = position++;
|
Console.CursorLeft = position++;
|
||||||
Console.Write(" ");
|
Console.Write(" ");
|
||||||
}
|
}
|
||||||
|
|
||||||
Console.CursorLeft = 35;
|
Console.CursorLeft = BarLength + 4;
|
||||||
Console.BackgroundColor = ConsoleColor.Black;
|
Console.BackgroundColor = ConsoleColor.Black;
|
||||||
if (speed is -1 || unit == null)
|
if (progress.CanAproximateTo(Max))
|
||||||
{
|
Console.Write(progress + " % ✓");
|
||||||
if (progress.CanAproximateTo(Max))
|
|
||||||
Console.Write(progress + " % ✓");
|
|
||||||
else
|
|
||||||
Console.Write(MathF.Round(progress, 2) + " % ");
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
Console.Write(progress + $"{speed} {unit}/s ");
|
Console.Write(MathF.Round(progress, 2) + " % ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,13 +121,13 @@ namespace PluginManager.Others
|
|||||||
/// A way to create a table based on input data
|
/// A way to create a table based on input data
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="data">The List of arrays of strings that represent the rows.</param>
|
/// <param name="data">The List of arrays of strings that represent the rows.</param>
|
||||||
public static void FormatAndAlignTable(List<string[]> data, TableFormat format = TableFormat.CENTER_EACH_COLUMN_BASED)
|
public static void FormatAndAlignTable(List<string[]> data, TableFormat format)
|
||||||
{
|
{
|
||||||
if (format == TableFormat.CENTER_EACH_COLUMN_BASED)
|
if (format == TableFormat.CENTER_EACH_COLUMN_BASED)
|
||||||
{
|
{
|
||||||
char tableLine = '-';
|
char tableLine = '-';
|
||||||
char tableCross = '+';
|
char tableCross = '+';
|
||||||
char tableWall = '|';
|
char tableWall = '|';
|
||||||
|
|
||||||
int[] len = new int[data[0].Length];
|
int[] len = new int[data[0].Length];
|
||||||
foreach (var line in data)
|
foreach (var line in data)
|
||||||
@@ -196,8 +233,8 @@ namespace PluginManager.Others
|
|||||||
|
|
||||||
if (format == TableFormat.DEFAULT)
|
if (format == TableFormat.DEFAULT)
|
||||||
{
|
{
|
||||||
int[] widths = new int[data[0].Length];
|
int[] widths = new int[data[0].Length];
|
||||||
int space_between_columns = int.Parse(Config.GetValue<Dictionary<string, string>>("TableVariables")?["DefaultSpace"]!);
|
int space_between_columns = int.Parse(Config.GetValue<Dictionary<string, string>>("TableVariables")?["DefaultSpace"]!);
|
||||||
for (int i = 0; i < data.Count; i++)
|
for (int i = 0; i < data.Count; i++)
|
||||||
{
|
{
|
||||||
for (int j = 0; j < data[i].Length; j++)
|
for (int j = 0; j < data[i].Length; j++)
|
||||||
@@ -230,7 +267,7 @@ namespace PluginManager.Others
|
|||||||
public static void WriteColorText(string text, bool appendNewLineAtEnd = true)
|
public static void WriteColorText(string text, bool appendNewLineAtEnd = true)
|
||||||
{
|
{
|
||||||
ConsoleColor initialForeGround = Console.ForegroundColor;
|
ConsoleColor initialForeGround = Console.ForegroundColor;
|
||||||
char[] input = text.ToCharArray();
|
char[] input = text.ToCharArray();
|
||||||
for (int i = 0; i < input.Length; i++)
|
for (int i = 0; i < input.Length; i++)
|
||||||
{
|
{
|
||||||
if (input[i] == Config.GetValue<char>("ColorPrefix"))
|
if (input[i] == Config.GetValue<char>("ColorPrefix"))
|
||||||
|
|||||||
@@ -31,3 +31,6 @@ public enum PluginType { Command, Event, Unknown }
|
|||||||
public enum UnzipProgressType { PercentageFromNumberOfFiles, PercentageFromTotalSize }
|
public enum UnzipProgressType { PercentageFromNumberOfFiles, PercentageFromTotalSize }
|
||||||
|
|
||||||
public enum TableFormat { CENTER_EACH_COLUMN_BASED, CENTER_OVERALL_LENGTH, DEFAULT }
|
public enum TableFormat { CENTER_EACH_COLUMN_BASED, CENTER_OVERALL_LENGTH, DEFAULT }
|
||||||
|
|
||||||
|
public enum SaveType { NORMAL, BACKUP }
|
||||||
|
public enum ProgressBarType { NORMAL, NO_END }
|
||||||
@@ -26,17 +26,17 @@ namespace PluginManager.Others
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The location for all logs
|
/// The location for all logs
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly string logFolder = @"./Output/Logs/";
|
public static readonly string logFolder = @"./Data/Output/Logs/";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The location for all errors
|
/// The location for all errors
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly string errFolder = @"./Output/Errors/";
|
public static readonly string errFolder = @"./Data/Output/Errors/";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Archives folder
|
/// Archives folder
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly string pakFolder = @"./Data/Resources/PAK/";
|
public static readonly string pakFolder = @"./Data/PAKS/";
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Beta testing folder
|
/// Beta testing folder
|
||||||
@@ -50,7 +50,7 @@ namespace PluginManager.Others
|
|||||||
/// <param name="FileName">The file name that is inside the archive or its full path</param>
|
/// <param name="FileName">The file name that is inside the archive or its full path</param>
|
||||||
/// <param name="archFile">The archive location from the PAKs folder</param>
|
/// <param name="archFile">The archive location from the PAKs folder</param>
|
||||||
/// <returns>A string that represents the content of the file or null if the file does not exists or it has no content</returns>
|
/// <returns>A string that represents the content of the file or null if the file does not exists or it has no content</returns>
|
||||||
public static Stream? ReadFromPakAsync(string FileName, string archFile)
|
public static async Task<Stream?> ReadFromPakAsync(string FileName, string archFile)
|
||||||
{
|
{
|
||||||
archFile = pakFolder + archFile;
|
archFile = pakFolder + archFile;
|
||||||
Directory.CreateDirectory(pakFolder);
|
Directory.CreateDirectory(pakFolder);
|
||||||
@@ -58,7 +58,11 @@ namespace PluginManager.Others
|
|||||||
|
|
||||||
using ZipArchive archive = ZipFile.OpenRead(archFile);
|
using ZipArchive archive = ZipFile.OpenRead(archFile);
|
||||||
ZipArchiveEntry? entry = archive.GetEntry(FileName);
|
ZipArchiveEntry? entry = archive.GetEntry(FileName);
|
||||||
return entry?.Open();
|
if (entry is null) return Stream.Null;
|
||||||
|
MemoryStream stream = new MemoryStream();
|
||||||
|
await (entry?.Open()!).CopyToAsync(stream);
|
||||||
|
|
||||||
|
return stream;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -261,10 +265,9 @@ namespace PluginManager.Others
|
|||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public static async Task SaveToJsonFile<T>(string file, T Data)
|
public static async Task SaveToJsonFile<T>(string file, T Data)
|
||||||
{
|
{
|
||||||
File.Delete(file);
|
MemoryStream str = new MemoryStream();
|
||||||
var s = File.Open(file, FileMode.OpenOrCreate);
|
await JsonSerializer.SerializeAsync(str, Data, typeof(T), new JsonSerializerOptions { WriteIndented = true });
|
||||||
await JsonSerializer.SerializeAsync(s, Data, typeof(T), new JsonSerializerOptions { WriteIndented = true });
|
await File.WriteAllBytesAsync(file, str.ToArray());
|
||||||
s.Close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -277,8 +280,7 @@ namespace PluginManager.Others
|
|||||||
{
|
{
|
||||||
Stream text;
|
Stream text;
|
||||||
if (File.Exists(input))
|
if (File.Exists(input))
|
||||||
text = File.OpenRead(input);
|
text = new MemoryStream(await File.ReadAllBytesAsync(input));
|
||||||
|
|
||||||
else
|
else
|
||||||
text = new MemoryStream(Encoding.ASCII.GetBytes(input));
|
text = new MemoryStream(Encoding.ASCII.GetBytes(input));
|
||||||
text.Position = 0;
|
text.Position = 0;
|
||||||
|
|||||||
@@ -16,11 +16,6 @@ Plugin Types:
|
|||||||
1. Commands
|
1. Commands
|
||||||
2. Events
|
2. Events
|
||||||
|
|
||||||
<!--
|
|
||||||
Project Structure
|
|
||||||
|
|
||||||
-->
|
|
||||||
|
|
||||||
### How to create a plugin
|
### How to create a plugin
|
||||||
|
|
||||||
First of all, Create a new project (class library) in Visual Studio.
|
First of all, Create a new project (class library) in Visual Studio.
|
||||||
|
|||||||
Reference in New Issue
Block a user