Пример #1
0
        private async Task <List <Media> > GetMediaFromAttachments(IReadOnlyCollection <IAttachment> attachments)
        {
            if (attachments == null || attachments.Count == 0)
            {
                return(null);
            }

            List <Media> mediaContent    = new List <Media>();
            var          attachmentFiles = AttachmentHelper.DownloadAttachments(attachments);

            try
            {
                foreach (var file in attachmentFiles)
                {
                    string mediaType = $"image/{Path.GetExtension(file).Replace(".", string.Empty)}";
                    byte[] fileData  = File.ReadAllBytes(file);
                    var    media     = await _twitterContext.UploadMediaAsync(fileData, mediaType, "tweet_image");

                    mediaContent.Add(media);
                    File.Delete(file);
                }

                return(mediaContent);
            }
            finally
            {
                AttachmentHelper.DeleteFiles(attachmentFiles);
            }
        }
Пример #2
0
            public async Task CleanTempDir([Summary("The type of temp files to delete. Possible values: `images, media, text, all (default value)`")] string filter = "all")
            {
                AttachmentFilter filterType;

                switch (filter)
                {
                case "all":
                default:
                    filterType = AttachmentFilter.All;
                    break;

                case "images":
                    filterType = AttachmentFilter.Images;
                    break;

                case "media":
                    filterType = AttachmentFilter.Media;
                    break;

                case "text":
                    filterType = AttachmentFilter.Plaintext;
                    break;
                }
                List <string> files = AttachmentHelper.GetTempAssets(filterType);

                if (files.Count == 0)
                {
                    await ReplyAsync("No temp files to delete.");
                }
                else
                {
                    AttachmentHelper.DeleteFiles(files);
                    await ReplyAsync($"Deleted {files.Count} temp files.");
                }
            }
 public void DeleteImages(List <string> images)
 {
     AttachmentHelper.DeleteFiles(images);
 }