This commit is contained in:
2022-09-10 16:47:00 +03:00
parent 571c0a5360
commit 81cc6709d6
9 changed files with 73 additions and 46 deletions

Binary file not shown.

View File

@@ -5,6 +5,7 @@ using Discord;
using Discord.Commands;
using Discord.WebSocket;
using PluginManager;
using PluginManager.Interfaces;
using PluginManager.Loaders;
using PluginManager.Others;
@@ -42,9 +43,6 @@ internal class Help : DBCommand
/// The main body of the command
/// </summary>
/// <param name="context">The command context</param>
/// <param name="message">The command message</param>
/// <param name="client">The discord bot client</param>
/// <param name="isDM">True if the message was sent from a DM channel, false otherwise</param>
public void ExecuteServer(SocketCommandContext context)
{
var args = Functions.GetArguments(context.Message);
@@ -86,7 +84,7 @@ internal class Help : DBCommand
var cmd = PluginLoader.Commands!.Find(p => p.Command == command || (p.Aliases is not null && p.Aliases.Contains(command)));
if (cmd == null) return null;
embedBuilder.AddField("Usage", cmd.Usage);
embedBuilder.AddField("Usage", Config.GetValue<string>("prefix") + cmd.Usage);
embedBuilder.AddField("Description", cmd.Description);
if (cmd.Aliases is null)
return embedBuilder;

View File

@@ -8,7 +8,7 @@
<StartupObject />
<SignAssembly>False</SignAssembly>
<IsPublishable>True</IsPublishable>
<AssemblyVersion>1.0.0.11</AssemblyVersion>
<AssemblyVersion>1.0.0.12</AssemblyVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">

View File

@@ -32,10 +32,6 @@ public class Program
public static void Main(string[] args)
{
Console.WriteLine("Loading resources ...");
Directory.CreateDirectory("./Data/Resources");
Directory.CreateDirectory("./Data/Plugins/Commands");
Directory.CreateDirectory("./Data/Plugins/Events");
PreLoadComponents().Wait();
do
{
@@ -225,23 +221,6 @@ public class Program
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 (args.Contains("lp") || args.Contains("loadplugins"))
@@ -267,6 +246,13 @@ public class Program
len = 0;
}
if (len > 0 && args[0] == "/updateplug")
{
string plugName = args.MergeStrings(1);
Console.WriteLine("Updating " + plugName);
await ConsoleCommandsHandler.ExecuteCommad("dwplug" + plugName);
return;
}
if (len == 0 || (args[0] != "--exec" && args[0] != "--execute"))
{
@@ -348,6 +334,10 @@ public class Program
{
Console_Utilities.ProgressBar main = new Console_Utilities.ProgressBar(ProgressBarType.NO_END);
main.Start();
Directory.CreateDirectory("./Data/Resources");
Directory.CreateDirectory("./Data/Plugins/Commands");
Directory.CreateDirectory("./Data/Plugins/Events");
Directory.CreateDirectory("./Data/PAKS");
await Config.LoadConfig();
if (Config.ContainsKey("DeleteLogsAtStartup"))
if (Config.GetValue<bool>("DeleteLogsAtStartup"))

View File

@@ -12,7 +12,7 @@ namespace FreeGamesModule
public string Description => "Check out any free game";
public string Usage => "free";
public string Usage => "free [platform]";
public bool requireAdmin => false;

View File

@@ -184,6 +184,11 @@ namespace PluginManager
SaveConfig(SaveType.NORMAL);
}
public static bool IsReadOnly(string key)
{
return appConfig.ProtectedKeyWords.Contains(key);
}
public static async Task SaveConfig(SaveType type)
{
if (type == SaveType.NORMAL)
@@ -229,6 +234,6 @@ namespace PluginManager
public static bool ContainsValue<T>(T value) => appConfig!.ApplicationVariables!.ContainsValue(value!);
public static bool ContainsKey(string key) => appConfig!.ApplicationVariables!.ContainsKey(key);
public static ReadOnlyDictionary<string, object> GetAllVariables() => new(appConfig!.ApplicationVariables!);
public static IDictionary<string, object> GetAllVariables() => appConfig.ApplicationVariables;
}
}

View File

@@ -164,11 +164,10 @@ public class ConsoleCommandsHandler
path = $"./{info[1].Split('/')[info[1].Split('/').Length - 1]}";
//Console.WriteLine("Downloading: " + path + " [" + info[1] + "]");
await ServerCom.DownloadFileAsync(info[1], path);
if (info[0] == "Command" || info[0] == "Event")
if (info[0] == "Event")
Config.PluginConfig.InstalledPlugins.Add(new(name, PluginType.Event));
else if (info[0] == "Command")
Config.PluginConfig.InstalledPlugins.Add(new(name, PluginType.Command));
if (info[0] == "Event")
Config.PluginConfig.InstalledPlugins.Add(new(name, PluginType.Event));
else if (info[0] == "Command")
Config.PluginConfig.InstalledPlugins.Add(new(name, PluginType.Command));
Console.WriteLine("\n");
@@ -190,11 +189,12 @@ public class ConsoleCommandsHandler
if (File.Exists("./" + split[1])) File.Delete("./" + split[1]);
await ServerCom.DownloadFileAsync(split[0], "./" + split[1]);
Console.WriteLine();
if (split[0].EndsWith(".zip") || split[0].EndsWith(".pak") || split[0].EndsWith(".pkg"))
if (split[0].EndsWith(".pak"))
File.Move("./" + split[1], "./Data/PAKS/" + split[1], true);
else if (split[0].EndsWith(".zip") || split[0].EndsWith(".pkg"))
{
Console.WriteLine($"Extracting {split[1]} ...");
var bar = new Console_Utilities.ProgressBar(ProgressBarType.NO_END) { Max = 100f, Color = ConsoleColor.Green };
var bar = new Console_Utilities.ProgressBar(ProgressBarType.NO_END);// { Max = 100f, Color = ConsoleColor.Green };
bar.Start();
await Functions.ExtractArchive("./" + split[1], "./", null, UnzipProgressType.PercentageFromTotalSize);
bar.Stop();

View File

@@ -50,21 +50,42 @@ namespace PluginManager.Others
/// <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>
/// <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 async Task<Stream?> ReadFromPakAsync(string FileName, string archFile)
public static async Task<string> ReadFromPakAsync(string FileName, string archFile)
{
archFile = pakFolder + archFile;
Directory.CreateDirectory(pakFolder);
if (!File.Exists(archFile)) throw new FileNotFoundException("Failed to load file !");
if (!File.Exists(archFile))
throw new Exception("Failed to load file !");
using ZipArchive archive = ZipFile.OpenRead(archFile);
ZipArchiveEntry? entry = archive.GetEntry(FileName);
if (entry is null) return Stream.Null;
MemoryStream stream = new MemoryStream();
await (entry?.Open()!).CopyToAsync(stream);
try
{
string textValue = null;
using (var fs = new FileStream(archFile, FileMode.Open))
using (var zip = new ZipArchive(fs, ZipArchiveMode.Read))
foreach (var entry in zip.Entries)
{
if (entry.Name == FileName || entry.FullName == FileName)
{
using (Stream s = entry.Open())
using (StreamReader reader = new StreamReader(s))
{
textValue = await reader.ReadToEndAsync();
reader.Close();
s.Close();
fs.Close();
}
}
}
return textValue;
}
catch
{
await Task.Delay(100);
return await ReadFromPakAsync(FileName, archFile);
}
return stream;
}
/// <summary>
/// Write logs to file
/// </summary>

View File

@@ -27,7 +27,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Others", "Others", "{727BBA
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Updater", "Updater\Updater.csproj", "{24616F7E-E2E9-45A3-8A44-AB51FCD2D525}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "FreeGamesModule", "FreeGamesModule\FreeGamesModule.csproj", "{8959C766-414D-4EF8-BC85-9928B30AAF0A}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "FreeGamesModule", "FreeGamesModule\FreeGamesModule.csproj", "{8959C766-414D-4EF8-BC85-9928B30AAF0A}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DiscordBotWindowsUI", "DiscordBotWindowsUI\DiscordBotWindowsUI.csproj", "{EFE12083-F9FE-4807-8E39-809E0391BAF0}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WindowsUI", "WindowsUI\WindowsUI.csproj", "{ECF79CD3-789E-476D-8512-CE0FAF71ADF5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -71,6 +75,14 @@ Global
{8959C766-414D-4EF8-BC85-9928B30AAF0A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8959C766-414D-4EF8-BC85-9928B30AAF0A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8959C766-414D-4EF8-BC85-9928B30AAF0A}.Release|Any CPU.Build.0 = Release|Any CPU
{EFE12083-F9FE-4807-8E39-809E0391BAF0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{EFE12083-F9FE-4807-8E39-809E0391BAF0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{EFE12083-F9FE-4807-8E39-809E0391BAF0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{EFE12083-F9FE-4807-8E39-809E0391BAF0}.Release|Any CPU.Build.0 = Release|Any CPU
{ECF79CD3-789E-476D-8512-CE0FAF71ADF5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{ECF79CD3-789E-476D-8512-CE0FAF71ADF5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{ECF79CD3-789E-476D-8512-CE0FAF71ADF5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{ECF79CD3-789E-476D-8512-CE0FAF71ADF5}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -86,6 +98,7 @@ Global
{727BBA0B-9114-4BC8-B9A8-3F461449A564} = {1862ABD5-7C30-4F15-A561-45AC8A9CA10E}
{24616F7E-E2E9-45A3-8A44-AB51FCD2D525} = {727BBA0B-9114-4BC8-B9A8-3F461449A564}
{8959C766-414D-4EF8-BC85-9928B30AAF0A} = {449FA364-0B72-43FF-B3A3-806E2916200E}
{ECF79CD3-789E-476D-8512-CE0FAF71ADF5} = {A290C028-77C4-4D1D-AB43-DDFE6ABD9012}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3FB3C5DE-ED21-4D2E-ABDD-3A00EE4A2FFF}