This commit is contained in:
2022-04-22 14:34:55 +03:00
parent 923d3109ba
commit aefd06e8eb
26 changed files with 368 additions and 287 deletions

View File

@@ -1,6 +1,4 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>
<dependentAssembly>
<assemblyIdentity name="System.Runtime" publicKeyToken="b03f5f7f11d50a3a" culture="neutral"/>
<bindingRedirect oldVersion="0.0.0.0-5.0.0.0" newVersion="4.0.0.0"/>
</dependentAssembly>

View File

@@ -9,7 +9,7 @@ using PluginManager.Others;
using System.Collections.Generic;
namespace PluginManager.Commands
namespace DiscordBot.Discord.Commands
{
internal class Help : DBCommand
{

View File

@@ -0,0 +1,65 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Diagnostics;
using System.Text;
using System.Threading.Tasks;
using Discord.WebSocket;
using dsc = Discord.Commands;
using ds = Discord;
using PluginManager.Interfaces;
using PluginManager.Others.Permissions;
using PluginManager.Online;
using PluginManager.Others;
namespace DiscordBot.Discord.Commands
{
class Restart : DBCommand
{
string DBCommand.Command => "restart";
string DBCommand.Description => "Restart the bot";
string DBCommand.Usage => "restart [-option]";
bool DBCommand.canUseDM => false;
bool DBCommand.canUseServer => true;
bool DBCommand.requireAdmin => true;
void DBCommand.Execute(dsc.SocketCommandContext context, SocketMessage message, DiscordSocketClient client, bool isDM)
{
if (!DiscordPermissions.hasPermission(message.Author as SocketGuildUser, ds.GuildPermission.Administrator)) return;
var args = Functions.GetArguments(message);
if (args.Count != 0)
{
switch (args[0])
{
case "-p":
case "-poweroff":
case "-c":
case "-close":
Environment.Exit(0);
break;
case "-cmd":
case "-args":
Process.Start("./DiscordBot.exe", Functions.MergeStrings(args.ToArray(), 1));
Environment.Exit(0);
break;
}
return;
}
Process.Start("./DiscordBot.exe", "--execute:lp");
Environment.Exit(0);
}
}
}

View File

@@ -21,9 +21,6 @@ namespace PluginManager.Core
private readonly CommandService commandService;
private readonly string botPrefix;
internal static bool awaitRestartOnSetCommand = false;
internal static SocketUser RestartOnSetCommandCaster = null;
public CommandHandler(DiscordSocketClient client, CommandService commandService, string botPrefix)
{
this.client = client;
@@ -56,28 +53,7 @@ namespace PluginManager.Core
return;
}
if (!(message.HasStringPrefix(botPrefix, ref argPos) || message.Author.IsBot))
if (message.Author.IsBot) return;
else
{
if (awaitRestartOnSetCommand && RestartOnSetCommandCaster is not null)
{
if (message.Content.ToLower() == "yes")
{
if (!(((SocketGuildUser)message.Author).hasPermission(GuildPermission.Administrator)))
{
await message.Channel.SendMessageAsync("You do not have permission to use this command !");
awaitRestartOnSetCommand = false;
RestartOnSetCommandCaster = null;
return;
}
var fileName = Assembly.GetExecutingAssembly().Location;
System.Diagnostics.Process.Start(fileName);
Environment.Exit(0);
}
}
return;
}
if (message.Author.IsBot) return;
var context = new SocketCommandContext(client, message);

View File

@@ -4,6 +4,8 @@
<OutputType>Exe</OutputType>
<TargetFramework>net5.0</TargetFramework>
<Nullable>disable</Nullable>
<ApplicationIcon />
<StartupObject />
</PropertyGroup>
<ItemGroup>