Skip to content

Commit bb41fc2

Browse files
authored
Merge pull request #25 from Amino-NET-Group/feature/add-more-functions
Feature/add more functions
2 parents fef89ba + 0a0bee2 commit bb41fc2

File tree

2 files changed

+139
-6
lines changed

2 files changed

+139
-6
lines changed

Amino.NET/Client.cs

Lines changed: 136 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44
using System.Globalization;
55
using System.IO;
66
using System.Linq;
7+
using System.Net.Http;
78
using System.Text;
89
using System.Threading;
910
using System.Threading.Tasks;
10-
using System.Threading.Tasks.Dataflow;
11-
using Amino.Objects;
1211
using Newtonsoft.Json;
1312
using Newtonsoft.Json.Linq;
1413
using RestSharp;
@@ -389,6 +388,47 @@ public Task login_sid(string sessionId, bool fetchProfile = true, bool connectSo
389388
return Task.CompletedTask;
390389
}
391390

391+
/// <summary>
392+
/// Allows you to register an Amino account using a google account
393+
/// </summary>
394+
/// <param name="nickname"></param>
395+
/// <param name="googleToken"></param>
396+
/// <param name="password"></param>
397+
/// <param name="deviceId"></param>
398+
/// <returns></returns>
399+
/// <exception cref="Exception"></exception>
400+
public Task register_google(string nickname, string googleToken, string password, string deviceId = null)
401+
{
402+
deviceId = deviceId == null ? helpers.generate_device_id() : deviceId;
403+
RestClient client = new RestClient(helpers.BaseUrl);
404+
RestRequest request = new RestRequest("/g/s/auth/login");
405+
request.AddHeaders(headers);
406+
407+
Dictionary<string, object> data = new Dictionary<string, object>()
408+
{
409+
{ "secret", $"12 {googleToken}" },
410+
{ "secret2", $"0 {password}" },
411+
{ "deviceID", deviceId },
412+
{ "clientType", 100 },
413+
{ "nickname", nickname },
414+
{ "latitude", 0 },
415+
{ "longitude", 0 },
416+
{ "address", null },
417+
{ "clientCallbackURL", "narviiapp://relogin" },
418+
{ "timestamp", helpers.GetTimestamp() * 1000 },
419+
};
420+
421+
request.AddJsonBody(System.Text.Json.JsonSerializer.Serialize(data));
422+
request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(System.Text.Json.JsonSerializer.Serialize(data)));
423+
424+
var response = client.ExecutePost(request);
425+
if((int)response.StatusCode != 200) { throw new Exception(response.Content); }
426+
if(debug) { Trace.WriteLine(response.Content); }
427+
return Task.CompletedTask;
428+
}
429+
430+
431+
392432

393433
/// <summary>
394434
/// Allows you to register an Amino account
@@ -428,7 +468,7 @@ public Task register(string _name, string _email, string _password, string _veri
428468
RestClient client = new RestClient(helpers.BaseUrl);
429469
RestRequest request = new RestRequest("/g/s/auth/register");
430470
request.AddHeaders(headers);
431-
request.AddJsonBody(data);
471+
request.AddJsonBody(JsonConvert.SerializeObject(data));
432472
request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data)));
433473
var response = client.ExecutePost(request);
434474
if ((int)response.StatusCode != 200) { throw new Exception(response.Content); }
@@ -1416,6 +1456,11 @@ public Task flag_community(string communityId, string reason, Types.Flag_Types f
14161456
/// <returns>string : The URL to the media file you just uploaded</returns>
14171457
public string upload_media(string filePath, Types.upload_File_Types type)
14181458
{
1459+
if(filePath.StartsWith("http"))
1460+
{
1461+
byte[] fileBytes = new HttpClient().GetAsync(filePath).Result.Content.ReadAsByteArrayAsync().Result;
1462+
return upload_media(fileBytes, type);
1463+
}
14191464
return upload_media(File.ReadAllBytes(filePath), type);
14201465
}
14211466

@@ -2421,6 +2466,94 @@ public Task send_sticker(string chatId, string stickerId)
24212466
return Task.CompletedTask;
24222467
}
24232468

