Skip to content

Commit ae4ceca

Browse files
committed
finished demo PostBuilder
[ # ] Changed PostBuilder.MediaList from Dictionary<byte[], string> to List<(byte[], string?, string?)> [ + ] Added PostBuilder.BackgroundImage [ + ] Added PostBuilder.BackgroundColor [ + ] Added PostBuilder.BackgroundType [ + ] Added PostBuilder.FansOnly [ + ] Added PostBuilder.WithBackgroundImage(byte[]) [ + ] Added PostBuilder.WithBackgroundImage(string) [ # ] Adjusted functions to handle new parameters like caption and mediaKey [ + ] Added SubClient.create_post(PostBuilder)
1 parent 53e1b4f commit ae4ceca

2 files changed

Lines changed: 51 additions & 6 deletions

File tree

Amino.NET/Builders/PostBuilder.cs

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
11
using System.Collections.Generic;
2+
using System.ComponentModel;
23
using System.IO;
4+
using System.Reflection.Metadata.Ecma335;
35

46
namespace Amino.NET.Builders
57
{
68
public class PostBuilder
79
{
810
public byte[] CoverImage { get; private set; }
11+
public byte[] BackgroundImage { get; private set; }
12+
public string BackgroundColor { get; private set; } = "#ffffff";
913
public string Content { get; set; }
1014
public string Title { get; set; }
11-
public Dictionary<byte[], string> MediaList { get; } = new Dictionary<byte[], string>();
15+
public List<(byte[], string?, string?)> MediaList { get; } = new List<(byte[], string?, string?)>();
1216
public PostTypes PostType { get; set; } = PostTypes.Blog;
17+
public BackgroundTypes BackgroundType { get; set; } = BackgroundTypes.Color;
18+
public bool FansOnly { get; set; }
19+
1320

1421
public void WithCover(byte[] cover)
1522
{
@@ -19,21 +26,39 @@ public void WithCover(string coverPath)
1926
{
2027
WithCover(File.ReadAllBytes(coverPath));
2128
}
22-
public void AddMedia(byte[] media, string mediaKey)
29+
30+
public void WithBackgroundImage(byte[] media)
31+
{
32+
BackgroundImage = media;
33+
}
34+
35+
public void WithBackgroundImage(string mediaPath)
2336
{
24-
MediaList.Add(media, mediaKey);
37+
WithBackgroundImage(File.ReadAllBytes(mediaPath));
2538
}
2639

27-
public void AddMedia(string mediaPath, string mediaKey)
40+
public void AddMedia(byte[] media, string mediaKey = null, string caption = null)
2841
{
29-
AddMedia(File.ReadAllBytes(mediaPath), mediaKey);
42+
MediaList.Add((media, mediaKey, caption));
3043
}
3144

45+
public void AddMedia(string mediaPath, string mediaKey = null, string caption = null)
46+
{
47+
AddMedia(File.ReadAllBytes(mediaPath), mediaKey, caption);
48+
}
49+
50+
public string EmbedImage(string mediaKey) => $"[IMG={mediaKey}]";
51+
3252
public enum PostTypes
3353
{
3454
Blog,
3555
Wiki
3656
}
57+
public enum BackgroundTypes
58+
{
59+
Color,
60+
Image
61+
}
3762

3863
}
3964
}

Amino.NET/SubClient.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
using Newtonsoft.Json;
1+
using Amino.NET.Builders;
2+
using Newtonsoft.Json;
23
using Newtonsoft.Json.Linq;
34
using RestSharp;
45
using System;
56
using System.Collections.Generic;
67
using System.Diagnostics;
78
using System.Diagnostics.CodeAnalysis;
89
using System.IO;
10+
using System.Linq;
911
using System.Reactive.Subjects;
1012
using System.Runtime.Serialization.Formatters;
1113
using System.Text;
@@ -191,6 +193,24 @@ public Task post_blog(string title, string content, IEnumerable<byte[]> imageLis
191193
return Task.CompletedTask;
192194
}
193195

196+
public Task create_post(PostBuilder post)
197+
{
198+
List<byte[]> _media = new List<byte[]>();
199+
switch(post.PostType)
200+
{
201+
case PostBuilder.PostTypes.Blog:
202+
foreach (var media in post.MediaList) { _media.Add(media.Item1); }
203+
post_blog(post.Title, post.Content, _media, post.FansOnly, post.BackgroundColor);
204+
break;
205+
case PostBuilder.PostTypes.Wiki:
206+
foreach (var media in post.MediaList) { _media.Add(media.Item1); }
207+
post_wiki(post.Title, post.Content, _media, post.FansOnly, post.BackgroundColor);
208+
break;
209+
}
210+
return Task.CompletedTask;
211+
}
212+
213+
194214
/// <summary>
195215
/// Allows you to post a Wiki post on the current Community
196216
/// </summary>

0 commit comments

Comments
 (0)