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.Others; namespace DiscordBot.Discord.Commands { internal class Restart : DBCommand { /// /// Command name /// public string Command => "restart"; /// /// Command Description /// public string Description => "Restart the bot"; /// /// Command usage /// public string Usage => "restart [-p | -c | -args | -cmd] "; /// /// Check if the command can be used /> /// public bool canUseDM => false; /// /// Check if the command can be used in a server /// public bool canUseServer => true; /// /// Check if the command require administrator to be executed /// public bool requireAdmin => false; /// /// The main body of the command /// /// The command context /// The command message /// The discord bot client /// True if the message was sent from a DM channel, false otherwise public async void 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); var OS = Functions.GetOperatinSystem(); if (args.Count == 0) { switch (OS) { case PluginManager.Others.OperatingSystem.WINDOWS: Process.Start("./DiscordBot.exe"); break; case PluginManager.Others.OperatingSystem.LINUX: case PluginManager.Others.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": switch (OS) { case PluginManager.Others.OperatingSystem.WINDOWS: Process.Start("./DiscordBot.exe", Functions.MergeStrings(args.ToArray(), 1)); break; case PluginManager.Others.OperatingSystem.LINUX: case PluginManager.Others.OperatingSystem.MAC_OS: Process.Start("./DiscordBot", Functions.MergeStrings(args.ToArray(), 1)); break; default: return; } Environment.Exit(0); break; default: await context.Channel.SendMessageAsync("Invalid argument. Use `help restart` to see the usage."); break; } } } }