Esempio n. 1
0
        private async Task EditFile(FileInfo file)
        {
            var interactivity = CommandContext.Client.GetInteractivity();

            await DownloadFile(file);

            await CommandContext.RespondAsync("**Please send back the file as an attachment.**");

            var updatedFileAttachment = await interactivity.WaitForMessageAsync(
                x => x.Author.Id == CommandContext.User.Id && x.Channel.Id == CommandContext.Channel.Id &&
                x.Attachments.Any(
                    y => y.FileName.EndsWith(file.Extension)),
                TimeSpan.FromMinutes(5));

            if (FitsMask(updatedFileAttachment.Result.Attachments[0].FileName))
            {
                await CommandContext.RespondAsync("This File Type is banned.");

                return;
            }

            var updatedFileContent = DownloadString(updatedFileAttachment.Result.Attachments[0].Url);

            FileSystem.DeleteFile(file.FullName);
            FileSystem.AppendTextFile(file.FullName, Encoding.ASCII.GetBytes(updatedFileContent));
            await CommandContext.RespondAsync($"Edited **{file.Name}**");
        }
Esempio n. 2
0
        private async Task DeleteFile(FileInfo file)
        {
            FileSystem.DeleteFile(file.FullName);
            var msg = await CommandContext.RespondAsync($"Deleted **{file.FullName}**");

            await CleanUp(CommandContext.Channel, msg);
        }
Esempio n. 3
0
        public string GetFileContent(FileInfo file)
        {
            var fileBytes   = FileSystem.ReadFile(file.FullName);
            var fileContent = Encoding.UTF8.GetString(fileBytes);

            return(fileContent);
        }
Esempio n. 4
0
        private async Task CopyFile(FileInfo file)
        {
            var interactivity = CommandContext.Client.GetInteractivity();
            var msg           = await CommandContext.RespondAsync(
                $"Enter absolute path you would like to copy {file.Name} to.\nE.G. **Servers/server**");

            var copyTo = await interactivity.WaitForMessageAsync(x => x.Author.Id == CommandContext.User.Id);

            FileSystem.CopyFile(file.FullName, Service.WorkingDirectory + copyTo.Result.Content + "/" + file.Name);
            await CommandContext.RespondAsync(
                $"Copied {file.Name} to {Service.WorkingDirectory}/{copyTo.Result.Content}");

            await CleanUp(CommandContext.Channel, msg);
        }
Esempio n. 5
0
        private async Task ExtractFile(FileInfo file)
        {
            try
            {
                var msg = await CommandContext.RespondAsync("Extracting");

                FileSystem.Extract(file.FullName, file.Directory,
                                   new VirtualDirectorySecurity(file.Directory + "\\").VirtualDirectorySecurityString);
                await CommandContext.RespondAsync("Extracted");
                await CleanUp(CommandContext.Channel, msg);
            }
            catch (Exception e)
            {
                await CommandContext.RespondAsync(e.Message);
            }
        }
Esempio n. 6
0
        private async Task RenameFile(FileInfo file)
        {
            var interactivity = CommandContext.Client.GetInteractivity();
            var msg           = await CommandContext.RespondAsync($"**What would you like to rename '{file.Name}' to?**");

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

            if (FitsMask(renameName.Result.Content))
            {
                await CommandContext.RespondAsync("This File Type is banned.");

                return;
            }

            FileSystem.RenameFile(file.FullName, file.Directory + renameName.Result.Content, "None", "Discord", "None");
            await CommandContext.RespondAsync($"Renamed **{file.Name}** to **{renameName.Result.Content}**");

            await CleanUp(CommandContext.Channel, msg);
        }
Esempio n. 7
0
        public async Task DownloadFile(FileInfo file)
        {
            var server            = new Server(Service.ServerId);
            var directorySecurity = new TCAdmin.SDK.VirtualFileSystem.VirtualDirectorySecurity
            {
                Permissions        = Permission.Read | Permission.Write | Permission.Delete,
                PermissionType     = PermissionType.Root,
                RelativeExecutable =
                    Strings.ReplaceCaseInsensitive(Service.Executable, Service.RootDirectory, string.Empty),
                VirtualDirectoryName = Service.ConnectionInfo,
                RootPhysicalPath     = Service.RootDirectory,
                RealPhysicalPath     =
                    TCAdmin.SDK.Misc.FileSystem.FixAbsoluteFilePath(Service.RootDirectory, server.OperatingSystem),
                ServerId = server.ServerId
            };
            var download = new RemoteDownload(server)
            {
                DirectorySecurity = directorySecurity,
                FileName          = file.FullName
            };

            if (file.Length / 1024 > 8)
            {
                await CommandContext.RespondAsync(
                    embed : EmbedTemplates.CreateSuccessEmbed(
                        $"[<{download.GetDownloadUrl()}>](**Click here to download {file.Name}**)"));
            }
            else
            {
                using (var client = new WebClient())
                {
                    client.DownloadFileCompleted += delegate { CommandContext.RespondWithFileAsync(file.Name); };

                    client.DownloadFileAsync(new Uri(download.GetDownloadUrl()), file.Name);
                }
            }

            await Task.Delay(3000);

            File.Delete(file.Name);
        }
Esempio n. 8
0
        public async Task <bool> FileAction(FileInfo file, EFileActions option)
        {
            switch (option)
            {
            case EFileActions.Delete:
                await DeleteFile(file);

                return(true);

            case EFileActions.Copy:
                await CopyFile(file);

                return(true);

            case EFileActions.Edit:
                await EditFile(file);

                return(true);

            case EFileActions.Extract:
                await ExtractFile(file);

                return(true);

            case EFileActions.Rename:
                await RenameFile(file);

                return(true);

            case EFileActions.Download:
                await DownloadFile(file);

                return(true);
            }

            return(false);
        }