Exemplo n.º 1
0
 private async Task Action_SendCommand(SocketMessage message, string command)
 {
     string[] args = command.Split(' ');
     if (args.Length >= 2 && int.TryParse(args[1], out int i))
     {
         await Application.Current.Dispatcher.Invoke(async() =>
         {
             MainWindow WindowsGSM = (MainWindow)Application.Current.MainWindow;
             if (WindowsGSM.IsServerExist(args[1]))
             {
                 MainWindow.ServerStatus serverStatus = WindowsGSM.GetServerStatus(args[1]);
                 if (serverStatus == MainWindow.ServerStatus.Started)
                 {
                     string sendCommand = command.Substring(args[1].Length + 6);
                     bool sent          = await WindowsGSM.SendCommandById(args[1], sendCommand, message.Author.Id.ToString(), message.Author.Username);
                     await message.Channel.SendMessageAsync($"Server (ID: {args[1]}) {(sent ? "Command sent" : "Fail to send command")}. | `{sendCommand}`");
                 }
                 else
                 {
                     await message.Channel.SendMessageAsync($"Server (ID: {args[1]}) currently in {serverStatus.ToString()} state, not able to send command.");
                 }
             }
             else
             {
                 await message.Channel.SendMessageAsync($"Server (ID: {args[1]}) does not exists.");
             }
         });
     }
     else
     {
         await message.Channel.SendMessageAsync($"Usage: {Configs.GetBotPrefix()}wgsm send `<SERVERID>` `<COMMAND>`");
     }
 }
Exemplo n.º 2
0
 private async Task Action_Backup(SocketMessage message, string command)
 {
     string[] args = command.Split(' ');
     if (args.Length >= 2 && int.TryParse(args[1], out int i))
     {
         await Application.Current.Dispatcher.Invoke(async() =>
         {
             MainWindow WindowsGSM = (MainWindow)Application.Current.MainWindow;
             if (WindowsGSM.IsServerExist(args[1]))
             {
                 MainWindow.ServerStatus serverStatus = WindowsGSM.GetServerStatus(args[1]);
                 if (serverStatus == MainWindow.ServerStatus.Stopped)
                 {
                     await message.Channel.SendMessageAsync($"Server (ID: {args[1]}) Backup started - this may take some time.");
                     bool backuped = await WindowsGSM.BackupServerById(args[1], message.Author.Id.ToString(), message.Author.Username);
                     await message.Channel.SendMessageAsync($"Server (ID: {args[1]}) {(backuped ? "Backup Complete" : "Fail to Backup")}.");
                 }
                 else if (serverStatus == MainWindow.ServerStatus.Backuping)
                 {
                     await message.Channel.SendMessageAsync($"Server (ID: {args[1]}) already Backuping.");
                 }
                 else
                 {
                     await message.Channel.SendMessageAsync($"Server (ID: {args[1]}) currently in {serverStatus.ToString()} state, not able to backup.");
                 }
             }
             else
             {
                 await message.Channel.SendMessageAsync($"Server (ID: {args[1]}) does not exists.");
             }
         });
     }
     else
     {
         await message.Channel.SendMessageAsync($"Usage: {Configs.GetBotPrefix()}wgsm backup `<SERVERID>`");
     }
 }
Exemplo n.º 3
0
        private async Task Action_Restart(SocketMessage message, string command)
        {
            string[] args = command.Split(' ');
            if (args.Length == 2 && int.TryParse(args[1], out int i))
            {
                await Application.Current.Dispatcher.Invoke(async() =>
                {
                    MainWindow WindowsGSM = (MainWindow)Application.Current.MainWindow;
                    if (WindowsGSM.IsServerExist(args[1]))
                    {
                        MainWindow.ServerStatus serverStatus = WindowsGSM.GetServerStatus(args[1]);
                        if (serverStatus == MainWindow.ServerStatus.Started)
                        {
                            bool started = await WindowsGSM.RestartServerById(args[1], message.Author.Id.ToString(), message.Author.Username);
                            await message.Channel.SendMessageAsync($"Server (ID: {args[1]}) {(started ? "Restarted" : "Fail to Restart")}.");
                        }
                        else
                        {
                            await message.Channel.SendMessageAsync($"Server (ID: {args[1]}) currently in {serverStatus.ToString()} state, not able to restart.");
                        }

                        await SendServerEmbed(message, Color.Blue, args[1], WindowsGSM.GetServerStatus(args[1]).ToString(), WindowsGSM.GetServerName(args[1]));
                    }
                    else
                    {
                        await message.Channel.SendMessageAsync($"Server (ID: {args[1]}) does not exists.");
                    }
                });
            }
            else
            {
                await message.Channel.SendMessageAsync($"Usage: {Configs.GetBotPrefix()}wgsm restart `<SERVERID>`");
            }
        }