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_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>`");
            }
        }
Exemplo n.º 3
0
 private async Task Action_Update(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]}) Update started - this may take some time.");
                     bool updated = await WindowsGSM.UpdateServerById(args[1], message.Author.Id.ToString(), message.Author.Username);
                     await message.Channel.SendMessageAsync($"Server (ID: {args[1]}) {(updated ? "Updated" : "Fail to Update")}.");
                 }
                 else if (serverStatus == MainWindow.ServerStatus.Updating)
                 {
                     await message.Channel.SendMessageAsync($"Server (ID: {args[1]}) already Updating.");
                 }
                 else
                 {
                     await message.Channel.SendMessageAsync($"Server (ID: {args[1]}) currently in {serverStatus} state, not able to update.");
                 }
             }
             else
             {
                 await message.Channel.SendMessageAsync($"Server (ID: {args[1]}) does not exists.");
             }
         });
     }
     else
     {
         await message.Channel.SendMessageAsync($"Usage: {Configs.GetBotPrefix()}wgsm update `<SERVERID>`");
     }
 }