Skip to content

Commit af78211

Browse files
committed
added more to ACMClient
[ # ] Types now has a RoleType enum [ + ] Added TopicStyle object [ + ] Added Topic object [ + ] Added JoinRequestUser object [ + ] Added JoinRequestApplicant object [ + ] Added JoinRequest object [ + ] Added CommunityStats object [ + ] Added BlogCategory object [ # ] AdvancedCommunityInfo now contains MediaList and UserAddedTopicList [ # ] Added ACMClient functions: list_communities(int,int), get_blog_categories(int,int), change_sidebar_color(string), get_community_info(), promote(string, Types.RoleTypes), get_join_requests(int,int), accept/reject_join_request(string), get_community_stats()
1 parent 3ab8dfd commit af78211

10 files changed

Lines changed: 268 additions & 21 deletions

Amino.NET/ACMClient.cs

Lines changed: 128 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Newtonsoft.Json;
1+
using Amino.Objects;
22
using Newtonsoft.Json.Linq;
33
using RestSharp;
44
using System;
@@ -44,30 +44,30 @@ public ACMClient(Amino.SubClient client)
4444
RClient.AddDefaultHeaders(Client.headers);
4545
}
4646

47-
public Task create_community(string name, string tagline, byte[] icon, string themeColor, Types.Join_Types joinType = Types.Join_Types.Open, Types.Supported_Languages primaryLanguage = Types.Supported_Languages.english)
47+
public Task create_community(string name, string tagline, byte[] icon, string themeColor, Types.Join_Types joinType = Types.Join_Types.Open, Types.Supported_Languages primaryLanguage = Types.Supported_Languages.English)
4848
{
4949
string _lang = "en";
50-
switch(primaryLanguage)
50+
switch (primaryLanguage)
5151
{
52-
case Types.Supported_Languages.english:
52+
case Types.Supported_Languages.English:
5353
_lang = "en";
5454
break;
55-
case Types.Supported_Languages.spanish:
55+
case Types.Supported_Languages.Spanish:
5656
_lang = "es";
5757
break;
58-
case Types.Supported_Languages.portuguese:
58+
case Types.Supported_Languages.Portuguese:
5959
_lang = "pt";
6060
break;
61-
case Types.Supported_Languages.arabic:
61+
case Types.Supported_Languages.Arabic:
6262
_lang = "ar";
6363
break;
64-
case Types.Supported_Languages.russian:
64+
case Types.Supported_Languages.Russian:
6565
_lang = "ru";
6666
break;
67-
case Types.Supported_Languages.french:
67+
case Types.Supported_Languages.French:
6868
_lang = "fr";
6969
break;
70-
case Types.Supported_Languages.german:
70+
case Types.Supported_Languages.German:
7171
_lang = "de";
7272
break;
7373
}
@@ -90,14 +90,14 @@ public Task create_community(string name, string tagline, byte[] icon, string th
9090
{ "timestamp", helpers.GetTimestamp() * 1000 }
9191
};
9292
RestRequest request = new RestRequest("/g/s/community");
93-
request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data)));
94-
request.AddJsonBody(JsonConvert.SerializeObject(data));
93+
request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonSerializer.Serialize(data)));
94+
request.AddJsonBody(JsonSerializer.Serialize(data));
9595

9696
var response = RClient.ExecutePost(request);
97-
if(!response.IsSuccessStatusCode) { throw new Exception(response.Content); }
98-
if(Client.debug) { Trace.WriteLine(response.Content); }
97+
if (!response.IsSuccessStatusCode) { throw new Exception(response.Content); }
98+
if (Client.Debug) { Trace.WriteLine(response.Content); }
9999
return Task.CompletedTask;
100-
100+
101101
}
102102

