patch
This commit is contained in:
@@ -8,7 +8,7 @@
|
|||||||
<StartupObject />
|
<StartupObject />
|
||||||
<SignAssembly>False</SignAssembly>
|
<SignAssembly>False</SignAssembly>
|
||||||
<IsPublishable>True</IsPublishable>
|
<IsPublishable>True</IsPublishable>
|
||||||
<AssemblyVersion>1.0.1.0</AssemblyVersion>
|
<AssemblyVersion>1.0.1.1</AssemblyVersion>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
|
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
using Discord.WebSocket;
|
using Discord.WebSocket;
|
||||||
|
|
||||||
using PluginManager.Interfaces;
|
|
||||||
using PluginManager.Loaders;
|
using PluginManager.Loaders;
|
||||||
using PluginManager.Online;
|
using PluginManager.Online;
|
||||||
using PluginManager.Others;
|
using PluginManager.Others;
|
||||||
@@ -259,6 +258,8 @@ public class ConsoleCommandsHandler
|
|||||||
await Config.Plugins.SetVersionAsync(name, ver);
|
await Config.Plugins.SetVersionAsync(name, ver);
|
||||||
|
|
||||||
isDownloading = false;
|
isDownloading = false;
|
||||||
|
|
||||||
|
await ExecuteCommad("localload " + name);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -307,15 +308,10 @@ public class ConsoleCommandsHandler
|
|||||||
{
|
{
|
||||||
if (client is null)
|
if (client is null)
|
||||||
return;
|
return;
|
||||||
var bar = new Utilities.ProgressBar(ProgressBarType.NO_END);
|
|
||||||
|
|
||||||
bar.Start();
|
|
||||||
bar.Stop("Saved config !");
|
|
||||||
Settings.Variables.outputStream.WriteLine();
|
|
||||||
Settings.sqlDatabase.Stop();
|
Settings.sqlDatabase.Stop();
|
||||||
await client.StopAsync();
|
await client.StopAsync();
|
||||||
await client.DisposeAsync();
|
await client.DisposeAsync();
|
||||||
|
|
||||||
await Task.Delay(1000);
|
await Task.Delay(1000);
|
||||||
Environment.Exit(0);
|
Environment.Exit(0);
|
||||||
}
|
}
|
||||||
@@ -335,19 +331,23 @@ public class ConsoleCommandsHandler
|
|||||||
await s.CopyToAsync(str);
|
await s.CopyToAsync(str);
|
||||||
var asmb = Assembly.Load(str.ToArray());
|
var asmb = Assembly.Load(str.ToArray());
|
||||||
|
|
||||||
var types = asmb.GetTypes();
|
await PluginLoader.LoadPluginFromAssembly(asmb, this.client);
|
||||||
foreach (var type in types)
|
}
|
||||||
if (type.IsClass && typeof(DBEvent).IsAssignableFrom(type))
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
var instance = (DBEvent)Activator.CreateInstance(type);
|
Settings.Variables.outputStream.WriteLine(ex.Message);
|
||||||
instance.Start(this.client);
|
}
|
||||||
Settings.Variables.outputStream.WriteLine($"[EVENT] Loaded external {type.FullName}!");
|
});
|
||||||
}
|
|
||||||
else if (type.IsClass && typeof(DBCommand).IsAssignableFrom(type))
|
AddCommand("localload", "Load a local command", "local [pluginName]", async args =>
|
||||||
{
|
{
|
||||||
var instance = (DBCommand)Activator.CreateInstance(type);
|
if (args.Length <= 1) return;
|
||||||
Settings.Variables.outputStream.WriteLine($"[CMD] Instance: {type.FullName} loaded !");
|
try
|
||||||
}
|
{
|
||||||
|
var pName = string.Join(' ', args, 1, args.Length - 1);
|
||||||
|
var asmb = Assembly.LoadFile(Path.GetFullPath("./Data/Plugins/" + pName + ".dll"));
|
||||||
|
|
||||||
|
await PluginLoader.LoadPluginFromAssembly(asmb, this.client);
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -422,6 +422,7 @@ public class ConsoleCommandsHandler
|
|||||||
|
|
||||||
AddCommand("reload", "Reload the bot with all plugins", () =>
|
AddCommand("reload", "Reload the bot with all plugins", () =>
|
||||||
{
|
{
|
||||||
|
|
||||||
if (Functions.GetOperatingSystem() == OperatingSystem.WINDOWS)
|
if (Functions.GetOperatingSystem() == OperatingSystem.WINDOWS)
|
||||||
{
|
{
|
||||||
Process.Start("DiscordBot.exe", "lp");
|
Process.Start("DiscordBot.exe", "lp");
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
|
using System.Reflection;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
using Discord;
|
using Discord;
|
||||||
@@ -108,7 +109,7 @@ public class PluginLoader
|
|||||||
|
|
||||||
private async void Loader_PluginLoaded(LoaderArgs args)
|
private async void Loader_PluginLoaded(LoaderArgs args)
|
||||||
{
|
{
|
||||||
// Settings.Variables.outputStream.WriteLine(args.TypeName);
|
|
||||||
switch (args.TypeName)
|
switch (args.TypeName)
|
||||||
{
|
{
|
||||||
case "DBCommand":
|
case "DBCommand":
|
||||||
@@ -139,7 +140,7 @@ public class PluginLoader
|
|||||||
builder.WithDescription(slash.Description);
|
builder.WithDescription(slash.Description);
|
||||||
builder.WithDMPermission(slash.canUseDM);
|
builder.WithDMPermission(slash.canUseDM);
|
||||||
builder.Options = slash.Options;
|
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());
|
await _client.CreateGlobalApplicationCommandAsync(builder.Build());
|
||||||
|
|
||||||
@@ -148,4 +149,36 @@ public class PluginLoader
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
public static async Task LoadPluginFromAssembly(Assembly asmb, DiscordSocketClient client)
|
||||||
|
{
|
||||||
|
var types = asmb.GetTypes();
|
||||||
|
foreach (var type in types)
|
||||||
|
if (type.IsClass && typeof(DBEvent).IsAssignableFrom(type))
|
||||||
|
{
|
||||||
|
var instance = (DBEvent)Activator.CreateInstance(type);
|
||||||
|
instance.Start(client);
|
||||||
|
PluginLoader.Events.Add(instance);
|
||||||
|
Settings.Variables.outputStream.WriteLine($"[EVENT] Loaded external {type.FullName}!");
|
||||||
|
}
|
||||||
|
else if (type.IsClass && typeof(DBCommand).IsAssignableFrom(type))
|
||||||
|
{
|
||||||
|
var instance = (DBCommand)Activator.CreateInstance(type);
|
||||||
|
PluginLoader.Commands.Add(instance);
|
||||||
|
Settings.Variables.outputStream.WriteLine($"[CMD] Instance: {type.FullName} loaded !");
|
||||||
|
}
|
||||||
|
else if (type.IsClass && typeof(DBSlashCommand).IsAssignableFrom(type))
|
||||||
|
{
|
||||||
|
var instance = (DBSlashCommand)Activator.CreateInstance(type);
|
||||||
|
SlashCommandBuilder builder = new SlashCommandBuilder();
|
||||||
|
builder.WithName(instance.Name);
|
||||||
|
builder.WithDescription(instance.Description);
|
||||||
|
builder.WithDMPermission(instance.canUseDM);
|
||||||
|
builder.Options = instance.Options;
|
||||||
|
|
||||||
|
await client.CreateGlobalApplicationCommandAsync(builder.Build());
|
||||||
|
PluginLoader.SlashCommands.Add(instance);
|
||||||
|
Settings.Variables.outputStream.WriteLine($"[SLASH] Instance: {type.FullName} loaded !");
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -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;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -41,11 +41,6 @@ public static class Functions
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly string pakFolder = @"./Data/PAKS/";
|
public static readonly string pakFolder = @"./Data/PAKS/";
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Beta testing folder
|
|
||||||
/// </summary>
|
|
||||||
public static readonly string betaFolder = @"./Data/BetaTest/";
|
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Read data from a file that is inside an archive (ZIP format)
|
/// Read data from a file that is inside an archive (ZIP format)
|
||||||
|
|||||||
Reference in New Issue
Block a user