Ejemplo n.º 1
0
        public async Task ServerPowerShell(CommandContext ctx, string serverName, [RemainingText] string script)
        {
            await ctx.TriggerTypingAsync();

            if (!script.StartsWith("```\n") && !script.EndsWith("```"))
            {
                await ctx.RespondAsync(embed : EmbedTemplates.CreateErrorEmbed("PowerShell",
                                                                               "**No script found!** Example Script: ```\necho 'test'\n```"));

                return;
            }

            if (!(Server.GetServers(true, serverName)[0] is Server server))
            {
                await ctx.RespondAsync(embed : EmbedTemplates.CreateErrorEmbed("Server Not Found",
                                                                               $"{serverName} could not be found."));

                return;
            }

            server.FileSystemService.CreateTextFile(@"C:\\DiscordScripts\\script.ps1",
                                                    Encoding.ASCII.GetBytes(script.Replace("```\n", string.Empty).Replace("```", string.Empty)));
            var console = new RemoteConsole(server, @"C:\\Windows\\System32\\cmd.exe",
                                            "/c powershell \"C:\\DiscordScripts\\script.ps1\"", "Powershell - Script", true);

            await ctx.RespondAsync(embed : EmbedTemplates.CreateInfoEmbed("Live Output",
                                                                          $"To start the command, click [here]({console.GetUrl()})"));
        }
Ejemplo n.º 2
0
        public async System.Threading.Tasks.Task TaskViewer(CommandContext ctx, string serviceConnectionInfo)
        {
            await ctx.TriggerTypingAsync();

            if (!(Service.GetGameServices(serviceConnectionInfo)[0] is Service service) || !service.Find())
            {
                await ctx.RespondAsync(embed : EmbedTemplates.CreateErrorEmbed("Task Manager",
                                                                               "**Cannot find service with search criteria: ** *" + serviceConnectionInfo + "*"));

                return;
            }

            var serviceTaskList =
                TCAdmin.TaskScheduler.SDK.Objects.Task.GetTasksForSource(service.GetType().ToString(),
                                                                         service.ServiceId.ToString());
            var servicesTask = serviceTaskList.Cast <TCAdmin.TaskScheduler.SDK.Objects.Task>().ToList();

            if (servicesTask.Count == 0)
            {
                await ctx.RespondAsync(embed : EmbedTemplates.CreateErrorEmbed("Task Manager", "No Tasks Found"));

                return;
            }

            var taskManager =
                new TcaTaskManager(
                    await ctx.RespondAsync(embed: EmbedTemplates.CreateInfoEmbed("Task Manager", "Initialize...")),
                    servicesTask.Last().TaskId);
            await taskManager.Initialize();
        }
Ejemplo n.º 3
0
        public async System.Threading.Tasks.Task TaskViewer(CommandContext ctx, int taskId)
        {
            await ctx.TriggerTypingAsync();

            var taskManager =
                new TcaTaskManager(
                    await ctx.RespondAsync(embed: EmbedTemplates.CreateInfoEmbed("Task Manager", "Initialize...")),
                    taskId);
            await taskManager.Initialize();
        }
Ejemplo n.º 4
0
        public async Task UnlinkServices(CommandContext ctx)
        {
            var msg = await ctx.RespondAsync(embed : EmbedTemplates.CreateInfoEmbed("Unlink Services",
                                                                                    "Unlinking all services. Please wait..."));

            DiscordService.ResetAllServices(ctx);
            await msg.ModifyAsync(
                embed : new Optional <DiscordEmbed>(
                    EmbedTemplates.CreateSuccessEmbed(description: "Unlinked all services.")));
        }
Ejemplo n.º 5
0
        public async System.Threading.Tasks.Task RconTask()
        {
            var interactivity = CommandContext.Client.GetInteractivity();
            await CommandContext.RespondAsync(embed : EmbedTemplates.CreateInfoEmbed("Remote Console",
                                                                                     "Please enter the RCON command to send to the server."));

            var command = await interactivity.WaitForMessageAsync(
                x => x.Author.Id == CommandContext.User.Id && x.Channel.Id == CommandContext.Channel.Id);

            await RconTask(command.Result.Content);
        }
