This commit is contained in:
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
BIN
BUILDS/net6.0/Plugins/Commands/Roles.dll
Normal file
BIN
BUILDS/net6.0/Plugins/Commands/Roles.dll
Normal file
Binary file not shown.
Binary file not shown.
@@ -7,8 +7,11 @@ using System.Reflection;
|
|||||||
using System.Runtime.Loader;
|
using System.Runtime.Loader;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
using Discord.WebSocket;
|
using Discord.WebSocket;
|
||||||
|
|
||||||
using DiscordBot.Discord.Core;
|
using DiscordBot.Discord.Core;
|
||||||
|
|
||||||
using PluginManager;
|
using PluginManager;
|
||||||
using PluginManager.Interfaces;
|
using PluginManager.Interfaces;
|
||||||
using PluginManager.Items;
|
using PluginManager.Items;
|
||||||
@@ -29,6 +32,7 @@ public class Program
|
|||||||
[Obsolete]
|
[Obsolete]
|
||||||
public static void Main(string[] args)
|
public static void Main(string[] args)
|
||||||
{
|
{
|
||||||
|
|
||||||
Directory.CreateDirectory("./Data/Resources");
|
Directory.CreateDirectory("./Data/Resources");
|
||||||
Directory.CreateDirectory("./Data/Plugins/Commands");
|
Directory.CreateDirectory("./Data/Plugins/Commands");
|
||||||
Directory.CreateDirectory("./Data/Plugins/Events");
|
Directory.CreateDirectory("./Data/Plugins/Events");
|
||||||
@@ -42,7 +46,7 @@ public class Program
|
|||||||
Console.WriteLine("Please enter the server ID: ");
|
Console.WriteLine("Please enter the server ID: ");
|
||||||
Console_Utilities.WriteColorText("You can find it in the Server Settings at &r\"Widget\"&c section");
|
Console_Utilities.WriteColorText("You can find it in the Server Settings at &r\"Widget\"&c section");
|
||||||
Console.WriteLine("Example: 1234567890123456789");
|
Console.WriteLine("Example: 1234567890123456789");
|
||||||
|
|
||||||
Console.WriteLine("This is not required, but is recommended. If you refuse to provide the ID, just press enter.\nThe server id is required to make easier for the bot to interact with the server.\nRemember: this bot is for one server ONLY.");
|
Console.WriteLine("This is not required, but is recommended. If you refuse to provide the ID, just press enter.\nThe server id is required to make easier for the bot to interact with the server.\nRemember: this bot is for one server ONLY.");
|
||||||
Console.Write("User Input > ");
|
Console.Write("User Input > ");
|
||||||
ConsoleKeyInfo key = Console.ReadKey();
|
ConsoleKeyInfo key = Console.ReadKey();
|
||||||
@@ -57,15 +61,15 @@ public class Program
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Config.AddValueToVariables("ServerID", SID, false);
|
Config.AddValueToVariables("ServerID", SID, false);
|
||||||
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
} while (true);
|
} while (true);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Config.ContainsKey("token") || Config.GetValue<string>("token") == null || Config.GetValue<string>("token")?.Length != 70)
|
if (!Config.ContainsKey("token") || Config.GetValue<string>("token") == null || Config.GetValue<string>("token")?.Length != 70)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Please insert your token");
|
Console.WriteLine("Please insert your token");
|
||||||
@@ -121,12 +125,12 @@ public class Program
|
|||||||
Console.ForegroundColor = ConsoleColor.White;
|
Console.ForegroundColor = ConsoleColor.White;
|
||||||
|
|
||||||
#if DEBUG
|
#if DEBUG
|
||||||
Console_Utilities.WriteColorText("&rSethBot (&yDEBUG&r) &c> ", false);
|
//Console_Utilities.WriteColorText("&rSethBot (&yDEBUG&r) &c> ", false);
|
||||||
var cmd = Console.ReadLine();
|
var cmd = Console.ReadLine();
|
||||||
if (!consoleCommandsHandler.HandleCommand(cmd!, false) && cmd.Length > 0)
|
if (!consoleCommandsHandler.HandleCommand(cmd!, false) && cmd.Length > 0)
|
||||||
Console.WriteLine("Failed to run command " + cmd);
|
Console.WriteLine("Failed to run command " + cmd);
|
||||||
#else
|
#else
|
||||||
Console_Utilities.WriteColorText("&rSethBot &c> ", false);
|
//Console_Utilities.WriteColorText("&rSethBot &c> ", false);
|
||||||
var cmd = Console.ReadLine();
|
var cmd = Console.ReadLine();
|
||||||
if (!consoleCommandsHandler.HandleCommand(cmd!) && cmd.Length > 0)
|
if (!consoleCommandsHandler.HandleCommand(cmd!) && cmd.Length > 0)
|
||||||
Console.WriteLine("Failed to run command " + cmd);
|
Console.WriteLine("Failed to run command " + cmd);
|
||||||
@@ -189,7 +193,7 @@ public class Program
|
|||||||
/// <param name="d">Directory path</param>
|
/// <param name="d">Directory path</param>
|
||||||
private static Task ClearFolder(string d)
|
private static Task ClearFolder(string d)
|
||||||
{
|
{
|
||||||
var files = Directory.GetFiles(d);
|
var files = Directory.GetFiles(d);
|
||||||
var fileNumb = files.Length;
|
var fileNumb = files.Length;
|
||||||
for (var i = 0; i < fileNumb; i++)
|
for (var i = 0; i < fileNumb; i++)
|
||||||
{
|
{
|
||||||
@@ -210,7 +214,7 @@ public class Program
|
|||||||
|
|
||||||
if (len == 3 && args[0] == "/download")
|
if (len == 3 && args[0] == "/download")
|
||||||
{
|
{
|
||||||
var url = args[1];
|
var url = args[1];
|
||||||
var location = args[2];
|
var location = args[2];
|
||||||
|
|
||||||
await ServerCom.DownloadFileAsync(url, location);
|
await ServerCom.DownloadFileAsync(url, location);
|
||||||
@@ -231,7 +235,7 @@ public class Program
|
|||||||
|
|
||||||
if (len == 0 || (args[0] != "--exec" && args[0] != "--execute"))
|
if (len == 0 || (args[0] != "--exec" && args[0] != "--execute"))
|
||||||
{
|
{
|
||||||
var b = await StartNoGUI();
|
var b = await StartNoGUI();
|
||||||
|
|
||||||
Thread mainThread = new Thread(() => NoGUI(b));
|
Thread mainThread = new Thread(() => NoGUI(b));
|
||||||
mainThread.Start();
|
mainThread.Start();
|
||||||
|
|||||||
14
DiscordBotConsoleLauncher/DiscordBotConsoleLauncher.csproj
Normal file
14
DiscordBotConsoleLauncher/DiscordBotConsoleLauncher.csproj
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
<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>
|
||||||
21
DiscordBotConsoleLauncher/Program.cs
Normal file
21
DiscordBotConsoleLauncher/Program.cs
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
@@ -12,7 +12,9 @@ namespace PluginManager
|
|||||||
internal class AppConfig
|
internal class AppConfig
|
||||||
{
|
{
|
||||||
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 static class Config
|
public static class Config
|
||||||
@@ -29,27 +31,27 @@ namespace PluginManager
|
|||||||
|
|
||||||
private static void LoadCommands()
|
private static void LoadCommands()
|
||||||
{
|
{
|
||||||
string cmd_path = "./Data/Plugins/Commands/";
|
string cmd_path = "./Data/Plugins/Commands/";
|
||||||
string[] files = Directory.GetFiles(cmd_path, $"*.{Loaders.PluginLoader.pluginCMDExtension}", SearchOption.AllDirectories);
|
string[] files = Directory.GetFiles(cmd_path, $"*.{Loaders.PluginLoader.pluginCMDExtension}", SearchOption.AllDirectories);
|
||||||
foreach (var file in files)
|
foreach (var file in files)
|
||||||
if (!file.Contains("PluginManager", StringComparison.InvariantCultureIgnoreCase))
|
if (!file.Contains("PluginManager", StringComparison.InvariantCultureIgnoreCase))
|
||||||
{
|
{
|
||||||
string PluginName = new FileInfo(file).Name;
|
string PluginName = new FileInfo(file).Name;
|
||||||
string name = PluginName.Substring(0, PluginName.Length - 1 - PluginManager.Loaders.PluginLoader.pluginCMDExtension.Length);
|
string name = PluginName.Substring(0, PluginName.Length - 1 - PluginManager.Loaders.PluginLoader.pluginCMDExtension.Length);
|
||||||
InstalledPlugins.Add(new(name, PluginType.Command));
|
InstalledPlugins.Add(new(name, PluginType.Command));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void LoadEvents()
|
private static void LoadEvents()
|
||||||
{
|
{
|
||||||
string eve_path = "./Data/Plugins/Events/";
|
string eve_path = "./Data/Plugins/Events/";
|
||||||
string[] files = Directory.GetFiles(eve_path, $"*.{Loaders.PluginLoader.pluginEVEExtension}", SearchOption.AllDirectories);
|
string[] files = Directory.GetFiles(eve_path, $"*.{Loaders.PluginLoader.pluginEVEExtension}", SearchOption.AllDirectories);
|
||||||
foreach (var file in files)
|
foreach (var file in files)
|
||||||
if (!file.Contains("PluginManager", StringComparison.InvariantCultureIgnoreCase))
|
if (!file.Contains("PluginManager", StringComparison.InvariantCultureIgnoreCase))
|
||||||
if (!file.Contains("PluginManager", StringComparison.InvariantCultureIgnoreCase))
|
if (!file.Contains("PluginManager", StringComparison.InvariantCultureIgnoreCase))
|
||||||
{
|
{
|
||||||
string PluginName = new FileInfo(file).Name;
|
string PluginName = new FileInfo(file).Name;
|
||||||
string name = PluginName.Substring(0, PluginName.Length - 1 - PluginManager.Loaders.PluginLoader.pluginEVEExtension.Length);
|
string name = PluginName.Substring(0, PluginName.Length - 1 - PluginManager.Loaders.PluginLoader.pluginEVEExtension.Length);
|
||||||
InstalledPlugins.Add(new(name, PluginType.Event));
|
InstalledPlugins.Add(new(name, PluginType.Event));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -77,6 +79,19 @@ 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 void SetPluginVersion(string pluginName, string newVersion)
|
||||||
|
{
|
||||||
|
if (appConfig.PluginVersions.ContainsKey(pluginName))
|
||||||
|
appConfig.PluginVersions[pluginName] = newVersion;
|
||||||
|
else appConfig.PluginVersions.Add(pluginName, newVersion);
|
||||||
|
|
||||||
|
SaveConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void RemovePluginVersion(string pluginName) => appConfig.PluginVersions.Remove(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)
|
||||||
{
|
{
|
||||||
if (value == null)
|
if (value == null)
|
||||||
@@ -183,11 +198,11 @@ namespace PluginManager
|
|||||||
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.");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
appConfig = new() { ApplicationVariables = new Dictionary<string, object>(), ProtectedKeyWords = new List<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!);
|
||||||
public static bool ContainsKey(string key) => appConfig!.ApplicationVariables!.ContainsKey(key);
|
public static bool ContainsKey(string key) => appConfig!.ApplicationVariables!.ContainsKey(key);
|
||||||
|
|
||||||
public static ReadOnlyDictionary<string, object> GetAllVariables() => new(appConfig!.ApplicationVariables!);
|
public static ReadOnlyDictionary<string, object> GetAllVariables() => new(appConfig!.ApplicationVariables!);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,18 +4,26 @@ using System.IO;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
using Discord.WebSocket;
|
using Discord.WebSocket;
|
||||||
|
|
||||||
using PluginManager.Loaders;
|
using PluginManager.Loaders;
|
||||||
using PluginManager.Online;
|
using PluginManager.Online;
|
||||||
|
using PluginManager.Online.Helpers;
|
||||||
|
using PluginManager.Online.Updates;
|
||||||
using PluginManager.Others;
|
using PluginManager.Others;
|
||||||
|
|
||||||
namespace PluginManager.Items;
|
namespace PluginManager.Items;
|
||||||
|
|
||||||
public class ConsoleCommandsHandler
|
public class ConsoleCommandsHandler
|
||||||
{
|
{
|
||||||
private static readonly PluginsManager manager = new("https://raw.githubusercontent.com/Wizzy69/installer/discord-bot-files/Plugins.txt");
|
private static readonly PluginsManager manager = new("https://raw.githubusercontent.com/Wizzy69/installer/discord-bot-files/Plugins.txt");
|
||||||
private static readonly List<ConsoleCommand> commandList = new();
|
private static readonly List<ConsoleCommand> commandList = new();
|
||||||
private readonly DiscordSocketClient? client;
|
private readonly DiscordSocketClient? client;
|
||||||
|
|
||||||
|
|
||||||
|
private static bool isDownloading = false;
|
||||||
|
private static bool pluginsLoaded = false;
|
||||||
|
|
||||||
public ConsoleCommandsHandler(DiscordSocketClient client)
|
public ConsoleCommandsHandler(DiscordSocketClient client)
|
||||||
{
|
{
|
||||||
@@ -26,7 +34,7 @@ public class ConsoleCommandsHandler
|
|||||||
|
|
||||||
private void InitializeBasicCommands()
|
private void InitializeBasicCommands()
|
||||||
{
|
{
|
||||||
var pluginsLoaded = false;
|
|
||||||
commandList.Clear();
|
commandList.Clear();
|
||||||
|
|
||||||
AddCommand("help", "Show help", "help <command>", args =>
|
AddCommand("help", "Show help", "help <command>", args =>
|
||||||
@@ -101,8 +109,10 @@ public class ConsoleCommandsHandler
|
|||||||
|
|
||||||
AddCommand("dwplug", "download plugin", "dwplug [name]", async args =>
|
AddCommand("dwplug", "download plugin", "dwplug [name]", async args =>
|
||||||
{
|
{
|
||||||
|
isDownloading = true;
|
||||||
if (args.Length == 1)
|
if (args.Length == 1)
|
||||||
{
|
{
|
||||||
|
isDownloading = false;
|
||||||
Console.WriteLine("Please specify plugin name");
|
Console.WriteLine("Please specify plugin name");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -116,10 +126,11 @@ public class ConsoleCommandsHandler
|
|||||||
{
|
{
|
||||||
if (name == "")
|
if (name == "")
|
||||||
{
|
{
|
||||||
|
isDownloading = false;
|
||||||
Console_Utilities.WriteColorText("Name is invalid");
|
Console_Utilities.WriteColorText("Name is invalid");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
isDownloading = false;
|
||||||
Console_Utilities.WriteColorText($"Failed to find plugin &b{name} &c!" + " Use &glistplugs &ccommand to display all available plugins !");
|
Console_Utilities.WriteColorText($"Failed to find plugin &b{name} &c!" + " Use &glistplugs &ccommand to display all available plugins !");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -160,9 +171,9 @@ public class ConsoleCommandsHandler
|
|||||||
if (split[0].EndsWith(".zip") || split[0].EndsWith(".pak") || split[0].EndsWith(".pkg"))
|
if (split[0].EndsWith(".zip") || split[0].EndsWith(".pak") || split[0].EndsWith(".pkg"))
|
||||||
{
|
{
|
||||||
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 { 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(() =>
|
||||||
@@ -189,6 +200,12 @@ public class ConsoleCommandsHandler
|
|||||||
|
|
||||||
Console.WriteLine();
|
Console.WriteLine();
|
||||||
}
|
}
|
||||||
|
VersionString? ver = await VersionString.GetVersionOfPackageFromWeb(name);
|
||||||
|
if (ver is null) throw new Exception("Incorrect version");
|
||||||
|
Config.SetPluginVersion(name, $"{ver.PackageID}.{ver.PackageMainVersion}.{ver.PackageCheckVersion}");
|
||||||
|
// Console.WriteLine();
|
||||||
|
|
||||||
|
isDownloading = false;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -209,8 +226,8 @@ public class ConsoleCommandsHandler
|
|||||||
{
|
{
|
||||||
if (args.Length < 4)
|
if (args.Length < 4)
|
||||||
return;
|
return;
|
||||||
var key = args[1];
|
var key = args[1];
|
||||||
var value = args[2];
|
var value = args[2];
|
||||||
var isReadOnly = args[3].Equals("true", StringComparison.CurrentCultureIgnoreCase);
|
var isReadOnly = args[3].Equals("true", StringComparison.CurrentCultureIgnoreCase);
|
||||||
|
|
||||||
try
|
try
|
||||||
@@ -276,6 +293,20 @@ public class ConsoleCommandsHandler
|
|||||||
return commandList.FirstOrDefault(t => t.CommandName == command);
|
return commandList.FirstOrDefault(t => t.CommandName == command);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static async Task ExecuteCommad(string command)
|
||||||
|
{
|
||||||
|
var args = command.Split(' ');
|
||||||
|
foreach (var item in commandList.ToList())
|
||||||
|
if (item.CommandName == args[0])
|
||||||
|
{
|
||||||
|
item.Action.Invoke(args);
|
||||||
|
Console.WriteLine();
|
||||||
|
|
||||||
|
while (isDownloading) await Task.Delay(1000);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public bool HandleCommand(string command, bool removeCommandExecution = true)
|
public bool HandleCommand(string command, bool removeCommandExecution = true)
|
||||||
{
|
{
|
||||||
var args = command.Split(' ');
|
var args = command.Split(' ');
|
||||||
@@ -292,6 +323,7 @@ public class ConsoleCommandsHandler
|
|||||||
|
|
||||||
Console.WriteLine();
|
Console.WriteLine();
|
||||||
item.Action(args);
|
item.Action(args);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,29 +3,32 @@ using System.Collections.Generic;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Reflection;
|
using System.Reflection;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
using PluginManager.Online.Updates;
|
||||||
using PluginManager.Others;
|
using PluginManager.Others;
|
||||||
|
|
||||||
namespace PluginManager.Loaders;
|
namespace PluginManager.Loaders;
|
||||||
|
|
||||||
internal class LoaderArgs : EventArgs
|
internal class LoaderArgs : EventArgs
|
||||||
{
|
{
|
||||||
internal string? PluginName { get; init; }
|
internal string? PluginName { get; init; }
|
||||||
internal string? TypeName { get; init; }
|
internal string? TypeName { get; init; }
|
||||||
internal bool IsLoaded { get; init; }
|
internal bool IsLoaded { get; init; }
|
||||||
internal Exception? Exception { get; init; }
|
internal Exception? Exception { get; init; }
|
||||||
internal object? Plugin { get; init; }
|
internal object? Plugin { get; init; }
|
||||||
}
|
}
|
||||||
|
|
||||||
internal class Loader<T>
|
internal class Loader<T>
|
||||||
{
|
{
|
||||||
internal Loader(string path, string extension)
|
internal Loader(string path, string extension)
|
||||||
{
|
{
|
||||||
this.path = path;
|
this.path = path;
|
||||||
this.extension = extension;
|
this.extension = extension;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private string path { get; }
|
private string path { get; }
|
||||||
private string extension { get; }
|
private string extension { get; }
|
||||||
|
|
||||||
|
|
||||||
@@ -49,16 +52,17 @@ internal class Loader<T>
|
|||||||
var files = Directory.GetFiles(path, $"*.{extension}", SearchOption.AllDirectories);
|
var files = Directory.GetFiles(path, $"*.{extension}", SearchOption.AllDirectories);
|
||||||
foreach (var file in files)
|
foreach (var file in files)
|
||||||
{
|
{
|
||||||
|
|
||||||
Assembly.LoadFrom(file);
|
Assembly.LoadFrom(file);
|
||||||
if (FileLoaded != null)
|
if (FileLoaded != null)
|
||||||
{
|
{
|
||||||
var args = new LoaderArgs
|
var args = new LoaderArgs
|
||||||
{
|
{
|
||||||
Exception = null,
|
Exception = null,
|
||||||
TypeName = nameof(T),
|
TypeName = nameof(T),
|
||||||
IsLoaded = false,
|
IsLoaded = false,
|
||||||
PluginName = file,
|
PluginName = new FileInfo(file).Name.Split('.')[0],
|
||||||
Plugin = null
|
Plugin = null
|
||||||
};
|
};
|
||||||
FileLoaded.Invoke(args);
|
FileLoaded.Invoke(args);
|
||||||
}
|
}
|
||||||
@@ -83,13 +87,13 @@ internal class Loader<T>
|
|||||||
|
|
||||||
if (PluginLoaded != null)
|
if (PluginLoaded != null)
|
||||||
PluginLoaded.Invoke(new LoaderArgs
|
PluginLoaded.Invoke(new LoaderArgs
|
||||||
{
|
{
|
||||||
Exception = null,
|
Exception = null,
|
||||||
IsLoaded = true,
|
IsLoaded = true,
|
||||||
PluginName = type.FullName,
|
PluginName = type.FullName,
|
||||||
TypeName = nameof(T),
|
TypeName = nameof(T),
|
||||||
Plugin = plugin
|
Plugin = plugin
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
|
|||||||
@@ -1,7 +1,14 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
using System.Threading;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
using Discord.WebSocket;
|
using Discord.WebSocket;
|
||||||
|
|
||||||
using PluginManager.Interfaces;
|
using PluginManager.Interfaces;
|
||||||
|
using PluginManager.Online.Updates;
|
||||||
using PluginManager.Others;
|
using PluginManager.Others;
|
||||||
|
|
||||||
namespace PluginManager.Loaders;
|
namespace PluginManager.Loaders;
|
||||||
@@ -15,8 +22,8 @@ public class PluginLoader
|
|||||||
private const string pluginCMDFolder = @"./Data/Plugins/Commands/";
|
private const string pluginCMDFolder = @"./Data/Plugins/Commands/";
|
||||||
private const string pluginEVEFolder = @"./Data/Plugins/Events/";
|
private const string pluginEVEFolder = @"./Data/Plugins/Events/";
|
||||||
|
|
||||||
internal const string pluginCMDExtension = "dll";
|
internal const string pluginCMDExtension = "dll";
|
||||||
internal const string pluginEVEExtension = "dll";
|
internal const string pluginEVEExtension = "dll";
|
||||||
private readonly DiscordSocketClient _client;
|
private readonly DiscordSocketClient _client;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -52,35 +59,58 @@ public class PluginLoader
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The main mathod that is called to load all events
|
/// The main mathod that is called to load all events
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void LoadPlugins()
|
public async void LoadPlugins()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
foreach (var file in Directory.GetFiles("./Data/Plugins", "*.dll", SearchOption.AllDirectories))
|
||||||
|
{
|
||||||
|
await Task.Run(async () =>
|
||||||
|
{
|
||||||
|
string name = new FileInfo(file).Name.Split('.')[0];
|
||||||
|
if (!Config.PluginVersionsContainsKey(name))
|
||||||
|
Config.SetPluginVersion(name, "0.0.0");
|
||||||
|
|
||||||
|
if (await PluginUpdater.CheckForUpdates(name))
|
||||||
|
await PluginUpdater.Download(name);
|
||||||
|
});
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
Commands = new List<DBCommand>();
|
Commands = new List<DBCommand>();
|
||||||
Events = new List<DBEvent>();
|
Events = new List<DBEvent>();
|
||||||
|
|
||||||
Functions.WriteLogFile("Starting plugin loader ... Client: " + _client.CurrentUser.Username);
|
Functions.WriteLogFile("Starting plugin loader ... Client: " + _client.CurrentUser.Username);
|
||||||
Console.WriteLine("Loading plugins");
|
Console.WriteLine("Loading plugins");
|
||||||
|
|
||||||
var commandsLoader = new Loader<DBCommand>(pluginCMDFolder, pluginCMDExtension);
|
var commandsLoader = new Loader<DBCommand>(pluginCMDFolder, pluginCMDExtension);
|
||||||
var eventsLoader = new Loader<DBEvent>(pluginEVEFolder, pluginEVEExtension);
|
var eventsLoader = new Loader<DBEvent>(pluginEVEFolder, pluginEVEExtension);
|
||||||
|
|
||||||
commandsLoader.FileLoaded += OnCommandFileLoaded;
|
commandsLoader.FileLoaded += OnCommandFileLoaded;
|
||||||
commandsLoader.PluginLoaded += OnCommandLoaded;
|
commandsLoader.PluginLoaded += OnCommandLoaded;
|
||||||
|
|
||||||
eventsLoader.FileLoaded += EventFileLoaded;
|
eventsLoader.FileLoaded += EventFileLoaded;
|
||||||
eventsLoader.PluginLoaded += OnEventLoaded;
|
eventsLoader.PluginLoaded += OnEventLoaded;
|
||||||
|
|
||||||
Commands = commandsLoader.Load();
|
Commands = commandsLoader.Load();
|
||||||
Events = eventsLoader.Load();
|
Events = eventsLoader.Load();
|
||||||
|
|
||||||
|
// Console.WriteLine("Press Enter to enable console commands");
|
||||||
}
|
}
|
||||||
|
|
||||||
private void EventFileLoaded(LoaderArgs e)
|
private void EventFileLoaded(LoaderArgs e)
|
||||||
{
|
{
|
||||||
if (e.IsLoaded) Functions.WriteLogFile($"[EVENT] Event from file [{e.PluginName}] has been successfully created !");
|
if (!e.IsLoaded)
|
||||||
|
{
|
||||||
|
Functions.WriteLogFile($"[EVENT] Event from file [{e.PluginName}] has been successfully created !");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnCommandFileLoaded(LoaderArgs e)
|
private void OnCommandFileLoaded(LoaderArgs e)
|
||||||
{
|
{
|
||||||
if (e.IsLoaded) Functions.WriteLogFile($"[CMD] Command from file [{e.PluginName}] has been successfully loaded !");
|
if (!e.IsLoaded)
|
||||||
|
{
|
||||||
|
Functions.WriteLogFile($"[CMD] Command from file [{e.PluginName}] has been successfully loaded !");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnEventLoaded(LoaderArgs e)
|
private void OnEventLoaded(LoaderArgs e)
|
||||||
|
|||||||
77
PluginManager/Online/Helpers/VersionString.cs
Normal file
77
PluginManager/Online/Helpers/VersionString.cs
Normal file
@@ -0,0 +1,77 @@
|
|||||||
|
using PluginManager.Others;
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using System.Linq;
|
||||||
|
|
||||||
|
namespace PluginManager.Online.Helpers
|
||||||
|
{
|
||||||
|
public class VersionString
|
||||||
|
{
|
||||||
|
public int PackageID;
|
||||||
|
public int PackageMainVersion;
|
||||||
|
public int PackageCheckVersion;
|
||||||
|
|
||||||
|
public VersionString(string version)
|
||||||
|
{
|
||||||
|
string[] data = version.Split('.');
|
||||||
|
try
|
||||||
|
{
|
||||||
|
PackageID = int.Parse(data[0]);
|
||||||
|
PackageMainVersion = int.Parse(data[1]);
|
||||||
|
PackageCheckVersion = int.Parse(data[2]);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
throw new Exception("Failed to write Version", ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator >(VersionString s1, VersionString s2)
|
||||||
|
{
|
||||||
|
if (s1.PackageID != s2.PackageID) throw new Exception("Can not compare two different paks");
|
||||||
|
if (s1.PackageMainVersion > s2.PackageMainVersion) return true;
|
||||||
|
if (s1.PackageMainVersion == s2.PackageMainVersion && s1.PackageCheckVersion > s2.PackageCheckVersion) return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator <(VersionString s1, VersionString s2) => !(s1 > s2) && s1 != s2;
|
||||||
|
|
||||||
|
public static bool operator ==(VersionString s1, VersionString s2)
|
||||||
|
{
|
||||||
|
if (s1.PackageID == s2.PackageID && s1.PackageMainVersion == s2.PackageMainVersion && s1.PackageCheckVersion == s2.PackageCheckVersion) return true;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator !=(VersionString s1, VersionString 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 override string ToString()
|
||||||
|
{
|
||||||
|
return "{PackageID: " + PackageID + ", PackageVersion: " + PackageMainVersion + ", PackageCheckVersion: " + PackageCheckVersion + "}";
|
||||||
|
}
|
||||||
|
|
||||||
|
public static VersionString? GetVersionOfPackage(string pakName)
|
||||||
|
{
|
||||||
|
if (!Config.PluginVersionsContainsKey(pakName))
|
||||||
|
return null;
|
||||||
|
return new VersionString(Config.GetPluginVersion(pakName));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task<VersionString?> GetVersionOfPackageFromWeb(string pakName)
|
||||||
|
{
|
||||||
|
string url = "https://raw.githubusercontent.com/Wizzy69/installer/discord-bot-files/Versions";
|
||||||
|
List<string> data = await ServerCom.ReadTextFromURL(url);
|
||||||
|
string? version = (from item in data
|
||||||
|
where !item.StartsWith("#") && item.StartsWith(pakName)
|
||||||
|
select item.Split(',')[1]).FirstOrDefault();
|
||||||
|
if (version == default || version == null) return null;
|
||||||
|
return new VersionString(version);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
50
PluginManager/Online/Updates/PluginUpdater.cs
Normal file
50
PluginManager/Online/Updates/PluginUpdater.cs
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
using PluginManager.Items;
|
||||||
|
using PluginManager.Online.Helpers;
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace PluginManager.Online.Updates
|
||||||
|
{
|
||||||
|
public class PluginUpdater
|
||||||
|
{
|
||||||
|
public static async Task<bool> CheckForUpdates(string pakName)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var webV = await VersionString.GetVersionOfPackageFromWeb(pakName);
|
||||||
|
var local = VersionString.GetVersionOfPackage(pakName);
|
||||||
|
|
||||||
|
if (local is null) return true;
|
||||||
|
if (webV is null) return false;
|
||||||
|
|
||||||
|
if (webV == local) return false;
|
||||||
|
if (webV > local) return true;
|
||||||
|
}
|
||||||
|
catch (Exception ex) { Console.WriteLine(ex.Message); }
|
||||||
|
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task<Update> DownloadUpdateInfo(string pakName)
|
||||||
|
{
|
||||||
|
string url = "https://raw.githubusercontent.com/Wizzy69/installer/discord-bot-files/Versions";
|
||||||
|
List<string> info = await ServerCom.ReadTextFromURL(url);
|
||||||
|
VersionString? version = await VersionString.GetVersionOfPackageFromWeb(pakName);
|
||||||
|
|
||||||
|
if (version is null) return Update.Empty;
|
||||||
|
Update update = new Update(pakName, string.Join('\n', info), version);
|
||||||
|
return update;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async Task Download(string pakName)
|
||||||
|
{
|
||||||
|
Console.WriteLine("An update was found for " + pakName);
|
||||||
|
await ConsoleCommandsHandler.ExecuteCommad("dwplug " + pakName);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
36
PluginManager/Online/Updates/Update.cs
Normal file
36
PluginManager/Online/Updates/Update.cs
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
using PluginManager.Online.Helpers;
|
||||||
|
|
||||||
|
namespace PluginManager.Online.Updates
|
||||||
|
{
|
||||||
|
public class Update
|
||||||
|
{
|
||||||
|
public static Update Empty = new Update(null, null, null);
|
||||||
|
public string pakName;
|
||||||
|
public string UpdateMessage;
|
||||||
|
|
||||||
|
public VersionString newVersion;
|
||||||
|
|
||||||
|
private bool isEmpty;
|
||||||
|
|
||||||
|
public Update(string pakName, string updateMessage, VersionString newVersion)
|
||||||
|
{
|
||||||
|
this.pakName = pakName;
|
||||||
|
UpdateMessage = updateMessage;
|
||||||
|
this.newVersion = newVersion;
|
||||||
|
|
||||||
|
if (pakName is null && updateMessage is null && newVersion is null)
|
||||||
|
isEmpty = true;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
if (isEmpty)
|
||||||
|
throw new System.Exception("The update is EMPTY. Can not print information about an empty update !");
|
||||||
|
return $"Package Name: {this.pakName}\n" +
|
||||||
|
$"Update Message: {UpdateMessage}\n" +
|
||||||
|
$"Version: {newVersion.ToString()}";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -68,7 +68,7 @@ namespace PluginManager.Others
|
|||||||
public static void WriteLogFile(string LogMessage)
|
public static void WriteLogFile(string LogMessage)
|
||||||
{
|
{
|
||||||
string logsPath = logFolder + $"{DateTime.Today.ToShortDateString().Replace("/", "-").Replace("\\", "-")} Log.txt";
|
string logsPath = logFolder + $"{DateTime.Today.ToShortDateString().Replace("/", "-").Replace("\\", "-")} Log.txt";
|
||||||
if (!Directory.Exists(logFolder)) Directory.CreateDirectory(logFolder);
|
Directory.CreateDirectory(logFolder);
|
||||||
File.AppendAllText(logsPath, LogMessage + " \n");
|
File.AppendAllText(logsPath, LogMessage + " \n");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,7 +79,7 @@ namespace PluginManager.Others
|
|||||||
public static void WriteErrFile(string ErrMessage)
|
public static void WriteErrFile(string ErrMessage)
|
||||||
{
|
{
|
||||||
string errPath = errFolder + $"{DateTime.Today.ToShortDateString().Replace("/", "-").Replace("\\", "-")} Error.txt";
|
string errPath = errFolder + $"{DateTime.Today.ToShortDateString().Replace("/", "-").Replace("\\", "-")} Error.txt";
|
||||||
if (!Directory.Exists(errFolder)) Directory.CreateDirectory(errFolder);
|
Directory.CreateDirectory(errFolder);
|
||||||
File.AppendAllText(errPath, ErrMessage + " \n");
|
File.AppendAllText(errPath, ErrMessage + " \n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "EVE_LevelingSystem", "EVE_L
|
|||||||
EndProject
|
EndProject
|
||||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CMD_LevelingSystem", "CMD_LevelingSystem\CMD_LevelingSystem.csproj", "{1A4E49FF-9A0A-4C54-AF35-CFFBA64353D9}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CMD_LevelingSystem", "CMD_LevelingSystem\CMD_LevelingSystem.csproj", "{1A4E49FF-9A0A-4C54-AF35-CFFBA64353D9}"
|
||||||
EndProject
|
EndProject
|
||||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Roles", "Roles\Roles.csproj", "{954F2AA9-6624-4554-946D-0F17B84487C3}"
|
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Roles", "Roles\Roles.csproj", "{954F2AA9-6624-4554-946D-0F17B84487C3}"
|
||||||
EndProject
|
EndProject
|
||||||
Global
|
Global
|
||||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
|||||||
Reference in New Issue
Block a user