Reformatting code
This commit is contained in:
@@ -5,12 +5,12 @@ using PluginManager.Others;
|
||||
|
||||
namespace DiscordBot.Bot.Actions;
|
||||
|
||||
public class Clear : ICommandAction
|
||||
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 string ActionName => "clear";
|
||||
public string Description => "Clears the console";
|
||||
public string Usage => "clear";
|
||||
public InternalActionRunType RunType => InternalActionRunType.ON_CALL;
|
||||
|
||||
public Task Execute(string[] args)
|
||||
{
|
||||
|
||||
@@ -6,12 +6,12 @@ using PluginManager.Others;
|
||||
|
||||
namespace DiscordBot.Bot.Actions;
|
||||
|
||||
public class Exit : ICommandAction
|
||||
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 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)
|
||||
{
|
||||
@@ -23,7 +23,7 @@ public class Exit : ICommandAction
|
||||
}
|
||||
else
|
||||
{
|
||||
switch ( args[0] )
|
||||
switch (args[0])
|
||||
{
|
||||
case "help":
|
||||
Console.WriteLine("Usage : exit [help|force]");
|
||||
|
||||
@@ -19,20 +19,20 @@ internal static class PluginMethods
|
||||
internal static async Task List(PluginsManager manager)
|
||||
{
|
||||
var data = await ConsoleUtilities.ExecuteWithProgressBar(manager.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);
|
||||
@@ -42,30 +42,32 @@ internal static class PluginMethods
|
||||
return;
|
||||
}
|
||||
|
||||
var pluginType = pluginData[0];
|
||||
var pluginLink = pluginData[1];
|
||||
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...");
|
||||
.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; });
|
||||
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();
|
||||
});
|
||||
await ServerCom.DownloadFileAsync(pluginLink, $"./Data/{pluginType}s/{pluginName}.dll", progress);
|
||||
|
||||
downloadTask.Increment(100);
|
||||
|
||||
ctx.Refresh();
|
||||
}
|
||||
);
|
||||
|
||||
if (pluginRequirements == string.Empty)
|
||||
{
|
||||
@@ -75,150 +77,162 @@ internal static class PluginMethods
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
gatherInformationTask.Increment(100);
|
||||
});
|
||||
.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);
|
||||
|
||||
gatherInformationTask.Increment(100);
|
||||
}
|
||||
);
|
||||
List<Tuple<ProgressTask, IProgress<float>, string, string>> downloadTasks = new();
|
||||
await AnsiConsole.Progress()
|
||||
.Columns(new ProgressColumn[]
|
||||
{
|
||||
new TaskDescriptionColumn(),
|
||||
new ProgressBarColumn(),
|
||||
new PercentageColumn()
|
||||
})
|
||||
.StartAsync(async ctx =>
|
||||
{
|
||||
|
||||
.Columns(new ProgressColumn[]
|
||||
{
|
||||
new TaskDescriptionColumn(),
|
||||
new ProgressBarColumn(),
|
||||
new PercentageColumn()
|
||||
}
|
||||
)
|
||||
.StartAsync(async ctx =>
|
||||
{
|
||||
|
||||
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;
|
||||
});
|
||||
|
||||
task.IsIndeterminate = true;
|
||||
downloadTasks.Add(new Tuple<ProgressTask, IProgress<float>, string, string>(task, progress, url, fileName));
|
||||
}
|
||||
foreach (var info in requirementsUrLs)
|
||||
{
|
||||
if (info.Length < 2) continue;
|
||||
string[] data = info.Split(',');
|
||||
string url = data[0];
|
||||
string fileName = data[1];
|
||||
|
||||
if (!int.TryParse(Config.AppSettings["MaxParallelDownloads"], out int maxParallelDownloads))
|
||||
{
|
||||
maxParallelDownloads = 5;
|
||||
Config.AppSettings.Add("MaxParallelDownloads", "5");
|
||||
await Config.AppSettings.SaveToFile();
|
||||
}
|
||||
|
||||
var options = new ParallelOptions()
|
||||
{
|
||||
MaxDegreeOfParallelism = maxParallelDownloads,
|
||||
TaskScheduler = TaskScheduler.Default
|
||||
};
|
||||
var task = ctx.AddTask($"Downloading {fileName}: ");
|
||||
IProgress<float> progress = new Progress<float>(p =>
|
||||
{
|
||||
task.Value = p;
|
||||
}
|
||||
);
|
||||
|
||||
await Parallel.ForEachAsync(downloadTasks, options, async (tuple, token) =>
|
||||
{
|
||||
tuple.Item1.IsIndeterminate = false;
|
||||
await ServerCom.DownloadFileAsync(tuple.Item3, $"./{tuple.Item4}", tuple.Item2);
|
||||
});
|
||||
task.IsIndeterminate = true;
|
||||
downloadTasks.Add(new Tuple<ProgressTask, IProgress<float>, string, string>(task, progress, url, fileName));
|
||||
}
|
||||
|
||||
if (!int.TryParse(Config.AppSettings["MaxParallelDownloads"], out int maxParallelDownloads))
|
||||
{
|
||||
maxParallelDownloads = 5;
|
||||
Config.AppSettings.Add("MaxParallelDownloads", "5");
|
||||
await Config.AppSettings.SaveToFile();
|
||||
}
|
||||
|
||||
var options = new ParallelOptions()
|
||||
{
|
||||
MaxDegreeOfParallelism = maxParallelDownloads,
|
||||
TaskScheduler = TaskScheduler.Default
|
||||
};
|
||||
|
||||
await Parallel.ForEachAsync(downloadTasks, options, async (tuple, token) =>
|
||||
{
|
||||
tuple.Item1.IsIndeterminate = false;
|
||||
await ServerCom.DownloadFileAsync(tuple.Item3, $"./{tuple.Item4}", tuple.Item2);
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
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 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);
|
||||
}
|
||||
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);
|
||||
}
|
||||
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;
|
||||
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);
|
||||
}
|
||||
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;
|
||||
};
|
||||
Console.ForegroundColor = cc;
|
||||
};
|
||||
|
||||
loader.onSLSHLoad += (name, typeName, success, exception) =>
|
||||
{
|
||||
if (name == null || name.Length < 2)
|
||||
name = typeName;
|
||||
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);
|
||||
}
|
||||
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;
|
||||
};
|
||||
Console.ForegroundColor = cc;
|
||||
};
|
||||
|
||||
loader.LoadPlugins();
|
||||
Console.ForegroundColor = cc;
|
||||
return true;
|
||||
loader.LoadPlugins();
|
||||
Console.ForegroundColor = cc;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -5,26 +5,26 @@ namespace DiscordBot.Bot.Actions.Extra;
|
||||
|
||||
internal static class SettingsConfigExtra
|
||||
{
|
||||
internal static void SetSettings(string key, params string[] value)
|
||||
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();
|
||||
// Config.AppSettings.SaveToFile().Wait();
|
||||
}
|
||||
|
||||
internal static void RemoveSettings(string key)
|
||||
{
|
||||
if (key is null) return;
|
||||
|
||||
if(!Config.AppSettings.ContainsKey(key))
|
||||
|
||||
if (!Config.AppSettings.ContainsKey(key))
|
||||
return;
|
||||
|
||||
|
||||
Config.AppSettings.Remove(key);
|
||||
}
|
||||
|
||||
@@ -33,11 +33,11 @@ internal static class SettingsConfigExtra
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ using PluginManager.Others;
|
||||
|
||||
namespace DiscordBot.Bot.Actions;
|
||||
|
||||
public class Help : ICommandAction
|
||||
public class Help: ICommandAction
|
||||
{
|
||||
public string ActionName => "help";
|
||||
|
||||
@@ -34,8 +34,8 @@ public class Help : ICommandAction
|
||||
items.Add(new[] { "-", "-", "-" });
|
||||
|
||||
ConsoleUtilities.FormatAndAlignTable(items,
|
||||
TableFormat.CENTER_EACH_COLUMN_BASED
|
||||
);
|
||||
TableFormat.CENTER_EACH_COLUMN_BASED
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ public class Help : ICommandAction
|
||||
};
|
||||
|
||||
ConsoleUtilities.FormatAndAlignTable(actionData,
|
||||
TableFormat.CENTER_EACH_COLUMN_BASED
|
||||
);
|
||||
TableFormat.CENTER_EACH_COLUMN_BASED
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ using Spectre.Console;
|
||||
|
||||
namespace DiscordBot.Bot.Actions;
|
||||
|
||||
public class Plugin : ICommandAction
|
||||
public class Plugin: ICommandAction
|
||||
{
|
||||
private bool pluginsLoaded;
|
||||
public string ActionName => "plugin";
|
||||
@@ -46,7 +46,7 @@ public class Plugin : ICommandAction
|
||||
case "refresh":
|
||||
await PluginMethods.RefreshPlugins(true);
|
||||
break;
|
||||
|
||||
|
||||
case "list":
|
||||
await PluginMethods.List(manager);
|
||||
break;
|
||||
@@ -56,7 +56,7 @@ public class Plugin : ICommandAction
|
||||
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);
|
||||
@@ -84,4 +84,4 @@ public class Plugin : ICommandAction
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ using PluginManager.Others;
|
||||
|
||||
namespace DiscordBot.Bot.Actions;
|
||||
|
||||
public class SettingsConfig : ICommandAction
|
||||
public class SettingsConfig: ICommandAction
|
||||
{
|
||||
public string ActionName => "config";
|
||||
public string Description => "Change the settings of the bot";
|
||||
@@ -19,7 +19,7 @@ public class SettingsConfig : ICommandAction
|
||||
{
|
||||
foreach (var settings in Config.AppSettings)
|
||||
Console.WriteLine(settings.Key + ": " + settings.Value);
|
||||
|
||||
|
||||
return Task.CompletedTask;
|
||||
}
|
||||
|
||||
@@ -27,25 +27,25 @@ public class SettingsConfig : ICommandAction
|
||||
{
|
||||
case "-s":
|
||||
case "set":
|
||||
if(args.Length < 3)
|
||||
if (args.Length < 3)
|
||||
return Task.CompletedTask;
|
||||
SettingsConfigExtra.SetSettings(args[1],args[2..]);
|
||||
SettingsConfigExtra.SetSettings(args[1], args[2..]);
|
||||
break;
|
||||
|
||||
|
||||
case "-r":
|
||||
case "remove":
|
||||
if(args.Length < 2)
|
||||
if (args.Length < 2)
|
||||
return Task.CompletedTask;
|
||||
SettingsConfigExtra.RemoveSettings(args[1]);
|
||||
break;
|
||||
|
||||
|
||||
case "-a":
|
||||
case "add":
|
||||
if(args.Length < 3)
|
||||
if (args.Length < 3)
|
||||
return Task.CompletedTask;
|
||||
SettingsConfigExtra.AddSettings(args[1], args[2..]);
|
||||
break;
|
||||
|
||||
|
||||
case "-h":
|
||||
case "-help":
|
||||
Console.WriteLine("Options:");
|
||||
@@ -54,14 +54,14 @@ public class SettingsConfig : ICommandAction
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ namespace DiscordBot.Bot.Commands;
|
||||
/// <summary>
|
||||
/// The help command
|
||||
/// </summary>
|
||||
internal class Help : DBCommand
|
||||
internal class Help: DBCommand
|
||||
{
|
||||
/// <summary>
|
||||
/// Command name
|
||||
@@ -76,7 +76,7 @@ internal class Help : DBCommand
|
||||
var embedBuilder = new EmbedBuilder();
|
||||
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.AppSettings["prefix"] + cmd.Usage);
|
||||
|
||||
@@ -8,11 +8,11 @@ using PluginManager.Others;
|
||||
|
||||
namespace DiscordBot.Bot.Commands.SlashCommands;
|
||||
|
||||
public class Help : DBSlashCommand
|
||||
public class Help: DBSlashCommand
|
||||
{
|
||||
public string Name => "help";
|
||||
public string Name => "help";
|
||||
public string Description => "This command allows you to check all loaded commands";
|
||||
public bool canUseDM => true;
|
||||
public bool canUseDM => true;
|
||||
|
||||
public List<SlashCommandOptionBuilder> Options =>
|
||||
new()
|
||||
|
||||
@@ -29,13 +29,13 @@
|
||||
<None Remove="Data\**"/>
|
||||
<None Remove="obj\**"/>
|
||||
<None Remove="Output\**"/>
|
||||
<None Remove="builder.bat" />
|
||||
<None Remove="builder.sh" />
|
||||
<None Remove="builder.bat"/>
|
||||
<None Remove="builder.sh"/>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Discord.Net" Version="3.11.0"/>
|
||||
<PackageReference Include="pythonnet" Version="3.0.1" />
|
||||
<PackageReference Include="Spectre.Console" Version="0.47.0" />
|
||||
<PackageReference Include="pythonnet" Version="3.0.1"/>
|
||||
<PackageReference Include="Spectre.Console" Version="0.47.0"/>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\PluginManager\PluginManager.csproj"/>
|
||||
|
||||
@@ -16,16 +16,16 @@ public static class Entry
|
||||
File.Delete(plugin);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
var currentDomain = AppDomain.CurrentDomain;
|
||||
currentDomain.AssemblyResolve += LoadFromSameFolder;
|
||||
|
||||
static Assembly LoadFromSameFolder(object sender, ResolveEventArgs args)
|
||||
{
|
||||
var folderPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "./Libraries");
|
||||
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;
|
||||
var assembly = Assembly.LoadFrom(assemblyPath);
|
||||
|
||||
@@ -9,9 +9,9 @@ public static class Installer
|
||||
{
|
||||
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 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";
|
||||
@@ -20,9 +20,9 @@ public static class Installer
|
||||
Config.AppSettings.Add("ServerID", serverId);
|
||||
|
||||
Config.AppSettings.SaveToFile();
|
||||
|
||||
|
||||
AnsiConsole.MarkupLine("[bold]Config saved ![/]");
|
||||
|
||||
|
||||
Config.Logger.Log("Config Saved", source: typeof(Installer));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,9 +22,9 @@ public class Program
|
||||
public static void Startup(string[] args)
|
||||
{
|
||||
PreLoadComponents(args).Wait();
|
||||
|
||||
|
||||
if (!AppSettings.ContainsKey("ServerID") || !AppSettings.ContainsKey("token") || !AppSettings.ContainsKey("prefix"))
|
||||
Installer.GenerateStartupConfig();
|
||||
Installer.GenerateStartupConfig();
|
||||
|
||||
HandleInput().Wait();
|
||||
}
|
||||
@@ -37,8 +37,8 @@ public class Program
|
||||
internalActionManager.Initialize().Wait();
|
||||
internalActionManager.Execute("plugin", "load").Wait();
|
||||
internalActionManager.Refresh().Wait();
|
||||
|
||||
|
||||
|
||||
|
||||
while (true)
|
||||
{
|
||||
var cmd = Console.ReadLine();
|
||||
@@ -64,21 +64,21 @@ public class Program
|
||||
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");
|
||||
|
||||
|
||||
ConsoleUtilities.WriteColorText("&rRemember to close the bot using the ShutDown command (&yexit&r) or some settings won't be saved");
|
||||
|
||||
ConsoleUtilities.WriteColorText($"Running on &m{Functions.GetOperatingSystem()}");
|
||||
Console.WriteLine("============================ LOG ============================");
|
||||
|
||||
|
||||
Console.ForegroundColor = ConsoleColor.White;
|
||||
try
|
||||
{
|
||||
var token = AppSettings["token"];
|
||||
var token = AppSettings["token"];
|
||||
var prefix = AppSettings["prefix"];
|
||||
var discordbooter = new Boot(token, prefix);
|
||||
await discordbooter.Awake();
|
||||
}
|
||||
catch ( Exception ex )
|
||||
catch (Exception ex)
|
||||
{
|
||||
Logger.Log(ex.ToString(), source: typeof(Program), type: LogType.CRITICAL);
|
||||
}
|
||||
@@ -96,18 +96,20 @@ public class Program
|
||||
internalActionManager = new InternalActionManager("./Data/Plugins", "*.dll");
|
||||
NoGUI();
|
||||
}
|
||||
catch ( IOException ex )
|
||||
catch (IOException ex)
|
||||
{
|
||||
if (ex.Message == "No process is on the other end of the pipe." || (uint)ex.HResult == 0x800700E9)
|
||||
{
|
||||
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 !");
|
||||
|
||||
"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);
|
||||
"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
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -115,7 +117,7 @@ public class Program
|
||||
private static async Task PreLoadComponents(string[] args)
|
||||
{
|
||||
await Initialize();
|
||||
|
||||
|
||||
Logger.OnLog += (sender, logMessage) =>
|
||||
{
|
||||
string messageColor = logMessage.Type switch
|
||||
@@ -133,10 +135,10 @@ public class Program
|
||||
Console.WriteLine(logMessage.Message);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
AnsiConsole.MarkupLine($"{messageColor}{logMessage.ThrowTime} {logMessage.Message} [/]");
|
||||
};
|
||||
|
||||
|
||||
AppSettings["Version"] = Assembly.GetExecutingAssembly().GetName().Version.ToString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,24 +9,24 @@ namespace DiscordBot.Utilities;
|
||||
|
||||
public class TableData
|
||||
{
|
||||
public List<string> Columns;
|
||||
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);
|
||||
@@ -41,23 +41,23 @@ public static class ConsoleUtilities
|
||||
T result = default;
|
||||
await AnsiConsole.Progress()
|
||||
.Columns(
|
||||
new ProgressColumn[]
|
||||
{
|
||||
new TaskDescriptionColumn(),
|
||||
new ProgressBarColumn(),
|
||||
new PercentageColumn(),
|
||||
}
|
||||
)
|
||||
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);
|
||||
async ctx =>
|
||||
{
|
||||
var task = ctx.AddTask(message);
|
||||
task.IsIndeterminate = true;
|
||||
result = await function;
|
||||
task.Increment(100);
|
||||
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -66,21 +66,23 @@ public static class ConsoleUtilities
|
||||
{
|
||||
await AnsiConsole.Progress()
|
||||
.Columns(new ProgressColumn[]
|
||||
{
|
||||
new TaskDescriptionColumn(),
|
||||
new ProgressBarColumn(),
|
||||
new PercentageColumn(),
|
||||
})
|
||||
{
|
||||
new TaskDescriptionColumn(),
|
||||
new ProgressBarColumn(),
|
||||
new PercentageColumn(),
|
||||
}
|
||||
)
|
||||
.StartAsync(async ctx =>
|
||||
{
|
||||
var task = ctx.AddTask(message);
|
||||
task.IsIndeterminate = true;
|
||||
await function;
|
||||
task.Increment(100);
|
||||
|
||||
});
|
||||
{
|
||||
var task = ctx.AddTask(message);
|
||||
task.IsIndeterminate = true;
|
||||
await function;
|
||||
task.Increment(100);
|
||||
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
private static readonly Dictionary<char, ConsoleColor> Colors = new()
|
||||
{
|
||||
{ 'g', ConsoleColor.Green },
|
||||
@@ -91,7 +93,7 @@ public static class ConsoleUtilities
|
||||
};
|
||||
|
||||
private static readonly char ColorPrefix = '&';
|
||||
|
||||
|
||||
private static bool CanAproximateTo(this float f, float y)
|
||||
{
|
||||
return MathF.Abs(f - y) < 0.000001;
|
||||
@@ -104,7 +106,7 @@ public static class ConsoleUtilities
|
||||
table.AddColumns(tableData.Columns.ToArray());
|
||||
foreach (var row in tableData.Rows)
|
||||
table.AddRow(row);
|
||||
|
||||
|
||||
AnsiConsole.Write(table);
|
||||
}
|
||||
|
||||
@@ -123,12 +125,12 @@ public static class ConsoleUtilities
|
||||
data.RemoveAt(0);
|
||||
foreach (var row in data)
|
||||
table.AddRow(row);
|
||||
|
||||
|
||||
AnsiConsole.Write(table);
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (format == TableFormat.CENTER_EACH_COLUMN_BASED)
|
||||
{
|
||||
var tableLine = '-';
|
||||
@@ -317,18 +319,18 @@ public static class ConsoleUtilities
|
||||
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);
|
||||
}
|
||||
}
|
||||
);
|
||||
{
|
||||
while (isRunning)
|
||||
{
|
||||
Console.SetCursorPosition(0, Console.CursorTop);
|
||||
Console.Write(" " + Sequence[position] + " " + Message + " ");
|
||||
position++;
|
||||
if (position >= Sequence.Length)
|
||||
position = 0;
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
thread.Start();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user