Ejemplo n.º 6
0
        public async System.Threading.Tasks.Task TaskList(CommandContext ctx, string serviceConnectionInfo, int amountOfTasks)
        {
            await ctx.TriggerTypingAsync();

            var interactivity = ctx.Client.GetInteractivity();

            if (!(Service.GetGameServices(serviceConnectionInfo)[0] is Service service) || !service.Find())
            {
                await ctx.RespondAsync(embed : EmbedTemplates.CreateErrorEmbed("Task Manager",
                                                                               "**Cannot find service with search criteria: ** *" + serviceConnectionInfo + "*"));

                return;
            }

            var serviceTaskList =
                TCAdmin.TaskScheduler.SDK.Objects.Task.GetTasksForSource(service.GetType().ToString(),
                                                                         service.ServiceId.ToString());
            var servicesTask = new List <TCAdmin.TaskScheduler.SDK.Objects.Task>();

            foreach (TCAdmin.TaskScheduler.SDK.Objects.Task task in serviceTaskList)
            {
                servicesTask.Add(task);
            }

            if (servicesTask.Count == 0)
            {
                await ctx.RespondAsync(embed : EmbedTemplates.CreateErrorEmbed("Task Manager", "No Tasks Found"));

                return;
            }

            var tasksList  = string.Empty;
            var taskIdList = 1;

            tasksList = servicesTask.Take(amountOfTasks).Aggregate(tasksList,
                                                                   (current, task) => current + $"**{taskIdList++}**) {task.Name} [{task.ScheduledTime:f}]\n");

            await ctx.RespondAsync(embed : EmbedTemplates.CreateInfoEmbed("Task Picker", tasksList));

            var msg = await interactivity.WaitForMessageAsync(x => x.Channel == ctx.Channel && x.Author == ctx.User);

            if (int.TryParse(msg.Result.Content, out var result))
            {
                var taskManager = new TcaTaskManager(
                    await ctx.RespondAsync(embed: EmbedTemplates.CreateInfoEmbed("Task Manager", "Initialize...")),
                    servicesTask[result - 1].TaskId);
                await taskManager.Initialize();
            }
            else
            {
                await ctx.RespondAsync(embed : EmbedTemplates.CreateErrorEmbed("Task Manager", "Invalid Option"));
            }
        }
        public async Task PlayersTask(CommandContext ctx)
        {
            var settings =
                new NexusModuleConfiguration <PlayersMenuSettings>("PlayerMenuSettings", "./Config/TCAdminModule/")
                .GetConfiguration();
            await ctx.TriggerTypingAsync();

            var service = await DiscordService.GetService(ctx);

            var server = new Server(service.ServerId);

            var query = ServerQuery.GetQueryResults(server, new TCAdmin.GameHosting.SDK.Objects.Game(service.GameId),
                                                    service);

            if (query.NumPlayers == 0)
            {
                await ctx.RespondAsync(
                    embed : EmbedTemplates.CreateErrorEmbed(service.NameNoHtml, "**No players online**"));

                return;
            }

            if (query.NumPlayers != query.Players.Count)
            {
                await ctx.RespondAsync(embed : EmbedTemplates.CreateInfoEmbed(service.NameNoHtml,
                                                                              $"There are **{query.NumPlayers}/{query.MaxPlayers}** online!"));

                return;
            }

            var embed = new DiscordEmbedBuilder
            {
                Title     = $"{service.Name} | Players: {query.NumPlayers}/{query.MaxPlayers}",
                Color     = new Optional <DiscordColor>(new DiscordColor(settings.HexColor)),
                Timestamp = DateTime.Now,
                Thumbnail = new DiscordEmbedBuilder.EmbedThumbnail
                {
                    Url = settings.ThumbnailUrl
                }
            };

            foreach (var player in query.Players.OrderBy(x => x.Name))
            {
                embed.Description += $":bust_in_silhouette: {player.Name}\n";
            }

            await ctx.RespondAsync(embed : embed);
        }