103103
public Task delete_community(string email, string password, string verificationCode)
@@ -110,17 +110,124 @@ public Task delete_community(string email, string password, string verificationC
110110
}},
111111
{ "type", 1 },
112112
{ "identity", email },
113-
{ "deviceId", this.Client.deviceID },
113+
{ "deviceId", this.Client.DeviceId },
114114
{ "timestamp", helpers.GetTimestamp() * 1000 }
115115
};
116116
RestRequest request = new RestRequest($"/g/s-x{CommunityId}/community/delete-request");
117-
request.AddJsonBody(JsonConvert.SerializeObject(data));
118-
request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data)));
117+
request.AddJsonBody(JsonSerializer.Serialize(data));
118+
request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonSerializer.Serialize(data)));
119+
var response = RClient.ExecutePost(request);
120+
if (!response.IsSuccessStatusCode) { throw new Exception(response.Content); }
121+
if (Client.Debug) { Trace.WriteLine(response.Content); }
122+
return Task.CompletedTask;
123+
}
124+
125+
public List<Community> list_communities(int start = 0, int size = 25)
126+
{
127+
RestRequest request = new RestRequest($"/g/s/community/managed?start={start}&size={size}");
128+
var response = RClient.ExecuteGet(request);
129+
if (!response.IsSuccessStatusCode) { throw new Exception(response.Content); }
130+
if (Client.Debug) { Trace.WriteLine(response.Content); }
131+
return System.Text.Json.JsonSerializer.Deserialize<List<Community>>(JsonDocument.Parse(response.Content).RootElement.GetProperty("communityList").GetRawText());
132+
}
133+
134+
public List<BlogCategory> get_blog_categories(int start = 0, int size = 25)
135+
{
136+
RestRequest request = new RestRequest($"/x{CommunityId}/s/blog-category?start={start}&size={size}");
137+
var response = RClient.ExecuteGet(request);
138+
if (!response.IsSuccessStatusCode) { throw new Exception(response.Content); }
139+
if (Client.Debug) { Trace.WriteLine(response.Content); }
140+
return System.Text.Json.JsonSerializer.Deserialize<List<BlogCategory>>(JsonDocument.Parse(response.Content).RootElement.GetProperty("blogCategoryList").GetRawText());
141+
}
142+
143+
144+
public Task change_sidebar_color(string color)
145+
{
146+
RestRequest request = new RestRequest($"/x{CommunityId}/s/community/configuration");
147+
Dictionary<string, object> data = new Dictionary<string, object>()
148+
{
149+
{ "path", "appearance.leftSidePanel.style.iconColor" },
150+
{ "value", color.Length == 7 ? color : "#000000" },
151+
{ "timestamp", helpers.GetTimestamp() * 1000 }
152+
};
153+
request.AddHeader("NDC-MSG-SIG", System.Text.Json.JsonSerializer.Serialize(data));
154+
request.AddJsonBody(JsonSerializer.Serialize(data));
155+
var response = RClient.ExecutePost(request);
156+
if (!response.IsSuccessStatusCode) { throw new Exception(response.Content); }
157+
if (Client.Debug) { Trace.WriteLine(response.Content); }
158+
return Task.CompletedTask;
159+
}
160+
161+
public AdvancedCommunityInfo get_community_info()
162+
{
163+
RestRequest request = new RestRequest($"/g/s-x{CommunityId}/community/info?withTopicList=1&withInfluencerList=1&influencerListOrderStrategy=fansCount");
164+
var response = RClient.ExecuteGet(request);
165+
if (!response.IsSuccessStatusCode) { throw new Exception(response.Content); }
166+
if (Client.Debug) { Trace.WriteLine(response.Content); }
167+
return JsonSerializer.Deserialize<AdvancedCommunityInfo>(JsonDocument.Parse(response.Content).RootElement.GetProperty("community").GetRawText());
168+
}
169+
170+
public Task promote(string userId, Types.RoleTypes roleType)
171+
{
172+
string _role = "";
173+
switch (roleType)
174+
{
175+
case Types.RoleTypes.Agent:
176+
_role = "transfer-agent";
177+
break;
178+
case Types.RoleTypes.Leader:
179+
_role = "leader";
180+
break;
181+
case Types.RoleTypes.Curator:
182+
_role = "curator";
183+
break;
184+
}
185+
RestRequest request = new RestRequest($"/x{CommunityId}/s/user-profile/{userId}/{_role}");
186+
var response = RClient.ExecutePost(request);
187+
if (!response.IsSuccessStatusCode) { throw new Exception(response.Content); }
188+
if (Client.Debug) { Trace.WriteLine(response.Content); }
189+
return Task.CompletedTask;
190+
}
191+
192+
public List<JoinRequest> get_join_request(int start = 0, int size = 25)
193+
{
194+
RestRequest request = new RestRequest($"/x{CommunityId}/s/community/membership-request?status=pending?start={start}&size={size}");
195+
var response = RClient.ExecuteGet(request);
196+
if (!response.IsSuccessStatusCode) { throw new Exception(response.Content); }
197+
if (Client.Debug) { Trace.WriteLine(response.Content); }
198+
return JsonSerializer.Deserialize<List<JoinRequest>>(JsonDocument.Parse(response.Content).RootElement.GetRawText());
199+
}
200+
201+
public Task accept_join_request(string userId)
202+
{
203+
Dictionary<string, object> data = new Dictionary<string, object>();
204+
RestRequest request = new RestRequest($"/x{CommunityId}/s/community/membership-request/{userId}/accept");
205+
request.AddJsonBody(JsonSerializer.Serialize(data));
206+
request.AddHeader("NDC-MSG-SIG", JsonSerializer.Serialize(data));
119207
var response = RClient.ExecutePost(request);
120-
if(!response.IsSuccessStatusCode) { throw new Exception(response.Content); }
121-
if(Client.debug) { Trace.WriteLine(response.Content); }
208+
if (!response.IsSuccessStatusCode) { throw new Exception(response.Content); }
209+
if (Client.Debug) { Trace.WriteLine(response.Content); }
210+
return Task.CompletedTask;
211+
}
212+
public Task reject_join_request(string userId)
213+
{
214+
Dictionary<string, object> data = new Dictionary<string, object>();
215+
RestRequest request = new RestRequest($"/x{CommunityId}/s/community/membership-request/{userId}/reject");
216+
request.AddJsonBody(JsonSerializer.Serialize(data));
217+
request.AddHeader("NDC-MSG-SIG", JsonSerializer.Serialize(data));
218+
var response = RClient.ExecutePost(request);
219+
if (!response.IsSuccessStatusCode) { throw new Exception(response.Content); }
220+
if (Client.Debug) { Trace.WriteLine(response.Content); }
122221
return Task.CompletedTask;
123222
}
124223