2469+
/// <summary>
2470+
/// Allows you to get information about a blog post
2471+
/// </summary>
2472+
/// <param name="blogId"></param>
2473+
/// <returns></returns>
2474+
/// <exception cref="Exception"></exception>
2475+
public Objects.Blog get_blog_info(string blogId)
2476+
{
2477+
RestClient client = new RestClient(helpers.BaseUrl);
2478+
RestRequest request = new RestRequest($"/g/s/blog/{blogId}");
2479+
request.AddHeaders(headers);
2480+
var response = client.ExecuteGet(request);
2481+
if((int)response.StatusCode != 200) { throw new Exception(response.Content); }
2482+
if(debug) { Trace.WriteLine(response.Content); }
2483+
return new Objects.Blog(JObject.Parse(response.Content));
2484+
}
2485+
2486+
2487+
/// <summary>
2488+
/// Allows you to get information about a wiki post
2489+
/// </summary>
2490+
/// <param name="wikiId"></param>
2491+
/// <returns></returns>
2492+
/// <exception cref="Exception"></exception>
2493+
public Objects.Wiki get_wiki_info(string wikiId)
2494+
{
2495+
RestClient client = new RestClient(helpers.BaseUrl);
2496+
RestRequest request = new RestRequest($"/g/s/item/{wikiId}");
2497+
request.AddHeaders(headers);
2498+
var response = client.ExecuteGet(request);
2499+
if((int)response.StatusCode != 200) { throw new Exception(response.Content); }
2500+
if(debug) { Trace.WriteLine(response.Content); }
2501+
return new Objects.Wiki(JObject.Parse(response.Content));
2502+
}
2503+
2504+
/// <summary>
2505+
/// Allows you to get information about a message in a chat
2506+
/// </summary>
2507+
/// <param name="chatId"></param>
2508+
/// <param name="messageId"></param>
2509+
/// <returns></returns>
2510+
/// <exception cref="Exception"></exception>
2511+
public Objects.Message get_message_info(string chatId, string messageId)
2512+
{
2513+
RestClient client = new RestClient(helpers.BaseUrl);
2514+
RestRequest request = new RestRequest($"/g/s/chat/thread/{chatId}/message/{messageId}");
2515+
request.AddHeaders(headers);
2516+
var response = client.ExecuteGet(request);
2517+
if((int)response.StatusCode != 200) { throw new Exception(response.Content); }
2518+
if(debug) { Trace.WriteLine(response.Content); }
2519+
return new Objects.Message(JObject.Parse(response.Content));
2520+
}
2521+
2522+
/// <summary>
2523+
/// Allows you to get comments from a blog, THIS FUNCTION IS NOT FINISHED
2524+
/// </summary>
2525+
/// <param name="blogId"></param>
2526+
/// <param name="start"></param>
2527+
/// <param name="size"></param>
2528+
/// <param name="sorting"></param>
2529+
/// <returns></returns>
2530+
/// <exception cref="Exception"></exception>
2531+
public List<Objects.Comment> get_blog_comments(string blogId, int start = 0, int size = 25, Types.Sorting_Types sorting = Types.Sorting_Types.Newest)
2532+
{
2533+
string sortingType = "";
2534+
switch(sorting)
2535+
{
2536+
case Types.Sorting_Types.Newest:
2537+
sortingType = "newest";
2538+
break;
2539+
case Types.Sorting_Types.Oldest:
2540+
sortingType = "oldest";
2541+
break;
2542+
case Types.Sorting_Types.Top:
2543+
sortingType = "vote";
2544+
break;
2545+
}
2546+
RestClient client = new RestClient(helpers.BaseUrl);
2547+
RestRequest request = new RestRequest($"/g/s/blog/{blogId}?sort={sortingType}&start={size}&size={size}");
2548+
request.AddHeaders(headers);
2549+
var response = client.ExecuteGet(request);
2550+
if((int)response.StatusCode != 200) { throw new Exception(response.Content); }
2551+
if(debug) { Trace.WriteLine(response.Content); }
2552+
2553+
return null; // FINISH LATER
2554+
2555+
}
2556+
24242557

24252558
/// <summary>
24262559
/// Sets the SubClient of the Client, not for development use

Amino.NET/SubClient.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public Task delete_invite_code(string inviteId)
147147
/// <param name="fansOnly"></param>
148148
/// <param name="backgroundColor"></param>
149149
/// <returns></returns>
150-
public Task post_blog(string title, string content, List<byte[]> imageList = null, bool fansOnly = false, string backgroundColor = null)
150+
public Task post_blog(string title, string content, IEnumerable<byte[]> imageList = null, bool fansOnly = false, string backgroundColor = null)
151151
{
152152
JArray mediaList = new JArray();
153153
JObject extensionData = new JObject();
@@ -200,7 +200,7 @@ public Task post_blog(string title, string content, List<byte[]> imageList = nul
200200
/// <param name="fansOnly"></param>
201201
/// <param name="backgroundColor"></param>
202202
/// <returns></returns>
203-
public Task post_wiki(string title, string content, List<byte[]> imageList = null, bool fansOnly = false, string backgroundColor = null)
203+
public Task post_wiki(string title, string content, IEnumerable<byte[]> imageList = null, bool fansOnly = false, string backgroundColor = null)
204204
{
205205
JArray mediaList = new JArray();
206206
JObject extensionData = new JObject();
@@ -249,7 +249,7 @@ public Task post_wiki(string title, string content, List<byte[]> imageList = nul
249249
/// <param name="fansOnly"></param>
250250
/// <param name="backgroundColor"></param>
251251
/// <returns></returns>
252-
public Task edit_blog(string blogId, string title = null, string content = null, List<byte[]> imageList = null, bool fansOnly = false, string backgroundColor = null)
252+
public Task edit_blog(string blogId, string title = null, string content = null, IEnumerable<byte[]> imageList = null, bool fansOnly = false, string backgroundColor = null)
253253
{
254254
JArray mediaList = new JArray();
255255
JObject extensionData = new JObject();

0 commit comments

Comments
 (0)