Ejemplo n.º 8
0
        public async Task ServerCmd(CommandContext ctx, string serverName, [RemainingText] string script)
        {
            await ctx.TriggerTypingAsync();

            if (!(Server.GetServers(true, serverName)[0] is Server server))
            {
                await ctx.RespondAsync(embed : EmbedTemplates.CreateErrorEmbed("Server Not Found",
                                                                               $"{serverName} could not be found."));

                return;
            }

            var console = new RemoteConsole(server, @"C:\\Windows\\System32\\cmd.exe", "/c " + script,
                                            "Command Prompt - Script", true);

            await ctx.RespondAsync(embed : EmbedTemplates.CreateInfoEmbed("Live Output",
                                                                          $"To start the command, click [here]({console.GetUrl()})"));
        }
Ejemplo n.º 9
0
        public static async Task <User> SetupAccount(CommandContext ctx)
        {
            var companyInfo = new CompanyInfo(2);
            var embed       = EmbedTemplates.CreateInfoEmbed("Account Setup", $"**Hey {ctx.Member.Mention}!**\n\n" +
                                                             $"It seems I don't know you! Please link your discord and {companyInfo.CompanyName} together!\n\n" +
                                                             $"[Click Here to link your account]({companyInfo.ControlPanelUrl}/AccountSecurity?sso=true)");

            if (!string.IsNullOrEmpty(AccountServiceConfiguration.LoginConfiguration.ImageUrl))
            {
                embed.ImageUrl = AccountServiceConfiguration.LoginConfiguration.ImageUrl;
            }

            embed.Color =
                new Optional <DiscordColor>(new DiscordColor(AccountServiceConfiguration.LoginConfiguration.EmbedColor));
            await ctx.RespondAsync(embed : embed);

            return(null);
        }
Ejemplo n.º 10
0
        public async Task Whois(CommandContext ctx, DiscordMember member)
        {
            var user = AccountsService.GetUser(member.Id);

            if (user == null || !user.Find())
            {
                await ctx.RespondAsync(embed : EmbedTemplates.CreateErrorEmbed(description: "User not found"));

                return;
            }

            var userInfo = $"**User: {user.UserName} ({user.UserId})**\n" +
                           $"**Owner: {user.OwnerId} Sub: {user.SubUserOwnerId}**\n" +
                           $"**Role ID: {user.RoleId} Name: {user.RoleName}**\n";
            var embed = EmbedTemplates.CreateInfoEmbed("User Information: " + user.FullName, userInfo);

            await ctx.RespondAsync(embed : embed);
        }
        public async Task Signin(CommandContext ctx)
        {
            if (AccountsService.IsUserAuthenticated(ctx.User.Id))
            {
                await ctx.RespondAsync(
                    embed : EmbedTemplates.CreateErrorEmbed(description: "You are already logged in!"));

                return;
            }
            var user = AccountsService.GetUser(ctx.User.Id);

            if (user == null)
            {
                await AccountsService.SetupAccount(ctx);

                return;
            }

            await ctx.RespondAsync(embed : EmbedTemplates.CreateInfoEmbed("Login", "**You are already logged in**"));
        }
        private static async Task <Service> ChooseServiceFromList(CommandContext ctx, IReadOnlyList <Service> services)
        {
            var interactivity = ctx.Client.GetInteractivity();

            var serviceId      = 1;
            var servicesString = services.Aggregate(
                string.Empty,
                (current, service) =>
                current + $"**{serviceId++}**) {service.Name} **({service.IpAddress}:{service.GamePort})**\n");

            if (servicesString.Length >= 1900)
            {
                await interactivity.SendPaginatedMessageAsync(ctx.Channel, ctx.User,
                                                              interactivity.GeneratePagesInContent(servicesString));

                await ctx.RespondAsync(
                    embed : EmbedTemplates.CreateInfoEmbed("Tip!",
                                                           "When you have found the number of the server press the **STOP** Button then type the ID number."));
            }
            else
            {
                await ctx.RespondAsync(embed : EmbedTemplates.CreateInfoEmbed("Service Picker", servicesString));
            }

            var serviceOption =
                await interactivity.WaitForMessageAsync(x =>
                                                        x.Author.Id == ctx.User.Id && x.Channel.Id == ctx.Channel.Id);

            if (serviceOption.TimedOut)
            {
                throw new CustomMessageException(EmbedTemplates.CreateInfoEmbed("Timeout", ""));
            }

            if (int.TryParse(serviceOption.Result.Content, out var result) && result <= serviceId && result > 0)
            {
                return(services[result - 1]);
            }

            throw new CustomMessageException(EmbedTemplates.CreateErrorEmbed(description: "Not a number!"));
        }
        public static async Task <ServiceChartType> GetGraphType(CommandContext ctx)
        {
            var interactivity = ctx.Client.GetInteractivity();
            ServiceChartType chartType;

            const string options = "**1**) Players\n" +
                                   "**2**) CPU Usage\n" +
                                   "**3**) RAM Usage";
            await ctx.RespondAsync(
                embed : EmbedTemplates.CreateInfoEmbed("Selection", "**Please choose an option:**\n\n" + options));

            var graphChoice = await interactivity.WaitForMessageAsync(x => x.Author.Id == ctx.User.Id);

            switch (graphChoice.Result.Content.ToLower())
            {
            case "1":
                chartType = ServiceChartType.Players;
                break;

            case "2":
                chartType = ServiceChartType.Processor;
                break;

            case "3":
                chartType = ServiceChartType.Memory;
                break;

            default:
                await ctx.RespondAsync(
                    embed : EmbedTemplates.CreateErrorEmbed("Unknown Option", "Defaulting to Players graph"));

                chartType = ServiceChartType.Players;
                break;
            }

            return(chartType);
        }