125-
}
224+
public CommunityStats get_community_stats()
225+
{
226+
RestRequest request = new RestRequest($"/x{CommunityId}/s/community/stats");
227+
var response = RClient.ExecutePost(request);
228+
if (!response.IsSuccessStatusCode) { throw new Exception(response.Content); }
229+
if (Client.Debug) { Trace.WriteLine(response.Content); }
230+
return JsonSerializer.Deserialize<CommunityStats>(JsonDocument.Parse(response.Content).RootElement.GetProperty("communityStats").GetRawText());
231+
}
232+
}
126233
}

Amino.NET/Objects/AdvancedCommunityInfo.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,9 @@ public class AdvancedCommunityInfo
3737
[JsonPropertyName("agent")] public GenericProfile Agent { get; set; }
3838
[JsonPropertyName("themePack")] public CommunityThemePack ThemePack { get; set; }
3939
[JsonPropertyName("advancedSettings")] public CommunityAdvancedSettings AdvancedSettings { get; set; }
40+
41+
[JsonPropertyName("userAddedTopicList")] public List<Topic> UserAddedTopicList { get; set; }
42+
[JsonPropertyName("mediaList")] public List<List<string>> MediaList { get; set; }
43+
4044
}
4145
}

Amino.NET/Objects/BlogCategory.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Text.Json.Serialization;
6+
using System.Threading.Tasks;
7+
8+
namespace Amino.Objects
9+
{
10+
public class BlogCategory
11+
{
12+
[JsonPropertyName("status")] public int Status { get; set; }
13+
[JsonPropertyName("modifiedTime")] public string ModifiedTime { get; set; }
14+
[JsonPropertyName("icon")] public string IconUrl { get; set; }
15+
[JsonPropertyName("style")] public int Style { get; set; }
16+
[JsonPropertyName("label")] public string Label { get; set; }
17+
[JsonPropertyName("content")] public string Content { get; set; }
18+
[JsonPropertyName("createdTime")] public string CreatedTime { get; set; }
19+
[JsonPropertyName("position")] public int Position { get; set; }
20+
[JsonPropertyName("type")] public int Type { get; set; }
21+
[JsonPropertyName("categoryId")] public string CategoryId { get; set; }
22+
[JsonPropertyName("blogsCount")] public int BlogsCount { get; set; }
23+
}
24+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Text.Json.Serialization;
6+
using System.Threading.Tasks;
7+
8+
namespace Amino.Objects
9+
{
10+
public class CommunityStats
11+
{
12+
[JsonPropertyName("dailyActiveMembers")] public int DailyActiveMembers { get; set; }
13+
[JsonPropertyName("monthlyActiveMembers")] public int MonthlyActiveMembers { get; set; }
14+
[JsonPropertyName("totalTimeSpent")] public int TotalTimeSpent { get; set; }
15+
[JsonPropertyName("totalPostsCreated")] public int TotalPostsCreated { get; set; }
16+
[JsonPropertyName("newMembersToday")] public int NewMembersToday { get; set; }
17+
[JsonPropertyName("totalMembers")] public int TotalMembers { get; set; }
18+
}
19+
}

Amino.NET/Objects/JoinRequest.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Text.Json.Serialization;
6+
using System.Threading.Tasks;
7+
8+
namespace Amino.Objects
9+
{
10+
public class JoinRequest
11+
{
12+
[JsonPropertyName("communityMembershipRequestCount")] public int CommunityMembershipRequestCount { get; set; }
13+
[JsonPropertyName("communityMembershipRequestList")] public List<JoinRequestUser> CommunityMembershipRequestList { get; set; }
14+
}
15+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Text.Json.Serialization;
6+
using System.Threading.Tasks;
7+
8+
namespace Amino.Objects
9+
{
10+
public class JoinRequestApplicant
11+
{
12+
[JsonPropertyName("status")] public int Status { get; set; }
13+
[JsonPropertyName("uid")] public string UserId { get; set; }
14+
[JsonPropertyName("isGlobal")] public bool IsGlobal { get; set; }
15+
[JsonPropertyName("role")] public int Role { get; set; }
16+
[JsonPropertyName("isStaff")] public bool IsStaff { get; set; }
17+
[JsonPropertyName("nickname")] public string Nickname { get; set; }
18+
[JsonPropertyName("icon")] public string IconUrl { get; set; }
19+
}
20+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Text.Json.Serialization;
6+
using System.Threading.Tasks;
7+
8+
namespace Amino.Objects
9+
{
10+
public class JoinRequestUser
11+
{
12+
[JsonPropertyName("status")] public int Status { get; set; }
13+
[JsonPropertyName("requestId")] public string RequestId { get; set; }
14+
[JsonPropertyName("modifiedTime")] public string ModifiedTime { get; set; }
15+
[JsonPropertyName("ndcId")] public int CommunityId { get; set; }
16+
[JsonPropertyName("createdTime")] public string CreatedTime { get; set; }
17+
[JsonPropertyName("message")] public string Message { get; set; }
18+
[JsonPropertyName("uid")] public string UserId { get; set; }
19+
[JsonPropertyName("applicant")] public JoinRequestApplicant Applicant { get; set; }
20+
}
21+
}

Amino.NET/Objects/Topic.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Text.Json.Serialization;
6+
using System.Threading.Tasks;
7+
8+
namespace Amino.Objects
9+
{
10+
public class Topic
11+
{
12+
[JsonPropertyName("topicId")] public int TopicId { get; set; }
13+
[JsonPropertyName("name")] public string Name { get; set; }
14+
[JsonPropertyName("style")] public TopicStyle Style { get; set; }
15+
}
16+
}

Amino.NET/Objects/TopicStyle.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Text.Json.Serialization;
6+
using System.Threading.Tasks;
7+
8+
namespace Amino.Objects
9+
{
10+
public class TopicStyle
11+
{
12+
[JsonPropertyName("backgroundColor")] public string BackgroundColor { get; set; }
13+
}
14+
}

Amino.NET/Types.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -276,5 +276,12 @@ public enum Leaderboard_Ranking_Types
276276
CheckIn = 4,
277277
quiz = 5
278278
}
279+
280+
public enum RoleTypes
281+
{
282+
Agent,
283+
Leader,
284+
Curator
285+
}
279286
}
280287
}

0 commit comments

Comments
 (0)