Reimplemented Command Actions.
This commit is contained in:
62
DiscordBot/Discord/Actions/Help.cs
Normal file
62
DiscordBot/Discord/Actions/Help.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using PluginManager.Others;
|
||||
using PluginManager.Interfaces;
|
||||
|
||||
namespace DiscordBot.Discord.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[] { "-", "-", "-" });
|
||||
|
||||
DiscordBot.Utilities.Utilities.FormatAndAlignTable(items, Utilities.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[] { "-", "-", "-" }
|
||||
};
|
||||
|
||||
DiscordBot.Utilities.Utilities.FormatAndAlignTable(actionData, Utilities.TableFormat.CENTER_EACH_COLUMN_BASED);
|
||||
}
|
||||
}
|
||||
}
|
||||
49
DiscordBot/Discord/Actions/ListPlugins.cs
Normal file
49
DiscordBot/Discord/Actions/ListPlugins.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
using PluginManager.Interfaces;
|
||||
using PluginManager.Others;
|
||||
|
||||
namespace DiscordBot.Discord.Actions
|
||||
{
|
||||
public class ListPlugins : ICommandAction
|
||||
{
|
||||
public string ActionName => "listplugs";
|
||||
|
||||
public string Description => "Lists all plugins";
|
||||
|
||||
public string Usage => "listplugs";
|
||||
|
||||
public InternalActionRunType RunType => InternalActionRunType.ON_CALL;
|
||||
|
||||
public async Task Execute(string[] args)
|
||||
{
|
||||
|
||||
var manager = new PluginManager.Online.PluginsManager(Program.URLs["PluginList"], Program.URLs["PluginVersions"]);
|
||||
if (manager == null)
|
||||
{
|
||||
Console.WriteLine("Plugin manager is null");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
var data = await manager.GetAvailablePlugins();
|
||||
var items = new List<string[]>
|
||||
{
|
||||
new[] { "-", "-", "-", "-" },
|
||||
new[] { "Name", "Type", "Description", "Required" },
|
||||
new[] { "-", "-", "-", "-" }
|
||||
};
|
||||
|
||||
foreach (var plugin in data)
|
||||
{
|
||||
items.Add(new[] { plugin[0], plugin[1], plugin[2], plugin[3] });
|
||||
}
|
||||
|
||||
items.Add(new[] { "-", "-", "-", "-" });
|
||||
|
||||
DiscordBot.Utilities.Utilities.FormatAndAlignTable(items, Utilities.TableFormat.DEFAULT);
|
||||
}
|
||||
}
|
||||
}
|
||||
94
DiscordBot/Discord/Actions/LoadPlugins.cs
Normal file
94
DiscordBot/Discord/Actions/LoadPlugins.cs
Normal file
@@ -0,0 +1,94 @@
|
||||
using System.Runtime.CompilerServices;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
using PluginManager.Interfaces;
|
||||
using PluginManager.Loaders;
|
||||
using PluginManager.Others;
|
||||
|
||||
namespace DiscordBot.Discord.Actions
|
||||
{
|
||||
public class LoadPlugins : ICommandAction
|
||||
{
|
||||
public string ActionName => "loadplugs";
|
||||
|
||||
public string Description => "Loads all plugins";
|
||||
|
||||
public string Usage => "loadplugs";
|
||||
|
||||
private bool pluginsLoaded = false;
|
||||
|
||||
public InternalActionRunType RunType => InternalActionRunType.ON_STARTUP;
|
||||
|
||||
public async Task Execute(string[] args)
|
||||
{
|
||||
if (pluginsLoaded)
|
||||
return;
|
||||
var loader = new PluginLoader(PluginManager.Config.DiscordBot.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;
|
||||
Console.WriteLine("[CMD] Successfully loaded command : " + name);
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
if (exception is null)
|
||||
Console.WriteLine("An error occured while loading: " + name);
|
||||
else
|
||||
Console.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;
|
||||
Console.WriteLine("[EVENT] Successfully loaded event : " + name);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.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;
|
||||
Console.WriteLine("[SLASH] Successfully loaded command : " + name);
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.ForegroundColor = ConsoleColor.Red;
|
||||
Console.WriteLine("[SLASH] Failed to load command : " + name + " because " + exception!.Message);
|
||||
}
|
||||
|
||||
Console.ForegroundColor = cc;
|
||||
};
|
||||
|
||||
loader.LoadPlugins();
|
||||
Console.ForegroundColor = cc;
|
||||
pluginsLoaded = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user