Ejemplo n.º 14
0
 public async System.Threading.Tasks.Task Who(CommandContext ctx)
 {
     var user = AccountsService.GetUser(ctx.User.Id);
     await ctx.RespondAsync(
         embed : EmbedTemplates.CreateInfoEmbed("User Information", $"You are: **{user.UserName}**"));
 }
Ejemplo n.º 15
0
        public async System.Threading.Tasks.Task InitializeFileManagerAsync()
        {
            var interactivity = CommandContext.Client.GetInteractivity();
            var waitMsg       = await CommandContext.RespondAsync("Please wait");

            if (!FileSystem.DirectoryExists(CurrentDirectory))
            {
                throw new CustomMessageException(EmbedTemplates.CreateErrorEmbed("Could not find directory"));
            }

            var embed = new DiscordEmbedBuilder
            {
                Title       = "File Manager", Color = new Optional <DiscordColor>(new DiscordColor(_settings.HexColor)),
                Description = $"**Navigating {CurrentDirectory}**\n\n",
                Thumbnail   = new DiscordEmbedBuilder.EmbedThumbnail
                {
                    Url = _settings.ThumbnailUrl
                }
            };

            embed = UpdateEmbedListing(embed);

            await waitMsg.DeleteAsync();

            ListingMessage = await CommandContext.RespondAsync(embed : embed);

            var      currentlyInFile = false;
            FileInfo currentFileInfo = null;

            while (true)
            {
                var choice = await interactivity.WaitForMessageAsync(x =>
                                                                     x.Author.Id == CommandContext.User.Id && x.Channel.Id == CommandContext.Channel.Id);

                if (choice.TimedOut)
                {
                    await ListingMessage.ModifyAsync(
                        embed : new Optional <DiscordEmbed>(
                            EmbedTemplates.CreateInfoEmbed("File Manager", "Ended Session")));

                    return;
                }

                var message = choice.Result.Content.ToLower();
                await choice.Result.DeleteAsync();

                if (_settings.ExitCommand.Contains(message))
                {
                    await ListingMessage.DeleteAsync();

                    return;
                }

                if (_settings.GoBackCommand.Contains(message))
                {
                    if (currentlyInFile)
                    {
                        CurrentListing  = FileSystemUtilities.NavigateCurrentFolder(currentFileInfo.Directory);
                        currentFileInfo = null;
                        currentlyInFile = false;
                        var updatedEmbed = UpdateEmbedListing(embed);
                        await ListingMessage.ModifyAsync(embed : updatedEmbed.Build());
                    }
                    else
                    {
                        if (IsServer)
                        {
                            CurrentListing   = FileSystemUtilities.NavigateBackFolder(CurrentDirectory + "\\");
                            CurrentDirectory = new DirectoryInfo(CurrentDirectory).Parent?.FullName + "\\";
                            var updatedEmbed = UpdateEmbedListing(embed);
                            await ListingMessage.ModifyAsync(embed : updatedEmbed.Build());

                            continue;
                        }

                        if (FileSystemUtilities.CanGoBack(CurrentDirectory + "\\",
                                                          AuthenticationService.Service.ServiceId) && !LockDirectory)
                        {
                            CurrentListing   = FileSystemUtilities.NavigateBackFolder(CurrentDirectory + "\\");
                            CurrentDirectory = new DirectoryInfo(CurrentDirectory).Parent?.FullName + "\\";
                            var updatedEmbed = UpdateEmbedListing(embed);
                            await ListingMessage.ModifyAsync(embed : updatedEmbed.Build());
                        }
                    }
                }

                else if (int.TryParse(message, out var index))
                {
                    if (currentlyInFile)
                    {
                        var fileAction = (FileSystemUtilities.EFileActions)index;
                        if (await FileSystemUtilities.FileAction(currentFileInfo, fileAction))
                        {
                            if (fileAction == FileSystemUtilities.EFileActions.Extract ||
                                fileAction == FileSystemUtilities.EFileActions.Delete)
                            {
                                CurrentListing = FileSystemUtilities.NavigateCurrentFolder(CurrentDirectory);
                                var updatedEmbed = UpdateEmbedListing(embed);
                                await ListingMessage.ModifyAsync(embed : updatedEmbed.Build());

                                currentlyInFile = false;
                                currentFileInfo = null;
                            }
                            else
                            {
                                var updatedEmbed = UpdateEmbedListing(currentFileInfo, embed);
                                await ListingMessage.ModifyAsync(embed : updatedEmbed.Build());
                            }
                        }

                        continue;
                    }

                    var type = FileSystemUtilities.GetListingType(int.Parse(message), CurrentListing);

                    if (type == FileSystemUtilities.EListingType.Directory)
                    {
                        CurrentDirectory = CurrentListing.Directories[index - 1].FullName + "\\";
                        CurrentListing   = FileSystemUtilities.NavigateNextFolder(index, CurrentListing);
                        var updatedEmbed = UpdateEmbedListing(embed);
                        await ListingMessage.ModifyAsync(embed : updatedEmbed.Build());
                    }
                    else
                    {
                        var fileInfo = FileSystemUtilities.GetFileInfo(index - CurrentListing.Directories.Length,
                                                                       CurrentListing);
                        currentFileInfo = fileInfo;
                        currentlyInFile = true;
                        var updatedEmbed = UpdateEmbedListing(fileInfo, embed);
                        await ListingMessage.ModifyAsync(embed : updatedEmbed.Build());
                    }
                }

                else if (char.TryParse(message, out var result))
                {
                    var action = ToEnum <FileSystemUtilities.EDirectoryActions>(result.ToString().ToUpper());

                    if (!Enum.IsDefined(typeof(FileSystemUtilities.EDirectoryActions), action))
                    {
                        await CommandContext.RespondAsync("Cannot execute option if does not exist.");

                        continue;
                    }

                    if (await FileSystemUtilities.DirectoryAction(action, CurrentListing, CurrentDirectory))
                    {
                        if (action == FileSystemUtilities.EDirectoryActions.DeleteFolder)
                        {
                            CurrentListing = FileSystemUtilities.NavigateBackFolder(CurrentDirectory);
                            var updatedEmbed = UpdateEmbedListing(embed);
                            await ListingMessage.ModifyAsync(embed : updatedEmbed.Build());
                        }
                        else
                        {
                            CurrentListing = FileSystemUtilities.NavigateCurrentFolder(CurrentDirectory);
                            var updatedEmbed = UpdateEmbedListing(embed);
                            await ListingMessage.ModifyAsync(embed : updatedEmbed.Build());
                        }
                    }
                    else
                    {
                        await CommandContext.RespondAsync("Error in refreshing directory");
                    }
                }
                else
                {
                    await CommandContext.RespondAsync("I don't know what you mean by " + message);
                }
            }
        }