Compare commits
116 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 3858156393 | |||
| 6279c5c3a9 | |||
| f58a57c6cd | |||
| d00ebfd7ed | |||
| ab279bd284 | |||
| 89c4932cd7 | |||
| c577f625c2 | |||
| 58624f4037 | |||
| c9249dc71b | |||
| 5e4f1ca35f | |||
| 0d8fdb5904 | |||
| 92a18e3495 | |||
| e929646e8e | |||
| 6315d13d18 | |||
| ee527bb36f | |||
| 86514d1770 | |||
| 9e8ed1e911 | |||
| f3c3c7939c | |||
| 361ed37362 | |||
| ed3128b940 | |||
| 6bbd68a135 | |||
| 06d322b5b3 | |||
| 5497ee9119 | |||
| 0aa78e3560 | |||
| 41ad37b3bb | |||
| 0104d09509 | |||
| b4f5e40f12 | |||
| 7107b17f19 | |||
| 42e1fd917e | |||
| 9e6fcdbe6f | |||
| a24d8aa222 | |||
| 0e5c9ff14b | |||
| f8977d8840 | |||
| bb9768f3a1 | |||
| b3d6930142 | |||
| 5254be44be | |||
| 207e0d6abd | |||
| 968d23380f | |||
| fff9e2e897 | |||
| 3e4e777d8d | |||
| 7f906d400f | |||
| c1161a3bca | |||
| ac512e3a27 | |||
| 730b628fe3 | |||
| 701edc5c6a | |||
| e7688762b8 | |||
| a7a71bf49a | |||
| ac7212ca00 | |||
| 298e557260 | |||
| 7ba791f906 | |||
| 4a6a12baae | |||
| f1dda5da3c | |||
| 3ab96e2d0d | |||
| 970c519a32 | |||
| 188920ec7f | |||
| dcfc4ea32f | |||
| a8c02176d3 | |||
| 1665d47a25 | |||
| 0b2f1e6ab6 | |||
| bcd9245502 | |||
| 59da9b295b | |||
| 99d7d5e7e7 | |||
| e4c60f1606 | |||
| 77f1bef862 | |||
| f16c139362 | |||
| c94cdca6eb | |||
| dcdf80112d | |||
| eb836c5b74 | |||
| de680c6771 | |||
|
|
bcef58a46b | ||
|
|
0dc8cdbce5 | ||
|
|
dbdbaa9802 | ||
|
|
5edcf93371 | ||
|
|
b0be76c62b | ||
| 75a77389a8 | |||
| 0bbced3d58 | |||
| 244209093e | |||
| 54a68d635d | |||
| d7a5cb5a64 | |||
| 6124f89cb0 | |||
| 810a527cc1 | |||
| 0a2dff0c6d | |||
| 382c376c03 | |||
| 84b7d663bc | |||
| 623232b67e | |||
| d5df6cfb9d | |||
| 10b9548c29 | |||
| fa1a136ef1 | |||
| d20cb62139 | |||
| f2418d0395 | |||
| 460a85944a | |||
| 7e2fa02d07 | |||
| 873855937f | |||
| 1cdd2644df | |||
| 532540b74f | |||
| 9ba4ca43e2 | |||
| 8bcaf3f254 | |||
| 0d5c90323a | |||
| 5b01b15216 | |||
| 4f18f505f4 | |||
| 2d3566a01a | |||
| 22f2cd4e59 | |||
| 1683234376 | |||
| 69d99b4189 | |||
| 4a5e0ef2f3 | |||
| 79731a9704 | |||
| bd53d099d1 | |||
| de61f5de88 | |||
| 0527d43dd2 | |||
| e3511cd96b | |||
| d355d3c9b7 | |||
| 5bb13aa4a6 | |||
| 655f5e2ce0 | |||
| 9014d78a7d | |||
| 1c026e7f49 | |||
| d32b3902c9 |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -98,6 +98,7 @@ StyleCopReport.xml
|
||||
*.pidb
|
||||
*.svclog
|
||||
*.scc
|
||||
*.code-workspace
|
||||
|
||||
# Chutzpah Test files
|
||||
_Chutzpah*
|
||||
@@ -370,3 +371,6 @@ FodyWeavers.xsd
|
||||
/DiscordBot.rar
|
||||
/DiscordBot/Data/
|
||||
/DiscordBot/Updater/
|
||||
.idea/
|
||||
DiscordBot/Launcher.exe
|
||||
DiscordBotUI/*
|
||||
|
||||
26
.vscode/launch.json
vendored
Normal file
26
.vscode/launch.json
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
// Use IntelliSense to find out which attributes exist for C# debugging
|
||||
// Use hover for the description of the existing attributes
|
||||
// For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md
|
||||
"name": ".NET Core Launch (console)",
|
||||
"type": "coreclr",
|
||||
"request": "launch",
|
||||
"preLaunchTask": "build",
|
||||
// If you have changed target frameworks, make sure to update the program path.
|
||||
"program": "${workspaceFolder}/DiscordBot/bin/Debug/net6.0/DiscordBot.dll",
|
||||
"args": [],
|
||||
"cwd": "${workspaceFolder}/DiscordBot/bin/Debug/net6.0/",
|
||||
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
|
||||
"console": "externalTerminal",
|
||||
"stopAtEntry": false
|
||||
},
|
||||
{
|
||||
"name": ".NET Core Attach",
|
||||
"type": "coreclr",
|
||||
"request": "attach"
|
||||
}
|
||||
]
|
||||
}
|
||||
41
.vscode/tasks.json
vendored
Normal file
41
.vscode/tasks.json
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
{
|
||||
"version": "2.0.0",
|
||||
"tasks": [
|
||||
{
|
||||
"label": "build",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"build",
|
||||
"${workspaceFolder}/DiscordBot/DiscordBot.csproj",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "publish",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"publish",
|
||||
"${workspaceFolder}/DiscordBot/DiscordBot.csproj",
|
||||
"/property:GenerateFullPaths=true",
|
||||
"/consoleloggerparameters:NoSummary"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
},
|
||||
{
|
||||
"label": "watch",
|
||||
"command": "dotnet",
|
||||
"type": "process",
|
||||
"args": [
|
||||
"watch",
|
||||
"run",
|
||||
"--project",
|
||||
"${workspaceFolder}/DiscordBot/DiscordBot.csproj"
|
||||
],
|
||||
"problemMatcher": "$msCompile"
|
||||
}
|
||||
]
|
||||
}
|
||||
23
DiscordBot/Bot/Actions/Clear.cs
Normal file
23
DiscordBot/Bot/Actions/Clear.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using PluginManager.Interfaces;
|
||||
using PluginManager.Others;
|
||||
|
||||
namespace DiscordBot.Bot.Actions;
|
||||
|
||||
public class Clear : ICommandAction
|
||||
{
|
||||
public string ActionName => "clear";
|
||||
public string Description => "Clears the console";
|
||||
public string Usage => "clear";
|
||||
public InternalActionRunType RunType => InternalActionRunType.ON_CALL;
|
||||
|
||||
public Task Execute(string[] args)
|
||||
{
|
||||
Console.Clear();
|
||||
Console.ForegroundColor = ConsoleColor.Yellow;
|
||||
Console.WriteLine("===== Seth Discord Bot =====");
|
||||
Console.ResetColor();
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
46
DiscordBot/Bot/Actions/Exit.cs
Normal file
46
DiscordBot/Bot/Actions/Exit.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using PluginManager;
|
||||
using PluginManager.Interfaces;
|
||||
using PluginManager.Others;
|
||||
|
||||
namespace DiscordBot.Bot.Actions;
|
||||
|
||||
public class Exit : ICommandAction
|
||||
{
|
||||
public string ActionName => "exit";
|
||||
public string Description => "Exits the bot and saves the config. Use exit help for more info.";
|
||||
public string Usage => "exit [help|force (-f)]";
|
||||
public InternalActionRunType RunType => InternalActionRunType.ON_CALL;
|
||||
|
||||
public async Task Execute(string[] args)
|
||||
{
|
||||
if (args is null || args.Length == 0)
|
||||
{
|
||||
Config.Logger.Log("Exiting...", source: typeof(ICommandAction), type: LogType.WARNING);
|
||||
await Config.AppSettings.SaveToFile();
|
||||
Environment.Exit(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
switch ( args[0] )
|
||||
{
|
||||
case "help":
|
||||
Console.WriteLine("Usage : exit [help|force]");
|
||||
Console.WriteLine("help : Displays this message");
|
||||
Console.WriteLine("force | -f : Exits the bot without saving the config");
|
||||
break;
|
||||
|
||||
case "-f":
|
||||
case "force":
|
||||
Config.Logger.Log("Exiting (FORCE)...", source: typeof(ICommandAction), type: LogType.WARNING);
|
||||
Environment.Exit(0);
|
||||
break;
|
||||
|
||||
default:
|
||||
Console.WriteLine("Invalid argument !");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
204
DiscordBot/Bot/Actions/Extra/PluginMethods.cs
Normal file
204
DiscordBot/Bot/Actions/Extra/PluginMethods.cs
Normal file
@@ -0,0 +1,204 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using DiscordBot.Utilities;
|
||||
using PluginManager;
|
||||
using PluginManager.Interfaces;
|
||||
using PluginManager.Loaders;
|
||||
using PluginManager.Online;
|
||||
using PluginManager.Others;
|
||||
using Spectre.Console;
|
||||
|
||||
namespace DiscordBot.Bot.Actions.Extra;
|
||||
|
||||
internal static class PluginMethods
|
||||
{
|
||||
private static readonly PluginsManager PluginsManager = new();
|
||||
|
||||
internal static async Task List()
|
||||
{
|
||||
var data = await ConsoleUtilities.ExecuteWithProgressBar(PluginsManager.GetAvailablePlugins(), "Loading plugins...");
|
||||
|
||||
TableData tableData = new(new List<string> { "Name", "Description", "Type", "Version" });
|
||||
foreach (var plugin in data) tableData.AddRow(plugin);
|
||||
|
||||
tableData.HasRoundBorders = false;
|
||||
tableData.PrintAsTable();
|
||||
}
|
||||
|
||||
internal static async Task RefreshPlugins(bool quiet)
|
||||
{
|
||||
await Program.internalActionManager.Execute("plugin", "load", quiet ? "-q" : string.Empty);
|
||||
await Program.internalActionManager.Refresh();
|
||||
}
|
||||
|
||||
internal static async Task DownloadPlugin(PluginsManager manager, string pluginName)
|
||||
{
|
||||
var pluginData = await manager.GetPluginLinkByName(pluginName);
|
||||
if (pluginData.Length == 0)
|
||||
{
|
||||
Console.WriteLine($"Plugin {pluginName} not found. Please check the spelling and try again.");
|
||||
return;
|
||||
}
|
||||
|
||||
var pluginType = pluginData[0];
|
||||
var pluginLink = pluginData[1];
|
||||
var pluginRequirements = pluginData[2];
|
||||
|
||||
|
||||
await AnsiConsole.Progress()
|
||||
.Columns(new ProgressColumn[]
|
||||
{
|
||||
new TaskDescriptionColumn(),
|
||||
new ProgressBarColumn(),
|
||||
new PercentageColumn()
|
||||
})
|
||||
.StartAsync(async ctx =>
|
||||
{
|
||||
var downloadTask = ctx.AddTask("Downloading plugin...");
|
||||
|
||||
IProgress<float> progress = new Progress<float>(p => { downloadTask.Value = p; });
|
||||
|
||||
await ServerCom.DownloadFileAsync(pluginLink, $"./Data/{pluginType}s/{pluginName}.dll", progress);
|
||||
|
||||
downloadTask.Increment(100);
|
||||
|
||||
ctx.Refresh();
|
||||
});
|
||||
|
||||
if (pluginRequirements == string.Empty)
|
||||
{
|
||||
Console.WriteLine("Finished installing " + pluginName + " successfully");
|
||||
await RefreshPlugins(false);
|
||||
return;
|
||||
}
|
||||
|
||||
List<string> requirementsUrLs = new();
|
||||
|
||||
await AnsiConsole.Progress()
|
||||
.Columns(new ProgressColumn[]
|
||||
{
|
||||
new TaskDescriptionColumn(),
|
||||
new ProgressBarColumn(),
|
||||
new PercentageColumn()
|
||||
})
|
||||
.StartAsync(async ctx =>
|
||||
{
|
||||
var gatherInformationTask = ctx.AddTask("Gathering info...");
|
||||
gatherInformationTask.IsIndeterminate = true;
|
||||
requirementsUrLs = await ServerCom.ReadTextFromURL(pluginRequirements);
|
||||
await Task.Delay(2000);
|
||||
gatherInformationTask.Increment(100);
|
||||
});
|
||||
|
||||
await AnsiConsole.Progress()
|
||||
.Columns(new ProgressColumn[]
|
||||
{
|
||||
new TaskDescriptionColumn(),
|
||||
new ProgressBarColumn(),
|
||||
new PercentageColumn()
|
||||
})
|
||||
.StartAsync(async ctx =>
|
||||
{
|
||||
List<Tuple<ProgressTask, IProgress<float>, Task>> downloadTasks = new();
|
||||
|
||||
foreach (var info in requirementsUrLs)
|
||||
{
|
||||
if (info.Length < 2) continue;
|
||||
string[] data = info.Split(',');
|
||||
string url = data[0];
|
||||
string fileName = data[1];
|
||||
|
||||
var task = ctx.AddTask($"Downloading {fileName}...");
|
||||
IProgress<float> progress = new Progress<float>(p =>
|
||||
{
|
||||
task.Value = p;
|
||||
});
|
||||
|
||||
var downloadTask = ServerCom.DownloadFileAsync(url, $"./{fileName}", progress);
|
||||
downloadTasks.Add(new Tuple<ProgressTask, IProgress<float>, Task>(task, progress, downloadTask));
|
||||
}
|
||||
|
||||
foreach (var task in downloadTasks)
|
||||
{
|
||||
await task.Item3;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
await RefreshPlugins(false);
|
||||
}
|
||||
|
||||
internal static async Task<bool> LoadPlugins(string[] args)
|
||||
{
|
||||
var loader = new PluginLoader(Config.DiscordBot.client);
|
||||
if (args.Length == 2 && args[1] == "-q")
|
||||
{
|
||||
loader.LoadPlugins();
|
||||
return true;
|
||||
}
|
||||
|
||||
var cc = Console.ForegroundColor;
|
||||
loader.onCMDLoad += (name, typeName, success, exception) =>
|
||||
{
|
||||
if (name == null || name.Length < 2)
|
||||
name = typeName;
|
||||
if (success)
|
||||
{
|
||||
Config.Logger.Log("Successfully loaded command : " + name, source: typeof(ICommandAction),
|
||||
type: LogType.INFO);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
Config.Logger.Log("Failed to load command : " + name + " because " + exception?.Message,
|
||||
source: typeof(ICommandAction), type: LogType.ERROR);
|
||||
}
|
||||
|
||||
Console.ForegroundColor = cc;
|
||||
};
|
||||
loader.onEVELoad += (name, typeName, success, exception) =>
|
||||
{
|
||||
if (name == null || name.Length < 2)
|
||||
name = typeName;
|
||||
|
||||
if (success)
|
||||
{
|
||||
Config.Logger.Log("Successfully loaded event : " + name, source: typeof(ICommandAction),
|
||||
type: LogType.INFO);
|
||||
}
|
||||
else
|
||||
{
|
||||
Config.Logger.Log("Failed to load event : " + name + " because " + exception?.Message,
|
||||
source: typeof(ICommandAction), type: LogType.ERROR);
|
||||
}
|
||||
|
||||
Console.ForegroundColor = cc;
|
||||
};
|
||||
|
||||
loader.onSLSHLoad += (name, typeName, success, exception) =>
|
||||
{
|
||||
if (name == null || name.Length < 2)
|
||||
name = typeName;
|
||||
|
||||
if (success)
|
||||
{
|
||||
Config.Logger.Log("Successfully loaded slash command : " + name, source: typeof(ICommandAction),
|
||||
type: LogType.INFO);
|
||||
}
|
||||
else
|
||||
{
|
||||
Config.Logger.Log("Failed to load slash command : " + name + " because " + exception?.Message,
|
||||
source: typeof(ICommandAction), type: LogType.ERROR);
|
||||
}
|
||||
|
||||
Console.ForegroundColor = cc;
|
||||
};
|
||||
|
||||
loader.LoadPlugins();
|
||||
Console.ForegroundColor = cc;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
43
DiscordBot/Bot/Actions/Extra/SettingsConfigExtra.cs
Normal file
43
DiscordBot/Bot/Actions/Extra/SettingsConfigExtra.cs
Normal file
@@ -0,0 +1,43 @@
|
||||
using System.Linq;
|
||||
using PluginManager;
|
||||
|
||||
namespace DiscordBot.Bot.Actions.Extra;
|
||||
|
||||
internal static class SettingsConfigExtra
|
||||
{
|
||||
internal static void SetSettings(string key, params string[] value)
|
||||
{
|
||||
if (key is null) return;
|
||||
|
||||
if (value is null) return;
|
||||
|
||||
if (!Config.AppSettings.ContainsKey(key))
|
||||
return;
|
||||
|
||||
Config.AppSettings[key] = string.Join(' ', value);
|
||||
// Config.AppSettings.SaveToFile().Wait();
|
||||
}
|
||||
|
||||
internal static void RemoveSettings(string key)
|
||||
{
|
||||
if (key is null) return;
|
||||
|
||||
if(!Config.AppSettings.ContainsKey(key))
|
||||
return;
|
||||
|
||||
Config.AppSettings.Remove(key);
|
||||
}
|
||||
|
||||
internal static void AddSettings(string key, params string[] value)
|
||||
{
|
||||
if (key is null) return;
|
||||
|
||||
if (value is null) return;
|
||||
|
||||
if (Config.AppSettings.ContainsKey(key))
|
||||
return;
|
||||
|
||||
Config.AppSettings.Add(key, string.Join(' ', value));
|
||||
// Config.AppSettings.SaveToFile().Wait();
|
||||
}
|
||||
}
|
||||
62
DiscordBot/Bot/Actions/Help.cs
Normal file
62
DiscordBot/Bot/Actions/Help.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using DiscordBot.Utilities;
|
||||
using PluginManager.Interfaces;
|
||||
using PluginManager.Others;
|
||||
|
||||
namespace DiscordBot.Bot.Actions;
|
||||
|
||||
public class Help : ICommandAction
|
||||
{
|
||||
public string ActionName => "help";
|
||||
|
||||
public string Description => "Shows the list of commands and their usage";
|
||||
|
||||
public string Usage => "help [command]";
|
||||
|
||||
public InternalActionRunType RunType => InternalActionRunType.ON_CALL;
|
||||
|
||||
public async Task Execute(string[] args)
|
||||
{
|
||||
if (args == null || args.Length == 0)
|
||||
{
|
||||
var items = new List<string[]>
|
||||
{
|
||||
new[] { "-", "-", "-" },
|
||||
new[] { "Command", "Usage", "Description" },
|
||||
new[] { "-", "-", "-" }
|
||||
};
|
||||
|
||||
foreach (var a in Program.internalActionManager.Actions)
|
||||
items.Add(new[] { a.Key, a.Value.Usage, a.Value.Description });
|
||||
|
||||
items.Add(new[] { "-", "-", "-" });
|
||||
|
||||
ConsoleUtilities.FormatAndAlignTable(items,
|
||||
TableFormat.CENTER_EACH_COLUMN_BASED
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Program.internalActionManager.Actions.ContainsKey(args[0]))
|
||||
{
|
||||
Console.WriteLine("Command not found");
|
||||
return;
|
||||
}
|
||||
|
||||
var action = Program.internalActionManager.Actions[args[0]];
|
||||
var actionData = new List<string[]>
|
||||
{
|
||||
new[] { "-", "-", "-" },
|
||||
new[] { "Command", "Usage", "Description" },
|
||||
new[] { "-", "-", "-" },
|
||||
new[] { action.ActionName, action.Usage, action.Description },
|
||||
new[] { "-", "-", "-" }
|
||||
};
|
||||
|
||||
ConsoleUtilities.FormatAndAlignTable(actionData,
|
||||
TableFormat.CENTER_EACH_COLUMN_BASED
|
||||
);
|
||||
}
|
||||
}
|
||||
82
DiscordBot/Bot/Actions/Plugin.cs
Normal file
82
DiscordBot/Bot/Actions/Plugin.cs
Normal file
@@ -0,0 +1,82 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Input;
|
||||
using DiscordBot.Bot.Actions.Extra;
|
||||
using PluginManager;
|
||||
using PluginManager.Interfaces;
|
||||
using PluginManager.Loaders;
|
||||
using PluginManager.Online;
|
||||
using PluginManager.Others;
|
||||
using Spectre.Console;
|
||||
|
||||
namespace DiscordBot.Bot.Actions;
|
||||
|
||||
public class Plugin : ICommandAction
|
||||
{
|
||||
private bool pluginsLoaded;
|
||||
public string ActionName => "plugin";
|
||||
public string Description => "Manages plugins. Use plugin help for more info.";
|
||||
public string Usage => "plugin [help|list|load|install|refresh]";
|
||||
public InternalActionRunType RunType => InternalActionRunType.ON_CALL;
|
||||
|
||||
public async Task Execute(string[] args)
|
||||
{
|
||||
if (args is null || args.Length == 0 || args[0] == "help")
|
||||
{
|
||||
Console.WriteLine("Usage : plugin [help|list|load|install]");
|
||||
Console.WriteLine("help : Displays this message");
|
||||
Console.WriteLine("list : Lists all plugins");
|
||||
Console.WriteLine("load : Loads all plugins");
|
||||
Console.WriteLine("install : Installs a plugin");
|
||||
Console.WriteLine("refresh : Refreshes the plugin list");
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
var manager = new PluginsManager();
|
||||
|
||||
switch (args[0])
|
||||
{
|
||||
case "refresh":
|
||||
await PluginMethods.RefreshPlugins(true);
|
||||
break;
|
||||
|
||||
case "list":
|
||||
await PluginMethods.List();
|
||||
break;
|
||||
case "load":
|
||||
if (pluginsLoaded)
|
||||
{
|
||||
Config.Logger.Log("Plugins already loaded", source: typeof(ICommandAction), type: LogType.WARNING);
|
||||
break;
|
||||
}
|
||||
|
||||
if (Config.DiscordBot is null)
|
||||
{
|
||||
Config.Logger.Log("DiscordBot is null", source: typeof(ICommandAction), type: LogType.WARNING);
|
||||
break;
|
||||
}
|
||||
|
||||
pluginsLoaded = await PluginMethods.LoadPlugins(args);
|
||||
break;
|
||||
|
||||
case "install":
|
||||
var pluginName = string.Join(' ', args, 1, args.Length - 1);
|
||||
if (string.IsNullOrEmpty(pluginName) || pluginName.Length < 2)
|
||||
{
|
||||
Console.WriteLine("Please specify a plugin name");
|
||||
Console.Write("Plugin name : ");
|
||||
pluginName = Console.ReadLine();
|
||||
if (string.IsNullOrEmpty(pluginName) || pluginName.Length < 2)
|
||||
{
|
||||
Console.WriteLine("Invalid plugin name");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
await PluginMethods.DownloadPlugin(manager, pluginName);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
67
DiscordBot/Bot/Actions/SettingsConfig.cs
Normal file
67
DiscordBot/Bot/Actions/SettingsConfig.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using DiscordBot.Bot.Actions.Extra;
|
||||
using PluginManager;
|
||||
using PluginManager.Interfaces;
|
||||
using PluginManager.Others;
|
||||
|
||||
namespace DiscordBot.Bot.Actions;
|
||||
|
||||
public class SettingsConfig : ICommandAction
|
||||
{
|
||||
public string ActionName => "config";
|
||||
public string Description => "Change the settings of the bot";
|
||||
public string Usage => "config [options] <setting?> <value?>";
|
||||
public InternalActionRunType RunType => InternalActionRunType.ON_CALL;
|
||||
public Task Execute(string[] args)
|
||||
{
|
||||
if (args is null)
|
||||
{
|
||||
foreach (var settings in Config.AppSettings)
|
||||
Console.WriteLine(settings.Key + ": " + settings.Value);
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
switch (args[0])
|
||||
{
|
||||
case "-s":
|
||||
case "set":
|
||||
if(args.Length < 3)
|
||||
return Task.CompletedTask;
|
||||
SettingsConfigExtra.SetSettings(args[1],args[2..]);
|
||||
break;
|
||||
|
||||
case "-r":
|
||||
case "remove":
|
||||
if(args.Length < 2)
|
||||
return Task.CompletedTask;
|
||||
SettingsConfigExtra.RemoveSettings(args[1]);
|
||||
break;
|
||||
|
||||
case "-a":
|
||||
case "add":
|
||||
if(args.Length < 3)
|
||||
return Task.CompletedTask;
|
||||
SettingsConfigExtra.AddSettings(args[1], args[2..]);
|
||||
break;
|
||||
|
||||
case "-h":
|
||||
case "-help":
|
||||
Console.WriteLine("Options:");
|
||||
Console.WriteLine("-s <settingName> <newValue>: Set a setting");
|
||||
Console.WriteLine("-r <settingName>: Remove a setting");
|
||||
Console.WriteLine("-a <settingName> <newValue>: Add a setting");
|
||||
Console.WriteLine("-h: Show this help message");
|
||||
break;
|
||||
|
||||
default:
|
||||
Console.WriteLine("Invalid option");
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,11 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
|
||||
using PluginManager;
|
||||
using PluginManager.Interfaces;
|
||||
using PluginManager.Loaders;
|
||||
using PluginManager.Others;
|
||||
|
||||
namespace DiscordBot.Discord.Commands;
|
||||
namespace DiscordBot.Bot.Commands;
|
||||
|
||||
/// <summary>
|
||||
/// The help command
|
||||
@@ -41,19 +38,16 @@ internal class Help : DBCommand
|
||||
/// The main body of the command
|
||||
/// </summary>
|
||||
/// <param name="context">The command context</param>
|
||||
public void ExecuteServer(SocketCommandContext context)
|
||||
public void ExecuteServer(DBCommandExecutingArguments args)
|
||||
{
|
||||
var args = Functions.GetArguments(context.Message);
|
||||
if (args.Count != 0)
|
||||
if (args.arguments is not null)
|
||||
{
|
||||
foreach (var item in args)
|
||||
{
|
||||
var e = GenerateHelpCommand(item);
|
||||
var e = GenerateHelpCommand(args.arguments[0]);
|
||||
if (e is null)
|
||||
context.Channel.SendMessageAsync("Unknown Command " + item);
|
||||
args.context.Channel.SendMessageAsync("Unknown Command " + args.arguments[0]);
|
||||
else
|
||||
context.Channel.SendMessageAsync(embed: e.Build());
|
||||
}
|
||||
args.context.Channel.SendMessageAsync(embed: e.Build());
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
@@ -63,25 +57,29 @@ internal class Help : DBCommand
|
||||
var adminCommands = "";
|
||||
var normalCommands = "";
|
||||
|
||||
foreach (var cmd in PluginLoader.Commands!)
|
||||
foreach (var cmd in PluginLoader.Commands)
|
||||
if (cmd.requireAdmin)
|
||||
adminCommands += cmd.Command + " ";
|
||||
else
|
||||
normalCommands += cmd.Command + " ";
|
||||
|
||||
|
||||
if (adminCommands.Length > 0)
|
||||
embedBuilder.AddField("Admin Commands", adminCommands);
|
||||
if (normalCommands.Length > 0)
|
||||
embedBuilder.AddField("Normal Commands", normalCommands);
|
||||
context.Channel.SendMessageAsync(embed: embedBuilder.Build());
|
||||
args.context.Channel.SendMessageAsync(embed: embedBuilder.Build());
|
||||
}
|
||||
|
||||
private EmbedBuilder GenerateHelpCommand(string command)
|
||||
{
|
||||
var embedBuilder = new EmbedBuilder();
|
||||
var cmd = PluginLoader.Commands!.Find(p => p.Command == command ||
|
||||
(p.Aliases is not null && p.Aliases.Contains(command)));
|
||||
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", Config.Variables.GetValue("prefix") + cmd.Usage);
|
||||
embedBuilder.AddField("Usage", Config.AppSettings["prefix"] + cmd.Usage);
|
||||
embedBuilder.AddField("Description", cmd.Description);
|
||||
if (cmd.Aliases is null)
|
||||
return embedBuilder;
|
||||
57
DiscordBot/Bot/Commands/SlashCommands/Help.cs
Normal file
57
DiscordBot/Bot/Commands/SlashCommands/Help.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Discord;
|
||||
using Discord.WebSocket;
|
||||
using PluginManager.Interfaces;
|
||||
using PluginManager.Loaders;
|
||||
using PluginManager.Others;
|
||||
|
||||
namespace DiscordBot.Bot.Commands.SlashCommands;
|
||||
|
||||
public class Help : DBSlashCommand
|
||||
{
|
||||
public string Name => "help";
|
||||
public string Description => "This command allows you to check all loaded commands";
|
||||
public bool canUseDM => true;
|
||||
|
||||
public List<SlashCommandOptionBuilder> Options =>
|
||||
new()
|
||||
{
|
||||
new SlashCommandOptionBuilder()
|
||||
.WithName("command")
|
||||
.WithDescription("The command you want to get help for")
|
||||
.WithRequired(false)
|
||||
.WithType(ApplicationCommandOptionType.String)
|
||||
};
|
||||
|
||||
public async void ExecuteServer(SocketSlashCommand context)
|
||||
{
|
||||
EmbedBuilder embedBuilder = new();
|
||||
|
||||
embedBuilder.WithTitle("Help Command");
|
||||
embedBuilder.WithColor(Functions.RandomColor);
|
||||
var slashCommands = PluginLoader.SlashCommands;
|
||||
var options = context.Data.Options;
|
||||
|
||||
//Console.WriteLine("Options: " + options.Count);
|
||||
if (options is null || options.Count == 0)
|
||||
foreach (var slashCommand in slashCommands)
|
||||
embedBuilder.AddField(slashCommand.Name, slashCommand.Description);
|
||||
|
||||
if (options.Count > 0)
|
||||
{
|
||||
var commandName = options.First().Name;
|
||||
var slashCommand = slashCommands.FirstOrDefault(x => x.Name == commandName);
|
||||
if (slashCommand is null)
|
||||
{
|
||||
await context.RespondAsync("Unknown Command " + commandName);
|
||||
return;
|
||||
}
|
||||
|
||||
embedBuilder.AddField(slashCommand.Name, slashCommand.canUseDM)
|
||||
.WithDescription(slashCommand.Description);
|
||||
}
|
||||
|
||||
await context.RespondAsync(embed: embedBuilder.Build());
|
||||
}
|
||||
}
|
||||
@@ -1,100 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using PluginManager.Interfaces;
|
||||
using PluginManager.Others;
|
||||
using DiscordLibCommands = Discord.Commands;
|
||||
using DiscordLib = Discord;
|
||||
using OperatingSystem = PluginManager.Others.OperatingSystem;
|
||||
|
||||
namespace DiscordBot.Discord.Commands;
|
||||
|
||||
internal class Restart : DBCommand
|
||||
{
|
||||
/// <summary>
|
||||
/// Command name
|
||||
/// </summary>
|
||||
public string Command => "restart";
|
||||
|
||||
public List<string> Aliases => null;
|
||||
|
||||
/// <summary>
|
||||
/// Command Description
|
||||
/// </summary>
|
||||
public string Description => "Restart the bot";
|
||||
|
||||
/// <summary>
|
||||
/// Command usage
|
||||
/// </summary>
|
||||
public string Usage => "restart [-p | -c | -args | -cmd] <args>";
|
||||
|
||||
/// <summary>
|
||||
/// Check if the command require administrator to be executed
|
||||
/// </summary>
|
||||
public bool requireAdmin => true;
|
||||
|
||||
/// <summary>
|
||||
/// The main body of the command
|
||||
/// </summary>
|
||||
/// <param name="context">The command context</param>
|
||||
public async void ExecuteServer(DiscordLibCommands.SocketCommandContext context)
|
||||
{
|
||||
var args = Functions.GetArguments(context.Message);
|
||||
var OS = Functions.GetOperatingSystem();
|
||||
if (args.Count == 0)
|
||||
{
|
||||
switch (OS)
|
||||
{
|
||||
case OperatingSystem.WINDOWS:
|
||||
Process.Start("./DiscordBot.exe");
|
||||
break;
|
||||
case OperatingSystem.LINUX:
|
||||
case OperatingSystem.MAC_OS:
|
||||
Process.Start("./DiscordBot");
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
switch (args[0])
|
||||
{
|
||||
case "-p":
|
||||
case "-poweroff":
|
||||
case "-c":
|
||||
case "-close":
|
||||
Environment.Exit(0);
|
||||
break;
|
||||
case "-cmd":
|
||||
case "-args":
|
||||
var cmd = "--args";
|
||||
|
||||
if (args.Count > 1)
|
||||
for (var i = 1; i < args.Count; i++)
|
||||
cmd += $" {args[i]}";
|
||||
|
||||
|
||||
switch (OS)
|
||||
{
|
||||
case OperatingSystem.WINDOWS:
|
||||
Functions.WriteLogFile("Restarting the bot with the following arguments: \"" + cmd + "\"");
|
||||
Process.Start("./DiscordBot.exe", cmd);
|
||||
break;
|
||||
case OperatingSystem.LINUX:
|
||||
//case PluginManager.Others.OperatingSystem.MAC_OS: ?? - not tested
|
||||
Process.Start("./DiscordBot", cmd);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
Environment.Exit(0);
|
||||
break;
|
||||
default:
|
||||
await context.Channel.SendMessageAsync("Invalid argument. Use `help restart` to see the usage.");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,126 +0,0 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Discord.Commands;
|
||||
using Discord.WebSocket;
|
||||
|
||||
using PluginManager.Loaders;
|
||||
using PluginManager.Others;
|
||||
using PluginManager.Others.Permissions;
|
||||
|
||||
namespace DiscordBot.Discord.Core;
|
||||
|
||||
internal class CommandHandler
|
||||
{
|
||||
private readonly string botPrefix;
|
||||
private readonly DiscordSocketClient client;
|
||||
private readonly CommandService commandService;
|
||||
|
||||
/// <summary>
|
||||
/// Command handler constructor
|
||||
/// </summary>
|
||||
/// <param name="client">The discord bot client</param>
|
||||
/// <param name="commandService">The discord bot command service</param>
|
||||
/// <param name="botPrefix">The prefix to watch for</param>
|
||||
public CommandHandler(DiscordSocketClient client, CommandService commandService, string botPrefix)
|
||||
{
|
||||
this.client = client;
|
||||
this.commandService = commandService;
|
||||
this.botPrefix = botPrefix;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The method to initialize all commands
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task InstallCommandsAsync()
|
||||
{
|
||||
client.MessageReceived += MessageHandler;
|
||||
client.SlashCommandExecuted += Client_SlashCommandExecuted;
|
||||
await commandService.AddModulesAsync(Assembly.GetEntryAssembly(), null);
|
||||
}
|
||||
|
||||
private async Task Client_SlashCommandExecuted(SocketSlashCommand arg)
|
||||
{
|
||||
try
|
||||
{
|
||||
var plugin = PluginLoader.SlashCommands!
|
||||
.Where(p => p.Name == arg.Data.Name)
|
||||
.FirstOrDefault();
|
||||
|
||||
if (plugin is null) throw new Exception("Failed to run command. !");
|
||||
|
||||
|
||||
if (arg.Channel is SocketDMChannel)
|
||||
plugin.ExecuteDM(arg);
|
||||
else plugin.ExecuteServer(arg);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Console.WriteLine(ex.ToString());
|
||||
ex.WriteErrFile();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The message handler for the bot
|
||||
/// </summary>
|
||||
/// <param name="Message">The message got from the user in discord chat</param>
|
||||
/// <returns></returns>
|
||||
private async Task MessageHandler(SocketMessage Message)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (Message as SocketUserMessage == null)
|
||||
return;
|
||||
|
||||
var message = Message as SocketUserMessage;
|
||||
|
||||
if (message == null)
|
||||
return;
|
||||
|
||||
if (!message.Content.StartsWith(botPrefix))
|
||||
return;
|
||||
|
||||
var argPos = 0;
|
||||
|
||||
if (message.HasMentionPrefix(client.CurrentUser, ref argPos))
|
||||
{
|
||||
await message.Channel.SendMessageAsync("Can not exec mentioned commands !");
|
||||
return;
|
||||
}
|
||||
|
||||
if (message.Author.IsBot)
|
||||
return;
|
||||
|
||||
var context = new SocketCommandContext(client, message);
|
||||
|
||||
await commandService.ExecuteAsync(context, argPos, null);
|
||||
|
||||
var plugin = PluginLoader.Commands!
|
||||
.Where(
|
||||
p => p.Command == message.Content.Split(' ')[0].Substring(botPrefix.Length) ||
|
||||
(p.Aliases is not null &&
|
||||
p.Aliases.Contains(
|
||||
message.Content.Split(' ')[0].Substring(botPrefix.Length))))
|
||||
.FirstOrDefault();
|
||||
|
||||
if (plugin is null) throw new Exception("Failed to run command. !");
|
||||
|
||||
if (plugin.requireAdmin && !context.Message.Author.isAdmin())
|
||||
return;
|
||||
|
||||
if (context.Channel is SocketDMChannel)
|
||||
plugin.ExecuteDM(context);
|
||||
else plugin.ExecuteServer(context);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
ex.WriteErrFile();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<Nullable>disable</Nullable>
|
||||
<ApplicationIcon />
|
||||
<StartupObject />
|
||||
<SignAssembly>False</SignAssembly>
|
||||
<IsPublishable>True</IsPublishable>
|
||||
<AssemblyVersion>1.0.1.0</AssemblyVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<DebugType>none</DebugType>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
||||
<DebugType>none</DebugType>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Remove="Data\**" />
|
||||
<Compile Remove="obj\**" />
|
||||
<Compile Remove="Output\**" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Remove="Data\**" />
|
||||
<EmbeddedResource Remove="obj\**" />
|
||||
<EmbeddedResource Remove="Output\**" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="Data\**" />
|
||||
<None Remove="obj\**" />
|
||||
<None Remove="Output\**" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Discord.Net" Version="3.7.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\PluginManager\PluginManager.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
|
||||
<Exec Command="xcopy /B /Y "$(TargetDir)*.dll" "$(TargetDir)Libraries"" />
|
||||
</Target>
|
||||
|
||||
</Project>
|
||||
@@ -1,5 +1,4 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
@@ -8,41 +7,37 @@
|
||||
<StartupObject/>
|
||||
<SignAssembly>False</SignAssembly>
|
||||
<IsPublishable>True</IsPublishable>
|
||||
<AssemblyVersion>1.0.1.0</AssemblyVersion>
|
||||
<AssemblyVersion>1.0.3.1</AssemblyVersion>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<DebugType>none</DebugType>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|AnyCPU'">
|
||||
<DebugType>none</DebugType>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Compile Remove="Data\**"/>
|
||||
<Compile Remove="obj\**"/>
|
||||
<Compile Remove="Output\**"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Remove="Data\**"/>
|
||||
<EmbeddedResource Remove="obj\**"/>
|
||||
<EmbeddedResource Remove="Output\**"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="Data\**"/>
|
||||
<None Remove="obj\**"/>
|
||||
<None Remove="Output\**"/>
|
||||
<None Remove="builder.bat" />
|
||||
<None Remove="builder.sh" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Discord.Net" Version="3.7.2" />
|
||||
<PackageReference Include="Discord.Net" Version="3.11.0"/>
|
||||
<PackageReference Include="pythonnet" Version="3.0.1" />
|
||||
<PackageReference Include="Spectre.Console" Version="0.47.0" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\PluginManager\PluginManager.csproj"/>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -2,28 +2,37 @@
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
|
||||
namespace DiscordBot
|
||||
{
|
||||
namespace DiscordBot;
|
||||
|
||||
public class Entry
|
||||
public static class Entry
|
||||
{
|
||||
[STAThread]
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
AppDomain currentDomain = AppDomain.CurrentDomain;
|
||||
currentDomain.AssemblyResolve += new ResolveEventHandler(LoadFromSameFolder);
|
||||
#if DEBUG
|
||||
if (args.Length == 1 && args[0] == "/purge_plugins")
|
||||
{
|
||||
foreach (var plugin in Directory.GetFiles("./Data/Plugins", "*.dll", SearchOption.AllDirectories))
|
||||
{
|
||||
File.Delete(plugin);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
var currentDomain = AppDomain.CurrentDomain;
|
||||
currentDomain.AssemblyResolve += LoadFromSameFolder;
|
||||
|
||||
static Assembly LoadFromSameFolder(object sender, ResolveEventArgs args)
|
||||
{
|
||||
string folderPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "./Libraries");
|
||||
string assemblyPath = Path.Combine(folderPath, new AssemblyName(args.Name).Name + ".dll");
|
||||
var folderPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "./Libraries");
|
||||
var assemblyPath = Path.Combine(folderPath, new AssemblyName(args.Name).Name + ".dll");
|
||||
if (!File.Exists(assemblyPath)) return null;
|
||||
Assembly assembly = Assembly.LoadFrom(assemblyPath);
|
||||
var assembly = Assembly.LoadFrom(assemblyPath);
|
||||
|
||||
return assembly;
|
||||
}
|
||||
|
||||
Program.Startup(args);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
28
DiscordBot/Installer.cs
Normal file
28
DiscordBot/Installer.cs
Normal file
@@ -0,0 +1,28 @@
|
||||
using PluginManager;
|
||||
using Spectre.Console;
|
||||
|
||||
namespace DiscordBot;
|
||||
|
||||
public static class Installer
|
||||
{
|
||||
public static void GenerateStartupConfig()
|
||||
{
|
||||
AnsiConsole.MarkupLine("Welcome to the [bold]SethBot[/] installer !");
|
||||
AnsiConsole.MarkupLine("First, we need to configure the bot. Don't worry, it will be quick !");
|
||||
|
||||
var token = AnsiConsole.Ask<string>("Please enter the bot [yellow]token[/]:");
|
||||
var prefix = AnsiConsole.Ask<string>("Please enter the bot [yellow]prefix[/]:");
|
||||
var serverId = AnsiConsole.Ask<string>("Please enter the [yellow]Server ID[/]:");
|
||||
|
||||
if (string.IsNullOrWhiteSpace(serverId)) serverId = "NULL";
|
||||
Config.AppSettings.Add("token", token);
|
||||
Config.AppSettings.Add("prefix", prefix);
|
||||
Config.AppSettings.Add("ServerID", serverId);
|
||||
|
||||
Config.AppSettings.SaveToFile();
|
||||
|
||||
AnsiConsole.MarkupLine("[bold]Config saved ![/]");
|
||||
|
||||
Config.Logger.Log("Config Saved", source: typeof(Installer));
|
||||
}
|
||||
}
|
||||
@@ -1,191 +1,32 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using DiscordBot.Discord.Core;
|
||||
|
||||
using PluginManager;
|
||||
using PluginManager.Database;
|
||||
using PluginManager.Items;
|
||||
using PluginManager.Online;
|
||||
using PluginManager.Online.Helpers;
|
||||
using DiscordBot.Utilities;
|
||||
using PluginManager.Bot;
|
||||
using PluginManager.Others;
|
||||
|
||||
using Terminal.Gui;
|
||||
|
||||
using OperatingSystem = PluginManager.Others.OperatingSystem;
|
||||
using PluginManager.Others.Actions;
|
||||
using Spectre.Console;
|
||||
using static PluginManager.Config;
|
||||
|
||||
namespace DiscordBot;
|
||||
|
||||
public class Program
|
||||
{
|
||||
private static bool loadPluginsOnStartup;
|
||||
private static bool listPluginsAtStartup;
|
||||
private static ConsoleCommandsHandler consoleCommandsHandler;
|
||||
public static InternalActionManager internalActionManager;
|
||||
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
[STAThread]
|
||||
public static void Startup(string[] args)
|
||||
{
|
||||
PreLoadComponents(args).Wait();
|
||||
|
||||
PreLoadComponents().Wait();
|
||||
if (!AppSettings.ContainsKey("ServerID") || !AppSettings.ContainsKey("token") || !AppSettings.ContainsKey("prefix"))
|
||||
Installer.GenerateStartupConfig();
|
||||
|
||||
if (!Config.Variables.Exists("ServerID") || !Config.Variables.Exists("token") ||
|
||||
Config.Variables.GetValue("token") == null ||
|
||||
(Config.Variables.GetValue("token")?.Length != 70 && Config.Variables.GetValue("token")?.Length != 59) ||
|
||||
!Config.Variables.Exists("prefix") || Config.Variables.GetValue("prefix") == null ||
|
||||
Config.Variables.GetValue("prefix")?.Length != 1 ||
|
||||
(args.Length == 1 && args[0] == "/reset"))
|
||||
{
|
||||
Application.Init();
|
||||
var top = Application.Top;
|
||||
var win = new Window("Discord Bot Config - " + Assembly.GetExecutingAssembly().GetName().Version)
|
||||
{
|
||||
X = 0,
|
||||
Y = 1,
|
||||
Width = Dim.Fill(),
|
||||
Height = Dim.Fill()
|
||||
};
|
||||
|
||||
top.Add(win);
|
||||
|
||||
var labelInfo = new Label(
|
||||
"Configuration file not found or invalid. " +
|
||||
"Please fill the following fields to create a new configuration file."
|
||||
)
|
||||
{
|
||||
X = Pos.Center(),
|
||||
Y = 2
|
||||
};
|
||||
|
||||
|
||||
var labelToken = new Label("Please insert your token here: ")
|
||||
{
|
||||
X = 5,
|
||||
Y = 5
|
||||
};
|
||||
|
||||
var textFiledToken = new TextField("")
|
||||
{
|
||||
X = Pos.Left(labelToken) + labelToken.Text.Length + 2,
|
||||
Y = labelToken.Y,
|
||||
Width = 70
|
||||
};
|
||||
|
||||
var labelPrefix = new Label("Please insert your prefix here: ")
|
||||
{
|
||||
X = 5,
|
||||
Y = 8
|
||||
};
|
||||
var textFiledPrefix = new TextField("")
|
||||
{
|
||||
X = Pos.Left(labelPrefix) + labelPrefix.Text.Length + 2,
|
||||
Y = labelPrefix.Y,
|
||||
Width = 1
|
||||
};
|
||||
|
||||
var labelServerid = new Label("Please insert your server id here (optional): ")
|
||||
{
|
||||
X = 5,
|
||||
Y = 11
|
||||
};
|
||||
var textFiledServerID = new TextField("")
|
||||
{
|
||||
X = Pos.Left(labelServerid) + labelServerid.Text.Length + 2,
|
||||
Y = labelServerid.Y,
|
||||
Width = 18
|
||||
};
|
||||
|
||||
var button = new Button("Submit")
|
||||
{
|
||||
X = Pos.Center() - 10,
|
||||
Y = 16
|
||||
};
|
||||
|
||||
var button2 = new Button("License")
|
||||
{
|
||||
X = Pos.Center() + 10,
|
||||
Y = 16
|
||||
};
|
||||
|
||||
var button3 = new Button("ⓘ")
|
||||
{
|
||||
X = Pos.Left(textFiledServerID) + 20,
|
||||
Y = textFiledServerID.Y
|
||||
};
|
||||
|
||||
Console.CancelKeyPress += (sender, e) => { top.Running = false; };
|
||||
|
||||
button.Clicked += () =>
|
||||
{
|
||||
var passMessage = "";
|
||||
if (textFiledToken.Text.Length != 70 && textFiledToken.Text.Length != 59)
|
||||
passMessage += "Invalid token, ";
|
||||
if (textFiledPrefix.Text.ContainsAny("0123456789/\\ ") || textFiledPrefix.Text.Length != 1)
|
||||
passMessage += "Invalid prefix, ";
|
||||
if (textFiledServerID.Text.Length != 18 && textFiledServerID.Text.Length > 0)
|
||||
passMessage += "Invalid serverID";
|
||||
|
||||
if (passMessage != "")
|
||||
{
|
||||
MessageBox.ErrorQuery("Discord Bot Settings",
|
||||
"Failed to pass check. Invalid information given:\n" + passMessage, "Retry");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Config.Variables.Add("ServerID", (string)textFiledServerID.Text, true);
|
||||
Config.Variables.Add("token", (string)textFiledToken.Text, true);
|
||||
Config.Variables.Add("prefix", (string)textFiledPrefix.Text, true);
|
||||
|
||||
MessageBox.Query("Discord Bot Settings", "Successfully saved config !\nJust start the bot :D",
|
||||
"Start :D");
|
||||
top.Running = false;
|
||||
};
|
||||
|
||||
button2.Clicked += async () =>
|
||||
{
|
||||
var license =
|
||||
await ServerCom.ReadTextFromURL(
|
||||
"https://raw.githubusercontent.com/Wizzy69/installer/discord-bot-files/LICENSE.txt");
|
||||
var ProductLicense =
|
||||
"Seth Discord Bot\n\nDeveloped by Wizzy#9181\nThis application can be used and modified by anyone. Plugin development for this application is also free and supported";
|
||||
var r = MessageBox.Query("Discord Bot Settings", ProductLicense, "Close", "Read about libraries used");
|
||||
if (r == 1)
|
||||
{
|
||||
var i = 0;
|
||||
while (i < license.Count)
|
||||
{
|
||||
var print_message = license[i++] + "\n";
|
||||
for (; i < license.Count && !license[i].StartsWith("-----------"); i++)
|
||||
print_message += license[i] + "\n";
|
||||
if (print_message.Contains("https://"))
|
||||
print_message += "\n\nCTRL + Click on a link to open it";
|
||||
if (MessageBox.Query("Licenses", print_message, "Next", "Quit") == 1) break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
button3.Clicked += () =>
|
||||
{
|
||||
MessageBox.Query("Discord Bot Settings",
|
||||
"Server ID can be found in Server settings => Widget => Server ID",
|
||||
"Close");
|
||||
};
|
||||
|
||||
win.Add(labelInfo, labelPrefix, labelServerid, labelToken);
|
||||
win.Add(textFiledToken, textFiledPrefix, textFiledServerID, button3);
|
||||
win.Add(button, button2);
|
||||
Application.Run();
|
||||
Application.Shutdown();
|
||||
}
|
||||
|
||||
HandleInput(args).Wait();
|
||||
HandleInput().Wait();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -193,24 +34,21 @@ public class Program
|
||||
/// </summary>
|
||||
private static void NoGUI()
|
||||
{
|
||||
#if DEBUG
|
||||
Settings.Variables.outputStream.WriteLine();
|
||||
ConsoleCommandsHandler.ExecuteCommad("lp").Wait();
|
||||
#else
|
||||
if (loadPluginsOnStartup) consoleCommandsHandler.HandleCommand("lp");
|
||||
if (listPluginsAtStartup) consoleCommandsHandler.HandleCommand("listplugs");
|
||||
#endif
|
||||
internalActionManager.Initialize().Wait();
|
||||
internalActionManager.Execute("plugin", "load").Wait();
|
||||
internalActionManager.Refresh().Wait();
|
||||
|
||||
|
||||
while (true)
|
||||
{
|
||||
var cmd = Console.ReadLine();
|
||||
if (!consoleCommandsHandler.HandleCommand(cmd!
|
||||
#if DEBUG
|
||||
, false
|
||||
#endif
|
||||
var args = cmd.Split(' ');
|
||||
var command = args[0];
|
||||
args = args.Skip(1).ToArray();
|
||||
if (args.Length == 0)
|
||||
args = null;
|
||||
|
||||
) && cmd.Length > 0)
|
||||
Settings.Variables.outputStream.WriteLine("Failed to run command " + cmd);
|
||||
internalActionManager.Execute(command, args).Wait(); // Execute the command
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,56 +56,31 @@ public class Program
|
||||
/// Start the bot without user interface
|
||||
/// </summary>
|
||||
/// <returns>Returns the boot loader for the Discord Bot</returns>
|
||||
private static async Task<Boot> StartNoGui()
|
||||
private static async Task StartNoGui()
|
||||
{
|
||||
Console.Clear();
|
||||
Console.ForegroundColor = ConsoleColor.DarkYellow;
|
||||
|
||||
var startupMessageList =
|
||||
await ServerCom.ReadTextFromURL(
|
||||
"https://raw.githubusercontent.com/Wizzy69/installer/discord-bot-files/StartupMessage");
|
||||
Console.WriteLine($"Running on version: {Assembly.GetExecutingAssembly().GetName().Version}");
|
||||
Console.WriteLine("Git SethBot: https://github.com/andreitdr/SethDiscordBot");
|
||||
Console.WriteLine("Git Plugins: https://github.com/andreitdr/SethPlugins");
|
||||
|
||||
foreach (var message in startupMessageList)
|
||||
Settings.Variables.outputStream.WriteLine(message);
|
||||
ConsoleUtilities.WriteColorText("&rRemember to close the bot using the ShutDown command (&yexit&r) or some settings won't be saved");
|
||||
|
||||
Settings.Variables.outputStream.WriteLine(
|
||||
$"Running on version: {Assembly.GetExecutingAssembly().GetName().Version}");
|
||||
Settings.Variables.outputStream.WriteLine($"Git URL: {Settings.Variables.WebsiteURL}");
|
||||
ConsoleUtilities.WriteColorText($"Running on &m{Functions.GetOperatingSystem()}");
|
||||
Console.WriteLine("============================ LOG ============================");
|
||||
|
||||
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;
|
||||
|
||||
if (Config.Variables.Exists("LaunchMessage"))
|
||||
Utilities.WriteColorText(Config.Variables.GetValue("LaunchMessage"));
|
||||
|
||||
|
||||
Utilities.WriteColorText(
|
||||
"Please note that the bot saves a backup save file every time you are using the shudown command (&ysd&c)");
|
||||
Settings.Variables.outputStream.WriteLine("============================ LOG ============================");
|
||||
|
||||
try
|
||||
{
|
||||
string token = "";
|
||||
#if DEBUG
|
||||
|
||||
if (await Settings.sqlDatabase.TableExistsAsync("BetaTest"))
|
||||
{
|
||||
Settings.Variables.outputStream.WriteLine("Starting in DEBUG MODE");
|
||||
token = await Settings.sqlDatabase.GetValueAsync("BetaTest", "VariableName", "Token", "Value");
|
||||
}
|
||||
#else
|
||||
token = Config.Variables.GetValue("token");
|
||||
#endif
|
||||
var prefix = Config.Variables.GetValue("prefix");
|
||||
var token = AppSettings["token"];
|
||||
var prefix = AppSettings["prefix"];
|
||||
var discordbooter = new Boot(token, prefix);
|
||||
await discordbooter.Awake();
|
||||
return discordbooter;
|
||||
}
|
||||
catch ( Exception ex )
|
||||
{
|
||||
Settings.Variables.outputStream.WriteLine(ex);
|
||||
return null;
|
||||
Logger.Log(ex.ToString(), source: typeof(Program), type: LogType.CRITICAL);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -275,167 +88,55 @@ public class Program
|
||||
/// Handle user input arguments from the startup of the application
|
||||
/// </summary>
|
||||
/// <param name="args">The arguments</param>
|
||||
private static async Task HandleInput(string[] args)
|
||||
{
|
||||
var len = args.Length;
|
||||
|
||||
var b = await StartNoGui();
|
||||
consoleCommandsHandler = new ConsoleCommandsHandler(b.client);
|
||||
|
||||
if (len > 0 && args[0] == "/remplug")
|
||||
{
|
||||
var plugName = string.Join(' ', args, 1, args.Length - 1);
|
||||
Settings.Variables.outputStream.WriteLine("Starting to remove " + plugName);
|
||||
await ConsoleCommandsHandler.ExecuteCommad("remplug " + plugName);
|
||||
loadPluginsOnStartup = true;
|
||||
}
|
||||
|
||||
if (len > 0 && args[0] == "/lp")
|
||||
loadPluginsOnStartup = true;
|
||||
|
||||
var mainThread = new Thread(() =>
|
||||
private static async Task HandleInput()
|
||||
{
|
||||
await StartNoGui();
|
||||
try
|
||||
{
|
||||
internalActionManager = new InternalActionManager("./Data/Plugins", "*.dll");
|
||||
NoGUI();
|
||||
}
|
||||
catch ( IOException ex )
|
||||
{
|
||||
if (ex.Message == "No process is on the other end of the pipe." || (uint)ex.HResult == 0x800700E9)
|
||||
{
|
||||
if (Config.Variables.Exists("LaunchMessage"))
|
||||
Config.Variables.Add("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());
|
||||
if (AppSettings.ContainsKey("LaunchMessage"))
|
||||
AppSettings.Add("LaunchMessage",
|
||||
"An error occured while closing the bot last time. Please consider closing the bot using the &rexit&c method !\n" +
|
||||
"There is a risk of losing all data or corruption of the save file, which in some cases requires to reinstall the bot !");
|
||||
|
||||
Logger.Log("An error occured while closing the bot last time. Please consider closing the bot using the &rexit&c method !\n" +
|
||||
"There is a risk of losing all data or corruption of the save file, which in some cases requires to reinstall the bot !",
|
||||
source: typeof(Program), type: LogType.ERROR);
|
||||
}
|
||||
}
|
||||
});
|
||||
mainThread.Start();
|
||||
}
|
||||
|
||||
private static async Task PreLoadComponents()
|
||||
private static async Task PreLoadComponents(string[] args)
|
||||
{
|
||||
Settings.Variables.outputStream = Console.Out;
|
||||
Settings.Variables.outputStream.WriteLine("Loading resources ...");
|
||||
var main = new Utilities.ProgressBar(ProgressBarType.NO_END);
|
||||
main.Start();
|
||||
Directory.CreateDirectory("./Data/Resources");
|
||||
Directory.CreateDirectory("./Data/Plugins");
|
||||
Directory.CreateDirectory("./Data/PAKS");
|
||||
await Initialize();
|
||||
|
||||
Settings.sqlDatabase = new SqlDatabase(Functions.dataFolder + "SetDB.dat");
|
||||
|
||||
await Settings.sqlDatabase.Open();
|
||||
await Config.Initialize();
|
||||
|
||||
|
||||
|
||||
if (await Config.Variables.ExistsAsync("DeleteLogsAtStartup"))
|
||||
if (await Config.Variables.GetValueAsync("DeleteLogsAtStartup") == "true")
|
||||
foreach (var file in Directory.GetFiles("./Output/Logs/"))
|
||||
File.Delete(file);
|
||||
var OnlineDefaultKeys =
|
||||
await ServerCom.ReadTextFromURL(
|
||||
"https://raw.githubusercontent.com/Wizzy69/installer/discord-bot-files/SetupKeys");
|
||||
|
||||
|
||||
if (!await Config.Variables.ExistsAsync("Version"))
|
||||
await Config.Variables.AddAsync("Version", Assembly.GetExecutingAssembly().GetName().Version.ToString(), false);
|
||||
else
|
||||
await Config.Variables.SetValueAsync("Version", Assembly.GetExecutingAssembly().GetName().Version.ToString());
|
||||
|
||||
|
||||
foreach (var key in OnlineDefaultKeys)
|
||||
Logger.OnLog += (sender, logMessage) =>
|
||||
{
|
||||
if (key.Length <= 3 || !key.Contains(' ')) continue;
|
||||
var s = key.Split(' ');
|
||||
try
|
||||
string messageColor = logMessage.Type switch
|
||||
{
|
||||
if (await Config.Variables.ExistsAsync(s[0])) await Config.Variables.SetValueAsync(s[0], s[1]);
|
||||
else
|
||||
await Config.Variables.AddAsync(s[0], s[1], s[2].ToLower() == "true");
|
||||
}
|
||||
catch (Exception ex)
|
||||
LogType.INFO => "[green]",
|
||||
LogType.WARNING => "[yellow]",
|
||||
LogType.ERROR => "[red]",
|
||||
LogType.CRITICAL => "[red]",
|
||||
_ => "[white]"
|
||||
};
|
||||
|
||||
if (logMessage.Message.Contains('['))
|
||||
{
|
||||
Functions.WriteErrFile(ex.Message);
|
||||
}
|
||||
// If the message contains a tag, just print it as it is. No need to format it
|
||||
Console.WriteLine(logMessage.Message);
|
||||
return;
|
||||
}
|
||||
|
||||
AnsiConsole.MarkupLine($"{messageColor}{logMessage.ThrowTime} {logMessage.Message} [/]");
|
||||
};
|
||||
|
||||
var onlineSettingsList =
|
||||
await ServerCom.ReadTextFromURL(
|
||||
"https://raw.githubusercontent.com/Wizzy69/installer/discord-bot-files/OnlineData");
|
||||
main.Stop("Loaded online settings. Loading updates ...");
|
||||
foreach (var key in onlineSettingsList)
|
||||
{
|
||||
if (key.Length <= 3 || !key.Contains(' ')) continue;
|
||||
|
||||
var s = key.Split(' ');
|
||||
switch (s[0])
|
||||
{
|
||||
case "CurrentVersion":
|
||||
var newVersion = s[1];
|
||||
if (!newVersion.Equals(await Config.Variables.GetValueAsync("Version")))
|
||||
{
|
||||
var nVer = new VersionString(newVersion.Substring(2));
|
||||
var cVer = new VersionString((await Config.Variables.GetValueAsync("Version")).Substring(2));
|
||||
if (cVer > nVer)
|
||||
{
|
||||
await Config.Variables.SetValueAsync("Version", "1." + cVer.ToShortString() + " (Beta)");
|
||||
break;
|
||||
}
|
||||
|
||||
if (Functions.GetOperatingSystem() == OperatingSystem.WINDOWS)
|
||||
{
|
||||
var url =
|
||||
$"https://github.com/Wizzy69/SethDiscordBot/releases/download/v{newVersion}/net6.0.zip";
|
||||
Process.Start(".\\Updater\\Updater.exe",
|
||||
$"{newVersion} {url} {Process.GetCurrentProcess().ProcessName}");
|
||||
}
|
||||
else
|
||||
{
|
||||
var url =
|
||||
$"https://github.com/Wizzy69/SethDiscordBot/releases/download/v{newVersion}/net6.0_linux.zip";
|
||||
Settings.Variables.outputStream.WriteLine("Downloading update ...");
|
||||
await ServerCom.DownloadFileNoProgressAsync(url, "./update.zip");
|
||||
await File.WriteAllTextAsync("Install.sh",
|
||||
"#!/bin/bash\nunzip -qq update.zip -d ./\nrm update.zip\nchmod +x SethDiscordBot\n./DiscordBot");
|
||||
Process.Start("Install.sh").WaitForExit();
|
||||
Environment.Exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case "UpdaterVersion":
|
||||
var updaternewversion = s[1];
|
||||
if (Functions.GetOperatingSystem() == OperatingSystem.LINUX)
|
||||
break;
|
||||
|
||||
if (!await Config.Variables.ExistsAsync("UpdaterVersion"))
|
||||
await Config.Variables.AddAsync("UpdaterVersion", "0.0.0.0", false);
|
||||
if (await Config.Variables.GetValueAsync("UpdaterVersion") != updaternewversion ||
|
||||
!Directory.Exists("./Updater") ||
|
||||
!File.Exists("./Updater/Updater.exe"))
|
||||
{
|
||||
Console.Clear();
|
||||
Settings.Variables.outputStream.WriteLine("Installing updater ...\nDo NOT close the bot during update !");
|
||||
var bar = new Utilities.ProgressBar(ProgressBarType.NO_END);
|
||||
bar.Start();
|
||||
await ServerCom.DownloadFileNoProgressAsync(
|
||||
"https://github.com/Wizzy69/installer/releases/download/release-1-discordbot/Updater.zip",
|
||||
"./Updater.zip");
|
||||
await Functions.ExtractArchive("./Updater.zip", "./", null,
|
||||
UnzipProgressType.PercentageFromTotalSize);
|
||||
await Config.Variables.SetValueAsync("UpdaterVersion", updaternewversion);
|
||||
File.Delete("Updater.zip");
|
||||
bar.Stop("Updater has been updated !");
|
||||
Console.Clear();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
Console.Clear();
|
||||
AppSettings["Version"] = Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
||||
}
|
||||
}
|
||||
342
DiscordBot/Utilities/Console Utilities.cs
Normal file
342
DiscordBot/Utilities/Console Utilities.cs
Normal file
@@ -0,0 +1,342 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Spectre.Console;
|
||||
|
||||
namespace DiscordBot.Utilities;
|
||||
|
||||
public class TableData
|
||||
{
|
||||
public List<string> Columns;
|
||||
public List<string[]> Rows;
|
||||
|
||||
public bool IsEmpty => Rows.Count == 0;
|
||||
public bool HasRoundBorders { get; set; } = true;
|
||||
|
||||
public TableData(List<string> columns)
|
||||
{
|
||||
Columns = columns;
|
||||
Rows = new List<string[]>();
|
||||
}
|
||||
|
||||
public TableData(string[] columns)
|
||||
{
|
||||
Columns = columns.ToList();
|
||||
Rows = new List<string[]>();
|
||||
}
|
||||
|
||||
public void AddRow(string[] row)
|
||||
{
|
||||
Rows.Add(row);
|
||||
}
|
||||
}
|
||||
|
||||
public static class ConsoleUtilities
|
||||
{
|
||||
|
||||
public static async Task<T> ExecuteWithProgressBar<T>(Task<T> function, string message)
|
||||
{
|
||||
T result = default;
|
||||
await AnsiConsole.Progress()
|
||||
.Columns(
|
||||
new ProgressColumn[]
|
||||
{
|
||||
new TaskDescriptionColumn(),
|
||||
new ProgressBarColumn(),
|
||||
new PercentageColumn(),
|
||||
}
|
||||
)
|
||||
.StartAsync(
|
||||
async ctx =>
|
||||
{
|
||||
var task = ctx.AddTask(message);
|
||||
task.IsIndeterminate = true;
|
||||
result = await function;
|
||||
task.Increment(100);
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async Task ExecuteWithProgressBar(Task function, string message)
|
||||
{
|
||||
await AnsiConsole.Progress()
|
||||
.Columns(new ProgressColumn[]
|
||||
{
|
||||
new TaskDescriptionColumn(),
|
||||
new ProgressBarColumn(),
|
||||
new PercentageColumn(),
|
||||
})
|
||||
.StartAsync(async ctx =>
|
||||
{
|
||||
var task = ctx.AddTask(message);
|
||||
task.IsIndeterminate = true;
|
||||
await function;
|
||||
task.Increment(100);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
private static readonly Dictionary<char, ConsoleColor> Colors = new()
|
||||
{
|
||||
{ 'g', ConsoleColor.Green },
|
||||
{ 'b', ConsoleColor.Blue },
|
||||
{ 'r', ConsoleColor.Red },
|
||||
{ 'm', ConsoleColor.Magenta },
|
||||
{ 'y', ConsoleColor.Yellow }
|
||||
};
|
||||
|
||||
private static readonly char ColorPrefix = '&';
|
||||
|
||||
private static bool CanAproximateTo(this float f, float y)
|
||||
{
|
||||
return MathF.Abs(f - y) < 0.000001;
|
||||
}
|
||||
|
||||
public static void PrintAsTable(this TableData tableData)
|
||||
{
|
||||
var table = new Table();
|
||||
table.Border(tableData.HasRoundBorders ? TableBorder.Rounded : TableBorder.Square);
|
||||
table.AddColumns(tableData.Columns.ToArray());
|
||||
foreach (var row in tableData.Rows)
|
||||
table.AddRow(row);
|
||||
|
||||
AnsiConsole.Write(table);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A way to create a table based on input data
|
||||
/// </summary>
|
||||
/// <param name="data">The List of arrays of string that represent the rows.</param>
|
||||
public static void FormatAndAlignTable(List<string[]> data, TableFormat format)
|
||||
{
|
||||
if (format == TableFormat.SPECTRE_CONSOLE)
|
||||
{
|
||||
var table = new Table();
|
||||
table.Border(TableBorder.Rounded);
|
||||
table.AddColumns(data[0]);
|
||||
data.RemoveAt(0);
|
||||
foreach (var row in data)
|
||||
table.AddRow(row);
|
||||
|
||||
AnsiConsole.Write(table);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (format == TableFormat.CENTER_EACH_COLUMN_BASED)
|
||||
{
|
||||
var tableLine = '-';
|
||||
var tableCross = '+';
|
||||
var tableWall = '|';
|
||||
|
||||
var len = new int[data[0].Length];
|
||||
foreach (var line in data)
|
||||
for (var i = 0; i < line.Length; i++)
|
||||
if (line[i].Length > len[i])
|
||||
len[i] = line[i].Length;
|
||||
|
||||
|
||||
foreach (var row in data)
|
||||
{
|
||||
if (row[0][0] == tableLine)
|
||||
Console.Write(tableCross);
|
||||
else
|
||||
Console.Write(tableWall);
|
||||
for (var l = 0; l < row.Length; l++)
|
||||
{
|
||||
if (row[l][0] == tableLine)
|
||||
{
|
||||
for (var i = 0; i < len[l] + 4; ++i)
|
||||
Console.Write(tableLine);
|
||||
}
|
||||
else if (row[l].Length == len[l])
|
||||
{
|
||||
Console.Write(" ");
|
||||
Console.Write(row[l]);
|
||||
Console.Write(" ");
|
||||
}
|
||||
else
|
||||
{
|
||||
var lenHalf = row[l].Length / 2;
|
||||
for (var i = 0; i < (len[l] + 4) / 2 - lenHalf; ++i)
|
||||
Console.Write(" ");
|
||||
Console.Write(row[l]);
|
||||
for (var i = (len[l] + 4) / 2 + lenHalf + 1; i < len[l] + 4; ++i)
|
||||
Console.Write(" ");
|
||||
if (row[l].Length % 2 == 0)
|
||||
Console.Write(" ");
|
||||
}
|
||||
|
||||
Console.Write(row[l][0] == tableLine ? tableCross : tableWall);
|
||||
}
|
||||
|
||||
Console.WriteLine(); //end line
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (format == TableFormat.CENTER_OVERALL_LENGTH)
|
||||
{
|
||||
var maxLen = 0;
|
||||
foreach (var row in data)
|
||||
foreach (var s in row)
|
||||
if (s.Length > maxLen)
|
||||
maxLen = s.Length;
|
||||
|
||||
var div = (maxLen + 4) / 2;
|
||||
|
||||
foreach (var row in data)
|
||||
{
|
||||
Console.Write("\t");
|
||||
if (row[0] == "-")
|
||||
Console.Write("+");
|
||||
else
|
||||
Console.Write("|");
|
||||
|
||||
foreach (var s in row)
|
||||
{
|
||||
if (s == "-")
|
||||
{
|
||||
for (var i = 0; i < maxLen + 4; ++i)
|
||||
Console.Write("-");
|
||||
}
|
||||
else if (s.Length == maxLen)
|
||||
{
|
||||
Console.Write(" ");
|
||||
Console.Write(s);
|
||||
Console.Write(" ");
|
||||
}
|
||||
else
|
||||
{
|
||||
var lenHalf = s.Length / 2;
|
||||
for (var i = 0; i < div - lenHalf; ++i)
|
||||
Console.Write(" ");
|
||||
Console.Write(s);
|
||||
for (var i = div + lenHalf + 1; i < maxLen + 4; ++i)
|
||||
Console.Write(" ");
|
||||
if (s.Length % 2 == 0)
|
||||
Console.Write(" ");
|
||||
}
|
||||
|
||||
if (s == "-")
|
||||
Console.Write("+");
|
||||
else
|
||||
Console.Write("|");
|
||||
}
|
||||
|
||||
Console.WriteLine(); //end line
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (format == TableFormat.DEFAULT)
|
||||
{
|
||||
var widths = new int[data[0].Length];
|
||||
var space_between_columns = 3;
|
||||
for (var i = 0; i < data.Count; i++)
|
||||
for (var j = 0; j < data[i].Length; j++)
|
||||
if (data[i][j].Length > widths[j])
|
||||
widths[j] = data[i][j].Length;
|
||||
|
||||
for (var i = 0; i < data.Count; i++)
|
||||
{
|
||||
for (var j = 0; j < data[i].Length; j++)
|
||||
{
|
||||
if (data[i][j] == "-")
|
||||
data[i][j] = " ";
|
||||
Console.Write(data[i][j]);
|
||||
for (var k = 0; k < widths[j] - data[i][j].Length + 1 + space_between_columns; k++)
|
||||
Console.Write(" ");
|
||||
}
|
||||
|
||||
Console.WriteLine();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
throw new Exception("Unknown type of table");
|
||||
}
|
||||
|
||||
public static void WriteColorText(string text, bool appendNewLineAtEnd = true)
|
||||
{
|
||||
var initialForeGround = Console.ForegroundColor;
|
||||
var input = text.ToCharArray();
|
||||
for (var i = 0; i < input.Length; i++)
|
||||
if (input[i] == ColorPrefix)
|
||||
{
|
||||
if (i + 1 < input.Length)
|
||||
{
|
||||
if (Colors.ContainsKey(input[i + 1]))
|
||||
{
|
||||
Console.ForegroundColor = Colors[input[i + 1]];
|
||||
i++;
|
||||
}
|
||||
else if (input[i + 1] == 'c')
|
||||
{
|
||||
Console.ForegroundColor = initialForeGround;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.Write(input[i]);
|
||||
}
|
||||
|
||||
Console.ForegroundColor = initialForeGround;
|
||||
if (appendNewLineAtEnd)
|
||||
Console.WriteLine();
|
||||
}
|
||||
|
||||
|
||||
public class Spinner
|
||||
{
|
||||
private readonly string[] Sequence;
|
||||
private bool isRunning;
|
||||
public string Message;
|
||||
private int position;
|
||||
private Thread thread;
|
||||
|
||||
public Spinner()
|
||||
{
|
||||
Sequence = new[] { "|", "/", "-", "\\" };
|
||||
position = 0;
|
||||
}
|
||||
|
||||
public void Start()
|
||||
{
|
||||
Console.CursorVisible = false;
|
||||
isRunning = true;
|
||||
thread = new Thread(() =>
|
||||
{
|
||||
while (isRunning)
|
||||
{
|
||||
Console.SetCursorPosition(0, Console.CursorTop);
|
||||
Console.Write(" " + Sequence[position] + " " + Message + " ");
|
||||
position++;
|
||||
if (position >= Sequence.Length)
|
||||
position = 0;
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
thread.Start();
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
isRunning = false;
|
||||
Console.CursorVisible = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
9
DiscordBot/Utilities/Enums.cs
Normal file
9
DiscordBot/Utilities/Enums.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace DiscordBot.Utilities;
|
||||
|
||||
public enum TableFormat
|
||||
{
|
||||
SPECTRE_CONSOLE,
|
||||
CENTER_EACH_COLUMN_BASED,
|
||||
CENTER_OVERALL_LENGTH,
|
||||
DEFAULT
|
||||
}
|
||||
35
DiscordBot/builder.bat
Normal file
35
DiscordBot/builder.bat
Normal file
@@ -0,0 +1,35 @@
|
||||
@echo off
|
||||
echo "Building..."
|
||||
|
||||
echo "Building linux-x64 not self-contained"
|
||||
dotnet publish -r linux-x64 -p:PublishSingleFile=false --self-contained true -c Release -o ../publish/linux-x64
|
||||
|
||||
echo "Building win-x64 not self-contained"
|
||||
dotnet publish -r win-x64 -p:PublishSingleFile=false --self-contained true -c Release -o ../publish/win-x64
|
||||
|
||||
echo "Building osx-x64 not self-contained"
|
||||
dotnet publish -r osx-x64 -p:PublishSingleFile=false --self-contained true -c Release -o ../publish/osx-x64
|
||||
|
||||
|
||||
echo "Building linux-x64 self-contained"
|
||||
dotnet publish -r linux-x64 -p:PublishSingleFile=true --self-contained true -c Release -o ../publish/linux-x64-selfcontained
|
||||
|
||||
echo "Building win-x64 self-contained"
|
||||
dotnet publish -r win-x64 -p:PublishSingleFile=true --self-contained true -c Release -o ../publish/win-x64-selfcontained
|
||||
|
||||
echo "Building osx-x64 self-contained"
|
||||
dotnet publish -r osx-x64 -p:PublishSingleFile=true --self-contained true -c Release -o ../publish/osx-x64-selfcontained
|
||||
|
||||
echo "Zipping..."
|
||||
mkdir ../publish/zip
|
||||
|
||||
|
||||
zip -r ../publish/zip/linux-x64.zip ../publish/linux-x64
|
||||
zip -r ../publish/zip/win-x64.zip ../publish/win-x64
|
||||
zip -r ../publish/zip/osx-x64.zip ../publish/osx-x64
|
||||
|
||||
zip -r ../publish/zip/linux-x64-selfcontained.zip ../publish/linux-x64-selfcontained
|
||||
zip -r ../publish/zip/win-x64-selfcontained.zip ../publish/win-x64-selfcontained
|
||||
zip -r ../publish/zip/osx-x64-selfcontained.zip ../publish/osx-x64-selfcontained
|
||||
|
||||
echo "Done!"
|
||||
36
DiscordBot/builder.sh
Normal file
36
DiscordBot/builder.sh
Normal file
@@ -0,0 +1,36 @@
|
||||
# All files in this directory will be copied to the root of the container
|
||||
|
||||
echo "Building..."
|
||||
|
||||
echo "Building linux-x64 not self-contained"
|
||||
dotnet publish -r linux-x64 -p:PublishSingleFile=false --self-contained true -c Release -o ./publish/linux-x64
|
||||
|
||||
echo "Building win-x64 not self-contained"
|
||||
dotnet publish -r win-x64 -p:PublishSingleFile=false --self-contained true -c Release -o ./publish/win-x64
|
||||
|
||||
echo "Building osx-x64 not self-contained"
|
||||
dotnet publish -r osx-x64 -p:PublishSingleFile=false --self-contained true -c Release -o ./publish/osx-x64
|
||||
|
||||
#One file per platform
|
||||
echo "Building linux-x64 self-contained"
|
||||
dotnet publish -r linux-x64 -p:PublishSingleFile=true --self-contained true -c Release -o ./publish/linux-x64-selfcontained
|
||||
|
||||
echo "Building win-x64 self-contained"
|
||||
dotnet publish -r win-x64 -p:PublishSingleFile=true --self-contained true -c Release -o ./publish/win-x64-selfcontained
|
||||
|
||||
echo "Building osx-x64 self-contained"
|
||||
dotnet publish -r osx-x64 -p:PublishSingleFile=true --self-contained true -c Release -o ./publish/osx-x64-selfcontained
|
||||
|
||||
echo "Zipping..."
|
||||
mkdir ./publish/zip
|
||||
|
||||
|
||||
zip -r ./publish/zip/linux-x64.zip ./publish/linux-x64
|
||||
zip -r ./publish/zip/win-x64.zip ./publish/win-x64
|
||||
zip -r ./publish/zip/osx-x64.zip ./publish/osx-x64
|
||||
|
||||
zip -r ./publish/zip/linux-x64-selfcontained.zip ./publish/linux-x64-selfcontained
|
||||
zip -r ./publish/zip/win-x64-selfcontained.zip ./publish/win-x64-selfcontained
|
||||
zip -r ./publish/zip/osx-x64-selfcontained.zip ./publish/osx-x64-selfcontained
|
||||
|
||||
echo "Done!"
|
||||
@@ -1,15 +1,13 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Discord.WebSocket;
|
||||
using PluginManager.Others;
|
||||
|
||||
using static PluginManager.Others.Functions;
|
||||
namespace PluginManager.Bot;
|
||||
|
||||
namespace DiscordBot.Discord.Core;
|
||||
|
||||
internal class Boot
|
||||
public class Boot
|
||||
{
|
||||
/// <summary>
|
||||
/// The bot prefix
|
||||
@@ -51,22 +49,27 @@ internal class Boot
|
||||
/// <summary>
|
||||
/// Checks if the bot is ready
|
||||
/// </summary>
|
||||
/// <value> true if the bot is ready, othwerwise false </value>
|
||||
/// <value> true if the bot is ready, otherwise false </value>
|
||||
public bool isReady { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// The start method for the bot. This method is used to load the bot
|
||||
/// </summary>
|
||||
/// <param name="config">
|
||||
/// The discord socket config. If null then the default one will be applied (AlwaysDownloadUsers=true,
|
||||
/// UseInteractionSnowflakeDate=false, GatewayIntents=GatewayIntents.All)
|
||||
/// </param>
|
||||
/// <returns>Task</returns>
|
||||
public async Task Awake()
|
||||
public async Task Awake(DiscordSocketConfig? config = null)
|
||||
{
|
||||
var config = new DiscordSocketConfig
|
||||
if (config is null)
|
||||
config = new DiscordSocketConfig
|
||||
{
|
||||
|
||||
AlwaysDownloadUsers = true,
|
||||
|
||||
//Disable system clock checkup (for responses at slash commands)
|
||||
UseInteractionSnowflakeDate = false
|
||||
UseInteractionSnowflakeDate = false,
|
||||
GatewayIntents = GatewayIntents.All
|
||||
};
|
||||
|
||||
client = new DiscordSocketClient(config);
|
||||
@@ -79,11 +82,11 @@ internal class Boot
|
||||
await client.StartAsync();
|
||||
|
||||
commandServiceHandler = new CommandHandler(client, service, botPrefix);
|
||||
|
||||
await commandServiceHandler.InstallCommandsAsync();
|
||||
|
||||
Config._DiscordBotClient = this;
|
||||
|
||||
|
||||
await Task.Delay(2000);
|
||||
while (!isReady) ;
|
||||
}
|
||||
|
||||
@@ -94,32 +97,36 @@ internal class Boot
|
||||
client.Log += Log;
|
||||
client.LoggedIn += LoggedIn;
|
||||
client.Ready += Ready;
|
||||
client.Disconnected += Client_Disconnected;
|
||||
}
|
||||
|
||||
private async Task Client_Disconnected(Exception arg)
|
||||
{
|
||||
if (arg.Message.Contains("401"))
|
||||
{
|
||||
Config.AppSettings.Remove("token");
|
||||
Config.Logger.Log("The token is invalid. Please restart the bot and enter a valid token.", source:typeof(Boot), type: LogType.CRITICAL);
|
||||
await Config.AppSettings.SaveToFile();
|
||||
await Task.Delay(4000);
|
||||
Environment.Exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
private async Task Client_LoggedOut()
|
||||
{
|
||||
WriteLogFile("Successfully Logged Out");
|
||||
Config.Logger.Log("Successfully Logged Out", source: typeof(Boot));
|
||||
await Log(new LogMessage(LogSeverity.Info, "Boot", "Successfully logged out from discord !"));
|
||||
|
||||
/* var cmds = await client.GetGlobalApplicationCommandsAsync();
|
||||
foreach (var cmd in cmds)
|
||||
await cmd.DeleteAsync();*/
|
||||
}
|
||||
|
||||
private async Task Ready()
|
||||
private Task Ready()
|
||||
{
|
||||
Console.Title = "ONLINE";
|
||||
|
||||
|
||||
isReady = true;
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
private Task LoggedIn()
|
||||
{
|
||||
Console.Title = "CONNECTED";
|
||||
WriteLogFile("The bot has been logged in at " + DateTime.Now.ToShortDateString() + " (" +
|
||||
DateTime.Now.ToShortTimeString() + ")"
|
||||
);
|
||||
Config.Logger.Log("Successfully Logged In", source: typeof(Boot));
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
@@ -129,21 +136,12 @@ internal class Boot
|
||||
{
|
||||
case LogSeverity.Error:
|
||||
case LogSeverity.Critical:
|
||||
WriteErrFile(message.Message);
|
||||
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine("[ERROR] " + message.Message);
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
|
||||
Config.Logger.Log(message.Message, source: typeof(Boot), type: LogType.ERROR);
|
||||
break;
|
||||
|
||||
case LogSeverity.Info:
|
||||
case LogSeverity.Debug:
|
||||
WriteLogFile(message.Message);
|
||||
|
||||
Console.ForegroundColor = ConsoleColor.Cyan;
|
||||
Console.WriteLine("[INFO] " + message.Message);
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
Config.Logger.Log(message.Message, source: typeof(Boot), type: LogType.INFO);
|
||||
|
||||
|
||||
break;
|
||||
157
PluginManager/Bot/CommandHandler.cs
Normal file
157
PluginManager/Bot/CommandHandler.cs
Normal file
@@ -0,0 +1,157 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using Discord.Commands;
|
||||
using Discord.WebSocket;
|
||||
using PluginManager.Interfaces;
|
||||
using PluginManager.Loaders;
|
||||
using PluginManager.Others;
|
||||
using PluginManager.Others.Permissions;
|
||||
|
||||
namespace PluginManager.Bot;
|
||||
|
||||
internal class CommandHandler
|
||||
{
|
||||
private readonly string botPrefix;
|
||||
private readonly DiscordSocketClient client;
|
||||
private readonly CommandService commandService;
|
||||
|
||||
/// <summary>
|
||||
/// Command handler constructor
|
||||
/// </summary>
|
||||
/// <param name="client">The discord bot client</param>
|
||||
/// <param name="commandService">The discord bot command service</param>
|
||||
/// <param name="botPrefix">The prefix to watch for</param>
|
||||
public CommandHandler(DiscordSocketClient client, CommandService commandService, string botPrefix)
|
||||
{
|
||||
this.client = client;
|
||||
this.commandService = commandService;
|
||||
this.botPrefix = botPrefix;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The method to initialize all commands
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task InstallCommandsAsync()
|
||||
{
|
||||
client.MessageReceived += MessageHandler;
|
||||
client.SlashCommandExecuted += Client_SlashCommandExecuted;
|
||||
await commandService.AddModulesAsync(Assembly.GetEntryAssembly(), null);
|
||||
}
|
||||
|
||||
private Task Client_SlashCommandExecuted(SocketSlashCommand arg)
|
||||
{
|
||||
try
|
||||
{
|
||||
var plugin = PluginLoader.SlashCommands!.FirstOrDefault(p => p.Name == arg.Data.Name);
|
||||
|
||||
if (plugin is null)
|
||||
throw new Exception("Failed to run command. !");
|
||||
|
||||
|
||||
if (arg.Channel is SocketDMChannel)
|
||||
plugin.ExecuteDM(arg);
|
||||
else plugin.ExecuteServer(arg);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Config.Logger.Log(ex.Message, type: LogType.ERROR, source: typeof(CommandHandler));
|
||||
}
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The message handler for the bot
|
||||
/// </summary>
|
||||
/// <param name="Message">The message got from the user in discord chat</param>
|
||||
/// <returns></returns>
|
||||
private async Task MessageHandler(SocketMessage Message)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (Message.Author.IsBot)
|
||||
return;
|
||||
|
||||
if (Message as SocketUserMessage == null)
|
||||
return;
|
||||
|
||||
var message = Message as SocketUserMessage;
|
||||
|
||||
if (message is null)
|
||||
return;
|
||||
|
||||
var argPos = 0;
|
||||
|
||||
if (!message.Content.StartsWith(botPrefix) && !message.HasMentionPrefix(client.CurrentUser, ref argPos))
|
||||
return;
|
||||
|
||||
var context = new SocketCommandContext(client, message);
|
||||
|
||||
await commandService.ExecuteAsync(context, argPos, null);
|
||||
|
||||
DBCommand? plugin;
|
||||
var cleanMessage = "";
|
||||
|
||||
if (message.HasMentionPrefix(client.CurrentUser, ref argPos))
|
||||
{
|
||||
var mentionPrefix = "<@" + client.CurrentUser.Id + ">";
|
||||
|
||||
plugin = PluginLoader.Commands!
|
||||
.FirstOrDefault(plug => plug.Command ==
|
||||
message.Content.Substring(mentionPrefix.Length + 1)
|
||||
.Split(' ')[0] ||
|
||||
(
|
||||
plug.Aliases is not null &&
|
||||
plug.Aliases.Contains(message.CleanContent
|
||||
.Substring(mentionPrefix.Length + 1)
|
||||
.Split(' ')[0])
|
||||
));
|
||||
|
||||
cleanMessage = message.Content.Substring(mentionPrefix.Length + 1);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
plugin = PluginLoader.Commands!
|
||||
.FirstOrDefault(p => p.Command ==
|
||||
message.Content.Split(' ')[0].Substring(botPrefix.Length) ||
|
||||
(p.Aliases is not null &&
|
||||
p.Aliases.Contains(
|
||||
message.Content.Split(' ')[0]
|
||||
.Substring(botPrefix.Length))));
|
||||
cleanMessage = message.Content.Substring(botPrefix.Length);
|
||||
}
|
||||
|
||||
if (plugin is null)
|
||||
return;
|
||||
|
||||
if (plugin.requireAdmin && !context.Message.Author.isAdmin())
|
||||
return;
|
||||
|
||||
var split = cleanMessage.Split(' ');
|
||||
|
||||
string[]? argsClean = null;
|
||||
if (split.Length > 1)
|
||||
argsClean = string.Join(' ', split, 1, split.Length - 1).Split(' ');
|
||||
|
||||
DBCommandExecutingArguments cmd = new(context, cleanMessage, split[0], argsClean);
|
||||
|
||||
Config.Logger.Log(
|
||||
message: $"User ({context.User.Username}) from Guild \"{context.Guild.Name}\" executed command \"{cmd.cleanContent}\"",
|
||||
source: typeof(CommandHandler),
|
||||
type: LogType.INFO
|
||||
);
|
||||
|
||||
if (context.Channel is SocketDMChannel)
|
||||
plugin.ExecuteDM(cmd);
|
||||
else plugin.ExecuteServer(cmd);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Config.Logger.Log(ex.Message, type: LogType.ERROR, source: typeof(CommandHandler));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,199 +1,43 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using PluginManager.Online.Helpers;
|
||||
using PluginManager.Bot;
|
||||
using PluginManager.Others;
|
||||
using PluginManager.Others.Logger;
|
||||
|
||||
namespace PluginManager;
|
||||
|
||||
public static class Config
|
||||
public class Config
|
||||
{
|
||||
private static bool IsLoaded = false;
|
||||
private static bool _isLoaded;
|
||||
public static Logger Logger;
|
||||
public static SettingsDictionary<string, string> AppSettings;
|
||||
|
||||
internal static Boot? _DiscordBotClient;
|
||||
|
||||
public static Boot? DiscordBot => _DiscordBotClient;
|
||||
|
||||
public static async Task Initialize()
|
||||
{
|
||||
if (IsLoaded)
|
||||
return;
|
||||
if (_isLoaded) return;
|
||||
|
||||
if (!await Settings.sqlDatabase.TableExistsAsync("Plugins"))
|
||||
await Settings.sqlDatabase.CreateTableAsync("Plugins", "PluginName", "Version");
|
||||
if (!await Settings.sqlDatabase.TableExistsAsync("Variables"))
|
||||
await Settings.sqlDatabase.CreateTableAsync("Variables", "VarName", "Value", "ReadOnly");
|
||||
Directory.CreateDirectory("./Data/Resources");
|
||||
Directory.CreateDirectory("./Data/Plugins");
|
||||
Directory.CreateDirectory("./Data/PAKS");
|
||||
Directory.CreateDirectory("./Data/Logs/Logs");
|
||||
Directory.CreateDirectory("./Data/Logs/Errors");
|
||||
|
||||
IsLoaded = true;
|
||||
}
|
||||
AppSettings = new SettingsDictionary<string, string>("./Data/Resources/config.json");
|
||||
|
||||
public static class Variables
|
||||
{
|
||||
public static async Task<string> GetValueAsync(string VarName)
|
||||
{
|
||||
if (!IsLoaded)
|
||||
throw new Exception("Config is not loaded");
|
||||
return await Settings.sqlDatabase.GetValueAsync("Variables", "VarName", VarName, "Value");
|
||||
}
|
||||
AppSettings["LogFolder"] = "./Data/Logs/Logs";
|
||||
|
||||
public static string GetValue(string VarName)
|
||||
{
|
||||
if (!IsLoaded)
|
||||
throw new Exception("Config is not loaded");
|
||||
return Settings.sqlDatabase.GetValue("Variables", "VarName", VarName, "Value");
|
||||
}
|
||||
Logger = new Logger(false, true);
|
||||
|
||||
ArchiveManager.Initialize();
|
||||
|
||||
public static async Task SetValueAsync(string VarName, string Value)
|
||||
{
|
||||
if (!IsLoaded)
|
||||
throw new Exception("Config is not loaded");
|
||||
_isLoaded = true;
|
||||
|
||||
if (await IsReadOnlyAsync(VarName))
|
||||
throw new Exception($"Variable ({VarName}) is read only and can not be changed to {Value}");
|
||||
|
||||
await Settings.sqlDatabase.SetValueAsync("Variables", "VarName", VarName, "Value", Value);
|
||||
}
|
||||
|
||||
public static void SetValue(string VarName, string Value)
|
||||
{
|
||||
if (!IsLoaded)
|
||||
throw new Exception("Config is not loaded");
|
||||
if (IsReadOnly(VarName))
|
||||
throw new Exception($"Variable ({VarName}) is read only and can not be changed to {Value}");
|
||||
Settings.sqlDatabase.SetValue("Variables", "VarName", VarName, "Value", Value);
|
||||
}
|
||||
|
||||
|
||||
public static async Task<bool> IsReadOnlyAsync(string VarName)
|
||||
{
|
||||
if (!IsLoaded)
|
||||
throw new Exception("Config is not loaded");
|
||||
return (await Settings.sqlDatabase.GetValueAsync("Variables", "VarName", VarName, "ReadOnly")).Equals("true", StringComparison.CurrentCultureIgnoreCase);
|
||||
}
|
||||
|
||||
public static bool IsReadOnly(string VarName)
|
||||
{
|
||||
if (!IsLoaded)
|
||||
throw new Exception("Config is not loaded");
|
||||
return (Settings.sqlDatabase.GetValue("Variables", "VarName", VarName, "ReadOnly")).Equals("true", StringComparison.CurrentCultureIgnoreCase);
|
||||
}
|
||||
|
||||
public static async Task SetReadOnlyAsync(string VarName, bool ReadOnly)
|
||||
{
|
||||
if (!IsLoaded)
|
||||
throw new Exception("Config is not loaded");
|
||||
await Settings.sqlDatabase.SetValueAsync("Variables", "VarName", VarName, "ReadOnly", ReadOnly ? "true" : "false");
|
||||
}
|
||||
|
||||
public static void SetReadOnly(string VarName, bool ReadOnly)
|
||||
{
|
||||
if (!IsLoaded)
|
||||
throw new Exception("Config is not loaded");
|
||||
Settings.sqlDatabase.SetValue("Variables", "VarName", VarName, "ReadOnly", ReadOnly ? "true" : "false");
|
||||
}
|
||||
|
||||
public static async Task<bool> ExistsAsync(string VarName)
|
||||
{
|
||||
if (!IsLoaded)
|
||||
throw new Exception("Config is not loaded");
|
||||
return await Settings.sqlDatabase.KeyExistsAsync("Variables", "VarName", VarName);
|
||||
}
|
||||
|
||||
public static bool Exists(string VarName)
|
||||
{
|
||||
if (!IsLoaded)
|
||||
throw new Exception("Config is not loaded");
|
||||
return Settings.sqlDatabase.KeyExists("Variables", "VarName", VarName);
|
||||
}
|
||||
|
||||
public static async Task AddAsync(string VarName, string Value, bool ReadOnly = false)
|
||||
{
|
||||
if (!IsLoaded)
|
||||
throw new Exception("Config is not loaded");
|
||||
if (await ExistsAsync(VarName))
|
||||
{
|
||||
await SetValueAsync(VarName, Value);
|
||||
await SetReadOnlyAsync(VarName, ReadOnly);
|
||||
return;
|
||||
}
|
||||
await Settings.sqlDatabase.InsertAsync("Variables", VarName, Value, ReadOnly ? "true" : "false");
|
||||
}
|
||||
|
||||
public static void Add(string VarName, string Value, bool ReadOnly = false)
|
||||
{
|
||||
if (!IsLoaded)
|
||||
throw new Exception("Config is not loaded");
|
||||
if (Exists(VarName))
|
||||
{
|
||||
SetValue(VarName, Value);
|
||||
SetReadOnly(VarName, ReadOnly);
|
||||
return;
|
||||
}
|
||||
Settings.sqlDatabase.Insert("Variables", VarName, Value, ReadOnly ? "true" : "false");
|
||||
}
|
||||
|
||||
public static async Task RemoveKeyAsync(string VarName)
|
||||
{
|
||||
if (!IsLoaded)
|
||||
throw new Exception("Config is not loaded");
|
||||
await Settings.sqlDatabase.RemoveKeyAsync("Variables", "VarName", VarName);
|
||||
}
|
||||
|
||||
public static void RemoveKey(string VarName)
|
||||
{
|
||||
if (!IsLoaded)
|
||||
throw new Exception("Config is not loaded");
|
||||
Settings.sqlDatabase.RemoveKey("Variables", "VarName", VarName);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Plugins
|
||||
{
|
||||
public static async Task<string> GetVersionAsync(string pluginName)
|
||||
{
|
||||
if (!IsLoaded)
|
||||
throw new Exception("Config is not loaded yet");
|
||||
|
||||
string result = await Settings.sqlDatabase.GetValueAsync("Plugins", "PluginName", pluginName, "Version");
|
||||
if (result is null)
|
||||
return "0.0.0";
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static string GetVersion(string pluginName)
|
||||
{
|
||||
if (!IsLoaded)
|
||||
throw new Exception("Config is not loaded yet");
|
||||
|
||||
string result = Settings.sqlDatabase.GetValue("Plugins", "PluginName", pluginName, "Version");
|
||||
if (result is null)
|
||||
return "0.0.0";
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static async Task SetVersionAsync(string pluginName, VersionString version)
|
||||
{
|
||||
if (!IsLoaded)
|
||||
throw new Exception("Config is not loaded yet");
|
||||
|
||||
if (!await Settings.sqlDatabase.KeyExistsAsync("Plugins", "PluginName", pluginName))
|
||||
{
|
||||
await Settings.sqlDatabase.InsertAsync("Plugins", pluginName, version.ToShortString());
|
||||
return;
|
||||
}
|
||||
await Settings.sqlDatabase.SetValueAsync("Plugins", "PluginName", pluginName, "Version", version.ToShortString());
|
||||
}
|
||||
|
||||
public static void SetVersion(string pluginName, VersionString version)
|
||||
{
|
||||
if (!IsLoaded)
|
||||
throw new Exception("Config is not loaded yet");
|
||||
|
||||
if (!Settings.sqlDatabase.KeyExists("Plugins", "PluginName", pluginName))
|
||||
{
|
||||
Settings.sqlDatabase.Insert("Plugins", pluginName, version.ToShortString());
|
||||
return;
|
||||
}
|
||||
|
||||
Settings.sqlDatabase.SetValue("Plugins", "PluginName", pluginName, "Version", version.ToShortString());
|
||||
Logger.Log(message: "Config initialized", source: typeof(Config));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,89 +1,128 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.SQLite;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
namespace PluginManager.Database
|
||||
{
|
||||
|
||||
namespace PluginManager.Database;
|
||||
|
||||
public class SqlDatabase
|
||||
{
|
||||
private string ConnectionString;
|
||||
private SQLiteConnection Connection;
|
||||
private readonly SQLiteConnection Connection;
|
||||
|
||||
/// <summary>
|
||||
/// Initialize a SQL connection by specifing its private path
|
||||
/// </summary>
|
||||
/// <param name="fileName">The path to the database (it is starting from ./Data/Resources/)</param>
|
||||
public SqlDatabase(string fileName)
|
||||
{
|
||||
if (!fileName.StartsWith("./Data/Resources/"))
|
||||
fileName = Path.Combine("./Data/Resources", fileName);
|
||||
if (!File.Exists(fileName))
|
||||
SQLiteConnection.CreateFile(fileName);
|
||||
ConnectionString = $"URI=file:{fileName}";
|
||||
Connection = new SQLiteConnection(ConnectionString);
|
||||
var connectionString = $"URI=file:{fileName}";
|
||||
Connection = new SQLiteConnection(connectionString);
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Open the SQL Connection. To close use the Stop() method
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task Open()
|
||||
{
|
||||
await Connection.OpenAsync();
|
||||
|
||||
//Console.WriteLine("Opened database successfully");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>
|
||||
/// Insert into a specified table some values
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <param name="tableName">The table name</param>
|
||||
/// <param name="values">The values to be inserted (in the correct order and number)</param>
|
||||
/// <returns></returns>
|
||||
public async Task InsertAsync(string tableName, params string[] values)
|
||||
{
|
||||
|
||||
string query = $"INSERT INTO {tableName} VALUES (";
|
||||
for (int i = 0; i < values.Length; i++)
|
||||
var query = $"INSERT INTO {tableName} VALUES (";
|
||||
for (var i = 0; i < values.Length; i++)
|
||||
{
|
||||
query += $"'{values[i]}'";
|
||||
if (i != values.Length - 1)
|
||||
query += ", ";
|
||||
}
|
||||
|
||||
query += ")";
|
||||
|
||||
SQLiteCommand command = new SQLiteCommand(query, Connection);
|
||||
var command = new SQLiteCommand(query, Connection);
|
||||
await command.ExecuteNonQueryAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// <para>
|
||||
/// Insert into a specified table some values
|
||||
/// </para>
|
||||
/// </summary>
|
||||
/// <param name="tableName">The table name</param>
|
||||
/// <param name="values">The values to be inserted (in the correct order and number)</param>
|
||||
/// <returns></returns>
|
||||
public void Insert(string tableName, params string[] values)
|
||||
{
|
||||
|
||||
string query = $"INSERT INTO {tableName} VALUES (";
|
||||
for (int i = 0; i < values.Length; i++)
|
||||
var query = $"INSERT INTO {tableName} VALUES (";
|
||||
for (var i = 0; i < values.Length; i++)
|
||||
{
|
||||
query += $"'{values[i]}'";
|
||||
if (i != values.Length - 1)
|
||||
query += ", ";
|
||||
}
|
||||
|
||||
query += ")";
|
||||
|
||||
SQLiteCommand command = new SQLiteCommand(query, Connection);
|
||||
var command = new SQLiteCommand(query, Connection);
|
||||
command.ExecuteNonQuery();
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove every row in a table that has a certain propery
|
||||
/// </summary>
|
||||
/// <param name="tableName">The table name</param>
|
||||
/// <param name="KeyName">The column name that the search is made by</param>
|
||||
/// <param name="KeyValue">The value that is searched in the specified column</param>
|
||||
/// <returns></returns>
|
||||
public async Task RemoveKeyAsync(string tableName, string KeyName, string KeyValue)
|
||||
{
|
||||
var query = $"DELETE FROM {tableName} WHERE {KeyName} = '{KeyValue}'";
|
||||
|
||||
string query = $"DELETE FROM {tableName} WHERE {KeyName} = '{KeyValue}'";
|
||||
|
||||
SQLiteCommand command = new SQLiteCommand(query, Connection);
|
||||
var command = new SQLiteCommand(query, Connection);
|
||||
await command.ExecuteNonQueryAsync();
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Remove every row in a table that has a certain propery
|
||||
/// </summary>
|
||||
/// <param name="tableName">The table name</param>
|
||||
/// <param name="KeyName">The column name that the search is made by</param>
|
||||
/// <param name="KeyValue">The value that is searched in the specified column</param>
|
||||
/// <returns></returns>
|
||||
public void RemoveKey(string tableName, string KeyName, string KeyValue)
|
||||
{
|
||||
var query = $"DELETE FROM {tableName} WHERE {KeyName} = '{KeyValue}'";
|
||||
|
||||
|
||||
string query = $"DELETE FROM {tableName} WHERE {KeyName} = '{KeyValue}'";
|
||||
|
||||
SQLiteCommand command = new SQLiteCommand(query, Connection);
|
||||
var command = new SQLiteCommand(query, Connection);
|
||||
command.ExecuteNonQuery();
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Check if the key exists in the table
|
||||
/// </summary>
|
||||
/// <param name="tableName">The table name</param>
|
||||
/// <param name="keyName">The column that the search is made by</param>
|
||||
/// <param name="KeyValue">The value that is searched in the specified column</param>
|
||||
/// <returns></returns>
|
||||
public async Task<bool> KeyExistsAsync(string tableName, string keyName, string KeyValue)
|
||||
{
|
||||
string query = $"SELECT * FROM {tableName} where {keyName} = '{KeyValue}'";
|
||||
var query = $"SELECT * FROM {tableName} where {keyName} = '{KeyValue}'";
|
||||
|
||||
if (await ReadDataAsync(query) is not null)
|
||||
return true;
|
||||
@@ -91,100 +130,158 @@ namespace PluginManager.Database
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if the key exists in the table
|
||||
/// </summary>
|
||||
/// <param name="tableName">The table name</param>
|
||||
/// <param name="keyName">The column that the search is made by</param>
|
||||
/// <param name="KeyValue">The value that is searched in the specified column</param>
|
||||
/// <returns></returns>
|
||||
public bool KeyExists(string tableName, string keyName, string KeyValue)
|
||||
{
|
||||
string query = $"SELECT * FROM {tableName} where {keyName} = '{KeyValue}'";
|
||||
var query = $"SELECT * FROM {tableName} where {keyName} = '{KeyValue}'";
|
||||
|
||||
if (ReadData(query) is not null)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public async Task SetValueAsync(string tableName, string keyName, string KeyValue, string ResultColumnName, string ResultColumnValue)
|
||||
/// <summary>
|
||||
/// Set value of a column in a table
|
||||
/// </summary>
|
||||
/// <param name="tableName">The table name</param>
|
||||
/// <param name="keyName">The column that the search is made by</param>
|
||||
/// <param name="KeyValue">The value that is searched in the column specified</param>
|
||||
/// <param name="ResultColumnName">The column that has to be modified</param>
|
||||
/// <param name="ResultColumnValue">The new value that will replace the old value from the column specified</param>
|
||||
public async Task SetValueAsync(
|
||||
string tableName, string keyName, string KeyValue, string ResultColumnName,
|
||||
string ResultColumnValue)
|
||||
{
|
||||
if (!await TableExistsAsync(tableName))
|
||||
throw new System.Exception($"Table {tableName} does not exist");
|
||||
throw new Exception($"Table {tableName} does not exist");
|
||||
|
||||
await ExecuteAsync($"UPDATE {tableName} SET {ResultColumnName}='{ResultColumnValue}' WHERE {keyName}='{KeyValue}'");
|
||||
await ExecuteAsync(
|
||||
$"UPDATE {tableName} SET {ResultColumnName}='{ResultColumnValue}' WHERE {keyName}='{KeyValue}'");
|
||||
}
|
||||
|
||||
public void SetValue(string tableName, string keyName, string KeyValue, string ResultColumnName, string ResultColumnValue)
|
||||
/// <summary>
|
||||
/// Set value of a column in a table
|
||||
/// </summary>
|
||||
/// <param name="tableName">The table name</param>
|
||||
/// <param name="keyName">The column that the search is made by</param>
|
||||
/// <param name="KeyValue">The value that is searched in the column specified</param>
|
||||
/// <param name="ResultColumnName">The column that has to be modified</param>
|
||||
/// <param name="ResultColumnValue">The new value that will replace the old value from the column specified</param>
|
||||
public void SetValue(
|
||||
string tableName, string keyName, string KeyValue, string ResultColumnName,
|
||||
string ResultColumnValue)
|
||||
{
|
||||
if (!TableExists(tableName))
|
||||
throw new System.Exception($"Table {tableName} does not exist");
|
||||
throw new Exception($"Table {tableName} does not exist");
|
||||
|
||||
Execute($"UPDATE {tableName} SET {ResultColumnName}='{ResultColumnValue}' WHERE {keyName}='{KeyValue}'");
|
||||
}
|
||||
|
||||
|
||||
public async Task<string> GetValueAsync(string tableName, string keyName, string KeyValue, string ResultColumnName)
|
||||
/// <summary>
|
||||
/// Get value from a column in a table
|
||||
/// </summary>
|
||||
/// <param name="tableName">The table name</param>
|
||||
/// <param name="keyName">The column that the search is made by</param>
|
||||
/// <param name="KeyValue">The value that is searched in the specified column</param>
|
||||
/// <param name="ResultColumnName">The column that has the result</param>
|
||||
/// <returns>A string that has the requested value (can be null if nothing found)</returns>
|
||||
public async Task<string?> GetValueAsync(
|
||||
string tableName, string keyName, string KeyValue,
|
||||
string ResultColumnName)
|
||||
{
|
||||
if (!await TableExistsAsync(tableName))
|
||||
throw new System.Exception($"Table {tableName} does not exist");
|
||||
throw new Exception($"Table {tableName} does not exist");
|
||||
|
||||
return await ReadDataAsync($"SELECT {ResultColumnName} FROM {tableName} WHERE {keyName}='{KeyValue}'");
|
||||
}
|
||||
|
||||
public string GetValue(string tableName, string keyName, string KeyValue, string ResultColumnName)
|
||||
/// <summary>
|
||||
/// Get value from a column in a table
|
||||
/// </summary>
|
||||
/// <param name="tableName">The table name</param>
|
||||
/// <param name="keyName">The column that the search is made by</param>
|
||||
/// <param name="KeyValue">The value that is searched in the specified column</param>
|
||||
/// <param name="ResultColumnName">The column that has the result</param>
|
||||
/// <returns>A string that has the requested value (can be null if nothing found)</returns>
|
||||
public string? GetValue(string tableName, string keyName, string KeyValue, string ResultColumnName)
|
||||
{
|
||||
if (!TableExists(tableName))
|
||||
throw new System.Exception($"Table {tableName} does not exist");
|
||||
throw new Exception($"Table {tableName} does not exist");
|
||||
|
||||
return ReadData($"SELECT {ResultColumnName} FROM {tableName} WHERE {keyName}='{KeyValue}'");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stop the connection to the SQL Database
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async void Stop()
|
||||
{
|
||||
await Connection.CloseAsync();
|
||||
}
|
||||
|
||||
public async Task AddColumnsToTableAsync(string tableName, string[] columns)
|
||||
/// <summary>
|
||||
/// Change the structure of a table by adding new columns
|
||||
/// </summary>
|
||||
/// <param name="tableName">The table name</param>
|
||||
/// <param name="columns">The columns to be added</param>
|
||||
/// <param name="TYPE">The type of the columns (TEXT, INTEGER, FLOAT, etc)</param>
|
||||
/// <returns></returns>
|
||||
public async Task AddColumnsToTableAsync(string tableName, string[] columns, string TYPE = "TEXT")
|
||||
{
|
||||
|
||||
var command = Connection.CreateCommand();
|
||||
command.CommandText = $"SELECT * FROM {tableName}";
|
||||
var reader = await command.ExecuteReaderAsync();
|
||||
var tableColumns = new List<string>();
|
||||
for (int i = 0; i < reader.FieldCount; i++)
|
||||
for (var i = 0; i < reader.FieldCount; i++)
|
||||
tableColumns.Add(reader.GetName(i));
|
||||
|
||||
foreach (var column in columns)
|
||||
{
|
||||
if (!tableColumns.Contains(column))
|
||||
{
|
||||
command.CommandText = $"ALTER TABLE {tableName} ADD COLUMN {column} TEXT";
|
||||
command.CommandText = $"ALTER TABLE {tableName} ADD COLUMN {column} {TYPE}";
|
||||
await command.ExecuteNonQueryAsync();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void AddColumnsToTable(string tableName, string[] columns)
|
||||
/// <summary>
|
||||
/// Change the structure of a table by adding new columns
|
||||
/// </summary>
|
||||
/// <param name="tableName">The table name</param>
|
||||
/// <param name="columns">The columns to be added</param>
|
||||
/// <param name="TYPE">The type of the columns (TEXT, INTEGER, FLOAT, etc)</param>
|
||||
/// <returns></returns>
|
||||
public void AddColumnsToTable(string tableName, string[] columns, string TYPE = "TEXT")
|
||||
{
|
||||
|
||||
var command = Connection.CreateCommand();
|
||||
command.CommandText = $"SELECT * FROM {tableName}";
|
||||
var reader = command.ExecuteReader();
|
||||
var tableColumns = new List<string>();
|
||||
for (int i = 0; i < reader.FieldCount; i++)
|
||||
for (var i = 0; i < reader.FieldCount; i++)
|
||||
tableColumns.Add(reader.GetName(i));
|
||||
|
||||
foreach (var column in columns)
|
||||
{
|
||||
if (!tableColumns.Contains(column))
|
||||
{
|
||||
command.CommandText = $"ALTER TABLE {tableName} ADD COLUMN {column} TEXT";
|
||||
command.CommandText = $"ALTER TABLE {tableName} ADD COLUMN {column} {TYPE}";
|
||||
command.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if a table exists
|
||||
/// </summary>
|
||||
/// <param name="tableName">The table name</param>
|
||||
/// <returns>True if the table exists, false if not</returns>
|
||||
public async Task<bool> TableExistsAsync(string tableName)
|
||||
{
|
||||
|
||||
var cmd = Connection.CreateCommand();
|
||||
cmd.CommandText = $"SELECT name FROM sqlite_master WHERE type='table' AND name='{tableName}'";
|
||||
var result = await cmd.ExecuteScalarAsync();
|
||||
@@ -194,9 +291,13 @@ namespace PluginManager.Database
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if a table exists
|
||||
/// </summary>
|
||||
/// <param name="tableName">The table name</param>
|
||||
/// <returns>True if the table exists, false if not</returns>
|
||||
public bool TableExists(string tableName)
|
||||
{
|
||||
|
||||
var cmd = Connection.CreateCommand();
|
||||
cmd.CommandText = $"SELECT name FROM sqlite_master WHERE type='table' AND name='{tableName}'";
|
||||
var result = cmd.ExecuteScalar();
|
||||
@@ -206,105 +307,176 @@ namespace PluginManager.Database
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a table
|
||||
/// </summary>
|
||||
/// <param name="tableName">The table name</param>
|
||||
/// <param name="columns">The columns of the table</param>
|
||||
/// <returns></returns>
|
||||
public async Task CreateTableAsync(string tableName, params string[] columns)
|
||||
{
|
||||
|
||||
var cmd = Connection.CreateCommand();
|
||||
cmd.CommandText = $"CREATE TABLE IF NOT EXISTS {tableName} ({string.Join(", ", columns)})";
|
||||
await cmd.ExecuteNonQueryAsync();
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Create a table
|
||||
/// </summary>
|
||||
/// <param name="tableName">The table name</param>
|
||||
/// <param name="columns">The columns of the table</param>
|
||||
/// <returns></returns>
|
||||
public void CreateTable(string tableName, params string[] columns)
|
||||
{
|
||||
|
||||
var cmd = Connection.CreateCommand();
|
||||
cmd.CommandText = $"CREATE TABLE IF NOT EXISTS {tableName} ({string.Join(", ", columns)})";
|
||||
cmd.ExecuteNonQuery();
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Execute a custom query
|
||||
/// </summary>
|
||||
/// <param name="query">The query</param>
|
||||
/// <returns>The number of rows that the query modified</returns>
|
||||
public async Task<int> ExecuteAsync(string query)
|
||||
{
|
||||
if (!Connection.State.HasFlag(System.Data.ConnectionState.Open))
|
||||
if (!Connection.State.HasFlag(ConnectionState.Open))
|
||||
await Connection.OpenAsync();
|
||||
var command = new SQLiteCommand(query, Connection);
|
||||
int answer = await command.ExecuteNonQueryAsync();
|
||||
var answer = await command.ExecuteNonQueryAsync();
|
||||
return answer;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Execute a custom query
|
||||
/// </summary>
|
||||
/// <param name="query">The query</param>
|
||||
/// <returns>The number of rows that the query modified</returns>
|
||||
public int Execute(string query)
|
||||
{
|
||||
if (!Connection.State.HasFlag(System.Data.ConnectionState.Open))
|
||||
if (!Connection.State.HasFlag(ConnectionState.Open))
|
||||
Connection.Open();
|
||||
var command = new SQLiteCommand(query, Connection);
|
||||
int r = command.ExecuteNonQuery();
|
||||
var r = command.ExecuteNonQuery();
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
public async Task<string> ReadDataAsync(string query)
|
||||
/// <summary>
|
||||
/// Read data from the result table and return the first row
|
||||
/// </summary>
|
||||
/// <param name="query">The query</param>
|
||||
/// <returns>The result is a string that has all values separated by space character</returns>
|
||||
public async Task<string?> ReadDataAsync(string query)
|
||||
{
|
||||
if (!Connection.State.HasFlag(System.Data.ConnectionState.Open))
|
||||
if (!Connection.State.HasFlag(ConnectionState.Open))
|
||||
await Connection.OpenAsync();
|
||||
var command = new SQLiteCommand(query, Connection);
|
||||
var reader = await command.ExecuteReaderAsync();
|
||||
|
||||
object[] values = new object[reader.FieldCount];
|
||||
var values = new object[reader.FieldCount];
|
||||
if (reader.Read())
|
||||
{
|
||||
reader.GetValues(values);
|
||||
return string.Join<object>(" ", values);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public string ReadData(string query)
|
||||
/// <summary>
|
||||
/// Read data from the result table and return the first row
|
||||
/// </summary>
|
||||
/// <param name="query">The query</param>
|
||||
/// <returns>The result is a string that has all values separated by space character</returns>
|
||||
public string? ReadData(string query)
|
||||
{
|
||||
if (!Connection.State.HasFlag(System.Data.ConnectionState.Open))
|
||||
if (!Connection.State.HasFlag(ConnectionState.Open))
|
||||
Connection.Open();
|
||||
var command = new SQLiteCommand(query, Connection);
|
||||
var reader = command.ExecuteReader();
|
||||
|
||||
object[] values = new object[reader.FieldCount];
|
||||
var values = new object[reader.FieldCount];
|
||||
if (reader.Read())
|
||||
{
|
||||
reader.GetValues(values);
|
||||
return string.Join<object>(" ", values);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public async Task<object[]> ReadDataArrayAsync(string query)
|
||||
/// <summary>
|
||||
/// Read data from the result table and return the first row
|
||||
/// </summary>
|
||||
/// <param name="query">The query</param>
|
||||
/// <returns>The first row as separated items</returns>
|
||||
public async Task<object[]?> ReadDataArrayAsync(string query)
|
||||
{
|
||||
if (!Connection.State.HasFlag(System.Data.ConnectionState.Open))
|
||||
if (!Connection.State.HasFlag(ConnectionState.Open))
|
||||
await Connection.OpenAsync();
|
||||
var command = new SQLiteCommand(query, Connection);
|
||||
var reader = await command.ExecuteReaderAsync();
|
||||
|
||||
object[] values = new object[reader.FieldCount];
|
||||
var values = new object[reader.FieldCount];
|
||||
if (reader.Read())
|
||||
{
|
||||
reader.GetValues(values);
|
||||
return values;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public object[] ReadDataArray(string query)
|
||||
|
||||
/// <summary>
|
||||
/// Read data from the result table and return the first row
|
||||
/// </summary>
|
||||
/// <param name="query">The query</param>
|
||||
/// <returns>The first row as separated items</returns>
|
||||
public object[]? ReadDataArray(string query)
|
||||
{
|
||||
if (!Connection.State.HasFlag(System.Data.ConnectionState.Open))
|
||||
if (!Connection.State.HasFlag(ConnectionState.Open))
|
||||
Connection.Open();
|
||||
var command = new SQLiteCommand(query, Connection);
|
||||
var reader = command.ExecuteReader();
|
||||
|
||||
object[] values = new object[reader.FieldCount];
|
||||
var values = new object[reader.FieldCount];
|
||||
if (reader.Read())
|
||||
{
|
||||
reader.GetValues(values);
|
||||
return values;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read all rows from the result table and return them as a list of string arrays. The string arrays contain the
|
||||
/// values of each row
|
||||
/// </summary>
|
||||
/// <param name="query">The query</param>
|
||||
/// <returns>A list of string arrays representing the values that the query returns</returns>
|
||||
public async Task<List<string[]>?> ReadAllRowsAsync(string query)
|
||||
{
|
||||
if (!Connection.State.HasFlag(ConnectionState.Open))
|
||||
await Connection.OpenAsync();
|
||||
var command = new SQLiteCommand(query, Connection);
|
||||
var reader = await command.ExecuteReaderAsync();
|
||||
|
||||
if (!reader.HasRows)
|
||||
return null;
|
||||
|
||||
List<string[]> rows = new();
|
||||
while (await reader.ReadAsync())
|
||||
{
|
||||
var values = new string[reader.FieldCount];
|
||||
reader.GetValues(values);
|
||||
rows.Add(values);
|
||||
}
|
||||
|
||||
if (rows.Count == 0) return null;
|
||||
|
||||
return rows;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Discord.Commands;
|
||||
using PluginManager.Others;
|
||||
|
||||
namespace PluginManager.Interfaces;
|
||||
|
||||
@@ -36,16 +35,16 @@ public interface DBCommand
|
||||
/// <summary>
|
||||
/// The main body of the command. This is what is executed when user calls the command in Server
|
||||
/// </summary>
|
||||
/// <param name="context">The disocrd Context</param>
|
||||
void ExecuteServer(SocketCommandContext context)
|
||||
/// <param name="args">The disocrd Context</param>
|
||||
void ExecuteServer(DBCommandExecutingArguments args)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The main body of the command. This is what is executed when user calls the command in DM
|
||||
/// </summary>
|
||||
/// <param name="context">The disocrd Context</param>
|
||||
void ExecuteDM(SocketCommandContext context)
|
||||
/// <param name="args">The disocrd Context</param>
|
||||
void ExecuteDM(DBCommandExecutingArguments args)
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,9 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Discord;
|
||||
using Discord.WebSocket;
|
||||
|
||||
namespace PluginManager.Interfaces
|
||||
{
|
||||
namespace PluginManager.Interfaces;
|
||||
|
||||
public interface DBSlashCommand
|
||||
{
|
||||
string Name { get; }
|
||||
@@ -16,10 +15,7 @@ namespace PluginManager.Interfaces
|
||||
|
||||
void ExecuteServer(SocketSlashCommand context)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void ExecuteDM(SocketSlashCommand context) { }
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
17
PluginManager/Interfaces/IInternalAction.cs
Normal file
17
PluginManager/Interfaces/IInternalAction.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System.Threading.Tasks;
|
||||
using PluginManager.Others;
|
||||
|
||||
namespace PluginManager.Interfaces;
|
||||
|
||||
public interface ICommandAction
|
||||
{
|
||||
public string ActionName { get; }
|
||||
|
||||
public string? Description { get; }
|
||||
|
||||
public string? Usage { get; }
|
||||
|
||||
public InternalActionRunType RunType { get; }
|
||||
|
||||
public Task Execute(string[]? args);
|
||||
}
|
||||
15
PluginManager/Interfaces/Logger/ILog.cs
Normal file
15
PluginManager/Interfaces/Logger/ILog.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using PluginManager.Others;
|
||||
|
||||
namespace PluginManager.Interfaces.Logger;
|
||||
|
||||
internal interface ILog
|
||||
{
|
||||
string Message { get; set; }
|
||||
string OutputFile { get; set; }
|
||||
|
||||
Type? Source { get; set; }
|
||||
|
||||
LogType Type { get; set; }
|
||||
DateTime ThrowTime { get; set; }
|
||||
}
|
||||
17
PluginManager/Interfaces/Logger/ILogger.cs
Normal file
17
PluginManager/Interfaces/Logger/ILogger.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using PluginManager.Others;
|
||||
using PluginManager.Others.Logger;
|
||||
|
||||
namespace PluginManager.Interfaces.Logger;
|
||||
|
||||
internal interface ILogger
|
||||
{
|
||||
bool IsEnabled { get; init; }
|
||||
bool OutputToFile { get; init; }
|
||||
|
||||
event EventHandler<Log> OnLog;
|
||||
void Log(
|
||||
string message = "", string outputFile = "", Type? source = default, LogType type = LogType.INFO,
|
||||
DateTime throwTime = default);
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
using Discord.WebSocket;
|
||||
|
||||
namespace PluginManager.Items;
|
||||
|
||||
public class Command
|
||||
{
|
||||
/// <summary>
|
||||
/// The author of the command
|
||||
/// </summary>
|
||||
public SocketUser? Author;
|
||||
|
||||
/// <summary>
|
||||
/// The Command class contructor
|
||||
/// </summary>
|
||||
/// <param name="message">The message that was sent</param>
|
||||
public Command(SocketMessage message)
|
||||
{
|
||||
Author = message.Author;
|
||||
var data = message.Content.Split(' ');
|
||||
Arguments = data.Length > 1 ? new List<string>(string.Join(' ', data, 1, data.Length - 1).Split(' ')) : new List<string>();
|
||||
CommandName = data[0].Substring(1);
|
||||
PrefixUsed = data[0][0];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The list of arguments
|
||||
/// </summary>
|
||||
public List<string> Arguments { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The command that is executed
|
||||
/// </summary>
|
||||
public string CommandName { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The prefix that is used for the command
|
||||
/// </summary>
|
||||
public char PrefixUsed { get; }
|
||||
}
|
||||
|
||||
public class ConsoleCommand
|
||||
{
|
||||
public string CommandName { get; init; }
|
||||
public string Description { get; init; }
|
||||
public string Usage { get; init; }
|
||||
public Action<string[]> Action { get; init; }
|
||||
}
|
||||
@@ -1,506 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Discord.WebSocket;
|
||||
|
||||
using PluginManager.Interfaces;
|
||||
using PluginManager.Loaders;
|
||||
using PluginManager.Online;
|
||||
using PluginManager.Others;
|
||||
|
||||
using OperatingSystem = PluginManager.Others.OperatingSystem;
|
||||
|
||||
namespace PluginManager.Items;
|
||||
|
||||
public class ConsoleCommandsHandler
|
||||
{
|
||||
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 bool isDownloading;
|
||||
private static bool pluginsLoaded;
|
||||
private readonly DiscordSocketClient? client;
|
||||
|
||||
public ConsoleCommandsHandler(DiscordSocketClient client)
|
||||
{
|
||||
this.client = client;
|
||||
InitializeBasicCommands();
|
||||
|
||||
|
||||
//Settings.Variables.outputStream.WriteLine("Initialized console command handler !");
|
||||
}
|
||||
|
||||
private void InitializeBasicCommands()
|
||||
{
|
||||
commandList.Clear();
|
||||
|
||||
AddCommand("help", "Show help", "help <command>", args =>
|
||||
{
|
||||
if (args.Length <= 1)
|
||||
{
|
||||
Settings.Variables.outputStream.WriteLine("Available commands:");
|
||||
var items = new List<string[]>();
|
||||
items.Add(new[] { "-", "-", "-" });
|
||||
items.Add(new[] { "Command", "Description", "Usage" });
|
||||
items.Add(new[] { " ", " ", "Argument type: <optional> [required]" });
|
||||
items.Add(new[] { "-", "-", "-" });
|
||||
|
||||
foreach (var command in commandList)
|
||||
{
|
||||
var pa = from p in command.Action.Method.GetParameters()
|
||||
where p.Name != null
|
||||
select p.ParameterType.FullName;
|
||||
items.Add(new[] { command.CommandName, command.Description, command.Usage });
|
||||
}
|
||||
|
||||
items.Add(new[] { "-", "-", "-" });
|
||||
Utilities.FormatAndAlignTable(items, TableFormat.DEFAULT);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var command in commandList)
|
||||
if (command.CommandName == args[1])
|
||||
{
|
||||
Settings.Variables.outputStream.WriteLine("Command description: " + command.Description);
|
||||
Settings.Variables.outputStream.WriteLine("Command execution format:" + command.Usage);
|
||||
return;
|
||||
}
|
||||
|
||||
Settings.Variables.outputStream.WriteLine("Command not found");
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
AddCommand("lp", "Load plugins", () =>
|
||||
{
|
||||
if (pluginsLoaded)
|
||||
return;
|
||||
var loader = new PluginLoader(client!);
|
||||
var cc = Console.ForegroundColor;
|
||||
loader.onCMDLoad += (name, typeName, success, exception) =>
|
||||
{
|
||||
if (name == null || name.Length < 2)
|
||||
name = typeName;
|
||||
if (success)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
Settings.Variables.outputStream.WriteLine("[CMD] Successfully loaded command : " + name);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
if (exception is null)
|
||||
Settings.Variables.outputStream.WriteLine("An error occured while loading: " + name);
|
||||
else
|
||||
Settings.Variables.outputStream.WriteLine("[CMD] Failed to load command : " + name + " because " + exception!.Message);
|
||||
}
|
||||
|
||||
Console.ForegroundColor = cc;
|
||||
};
|
||||
loader.onEVELoad += (name, typeName, success, exception) =>
|
||||
{
|
||||
if (name == null || name.Length < 2)
|
||||
name = typeName;
|
||||
|
||||
if (success)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
Settings.Variables.outputStream.WriteLine("[EVENT] Successfully loaded event : " + name);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Settings.Variables.outputStream.WriteLine("[EVENT] Failed to load event : " + name + " because " + exception!.Message);
|
||||
}
|
||||
|
||||
Console.ForegroundColor = cc;
|
||||
};
|
||||
|
||||
loader.onSLSHLoad += (name, typeName, success, exception) =>
|
||||
{
|
||||
if (name == null || name.Length < 2)
|
||||
name = typeName;
|
||||
|
||||
if (success)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Green;
|
||||
Settings.Variables.outputStream.WriteLine("[SLASH] Successfully loaded command : " + name);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Settings.Variables.outputStream.WriteLine("[SLASH] Failed to load command : " + name + " because " + exception!.Message);
|
||||
}
|
||||
|
||||
Console.ForegroundColor = cc;
|
||||
};
|
||||
|
||||
loader.LoadPlugins();
|
||||
Console.ForegroundColor = cc;
|
||||
pluginsLoaded = true;
|
||||
}
|
||||
);
|
||||
|
||||
AddCommand("listplugs", "list available plugins", () => { manager.ListAvailablePlugins().Wait(); });
|
||||
|
||||
AddCommand("dwplug", "download plugin", "dwplug [name]", async args =>
|
||||
{
|
||||
isDownloading = true;
|
||||
if (args.Length == 1)
|
||||
{
|
||||
isDownloading = false;
|
||||
Settings.Variables.outputStream.WriteLine("Please specify plugin name");
|
||||
return;
|
||||
}
|
||||
|
||||
var name = string.Join(' ', args, 1, args.Length - 1);
|
||||
// info[0] = plugin type
|
||||
// info[1] = plugin link
|
||||
// info[2] = if others are required, or string.Empty if none
|
||||
var info = await manager.GetPluginLinkByName(name);
|
||||
if (info[1] == null) // link is null
|
||||
{
|
||||
if (name == "")
|
||||
{
|
||||
isDownloading = false;
|
||||
Utilities.WriteColorText("Name is invalid");
|
||||
return;
|
||||
}
|
||||
|
||||
isDownloading = false;
|
||||
Utilities.WriteColorText($"Failed to find plugin &b{name} &c!" +
|
||||
" Use &glistplugs &ccommand to display all available plugins !");
|
||||
return;
|
||||
}
|
||||
|
||||
string path;
|
||||
if (info[0] == "Plugin")
|
||||
path = "./Data/Plugins/" + name + ".dll";
|
||||
else
|
||||
path = $"./{info[1].Split('/')[info[1].Split('/').Length - 1]}";
|
||||
|
||||
if (OperatingSystem.WINDOWS == Functions.GetOperatingSystem())
|
||||
{
|
||||
await ServerCom.DownloadFileAsync(info[1], path);
|
||||
}
|
||||
else if (OperatingSystem.LINUX == Functions.GetOperatingSystem())
|
||||
{
|
||||
var bar = new Utilities.ProgressBar(ProgressBarType.NO_END);
|
||||
bar.Start();
|
||||
await ServerCom.DownloadFileNoProgressAsync(info[1], path);
|
||||
bar.Stop("Plugin Downloaded !");
|
||||
}
|
||||
|
||||
|
||||
Settings.Variables.outputStream.WriteLine("\n");
|
||||
|
||||
// check requirements if any
|
||||
|
||||
if (info.Length == 3 && info[2] != string.Empty && info[2] != null)
|
||||
{
|
||||
Settings.Variables.outputStream.WriteLine($"Downloading requirements for plugin : {name}");
|
||||
|
||||
var lines = await ServerCom.ReadTextFromURL(info[2]);
|
||||
|
||||
foreach (var line in lines)
|
||||
{
|
||||
if (!(line.Length > 0 && line.Contains(",")))
|
||||
continue;
|
||||
var split = line.Split(',');
|
||||
Settings.Variables.outputStream.WriteLine($"\nDownloading item: {split[1]}");
|
||||
if (File.Exists("./" + split[1])) File.Delete("./" + split[1]);
|
||||
if (OperatingSystem.WINDOWS == Functions.GetOperatingSystem())
|
||||
{
|
||||
await ServerCom.DownloadFileAsync(split[0], "./" + split[1]);
|
||||
}
|
||||
else if (OperatingSystem.LINUX == Functions.GetOperatingSystem())
|
||||
{
|
||||
var bar = new Utilities.ProgressBar(ProgressBarType.NO_END);
|
||||
bar.Start();
|
||||
await ServerCom.DownloadFileNoProgressAsync(split[0], "./" + split[1]);
|
||||
bar.Stop("Item downloaded !");
|
||||
}
|
||||
|
||||
Settings.Variables.outputStream.WriteLine();
|
||||
if (split[0].EndsWith(".pak"))
|
||||
{
|
||||
File.Move("./" + split[1], "./Data/PAKS/" + split[1], true);
|
||||
}
|
||||
else if (split[0].EndsWith(".zip") || split[0].EndsWith(".pkg"))
|
||||
{
|
||||
Settings.Variables.outputStream.WriteLine($"Extracting {split[1]} ...");
|
||||
var bar = new Utilities.ProgressBar(
|
||||
ProgressBarType.NO_END);
|
||||
bar.Start();
|
||||
await Functions.ExtractArchive("./" + split[1], "./", null,
|
||||
UnzipProgressType.PercentageFromTotalSize);
|
||||
bar.Stop("Extracted");
|
||||
Settings.Variables.outputStream.WriteLine("\n");
|
||||
File.Delete("./" + split[1]);
|
||||
}
|
||||
}
|
||||
|
||||
Settings.Variables.outputStream.WriteLine();
|
||||
}
|
||||
|
||||
var ver = await ServerCom.GetVersionOfPackageFromWeb(name);
|
||||
if (ver is null) throw new Exception("Incorrect version");
|
||||
await Config.Plugins.SetVersionAsync(name, ver);
|
||||
|
||||
isDownloading = false;
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
AddCommand("value", "read value from VariableStack", "value [key]", args =>
|
||||
{
|
||||
if (args.Length != 2)
|
||||
return;
|
||||
if (!Config.Variables.Exists(args[1]))
|
||||
return;
|
||||
|
||||
var data = Config.Variables.GetValue(args[1]);
|
||||
Settings.Variables.outputStream.WriteLine($"{args[1]} => {data}");
|
||||
}
|
||||
);
|
||||
|
||||
AddCommand("add", "add variable to the system variables", "add [key] [value] [isReadOnly=true/false]", args =>
|
||||
{
|
||||
if (args.Length < 4)
|
||||
return;
|
||||
var key = args[1];
|
||||
var value = args[2];
|
||||
var isReadOnly = args[3].Equals("true", StringComparison.CurrentCultureIgnoreCase);
|
||||
|
||||
try
|
||||
{
|
||||
Config.Variables.Add(key, value, isReadOnly);
|
||||
Settings.Variables.outputStream.WriteLine($"Updated config file with the following command: {args[1]} => {value}");
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Settings.Variables.outputStream.WriteLine(ex.ToString());
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
AddCommand("remv", "remove variable from system variables", "remv [key]", args =>
|
||||
{
|
||||
if (args.Length < 2)
|
||||
return;
|
||||
Config.Variables.RemoveKey(args[1]);
|
||||
}
|
||||
);
|
||||
|
||||
AddCommand("sd", "Shuts down the discord bot", async () =>
|
||||
{
|
||||
if (client is null)
|
||||
return;
|
||||
var bar = new Utilities.ProgressBar(ProgressBarType.NO_END);
|
||||
|
||||
bar.Start();
|
||||
bar.Stop("Saved config !");
|
||||
Settings.Variables.outputStream.WriteLine();
|
||||
Settings.sqlDatabase.Stop();
|
||||
await client.StopAsync();
|
||||
await client.DisposeAsync();
|
||||
|
||||
await Task.Delay(1000);
|
||||
Environment.Exit(0);
|
||||
}
|
||||
);
|
||||
|
||||
AddCommand("import", "Load an external command", "import [pluginName]", async args =>
|
||||
{
|
||||
if (args.Length <= 1) return;
|
||||
try
|
||||
{
|
||||
var pName = string.Join(' ', args, 1, args.Length - 1);
|
||||
var client = new HttpClient();
|
||||
var url = (await manager.GetPluginLinkByName(pName))[1];
|
||||
if (url is null) throw new Exception($"Invalid plugin name {pName}.");
|
||||
var s = await client.GetStreamAsync(url);
|
||||
var str = new MemoryStream();
|
||||
await s.CopyToAsync(str);
|
||||
var asmb = Assembly.Load(str.ToArray());
|
||||
|
||||
var types = asmb.GetTypes();
|
||||
foreach (var type in types)
|
||||
if (type.IsClass && typeof(DBEvent).IsAssignableFrom(type))
|
||||
{
|
||||
var instance = (DBEvent)Activator.CreateInstance(type);
|
||||
instance.Start(this.client);
|
||||
Settings.Variables.outputStream.WriteLine($"[EVENT] Loaded external {type.FullName}!");
|
||||
}
|
||||
else if (type.IsClass && typeof(DBCommand).IsAssignableFrom(type))
|
||||
{
|
||||
var instance = (DBCommand)Activator.CreateInstance(type);
|
||||
Settings.Variables.outputStream.WriteLine($"[CMD] Instance: {type.FullName} loaded !");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Settings.Variables.outputStream.WriteLine(ex.Message);
|
||||
}
|
||||
});
|
||||
|
||||
AddCommand("remplug", "Remove a plugin", "remplug [plugName]", async args =>
|
||||
{
|
||||
if (args.Length <= 1) return;
|
||||
|
||||
isDownloading = true;
|
||||
var plugName = string.Join(' ', args, 1, args.Length - 1);
|
||||
if (pluginsLoaded)
|
||||
{
|
||||
if (Functions.GetOperatingSystem() == 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;
|
||||
}
|
||||
|
||||
|
||||
var location = $"./Data/Plugins/{plugName}.dll";
|
||||
|
||||
if (!File.Exists(location))
|
||||
{
|
||||
Settings.Variables.outputStream.WriteLine("The plugin does not exist");
|
||||
return;
|
||||
}
|
||||
|
||||
File.Delete(location);
|
||||
|
||||
Settings.Variables.outputStream.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]);
|
||||
|
||||
|
||||
Settings.Variables.outputStream.WriteLine("Removed: " + split[1]);
|
||||
}
|
||||
|
||||
if (Directory.Exists($"./Data/Plugins/{plugName}"))
|
||||
Directory.Delete($"./Data/Plugins/{plugName}", true);
|
||||
|
||||
if (Directory.Exists(plugName))
|
||||
Directory.Delete(plugName, true);
|
||||
}
|
||||
|
||||
isDownloading = false;
|
||||
Settings.Variables.outputStream.WriteLine(plugName + " has been successfully deleted !");
|
||||
});
|
||||
|
||||
AddCommand("reload", "Reload the bot with all plugins", () =>
|
||||
{
|
||||
if (Functions.GetOperatingSystem() == OperatingSystem.WINDOWS)
|
||||
{
|
||||
Process.Start("DiscordBot.exe", "lp");
|
||||
HandleCommand("sd");
|
||||
}
|
||||
else
|
||||
{
|
||||
Process.Start("./DiscordBot", "lp");
|
||||
HandleCommand("sd");
|
||||
}
|
||||
});
|
||||
|
||||
//AddCommand("");
|
||||
|
||||
//Sort the commands by name
|
||||
commandList.Sort((x, y) => x.CommandName.CompareTo(y.CommandName));
|
||||
}
|
||||
|
||||
public static void AddCommand(string command, string description, string usage, Action<string[]> action)
|
||||
{
|
||||
commandList.Add(new ConsoleCommand
|
||||
{ CommandName = command, Description = description, Action = action, Usage = usage });
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
Utilities.WriteColorText($"Command &r{command} &cadded to the list of commands");
|
||||
}
|
||||
|
||||
public static void AddCommand(string command, string description, Action action)
|
||||
{
|
||||
AddCommand(command, description, command, args => action());
|
||||
}
|
||||
|
||||
public static void RemoveCommand(string command)
|
||||
{
|
||||
commandList.RemoveAll(x => x.CommandName == command);
|
||||
}
|
||||
|
||||
public static bool CommandExists(string command)
|
||||
{
|
||||
return GetCommand(command) is not null;
|
||||
}
|
||||
|
||||
public static ConsoleCommand? GetCommand(string command)
|
||||
{
|
||||
return commandList.FirstOrDefault(t => t.CommandName == command);
|
||||
}
|
||||
|
||||
public 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);
|
||||
while (isDownloading) await Task.Delay(1000);
|
||||
}
|
||||
}
|
||||
|
||||
public bool HandleCommand(string command, bool removeCommandExecution = true)
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
var args = command.Split(' ');
|
||||
foreach (var item in commandList.ToList())
|
||||
if (item.CommandName == args[0])
|
||||
{
|
||||
if (removeCommandExecution)
|
||||
{
|
||||
Console.SetCursorPosition(0, Console.CursorTop - 1);
|
||||
for (var i = 0; i < command.Length + 30; i++)
|
||||
Settings.Variables.outputStream.Write(" ");
|
||||
Console.SetCursorPosition(0, Console.CursorTop);
|
||||
}
|
||||
|
||||
Settings.Variables.outputStream.WriteLine();
|
||||
item.Action(args);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
//Settings.Variables.outputStream.WriteLine($"Executing: {args[0]} with the following parameters: {args.MergeStrings(1)}");
|
||||
}
|
||||
}
|
||||
72
PluginManager/Loaders/ActionsLoader.cs
Normal file
72
PluginManager/Loaders/ActionsLoader.cs
Normal file
@@ -0,0 +1,72 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using PluginManager.Interfaces;
|
||||
using PluginManager.Others;
|
||||
|
||||
namespace PluginManager.Loaders;
|
||||
|
||||
public class ActionsLoader
|
||||
{
|
||||
public delegate void ActionLoaded(string name, string typeName, bool success, Exception? e = null);
|
||||
|
||||
private readonly string actionExtension = "dll";
|
||||
|
||||
private readonly string actionFolder = @"./Data/Plugins/";
|
||||
|
||||
public ActionsLoader(string path, string extension)
|
||||
{
|
||||
actionFolder = path;
|
||||
actionExtension = extension;
|
||||
}
|
||||
|
||||
public event ActionLoaded? ActionLoadedEvent;
|
||||
|
||||
public async Task<List<ICommandAction>?> Load()
|
||||
{
|
||||
Directory.CreateDirectory(actionFolder);
|
||||
var files = Directory.GetFiles(actionFolder, $"*.{actionExtension}", SearchOption.AllDirectories);
|
||||
|
||||
var actions = new List<ICommandAction>();
|
||||
|
||||
foreach (var file in files)
|
||||
try
|
||||
{
|
||||
Assembly.LoadFrom(file);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ActionLoadedEvent?.Invoke(file, "", false, e);
|
||||
}
|
||||
|
||||
var types = AppDomain.CurrentDomain.GetAssemblies()
|
||||
.SelectMany(s => s.GetTypes())
|
||||
.Where(p => typeof(ICommandAction).IsAssignableFrom(p) && !p.IsInterface);
|
||||
|
||||
foreach (var type in types)
|
||||
try
|
||||
{
|
||||
var action = (ICommandAction)Activator.CreateInstance(type);
|
||||
if (action.ActionName == null)
|
||||
{
|
||||
ActionLoadedEvent?.Invoke(action.ActionName, type.Name, false);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (action.RunType == InternalActionRunType.ON_STARTUP)
|
||||
await action.Execute(null);
|
||||
|
||||
ActionLoadedEvent?.Invoke(action.ActionName, type.Name, true);
|
||||
actions.Add(action);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
ActionLoadedEvent?.Invoke(type.Name, type.Name, false, e);
|
||||
}
|
||||
|
||||
return actions;
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
using PluginManager.Interfaces;
|
||||
using PluginManager.Others;
|
||||
|
||||
namespace PluginManager.Loaders;
|
||||
@@ -17,7 +17,7 @@ internal class LoaderArgs : EventArgs
|
||||
internal object? Plugin { get; init; }
|
||||
}
|
||||
|
||||
internal class Loader<T>
|
||||
internal class Loader
|
||||
{
|
||||
internal Loader(string path, string extension)
|
||||
{
|
||||
@@ -33,25 +33,38 @@ internal class Loader<T>
|
||||
|
||||
internal event PluginLoadedEventHandler? PluginLoaded;
|
||||
|
||||
internal List<T>? Load()
|
||||
|
||||
internal (List<DBEvent>?, List<DBCommand>?, List<DBSlashCommand>?) Load()
|
||||
{
|
||||
var list = new List<T>();
|
||||
List<DBEvent> events = new();
|
||||
List<DBSlashCommand> slashCommands = new();
|
||||
List<DBCommand> commands = new();
|
||||
|
||||
if (!Directory.Exists(path))
|
||||
{
|
||||
Directory.CreateDirectory(path);
|
||||
return null;
|
||||
return (null, null, null);
|
||||
}
|
||||
|
||||
var files = Directory.GetFiles(path, $"*.{extension}", SearchOption.AllDirectories);
|
||||
foreach (var file in files)
|
||||
{
|
||||
try
|
||||
{
|
||||
Assembly.LoadFrom(file);
|
||||
}
|
||||
catch
|
||||
{
|
||||
Config.Logger.Log("PluginName: " + new FileInfo(file).Name.Split('.')[0] + " not loaded", source: typeof(Loader), type: LogType.ERROR);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (FileLoaded != null)
|
||||
{
|
||||
var args = new LoaderArgs
|
||||
{
|
||||
Exception = null,
|
||||
TypeName = nameof(T),
|
||||
TypeName = null,
|
||||
IsLoaded = false,
|
||||
PluginName = new FileInfo(file).Name.Split('.')[0],
|
||||
Plugin = null
|
||||
@@ -60,6 +73,15 @@ internal class Loader<T>
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return (LoadItems<DBEvent>(), LoadItems<DBCommand>(), LoadItems<DBSlashCommand>());
|
||||
}
|
||||
|
||||
internal List<T> LoadItems<T>()
|
||||
{
|
||||
List<T> list = new();
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
var interfaceType = typeof(T);
|
||||
@@ -83,7 +105,10 @@ internal class Loader<T>
|
||||
Exception = null,
|
||||
IsLoaded = true,
|
||||
PluginName = type.FullName,
|
||||
TypeName = nameof(T),
|
||||
TypeName = typeof(T) == typeof(DBCommand) ? "DBCommand" :
|
||||
typeof(T) == typeof(DBEvent) ? "DBEvent" :
|
||||
typeof(T) == typeof(DBSlashCommand) ? "DBSlashCommand" :
|
||||
null,
|
||||
Plugin = plugin
|
||||
}
|
||||
);
|
||||
@@ -99,14 +124,17 @@ internal class Loader<T>
|
||||
TypeName = nameof(T)
|
||||
});
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Functions.WriteErrFile(ex.ToString());
|
||||
Config.Logger.Log(ex.Message, source: typeof(Loader), type: LogType.ERROR);
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
return list;
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,127 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
|
||||
using PluginManager.Interfaces;
|
||||
using PluginManager.Others;
|
||||
|
||||
namespace PluginManager.Loaders
|
||||
{
|
||||
internal class LoaderV2
|
||||
{
|
||||
internal LoaderV2(string path, string extension)
|
||||
{
|
||||
this.path = path;
|
||||
this.extension = extension;
|
||||
}
|
||||
|
||||
|
||||
private string path { get; }
|
||||
private string extension { get; }
|
||||
|
||||
internal event FileLoadedEventHandler? FileLoaded;
|
||||
|
||||
internal event PluginLoadedEventHandler? PluginLoaded;
|
||||
|
||||
|
||||
internal delegate void FileLoadedEventHandler(LoaderArgs args);
|
||||
|
||||
internal delegate void PluginLoadedEventHandler(LoaderArgs args);
|
||||
|
||||
|
||||
internal (List<DBEvent>?, List<DBCommand>?, List<DBSlashCommand>?) Load()
|
||||
{
|
||||
|
||||
List<DBEvent> events = new();
|
||||
List<DBSlashCommand> slashCommands = new();
|
||||
List<DBCommand> commands = new();
|
||||
|
||||
if (!Directory.Exists(path))
|
||||
{
|
||||
Directory.CreateDirectory(path);
|
||||
return (null, null, null);
|
||||
}
|
||||
|
||||
var files = Directory.GetFiles(path, $"*.{extension}", SearchOption.AllDirectories);
|
||||
foreach (var file in files)
|
||||
{
|
||||
Assembly.LoadFrom(file);
|
||||
if (FileLoaded != null)
|
||||
{
|
||||
var args = new LoaderArgs
|
||||
{
|
||||
Exception = null,
|
||||
TypeName = null,
|
||||
IsLoaded = false,
|
||||
PluginName = new FileInfo(file).Name.Split('.')[0],
|
||||
Plugin = null
|
||||
};
|
||||
FileLoaded.Invoke(args);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
return (LoadItems<DBEvent>(), LoadItems<DBCommand>(), LoadItems<DBSlashCommand>());
|
||||
}
|
||||
|
||||
internal List<T> LoadItems<T>()
|
||||
{
|
||||
List<T> list = new();
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
var interfaceType = typeof(T);
|
||||
var types = AppDomain.CurrentDomain.GetAssemblies()
|
||||
.SelectMany(a => a.GetTypes())
|
||||
.Where(p => interfaceType.IsAssignableFrom(p) && p.IsClass)
|
||||
.ToArray();
|
||||
|
||||
|
||||
list.Clear();
|
||||
foreach (var type in types)
|
||||
try
|
||||
{
|
||||
var plugin = (T)Activator.CreateInstance(type)!;
|
||||
list.Add(plugin);
|
||||
|
||||
|
||||
if (PluginLoaded != null)
|
||||
PluginLoaded.Invoke(new LoaderArgs
|
||||
{
|
||||
Exception = null,
|
||||
IsLoaded = true,
|
||||
PluginName = type.FullName,
|
||||
TypeName = typeof(T) == typeof(DBCommand) ? "DBCommand" : typeof(T) == typeof(DBEvent) ? "DBEvent" : "DBSlashCommand",
|
||||
Plugin = plugin
|
||||
}
|
||||
);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (PluginLoaded != null)
|
||||
PluginLoaded.Invoke(new LoaderArgs
|
||||
{
|
||||
Exception = ex,
|
||||
IsLoaded = false,
|
||||
PluginName = type.FullName,
|
||||
TypeName = nameof(T)
|
||||
});
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Functions.WriteErrFile(ex.ToString());
|
||||
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,10 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Discord;
|
||||
using Discord.WebSocket;
|
||||
|
||||
using PluginManager.Interfaces;
|
||||
using PluginManager.Online;
|
||||
using PluginManager.Online.Updates;
|
||||
using PluginManager.Others;
|
||||
|
||||
namespace PluginManager.Loaders;
|
||||
@@ -66,39 +62,36 @@ public class PluginLoader
|
||||
/// </summary>
|
||||
public static List<DBSlashCommand>? SlashCommands { get; set; }
|
||||
|
||||
public static int PluginsLoaded
|
||||
{
|
||||
get
|
||||
{
|
||||
var count = 0;
|
||||
if (Commands is not null)
|
||||
count += Commands.Count;
|
||||
if (Events is not null)
|
||||
count += Events.Count;
|
||||
if (SlashCommands is not null)
|
||||
count += SlashCommands.Count;
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The main mathod that is called to load all events
|
||||
/// </summary>
|
||||
public async void LoadPlugins()
|
||||
{
|
||||
//Check for updates in commands
|
||||
foreach (var file in Directory.GetFiles("./Data/Plugins/", $"*.{pluginExtension}",
|
||||
SearchOption.AllDirectories))
|
||||
await Task.Run(async () =>
|
||||
{
|
||||
var name = new FileInfo(file).Name.Split('.')[0];
|
||||
var version = await ServerCom.GetVersionOfPackageFromWeb(name);
|
||||
if (version is null)
|
||||
return;
|
||||
if (Config.Plugins.GetVersion(name) is not null)
|
||||
Config.Plugins.SetVersion(name, version);
|
||||
|
||||
if (await PluginUpdater.CheckForUpdates(name))
|
||||
await PluginUpdater.Download(name);
|
||||
});
|
||||
|
||||
|
||||
//Load all plugins
|
||||
|
||||
Commands = new List<DBCommand>();
|
||||
Events = new List<DBEvent>();
|
||||
SlashCommands = new List<DBSlashCommand>();
|
||||
|
||||
Functions.WriteLogFile("Starting plugin loader ... Client: " + _client.CurrentUser.Username);
|
||||
Settings.Variables.outputStream.WriteLine("Loading plugins");
|
||||
Config.Logger.Log("Starting plugin loader ... Client: " + _client.CurrentUser.Username, source: typeof(PluginLoader), type: LogType.INFO);
|
||||
|
||||
var loader = new LoaderV2("./Data/Plugins", "dll");
|
||||
loader.FileLoaded += (args) => Functions.WriteLogFile($"{args.PluginName} file Loaded");
|
||||
var loader = new Loader("./Data/Plugins", "dll");
|
||||
loader.FileLoaded += args => Config.Logger.Log($"{args.PluginName} file Loaded", source: typeof(PluginLoader), type: LogType.INFO);
|
||||
loader.PluginLoaded += Loader_PluginLoaded;
|
||||
var res = loader.Load();
|
||||
Events = res.Item1;
|
||||
@@ -108,7 +101,6 @@ public class PluginLoader
|
||||
|
||||
private async void Loader_PluginLoaded(LoaderArgs args)
|
||||
{
|
||||
// Settings.Variables.outputStream.WriteLine(args.TypeName);
|
||||
switch (args.TypeName)
|
||||
{
|
||||
case "DBCommand":
|
||||
@@ -124,28 +116,67 @@ public class PluginLoader
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Settings.Variables.outputStream.WriteLine(ex.ToString());
|
||||
Settings.Variables.outputStream.WriteLine("Plugin: " + args.PluginName);
|
||||
Settings.Variables.outputStream.WriteLine("Type: " + args.TypeName);
|
||||
Settings.Variables.outputStream.WriteLine("IsLoaded: " + args.IsLoaded);
|
||||
Config.Logger.Log(ex.Message, source: typeof(PluginLoader), type: LogType.ERROR);
|
||||
}
|
||||
|
||||
break;
|
||||
case "DBSlashCommand":
|
||||
if (args.IsLoaded)
|
||||
{
|
||||
var slash = (DBSlashCommand)args.Plugin;
|
||||
SlashCommandBuilder builder = new SlashCommandBuilder();
|
||||
var builder = new SlashCommandBuilder();
|
||||
builder.WithName(slash.Name);
|
||||
builder.WithDescription(slash.Description);
|
||||
builder.WithDMPermission(slash.canUseDM);
|
||||
builder.Options = slash.Options;
|
||||
//Settings.Variables.outputStream.WriteLine("Loaded " + slash.Name);
|
||||
onSLSHLoad?.Invoke(((DBSlashCommand)args.Plugin!).Name, args.TypeName, args.IsLoaded, args.Exception);
|
||||
|
||||
onSLSHLoad?.Invoke(((DBSlashCommand)args.Plugin!).Name, args.TypeName, args.IsLoaded,
|
||||
args.Exception);
|
||||
await _client.CreateGlobalApplicationCommandAsync(builder.Build());
|
||||
|
||||
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public static async Task LoadPluginFromAssembly(Assembly asmb, DiscordSocketClient client)
|
||||
{
|
||||
var types = asmb.GetTypes();
|
||||
foreach (var type in types)
|
||||
try
|
||||
{
|
||||
if (type.IsClass && typeof(DBEvent).IsAssignableFrom(type))
|
||||
{
|
||||
var instance = (DBEvent)Activator.CreateInstance(type);
|
||||
instance.Start(client);
|
||||
Events.Add(instance);
|
||||
Config.Logger.Log($"[EVENT] Loaded external {type.FullName}!", source: typeof(PluginLoader));
|
||||
}
|
||||
else if (type.IsClass && typeof(DBCommand).IsAssignableFrom(type))
|
||||
{
|
||||
var instance = (DBCommand)Activator.CreateInstance(type);
|
||||
Commands.Add(instance);
|
||||
Config.Logger.Log($"[CMD] Instance: {type.FullName} loaded !", source: typeof(PluginLoader));
|
||||
}
|
||||
else if (type.IsClass && typeof(DBSlashCommand).IsAssignableFrom(type))
|
||||
{
|
||||
var instance = (DBSlashCommand)Activator.CreateInstance(type);
|
||||
var builder = new SlashCommandBuilder();
|
||||
builder.WithName(instance.Name);
|
||||
builder.WithDescription(instance.Description);
|
||||
builder.WithDMPermission(instance.canUseDM);
|
||||
builder.Options = instance.Options;
|
||||
|
||||
await client.CreateGlobalApplicationCommandAsync(builder.Build());
|
||||
SlashCommands.Add(instance);
|
||||
Config.Logger.Log($"[SLASH] Instance: {type.FullName} loaded !", source: typeof(PluginLoader));
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//Console.WriteLine(ex.Message);
|
||||
Config.Logger.Log(ex.Message, source: typeof(PluginLoader), type: LogType.ERROR);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,8 @@ internal static class OnlineFunctions
|
||||
/// <param name="progress">The <see cref="IProgress{T}" /> that is used to track the download progress</param>
|
||||
/// <param name="cancellation">The cancellation token</param>
|
||||
/// <returns></returns>
|
||||
internal static async Task DownloadFileAsync(this HttpClient client, string url, Stream destination,
|
||||
internal static async Task DownloadFileAsync(
|
||||
this HttpClient client, string url, Stream destination,
|
||||
IProgress<float>? progress = null,
|
||||
IProgress<long>? downloadedBytes = null, int bufferSize = 81920,
|
||||
CancellationToken cancellation = default)
|
||||
@@ -34,20 +35,25 @@ internal static class OnlineFunctions
|
||||
if (progress == null || !contentLength.HasValue)
|
||||
{
|
||||
await download.CopyToAsync(destination, cancellation);
|
||||
if(!contentLength.HasValue)
|
||||
progress?.Report(100f);
|
||||
return;
|
||||
}
|
||||
|
||||
// Convert absolute progress (bytes downloaded) into relative progress (0% - 100%)
|
||||
var relativeProgress = new Progress<long>(totalBytes =>
|
||||
// total ... 100%
|
||||
// downloaded ... x%
|
||||
// x = downloaded * 100 / total => x = downloaded / total * 100
|
||||
var relativeProgress = new Progress<long>(totalBytesDownloaded =>
|
||||
{
|
||||
progress.Report((float)totalBytes / contentLength.Value * 100);
|
||||
downloadedBytes?.Report(totalBytes);
|
||||
progress?.Report(totalBytesDownloaded / (float)contentLength.Value * 100);
|
||||
downloadedBytes?.Report(totalBytesDownloaded);
|
||||
}
|
||||
);
|
||||
|
||||
// Use extension method to report progress while downloading
|
||||
await download.CopyToOtherStreamAsync(destination, bufferSize, relativeProgress, cancellation);
|
||||
progress.Report(1);
|
||||
progress.Report(100f);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,11 +12,25 @@ public class VersionString
|
||||
{
|
||||
var data = version.Split('.');
|
||||
try
|
||||
{
|
||||
if (data.Length == 3)
|
||||
{
|
||||
PackageVersionID = int.Parse(data[0]);
|
||||
PackageMainVersion = int.Parse(data[1]);
|
||||
PackageCheckVersion = int.Parse(data[2]);
|
||||
}
|
||||
else if (data.Length == 4)
|
||||
{
|
||||
// ignore the first item data[0]
|
||||
PackageVersionID = int.Parse(data[1]);
|
||||
PackageMainVersion = int.Parse(data[2]);
|
||||
PackageCheckVersion = int.Parse(data[3]);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception("Invalid version string");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine(version);
|
||||
@@ -24,6 +38,25 @@ public class VersionString
|
||||
}
|
||||
}
|
||||
|
||||
private bool Equals(VersionString other)
|
||||
{
|
||||
return PackageCheckVersion == other.PackageCheckVersion && PackageMainVersion == other.PackageMainVersion &&
|
||||
PackageVersionID == other.PackageVersionID;
|
||||
}
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj)) return false;
|
||||
if (ReferenceEquals(this, obj)) return true;
|
||||
if (obj.GetType() != GetType()) return false;
|
||||
return Equals((VersionString)obj);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(PackageCheckVersion, PackageMainVersion, PackageVersionID);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "{PackageID: " + PackageVersionID + ", PackageVersion: " + PackageMainVersion +
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using PluginManager.Online.Helpers;
|
||||
using PluginManager.Others;
|
||||
|
||||
using OperatingSystem = PluginManager.Others.OperatingSystem;
|
||||
|
||||
namespace PluginManager.Online;
|
||||
@@ -14,10 +12,21 @@ public class PluginsManager
|
||||
/// <summary>
|
||||
/// The Plugin Manager constructor
|
||||
/// </summary>
|
||||
/// <param name="link">The link to the file where all plugins are stored</param>
|
||||
public PluginsManager(string link)
|
||||
/// <param name="plink">The link to the file where all plugins are stored</param>
|
||||
/// <param name="vlink">The link to the file where all plugin versions are stored</param>
|
||||
public PluginsManager(string plink, string vlink)
|
||||
{
|
||||
PluginsLink = link;
|
||||
PluginsLink = plink;
|
||||
VersionsLink = vlink;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The default Plugin Manager constructor. It uses the default links.
|
||||
/// </summary>
|
||||
public PluginsManager()
|
||||
{
|
||||
PluginsLink = "https://raw.githubusercontent.com/andreitdr/SethPlugins/releases/PluginsList";
|
||||
VersionsLink = "https://raw.githubusercontent.com/andreitdr/SethPlugins/releases/Versions";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -25,12 +34,15 @@ public class PluginsManager
|
||||
/// </summary>
|
||||
public string PluginsLink { get; }
|
||||
|
||||
public string VersionsLink { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The method to load all plugins
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public async Task ListAvailablePlugins()
|
||||
public async Task<List<string[]>> GetAvailablePlugins()
|
||||
{
|
||||
// Config.Logger.Log("Got data from " + VersionsLink, this, LogLevel.INFO);
|
||||
try
|
||||
{
|
||||
var list = await ServerCom.ReadTextFromURL(PluginsLink);
|
||||
@@ -40,16 +52,12 @@ public class PluginsManager
|
||||
var op = Functions.GetOperatingSystem();
|
||||
|
||||
var len = lines.Length;
|
||||
string[] titles = { "Name", "Description", "Type", "Version" };
|
||||
data.Add(new[] { "-", "-", "-", "-" });
|
||||
data.Add(titles);
|
||||
data.Add(new[] { "-", "-", "-", "-" });
|
||||
for (var i = 0; i < len; i++)
|
||||
{
|
||||
if (lines[i].Length <= 2)
|
||||
continue;
|
||||
var content = lines[i].Split(',');
|
||||
var display = new string[titles.Length];
|
||||
var display = new string[4]; // 4 columns
|
||||
if (op == OperatingSystem.WINDOWS)
|
||||
{
|
||||
if (content[4].Contains("Windows"))
|
||||
@@ -58,7 +66,7 @@ public class PluginsManager
|
||||
display[1] = content[1];
|
||||
display[2] = content[2];
|
||||
display[3] =
|
||||
(await ServerCom.GetVersionOfPackageFromWeb(content[0]) ?? new VersionString("0.0.0"))
|
||||
(await GetVersionOfPackageFromWeb(content[0]) ?? new VersionString("0.0.0"))
|
||||
.ToShortString();
|
||||
data.Add(display);
|
||||
}
|
||||
@@ -71,22 +79,39 @@ public class PluginsManager
|
||||
display[1] = content[1];
|
||||
display[2] = content[2];
|
||||
display[3] =
|
||||
(await ServerCom.GetVersionOfPackageFromWeb(content[0]) ?? new VersionString("0.0.0"))
|
||||
(await GetVersionOfPackageFromWeb(content[0]) ?? new VersionString("0.0.0"))
|
||||
.ToShortString();
|
||||
data.Add(display);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data.Add(new[] { "-", "-", "-", "-" });
|
||||
|
||||
Utilities.FormatAndAlignTable(data, TableFormat.CENTER_EACH_COLUMN_BASED);
|
||||
return data;
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Settings.Variables.outputStream.WriteLine("Failed to execute command: listplugs\nReason: " + exception.Message);
|
||||
Functions.WriteErrFile(exception.ToString());
|
||||
Config.Logger.Log(message: "Failed to execute command: listplugs\nReason: " + exception.Message, source: typeof(PluginsManager), type: LogType.ERROR );
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public async Task<VersionString?> GetVersionOfPackageFromWeb(string pakName)
|
||||
{
|
||||
var data = await ServerCom.ReadTextFromURL(VersionsLink);
|
||||
foreach (var item in data)
|
||||
{
|
||||
if (item.StartsWith("#"))
|
||||
continue;
|
||||
|
||||
var split = item.Split(',');
|
||||
if (split[0] == pakName)
|
||||
{
|
||||
// Config.Logger.Log("Searched for " + pakName + " and found " + split[1] + " as version.", LogLevel.INFO);
|
||||
return new VersionString(split[1]);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -104,7 +129,7 @@ public class PluginsManager
|
||||
for (var i = 0; i < len; i++)
|
||||
{
|
||||
var contents = lines[i].Split(',');
|
||||
if (contents[0] == name)
|
||||
if (contents[0].ToLowerInvariant() == name.ToLowerInvariant())
|
||||
{
|
||||
if (contents.Length == 6)
|
||||
return new[] { contents[2], contents[3], contents[5] };
|
||||
@@ -116,10 +141,9 @@ public class PluginsManager
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Settings.Variables.outputStream.WriteLine("Failed to execute command: listplugs\nReason: " + exception.Message);
|
||||
Functions.WriteErrFile(exception.ToString());
|
||||
Config.Logger.Log("Failed to execute command: plugin list\nReason: " + exception.Message, source: typeof(PluginsManager), type: LogType.ERROR);
|
||||
}
|
||||
|
||||
return new string[] { null!, null!, null! };
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -3,11 +3,8 @@ using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using PluginManager.Online.Helpers;
|
||||
using PluginManager.Others;
|
||||
|
||||
namespace PluginManager.Online;
|
||||
|
||||
@@ -32,8 +29,9 @@ public static class ServerCom
|
||||
/// <param name="location">The location where to store the downloaded data</param>
|
||||
/// <param name="progress">The <see cref="IProgress{T}" /> to track the download</param>
|
||||
/// <returns></returns>
|
||||
public static async Task DownloadFileAsync(string URL, string location, IProgress<float> progress,
|
||||
IProgress<long>? downloadedBytes = null)
|
||||
public static async Task DownloadFileAsync(
|
||||
string URL, string location, IProgress<float> progress,
|
||||
IProgress<long>? downloadedBytes)
|
||||
{
|
||||
using (var client = new HttpClient())
|
||||
{
|
||||
@@ -46,69 +44,9 @@ public static class ServerCom
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Download file from url
|
||||
/// </summary>
|
||||
/// <param name="URL">The url to the file</param>
|
||||
/// <param name="location">The location where to store the downloaded data</param>
|
||||
/// <returns></returns>
|
||||
public static async Task DownloadFileAsync(string URL, string location)
|
||||
public static async Task DownloadFileAsync(string URl, string location, IProgress<float> progress)
|
||||
{
|
||||
var isDownloading = true;
|
||||
float c_progress = 0;
|
||||
|
||||
var pbar = new Utilities.ProgressBar(ProgressBarType.NORMAL) { Max = 100f, NoColor = true };
|
||||
|
||||
IProgress<float> progress = new Progress<float>(percent => { c_progress = percent; });
|
||||
|
||||
|
||||
var updateProgressBarTask = new Task(() =>
|
||||
{
|
||||
while (isDownloading)
|
||||
{
|
||||
pbar.Update(c_progress);
|
||||
if (c_progress == 100f)
|
||||
break;
|
||||
Thread.Sleep(500);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
new Thread(updateProgressBarTask.Start).Start();
|
||||
await DownloadFileAsync(URL, location, progress);
|
||||
|
||||
|
||||
c_progress = pbar.Max;
|
||||
pbar.Update(100f);
|
||||
isDownloading = false;
|
||||
await DownloadFileAsync(URl, location, progress, null);
|
||||
}
|
||||
|
||||
public static async Task DownloadFileNoProgressAsync(string URL, string location)
|
||||
{
|
||||
IProgress<float> progress = new Progress<float>();
|
||||
await DownloadFileAsync(URL, location, progress);
|
||||
}
|
||||
|
||||
public static VersionString? GetVersionOfPackage(string pakName)
|
||||
{
|
||||
if (Config.Plugins.GetVersion(pakName) is null)
|
||||
return null;
|
||||
return new VersionString(Config.Plugins.GetVersion(pakName));
|
||||
}
|
||||
|
||||
public static async Task<VersionString?> GetVersionOfPackageFromWeb(string pakName)
|
||||
{
|
||||
var url = "https://raw.githubusercontent.com/Wizzy69/installer/discord-bot-files/Versions";
|
||||
var data = await ReadTextFromURL(url);
|
||||
foreach (var item in data)
|
||||
{
|
||||
if (item.StartsWith("#"))
|
||||
continue;
|
||||
|
||||
string[] split = item.Split(',');
|
||||
if (split[0] == pakName)
|
||||
return new VersionString(split[1]);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -1,51 +0,0 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using PluginManager.Items;
|
||||
using PluginManager.Others;
|
||||
|
||||
namespace PluginManager.Online.Updates;
|
||||
|
||||
public class PluginUpdater
|
||||
{
|
||||
public static async Task<bool> CheckForUpdates(string pakName)
|
||||
{
|
||||
try
|
||||
{
|
||||
var webV = await ServerCom.GetVersionOfPackageFromWeb(pakName);
|
||||
var local = ServerCom.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)
|
||||
{
|
||||
var url = "https://raw.githubusercontent.com/Wizzy69/installer/discord-bot-files/Versions";
|
||||
var info = await ServerCom.ReadTextFromURL(url);
|
||||
var version = await ServerCom.GetVersionOfPackageFromWeb(pakName);
|
||||
|
||||
if (version is null) return Update.Empty;
|
||||
var update = new Update(pakName, string.Join('\n', info), version);
|
||||
return update;
|
||||
}
|
||||
|
||||
public static async Task Download(string pakName)
|
||||
{
|
||||
Utilities.WriteColorText("An update was found for &g" + pakName + "&c. Version: &r" +
|
||||
(await ServerCom.GetVersionOfPackageFromWeb(pakName))?.ToShortString() +
|
||||
"&c. Current Version: &y" +
|
||||
ServerCom.GetVersionOfPackage(pakName)?.ToShortString());
|
||||
await ConsoleCommandsHandler.ExecuteCommad("dwplug " + pakName);
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
using System;
|
||||
using PluginManager.Online.Helpers;
|
||||
|
||||
namespace PluginManager.Online.Updates;
|
||||
|
||||
public class Update
|
||||
{
|
||||
public static Update Empty = new(null, null, null);
|
||||
|
||||
private readonly bool isEmpty;
|
||||
|
||||
public VersionString newVersion;
|
||||
public string pakName;
|
||||
public string UpdateMessage;
|
||||
|
||||
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 Exception("The update is EMPTY. Can not print information about an empty update !");
|
||||
return $"Package Name: {pakName}\n" +
|
||||
$"Update Message: {UpdateMessage}\n" +
|
||||
$"Version: {newVersion}";
|
||||
}
|
||||
}
|
||||
66
PluginManager/Others/Actions/InternalActionsManager.cs
Normal file
66
PluginManager/Others/Actions/InternalActionsManager.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using PluginManager.Interfaces;
|
||||
using PluginManager.Loaders;
|
||||
|
||||
namespace PluginManager.Others.Actions;
|
||||
|
||||
public class InternalActionManager
|
||||
{
|
||||
public Dictionary<string, ICommandAction> Actions = new();
|
||||
public ActionsLoader loader;
|
||||
|
||||
public InternalActionManager(string path, string extension)
|
||||
{
|
||||
loader = new ActionsLoader(path, extension);
|
||||
}
|
||||
|
||||
public async Task Initialize()
|
||||
{
|
||||
//loader.ActionLoadedEvent += OnActionLoaded;
|
||||
var m_actions = await loader.Load();
|
||||
if (m_actions == null) return;
|
||||
foreach (var action in m_actions)
|
||||
{
|
||||
Actions.TryAdd(action.ActionName, action);
|
||||
}
|
||||
}
|
||||
|
||||
public async Task Refresh()
|
||||
{
|
||||
Actions.Clear();
|
||||
await Initialize();
|
||||
}
|
||||
|
||||
// private void OnActionLoaded(string name, string typeName, bool success, Exception? e)
|
||||
// {
|
||||
// if (!success)
|
||||
// {
|
||||
// Config.Logger.Error(e);
|
||||
// return;
|
||||
// }
|
||||
//
|
||||
// Config.Logger.Log($"Action {name} loaded successfully", LogLevel.INFO, true);
|
||||
// }
|
||||
|
||||
public async Task<string> Execute(string actionName, params string[]? args)
|
||||
{
|
||||
if (!Actions.ContainsKey(actionName))
|
||||
{
|
||||
Config.Logger.Log($"Action {actionName} not found", type: LogType.ERROR, source: typeof(InternalActionManager));
|
||||
return "Action not found";
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await Actions[actionName].Execute(args);
|
||||
return "Action executed";
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Config.Logger.Log(e.Message , type: LogType.ERROR, source: typeof(InternalActionManager));
|
||||
return e.Message;
|
||||
}
|
||||
}
|
||||
}
|
||||
176
PluginManager/Others/ArchiveManager.cs
Normal file
176
PluginManager/Others/ArchiveManager.cs
Normal file
@@ -0,0 +1,176 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PluginManager.Others;
|
||||
|
||||
public static class ArchiveManager
|
||||
{
|
||||
private static string? archiveFolder;
|
||||
public static bool isInitialized { get; private set; }
|
||||
|
||||
public static void Initialize()
|
||||
{
|
||||
if (isInitialized) throw new Exception("ArchiveManager is already initialized");
|
||||
|
||||
if (!Config.AppSettings.ContainsKey("ArchiveFolder"))
|
||||
Config.AppSettings["ArchiveFolder"] = "./Data/PAKS/";
|
||||
|
||||
archiveFolder = Config.AppSettings["ArchiveFolder"];
|
||||
|
||||
isInitialized = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a file from a zip archive. The output is a byte array
|
||||
/// </summary>
|
||||
/// <param name="fileName">The file name in the archive</param>
|
||||
/// <param name="archName">The archive location on the disk</param>
|
||||
/// <returns>An array of bytes that represents the Stream value from the file that was read inside the archive</returns>
|
||||
public async static Task<byte[]?> ReadStreamFromPakAsync(string fileName, string archName)
|
||||
{
|
||||
if (!isInitialized) throw new Exception("ArchiveManager is not initialized");
|
||||
|
||||
archName = archiveFolder + archName;
|
||||
|
||||
if (!File.Exists(archName))
|
||||
throw new Exception("Failed to load file !");
|
||||
|
||||
byte[]? data = null;
|
||||
|
||||
using (var zip = ZipFile.OpenRead(archName))
|
||||
{
|
||||
var entry = zip.Entries.FirstOrDefault(entry => entry.FullName == fileName || entry.Name == fileName);
|
||||
if (entry is null) throw new Exception("File not found in archive");
|
||||
|
||||
var MemoryStream = new MemoryStream();
|
||||
|
||||
var stream = entry.Open();
|
||||
await stream.CopyToAsync(MemoryStream);
|
||||
data = MemoryStream.ToArray();
|
||||
|
||||
stream.Close();
|
||||
MemoryStream.Close();
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read data from a file that is inside an archive (ZIP format)
|
||||
/// </summary>
|
||||
/// <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<string?> ReadFromPakAsync(string FileName, string archFile)
|
||||
{
|
||||
if (!isInitialized) throw new Exception("ArchiveManager is not initialized");
|
||||
archFile = archiveFolder + archFile;
|
||||
if (!File.Exists(archFile))
|
||||
throw new Exception("Failed to load file !");
|
||||
|
||||
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 (var s = entry.Open())
|
||||
using (var reader = new StreamReader(s))
|
||||
{
|
||||
textValue = await reader.ReadToEndAsync();
|
||||
reader.Close();
|
||||
s.Close();
|
||||
fs.Close();
|
||||
}
|
||||
}
|
||||
|
||||
return textValue;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Config.Logger.Log(message: ex.Message, source: typeof(ArchiveManager), type: LogType.ERROR); // Write the error to a file
|
||||
await Task.Delay(100);
|
||||
return await ReadFromPakAsync(FileName, archFile);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Extract zip to location
|
||||
/// </summary>
|
||||
/// <param name="zip">The zip location</param>
|
||||
/// <param name="folder">The target location</param>
|
||||
/// <param name="progress">The progress that is updated as a file is processed</param>
|
||||
/// <param name="type">The type of progress</param>
|
||||
/// <returns></returns>
|
||||
public static async Task ExtractArchive(
|
||||
string zip, string folder, IProgress<float> progress,
|
||||
UnzipProgressType type)
|
||||
{
|
||||
if (!isInitialized) throw new Exception("ArchiveManager is not initialized");
|
||||
Directory.CreateDirectory(folder);
|
||||
using (var archive = ZipFile.OpenRead(zip))
|
||||
{
|
||||
if (type == UnzipProgressType.PERCENTAGE_FROM_NUMBER_OF_FILES)
|
||||
{
|
||||
var totalZIPFiles = archive.Entries.Count();
|
||||
var currentZIPFile = 0;
|
||||
foreach (var entry in archive.Entries)
|
||||
{
|
||||
if (entry.FullName.EndsWith("/")) // it is a folder
|
||||
Directory.CreateDirectory(Path.Combine(folder, entry.FullName));
|
||||
|
||||
else
|
||||
try
|
||||
{
|
||||
entry.ExtractToFile(Path.Combine(folder, entry.FullName), true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Config.Logger.Log(ex.Message, source: typeof(ArchiveManager), type: LogType.ERROR);
|
||||
}
|
||||
|
||||
currentZIPFile++;
|
||||
await Task.Delay(10);
|
||||
if (progress != null)
|
||||
progress.Report((float)currentZIPFile / totalZIPFiles * 100);
|
||||
}
|
||||
}
|
||||
else if (type == UnzipProgressType.PERCENTAGE_FROM_TOTAL_SIZE)
|
||||
{
|
||||
ulong zipSize = 0;
|
||||
|
||||
foreach (var entry in archive.Entries)
|
||||
zipSize += (ulong)entry.CompressedLength;
|
||||
|
||||
ulong currentSize = 0;
|
||||
foreach (var entry in archive.Entries)
|
||||
{
|
||||
if (entry.FullName.EndsWith("/"))
|
||||
{
|
||||
Directory.CreateDirectory(Path.Combine(folder, entry.FullName));
|
||||
continue;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
entry.ExtractToFile(Path.Combine(folder, entry.FullName), true);
|
||||
currentSize += (ulong)entry.CompressedLength;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Config.Logger.Log(ex.Message, source: typeof(ArchiveManager), type: LogType.ERROR);
|
||||
}
|
||||
|
||||
await Task.Delay(10);
|
||||
if (progress != null)
|
||||
progress.Report((float)currentSize / zipSize * 100);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,60 +0,0 @@
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
|
||||
namespace PluginManager.Others;
|
||||
|
||||
/// <summary>
|
||||
/// A class that handles the sending of messages to the user.
|
||||
/// </summary>
|
||||
public static class ChannelManagement
|
||||
{
|
||||
/// <summary>
|
||||
/// Get the text channel by name from server
|
||||
/// </summary>
|
||||
/// <param name="server">The server</param>
|
||||
/// <param name="name">The channel name</param>
|
||||
/// <returns>
|
||||
/// <see cref="IGuildChannel" />
|
||||
/// </returns>
|
||||
public static IGuildChannel GetTextChannel(this IGuild server, string name)
|
||||
{
|
||||
return server.GetTextChannel(name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the voice channel by name from server
|
||||
/// </summary>
|
||||
/// <param name="server">The server</param>
|
||||
/// <param name="name">The channel name</param>
|
||||
/// <returns>
|
||||
/// <see cref="IGuildChannel" />
|
||||
/// </returns>
|
||||
public static IGuildChannel GetVoiceChannel(this IGuild server, string name)
|
||||
{
|
||||
return server.GetVoiceChannel(name);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the DM channel between <see cref="Discord.WebSocket.DiscordSocketClient" /> and <see cref="IGuildUser" />
|
||||
/// </summary>
|
||||
/// <param name="user"></param>
|
||||
/// <returns>
|
||||
/// <see cref="IDMChannel" />
|
||||
/// </returns>
|
||||
public static async Task<IDMChannel> GetDMChannel(IGuildUser user)
|
||||
{
|
||||
return await user.CreateDMChannelAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the channel where the message was sent
|
||||
/// </summary>
|
||||
/// <param name="message">The message</param>
|
||||
/// <returns>
|
||||
/// <see cref="IChannel" />
|
||||
/// </returns>
|
||||
public static IChannel GetChannel(IMessage message)
|
||||
{
|
||||
return message.Channel;
|
||||
}
|
||||
}
|
||||
@@ -1,365 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PluginManager.Others;
|
||||
|
||||
public static class Utilities
|
||||
{
|
||||
private static Dictionary<char, ConsoleColor> Colors = new()
|
||||
{
|
||||
{ 'g', ConsoleColor.Green },
|
||||
{ 'b', ConsoleColor.Blue },
|
||||
{ 'r', ConsoleColor.Red },
|
||||
{ 'm', ConsoleColor.Magenta },
|
||||
{ 'y', ConsoleColor.Yellow }
|
||||
};
|
||||
|
||||
private static char ColorPrefix = '&';
|
||||
|
||||
|
||||
private static bool CanAproximateTo(this float f, float y)
|
||||
{
|
||||
return MathF.Abs(f - y) < 0.000001;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A way to create a table based on input data
|
||||
/// </summary>
|
||||
/// <param name="data">The List of arrays of strings that represent the rows.</param>
|
||||
public static void FormatAndAlignTable(List<string[]> data, TableFormat format)
|
||||
{
|
||||
if (format == TableFormat.CENTER_EACH_COLUMN_BASED)
|
||||
{
|
||||
var tableLine = '-';
|
||||
var tableCross = '+';
|
||||
var tableWall = '|';
|
||||
|
||||
var len = new int[data[0].Length];
|
||||
foreach (var line in data)
|
||||
for (var i = 0; i < line.Length; i++)
|
||||
if (line[i].Length > len[i])
|
||||
len[i] = line[i].Length;
|
||||
|
||||
|
||||
foreach (var row in data)
|
||||
{
|
||||
if (row[0][0] == tableLine)
|
||||
Settings.Variables.outputStream.Write(tableCross);
|
||||
else
|
||||
Settings.Variables.outputStream.Write(tableWall);
|
||||
for (var l = 0; l < row.Length; l++)
|
||||
{
|
||||
if (row[l][0] == tableLine)
|
||||
{
|
||||
for (var i = 0; i < len[l] + 4; ++i)
|
||||
Settings.Variables.outputStream.Write(tableLine);
|
||||
}
|
||||
else if (row[l].Length == len[l])
|
||||
{
|
||||
Settings.Variables.outputStream.Write(" ");
|
||||
Settings.Variables.outputStream.Write(row[l]);
|
||||
Settings.Variables.outputStream.Write(" ");
|
||||
}
|
||||
else
|
||||
{
|
||||
var lenHalf = row[l].Length / 2;
|
||||
for (var i = 0; i < (len[l] + 4) / 2 - lenHalf; ++i)
|
||||
Settings.Variables.outputStream.Write(" ");
|
||||
Settings.Variables.outputStream.Write(row[l]);
|
||||
for (var i = (len[l] + 4) / 2 + lenHalf + 1; i < len[l] + 4; ++i)
|
||||
Settings.Variables.outputStream.Write(" ");
|
||||
if (row[l].Length % 2 == 0)
|
||||
Settings.Variables.outputStream.Write(" ");
|
||||
}
|
||||
|
||||
Settings.Variables.outputStream.Write(row[l][0] == tableLine ? tableCross : tableWall);
|
||||
}
|
||||
|
||||
Settings.Variables.outputStream.WriteLine(); //end line
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (format == TableFormat.CENTER_OVERALL_LENGTH)
|
||||
{
|
||||
var maxLen = 0;
|
||||
foreach (var row in data)
|
||||
foreach (var s in row)
|
||||
if (s.Length > maxLen)
|
||||
maxLen = s.Length;
|
||||
|
||||
var div = (maxLen + 4) / 2;
|
||||
|
||||
foreach (var row in data)
|
||||
{
|
||||
Settings.Variables.outputStream.Write("\t");
|
||||
if (row[0] == "-")
|
||||
Settings.Variables.outputStream.Write("+");
|
||||
else
|
||||
Settings.Variables.outputStream.Write("|");
|
||||
|
||||
foreach (var s in row)
|
||||
{
|
||||
if (s == "-")
|
||||
{
|
||||
for (var i = 0; i < maxLen + 4; ++i)
|
||||
Settings.Variables.outputStream.Write("-");
|
||||
}
|
||||
else if (s.Length == maxLen)
|
||||
{
|
||||
Settings.Variables.outputStream.Write(" ");
|
||||
Settings.Variables.outputStream.Write(s);
|
||||
Settings.Variables.outputStream.Write(" ");
|
||||
}
|
||||
else
|
||||
{
|
||||
var lenHalf = s.Length / 2;
|
||||
for (var i = 0; i < div - lenHalf; ++i)
|
||||
Settings.Variables.outputStream.Write(" ");
|
||||
Settings.Variables.outputStream.Write(s);
|
||||
for (var i = div + lenHalf + 1; i < maxLen + 4; ++i)
|
||||
Settings.Variables.outputStream.Write(" ");
|
||||
if (s.Length % 2 == 0)
|
||||
Settings.Variables.outputStream.Write(" ");
|
||||
}
|
||||
|
||||
if (s == "-")
|
||||
Settings.Variables.outputStream.Write("+");
|
||||
else
|
||||
Settings.Variables.outputStream.Write("|");
|
||||
}
|
||||
|
||||
Settings.Variables.outputStream.WriteLine(); //end line
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (format == TableFormat.DEFAULT)
|
||||
{
|
||||
var widths = new int[data[0].Length];
|
||||
var space_between_columns = 3;
|
||||
for (var i = 0; i < data.Count; i++)
|
||||
for (var j = 0; j < data[i].Length; j++)
|
||||
if (data[i][j].Length > widths[j])
|
||||
widths[j] = data[i][j].Length;
|
||||
|
||||
for (var i = 0; i < data.Count; i++)
|
||||
{
|
||||
for (var j = 0; j < data[i].Length; j++)
|
||||
{
|
||||
if (data[i][j] == "-")
|
||||
data[i][j] = " ";
|
||||
Settings.Variables.outputStream.Write(data[i][j]);
|
||||
for (var k = 0; k < widths[j] - data[i][j].Length + 1 + space_between_columns; k++)
|
||||
Settings.Variables.outputStream.Write(" ");
|
||||
}
|
||||
|
||||
Settings.Variables.outputStream.WriteLine();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
throw new Exception("Unknown type of table");
|
||||
}
|
||||
|
||||
public static void WriteColorText(string text, bool appendNewLineAtEnd = true)
|
||||
{
|
||||
if (Console.Out != Settings.Variables.outputStream)
|
||||
{
|
||||
Settings.Variables.outputStream.Write(text);
|
||||
if (appendNewLineAtEnd)
|
||||
Settings.Variables.outputStream.WriteLine();
|
||||
return;
|
||||
}
|
||||
var initialForeGround = Console.ForegroundColor;
|
||||
var input = text.ToCharArray();
|
||||
for (var i = 0; i < input.Length; i++)
|
||||
if (input[i] == ColorPrefix)
|
||||
{
|
||||
if (i + 1 < input.Length)
|
||||
{
|
||||
if (Colors.ContainsKey(input[i + 1]))
|
||||
{
|
||||
Console.ForegroundColor = Colors[input[i + 1]];
|
||||
i++;
|
||||
}
|
||||
else if (input[i + 1] == 'c')
|
||||
{
|
||||
Console.ForegroundColor = initialForeGround;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Settings.Variables.outputStream.Write(input[i]);
|
||||
}
|
||||
|
||||
Console.ForegroundColor = initialForeGround;
|
||||
if (appendNewLineAtEnd)
|
||||
Settings.Variables.outputStream.WriteLine();
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Progress bar object
|
||||
/// </summary>
|
||||
public class ProgressBar
|
||||
{
|
||||
private readonly int BarLength = 32;
|
||||
|
||||
private bool isRunning;
|
||||
private int position = 1;
|
||||
private bool positive = true;
|
||||
|
||||
public ProgressBar(ProgressBarType type)
|
||||
{
|
||||
if (Settings.Variables.outputStream != Console.Out)
|
||||
throw new Exception("This class (or function) can be used with console only. For UI please use another approach.");
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
public float Max { get; init; }
|
||||
public ConsoleColor Color { get; init; }
|
||||
public bool NoColor { get; init; }
|
||||
public ProgressBarType type { get; set; }
|
||||
|
||||
public int TotalLength { get; private set; }
|
||||
|
||||
|
||||
public async void Start()
|
||||
{
|
||||
if (type != ProgressBarType.NO_END)
|
||||
throw new Exception("Only NO_END progress bar can use this method");
|
||||
if (isRunning)
|
||||
throw new Exception("This progress bar is already running");
|
||||
|
||||
isRunning = true;
|
||||
while (isRunning)
|
||||
{
|
||||
UpdateNoEnd();
|
||||
await Task.Delay(100);
|
||||
}
|
||||
}
|
||||
|
||||
public async void Start(string message)
|
||||
{
|
||||
if (type != ProgressBarType.NO_END)
|
||||
throw new Exception("Only NO_END progress bar can use this method");
|
||||
if (isRunning)
|
||||
throw new Exception("This progress bar is already running");
|
||||
|
||||
isRunning = true;
|
||||
|
||||
TotalLength = message.Length + BarLength + 5;
|
||||
while (isRunning)
|
||||
{
|
||||
UpdateNoEnd(message);
|
||||
await Task.Delay(100);
|
||||
}
|
||||
}
|
||||
|
||||
public void Stop()
|
||||
{
|
||||
if (type != ProgressBarType.NO_END)
|
||||
throw new Exception("Only NO_END progress bar can use this method");
|
||||
if (!isRunning)
|
||||
throw new Exception("Can not stop a progressbar that did not start");
|
||||
isRunning = false;
|
||||
}
|
||||
|
||||
public void Stop(string message)
|
||||
{
|
||||
Stop();
|
||||
|
||||
if (message is not null)
|
||||
{
|
||||
Console.CursorLeft = 0;
|
||||
for (var i = 0; i < BarLength + message.Length + 1; i++)
|
||||
Settings.Variables.outputStream.Write(" ");
|
||||
Console.CursorLeft = 0;
|
||||
Settings.Variables.outputStream.WriteLine(message);
|
||||
}
|
||||
}
|
||||
|
||||
public void Update(float progress)
|
||||
{
|
||||
if (type == ProgressBarType.NO_END)
|
||||
throw new Exception("This function is for progress bars with end");
|
||||
|
||||
UpdateNormal(progress);
|
||||
}
|
||||
|
||||
private void UpdateNoEnd(string message)
|
||||
{
|
||||
Console.CursorLeft = 0;
|
||||
Settings.Variables.outputStream.Write("[");
|
||||
for (var i = 1; i <= position; i++)
|
||||
Settings.Variables.outputStream.Write(" ");
|
||||
Settings.Variables.outputStream.Write("<==()==>");
|
||||
position += positive ? 1 : -1;
|
||||
for (var i = position; i <= BarLength - 1 - (positive ? 0 : 2); i++)
|
||||
Settings.Variables.outputStream.Write(" ");
|
||||
Settings.Variables.outputStream.Write("] " + message);
|
||||
|
||||
|
||||
if (position == BarLength - 1 || position == 1)
|
||||
positive = !positive;
|
||||
}
|
||||
|
||||
private void UpdateNoEnd()
|
||||
{
|
||||
Console.CursorLeft = 0;
|
||||
Settings.Variables.outputStream.Write("[");
|
||||
for (var i = 1; i <= position; i++)
|
||||
Settings.Variables.outputStream.Write(" ");
|
||||
Settings.Variables.outputStream.Write("<==()==>");
|
||||
position += positive ? 1 : -1;
|
||||
for (var i = position; i <= BarLength - 1 - (positive ? 0 : 2); i++)
|
||||
Settings.Variables.outputStream.Write(" ");
|
||||
Settings.Variables.outputStream.Write("]");
|
||||
|
||||
|
||||
if (position == BarLength - 1 || position == 1)
|
||||
positive = !positive;
|
||||
}
|
||||
|
||||
private void UpdateNormal(float progress)
|
||||
{
|
||||
Console.CursorLeft = 0;
|
||||
Settings.Variables.outputStream.Write("[");
|
||||
Console.CursorLeft = BarLength;
|
||||
Settings.Variables.outputStream.Write("]");
|
||||
Console.CursorLeft = 1;
|
||||
var onechunk = 30.0f / Max;
|
||||
|
||||
var position = 1;
|
||||
|
||||
for (var i = 0; i < onechunk * progress; i++)
|
||||
{
|
||||
Console.BackgroundColor = NoColor ? ConsoleColor.Black : Color;
|
||||
Console.CursorLeft = position++;
|
||||
Settings.Variables.outputStream.Write("#");
|
||||
}
|
||||
|
||||
for (var i = position; i < BarLength; i++)
|
||||
{
|
||||
Console.BackgroundColor = NoColor ? ConsoleColor.Black : ConsoleColor.DarkGray;
|
||||
Console.CursorLeft = position++;
|
||||
Settings.Variables.outputStream.Write(" ");
|
||||
}
|
||||
|
||||
Console.CursorLeft = BarLength + 4;
|
||||
Console.BackgroundColor = ConsoleColor.Black;
|
||||
if (progress.CanAproximateTo(Max))
|
||||
Settings.Variables.outputStream.Write(progress + " % ✓");
|
||||
else
|
||||
Settings.Variables.outputStream.Write(MathF.Round(progress, 2) + " % ");
|
||||
}
|
||||
}
|
||||
}
|
||||
47
PluginManager/Others/DBCommandExecutingArguments.cs
Normal file
47
PluginManager/Others/DBCommandExecutingArguments.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System.Linq;
|
||||
using Discord.Commands;
|
||||
using Discord.WebSocket;
|
||||
using PluginManager.Bot;
|
||||
|
||||
namespace PluginManager.Others;
|
||||
|
||||
public class DBCommandExecutingArguments
|
||||
{
|
||||
public DBCommandExecutingArguments(
|
||||
SocketCommandContext context, string cleanContent, string commandUsed, string[]? arguments)
|
||||
{
|
||||
this.context = context;
|
||||
this.cleanContent = cleanContent;
|
||||
this.commandUsed = commandUsed;
|
||||
this.arguments = arguments;
|
||||
}
|
||||
|
||||
public DBCommandExecutingArguments(SocketUserMessage? message, DiscordSocketClient client)
|
||||
{
|
||||
this.context = new SocketCommandContext(client, message);
|
||||
int pos = 0;
|
||||
if (message.HasMentionPrefix(client.CurrentUser, ref pos))
|
||||
{
|
||||
var mentionPrefix = "<@" + client.CurrentUser.Id + ">";
|
||||
this.cleanContent = message.Content.Substring(mentionPrefix.Length + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.cleanContent = message.Content.Substring(Config.DiscordBot.botPrefix.Length);
|
||||
}
|
||||
|
||||
var split = this.cleanContent.Split(' ');
|
||||
|
||||
string[]? argsClean = null;
|
||||
if (split.Length > 1)
|
||||
argsClean = string.Join(' ', split, 1, split.Length - 1).Split(' ');
|
||||
|
||||
this.commandUsed = split[0];
|
||||
this.arguments = argsClean;
|
||||
}
|
||||
|
||||
public SocketCommandContext context { get; init; }
|
||||
public string cleanContent { get; init; }
|
||||
public string commandUsed { get; init; }
|
||||
public string[]? arguments { get; init; }
|
||||
}
|
||||
@@ -11,25 +11,11 @@ public enum OperatingSystem
|
||||
UNKNOWN
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// A list with all errors
|
||||
/// </summary>
|
||||
public enum Error
|
||||
{
|
||||
UNKNOWN_ERROR,
|
||||
GUILD_NOT_FOUND,
|
||||
STREAM_NOT_FOUND,
|
||||
INVALID_USER,
|
||||
INVALID_CHANNEL,
|
||||
INVALID_PERMISSIONS
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The output log type
|
||||
/// </summary>
|
||||
public enum OutputLogLevel
|
||||
public enum LogType
|
||||
{
|
||||
NONE,
|
||||
INFO,
|
||||
WARNING,
|
||||
ERROR,
|
||||
@@ -38,25 +24,24 @@ public enum OutputLogLevel
|
||||
|
||||
public enum UnzipProgressType
|
||||
{
|
||||
PercentageFromNumberOfFiles,
|
||||
PercentageFromTotalSize
|
||||
}
|
||||
|
||||
public enum TableFormat
|
||||
{
|
||||
CENTER_EACH_COLUMN_BASED,
|
||||
CENTER_OVERALL_LENGTH,
|
||||
DEFAULT
|
||||
PERCENTAGE_FROM_NUMBER_OF_FILES,
|
||||
PERCENTAGE_FROM_TOTAL_SIZE
|
||||
}
|
||||
|
||||
public enum SaveType
|
||||
{
|
||||
NORMAL,
|
||||
BACKUP
|
||||
TXT,
|
||||
JSON
|
||||
}
|
||||
|
||||
public enum ProgressBarType
|
||||
public enum InternalActionRunType
|
||||
{
|
||||
NORMAL,
|
||||
NO_END
|
||||
ON_STARTUP,
|
||||
ON_CALL
|
||||
}
|
||||
|
||||
internal enum ExceptionExitCode : int
|
||||
{
|
||||
CONFIG_FAILED_TO_LOAD = 1,
|
||||
CONFIG_KEY_NOT_FOUND = 2,
|
||||
}
|
||||
@@ -1,18 +1,11 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using Discord.WebSocket;
|
||||
|
||||
using PluginManager.Items;
|
||||
using Discord;
|
||||
|
||||
namespace PluginManager.Others;
|
||||
|
||||
@@ -23,98 +16,19 @@ public static class Functions
|
||||
{
|
||||
/// <summary>
|
||||
/// The location for the Resources folder
|
||||
/// String: ./Data/Resources/
|
||||
/// </summary>
|
||||
public static readonly string dataFolder = @"./Data/Resources/";
|
||||
|
||||
/// <summary>
|
||||
/// The location for all logs
|
||||
/// </summary>
|
||||
public static readonly string logFolder = @"./Data/Output/Logs/";
|
||||
|
||||
/// <summary>
|
||||
/// The location for all errors
|
||||
/// </summary>
|
||||
public static readonly string errFolder = @"./Data/Output/Errors/";
|
||||
|
||||
/// <summary>
|
||||
/// Archives folder
|
||||
/// </summary>
|
||||
public static readonly string pakFolder = @"./Data/PAKS/";
|
||||
|
||||
/// <summary>
|
||||
/// Beta testing folder
|
||||
/// </summary>
|
||||
public static readonly string betaFolder = @"./Data/BetaTest/";
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Read data from a file that is inside an archive (ZIP format)
|
||||
/// </summary>
|
||||
/// <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<string> ReadFromPakAsync(string FileName, string archFile)
|
||||
public static Color RandomColor
|
||||
{
|
||||
archFile = pakFolder + archFile;
|
||||
if (!File.Exists(archFile))
|
||||
throw new Exception("Failed to load file !");
|
||||
|
||||
try
|
||||
get
|
||||
{
|
||||
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 (var s = entry.Open())
|
||||
using (var reader = new StreamReader(s))
|
||||
{
|
||||
textValue = await reader.ReadToEndAsync();
|
||||
reader.Close();
|
||||
s.Close();
|
||||
fs.Close();
|
||||
var random = new Random();
|
||||
return new Color(random.Next(0, 255), random.Next(0, 255), random.Next(0, 255));
|
||||
}
|
||||
}
|
||||
|
||||
return textValue;
|
||||
}
|
||||
catch
|
||||
{
|
||||
await Task.Delay(100);
|
||||
return await ReadFromPakAsync(FileName, archFile);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Write logs to file
|
||||
/// </summary>
|
||||
/// <param name="LogMessage">The message to be wrote</param>
|
||||
public static void WriteLogFile(string LogMessage)
|
||||
{
|
||||
var logsPath = logFolder + $"{DateTime.Today.ToShortDateString().Replace("/", "-").Replace("\\", "-")} Log.txt";
|
||||
Directory.CreateDirectory(logFolder);
|
||||
File.AppendAllText(logsPath, LogMessage + " \n");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Write error to file
|
||||
/// </summary>
|
||||
/// <param name="ErrMessage">The message to be wrote</param>
|
||||
public static void WriteErrFile(string ErrMessage)
|
||||
{
|
||||
var errPath = errFolder +
|
||||
$"{DateTime.Today.ToShortDateString().Replace("/", "-").Replace("\\", "-")} Error.txt";
|
||||
Directory.CreateDirectory(errFolder);
|
||||
File.AppendAllText(errPath, ErrMessage + " \n");
|
||||
}
|
||||
|
||||
public static void WriteErrFile(this Exception ex)
|
||||
{
|
||||
WriteErrFile(ex.ToString());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get the Operating system you are runnin on
|
||||
/// </summary>
|
||||
@@ -127,12 +41,6 @@ public static class Functions
|
||||
return OperatingSystem.UNKNOWN;
|
||||
}
|
||||
|
||||
public static List<string> GetArguments(SocketMessage message)
|
||||
{
|
||||
var command = new Command(message);
|
||||
return command.Arguments;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copy one Stream to another <see langword="async" />
|
||||
/// </summary>
|
||||
@@ -145,7 +53,8 @@ public static class Functions
|
||||
/// <exception cref="ArgumentOutOfRangeException">Triggered if <paramref name="bufferSize" /> is less then or equal to 0</exception>
|
||||
/// <exception cref="InvalidOperationException">Triggered if <paramref name="stream" /> is not readable</exception>
|
||||
/// <exception cref="ArgumentException">Triggered in <paramref name="destination" /> is not writable</exception>
|
||||
public static async Task CopyToOtherStreamAsync(this Stream stream, Stream destination, int bufferSize,
|
||||
public static async Task CopyToOtherStreamAsync(
|
||||
this Stream stream, Stream destination, int bufferSize,
|
||||
IProgress<long>? progress = null,
|
||||
CancellationToken cancellationToken = default)
|
||||
{
|
||||
@@ -159,7 +68,8 @@ public static class Functions
|
||||
var buffer = new byte[bufferSize];
|
||||
long totalBytesRead = 0;
|
||||
int bytesRead;
|
||||
while ((bytesRead = await stream.ReadAsync(buffer, 0, buffer.Length, cancellationToken).ConfigureAwait(false)) != 0)
|
||||
while ((bytesRead = await stream.ReadAsync(buffer, 0, buffer.Length, cancellationToken)
|
||||
.ConfigureAwait(false)) != 0)
|
||||
{
|
||||
await destination.WriteAsync(buffer, 0, bytesRead, cancellationToken).ConfigureAwait(false);
|
||||
totalBytesRead += bytesRead;
|
||||
@@ -167,134 +77,22 @@ public static class Functions
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Extract zip to location
|
||||
/// </summary>
|
||||
/// <param name="zip">The zip location</param>
|
||||
/// <param name="folder">The target location</param>
|
||||
/// <param name="progress">The progress that is updated as a file is processed</param>
|
||||
/// <param name="type">The type of progress</param>
|
||||
/// <returns></returns>
|
||||
public static async Task ExtractArchive(string zip, string folder, IProgress<float> progress,
|
||||
UnzipProgressType type)
|
||||
{
|
||||
Directory.CreateDirectory(folder);
|
||||
using (var archive = ZipFile.OpenRead(zip))
|
||||
{
|
||||
if (type == UnzipProgressType.PercentageFromNumberOfFiles)
|
||||
{
|
||||
var totalZIPFiles = archive.Entries.Count();
|
||||
var currentZIPFile = 0;
|
||||
foreach (var entry in archive.Entries)
|
||||
{
|
||||
if (entry.FullName.EndsWith("/")) // it is a folder
|
||||
Directory.CreateDirectory(Path.Combine(folder, entry.FullName));
|
||||
|
||||
else
|
||||
try
|
||||
public static T SelectRandomValueOf<T>()
|
||||
{
|
||||
entry.ExtractToFile(Path.Combine(folder, entry.FullName), true);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Settings.Variables.outputStream.WriteLine($"Failed to extract {entry.Name}. Exception: {ex.Message}");
|
||||
var enums = Enum.GetValues(typeof(T));
|
||||
var random = new Random();
|
||||
return (T)enums.GetValue(random.Next(enums.Length));
|
||||
}
|
||||
|
||||
currentZIPFile++;
|
||||
await Task.Delay(10);
|
||||
if (progress != null)
|
||||
progress.Report((float)currentZIPFile / totalZIPFiles * 100);
|
||||
}
|
||||
}
|
||||
else if (type == UnzipProgressType.PercentageFromTotalSize)
|
||||
public static T RandomValue<T>(this T[] values)
|
||||
{
|
||||
ulong zipSize = 0;
|
||||
Random random = new();
|
||||
return values[random.Next(values.Length)];
|
||||
}
|
||||
|
||||
foreach (var entry in archive.Entries)
|
||||
zipSize += (ulong)entry.CompressedLength;
|
||||
|
||||
ulong currentSize = 0;
|
||||
foreach (var entry in archive.Entries)
|
||||
public static string ToResourcesPath(this string path)
|
||||
{
|
||||
if (entry.FullName.EndsWith("/"))
|
||||
{
|
||||
Directory.CreateDirectory(Path.Combine(folder, entry.FullName));
|
||||
continue;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
entry.ExtractToFile(Path.Combine(folder, entry.FullName), true);
|
||||
currentSize += (ulong)entry.CompressedLength;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Settings.Variables.outputStream.WriteLine($"Failed to extract {entry.Name}. Exception: {ex.Message}");
|
||||
}
|
||||
|
||||
await Task.Delay(10);
|
||||
if (progress != null)
|
||||
progress.Report((float)currentSize / zipSize * 100);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Save to JSON file
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The class type</typeparam>
|
||||
/// <param name="file">The file path</param>
|
||||
/// <param name="Data">The values</param>
|
||||
/// <returns></returns>
|
||||
public static async Task SaveToJsonFile<T>(string file, T Data)
|
||||
{
|
||||
var str = new MemoryStream();
|
||||
await JsonSerializer.SerializeAsync(str, Data, typeof(T), new JsonSerializerOptions { WriteIndented = true });
|
||||
await File.WriteAllBytesAsync(file, str.ToArray());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert json text or file to some kind of data
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The data type</typeparam>
|
||||
/// <param name="input">The file or json text</param>
|
||||
/// <returns></returns>
|
||||
public static async Task<T> ConvertFromJson<T>(string input)
|
||||
{
|
||||
Stream text;
|
||||
if (File.Exists(input))
|
||||
text = new MemoryStream(await File.ReadAllBytesAsync(input));
|
||||
else
|
||||
text = new MemoryStream(Encoding.ASCII.GetBytes(input));
|
||||
text.Position = 0;
|
||||
var obj = await JsonSerializer.DeserializeAsync<T>(text);
|
||||
text.Close();
|
||||
return (obj ?? default)!;
|
||||
}
|
||||
|
||||
public static bool TryReadValueFromJson(string input, string codeName, out JsonElement element)
|
||||
{
|
||||
Stream text;
|
||||
if (File.Exists(input))
|
||||
text = File.OpenRead(input);
|
||||
|
||||
else
|
||||
text = new MemoryStream(Encoding.ASCII.GetBytes(input));
|
||||
|
||||
var jsonObject = JsonDocument.Parse(text);
|
||||
|
||||
var data = jsonObject.RootElement.TryGetProperty(codeName, out element);
|
||||
return data;
|
||||
}
|
||||
|
||||
public static string CreateMD5(string input)
|
||||
{
|
||||
using (var md5 = MD5.Create())
|
||||
{
|
||||
var inputBytes = Encoding.ASCII.GetBytes(input);
|
||||
var hashBytes = md5.ComputeHash(inputBytes);
|
||||
return Convert.ToHexString(hashBytes);
|
||||
}
|
||||
return Path.Combine(dataFolder, path);
|
||||
}
|
||||
}
|
||||
47
PluginManager/Others/JsonManager.cs
Normal file
47
PluginManager/Others/JsonManager.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PluginManager;
|
||||
|
||||
public class JsonManager
|
||||
{
|
||||
/// <summary>
|
||||
/// Save to JSON file
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The class type</typeparam>
|
||||
/// <param name="file">The file path</param>
|
||||
/// <param name="Data">The values</param>
|
||||
/// <returns></returns>
|
||||
public static async Task SaveToJsonFile<T>(string file, T Data)
|
||||
{
|
||||
var str = new MemoryStream();
|
||||
await JsonSerializer.SerializeAsync(str, Data, typeof(T), new JsonSerializerOptions { WriteIndented = true });
|
||||
await File.WriteAllBytesAsync(file, str.ToArray());
|
||||
await str.FlushAsync();
|
||||
str.Close();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Convert json text or file to some kind of data
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The data type</typeparam>
|
||||
/// <param name="input">The file or json text</param>
|
||||
/// <returns></returns>
|
||||
public static async Task<T> ConvertFromJson<T>(string input)
|
||||
{
|
||||
Stream text;
|
||||
if (File.Exists(input))
|
||||
text = new MemoryStream(await File.ReadAllBytesAsync(input));
|
||||
else
|
||||
text = new MemoryStream(Encoding.ASCII.GetBytes(input));
|
||||
text.Position = 0;
|
||||
|
||||
var obj = await JsonSerializer.DeserializeAsync<T>(text);
|
||||
await text.FlushAsync();
|
||||
text.Close();
|
||||
return (obj ?? default)!;
|
||||
}
|
||||
}
|
||||
78
PluginManager/Others/Logger/Log.cs
Normal file
78
PluginManager/Others/Logger/Log.cs
Normal file
@@ -0,0 +1,78 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using PluginManager.Interfaces.Logger;
|
||||
|
||||
namespace PluginManager.Others.Logger;
|
||||
|
||||
public class Log : ILog
|
||||
{
|
||||
public string Message { get; set; }
|
||||
public string OutputFile { get; set; }
|
||||
public Type? Source { get; set; }
|
||||
public LogType Type { get; set; }
|
||||
public DateTime ThrowTime { get; set; }
|
||||
|
||||
public Log(string message, string outputFile, Type? source, LogType type, DateTime throwTime)
|
||||
{
|
||||
Message = message;
|
||||
OutputFile = outputFile;
|
||||
Source = source;
|
||||
Type = type;
|
||||
ThrowTime = throwTime;
|
||||
}
|
||||
|
||||
public Log(string message, string outputFile, Type? source, LogType type)
|
||||
{
|
||||
Message = message;
|
||||
OutputFile = outputFile;
|
||||
Source = source;
|
||||
Type = type;
|
||||
ThrowTime = DateTime.Now;
|
||||
}
|
||||
|
||||
public Log(string message, string outputFile, Type? source)
|
||||
{
|
||||
Message = message;
|
||||
OutputFile = outputFile;
|
||||
Source = source;
|
||||
Type = LogType.INFO;
|
||||
ThrowTime = DateTime.Now;
|
||||
}
|
||||
|
||||
public Log(string message, string outputFile)
|
||||
{
|
||||
Message = message;
|
||||
OutputFile = outputFile;
|
||||
Source = typeof(Log);
|
||||
Type = LogType.INFO;
|
||||
ThrowTime = DateTime.Now;
|
||||
}
|
||||
|
||||
public Log(string message)
|
||||
{
|
||||
Message = message;
|
||||
OutputFile = "";
|
||||
Source = typeof(Log);
|
||||
Type = LogType.INFO;
|
||||
ThrowTime = DateTime.Now;
|
||||
}
|
||||
|
||||
public static implicit operator Log(string message) => new (message);
|
||||
|
||||
public static implicit operator string(Log log) => $"[{log.ThrowTime}] {log.Message}";
|
||||
|
||||
public string AsLongString()
|
||||
{
|
||||
return $"[{ThrowTime}] [{Source}] [{Type}] {Message}";
|
||||
}
|
||||
|
||||
public string AsShortString()
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
public string FormatedLongString()
|
||||
{
|
||||
return $"[{ThrowTime}]\t[{Source}]\t\t\t[{Type}]\t{Message}";
|
||||
}
|
||||
}
|
||||
69
PluginManager/Others/Logger/Logger.cs
Normal file
69
PluginManager/Others/Logger/Logger.cs
Normal file
@@ -0,0 +1,69 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Threading.Tasks;
|
||||
using PluginManager.Interfaces.Logger;
|
||||
|
||||
namespace PluginManager.Others.Logger;
|
||||
|
||||
public sealed class Logger : ILogger
|
||||
{
|
||||
public bool IsEnabled { get; init; }
|
||||
public bool OutputToFile { get; init; }
|
||||
|
||||
public LogType LowestLogLevel { get; set; }
|
||||
private bool UseShortVersion { get; }
|
||||
|
||||
public Logger(bool useShortVersion, bool outputToFile, LogType lowestLogLevel = LogType.INFO)
|
||||
{
|
||||
UseShortVersion = useShortVersion;
|
||||
OutputToFile = outputToFile;
|
||||
IsEnabled = true;
|
||||
LowestLogLevel = lowestLogLevel;
|
||||
}
|
||||
|
||||
public event EventHandler<Log>? OnLog;
|
||||
|
||||
private async Task Log(Log logMessage)
|
||||
{
|
||||
if (!IsEnabled) return;
|
||||
|
||||
OnLog?.Invoke(this, logMessage);
|
||||
|
||||
if (logMessage.Type < LowestLogLevel) return;
|
||||
|
||||
if (OutputToFile)
|
||||
await File.AppendAllTextAsync(
|
||||
logMessage.OutputFile,
|
||||
(UseShortVersion ? logMessage : logMessage.AsLongString()) + "\n");
|
||||
}
|
||||
|
||||
public async void Log(string message = "", string outputFile = "", Type? source = default, LogType type = LogType.INFO, DateTime throwTime = default)
|
||||
{
|
||||
if (!IsEnabled) return;
|
||||
|
||||
if (type < LowestLogLevel) return;
|
||||
|
||||
if (string.IsNullOrEmpty(message)) return;
|
||||
|
||||
if (string.IsNullOrEmpty(outputFile)) outputFile = Config.AppSettings["LogFolder"] + "/" + DateTime.Now.ToString("yyyy-MM-dd") + ".log";
|
||||
|
||||
if(throwTime == default) throwTime = DateTime.Now;
|
||||
|
||||
if (source == default) source = typeof(Log);
|
||||
|
||||
await Log(new Log(message, outputFile, source, type, throwTime));
|
||||
|
||||
}
|
||||
|
||||
public async void Log(Exception exception, LogType logType = LogType.ERROR, Type? source = null)
|
||||
{
|
||||
if (!IsEnabled) return;
|
||||
|
||||
if (logType < LowestLogLevel) return;
|
||||
|
||||
await Log(new Log(exception.Message,
|
||||
Config.AppSettings["LogFolder"] + "/" + DateTime.Now.ToString("yyyy-MM-dd") + ".log",
|
||||
source, logType, DateTime.Now));
|
||||
}
|
||||
}
|
||||
129
PluginManager/Others/SettingsDictionary.cs
Normal file
129
PluginManager/Others/SettingsDictionary.cs
Normal file
@@ -0,0 +1,129 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace PluginManager.Others;
|
||||
|
||||
public class SettingsDictionary<TKey, TValue> : IDictionary<TKey, TValue>
|
||||
{
|
||||
public string? _file { get; }
|
||||
private IDictionary<TKey, TValue>? _dictionary;
|
||||
|
||||
public SettingsDictionary(string? file)
|
||||
{
|
||||
_file = file;
|
||||
if (!LoadFromFile())
|
||||
{
|
||||
_dictionary = new Dictionary<TKey, TValue>();
|
||||
SaveToFile();
|
||||
}
|
||||
}
|
||||
|
||||
public async Task SaveToFile()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(_file))
|
||||
await JsonManager.SaveToJsonFile(_file, _dictionary);
|
||||
}
|
||||
|
||||
private bool LoadFromFile()
|
||||
{
|
||||
if (!string.IsNullOrEmpty(_file))
|
||||
try
|
||||
{
|
||||
if (File.Exists(_file))
|
||||
{
|
||||
string FileContent = File.ReadAllText(_file);
|
||||
if (string.IsNullOrEmpty(FileContent))
|
||||
File.WriteAllText(_file, "{}");
|
||||
|
||||
if(!FileContent.Contains("{") || !FileContent.Contains("}"))
|
||||
File.WriteAllText(_file, "{}");
|
||||
}
|
||||
else
|
||||
File.WriteAllText(_file, "{}");
|
||||
_dictionary = JsonManager.ConvertFromJson<IDictionary<TKey, TValue>>(_file).Result;
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
public IEnumerator<KeyValuePair<TKey, TValue>> GetEnumerator()
|
||||
{
|
||||
return _dictionary!.GetEnumerator();
|
||||
}
|
||||
|
||||
IEnumerator IEnumerable.GetEnumerator()
|
||||
{
|
||||
return ((IEnumerable) _dictionary!).GetEnumerator();
|
||||
}
|
||||
|
||||
public void Add(KeyValuePair<TKey, TValue> item)
|
||||
{
|
||||
this._dictionary!.Add(item);
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
this._dictionary!.Clear();
|
||||
}
|
||||
|
||||
public bool Contains(KeyValuePair<TKey, TValue> item)
|
||||
{
|
||||
return this._dictionary!.Contains(item);
|
||||
}
|
||||
|
||||
public void CopyTo(KeyValuePair<TKey, TValue>[] array, int arrayIndex)
|
||||
{
|
||||
this._dictionary!.CopyTo(array, arrayIndex);
|
||||
}
|
||||
|
||||
public bool Remove(KeyValuePair<TKey, TValue> item)
|
||||
{
|
||||
return this._dictionary!.Remove(item);
|
||||
}
|
||||
|
||||
public int Count => _dictionary!.Count;
|
||||
public bool IsReadOnly => _dictionary!.IsReadOnly;
|
||||
public void Add(TKey key, TValue value)
|
||||
{
|
||||
this._dictionary!.Add(key, value);
|
||||
}
|
||||
|
||||
public bool ContainsKey(TKey key)
|
||||
{
|
||||
return this._dictionary!.ContainsKey(key);
|
||||
}
|
||||
|
||||
public bool Remove(TKey key)
|
||||
{
|
||||
return this._dictionary!.Remove(key);
|
||||
}
|
||||
|
||||
public bool TryGetValue(TKey key, out TValue value)
|
||||
{
|
||||
return this._dictionary!.TryGetValue(key, out value);
|
||||
}
|
||||
|
||||
public TValue this[TKey key]
|
||||
{
|
||||
get
|
||||
{
|
||||
if (this._dictionary!.ContainsKey(key))
|
||||
if(this._dictionary[key] is string s && !string.IsNullOrEmpty(s) && !string.IsNullOrWhiteSpace(s))
|
||||
return this._dictionary[key];
|
||||
|
||||
return default!;
|
||||
}
|
||||
set => this._dictionary![key] = value;
|
||||
}
|
||||
|
||||
public ICollection<TKey> Keys => _dictionary!.Keys;
|
||||
public ICollection<TValue> Values => _dictionary!.Values;
|
||||
}
|
||||
@@ -1,24 +1,18 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<DebugType>none</DebugType>
|
||||
<DebugSymbols>false</DebugSymbols>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Remove="BlankWindow1.xaml" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Discord.Net" Version="3.7.2" />
|
||||
<PackageReference Include="System.Data.SQLite" Version="1.0.116" />
|
||||
<PackageReference Include="Terminal.Gui" Version="1.8.2" />
|
||||
<PackageReference Include="Discord.Net" Version="3.11.0" />
|
||||
<PackageReference Include="System.Data.SQLite.Core" Version="1.0.118" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -1,21 +0,0 @@
|
||||
using System.IO;
|
||||
|
||||
using PluginManager.Database;
|
||||
|
||||
namespace PluginManager
|
||||
{
|
||||
public class Settings
|
||||
{
|
||||
|
||||
public static class Variables
|
||||
{
|
||||
public static string WebsiteURL = "https://wizzy69.github.io/SethDiscordBot";
|
||||
public static string UpdaterURL = "https://github.com/Wizzy69/installer/releases/download/release-1-discordbot/Updater.zip";
|
||||
|
||||
public static TextWriter outputStream;
|
||||
}
|
||||
|
||||
public static SqlDatabase sqlDatabase;
|
||||
}
|
||||
|
||||
}
|
||||
164
README.md
164
README.md
@@ -8,91 +8,96 @@ This project is based on:
|
||||
|
||||
|
||||
## Plugins
|
||||
#### Requirements:
|
||||
- [Visual Studio](https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=Community&channel=Release&version=VS2022&source=VSLandingPage&cid=2030&passive=false)
|
||||
- .NET 6 (downloaded with Visual Studio)
|
||||
- Some plugins can be found in [this repo](https://github.com/andreitdr/SethPlugins).
|
||||
|
||||
Plugin Types:
|
||||
1. Commands
|
||||
2. Events
|
||||
3. Slash Commands
|
||||
|
||||
### How to create a plugin
|
||||
|
||||
First of all, Create a new project (class library) in Visual Studio.
|
||||

|
||||
#### Requirements:
|
||||
- [Visual Studio](https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=Community&channel=Release&version=VS2022&source=VSLandingPage&cid=2030&passive=false)
|
||||
- .NET 6 (downloaded with Visual Studio)
|
||||
|
||||

|
||||
First of all, create a new project (class library) in Visual Studio.
|
||||
Then import the PluginManager as reference to your project.
|
||||
|
||||

|
||||
## 1. Commands
|
||||
|
||||

|
||||
|
||||
Now, let's add the PluginManager reference. It can be found inside the bot's main folder under
|
||||
`DiscordBot/bin/Debug/net6.0/PluginManager.dll` or `PluginManager/bin/Debug/net6.0/PluginManager.dll`
|
||||
after one successfull build.
|
||||
|
||||

|
||||
|
||||

|
||||
|
||||
1. Commands
|
||||
|
||||
Commands are loaded when all plugins are loaded into memory. When an user executes the command, only then the Execute function is called.
|
||||
Commands are loaded when all plugins are loaded into memory. The Execute method is called whenever any user (that respects the `requireAdmin` propery) calls the command using the bot prefix and the `Command`.
|
||||
Commands are plugins that allow users to interact with them.
|
||||
Here is an example of class that is a command class
|
||||
Here is an example:
|
||||
```cs
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Discord.WebSocket;
|
||||
|
||||
using PluginManager.Interfaces;
|
||||
|
||||
namespace CMD_Utils
|
||||
namespace LevelingSystem;
|
||||
|
||||
public class LevelCommand : DBCommand
|
||||
{
|
||||
class FlipCoin : DBCommand
|
||||
{
|
||||
public string Command => "flip";
|
||||
public string Command => "level";
|
||||
|
||||
public string Description => "Flip a coin";
|
||||
public List<string> Aliases => new() { "lvl" };
|
||||
|
||||
public string Usage => "flip";
|
||||
public string Description => "Display your current level";
|
||||
|
||||
public bool canUseDM => true;
|
||||
|
||||
public bool canUseServer => true;
|
||||
public string Usage => "level";
|
||||
|
||||
public bool requireAdmin => false;
|
||||
|
||||
public async void Execute(SocketCommandContext context, SocketMessage message, DiscordSocketClient client, bool isDM)
|
||||
public async void ExecuteServer(DBCommandExecutingArguments context)
|
||||
{
|
||||
System.Random random = new System.Random();
|
||||
int r = random.Next(1, 3);
|
||||
if (r == 1)
|
||||
await message.Channel.SendMessageAsync("Heads");
|
||||
else await message.Channel.SendMessageAsync("Tails");
|
||||
//Variables.database is a sql connection that is defined in an auxiliary file in the same napespace as this class
|
||||
object[] user = await Variables.database.ReadDataArrayAsync($"SELECT * FROM Levels WHERE UserID='{context.Message.Author.Id}'");
|
||||
if (user is null)
|
||||
{
|
||||
await context.Channel.SendMessageAsync("You are now unranked !");
|
||||
return;
|
||||
}
|
||||
|
||||
int level = (int)user[1];
|
||||
int exp = (int)user[2];
|
||||
|
||||
var builder = new EmbedBuilder();
|
||||
var r = new Random();
|
||||
builder.WithColor(r.Next(256), r.Next(256), r.Next(256));
|
||||
builder.AddField("Current Level", level, true)
|
||||
.AddField("Current EXP", exp, true)
|
||||
.AddField("Required Exp", (level * 8 + 24).ToString(), true);
|
||||
builder.WithTimestamp(DateTimeOffset.Now);
|
||||
builder.WithAuthor(context.Message.Author.Mention);
|
||||
await context.Channel.SendMessageAsync(embed: builder.Build());
|
||||
}
|
||||
|
||||
//Optional method (tell the bot what should it do if the command is executed from a DM channel)
|
||||
//public async void ExecuteDM(DBCommandExecutingArguments context) {
|
||||
//
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
```
|
||||
#### Code description:
|
||||
- Command - The keyword that triggers the execution for the command. This is what players must type in order to execute your command
|
||||
- Aliases - The aliases that can be used instead of the full name to execute the command
|
||||
- Description - The description of your command. Can be anything you like
|
||||
- Usage - The usage of your command. This is what `help [Command]` command will display
|
||||
- canUseDM - true if you plan to let users execute this command in DM chat with bot
|
||||
- canUseServer - true if you plan to let the users execute this command in a server chat
|
||||
- requireAdmin - true if this command requres an user with Administrator permission in the server
|
||||
- Execute () - the function of your command.
|
||||
- ExecuteServer () - the function that is executed only when the command is invoked in a server channel. (optional)
|
||||
- context - the command context
|
||||
- ExecuteDM () - the function that is executed only when the command is invoked in a private (DM) channel. (optional)
|
||||
- context - the command context
|
||||
- message - the message itself
|
||||
- client - the discord bot client
|
||||
- isDM - true if the message was sent from DM chat
|
||||
|
||||
From here on, start coding. When your plugin is done, build it as any DLL project then add it to the following path
|
||||
`{bot_executable}/Data/Plugins/Commands/<optional subfolder>/yourDLLName.dll`
|
||||
Then, reload bot and execute command `lp` in bot's console. The plugin should be loaded into memory or an error is thrown if not. If an error is thrown, then
|
||||
`{bot_executable}/Data/Plugins/<optional subfolder>/[plugin name].dll`
|
||||
Then, reload bot and execute command `plugin load` in the console. The plugin should be loaded into memory or an error is thrown if not. If an error is thrown, then
|
||||
there is something wrong in your command's code.
|
||||
|
||||
2. Events
|
||||
## 2. Events
|
||||
|
||||
Events are loaded when all plugins are loaded. At the moment when they are loaded, the Start function is called.
|
||||
Events are used if you want the bot to do something when something happens in server. The following example shows you how to catch when a user joins the server
|
||||
@@ -110,8 +115,6 @@ public class OnUserJoin : DBEvent
|
||||
|
||||
public async void Start(Discord.WebSocket.DiscordSocketClient client)
|
||||
{
|
||||
Console.WriteLine($"Hello World from {name}");
|
||||
|
||||
client.UserJoined += async (user) => {
|
||||
await (await user.CreateDMChannelAsync()).SendMessageAsync("Welcome to server !");
|
||||
};
|
||||
@@ -125,3 +128,68 @@ public class OnUserJoin : DBEvent
|
||||
- Start() - The main body of your event. This is executed when the bot loads all plugins
|
||||
- client - the discord bot client
|
||||
|
||||
|
||||
## 3. Slash Commands
|
||||
|
||||
|
||||
Slash commands are server based commands. They work the same way as normal commands, but they require the `/` prefix as they are integrated
|
||||
with the UI of Discord.
|
||||
Here is an example:
|
||||
```cs
|
||||
using Discord;
|
||||
using Discord.WebSocket;
|
||||
|
||||
using PluginManager.Interfaces;
|
||||
|
||||
namespace SlashCommands
|
||||
{
|
||||
public class Random : DBSlashCommand
|
||||
{
|
||||
public string Name => "random";
|
||||
|
||||
public string Description => "Generates a random nunber between 2 values";
|
||||
|
||||
public bool canUseDM => true;
|
||||
|
||||
public List<SlashCommandOptionBuilder> Options => new List<SlashCommandOptionBuilder>()
|
||||
{
|
||||
new SlashCommandOptionBuilder() {Name = "min-value", Description = "Minimum value", IsRequired=true, Type = ApplicationCommandOptionType.Integer, MinValue = 0, MaxValue = int.MaxValue-1},
|
||||
new SlashCommandOptionBuilder() {Name = "max-value", Description = "Maximum value", IsRequired=true, Type=ApplicationCommandOptionType.Integer,MinValue = 0, MaxValue = int.MaxValue-1}
|
||||
};
|
||||
|
||||
public async void ExecuteServer(SocketSlashCommand command)
|
||||
{
|
||||
var rnd = new System.Random();
|
||||
var options = command.Data.Options.ToArray();
|
||||
if (options.Count() != 2)
|
||||
{
|
||||
await command.RespondAsync("Invalid parameters", ephemeral: true);
|
||||
return;
|
||||
}
|
||||
|
||||
Int64 numberOne = (Int64)options[0].Value;
|
||||
Int64 numberTwo = (Int64)options[1].Value;
|
||||
|
||||
await command.RespondAsync("Your generated number is " + rnd.Next((int)numberOne, (int)numberTwo), ephemeral: true);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### Code description:
|
||||
- Name - the command name (execute with /{Name})
|
||||
- Description - The description of the command
|
||||
- canUseDM - true id this command can be activated in DM chat, false otherwise
|
||||
- Options - the arguments of the command
|
||||
- ExecuteServer() - this function will be called if the command is invoked in a server channel (optional)
|
||||
- context - the command context
|
||||
- ExecuteDM() - this function will be called if the command is invoked in a DM channel (optional)
|
||||
- context - the command context
|
||||
|
||||
|
||||
## Note:
|
||||
You can create multiple commands, events and slash commands into one single plugin (class library). The PluginManager will detect the classes and load them individualy. If there are more commands (normal commands, events or slash commands) into a single project (class library) they can use the same resources (a class for example) that is contained within the plugin.
|
||||
|
||||
|
||||
> Updated: 25.09.2023
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
|
||||
|
||||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.1.32421.90
|
||||
@@ -7,11 +7,13 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "DiscordBot", "DiscordBot\Di
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PluginManager", "PluginManager\PluginManager.csproj", "{EDD4D9B3-98DD-4367-A09F-D1C5ACB61132}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MusicLibrary", "..\DiscordBotItems\Plugins\MusicLibrary\MusicLibrary.csproj", "{878DFE01-4596-4EBC-9651-0679598CE794}"
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "SethPlugins", "SethPlugins", "{78B6D390-F61A-453F-B38D-E4C054321615}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SlashCommands", "..\DiscordBotItems\Plugins\SlashCommands\SlashCommands.csproj", "{C2D73BE8-997B-4A4A-8EA5-989BE33EE1DD}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MusicPlayer", "..\SethPlugins\MusicPlayer\MusicPlayer.csproj", "{1690CBBC-BDC0-4DD8-B701-F8817189D9D5}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "LevelingSystem", "..\DiscordBotItems\Plugins\LevelingSystem\LevelingSystem.csproj", "{0138F343-BBB9-4D5F-B499-D9C2978BE9AA}"
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "LevelingSystem", "..\SethPlugins\LevelingSystem\LevelingSystem.csproj", "{BFE3491C-AC01-4252-B242-6451270FC548}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PythonCompatibilityLayer", "..\SethPlugins\PythonCompatibilityLayer\PythonCompatibilityLayer.csproj", "{81ED4953-13E5-4950-96A8-8CEF5FD59559}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@@ -27,22 +29,27 @@ Global
|
||||
{EDD4D9B3-98DD-4367-A09F-D1C5ACB61132}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{EDD4D9B3-98DD-4367-A09F-D1C5ACB61132}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{EDD4D9B3-98DD-4367-A09F-D1C5ACB61132}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{878DFE01-4596-4EBC-9651-0679598CE794}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{878DFE01-4596-4EBC-9651-0679598CE794}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{878DFE01-4596-4EBC-9651-0679598CE794}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{878DFE01-4596-4EBC-9651-0679598CE794}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{C2D73BE8-997B-4A4A-8EA5-989BE33EE1DD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C2D73BE8-997B-4A4A-8EA5-989BE33EE1DD}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C2D73BE8-997B-4A4A-8EA5-989BE33EE1DD}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C2D73BE8-997B-4A4A-8EA5-989BE33EE1DD}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{0138F343-BBB9-4D5F-B499-D9C2978BE9AA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{0138F343-BBB9-4D5F-B499-D9C2978BE9AA}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{0138F343-BBB9-4D5F-B499-D9C2978BE9AA}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{0138F343-BBB9-4D5F-B499-D9C2978BE9AA}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{1690CBBC-BDC0-4DD8-B701-F8817189D9D5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{1690CBBC-BDC0-4DD8-B701-F8817189D9D5}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{1690CBBC-BDC0-4DD8-B701-F8817189D9D5}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{1690CBBC-BDC0-4DD8-B701-F8817189D9D5}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{BFE3491C-AC01-4252-B242-6451270FC548}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{BFE3491C-AC01-4252-B242-6451270FC548}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{BFE3491C-AC01-4252-B242-6451270FC548}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{BFE3491C-AC01-4252-B242-6451270FC548}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{81ED4953-13E5-4950-96A8-8CEF5FD59559}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{81ED4953-13E5-4950-96A8-8CEF5FD59559}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{81ED4953-13E5-4950-96A8-8CEF5FD59559}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{81ED4953-13E5-4950-96A8-8CEF5FD59559}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(NestedProjects) = preSolution
|
||||
{1690CBBC-BDC0-4DD8-B701-F8817189D9D5} = {78B6D390-F61A-453F-B38D-E4C054321615}
|
||||
{BFE3491C-AC01-4252-B242-6451270FC548} = {78B6D390-F61A-453F-B38D-E4C054321615}
|
||||
{81ED4953-13E5-4950-96A8-8CEF5FD59559} = {78B6D390-F61A-453F-B38D-E4C054321615}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {3FB3C5DE-ED21-4D2E-ABDD-3A00EE4A2FFF}
|
||||
EndGlobalSection
|
||||
|
||||
Reference in New Issue
Block a user