From f9d4d42a5f08e8829524dba61d6286644a92ecd2 Mon Sep 17 00:00:00 2001 From: Fabio Gaming Date: Sat, 16 Mar 2024 14:03:56 +0100 Subject: [PATCH 01/30] changed version to dev --- Amino.NET/Amino.NET.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Amino.NET/Amino.NET.csproj b/Amino.NET/Amino.NET.csproj index 97da2ce..30cb366 100644 --- a/Amino.NET/Amino.NET.csproj +++ b/Amino.NET/Amino.NET.csproj @@ -2,7 +2,7 @@ net7.0 - 1.5.1 + 1.5.1-Dev-7.1.2.8.3.5.0 FabioTheFox FabiDev An unofficial C# wrapper for Aminos REST API for making amino bots and tools From 878e49c801bbb971feca5b61d4d7a17c44809fa3 Mon Sep 17 00:00:00 2001 From: Fabio Gaming Date: Tue, 9 Apr 2024 22:52:51 +0200 Subject: [PATCH 02/30] refactoring Client [ # ] Some functions no longer throw an exception based on an Exception [ # ] More anonymous types have been removed [ # ] Adapted more functions to work with inline if expressions [ # ] Fixed code formatting --- Amino.NET/Client.cs | 1186 ++++++++++++++++--------------------------- 1 file changed, 441 insertions(+), 745 deletions(-) diff --git a/Amino.NET/Client.cs b/Amino.NET/Client.cs index ebea18f..5f98d89 100644 --- a/Amino.NET/Client.cs +++ b/Amino.NET/Client.cs @@ -476,39 +476,32 @@ public Task restore_account(string _email, string _password, string _deviceID = /// public Task delete_account(string _password) { - var data = new { deviceID = deviceID, secret = $"0 {_password}" }; - try - { - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest("/g/s/account/delete-request"); - request.AddHeaders(headers); - request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(System.Text.Json.JsonSerializer.Serialize(data))); - request.AddJsonBody(data); - var response = client.ExecutePost(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - sessionID = null; - secret = null; - userID = null; - json = null; - googleID = null; - appleID = null; - facebookID = null; - twitterID = null; - iconURL = null; - aminoID = null; - email = null; - phoneNumber = null; - nickname = null; - is_Global = false; - headerBuilder(); - _ = webSocket.DisconnectSocket(); - return Task.CompletedTask; - } - catch (Exception e) - { - throw new Exception(e.Message); - } + JObject data = new JObject() { { "deviceID", deviceID }, { "secret", $"0 {_password}" } }; + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest("/g/s/account/delete-request"); + request.AddHeaders(headers); + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(System.Text.Json.JsonSerializer.Serialize(data))); + request.AddJsonBody(data); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + sessionID = null; + secret = null; + userID = null; + json = null; + googleID = null; + appleID = null; + facebookID = null; + twitterID = null; + iconURL = null; + aminoID = null; + email = null; + phoneNumber = null; + nickname = null; + is_Global = false; + headerBuilder(); + _ = webSocket.DisconnectSocket(); + return Task.CompletedTask; } /// @@ -522,26 +515,23 @@ public Task delete_account(string _password) public Task activate_account(string _email, string _verificationCode, string _deviceID = null) { if (_deviceID == null) { if (deviceID != null) { _deviceID = deviceID; } else { _deviceID = helpers.generate_device_id(); } } - var data = new + + JObject data = new JObject() { - type = 1, - identity = _email, - data = new { code = _verificationCode }, - deviceID = _deviceID + { "type", 1 }, + { "identity", _email }, + { "data", new JObject() { "code", _verificationCode } }, + { "deviceId", _deviceID } }; - try - { - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest("/g/s/auth/activate-email"); - request.AddHeaders(headers); - request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(System.Text.Json.JsonSerializer.Serialize(data))); - request.AddJsonBody(data); - var response = client.ExecutePost(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; - } - catch (Exception e) { throw new Exception(e.Message); } + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest("/g/s/auth/activate-email"); + request.AddHeaders(headers); + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); + request.AddJsonBody(JsonConvert.SerializeObject(data)); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } /// @@ -560,19 +550,16 @@ public Task configure_account(Types.account_gender _gender = Types.account_gende { "gender", (int)_gender }, { "timestamp", helpers.GetTimestamp() * 1000 } }; - try - { - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest("/g/s/persona/profile/basic"); - request.AddHeaders(headers); - request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); - request.AddJsonBody(JsonConvert.SerializeObject(data)); - var response = client.ExecutePost(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; - } - catch (Exception e) { throw new Exception(e.Message); } + + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest("/g/s/persona/profile/basic"); + request.AddHeaders(headers); + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); + request.AddJsonBody(JsonConvert.SerializeObject(data)); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } /// @@ -623,18 +610,14 @@ public Task change_password(string _email, string _password, string _verificatio /// Object : Amino.Objects.GlobalProfile public Amino.Objects.GlobalProfile get_user_info(string _userId) { - try - { - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/g/s/user-profile/{_userId}"); - request.AddHeaders(headers); - var response = client.ExecuteGet(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - Amino.Objects.GlobalProfile profile = new Amino.Objects.GlobalProfile((JObject)JObject.Parse(response.Content)); - return profile; - } - catch (Exception e) { throw new Exception(e.Message); } + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/g/s/user-profile/{_userId}"); + request.AddHeaders(headers); + var response = client.ExecuteGet(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + Amino.Objects.GlobalProfile profile = new Amino.Objects.GlobalProfile((JObject)JObject.Parse(response.Content)); + return profile; } /// @@ -679,18 +662,15 @@ public bool check_device(string _deviceId) public Amino.Objects.EventLog get_event_log() { if (sessionID == null) { throw new Exception("ErrorCode: 0: Client not logged in"); } - try - { - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest("/g/s/eventlog/profile?language=en"); - request.AddHeaders(headers); - var response = client.ExecuteGet(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - Amino.Objects.EventLog eventLog = new Amino.Objects.EventLog(JObject.Parse(response.Content)); - return eventLog; - } - catch (Exception e) { throw new Exception(e.Message); } + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest("/g/s/eventlog/profile?language=en"); + request.AddHeaders(headers); + var response = client.ExecuteGet(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + Amino.Objects.EventLog eventLog = new Amino.Objects.EventLog(JObject.Parse(response.Content)); + return eventLog; + } @@ -706,25 +686,21 @@ public Amino.Objects.EventLog get_event_log() if (sessionID == null) { throw new Exception("ErrorCode: 0: Client not logged in"); } if (start < 0) { throw new Exception("start cannot be lower than 0"); } - try - { - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/g/s/community/joined?v=1&start={start}&size={size}"); - request.AddHeaders(headers); - var response = client.ExecuteGet(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/g/s/community/joined?v=1&start={start}&size={size}"); + request.AddHeaders(headers); + var response = client.ExecuteGet(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } - dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(response.Content); - JArray _jsonArray = jsonObj["communityList"]; - foreach (JObject _communityJson in _jsonArray) - { - Amino.Objects.Community community = new Objects.Community(_communityJson); - communityList.Add(community); - } - return communityList; + dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(response.Content); + JArray _jsonArray = jsonObj["communityList"]; + foreach (JObject _communityJson in _jsonArray) + { + Amino.Objects.Community community = new Objects.Community(_communityJson); + communityList.Add(community); } - catch (Exception e) { throw new Exception(e.Message); } + return communityList; } /// @@ -737,29 +713,25 @@ public Amino.Objects.EventLog get_event_log() { if (sessionID == null) { throw new Exception("ErrorCode: 0: Client not logged in"); } if (start < 0) { throw new Exception("start cannot be lower than 0"); } - try + List profileList = new List(); + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/g/s/community/joined?v=1&start={start}&size={size}"); + request.AddHeaders(headers); + var response = client.ExecuteGet(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + var profiles = ((JObject)JObject.Parse(response.Content)["userInfoInCommunities"]) + .Properties() + .Select(x => x.Value) + .Cast() + .ToList(); + foreach (var profile in profiles) { - List profileList = new List(); - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/g/s/community/joined?v=1&start={start}&size={size}"); - request.AddHeaders(headers); - var response = client.ExecuteGet(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - var profiles = ((JObject)JObject.Parse(response.Content)["userInfoInCommunities"]) - .Properties() - .Select(x => x.Value) - .Cast() - .ToList(); - foreach (var profile in profiles) - { - Objects.CommunityProfile C_Profile = new Objects.CommunityProfile(profile); - profileList.Add(C_Profile); - } - - return profileList; + Objects.CommunityProfile C_Profile = new Objects.CommunityProfile(profile); + profileList.Add(C_Profile); } - catch (Exception e) { throw new Exception(e.Message); } + + return profileList; } /// @@ -769,19 +741,14 @@ public Amino.Objects.EventLog get_event_log() public Objects.UserAccount get_account_info() { if (sessionID == null) { throw new Exception("ErrorCode: 0: Client not logged in"); } - try - { - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest("/g/s/account"); - request.AddHeaders(headers); - var response = client.ExecuteGet(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - Objects.UserAccount account = new Objects.UserAccount(JObject.Parse(response.Content)); - return account; - - } - catch (Exception e) { throw new Exception(e.Message); } + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest("/g/s/account"); + request.AddHeaders(headers); + var response = client.ExecuteGet(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + Objects.UserAccount account = new Objects.UserAccount(JObject.Parse(response.Content)); + return account; } /// @@ -795,29 +762,25 @@ public Objects.UserAccount get_account_info() if (sessionID == null) { throw new Exception("ErrorCode: 0: Client not logged in"); } if (start < 0) { throw new Exception("start cannot be lower than 0"); } - try - { - List chatList = new List(); - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/g/s/chat/thread?type=joined-me&start={start}&size={size}"); - request.AddHeaders(headers); - var response = client.ExecuteGet(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } + List chatList = new List(); + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/g/s/chat/thread?type=joined-me&start={start}&size={size}"); + request.AddHeaders(headers); + var response = client.ExecuteGet(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } - dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(response.Content); - JArray _chatList = jsonObj["threadList"]; - foreach (JObject chatJson in _chatList) - { - Objects.Chat chat = new Objects.Chat(chatJson); + dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(response.Content); + JArray _chatList = jsonObj["threadList"]; + foreach (JObject chatJson in _chatList) + { + Objects.Chat chat = new Objects.Chat(chatJson); - chatList.Add(chat); - } + chatList.Add(chat); + } - return chatList; + return chatList; - } - catch (Exception e) { throw new Exception(e.Message); } } /// @@ -829,19 +792,15 @@ public Objects.Chat get_chat_thread(string chatId) { if (sessionID == null) { throw new Exception("ErrorCode: 0: Client not logged in"); } - try - { - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/g/s/chat/thread/{chatId}"); - request.AddHeaders(headers); - var response = client.ExecuteGet(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(response.Content); - Objects.Chat chat = new Objects.Chat(jsonObj["thread"]); - return chat; - } - catch (Exception e) { throw new Exception(e.Message); } + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/g/s/chat/thread/{chatId}"); + request.AddHeaders(headers); + var response = client.ExecuteGet(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(response.Content); + Objects.Chat chat = new Objects.Chat(jsonObj["thread"]); + return chat; } /// @@ -855,25 +814,21 @@ public Objects.Chat get_chat_thread(string chatId) { if (sessionID == null) { throw new Exception("ErrorCode: 0: Client not logged in"); } if (start < 0) { throw new Exception("start cannot be lower than 0"); } - try + List chatMembers = new List(); + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/g/s/chat/thread/{chatId}/member?start={start}&size={size}&type=default&cv=1.2"); + request.AddHeaders(headers); + var response = client.ExecuteGet(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(response.Content); + JArray chatUserList = jsonObj["memberList"]; + foreach (JObject chatUser in chatUserList) { - List chatMembers = new List(); - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/g/s/chat/thread/{chatId}/member?start={start}&size={size}&type=default&cv=1.2"); - request.AddHeaders(headers); - var response = client.ExecuteGet(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(response.Content); - JArray chatUserList = jsonObj["memberList"]; - foreach (JObject chatUser in chatUserList) - { - Objects.ChatMember member = new Objects.ChatMember(chatUser); - chatMembers.Add(member); - } - return chatMembers; + Objects.ChatMember member = new Objects.ChatMember(chatUser); + chatMembers.Add(member); } - catch (Exception e) { throw new Exception(e.Message); } + return chatMembers; } /// /// Allows you to join a chat with the current Amino account @@ -883,17 +838,13 @@ public Objects.Chat get_chat_thread(string chatId) public Task join_chat(string chatId) { if (sessionID == null) { throw new Exception("ErrorCode: 0: Client not logged in"); } - try - { - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/g/s/chat/thread/{chatId}/member/{userID}"); - request.AddHeaders(headers); - var response = client.ExecutePost(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; - } - catch (Exception e) { throw new Exception(e.Message); } + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/g/s/chat/thread/{chatId}/member/{userID}"); + request.AddHeaders(headers); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } /// @@ -904,18 +855,14 @@ public Task join_chat(string chatId) public Task leave_chat(string chatId) { if (sessionID == null) { throw new Exception("ErrorCode: 0: Client not logged in"); } - try - { - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/g/s/chat/thread/{chatId}/member/{userID}"); - request.AddHeaders(headers); - request.Method = Method.Delete; - var response = client.Execute(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; - } - catch (Exception e) { throw new Exception(e.Message); } + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/g/s/chat/thread/{chatId}/member/{userID}"); + request.AddHeaders(headers); + request.Method = Method.Delete; + var response = client.Execute(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } /// @@ -927,23 +874,19 @@ public Task leave_chat(string chatId) public Task invite_to_chat(string[] userIds, string chatId) { if (sessionID == null) { throw new Exception("ErrorCode: 0: Client not logged in"); } - try - { - JObject data = new JObject(); - data.Add("timestamp", (Math.Round(helpers.GetTimestamp())) * 1000); - data.Add("uids", JToken.FromObject(new { userIds })); - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/g/s/chat/thread/{chatId}/member/invite"); - request.AddJsonBody(JsonConvert.SerializeObject(data)); - request.AddHeaders(headers); - request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(System.Text.Json.JsonSerializer.Serialize(data.ToString()))); + JObject data = new JObject(); + data.Add("timestamp", (Math.Round(helpers.GetTimestamp())) * 1000); + data.Add("uids", JToken.FromObject(new { userIds })); + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/g/s/chat/thread/{chatId}/member/invite"); + request.AddJsonBody(JsonConvert.SerializeObject(data)); + request.AddHeaders(headers); + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(System.Text.Json.JsonSerializer.Serialize(data.ToString()))); - var response = client.ExecutePost(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; - } - catch (Exception e) { throw new Exception(e.Message); } + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } /// @@ -958,17 +901,13 @@ public Task kick_from_chat(string userId, string chatId, bool allowRejoin = true int _allowRejoin; if (sessionID == null) { throw new Exception("ErrorCode: 0: Client not logged in"); } if (allowRejoin) { _allowRejoin = 1; } else { _allowRejoin = 0; } - try - { - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/g/s/chat/thread/{chatId}/member/{userId}?allowRejoin={_allowRejoin}"); - request.AddHeaders(headers); - var response = client.Delete(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; - } - catch (Exception e) { throw new Exception(e.Message); } + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/g/s/chat/thread/{chatId}/member/{userId}?allowRejoin={_allowRejoin}"); + request.AddHeaders(headers); + var response = client.Delete(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } /// @@ -983,25 +922,21 @@ public Task kick_from_chat(string userId, string chatId, bool allowRejoin = true if (sessionID == null) { throw new Exception("ErrorCode: 0: Client not logged in"); } string endPoint; if (!string.IsNullOrEmpty(pageToken) || !string.IsNullOrWhiteSpace(pageToken)) { endPoint = $"/g/s/chat/thread/{chatId}/message?v=2&pagingType=t&pageToken={pageToken}&size={size}"; } else { endPoint = $"/g/s/chat/thread/{chatId}/message?v=2&pagingType=t&size={size}"; } - try + List messageCollection = new List(); + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest(endPoint); + request.AddHeaders(headers); + var response = client.ExecuteGet(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(response.Content); + JArray chatMessageList = jsonObj["messageList"]; + foreach (JObject chatMessage in chatMessageList) { - List messageCollection = new List(); - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest(endPoint); - request.AddHeaders(headers); - var response = client.ExecuteGet(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(response.Content); - JArray chatMessageList = jsonObj["messageList"]; - foreach (JObject chatMessage in chatMessageList) - { - Objects.MessageCollection message = new Objects.MessageCollection(chatMessage, JObject.Parse(response.Content)); - messageCollection.Add(message); - } - return messageCollection; + Objects.MessageCollection message = new Objects.MessageCollection(chatMessage, JObject.Parse(response.Content)); + messageCollection.Add(message); } - catch (Exception e) { throw new Exception(e.Message); } + return messageCollection; } /// @@ -1011,25 +946,21 @@ public Task kick_from_chat(string userId, string chatId, bool allowRejoin = true /// List : Amino.Objects.CommunityInfo public List search_community(string aminoId) { - try + List communityInfoList = new List(); + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/g/s/search/amino-id-and-link?q={aminoId}"); + request.AddHeaders(headers); + var response = client.ExecuteGet(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(response.Content); + JArray communityInfo = jsonObj["resultList"]; + foreach (JObject community in communityInfo) { - List communityInfoList = new List(); - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/g/s/search/amino-id-and-link?q={aminoId}"); - request.AddHeaders(headers); - var response = client.ExecuteGet(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(response.Content); - JArray communityInfo = jsonObj["resultList"]; - foreach (JObject community in communityInfo) - { - Objects.CommunityInfo com = new Objects.CommunityInfo(community); - communityInfoList.Add(com); - } - return communityInfoList; + Objects.CommunityInfo com = new Objects.CommunityInfo(community); + communityInfoList.Add(com); } - catch (Exception e) { throw new Exception(e.Message); } + return communityInfoList; } /// @@ -1042,26 +973,21 @@ public Task kick_from_chat(string userId, string chatId, bool allowRejoin = true public List get_user_following(string userId, int start = 0, int size = 25) { if (start < 0) { throw new Exception("start cannot be lower than 0"); } - try + List userFollowingsList = new List(); + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/g/s/user-profile/{userId}/joined?start={start}&size={size}"); + request.AddHeaders(headers); + var response = client.ExecuteGet(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(response.Content); + JArray userFollowings = jsonObj["userProfileList"]; + foreach (JObject following in userFollowings) { - List userFollowingsList = new List(); - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/g/s/user-profile/{userId}/joined?start={start}&size={size}"); - request.AddHeaders(headers); - var response = client.ExecuteGet(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(response.Content); - JArray userFollowings = jsonObj["userProfileList"]; - foreach (JObject following in userFollowings) - { - Objects.UserFollowings _following = new Objects.UserFollowings(following); - userFollowingsList.Add(_following); - } - return userFollowingsList; - + Objects.UserFollowings _following = new Objects.UserFollowings(following); + userFollowingsList.Add(_following); } - catch (Exception e) { throw new Exception(e.Message); } + return userFollowingsList; } /// @@ -1074,26 +1000,21 @@ public Task kick_from_chat(string userId, string chatId, bool allowRejoin = true public List get_user_followers(string userId, int start = 0, int size = 25) { if (start < 0) { throw new Exception("start cannot be lower than 0"); } - try + List userFollowerList = new List(); + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/g/s/user-profile/{userId}/member?start={start}&size={size}"); + request.AddHeaders(headers); + var response = client.ExecuteGet(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(response.Content); + JArray userFollowers = jsonObj["userProfileList"]; + foreach (JObject follower in userFollowers) { - List userFollowerList = new List(); - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/g/s/user-profile/{userId}/member?start={start}&size={size}"); - request.AddHeaders(headers); - var response = client.ExecuteGet(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(response.Content); - JArray userFollowers = jsonObj["userProfileList"]; - foreach (JObject follower in userFollowers) - { - Objects.UserFollowings _follower = new Objects.UserFollowings(follower); - userFollowerList.Add(_follower); - } - return userFollowerList; - + Objects.UserFollowings _follower = new Objects.UserFollowings(follower); + userFollowerList.Add(_follower); } - catch (Exception e) { throw new Exception(e.Message); } + return userFollowerList; } @@ -1107,25 +1028,21 @@ public Task kick_from_chat(string userId, string chatId, bool allowRejoin = true public List get_user_visitors(string userId, int start = 0, int size = 25) { if (start < 0) { throw new Exception("start cannot be lower than 0"); } - try + List userVisitorList = new List(); + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/g/s/user-profile/{userId}/visitors?start={start}&size={size}"); + request.AddHeaders(headers); + var response = client.ExecuteGet(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(response.Content); + JArray userVisitors = jsonObj["visitors"]; + foreach (JObject visitor in userVisitors) { - List userVisitorList = new List(); - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/g/s/user-profile/{userId}/visitors?start={start}&size={size}"); - request.AddHeaders(headers); - var response = client.ExecuteGet(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(response.Content); - JArray userVisitors = jsonObj["visitors"]; - foreach (JObject visitor in userVisitors) - { - Objects.UserVisitor _visitor = new Objects.UserVisitor(visitor, jsonObj); - userVisitorList.Add(_visitor); - } - return userVisitorList; + Objects.UserVisitor _visitor = new Objects.UserVisitor(visitor, jsonObj); + userVisitorList.Add(_visitor); } - catch (Exception e) { throw new Exception(e.Message); } + return userVisitorList; } /// @@ -1138,25 +1055,21 @@ public Task kick_from_chat(string userId, string chatId, bool allowRejoin = true { if (sessionID == null) { throw new Exception("ErrorCode: 0: Client not logged in"); } if (start < 0) { throw new Exception("start cannot be lower than 0"); } - try + List blockedUserList = new List(); + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/g/s/block?start={start}&size={size}"); + request.AddHeaders(headers); + var response = client.ExecuteGet(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.StatusCode); } + dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(response.Content); + JArray blockedUsers = jsonObj["userProfileList"]; + foreach (JObject user in blockedUsers) { - List blockedUserList = new List(); - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/g/s/block?start={start}&size={size}"); - request.AddHeaders(headers); - var response = client.ExecuteGet(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.StatusCode); } - dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(response.Content); - JArray blockedUsers = jsonObj["userProfileList"]; - foreach (JObject user in blockedUsers) - { - Objects.BlockedUser _blockedUser = new Objects.BlockedUser(user); - blockedUserList.Add(_blockedUser); - } - return blockedUserList; + Objects.BlockedUser _blockedUser = new Objects.BlockedUser(user); + blockedUserList.Add(_blockedUser); } - catch (Exception e) { throw new Exception(e.Message); } + return blockedUserList; } /// @@ -1169,24 +1082,20 @@ public List get_blocker_users(int start = 0, int size = 25) { if (sessionID == null) { throw new Exception("ErrorCode: 0: Client not logged in"); } if (start < 0) { throw new Exception("start cannot be lower than 0"); } - try + List blockerUserList = new List(); + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/g/s/block/full-list?start={start}&size={size}"); + request.AddHeaders(headers); + var response = client.ExecuteGet(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(response.Content); + JArray blockerUsers = jsonObj["blockerUidList"]; + foreach (var user in blockerUsers) { - List blockerUserList = new List(); - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/g/s/block/full-list?start={start}&size={size}"); - request.AddHeaders(headers); - var response = client.ExecuteGet(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(response.Content); - JArray blockerUsers = jsonObj["blockerUidList"]; - foreach (var user in blockerUsers) - { - blockerUserList.Add(user.ToString()); - } - return blockerUserList; + blockerUserList.Add(user.ToString()); } - catch (Exception e) { throw new Exception(e.Message); } + return blockerUserList; } /// @@ -1200,42 +1109,37 @@ public List get_blocker_users(int start = 0, int size = 25) public List get_wall_comments(string userId, Types.Sorting_Types type, int start = 0, int size = 25) { if (start < 0) { throw new Exception("start cannot be lower than 0"); } - try + List commentList = new List(); + string _sorting_type; + switch (type) { - List commentList = new List(); - string _sorting_type; - switch (type) - { - case Types.Sorting_Types.Newest: - _sorting_type = "newest"; - break; - case Types.Sorting_Types.Oldest: - _sorting_type = "oldest"; - break; - case Types.Sorting_Types.Top: - _sorting_type = "vote"; - break; - default: - _sorting_type = "newest"; - break; - } - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/g/s/user-profile/{userId}/g-comment?sort={_sorting_type}&start={start}&size={size}"); - request.AddHeaders(headers); - var response = client.ExecuteGet(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(response.Content); - JArray comments = jsonObj["commentList"]; - foreach (JObject comment in comments) - { - Objects.Comment _comment = new Objects.Comment(comment); - commentList.Add(_comment); - } - return commentList; - + case Types.Sorting_Types.Newest: + _sorting_type = "newest"; + break; + case Types.Sorting_Types.Oldest: + _sorting_type = "oldest"; + break; + case Types.Sorting_Types.Top: + _sorting_type = "vote"; + break; + default: + _sorting_type = "newest"; + break; } - catch (Exception e) { throw new Exception(e.Message); } + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/g/s/user-profile/{userId}/g-comment?sort={_sorting_type}&start={start}&size={size}"); + request.AddHeaders(headers); + var response = client.ExecuteGet(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(response.Content); + JArray comments = jsonObj["commentList"]; + foreach (JObject comment in comments) + { + Objects.Comment _comment = new Objects.Comment(comment); + commentList.Add(_comment); + } + return commentList; } /// @@ -1251,27 +1155,23 @@ public Task flag(string reason, Types.Flag_Types flagType, Types.Flag_Targets ta { if (!asGuest) { if (sessionID == null) { throw new Exception("ErrorCode: 0: Client not logged in"); } } string _flag = asGuest ? "g-flag" : "flag"; - try + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/g/s/{_flag}"); + var data = new { - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/g/s/{_flag}"); - var data = new - { - flagType = (int)flagType, - message = reason, - timestamp = helpers.GetTimestamp() * 1000, - objectId = targetId, - objetType = (int)targetType - }; - request.AddHeaders(headers); - request.AddJsonBody(data); - request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(System.Text.Json.JsonSerializer.Serialize(data))); - var response = client.ExecutePost(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; - } - catch (Exception e) { throw new Exception(e.Message); } + flagType = (int)flagType, + message = reason, + timestamp = helpers.GetTimestamp() * 1000, + objectId = targetId, + objetType = (int)targetType + }; + request.AddHeaders(headers); + request.AddJsonBody(data); + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(System.Text.Json.JsonSerializer.Serialize(data))); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } /// @@ -1285,26 +1185,22 @@ public Task flag(string reason, Types.Flag_Types flagType, Types.Flag_Targets ta public Task delete_message(string chatId, string messageId, bool asStaff = false, string reason = null) { if (sessionID == null) { throw new Exception("ErrorCode: 0: Client not logged in"); } - try - { - JObject data = new JObject() + JObject data = new JObject() { { "adminOpName", 102 }, { "adminOpNote", new JObject() { "content", reason } }, { "timestamp", helpers.GetTimestamp() * 1000 } }; - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/g/s/chat/thread/{chatId}/message/{messageId}"); - if (asStaff) { request.Resource = request.Resource + "/admin"; } - request.AddHeaders(headers); - request.AddJsonBody(JsonConvert.SerializeObject(data)); - request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); - var response = client.ExecutePost(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; - } - catch (Exception e) { throw new Exception(e.Message); } + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/g/s/chat/thread/{chatId}/message/{messageId}"); + if (asStaff) { request.Resource = request.Resource + "/admin"; } + request.AddHeaders(headers); + request.AddJsonBody(JsonConvert.SerializeObject(data)); + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } /// /// Allows you to mark a message as read with the current Amino account @@ -1320,19 +1216,15 @@ public Task mark_as_read(string _chatId, string _messageId) { "messageId", _messageId }, { "timestamp", helpers.GetTimestamp() * 1000 } }; - try - { - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/g/s/chat/thread/{_chatId}/mark-as-read"); - request.AddHeaders(headers); - request.AddJsonBody(JsonConvert.SerializeObject(data)); - request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); - var response = client.ExecutePost(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; - } - catch (Exception e) { throw new Exception(e.Message); } + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/g/s/chat/thread/{_chatId}/mark-as-read"); + request.AddHeaders(headers); + request.AddJsonBody(JsonConvert.SerializeObject(data)); + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } /// @@ -1342,17 +1234,13 @@ public Task mark_as_read(string _chatId, string _messageId) /// public Task visit(string userId) { - try - { - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/g/s/user-profile/{userId}?action=visit"); - request.AddHeaders(headers); - var response = client.ExecuteGet(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; - } - catch (Exception e) { throw new Exception(e.Message); } + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/g/s/user-profile/{userId}?action=visit"); + request.AddHeaders(headers); + var response = client.ExecuteGet(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } /// @@ -1363,17 +1251,13 @@ public Task visit(string userId) public Task follow_user(string userId) { if (sessionID == null) { throw new Exception("ErrorCode: 0: Client not logged in"); } - try - { - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/g/s/user-profile/{userId}/member"); - request.AddHeaders(headers); - var response = client.ExecutePost(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; - } - catch (Exception e) { throw new Exception(e.Message); } + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/g/s/user-profile/{userId}/member"); + request.AddHeaders(headers); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } /// @@ -1384,18 +1268,13 @@ public Task follow_user(string userId) public Task unfollow_user(string _userId) { if (sessionID == null) { throw new Exception("ErrorCode: 0: Client not logged in"); } - try - { - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/g/s/user-profile/{_userId}/member/{userID}"); - request.AddHeaders(headers); - var response = client.Delete(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; - - } - catch (Exception e) { throw new Exception(e.Message); } + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/g/s/user-profile/{_userId}/member/{userID}"); + request.AddHeaders(headers); + var response = client.Delete(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } /// /// Allows you to block a user with the current Amino account @@ -1405,38 +1284,30 @@ public Task unfollow_user(string _userId) public Task block_user(string _userId) { if (sessionID == null) { throw new Exception("ErrorCode: 0: Client not logged in"); } - try - { - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/g/s/block/{_userId}"); - request.AddHeaders(headers); - var response = client.ExecutePost(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; - } - catch (Exception e) { throw new Exception(e.Message); } + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/g/s/block/{_userId}"); + request.AddHeaders(headers); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } /// /// Allows you to unblock a user with the current Amino account /// - /// - /// - public Task unblock_user(string _userId) - { - if (sessionID == null) { throw new Exception("ErrorCode: 0: Client not logged in"); } - try - { - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/g/s/block/{_userId}"); - request.AddHeaders(headers); - var response = client.Delete(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; - } - catch (Exception e) { throw new Exception(e.Message); } + /// + /// + public Task unblock_user(string _userId) + { + if (sessionID == null) { throw new Exception("ErrorCode: 0: Client not logged in"); } + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/g/s/block/{_userId}"); + request.AddHeaders(headers); + var response = client.Delete(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } /// @@ -1448,22 +1319,18 @@ public Task unblock_user(string _userId) public Task join_community(string communityId, string invitationCode = null) { if (sessionID == null) { throw new Exception("ErrorCode: 0: Client not logged in"); } - try - { - JObject data = new JObject(); - data.Add("timestamp", helpers.GetTimestamp() * 1000); - if (invitationCode != null) { data.Add("invitationId", invitationCode); } - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/x{communityId}/s/community/join"); - request.AddJsonBody(JsonConvert.SerializeObject(data)); - request.AddHeaders(headers); - request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); - var response = client.ExecutePost(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; - } - catch (Exception e) { throw new Exception(e.Message); } + JObject data = new JObject(); + data.Add("timestamp", helpers.GetTimestamp() * 1000); + if (invitationCode != null) { data.Add("invitationId", invitationCode); } + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/x{communityId}/s/community/join"); + request.AddJsonBody(JsonConvert.SerializeObject(data)); + request.AddHeaders(headers); + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } /// @@ -1475,24 +1342,20 @@ public Task join_community(string communityId, string invitationCode = null) public Task join_community_request(string communityId, string message = null) { if (sessionID == null) { throw new Exception("ErrorCode: 0: Client not logged in"); } - try + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/x{communityId}/s/community/membership-request"); + var data = new JObject() { - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/x{communityId}/s/community/membership-request"); - var data = new - { - message = message, - timestamp = helpers.GetTimestamp() * 1000 - }; - request.AddJsonBody(data); - request.AddHeaders(headers); - request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(System.Text.Json.JsonSerializer.Serialize(data))); - var response = client.ExecutePost(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; - } - catch (Exception e) { throw new Exception(e.Message); } + { "message", message }, + { "timestamp", helpers.GetTimestamp() * 1000 } + }; + request.AddJsonBody(JsonConvert.SerializeObject(data)); + request.AddHeaders(headers); + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } /// @@ -1503,17 +1366,13 @@ public Task join_community_request(string communityId, string message = null) public Task leave_community(string communityId) { if (sessionID == null) { throw new Exception("ErrorCode: 0: Client not logged in"); } - try - { - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/s/community/leave"); - request.AddHeaders(headers); - var response = client.ExecutePost(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; - } - catch (Exception e) { throw new Exception(e.Message); } + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/s/community/leave"); + request.AddHeaders(headers); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } /// @@ -1528,58 +1387,25 @@ public Task flag_community(string communityId, string reason, Types.Flag_Types f { if (!asGuest) { if (sessionID == null) { throw new Exception("ErrorCode: 0: Client not logged in"); } } int _flagType; - string _flag; - switch (flagType) - { - case Types.Flag_Types.Aggression: - _flagType = 0; - break; - case Types.Flag_Types.Spam: - _flagType = 2; - break; - case Types.Flag_Types.Off_Topic: - _flagType = 4; - break; - case Types.Flag_Types.Violence: - _flagType = 106; - break; - case Types.Flag_Types.Intolerance: - _flagType = 107; - break; - case Types.Flag_Types.Suicide: - _flagType = 108; - break; - case Types.Flag_Types.Pronography: - _flagType = 110; - break; - default: - _flagType = 0; - break; - } - if (asGuest) { _flag = "g-flag"; } else { _flag = "flag"; } - var data = new + string _flag = asGuest ? "g-flag" : "flag"; + JObject data = new JObject() { - objectId = communityId, - objectType = 16, - flagType = _flagType, - message = reason, - timestamp = helpers.GetTimestamp() * 1000 + { "objectId", communityId }, + { "objectType", 16 }, + { "flagType", (int)flagType }, + { "message", reason }, + { "timestamp", helpers.GetTimestamp() * 1000 } }; - try - { RestClient client = new RestClient(helpers.BaseUrl); RestRequest request = new RestRequest($"/x{communityId}/s/{_flag}"); request.AddHeaders(headers); - request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(System.Text.Json.JsonSerializer.Serialize(data))); - request.AddJsonBody(data); + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); + request.AddJsonBody(JsonConvert.SerializeObject(data)); var response = client.ExecutePost(request); if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } if (debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - } - catch (Exception e) { throw new Exception(e.Message); } - } /// @@ -1618,8 +1444,6 @@ public string upload_media(byte[] file, Types.upload_File_Types type) _fileType = "image/jpg"; break; } - try - { RestClient client = new RestClient(helpers.BaseUrl); RestRequest request = new RestRequest("/g/s/media/upload"); request.AddHeaders(headers); @@ -1631,8 +1455,6 @@ public string upload_media(byte[] file, Types.upload_File_Types type) if (debug) { Trace.WriteLine(response.Content); } dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(response.Content); return jsonObj["mediaValue"]; - } - catch (Exception e) { throw new Exception(e.Message); } } /// @@ -1699,8 +1521,6 @@ public Task edit_profile(string nickname = null, string content = null, byte[] i } } - try - { RestClient client = new RestClient(helpers.BaseUrl); RestRequest request = new RestRequest($"g/s/user-profile/{userID}"); request.AddHeaders(headers); @@ -1710,8 +1530,6 @@ public Task edit_profile(string nickname = null, string content = null, byte[] i if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } if (debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - } - catch (Exception e) { throw new Exception(e.Message); } } /// @@ -1723,29 +1541,23 @@ public Task edit_profile(string nickname = null, string content = null, byte[] i public Task set_privacy_status(bool isAnonymous = false, bool getNotifications = true) { if (sessionID == null) { throw new Exception("ErrorCode: 0: Client not logged in"); } - int _privacyMode; - int _notificationStatus; - if (isAnonymous) { _privacyMode = 2; } else { _privacyMode = 1; } - if (getNotifications) { _notificationStatus = 2; } else { _notificationStatus = 1; } - var data = new + int _privacyMode = isAnonymous ? 2 : 1; + int _notificationStatus = getNotifications ? 2 : 1; + JObject data = new JObject() { - timestamp = helpers.GetTimestamp() * 1000, - notificationStatus = _notificationStatus, - privacyMode = _privacyMode + { "timestamp", helpers.GetTimestamp() * 1000 }, + { "notificationStatus", _notificationStatus }, + { "privacyMode", _privacyMode } }; - try - { RestClient client = new RestClient(helpers.BaseUrl); RestRequest request = new RestRequest("/g/s/account/visit-settings"); request.AddHeaders(headers); - request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(System.Text.Json.JsonSerializer.Serialize(data))); - request.AddJsonBody(data); + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); + request.AddJsonBody(JsonConvert.SerializeObject(data)); var response = client.ExecutePost(request); if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } if (debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - } - catch (Exception e) { throw new Exception(e.Message); } } /// @@ -1756,24 +1568,20 @@ public Task set_privacy_status(bool isAnonymous = false, bool getNotifications = public Task set_amino_id(string aminoId) { if (sessionID == null) { throw new Exception("ErrorCode: 0: Client not logged in"); } - var data = new + JObject data = new JObject() { - timestamp = helpers.GetTimestamp() * 1000, - aminoId = aminoId + { "timestamp", helpers.GetTimestamp() * 1000 }, + { "aminoId", aminoId } }; - try - { RestClient client = new RestClient(helpers.BaseUrl); RestRequest request = new RestRequest("/g/s/account/change-amino-id"); request.AddHeaders(headers); - request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(System.Text.Json.JsonSerializer.Serialize(data))); - request.AddJsonBody(data); + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); + request.AddJsonBody(JsonConvert.SerializeObject(data)); var response = client.ExecutePost(request); if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } if (debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - } - catch (Exception e) { throw new Exception(e.Message); } } /// @@ -1784,8 +1592,6 @@ public Task set_amino_id(string aminoId) public Task add_linked_community(int communityId) { if (sessionID == null) { throw new Exception("ErrorCode: 0: Client not logged in"); } - try - { RestClient client = new RestClient(helpers.BaseUrl); RestRequest request = new RestRequest($"/g/s/user-profile/{userID}/linked-community/{communityId}"); request.AddHeaders(headers); @@ -1793,8 +1599,6 @@ public Task add_linked_community(int communityId) if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } if (debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - } - catch (Exception e) { throw new Exception(e.Message); } } /// @@ -1805,8 +1609,6 @@ public Task add_linked_community(int communityId) public Task remove_linked_community(int communityId) { if (sessionID == null) { throw new Exception("ErrorCode: 0: Client not logged in"); } - try - { RestClient client = new RestClient(helpers.BaseUrl); RestRequest request = new RestRequest($"/g/s/user-profile/{userID}/linked-community/{communityId}"); request.AddHeaders(headers); @@ -1814,8 +1616,6 @@ public Task remove_linked_community(int communityId) if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } if (debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - } - catch (Exception e) { throw new Exception(e.Message); } } /// @@ -1830,8 +1630,6 @@ public Task comment(string message, Types.Comment_Types type, string objectId) if (sessionID == null) { throw new Exception("ErrorCode: 0: Client not logged in"); } string _eventSource; bool _isReply = false; - try - { RestClient client = new RestClient(helpers.BaseUrl); RestRequest request = new RestRequest(); request.AddHeaders(headers); @@ -1872,8 +1670,6 @@ public Task comment(string message, Types.Comment_Types type, string objectId) if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } if (debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - } - catch (Exception e) { throw new Exception(e.Message); } } /// @@ -1886,8 +1682,6 @@ public Task comment(string message, Types.Comment_Types type, string objectId) public Task delete_comment(string commentId, Types.Comment_Types type, string objectId) { if (sessionID == null) { throw new Exception("ErrorCode: 0: Client not logged in"); } - try - { RestClient client = new RestClient(); RestRequest request = new RestRequest(); switch (type) @@ -1910,9 +1704,6 @@ public Task delete_comment(string commentId, Types.Comment_Types type, string ob if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } if (debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - - } - catch (Exception e) { throw new Exception(e.Message); } } /// @@ -1925,8 +1716,6 @@ public Task like_post(string objectId, Types.Post_Types type) { if (sessionID == null) { throw new Exception("ErrorCode: 0: Client not logged in"); } string _eventSource; - try - { RestClient client = new RestClient(helpers.BaseUrl); RestRequest request = new RestRequest(); switch (type) @@ -1944,22 +1733,19 @@ public Task like_post(string objectId, Types.Post_Types type) _eventSource = "UserProfileView"; break; } - var data = new - { - value = 4, - timestamp = helpers.GetTimestamp() * 1000, - eventSource = _eventSource - }; + JObject data = new JObject() + { + { "value", 4 }, + { "timestamp", helpers.GetTimestamp() * 1000 }, + { "eventSource", _eventSource } + }; request.AddHeaders(headers); - request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(System.Text.Json.JsonSerializer.Serialize(data))); - request.AddJsonBody(data); + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); + request.AddJsonBody(JsonConvert.SerializeObject(data)); var response = client.ExecutePost(request); if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } if (debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - - } - catch (Exception e) { throw new Exception(e.Message); } } /// @@ -1971,8 +1757,6 @@ public Task like_post(string objectId, Types.Post_Types type) public Task unlike_post(string objectId, Types.Post_Types type) { if (sessionID == null) { throw new Exception("ErrorCode: 0: Client not logged in"); } - try - { RestClient client = new RestClient(helpers.BaseUrl); RestRequest request = new RestRequest(); request.AddHeaders(headers); @@ -1993,8 +1777,6 @@ public Task unlike_post(string objectId, Types.Post_Types type) if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } if (debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - } - catch (Exception e) { throw new Exception(e.Message); } } /// @@ -2004,8 +1786,6 @@ public Task unlike_post(string objectId, Types.Post_Types type) public Objects.MembershipInfo get_membership_info() { if (sessionID == null) { throw new Exception("ErrorCode: 0: Client not logged in"); } - try - { RestClient client = new RestClient(helpers.BaseUrl); RestRequest request = new RestRequest("/g/s/membership?force=true"); request.AddHeaders(headers); @@ -2014,8 +1794,6 @@ public Objects.MembershipInfo get_membership_info() if (debug) { Trace.WriteLine(response.Content); } Objects.MembershipInfo membershipInfo = new Objects.MembershipInfo(JObject.Parse(response.Content)); return membershipInfo; - } - catch (Exception e) { throw new Exception(e.Message); } } /// @@ -2056,8 +1834,6 @@ public Objects.MembershipInfo get_membership_info() _language = "en"; break; } - try - { RestClient client = new RestClient(helpers.BaseUrl); RestRequest request = new RestRequest($"/g/s/announcement?language={_language}&start={start}&size={size}"); request.AddHeaders(headers); @@ -2073,8 +1849,6 @@ public Objects.MembershipInfo get_membership_info() ta_announcements.Add(_post); } return ta_announcements; - } - catch (Exception e) { throw new Exception(e.Message); } } /// @@ -2084,8 +1858,6 @@ public Objects.MembershipInfo get_membership_info() public Objects.WalletInfo get_wallet_info() { if (sessionID == null) { throw new Exception("ErrorCode: 0: Client not logged in"); } - try - { RestClient client = new RestClient(helpers.BaseUrl); RestRequest request = new RestRequest("/g/s/wallet"); request.AddHeaders(headers); @@ -2095,8 +1867,6 @@ public Objects.WalletInfo get_wallet_info() JObject jsonObj = JObject.Parse(response.Content); Objects.WalletInfo _walletInfo = new Objects.WalletInfo(jsonObj); return _walletInfo; - } - catch (Exception e) { throw new Exception(e.Message); } } /// @@ -2109,9 +1879,6 @@ public Objects.WalletInfo get_wallet_info() { if (sessionID == null) { throw new Exception("ErrorCode: 0: Client not logged in"); } if (start < 0) { throw new Exception("start cannot be lower than 0"); } - try - { - RestClient client = new RestClient(helpers.BaseUrl); RestRequest request = new RestRequest($"/g/s/wallet/coin/history?start={start}&size={size}"); request.AddHeaders(headers); @@ -2127,8 +1894,6 @@ public Objects.WalletInfo get_wallet_info() coinHistoryList.Add(_entry); } return coinHistoryList; - } - catch (Exception e) { throw new Exception(e.Message); } } /// @@ -2138,8 +1903,6 @@ public Objects.WalletInfo get_wallet_info() /// string : the target users ID public string get_from_deviceId(string deviceId) { - try - { RestClient client = new RestClient(helpers.BaseUrl); RestRequest request = new RestRequest($"/g/s/auid?deviceId={deviceId}"); request.AddHeaders(headers); @@ -2149,8 +1912,6 @@ public string get_from_deviceId(string deviceId) Console.WriteLine(response.Content); dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(response.Content); return jsonObj["auid"]; - } - catch (Exception e) { throw new Exception(e.Message); } } /// @@ -2160,8 +1921,6 @@ public string get_from_deviceId(string deviceId) /// Object : Amino.Objects.FromCode public Objects.FromCode get_from_code(string aminoUrl) { - try - { RestClient client = new RestClient(helpers.BaseUrl); RestRequest request = new RestRequest($"/g/s/link-resolution?q={aminoUrl}"); request.AddHeaders(headers); @@ -2171,8 +1930,6 @@ public Objects.FromCode get_from_code(string aminoUrl) dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(response.Content); Amino.Objects.FromCode fromCode = new Objects.FromCode(jsonObj); return fromCode; - } - catch (Exception e) { throw new Exception(e.Message); } } /// @@ -2185,15 +1942,13 @@ public Objects.FromCode get_from_code(string aminoUrl) public Objects.FromId get_from_id(string objectId, Amino.Types.Object_Types type, string communityId = null) { if (sessionID == null) { throw new Exception("ErrorCode: 0: Client not logged in"); } - var data = new + JObject data = new JObject() { - objectId = objectId, - targetCode = 1, - timestamp = helpers.GetTimestamp() * 1000, - objectType = (int)type + { "objectId", objectId }, + { "targetCode", 1 }, + { "timestamp", helpers.GetTimestamp() * 1000 }, + { "objectType", (int)type } }; - try - { RestClient client = new RestClient(helpers.BaseUrl); RestRequest request = new RestRequest(); if (communityId != null) @@ -2202,16 +1957,14 @@ public Objects.FromId get_from_id(string objectId, Amino.Types.Object_Types type } else { request.Resource = $"/g/s/link-resolution"; } request.AddHeaders(headers); - request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(System.Text.Json.JsonSerializer.Serialize(data))); - request.AddJsonBody(data); + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); + request.AddJsonBody(JsonConvert.SerializeObject(data)); var response = client.ExecutePost(request); if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } if (debug) { Trace.WriteLine(response.Content); } dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(response.Content); Amino.Objects.FromId fromId = new Objects.FromId(jsonObj); return fromId; - } - catch (Exception e) { throw new Exception(e.Message); } } /// @@ -2220,8 +1973,6 @@ public Objects.FromId get_from_id(string objectId, Amino.Types.Object_Types type /// string[] : language keys public string[] get_supported_languages() { - try - { RestClient client = new RestClient(helpers.BaseUrl); RestRequest request = new RestRequest("/g/s/community-collection/supported-languages?start=0&size=100"); request.AddHeaders(headers); @@ -2237,8 +1988,6 @@ public string[] get_supported_languages() langList.Add(language.ToString()); } return langList.ToArray(); - } - catch (Exception e) { throw new Exception(e.Message); } } /// @@ -2248,8 +1997,6 @@ public string[] get_supported_languages() public Task claim_new_user_coupon() { if (sessionID == null) { throw new Exception("ErrorCode: 0: Client not logged in"); } - try - { RestClient client = new RestClient(helpers.BaseUrl); RestRequest request = new RestRequest("/g/s/coupon/new-user-coupon/claim"); request.AddHeaders(headers); @@ -2257,8 +2004,6 @@ public Task claim_new_user_coupon() if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } if (debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - } - catch (Exception e) { throw new Exception(e.Message); } } @@ -2271,8 +2016,6 @@ public Task claim_new_user_coupon() public List get_all_users(int start = 0, int size = 25) { if (start < 0) { throw new Exception("start cannot be lower than 0"); } - try - { List userList = new List(); RestClient client = new RestClient(helpers.BaseUrl); RestRequest request = new RestRequest($"/g/s/user-profile?type=recent&start={start}&size={size}"); @@ -2288,8 +2031,6 @@ public Task claim_new_user_coupon() userList.Add(_user); } return userList; - } - catch (Exception e) { throw new Exception(e.Message); } } /// @@ -2300,8 +2041,6 @@ public Task claim_new_user_coupon() /// public Objects.AdvancedCommunityInfo get_community_info(string communityId) { - try - { RestClient client = new RestClient(helpers.BaseUrl); RestRequest request = new RestRequest($"/g/s-x{communityId}/community/info?withInfluencerList=1&withTopicList=true&influencerListOrderStrategy=fansCount"); request.AddHeaders(headers); @@ -2311,8 +2050,6 @@ public Objects.AdvancedCommunityInfo get_community_info(string communityId) dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(response.Content); Objects.AdvancedCommunityInfo community = new Objects.AdvancedCommunityInfo(jsonObj); return community; - } - catch (Exception e) { throw new Exception(e.Message); } } /// @@ -2335,8 +2072,6 @@ public Objects.AdvancedCommunityInfo get_community_info(int communityId) public Task accept_host(string chatId, string requestId) { if (sessionID == null) { throw new Exception("ErrorCode: 0: Client not logged in"); } - try - { RestClient client = new RestClient(helpers.BaseUrl); RestRequest request = new RestRequest($"/g/s/chat/thread/{chatId}/transfer-organizer/{requestId}/accept"); request.AddHeaders(headers); @@ -2347,8 +2082,6 @@ public Task accept_host(string chatId, string requestId) if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } if (debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - } - catch (Exception e) { throw new Exception(e.Message); } } @@ -2372,8 +2105,6 @@ public Task accept_organizer(string chatId, string requestId) /// Object : Amino.Objects.FromInvite public Amino.Objects.FromInvite link_identify(string inviteCode) { - try - { RestClient client = new RestClient(helpers.BaseUrl); RestRequest request = new RestRequest($"/g/s/community/link-identify?q=http%3A%2F%2Faminoapps.com%2Finvite%2F{inviteCode}"); request.AddHeaders(headers); @@ -2383,8 +2114,6 @@ public Amino.Objects.FromInvite link_identify(string inviteCode) JObject json = JObject.Parse(response.Content); Objects.FromInvite fromInvite = new Objects.FromInvite(json); return fromInvite; - } - catch (Exception e) { throw new Exception(e.Message); } } /// @@ -2395,8 +2124,6 @@ public Amino.Objects.FromInvite link_identify(string inviteCode) public Task wallet_config(Types.Wallet_Config_Levels walletLevel) { if (sessionID == null) { throw new Exception("ErrorCode: 0: Client not logged in"); } - try - { JObject data = new JObject() { { "adsLevel", (int)walletLevel }, @@ -2411,8 +2138,6 @@ public Task wallet_config(Types.Wallet_Config_Levels walletLevel) if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } if (debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - } - catch (Exception e) { throw new Exception(e.Message); } } /// @@ -2425,8 +2150,6 @@ public Task wallet_config(Types.Wallet_Config_Levels walletLevel) { if (sessionID == null) { throw new Exception("ErrorCode: 0: Client not logged in"); } if (start < 0) { throw new Exception("start cannot be lower than 0"); } - try - { List _avataFrameList = new List(); RestClient client = new RestClient(helpers.BaseUrl); RestRequest request = new RestRequest($"/g/s/avatar-frame?start={start}&size={size}"); @@ -2442,8 +2165,6 @@ public Task wallet_config(Types.Wallet_Config_Levels walletLevel) _avataFrameList.Add(_avatarFrame); } return _avataFrameList; - } - catch (Exception e) { throw new Exception(e.Message); } } /// @@ -2455,8 +2176,6 @@ public Task wallet_config(Types.Wallet_Config_Levels walletLevel) /// public Task invite_to_vc(string chatId, string userId) { - try - { RestClient client = new RestClient(helpers.BaseUrl); RestRequest request = new RestRequest($"/g/s/chat/thread/{chatId}/vvchat-presenter/invite"); @@ -2474,9 +2193,6 @@ public Task invite_to_vc(string chatId, string userId) if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } if (debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - - } - catch (Exception e) { throw new Exception(e.Message); } } /// @@ -2491,8 +2207,6 @@ public Task invite_to_vc(string chatId, string userId) /// public Objects.Message send_message(string message, string chatId, Types.Message_Types messageType = Types.Message_Types.General, string replyTo = null, List mentionUserIds = null) { - try - { List mentions = new List(); if (mentionUserIds == null) { mentionUserIds = new List(); } else @@ -2538,8 +2252,6 @@ public Objects.Message send_message(string message, string chatId, Types.Message if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } if (debug) { Trace.WriteLine(response.Content); } return new Objects.Message(JObject.Parse(response.Content)); - } - catch (Exception e) { throw new Exception(e.Message); } } /// @@ -2615,12 +2327,8 @@ public Task send_file_message(string chatId, byte[] file, Types.upload_File_Type /// public Task send_file_message(string chatId, string filePath, Types.upload_File_Types fileType) { - try - { send_file_message(chatId, File.ReadAllBytes(filePath), fileType); return Task.CompletedTask; - } - catch (Exception e) { throw new Exception(e.Message); } } @@ -2628,9 +2336,6 @@ public Task send_file_message(string chatId, string filePath, Types.upload_File_ public Task send_embed(string chatId, string content = null, string embedId = null, string embedLink = null, string embedTitle = null, string embedContent = null, byte[] embedImage = null) { - try - { - RestClient client = new RestClient(helpers.BaseUrl); RestRequest request = new RestRequest($"/g/s/chat/thread/{chatId}/message"); JObject data = new JObject @@ -2664,10 +2369,6 @@ public Task send_embed(string chatId, string content = null, string embedId = nu if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } if (debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - - - } - catch (Exception e) { throw new Exception(e.Message); } } public Task send_embed(string chatId, string content = null, string embedId = null, string embedLink = null, string embedTitle = null, string embedContent = null, string embedImagePath = null) @@ -2685,8 +2386,6 @@ public Task send_embed(string chatId, string content = null, string embedId = nu /// public Task send_sticker(string chatId, string stickerId) { - try - { JObject data = new JObject(); JObject attachementSub = new JObject(); JObject extensionSub = new JObject(); @@ -2720,9 +2419,6 @@ public Task send_sticker(string chatId, string stickerId) if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } if (debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - - } - catch (Exception e) { throw new Exception(e.Message); } } From 4c91bfa9e800e301e7b0fd4357a14d57f02abca0 Mon Sep 17 00:00:00 2001 From: Fabio Gaming Date: Tue, 9 Apr 2024 23:02:47 +0200 Subject: [PATCH 03/30] Refactored SubClient [ - ] Removed all Try Catch statements that would just repeat exceptions anyways [ # ] Fixed formatting --- Amino.NET/Client.cs | 862 ++++++++++++++++++++--------------------- Amino.NET/SubClient.cs | 287 +------------- 2 files changed, 436 insertions(+), 713 deletions(-) diff --git a/Amino.NET/Client.cs b/Amino.NET/Client.cs index 5f98d89..e4a34e7 100644 --- a/Amino.NET/Client.cs +++ b/Amino.NET/Client.cs @@ -1396,15 +1396,15 @@ public Task flag_community(string communityId, string reason, Types.Flag_Types f { "message", reason }, { "timestamp", helpers.GetTimestamp() * 1000 } }; - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/x{communityId}/s/{_flag}"); - request.AddHeaders(headers); - request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); - request.AddJsonBody(JsonConvert.SerializeObject(data)); - var response = client.ExecutePost(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/x{communityId}/s/{_flag}"); + request.AddHeaders(headers); + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); + request.AddJsonBody(JsonConvert.SerializeObject(data)); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } @@ -1444,17 +1444,17 @@ public string upload_media(byte[] file, Types.upload_File_Types type) _fileType = "image/jpg"; break; } - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest("/g/s/media/upload"); - request.AddHeaders(headers); - request.AddOrUpdateHeader("Content-Type", _fileType); - request.AddHeader("NDC-MSG-SIG", helpers.generate_file_signiture(file)); - request.AddBody(file, _fileType); - var response = client.ExecutePost(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(response.Content); - return jsonObj["mediaValue"]; + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest("/g/s/media/upload"); + request.AddHeaders(headers); + request.AddOrUpdateHeader("Content-Type", _fileType); + request.AddHeader("NDC-MSG-SIG", helpers.generate_file_signiture(file)); + request.AddBody(file, _fileType); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(response.Content); + return jsonObj["mediaValue"]; } /// @@ -1521,15 +1521,15 @@ public Task edit_profile(string nickname = null, string content = null, byte[] i } } - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"g/s/user-profile/{userID}"); - request.AddHeaders(headers); - request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(System.Text.Json.JsonSerializer.Serialize(data.ToString()))); - request.AddJsonBody(JsonConvert.SerializeObject(data)); - var response = client.ExecutePost(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"g/s/user-profile/{userID}"); + request.AddHeaders(headers); + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(System.Text.Json.JsonSerializer.Serialize(data.ToString()))); + request.AddJsonBody(JsonConvert.SerializeObject(data)); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } /// @@ -1549,15 +1549,15 @@ public Task set_privacy_status(bool isAnonymous = false, bool getNotifications = { "notificationStatus", _notificationStatus }, { "privacyMode", _privacyMode } }; - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest("/g/s/account/visit-settings"); - request.AddHeaders(headers); - request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); - request.AddJsonBody(JsonConvert.SerializeObject(data)); - var response = client.ExecutePost(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest("/g/s/account/visit-settings"); + request.AddHeaders(headers); + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); + request.AddJsonBody(JsonConvert.SerializeObject(data)); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } /// @@ -1573,15 +1573,15 @@ public Task set_amino_id(string aminoId) { "timestamp", helpers.GetTimestamp() * 1000 }, { "aminoId", aminoId } }; - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest("/g/s/account/change-amino-id"); - request.AddHeaders(headers); - request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); - request.AddJsonBody(JsonConvert.SerializeObject(data)); - var response = client.ExecutePost(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest("/g/s/account/change-amino-id"); + request.AddHeaders(headers); + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); + request.AddJsonBody(JsonConvert.SerializeObject(data)); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } /// @@ -1592,13 +1592,13 @@ public Task set_amino_id(string aminoId) public Task add_linked_community(int communityId) { if (sessionID == null) { throw new Exception("ErrorCode: 0: Client not logged in"); } - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/g/s/user-profile/{userID}/linked-community/{communityId}"); - request.AddHeaders(headers); - var response = client.ExecutePost(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/g/s/user-profile/{userID}/linked-community/{communityId}"); + request.AddHeaders(headers); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } /// @@ -1609,13 +1609,13 @@ public Task add_linked_community(int communityId) public Task remove_linked_community(int communityId) { if (sessionID == null) { throw new Exception("ErrorCode: 0: Client not logged in"); } - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/g/s/user-profile/{userID}/linked-community/{communityId}"); - request.AddHeaders(headers); - var response = client.Delete(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/g/s/user-profile/{userID}/linked-community/{communityId}"); + request.AddHeaders(headers); + var response = client.Delete(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } /// @@ -1630,46 +1630,46 @@ public Task comment(string message, Types.Comment_Types type, string objectId) if (sessionID == null) { throw new Exception("ErrorCode: 0: Client not logged in"); } string _eventSource; bool _isReply = false; - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest(); - request.AddHeaders(headers); - JObject data = new JObject(); - data.Add("content", message); - data.Add("stickerId", null); - data.Add("type", 0); - data.Add("timestamp", helpers.GetTimestamp() * 1000); + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest(); + request.AddHeaders(headers); + JObject data = new JObject(); + data.Add("content", message); + data.Add("stickerId", null); + data.Add("type", 0); + data.Add("timestamp", helpers.GetTimestamp() * 1000); - switch (type) - { - case Types.Comment_Types.User: - request.Resource = $"/g/s/user-profile/{objectId}/g-comment"; - _eventSource = "UserProfileView"; - break; - case Types.Comment_Types.Blog: - request.Resource = $"/g/s/blog/{objectId}/g-comment"; - _eventSource = "PostDetailView"; - break; - case Types.Comment_Types.Wiki: - request.Resource = $"/g/s/item/{objectId}/g-comment"; - _eventSource = "PostDetailView"; - break; - case Types.Comment_Types.Reply: - _isReply = true; - _eventSource = ""; - break; - default: - request.Resource = $"/g/s/user-profile/{objectId}/g-comment"; - _eventSource = "UserProfileView"; - break; - } - if (!_isReply) { data.Add("eventSource", _eventSource); } else { data.Add("respondTo", objectId); } - request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(System.Text.Json.JsonSerializer.Serialize(data.ToString()))); - request.AddJsonBody(data); - var response = client.ExecutePost(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + switch (type) + { + case Types.Comment_Types.User: + request.Resource = $"/g/s/user-profile/{objectId}/g-comment"; + _eventSource = "UserProfileView"; + break; + case Types.Comment_Types.Blog: + request.Resource = $"/g/s/blog/{objectId}/g-comment"; + _eventSource = "PostDetailView"; + break; + case Types.Comment_Types.Wiki: + request.Resource = $"/g/s/item/{objectId}/g-comment"; + _eventSource = "PostDetailView"; + break; + case Types.Comment_Types.Reply: + _isReply = true; + _eventSource = ""; + break; + default: + request.Resource = $"/g/s/user-profile/{objectId}/g-comment"; + _eventSource = "UserProfileView"; + break; + } + if (!_isReply) { data.Add("eventSource", _eventSource); } else { data.Add("respondTo", objectId); } + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(System.Text.Json.JsonSerializer.Serialize(data.ToString()))); + request.AddJsonBody(data); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } /// @@ -1682,28 +1682,28 @@ public Task comment(string message, Types.Comment_Types type, string objectId) public Task delete_comment(string commentId, Types.Comment_Types type, string objectId) { if (sessionID == null) { throw new Exception("ErrorCode: 0: Client not logged in"); } - RestClient client = new RestClient(); - RestRequest request = new RestRequest(); - switch (type) - { - case Types.Comment_Types.User: - request.Resource = $"/g/s/user-profile/{objectId}/g-comment/{commentId}"; - break; - case Types.Comment_Types.Blog: - request.Resource = $"/g/s/blog/{objectId}/g-comment/{commentId}"; - break; - case Types.Comment_Types.Wiki: - request.Resource = $"/g/s/item/{objectId}/g-comment/{commentId}"; - break; - default: - request.Resource = $"/g/s/user-profile/{objectId}/g-comment/{commentId}"; - break; - } - request.AddHeaders(headers); - var response = client.Delete(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + RestClient client = new RestClient(); + RestRequest request = new RestRequest(); + switch (type) + { + case Types.Comment_Types.User: + request.Resource = $"/g/s/user-profile/{objectId}/g-comment/{commentId}"; + break; + case Types.Comment_Types.Blog: + request.Resource = $"/g/s/blog/{objectId}/g-comment/{commentId}"; + break; + case Types.Comment_Types.Wiki: + request.Resource = $"/g/s/item/{objectId}/g-comment/{commentId}"; + break; + default: + request.Resource = $"/g/s/user-profile/{objectId}/g-comment/{commentId}"; + break; + } + request.AddHeaders(headers); + var response = client.Delete(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } /// @@ -1716,36 +1716,36 @@ public Task like_post(string objectId, Types.Post_Types type) { if (sessionID == null) { throw new Exception("ErrorCode: 0: Client not logged in"); } string _eventSource; - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest(); - switch (type) - { - case Types.Post_Types.Blog: - request.Resource = $"/g/s/blog/{objectId}/g-vote?cv=1.2"; - _eventSource = "UserProfileView"; - break; - case Types.Post_Types.Wiki: - request.Resource = $"/g/s/item/{objectId}/g-vote?cv=1.2"; - _eventSource = "PostDetailView"; - break; - default: - request.Resource = $"/g/s/blog/{objectId}/g-vote?cv=1.2"; - _eventSource = "UserProfileView"; - break; - } + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest(); + switch (type) + { + case Types.Post_Types.Blog: + request.Resource = $"/g/s/blog/{objectId}/g-vote?cv=1.2"; + _eventSource = "UserProfileView"; + break; + case Types.Post_Types.Wiki: + request.Resource = $"/g/s/item/{objectId}/g-vote?cv=1.2"; + _eventSource = "PostDetailView"; + break; + default: + request.Resource = $"/g/s/blog/{objectId}/g-vote?cv=1.2"; + _eventSource = "UserProfileView"; + break; + } JObject data = new JObject() { { "value", 4 }, { "timestamp", helpers.GetTimestamp() * 1000 }, { "eventSource", _eventSource } }; - request.AddHeaders(headers); - request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); - request.AddJsonBody(JsonConvert.SerializeObject(data)); - var response = client.ExecutePost(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + request.AddHeaders(headers); + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); + request.AddJsonBody(JsonConvert.SerializeObject(data)); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } /// @@ -1757,26 +1757,26 @@ public Task like_post(string objectId, Types.Post_Types type) public Task unlike_post(string objectId, Types.Post_Types type) { if (sessionID == null) { throw new Exception("ErrorCode: 0: Client not logged in"); } - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest(); - request.AddHeaders(headers); + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest(); + request.AddHeaders(headers); - switch (type) - { - case Types.Post_Types.Blog: - request.Resource = $"/g/s/blog/{objectId}/g-vote?eventSource=UserProfileView"; - break; - case Types.Post_Types.Wiki: - request.Resource = $"/g/s/item/{objectId}/g-vote?eventSource=PostDetailView"; - break; - default: - request.Resource = $"/g/s/blog/{objectId}/g-vote?eventSource=UserProfileView"; - break; - } - var response = client.Delete(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + switch (type) + { + case Types.Post_Types.Blog: + request.Resource = $"/g/s/blog/{objectId}/g-vote?eventSource=UserProfileView"; + break; + case Types.Post_Types.Wiki: + request.Resource = $"/g/s/item/{objectId}/g-vote?eventSource=PostDetailView"; + break; + default: + request.Resource = $"/g/s/blog/{objectId}/g-vote?eventSource=UserProfileView"; + break; + } + var response = client.Delete(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } /// @@ -1786,14 +1786,14 @@ public Task unlike_post(string objectId, Types.Post_Types type) public Objects.MembershipInfo get_membership_info() { if (sessionID == null) { throw new Exception("ErrorCode: 0: Client not logged in"); } - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest("/g/s/membership?force=true"); - request.AddHeaders(headers); - var response = client.ExecuteGet(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - Objects.MembershipInfo membershipInfo = new Objects.MembershipInfo(JObject.Parse(response.Content)); - return membershipInfo; + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest("/g/s/membership?force=true"); + request.AddHeaders(headers); + var response = client.ExecuteGet(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + Objects.MembershipInfo membershipInfo = new Objects.MembershipInfo(JObject.Parse(response.Content)); + return membershipInfo; } /// @@ -1834,21 +1834,21 @@ public Objects.MembershipInfo get_membership_info() _language = "en"; break; } - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/g/s/announcement?language={_language}&start={start}&size={size}"); - request.AddHeaders(headers); - var response = client.ExecuteGet(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(response.Content); - JArray announcements = jsonObj["blogList"]; - List ta_announcements = new List(); - foreach (JObject post in announcements) - { - Objects.Post _post = new Objects.Post(post); - ta_announcements.Add(_post); - } - return ta_announcements; + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/g/s/announcement?language={_language}&start={start}&size={size}"); + request.AddHeaders(headers); + var response = client.ExecuteGet(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(response.Content); + JArray announcements = jsonObj["blogList"]; + List ta_announcements = new List(); + foreach (JObject post in announcements) + { + Objects.Post _post = new Objects.Post(post); + ta_announcements.Add(_post); + } + return ta_announcements; } /// @@ -1858,15 +1858,15 @@ public Objects.MembershipInfo get_membership_info() public Objects.WalletInfo get_wallet_info() { if (sessionID == null) { throw new Exception("ErrorCode: 0: Client not logged in"); } - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest("/g/s/wallet"); - request.AddHeaders(headers); - var response = client.ExecuteGet(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - JObject jsonObj = JObject.Parse(response.Content); - Objects.WalletInfo _walletInfo = new Objects.WalletInfo(jsonObj); - return _walletInfo; + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest("/g/s/wallet"); + request.AddHeaders(headers); + var response = client.ExecuteGet(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + JObject jsonObj = JObject.Parse(response.Content); + Objects.WalletInfo _walletInfo = new Objects.WalletInfo(jsonObj); + return _walletInfo; } /// @@ -1879,21 +1879,21 @@ public Objects.WalletInfo get_wallet_info() { if (sessionID == null) { throw new Exception("ErrorCode: 0: Client not logged in"); } if (start < 0) { throw new Exception("start cannot be lower than 0"); } - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/g/s/wallet/coin/history?start={start}&size={size}"); - request.AddHeaders(headers); - var response = client.ExecuteGet(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(response.Content); - JArray historyEntry = jsonObj["coinHistoryList"]; - List coinHistoryList = new List(); - foreach (JObject entry in historyEntry) - { - Objects.CoinHistoryEntry _entry = new Objects.CoinHistoryEntry(entry); - coinHistoryList.Add(_entry); - } - return coinHistoryList; + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/g/s/wallet/coin/history?start={start}&size={size}"); + request.AddHeaders(headers); + var response = client.ExecuteGet(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(response.Content); + JArray historyEntry = jsonObj["coinHistoryList"]; + List coinHistoryList = new List(); + foreach (JObject entry in historyEntry) + { + Objects.CoinHistoryEntry _entry = new Objects.CoinHistoryEntry(entry); + coinHistoryList.Add(_entry); + } + return coinHistoryList; } /// @@ -1903,15 +1903,15 @@ public Objects.WalletInfo get_wallet_info() /// string : the target users ID public string get_from_deviceId(string deviceId) { - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/g/s/auid?deviceId={deviceId}"); - request.AddHeaders(headers); - var response = client.ExecuteGet(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - Console.WriteLine(response.Content); - dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(response.Content); - return jsonObj["auid"]; + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/g/s/auid?deviceId={deviceId}"); + request.AddHeaders(headers); + var response = client.ExecuteGet(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + Console.WriteLine(response.Content); + dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(response.Content); + return jsonObj["auid"]; } /// @@ -1921,15 +1921,15 @@ public string get_from_deviceId(string deviceId) /// Object : Amino.Objects.FromCode public Objects.FromCode get_from_code(string aminoUrl) { - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/g/s/link-resolution?q={aminoUrl}"); - request.AddHeaders(headers); - var response = client.ExecuteGet(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(response.Content); - Amino.Objects.FromCode fromCode = new Objects.FromCode(jsonObj); - return fromCode; + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/g/s/link-resolution?q={aminoUrl}"); + request.AddHeaders(headers); + var response = client.ExecuteGet(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(response.Content); + Amino.Objects.FromCode fromCode = new Objects.FromCode(jsonObj); + return fromCode; } /// @@ -1949,22 +1949,22 @@ public Objects.FromId get_from_id(string objectId, Amino.Types.Object_Types type { "timestamp", helpers.GetTimestamp() * 1000 }, { "objectType", (int)type } }; - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest(); - if (communityId != null) - { - request.Resource = $"/g/s-x{communityId}/link-resolution"; - } - else { request.Resource = $"/g/s/link-resolution"; } - request.AddHeaders(headers); - request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); - request.AddJsonBody(JsonConvert.SerializeObject(data)); - var response = client.ExecutePost(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(response.Content); - Amino.Objects.FromId fromId = new Objects.FromId(jsonObj); - return fromId; + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest(); + if (communityId != null) + { + request.Resource = $"/g/s-x{communityId}/link-resolution"; + } + else { request.Resource = $"/g/s/link-resolution"; } + request.AddHeaders(headers); + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); + request.AddJsonBody(JsonConvert.SerializeObject(data)); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(response.Content); + Amino.Objects.FromId fromId = new Objects.FromId(jsonObj); + return fromId; } /// @@ -1973,21 +1973,21 @@ public Objects.FromId get_from_id(string objectId, Amino.Types.Object_Types type /// string[] : language keys public string[] get_supported_languages() { - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest("/g/s/community-collection/supported-languages?start=0&size=100"); - request.AddHeaders(headers); - var response = client.ExecuteGet(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - Console.WriteLine(response.Content); - dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(response.Content); - JArray languageArray = jsonObj["supportedLanguages"]; - List langList = new List(); - foreach (JObject language in languageArray) - { - langList.Add(language.ToString()); - } - return langList.ToArray(); + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest("/g/s/community-collection/supported-languages?start=0&size=100"); + request.AddHeaders(headers); + var response = client.ExecuteGet(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + Console.WriteLine(response.Content); + dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(response.Content); + JArray languageArray = jsonObj["supportedLanguages"]; + List langList = new List(); + foreach (JObject language in languageArray) + { + langList.Add(language.ToString()); + } + return langList.ToArray(); } /// @@ -1997,13 +1997,13 @@ public string[] get_supported_languages() public Task claim_new_user_coupon() { if (sessionID == null) { throw new Exception("ErrorCode: 0: Client not logged in"); } - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest("/g/s/coupon/new-user-coupon/claim"); - request.AddHeaders(headers); - var response = client.ExecutePost(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest("/g/s/coupon/new-user-coupon/claim"); + request.AddHeaders(headers); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } @@ -2016,21 +2016,21 @@ public Task claim_new_user_coupon() public List get_all_users(int start = 0, int size = 25) { if (start < 0) { throw new Exception("start cannot be lower than 0"); } - List userList = new List(); - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/g/s/user-profile?type=recent&start={start}&size={size}"); - request.AddHeaders(headers); - var response = client.ExecuteGet(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(response.Content); - JArray userArray = jsonObj["userProfileList"]; - foreach (JObject user in userArray) - { - Objects.UserProfile _user = new Objects.UserProfile(user); - userList.Add(_user); - } - return userList; + List userList = new List(); + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/g/s/user-profile?type=recent&start={start}&size={size}"); + request.AddHeaders(headers); + var response = client.ExecuteGet(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(response.Content); + JArray userArray = jsonObj["userProfileList"]; + foreach (JObject user in userArray) + { + Objects.UserProfile _user = new Objects.UserProfile(user); + userList.Add(_user); + } + return userList; } /// @@ -2041,15 +2041,15 @@ public Task claim_new_user_coupon() /// public Objects.AdvancedCommunityInfo get_community_info(string communityId) { - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/g/s-x{communityId}/community/info?withInfluencerList=1&withTopicList=true&influencerListOrderStrategy=fansCount"); - request.AddHeaders(headers); - var response = client.ExecuteGet(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(response.Content); - Objects.AdvancedCommunityInfo community = new Objects.AdvancedCommunityInfo(jsonObj); - return community; + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/g/s-x{communityId}/community/info?withInfluencerList=1&withTopicList=true&influencerListOrderStrategy=fansCount"); + request.AddHeaders(headers); + var response = client.ExecuteGet(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(response.Content); + Objects.AdvancedCommunityInfo community = new Objects.AdvancedCommunityInfo(jsonObj); + return community; } /// @@ -2072,16 +2072,16 @@ public Objects.AdvancedCommunityInfo get_community_info(int communityId) public Task accept_host(string chatId, string requestId) { if (sessionID == null) { throw new Exception("ErrorCode: 0: Client not logged in"); } - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/g/s/chat/thread/{chatId}/transfer-organizer/{requestId}/accept"); - request.AddHeaders(headers); - var data = new { }; - request.AddJsonBody(data); - request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(System.Text.Json.JsonSerializer.Serialize(data))); - var response = client.ExecutePost(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/g/s/chat/thread/{chatId}/transfer-organizer/{requestId}/accept"); + request.AddHeaders(headers); + var data = new { }; + request.AddJsonBody(data); + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(System.Text.Json.JsonSerializer.Serialize(data))); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } @@ -2105,15 +2105,15 @@ public Task accept_organizer(string chatId, string requestId) /// Object : Amino.Objects.FromInvite public Amino.Objects.FromInvite link_identify(string inviteCode) { - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/g/s/community/link-identify?q=http%3A%2F%2Faminoapps.com%2Finvite%2F{inviteCode}"); - request.AddHeaders(headers); - var response = client.ExecuteGet(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - JObject json = JObject.Parse(response.Content); - Objects.FromInvite fromInvite = new Objects.FromInvite(json); - return fromInvite; + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/g/s/community/link-identify?q=http%3A%2F%2Faminoapps.com%2Finvite%2F{inviteCode}"); + request.AddHeaders(headers); + var response = client.ExecuteGet(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + JObject json = JObject.Parse(response.Content); + Objects.FromInvite fromInvite = new Objects.FromInvite(json); + return fromInvite; } /// @@ -2124,20 +2124,20 @@ public Amino.Objects.FromInvite link_identify(string inviteCode) public Task wallet_config(Types.Wallet_Config_Levels walletLevel) { if (sessionID == null) { throw new Exception("ErrorCode: 0: Client not logged in"); } - JObject data = new JObject() + JObject data = new JObject() { { "adsLevel", (int)walletLevel }, { "timestamp", helpers.GetTimestamp() * 1000 } }; - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest("/g/s/wallet/ads/config"); - request.AddHeaders(headers); - request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); - request.AddJsonBody(JsonConvert.SerializeObject(data)); - var response = client.ExecutePost(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest("/g/s/wallet/ads/config"); + request.AddHeaders(headers); + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); + request.AddJsonBody(JsonConvert.SerializeObject(data)); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } /// @@ -2150,21 +2150,21 @@ public Task wallet_config(Types.Wallet_Config_Levels walletLevel) { if (sessionID == null) { throw new Exception("ErrorCode: 0: Client not logged in"); } if (start < 0) { throw new Exception("start cannot be lower than 0"); } - List _avataFrameList = new List(); - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/g/s/avatar-frame?start={start}&size={size}"); - request.AddHeaders(headers); - var response = client.ExecuteGet(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(response.Content); - JArray avatarFrameArrray = jsonObj["avatarFrameList"]; - foreach (JObject avatarFrame in avatarFrameArrray) - { - Objects.AvatarFrame _avatarFrame = new Objects.AvatarFrame(avatarFrame); - _avataFrameList.Add(_avatarFrame); - } - return _avataFrameList; + List _avataFrameList = new List(); + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/g/s/avatar-frame?start={start}&size={size}"); + request.AddHeaders(headers); + var response = client.ExecuteGet(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(response.Content); + JArray avatarFrameArrray = jsonObj["avatarFrameList"]; + foreach (JObject avatarFrame in avatarFrameArrray) + { + Objects.AvatarFrame _avatarFrame = new Objects.AvatarFrame(avatarFrame); + _avataFrameList.Add(_avatarFrame); + } + return _avataFrameList; } /// @@ -2176,23 +2176,23 @@ public Task wallet_config(Types.Wallet_Config_Levels walletLevel) /// public Task invite_to_vc(string chatId, string userId) { - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/g/s/chat/thread/{chatId}/vvchat-presenter/invite"); + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/g/s/chat/thread/{chatId}/vvchat-presenter/invite"); - JObject data = new JObject() + JObject data = new JObject() { { "uid", userId }, { "timestamp", helpers.GetTimestamp() * 1000 } }; - request.AddHeaders(headers); - request.AddJsonBody(JsonConvert.SerializeObject(data)); - request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); + request.AddHeaders(headers); + request.AddJsonBody(JsonConvert.SerializeObject(data)); + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); - var response = client.ExecutePost(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } /// @@ -2207,51 +2207,51 @@ public Task invite_to_vc(string chatId, string userId) /// public Objects.Message send_message(string message, string chatId, Types.Message_Types messageType = Types.Message_Types.General, string replyTo = null, List mentionUserIds = null) { - List mentions = new List(); - if (mentionUserIds == null) { mentionUserIds = new List(); } - else + List mentions = new List(); + if (mentionUserIds == null) { mentionUserIds = new List(); } + else + { + foreach (string user in mentionUserIds) { - foreach (string user in mentionUserIds) - { - JObject _mention = new JObject(); - _mention.Add("uid", user); - mentions.Add(_mention); - } + JObject _mention = new JObject(); + _mention.Add("uid", user); + mentions.Add(_mention); } - message = message.Replace("<$", "").Replace("$>", ""); - JObject data = new JObject(); - JObject attachementSub = new JObject(); - JObject extensionSub = new JObject(); - JObject extensionSuBArray = new JObject(); - data.Add("type", (int)messageType); - data.Add("content", message); - data.Add("clientRefId", helpers.GetTimestamp() / 10 % 1000000000); - data.Add("timestamp", helpers.GetTimestamp() * 1000); - attachementSub.Add("objectId", null); - attachementSub.Add("objectType", null); - attachementSub.Add("link", null); - attachementSub.Add("title", null); - attachementSub.Add("content", null); - attachementSub.Add("mediaList", null); - extensionSuBArray.Add("link", null); - extensionSuBArray.Add("mediaType", 100); - extensionSuBArray.Add("mediaUploadValue", null); - extensionSuBArray.Add("mediaUploadValueContentType", "image/jpg"); - extensionSub.Add("mentionedArray", new JArray(mentions)); - extensionSub.Add("linkSnippetList", new JArray(extensionSuBArray)); - data.Add("attachedObject", attachementSub); - data.Add("extensions", extensionSub); - if (replyTo != null) { data.Add("replyMessageId", replyTo); } + } + message = message.Replace("<$", "").Replace("$>", ""); + JObject data = new JObject(); + JObject attachementSub = new JObject(); + JObject extensionSub = new JObject(); + JObject extensionSuBArray = new JObject(); + data.Add("type", (int)messageType); + data.Add("content", message); + data.Add("clientRefId", helpers.GetTimestamp() / 10 % 1000000000); + data.Add("timestamp", helpers.GetTimestamp() * 1000); + attachementSub.Add("objectId", null); + attachementSub.Add("objectType", null); + attachementSub.Add("link", null); + attachementSub.Add("title", null); + attachementSub.Add("content", null); + attachementSub.Add("mediaList", null); + extensionSuBArray.Add("link", null); + extensionSuBArray.Add("mediaType", 100); + extensionSuBArray.Add("mediaUploadValue", null); + extensionSuBArray.Add("mediaUploadValueContentType", "image/jpg"); + extensionSub.Add("mentionedArray", new JArray(mentions)); + extensionSub.Add("linkSnippetList", new JArray(extensionSuBArray)); + data.Add("attachedObject", attachementSub); + data.Add("extensions", extensionSub); + if (replyTo != null) { data.Add("replyMessageId", replyTo); } - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/g/s/chat/thread/{chatId}/message"); - request.AddHeaders(headers); - request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); - request.AddJsonBody(JsonConvert.SerializeObject(data)); - var response = client.ExecutePost(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return new Objects.Message(JObject.Parse(response.Content)); + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/g/s/chat/thread/{chatId}/message"); + request.AddHeaders(headers); + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); + request.AddJsonBody(JsonConvert.SerializeObject(data)); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return new Objects.Message(JObject.Parse(response.Content)); } /// @@ -2327,8 +2327,8 @@ public Task send_file_message(string chatId, byte[] file, Types.upload_File_Type /// public Task send_file_message(string chatId, string filePath, Types.upload_File_Types fileType) { - send_file_message(chatId, File.ReadAllBytes(filePath), fileType); - return Task.CompletedTask; + send_file_message(chatId, File.ReadAllBytes(filePath), fileType); + return Task.CompletedTask; } @@ -2336,9 +2336,9 @@ public Task send_file_message(string chatId, string filePath, Types.upload_File_ public Task send_embed(string chatId, string content = null, string embedId = null, string embedLink = null, string embedTitle = null, string embedContent = null, byte[] embedImage = null) { - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/g/s/chat/thread/{chatId}/message"); - JObject data = new JObject + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/g/s/chat/thread/{chatId}/message"); + JObject data = new JObject { { "type", 0 }, { "content", content }, @@ -2362,13 +2362,13 @@ public Task send_embed(string chatId, string content = null, string embedId = nu }; - request.AddHeaders(headers); - request.AddJsonBody(JsonConvert.SerializeObject(data)); - request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); - var response = client.ExecutePost(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + request.AddHeaders(headers); + request.AddJsonBody(JsonConvert.SerializeObject(data)); + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } public Task send_embed(string chatId, string content = null, string embedId = null, string embedLink = null, string embedTitle = null, string embedContent = null, string embedImagePath = null) @@ -2386,39 +2386,39 @@ public Task send_embed(string chatId, string content = null, string embedId = nu /// public Task send_sticker(string chatId, string stickerId) { - JObject data = new JObject(); - JObject attachementSub = new JObject(); - JObject extensionSub = new JObject(); - JObject extensionSuBArray = new JObject(); - data.Add("type", 3); - data.Add("content", null); - data.Add("clientRefId", helpers.GetTimestamp() / 10 % 1000000000); - data.Add("timestamp", helpers.GetTimestamp() * 1000); - attachementSub.Add("objectId", null); - attachementSub.Add("objectType", null); - attachementSub.Add("link", null); - attachementSub.Add("title", null); - attachementSub.Add("content", null); - attachementSub.Add("mediaList", null); - extensionSuBArray.Add("link", null); - extensionSuBArray.Add("mediaType", 100); - extensionSuBArray.Add("mediaUploadValue", null); - extensionSuBArray.Add("mediaUploadValueContentType", "image/jpg"); - extensionSub.Add("mentionedArray", new JArray()); - extensionSub.Add("linkSnippetList", new JArray(extensionSuBArray)); - data.Add("attachedObject", attachementSub); - data.Add("extensions", extensionSub); - data.Add("stickerId", stickerId); + JObject data = new JObject(); + JObject attachementSub = new JObject(); + JObject extensionSub = new JObject(); + JObject extensionSuBArray = new JObject(); + data.Add("type", 3); + data.Add("content", null); + data.Add("clientRefId", helpers.GetTimestamp() / 10 % 1000000000); + data.Add("timestamp", helpers.GetTimestamp() * 1000); + attachementSub.Add("objectId", null); + attachementSub.Add("objectType", null); + attachementSub.Add("link", null); + attachementSub.Add("title", null); + attachementSub.Add("content", null); + attachementSub.Add("mediaList", null); + extensionSuBArray.Add("link", null); + extensionSuBArray.Add("mediaType", 100); + extensionSuBArray.Add("mediaUploadValue", null); + extensionSuBArray.Add("mediaUploadValueContentType", "image/jpg"); + extensionSub.Add("mentionedArray", new JArray()); + extensionSub.Add("linkSnippetList", new JArray(extensionSuBArray)); + data.Add("attachedObject", attachementSub); + data.Add("extensions", extensionSub); + data.Add("stickerId", stickerId); - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/g/s/chat/thread/{chatId}/message"); - request.AddHeaders(headers); - request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); - request.AddJsonBody(JsonConvert.SerializeObject(data)); - var response = client.ExecutePost(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/g/s/chat/thread/{chatId}/message"); + request.AddHeaders(headers); + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); + request.AddJsonBody(JsonConvert.SerializeObject(data)); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } diff --git a/Amino.NET/SubClient.cs b/Amino.NET/SubClient.cs index b156043..3048bc2 100644 --- a/Amino.NET/SubClient.cs +++ b/Amino.NET/SubClient.cs @@ -80,8 +80,6 @@ public SubClient(Amino.Client _client, int _communityId) /// public List get_invite_codes(string status = "normal", int start = 0, int size = 25) { - try - { List inviteCodeList = new List(); RestClient client = new RestClient(helpers.BaseUrl); RestRequest request = new RestRequest($"/g/s-x{communityId}/community/invitation?status={status}&start={start}&size={size}"); @@ -99,8 +97,6 @@ public SubClient(Amino.Client _client, int _communityId) Console.WriteLine(response.Content); return inviteCodeList; - } catch(Exception e) { throw new Exception(e.Message); } - } /// @@ -111,8 +107,6 @@ public SubClient(Amino.Client _client, int _communityId) /// public Task generate_invite_code(int duration = 0, bool force = true) { - try - { RestClient client = new RestClient(helpers.BaseUrl); RestRequest request = new RestRequest($"/g/s-x{communityId}/community/invitation"); request.AddHeaders(headers); @@ -126,10 +120,6 @@ public Task generate_invite_code(int duration = 0, bool force = true) if((int)response.StatusCode != 200) { throw new Exception(response.Content); } if(debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - }catch(Exception e) - { - throw new Exception(e.Message); - } } /// @@ -139,8 +129,6 @@ public Task generate_invite_code(int duration = 0, bool force = true) /// public Task delete_invite_code(string inviteId) { - try - { RestClient client = new RestClient(helpers.BaseUrl); RestRequest request = new RestRequest($"/g/s-x{communityId}/community/invitation/{inviteId}"); request.AddHeaders(headers); @@ -148,7 +136,6 @@ public Task delete_invite_code(string inviteId) if((int)response.StatusCode != 200) { throw new Exception(response.Content); } if(debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - }catch(Exception e) { throw new Exception(e.Message); } } /// @@ -162,8 +149,6 @@ public Task delete_invite_code(string inviteId) /// public Task post_blog(string title, string content, List imageList = null, bool fansOnly = false, string backgroundColor = null) { - try - { JArray mediaList = new JArray(); JObject extensionData = new JObject(); @@ -204,10 +189,6 @@ public Task post_blog(string title, string content, List imageList = nul if(debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - }catch(Exception e) - { - throw new Exception(e.Message); - } } /// @@ -221,8 +202,6 @@ public Task post_blog(string title, string content, List imageList = nul /// public Task post_wiki(string title, string content, List imageList = null, bool fansOnly = false, string backgroundColor = null) { - try - { JArray mediaList = new JArray(); JObject extensionData = new JObject(); @@ -258,8 +237,6 @@ public Task post_wiki(string title, string content, List imageList = nul if((int)response.StatusCode != 200) { throw new Exception(response.Content); } if(debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - - } catch(Exception e) { throw new Exception(e.Message); } } /// @@ -274,8 +251,6 @@ public Task post_wiki(string title, string content, List imageList = nul /// public Task edit_blog(string blogId, string title = null, string content = null, List imageList = null, bool fansOnly = false, string backgroundColor = null) { - try - { JArray mediaList = new JArray(); JObject extensionData = new JObject(); @@ -316,11 +291,6 @@ public Task edit_blog(string blogId, string title = null, string content = null, if (debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - } - catch (Exception e) - { - throw new Exception(e.Message); - } } /// @@ -330,8 +300,6 @@ public Task edit_blog(string blogId, string title = null, string content = null, /// public Task delete_blog(string blogId) { - try - { RestClient client = new RestClient(helpers.BaseUrl); RestRequest request = new RestRequest($"/x{communityId}/s/blog/{blogId}"); request.AddHeaders(headers); @@ -339,7 +307,6 @@ public Task delete_blog(string blogId) if((int)response.StatusCode != 200) { throw new Exception(response.Content); } if(debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - } catch(Exception e) { throw new Exception(e.Message); } } /// @@ -349,8 +316,6 @@ public Task delete_blog(string blogId) /// public Task delete_wiki(string wikiId) { - try - { RestClient client = new RestClient(helpers.BaseUrl); RestRequest request = new RestRequest($"/x{communityId}/s/item/{wikiId}"); request.AddHeaders(headers); @@ -358,7 +323,6 @@ public Task delete_wiki(string wikiId) if((int)response.StatusCode != 200) { throw new Exception(response.Content); } if(debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - } catch(Exception e) { throw new Exception(e.Message); } } /// @@ -370,8 +334,6 @@ public Task delete_wiki(string wikiId) /// public Task repost_blog(string postId, Types.Repost_Types type, string content = null) { - try - { RestClient client = new RestClient(helpers.BaseUrl); RestRequest request = new RestRequest($"/x{communityId}/s/blog"); request.AddHeaders(headers); @@ -387,8 +349,6 @@ public Task repost_blog(string postId, Types.Repost_Types type, string content = if((int)response.StatusCode != 200) { throw new Exception(response.Content); } if(debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - - }catch(Exception e) { throw new Exception(e.Message); } } /// @@ -398,8 +358,6 @@ public Task repost_blog(string postId, Types.Repost_Types type, string content = /// public Task check_in(int? timezone = null) { - try - { int? tz; if (timezone != null) { tz = timezone; } else { tz = helpers.getTimezone(); } RestClient client = new RestClient(helpers.BaseUrl); @@ -414,7 +372,6 @@ public Task check_in(int? timezone = null) if((int)response.StatusCode != 200) { throw new Exception(response.Content); } if(debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - }catch(Exception e) { throw new Exception(e.Message); } } /// @@ -424,8 +381,6 @@ public Task check_in(int? timezone = null) /// public Task repair_check_in(Types.Repair_Types repairType) { - try - { RestClient client = new RestClient(helpers.BaseUrl); RestRequest request = new RestRequest($"/x{communityId}/s/check-in/repair"); request.AddHeaders(headers); @@ -438,7 +393,6 @@ public Task repair_check_in(Types.Repair_Types repairType) if((int)response.StatusCode != 200) { throw new Exception(response.Content); } if(debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - }catch(Exception e) { throw new Exception(e.Message); } } /// @@ -448,8 +402,6 @@ public Task repair_check_in(Types.Repair_Types repairType) /// public Task lottery(int? timezone = null) { - try - { int? tz; if (timezone != null) { tz = timezone; } else { tz = helpers.getTimezone(); } RestClient client = new RestClient(helpers.BaseUrl); @@ -464,8 +416,6 @@ public Task lottery(int? timezone = null) if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } if (debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - } - catch (Exception e) { throw new Exception(e.Message); } } /// @@ -482,8 +432,6 @@ public Task lottery(int? timezone = null) /// public Task edit_profile(string nickname = null, string content = null, byte[] icon = null, List imageList = null, List captionList = null, string backgroundColor = null, byte[] backgroundImage = null, string defaultChatBubbleId = null) { - try - { JObject data = new JObject(); JArray mediaList = new JArray(); @@ -521,8 +469,6 @@ public Task edit_profile(string nickname = null, string content = null, byte[] i if ((int)response.StatusCode != 200) throw new Exception(response.Content); if(debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - } - catch(Exception e) { throw new Exception(e.Message); } } /// @@ -533,8 +479,6 @@ public Task edit_profile(string nickname = null, string content = null, byte[] i /// public Task vote_poll(string postId, string optionId) { - try - { RestClient client = new RestClient(helpers.BaseUrl); RestRequest request = new RestRequest($"/x{communityId}/s/blog/{postId}/poll/option/{optionId}/vote"); JObject data = new JObject(); @@ -548,7 +492,6 @@ public Task vote_poll(string postId, string optionId) if((int)response.StatusCode != 200) { throw new Exception(response.Content); } if(debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - }catch(Exception e) { throw new Exception(e.Message); } } /// @@ -561,8 +504,6 @@ public Task vote_poll(string postId, string optionId) /// public Task comment(string message, Amino.Types.Comment_Types type, string targetId, bool isGuest = false) { - try - { string endPoint = null; JObject data = new JObject(); data.Add("content", message); @@ -599,8 +540,6 @@ public Task comment(string message, Amino.Types.Comment_Types type, string targe if((int)response.StatusCode != 200) { throw new Exception(response.Content); } if(debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - } - catch(Exception e) { throw new Exception(e.Message); } } /// @@ -612,8 +551,6 @@ public Task comment(string message, Amino.Types.Comment_Types type, string targe /// public Task delete_comment(string commentId, Amino.Types.Comment_Types type, string targetId) { - try - { string endPoint = null; switch(type) { @@ -638,7 +575,6 @@ public Task delete_comment(string commentId, Amino.Types.Comment_Types type, str if((int)response.StatusCode != 200) { throw new Exception(response.Content); } if(debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - }catch(Exception e) { throw new Exception(e.Message); } } /// @@ -649,8 +585,6 @@ public Task delete_comment(string commentId, Amino.Types.Comment_Types type, str /// public Task like_post(string postId, bool isWiki = false) { - try - { string endPoint = null; JObject data = new JObject(); @@ -667,8 +601,7 @@ public Task like_post(string postId, bool isWiki = false) if((int)response.StatusCode != 200) { throw new Exception(response.Content); } if(debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - } - catch(Exception e) { throw new Exception(e.Message); } + } /// @@ -679,8 +612,6 @@ public Task like_post(string postId, bool isWiki = false) /// public Task unlike_post(string postId, bool isWiki = false) { - try - { string endPoint = null; if(!isWiki) { endPoint = $"/x{communityId}/s/blog/{postId}/vote?eventSource=UserProfileView"; } else { endPoint = $"/x{communityId}/s/item/{postId}/vote?eventSource=PostDetailView"; } RestClient client = new RestClient(helpers.BaseUrl); @@ -690,7 +621,6 @@ public Task unlike_post(string postId, bool isWiki = false) if((int)response.StatusCode != 200) { throw new Exception(response.Content); } if(debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - }catch(Exception e) { throw new Exception(e.Message); } } /// @@ -702,8 +632,6 @@ public Task unlike_post(string postId, bool isWiki = false) /// public Task like_comment(string commentId, string targetId,Types.Comment_Types targetType) { - try - { string _targetType = null; string voteType = null; string targetValue = null; @@ -723,8 +651,6 @@ public Task like_comment(string commentId, string targetId,Types.Comment_Types t if((int)response.StatusCode != 200) { throw new Exception(response.Content); } if(debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - - }catch(Exception e) { throw new Exception(e.Message); } } @@ -737,8 +663,6 @@ public Task like_comment(string commentId, string targetId,Types.Comment_Types t /// public Task unlike_comment(string commentId, string targetId, Amino.Types.Comment_Types targetType) { - try - { string _targetType = null; string _eventSource = "PostDetailView"; if (targetType == Types.Comment_Types.User) { _targetType = "user-profile"; _eventSource = "UserProfileView"; } else if (targetType == Types.Comment_Types.Wiki) { _targetType = "item"; } else { _targetType = "blog"; } @@ -752,7 +676,6 @@ public Task unlike_comment(string commentId, string targetId, Amino.Types.Commen if((int)response.StatusCode != 200) { throw new Exception(response.Content); } if(debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - }catch(Exception e) { throw new Exception(e.Message); } } /// @@ -763,8 +686,6 @@ public Task unlike_comment(string commentId, string targetId, Amino.Types.Commen /// public Task upvote_comment(string commentId, string postId) { - try - { JObject data = new JObject(); data.Add("value", 1); data.Add("eventSource", "PostDetailView"); @@ -779,7 +700,6 @@ public Task upvote_comment(string commentId, string postId) if((int)response.StatusCode != 200) { throw new Exception(response.Content); } if (debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - }catch(Exception e) { throw new Exception(e.Message); } } /// @@ -790,8 +710,6 @@ public Task upvote_comment(string commentId, string postId) /// public Task downvote_comment(string commentId, string postId) { - try - { JObject data = new JObject(); data.Add("value", -1); data.Add("eventSource", "PostDetailView"); @@ -806,8 +724,6 @@ public Task downvote_comment(string commentId, string postId) if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } if (debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - } - catch (Exception e) { throw new Exception(e.Message); } } /// @@ -818,15 +734,12 @@ public Task downvote_comment(string commentId, string postId) /// public Task unvote_comment(string commentId, string postId) { - try - { RestClient client = new RestClient(helpers.BaseUrl); RestRequest request = new RestRequest($"/x{communityId}/s/blog/{postId}/comment/{commentId}/vote?eventSource=PostDetailView"); var response = client.Delete(request); if((int)response.StatusCode != 200) { throw new Exception(response.Content); } if (debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - }catch(Exception e) { throw new Exception(e.Message); } } /// @@ -838,8 +751,6 @@ public Task unvote_comment(string commentId, string postId) /// public Task reply_wall(string userId, string commentId, string message) { - try - { JObject data = new JObject(); data.Add("content", message); data.Add("stackId", null); @@ -857,8 +768,6 @@ public Task reply_wall(string userId, string commentId, string message) if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } if (debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - }catch(Exception e) { throw new Exception(e.Message); } - } /// @@ -868,8 +777,6 @@ public Task reply_wall(string userId, string commentId, string message) /// public Task set_activity_status(Types.Activity_Status_Types status) { - try - { JObject data = new JObject(); if (status == Types.Activity_Status_Types.On) { data.Add("onlineStatus", "on"); } else { data.Add("onlineStatus", "off"); } data.Add("duration", 86400); @@ -884,8 +791,6 @@ public Task set_activity_status(Types.Activity_Status_Types status) if((int)response.StatusCode != 200) { throw new Exception(response.Content); } if (debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - } - catch(Exception e) { throw new Exception(e.Message); } } /// @@ -894,8 +799,6 @@ public Task set_activity_status(Types.Activity_Status_Types status) /// public Task check_notification() { - try - { RestClient client = new RestClient(helpers.BaseUrl); RestRequest request = new RestRequest($"/x{communityId}/s/notification/checked"); request.AddHeaders(headers); @@ -903,7 +806,6 @@ public Task check_notification() if((int)response.StatusCode != 200) { throw new Exception(response.Content); } if(debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - }catch(Exception e) { throw new Exception(e.Message); } } /// @@ -913,8 +815,6 @@ public Task check_notification() /// public Task delete_notification(string notificationId) { - try - { RestClient client = new RestClient(helpers.BaseUrl); RestRequest request = new RestRequest($"/x{communityId}/s/notification/{notificationId}"); request.AddHeaders(headers); @@ -922,7 +822,6 @@ public Task delete_notification(string notificationId) if((int)response.StatusCode != 200) { throw new Exception(response.Content); } if(debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - }catch(Exception e) { throw new Exception(e.Message); } } /// @@ -931,8 +830,6 @@ public Task delete_notification(string notificationId) /// public Task clear_notifications() { - try - { RestClient client = new RestClient(helpers.BaseUrl); RestRequest request = new RestRequest($"/x{communityId}/s/notification"); request.AddHeaders(headers); @@ -940,7 +837,6 @@ public Task clear_notifications() if((int)response.StatusCode != 200) { throw new Exception(response.Content); } if(debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - }catch(Exception e) { throw new Exception(e.Message); } } /// @@ -949,8 +845,6 @@ public Task clear_notifications() /// public Task send_activity_time() { - try - { JObject data = new JObject(); JArray timeData = new JArray(); @@ -980,8 +874,7 @@ public Task send_activity_time() if (debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - } - catch(Exception e) { throw new Exception(e.Message); } + } @@ -997,8 +890,6 @@ public Task send_activity_time() /// public Task start_chat(List userIds, string message, string title = null, string content = null, bool isGlobal = false, bool publishToGlobal = false) { - try - { JObject data = new JObject(); data.Add("title", title); data.Add("inviteeUids", new JArray(userIds)); @@ -1017,8 +908,6 @@ public Task start_chat(List userIds, string message, string title = null if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } if (debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - } - catch(Exception e) { throw new Exception(e.Message); } } /// @@ -1045,8 +934,6 @@ public Task start_chat(string userId, string message, string title = null, strin /// public Task invite_to_chat(List userIds, string chatId) { - try - { JObject data = new JObject(); data.Add("uids", new JArray(userIds)); data.Add("timestamp", helpers.GetTimestamp() * 1000); @@ -1060,9 +947,6 @@ public Task invite_to_chat(List userIds, string chatId) if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } if (debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - - } - catch(Exception e) { throw new Exception(e.Message); } } /// @@ -1084,8 +968,6 @@ public Task invite_to_chat(string userId, string chatId) /// public Task add_to_favorites(string userId) { - try - { RestClient client = new RestClient(helpers.BaseUrl); RestRequest request = new RestRequest($"/x{communityId}/s/user-group/quick-access/{userId}"); request.AddHeaders(headers); @@ -1093,9 +975,6 @@ public Task add_to_favorites(string userId) if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } if (debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - - } - catch(Exception e) { throw new Exception(e.Message); } } /// @@ -1111,8 +990,6 @@ public Task send_coins(string targetId, int coins,Types.Send_Coin_Targets type, { if(transactionId == null) { transactionId = helpers.generate_transaction_id(); } string endpoint = ""; - try - { JObject data = new JObject(); JObject sub = new JObject(); switch(type) @@ -1143,27 +1020,20 @@ public Task send_coins(string targetId, int coins,Types.Send_Coin_Targets type, if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } if (debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - } - catch(Exception e) { throw new Exception(e.Message); } } public Task thank_tip(string chatId, string userId) { - try - { RestClient client = new RestClient(helpers.BaseUrl); RestRequest request = new RestRequest($"/x{communityId}/s/chat/thread/{chatId}/tipping/tipped-users/{userId}/thank"); var response = client.ExecutePost(request); if((int)response.StatusCode != 200) { throw new Exception(response.Content); } if(debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - }catch(Exception e) { throw new Exception(e.Message); } } public Task follow(List userIds) { - try - { JObject data = new JObject(); data.Add("timestamp", helpers.GetTimestamp() * 1000); data.Add("targetUidList", new JArray(userIds)); @@ -1176,24 +1046,16 @@ public Task follow(List userIds) if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } if (debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - } - catch (Exception e) { throw new Exception(e.Message); } } public Task follow(string userId) { - try - { follow(new List() { userId }); return Task.CompletedTask; - } - catch (Exception e) { throw new Exception(e.Message); } } public Task unfollow(string userId) { - try - { RestClient client = new RestClient(helpers.BaseUrl); RestRequest request = new RestRequest($"/x{communityId}/s/user-profile/{this.client.userID}/joined/{userId}"); request.AddHeaders(headers); @@ -1201,13 +1063,10 @@ public Task unfollow(string userId) if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } if (debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - }catch(Exception e) { throw new Exception(e.Message); } } public Task block(string userId) { - try - { RestClient client = new RestClient(helpers.BaseUrl); RestRequest request = new RestRequest($"/x{communityId}/s/block/{userId}"); request.AddHeaders(headers); @@ -1215,14 +1074,10 @@ public Task block(string userId) if((int)response.StatusCode != 200) { throw new Exception(response.Content); } if (debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - } - catch (Exception e) { throw new Exception(e.Message); } } public Task unblock(string userId) { - try - { RestClient client = new RestClient(helpers.BaseUrl); RestRequest request = new RestRequest($"/x{communityId}/s/block/{userId}"); request.AddHeaders(headers); @@ -1230,15 +1085,10 @@ public Task unblock(string userId) if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } if (debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - - } - catch (Exception e) { throw new Exception(e.Message); } } public Task visit(string userId) { - try - { RestClient client = new RestClient(helpers.BaseUrl); RestRequest request = new RestRequest($"/x{communityId}/s/user-profile/{userId}?action=visit"); request.AddHeaders(headers); @@ -1246,69 +1096,18 @@ public Task visit(string userId) if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } if (debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - }catch(Exception e) { throw new Exception(e.Message); } } public Task flag(string targetId, string reason, Types.Flag_Types flagType, Types.Flag_Targets targetType, bool asGuest = false) { - try - { - int _objectType = 0; - string flg = ""; - int _flagType = 0; - if (asGuest) { flg = "g-flag"; } else { flg = "flag"; } - switch (flagType) - { - case Types.Flag_Types.Aggression: - _flagType = 0; - break; - case Types.Flag_Types.Spam: - _flagType = 2; - break; - case Types.Flag_Types.Off_Topic: - _flagType = 4; - break; - case Types.Flag_Types.Violence: - _flagType = 106; - break; - case Types.Flag_Types.Intolerance: - _flagType = 107; - break; - case Types.Flag_Types.Suicide: - _flagType = 108; - break; - case Types.Flag_Types.Trolling: - _flagType = 109; - break; - case Types.Flag_Types.Pronography: - _flagType = 110; - break; - default: - _flagType = 0; - break; - } - switch (targetType) - { - case Types.Flag_Targets.User: - _objectType = 0; - break; - case Types.Flag_Targets.Blog: - _objectType = 1; - break; - case Types.Flag_Targets.Wiki: - _objectType = 2; - break; - default: - _objectType = 0; - break; - } + string flg = asGuest ? "g-flag" : "flag"; JObject data = new JObject(); data.Add("timestamp", helpers.GetTimestamp() * 1000); - data.Add("flagType", _flagType); + data.Add("flagType", (int)flagType); data.Add("message", reason); data.Add("objectId", targetId); - data.Add("objectType", _objectType); + data.Add("objectType", (int)targetType); RestClient client = new RestClient(helpers.BaseUrl); RestRequest request = new RestRequest($"/x{communityId}/s/{flg}"); @@ -1319,15 +1118,10 @@ public Task flag(string targetId, string reason, Types.Flag_Types flagType, Type if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } if (debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - - } - catch (Exception e) { throw new Exception(e.Message); } } public Objects.Message send_message(string message, string chatId, Types.Message_Types messageType = Types.Message_Types.General, string replyTo = null, List mentionUserIds = null) { - try - { List mentions = new List(); if(mentionUserIds == null) { mentionUserIds = new List(); } else { @@ -1372,8 +1166,6 @@ public Objects.Message send_message(string message, string chatId, Types.Message if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } if (debug) { Trace.WriteLine(response.Content); } return new Objects.Message(JObject.Parse(response.Content)); - } - catch (Exception e) { throw new Exception(e.Message); } } public Task send_file_message(string chatId, byte[] file, Types.upload_File_Types fileType) @@ -1433,20 +1225,12 @@ public Task send_file_message(string chatId, byte[] file, Types.upload_File_Type public Task send_file_message(string chatId, string filePath, Types.upload_File_Types fileType) { - try - { send_file_message(chatId, File.ReadAllBytes(filePath), fileType); return Task.CompletedTask; - } catch (Exception e) { throw new Exception(e.Message); } - } public Task send_embed(string chatId, string content = null, string embedId = null, string embedLink = null, string embedTitle = null, string embedContent = null, byte[] embedImage = null) { - - try - { - RestClient client = new RestClient(helpers.BaseUrl); RestRequest request = new RestRequest($"/x{communityId}/s/chat/thread/{chatId}/message"); JObject data = new JObject @@ -1480,10 +1264,6 @@ public Task send_embed(string chatId, string content = null, string embedId = nu if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } if (debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - - - } - catch(Exception e) { throw new Exception(e.Message); } } public Task send_embed(string chatId, string content = null, string embedId = null, string embedLink = null, string embedTitle = null, string embedContent = null, string embedImagePath = null) @@ -1494,10 +1274,6 @@ public Task send_embed(string chatId, string content = null, string embedId = nu public Task send_sticker(string chatId, string stickerId) { - try - { - - JObject data = new JObject(); JObject attachementSub = new JObject(); JObject extensionSub = new JObject(); @@ -1531,15 +1307,10 @@ public Task send_sticker(string chatId, string stickerId) if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } if (debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - - } - catch(Exception e) { throw new Exception(e.Message); } } public Task delete_message(string chatId, string messageId, bool asStaff = false, string reason = null) { - try - { string endPoint = $"/x{communityId}/s/chat/thread/{chatId}/message/{messageId}"; JObject data = new JObject(); data.Add("adminOpName", 102); @@ -1564,14 +1335,10 @@ public Task delete_message(string chatId, string messageId, bool asStaff = false if(debug) { Trace.WriteLine(response.Content); } } return Task.CompletedTask; - } - catch(Exception e) { throw new Exception(e.Message); } } public Task mark_as_read(string chatId, string messageId) { - try - { JObject data = new JObject(); data.Add("messageId", messageId); data.Add("timestamp", helpers.GetTimestamp() * 1000); @@ -1585,15 +1352,11 @@ public Task mark_as_read(string chatId, string messageId) if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } if (debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - } - catch(Exception e) { throw new Exception(e.Message); } } public Task transfer_host(string chatId, List userIds) { - try - { JObject data = new JObject(); data.Add("uidList", new JArray(userIds)); data.Add("timestamp", helpers.GetTimestamp() * 1000); @@ -1606,23 +1369,15 @@ public Task transfer_host(string chatId, List userIds) if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } if (debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - - } - catch(Exception e) { throw new Exception(e.Message); } } public Task transfer_host(string chatId, string userId) { - try - { return transfer_host(chatId, new List { userId }); - }catch(Exception e) { throw new Exception(e.Message); } } public Task accept_host(string chatId, string requestId) { - try - { JObject data = new JObject(); RestClient client = new RestClient(helpers.BaseUrl); RestRequest request = new RestRequest($"/x{communityId}/s/chat/thread/{chatId}/transfer-organizer/{requestId}/accept"); @@ -1633,14 +1388,10 @@ public Task accept_host(string chatId, string requestId) if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } if (debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - } - catch(Exception e) { throw new Exception(e.Message); } } public Task join_chat(string chatId) { - try - { RestClient client = new RestClient(helpers.BaseUrl); RestRequest request = new RestRequest($"/x{communityId}/s/chat/thread/{chatId}/member/{this.client.userID}"); request.AddHeaders(headers); @@ -1648,14 +1399,10 @@ public Task join_chat(string chatId) if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } if (debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - } - catch(Exception e) { throw new Exception(e.Message); } } public Task leave_chat(string chatId) { - try - { RestClient client = new RestClient(helpers.BaseUrl); RestRequest request = new RestRequest($"/x{communityId}/s/chat/thread/{chatId}/member/{this.client.userID}"); request.AddHeaders(headers); @@ -1663,15 +1410,11 @@ public Task leave_chat(string chatId) if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } if (debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - } - catch (Exception e) { throw new Exception(e.Message); } } public List get_user_following(string userId, int start = 0, int size = 25) { if (start < 0) { throw new Exception("start cannot be lower than 0"); } - try - { List userFollowingsList = new List(); RestClient client = new RestClient(helpers.BaseUrl); RestRequest request = new RestRequest($"/x{communityId}/s/user-profile/{userId}/joined?start={start}&size={size}"); @@ -1687,16 +1430,11 @@ public Task leave_chat(string chatId) userFollowingsList.Add(_following); } return userFollowingsList; - - } - catch (Exception e) { throw new Exception(e.Message); } } public List get_user_followers(string userId, int start = 0, int size = 25) { if (start < 0) { throw new Exception("start cannot be lower than 0"); } - try - { List userFollowerList = new List(); RestClient client = new RestClient(helpers.BaseUrl); RestRequest request = new RestRequest($"/x{communityId}/s/user-profile/{userId}/member?start={start}&size={size}"); @@ -1712,15 +1450,10 @@ public Task leave_chat(string chatId) userFollowerList.Add(_follower); } return userFollowerList; - - } - catch (Exception e) { throw new Exception(e.Message); } } public Objects.UserProfile get_user_info(string userId) { - try - { RestClient client = new RestClient(helpers.BaseUrl); RestRequest request = new RestRequest($"/x{communityId}/s/user-profile/{userId}"); request.AddHeaders(headers); @@ -1729,16 +1462,12 @@ public Objects.UserProfile get_user_info(string userId) if (debug) { Trace.WriteLine(response.Content); } Amino.Objects.UserProfile profile = new Amino.Objects.UserProfile((JObject)JObject.Parse(response.Content)["userProfile"]); return profile; - } - catch(Exception e) { throw new Exception(e.Message); } } public Task comment(string message, Types.Comment_Types type, string objectId) { string _eventSource; bool _isReply = false; - try - { RestClient client = new RestClient(helpers.BaseUrl); RestRequest request = new RestRequest(); request.AddHeaders(headers); @@ -1779,14 +1508,10 @@ public Task comment(string message, Types.Comment_Types type, string objectId) if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } if (debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; - } - catch (Exception e) { throw new Exception(e.Message); } } public List get_user_visitors(string userId, int start = 0, int size = 25) { if (start < 0) { throw new Exception("start cannot be lower than 0"); } - try - { List userVisitorList = new List(); RestClient client = new RestClient(helpers.BaseUrl); RestRequest request = new RestRequest($"/x{communityId}/s/user-profile/{userId}/visitors?start={start}&size={size}"); @@ -1802,8 +1527,6 @@ public Task comment(string message, Types.Comment_Types type, string objectId) userVisitorList.Add(_visitor); } return userVisitorList; - } - catch (Exception e) { throw new Exception(e.Message); } } public Objects.UserCheckins get_user_checkins(string userId) From 61f28c0fd2aa3132ce3ef34cf5b29a48520e195b Mon Sep 17 00:00:00 2001 From: Fabio Gaming Date: Sun, 14 Apr 2024 21:56:25 +0200 Subject: [PATCH 04/30] fixed formatting --- Amino.NET/SubClient.cs | 1768 ++++++++++++++++++++-------------------- 1 file changed, 885 insertions(+), 883 deletions(-) diff --git a/Amino.NET/SubClient.cs b/Amino.NET/SubClient.cs index 3048bc2..f3c5d84 100644 --- a/Amino.NET/SubClient.cs +++ b/Amino.NET/SubClient.cs @@ -80,24 +80,24 @@ public SubClient(Amino.Client _client, int _communityId) /// public List get_invite_codes(string status = "normal", int start = 0, int size = 25) { - List inviteCodeList = new List(); - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/g/s-x{communityId}/community/invitation?status={status}&start={start}&size={size}"); - request.AddHeaders(headers); - var response = client.ExecuteGet(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(response.Content); - JArray inviteCodesJson = jsonObj["communityInvitationList"]; - foreach(JObject code in inviteCodesJson) - { - Amino.Objects.InviteCode invCode = new Objects.InviteCode(code); - inviteCodeList.Add(invCode); - } - Console.WriteLine(response.Content); - return inviteCodeList; + List inviteCodeList = new List(); + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/g/s-x{communityId}/community/invitation?status={status}&start={start}&size={size}"); + request.AddHeaders(headers); + var response = client.ExecuteGet(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(response.Content); + JArray inviteCodesJson = jsonObj["communityInvitationList"]; + foreach (JObject code in inviteCodesJson) + { + Amino.Objects.InviteCode invCode = new Objects.InviteCode(code); + inviteCodeList.Add(invCode); + } + Console.WriteLine(response.Content); + return inviteCodeList; - } + } /// /// Allows you to generate a Community invite code (might require staff permissions) @@ -107,19 +107,19 @@ public SubClient(Amino.Client _client, int _communityId) /// public Task generate_invite_code(int duration = 0, bool force = true) { - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/g/s-x{communityId}/community/invitation"); - request.AddHeaders(headers); - JObject data = new JObject(); - data.Add("duration", duration); - data.Add("force", force); - data.Add("timestamp", helpers.GetTimestamp() * 1000); - request.AddJsonBody(JsonConvert.SerializeObject(data)); - request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); - var response = client.ExecuteGet(request); - if((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if(debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/g/s-x{communityId}/community/invitation"); + request.AddHeaders(headers); + JObject data = new JObject(); + data.Add("duration", duration); + data.Add("force", force); + data.Add("timestamp", helpers.GetTimestamp() * 1000); + request.AddJsonBody(JsonConvert.SerializeObject(data)); + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); + var response = client.ExecuteGet(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } /// @@ -129,13 +129,13 @@ public Task generate_invite_code(int duration = 0, bool force = true) /// public Task delete_invite_code(string inviteId) { - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/g/s-x{communityId}/community/invitation/{inviteId}"); - request.AddHeaders(headers); - var response = client.Delete(request); - if((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if(debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/g/s-x{communityId}/community/invitation/{inviteId}"); + request.AddHeaders(headers); + var response = client.Delete(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } /// @@ -149,46 +149,46 @@ public Task delete_invite_code(string inviteId) /// public Task post_blog(string title, string content, List imageList = null, bool fansOnly = false, string backgroundColor = null) { - JArray mediaList = new JArray(); - JObject extensionData = new JObject(); + JArray mediaList = new JArray(); + JObject extensionData = new JObject(); - if(imageList != null) + if (imageList != null) + { + JArray tempMedia = new JArray(); + foreach (byte[] bytes in imageList) { - JArray tempMedia = new JArray(); - foreach(byte[] bytes in imageList) - { - tempMedia = new JArray(); - tempMedia.Add(100); - tempMedia.Add(this.client.upload_media(bytes, Types.upload_File_Types.Image)); - tempMedia.Add(null); - mediaList.Add(tempMedia); - } + tempMedia = new JArray(); + tempMedia.Add(100); + tempMedia.Add(this.client.upload_media(bytes, Types.upload_File_Types.Image)); + tempMedia.Add(null); + mediaList.Add(tempMedia); } - if(fansOnly) { extensionData.Add("fansOnly", fansOnly); } - if(backgroundColor != null) { JObject color = new JObject(); color.Add("backgroundColor", backgroundColor); extensionData.Add(new JProperty("style", color)); } - - - - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/x{communityId}/s/blog"); - request.AddHeaders(headers); - JObject data = new JObject(); - data.Add("address", null); - data.Add("title", title); - data.Add("content", content); - data.Add("mediaList", new JArray(mediaList)); - data.Add(new JProperty("extensions", extensionData)); - data.Add("latitude", 0); - data.Add("longitude", 0); - data.Add("eventSource", "GlobalComposeMenu"); - data.Add("timestamp", helpers.GetTimestamp() * 1000); - request.AddJsonBody(JsonConvert.SerializeObject(data)); - request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); - var response = client.ExecutePost(request); - if((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if(debug) { Trace.WriteLine(response.Content); } + } + if (fansOnly) { extensionData.Add("fansOnly", fansOnly); } + if (backgroundColor != null) { JObject color = new JObject(); color.Add("backgroundColor", backgroundColor); extensionData.Add(new JProperty("style", color)); } + + + + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/x{communityId}/s/blog"); + request.AddHeaders(headers); + JObject data = new JObject(); + data.Add("address", null); + data.Add("title", title); + data.Add("content", content); + data.Add("mediaList", new JArray(mediaList)); + data.Add(new JProperty("extensions", extensionData)); + data.Add("latitude", 0); + data.Add("longitude", 0); + data.Add("eventSource", "GlobalComposeMenu"); + data.Add("timestamp", helpers.GetTimestamp() * 1000); + request.AddJsonBody(JsonConvert.SerializeObject(data)); + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + return Task.CompletedTask; } /// @@ -202,41 +202,41 @@ public Task post_blog(string title, string content, List imageList = nul /// public Task post_wiki(string title, string content, List imageList = null, bool fansOnly = false, string backgroundColor = null) { - JArray mediaList = new JArray(); - JObject extensionData = new JObject(); + JArray mediaList = new JArray(); + JObject extensionData = new JObject(); - if (imageList != null) + if (imageList != null) + { + JArray tempMedia = new JArray(); + foreach (byte[] bytes in imageList) { - JArray tempMedia = new JArray(); - foreach (byte[] bytes in imageList) - { - tempMedia = new JArray(); - tempMedia.Add(100); - tempMedia.Add(this.client.upload_media(bytes, Types.upload_File_Types.Image)); - tempMedia.Add(null); - mediaList.Add(tempMedia); - } + tempMedia = new JArray(); + tempMedia.Add(100); + tempMedia.Add(this.client.upload_media(bytes, Types.upload_File_Types.Image)); + tempMedia.Add(null); + mediaList.Add(tempMedia); } - if (fansOnly) { extensionData.Add("fansOnly", fansOnly); } - if (backgroundColor != null) { JObject color = new JObject(); color.Add("backgroundColor", backgroundColor); extensionData.Add(new JProperty("style", color)); } - - - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/x{communityId}/s/item"); - request.AddHeaders(headers); - JObject data = new JObject(); - data.Add("label", title); - data.Add("content", content); - data.Add("eventSource", "GlobalComposeMenu"); - data.Add("mediaList", new JArray(mediaList)); - data.Add(new JProperty("extensions", extensionData)); - data.Add("timestamp", helpers.GetTimestamp() * 1000); - request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); - request.AddJsonBody(JsonConvert.SerializeObject(data)); - var response = client.ExecutePost(request); - if((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if(debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + } + if (fansOnly) { extensionData.Add("fansOnly", fansOnly); } + if (backgroundColor != null) { JObject color = new JObject(); color.Add("backgroundColor", backgroundColor); extensionData.Add(new JProperty("style", color)); } + + + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/x{communityId}/s/item"); + request.AddHeaders(headers); + JObject data = new JObject(); + data.Add("label", title); + data.Add("content", content); + data.Add("eventSource", "GlobalComposeMenu"); + data.Add("mediaList", new JArray(mediaList)); + data.Add(new JProperty("extensions", extensionData)); + data.Add("timestamp", helpers.GetTimestamp() * 1000); + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); + request.AddJsonBody(JsonConvert.SerializeObject(data)); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } /// @@ -251,46 +251,46 @@ public Task post_wiki(string title, string content, List imageList = nul /// public Task edit_blog(string blogId, string title = null, string content = null, List imageList = null, bool fansOnly = false, string backgroundColor = null) { - JArray mediaList = new JArray(); - JObject extensionData = new JObject(); + JArray mediaList = new JArray(); + JObject extensionData = new JObject(); - if (imageList != null) + if (imageList != null) + { + JArray tempMedia = new JArray(); + foreach (byte[] bytes in imageList) { - JArray tempMedia = new JArray(); - foreach (byte[] bytes in imageList) - { - tempMedia = new JArray(); - tempMedia.Add(100); - tempMedia.Add(this.client.upload_media(bytes, Types.upload_File_Types.Image)); - tempMedia.Add(null); - mediaList.Add(tempMedia); - } + tempMedia = new JArray(); + tempMedia.Add(100); + tempMedia.Add(this.client.upload_media(bytes, Types.upload_File_Types.Image)); + tempMedia.Add(null); + mediaList.Add(tempMedia); } - if (fansOnly) { extensionData.Add("fansOnly", fansOnly); } - if (backgroundColor != null) { JObject color = new JObject(); color.Add("backgroundColor", backgroundColor); extensionData.Add(new JProperty("style", color)); } - - - - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/x{communityId}/s/blog"); - request.AddHeaders(headers); - JObject data = new JObject(); - data.Add("address", null); - data.Add("title", title); - data.Add("content", content); - data.Add("mediaList", new JArray(mediaList)); - data.Add(new JProperty("extensions", extensionData)); - data.Add("latitude", 0); - data.Add("longitude", 0); - data.Add("eventSource", "PostDetailView"); - data.Add("timestamp", helpers.GetTimestamp() * 1000); - request.AddJsonBody(JsonConvert.SerializeObject(data)); - request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); - var response = client.ExecutePost(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } + } + if (fansOnly) { extensionData.Add("fansOnly", fansOnly); } + if (backgroundColor != null) { JObject color = new JObject(); color.Add("backgroundColor", backgroundColor); extensionData.Add(new JProperty("style", color)); } + - return Task.CompletedTask; + + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/x{communityId}/s/blog"); + request.AddHeaders(headers); + JObject data = new JObject(); + data.Add("address", null); + data.Add("title", title); + data.Add("content", content); + data.Add("mediaList", new JArray(mediaList)); + data.Add(new JProperty("extensions", extensionData)); + data.Add("latitude", 0); + data.Add("longitude", 0); + data.Add("eventSource", "PostDetailView"); + data.Add("timestamp", helpers.GetTimestamp() * 1000); + request.AddJsonBody(JsonConvert.SerializeObject(data)); + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + + return Task.CompletedTask; } /// @@ -300,13 +300,13 @@ public Task edit_blog(string blogId, string title = null, string content = null, /// public Task delete_blog(string blogId) { - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/x{communityId}/s/blog/{blogId}"); - request.AddHeaders(headers); - var response = client.Delete(request); - if((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if(debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/x{communityId}/s/blog/{blogId}"); + request.AddHeaders(headers); + var response = client.Delete(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } /// @@ -316,13 +316,13 @@ public Task delete_blog(string blogId) /// public Task delete_wiki(string wikiId) { - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/x{communityId}/s/item/{wikiId}"); - request.AddHeaders(headers); - var response = client.Delete(request); - if((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if(debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/x{communityId}/s/item/{wikiId}"); + request.AddHeaders(headers); + var response = client.Delete(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } /// @@ -334,21 +334,21 @@ public Task delete_wiki(string wikiId) /// public Task repost_blog(string postId, Types.Repost_Types type, string content = null) { - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/x{communityId}/s/blog"); - request.AddHeaders(headers); - JObject data = new JObject(); - data.Add("content", content); - data.Add("refObjectId", postId); - data.Add("refObjectType", (int)type); - data.Add("type", 2); - data.Add("timestamp", helpers.GetTimestamp() * 1000); - request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); - request.AddJsonBody(JsonConvert.SerializeObject(data)); - var response = client.ExecutePost(request); - if((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if(debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/x{communityId}/s/blog"); + request.AddHeaders(headers); + JObject data = new JObject(); + data.Add("content", content); + data.Add("refObjectId", postId); + data.Add("refObjectType", (int)type); + data.Add("type", 2); + data.Add("timestamp", helpers.GetTimestamp() * 1000); + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); + request.AddJsonBody(JsonConvert.SerializeObject(data)); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } /// @@ -358,20 +358,20 @@ public Task repost_blog(string postId, Types.Repost_Types type, string content = /// public Task check_in(int? timezone = null) { - int? tz; - if (timezone != null) { tz = timezone; } else { tz = helpers.getTimezone(); } - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/x{communityId}/s/check-in"); - request.AddHeaders(headers); - JObject data = new JObject(); - data.Add("timestamp", helpers.GetTimestamp() * 1000); - data.Add("timezone", tz); - request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); - request.AddJsonBody(JsonConvert.SerializeObject(data)); - var response = client.ExecutePost(request); - if((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if(debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + int? tz; + if (timezone != null) { tz = timezone; } else { tz = helpers.getTimezone(); } + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/x{communityId}/s/check-in"); + request.AddHeaders(headers); + JObject data = new JObject(); + data.Add("timestamp", helpers.GetTimestamp() * 1000); + data.Add("timezone", tz); + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); + request.AddJsonBody(JsonConvert.SerializeObject(data)); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } /// @@ -381,18 +381,18 @@ public Task check_in(int? timezone = null) /// public Task repair_check_in(Types.Repair_Types repairType) { - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/x{communityId}/s/check-in/repair"); - request.AddHeaders(headers); - JObject data = new JObject(); - data.Add("timestamp", helpers.GetTimestamp() * 1000); - data.Add("repairMethod", Convert.ToString((int)repairType)); - request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); - request.AddJsonBody(JsonConvert.SerializeObject(data)); - var response = client.ExecutePost(request); - if((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if(debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/x{communityId}/s/check-in/repair"); + request.AddHeaders(headers); + JObject data = new JObject(); + data.Add("timestamp", helpers.GetTimestamp() * 1000); + data.Add("repairMethod", Convert.ToString((int)repairType)); + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); + request.AddJsonBody(JsonConvert.SerializeObject(data)); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } /// @@ -402,20 +402,20 @@ public Task repair_check_in(Types.Repair_Types repairType) /// public Task lottery(int? timezone = null) { - int? tz; - if (timezone != null) { tz = timezone; } else { tz = helpers.getTimezone(); } - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/x{communityId}/s/check-in"); - request.AddHeaders(headers); - JObject data = new JObject(); - data.Add("timestamp", helpers.GetTimestamp() * 1000); - data.Add("timezone", tz); - request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); - request.AddJsonBody(JsonConvert.SerializeObject(data)); - var response = client.ExecutePost(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + int? tz; + if (timezone != null) { tz = timezone; } else { tz = helpers.getTimezone(); } + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/x{communityId}/s/check-in"); + request.AddHeaders(headers); + JObject data = new JObject(); + data.Add("timestamp", helpers.GetTimestamp() * 1000); + data.Add("timezone", tz); + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); + request.AddJsonBody(JsonConvert.SerializeObject(data)); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } /// @@ -432,43 +432,43 @@ public Task lottery(int? timezone = null) /// public Task edit_profile(string nickname = null, string content = null, byte[] icon = null, List imageList = null, List captionList = null, string backgroundColor = null, byte[] backgroundImage = null, string defaultChatBubbleId = null) { - JObject data = new JObject(); + JObject data = new JObject(); - JArray mediaList = new JArray(); - JObject extensionData = new JObject(); + JArray mediaList = new JArray(); + JObject extensionData = new JObject(); - if (imageList != null) + if (imageList != null) + { + JArray tempMedia = new JArray(); + for (int i = 0; i != imageList.Count; i++) { - JArray tempMedia = new JArray(); - for(int i = 0; i != imageList.Count; i++) - { - tempMedia = new JArray(); - tempMedia.Add(100); - tempMedia.Add(this.client.upload_media(imageList[i], Types.upload_File_Types.Image)); - tempMedia.Add(captionList[i]); - mediaList.Add(tempMedia); - } + tempMedia = new JArray(); + tempMedia.Add(100); + tempMedia.Add(this.client.upload_media(imageList[i], Types.upload_File_Types.Image)); + tempMedia.Add(captionList[i]); + mediaList.Add(tempMedia); } - if (backgroundColor != null) { JObject color = new JObject(); color.Add("backgroundColor", backgroundColor); extensionData.Add(new JProperty("style", color)); } - if(backgroundImage != null) { JObject bgImg = new JObject(); JArray bgArr = new JArray(); bgArr.Add(100);bgArr.Add(this.client.upload_media(backgroundImage, Types.upload_File_Types.Image));bgArr.Add(null); bgArr.Add(null); bgArr.Add(null); bgImg.Add("backgroundMediaList", new JArray(bgArr)); extensionData.Add(new JProperty("style", bgImg)); } - if(defaultChatBubbleId != null) { JObject dchtbl = new JObject(); dchtbl.Add("defaultBubbleId", defaultChatBubbleId); extensionData.Add(dchtbl); } + } + if (backgroundColor != null) { JObject color = new JObject(); color.Add("backgroundColor", backgroundColor); extensionData.Add(new JProperty("style", color)); } + if (backgroundImage != null) { JObject bgImg = new JObject(); JArray bgArr = new JArray(); bgArr.Add(100); bgArr.Add(this.client.upload_media(backgroundImage, Types.upload_File_Types.Image)); bgArr.Add(null); bgArr.Add(null); bgArr.Add(null); bgImg.Add("backgroundMediaList", new JArray(bgArr)); extensionData.Add(new JProperty("style", bgImg)); } + if (defaultChatBubbleId != null) { JObject dchtbl = new JObject(); dchtbl.Add("defaultBubbleId", defaultChatBubbleId); extensionData.Add(dchtbl); } - data.Add("timestamp", helpers.GetTimestamp() * 1000); - data.Add(new JProperty("extensions", extensionData)); - if(nickname != null) { data.Add("nickname", nickname); } - if(content != null) { data.Add("content", content); } - if(icon != null) { data.Add("icon", this.client.upload_media(icon, Types.upload_File_Types.Image)); } + data.Add("timestamp", helpers.GetTimestamp() * 1000); + data.Add(new JProperty("extensions", extensionData)); + if (nickname != null) { data.Add("nickname", nickname); } + if (content != null) { data.Add("content", content); } + if (icon != null) { data.Add("icon", this.client.upload_media(icon, Types.upload_File_Types.Image)); } - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/x{communityId}/s/user-profile/{this.client.userID}"); - request.AddHeaders(headers); - request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); - request.AddJsonBody(JsonConvert.SerializeObject(data)); - var response = client.ExecutePost(request); - if ((int)response.StatusCode != 200) throw new Exception(response.Content); - if(debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/x{communityId}/s/user-profile/{this.client.userID}"); + request.AddHeaders(headers); + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); + request.AddJsonBody(JsonConvert.SerializeObject(data)); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) throw new Exception(response.Content); + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } /// @@ -479,19 +479,19 @@ public Task edit_profile(string nickname = null, string content = null, byte[] i /// public Task vote_poll(string postId, string optionId) { - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/x{communityId}/s/blog/{postId}/poll/option/{optionId}/vote"); - JObject data = new JObject(); - data.Add("timestamp", helpers.GetTimestamp() * 1000); - data.Add("eventSource", "PostDetailView"); - data.Add("value", 1); - request.AddHeaders(headers); - request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); - request.AddJsonBody(JsonConvert.SerializeObject(data)); - var response = client.ExecutePost(request); - if((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if(debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/x{communityId}/s/blog/{postId}/poll/option/{optionId}/vote"); + JObject data = new JObject(); + data.Add("timestamp", helpers.GetTimestamp() * 1000); + data.Add("eventSource", "PostDetailView"); + data.Add("value", 1); + request.AddHeaders(headers); + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); + request.AddJsonBody(JsonConvert.SerializeObject(data)); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } /// @@ -504,42 +504,42 @@ public Task vote_poll(string postId, string optionId) /// public Task comment(string message, Amino.Types.Comment_Types type, string targetId, bool isGuest = false) { - string endPoint = null; - JObject data = new JObject(); - data.Add("content", message); - data.Add("strickerId", null); - data.Add("type", 0); - data.Add("timestamp", helpers.GetTimestamp() * 1000); - string comType; - if (isGuest) { comType = "g-comment"; } else { comType = "comment"; } - switch(type) - { - case Types.Comment_Types.Blog: - data.Add("eventSource", "PostDetailView"); - endPoint = $"/x{communityId}/s/blog/{targetId}/{comType}"; - break; - case Types.Comment_Types.Wiki: - data.Add("eventSource", "PostDetailView"); - break; - case Types.Comment_Types.Reply: - data.Add("respondTo", targetId); - endPoint = $"/x{communityId}/s/item/{targetId}/{comType}"; - break; - case Types.Comment_Types.User: - data.Add("eventSource", "UserProfileView"); - endPoint = $"/x{communityId}/s/user-profile/{targetId}/{comType}"; - break; - } + string endPoint = null; + JObject data = new JObject(); + data.Add("content", message); + data.Add("strickerId", null); + data.Add("type", 0); + data.Add("timestamp", helpers.GetTimestamp() * 1000); + string comType; + if (isGuest) { comType = "g-comment"; } else { comType = "comment"; } + switch (type) + { + case Types.Comment_Types.Blog: + data.Add("eventSource", "PostDetailView"); + endPoint = $"/x{communityId}/s/blog/{targetId}/{comType}"; + break; + case Types.Comment_Types.Wiki: + data.Add("eventSource", "PostDetailView"); + break; + case Types.Comment_Types.Reply: + data.Add("respondTo", targetId); + endPoint = $"/x{communityId}/s/item/{targetId}/{comType}"; + break; + case Types.Comment_Types.User: + data.Add("eventSource", "UserProfileView"); + endPoint = $"/x{communityId}/s/user-profile/{targetId}/{comType}"; + break; + } - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest(endPoint); - request.AddHeaders(headers); - request.AddJsonBody(JsonConvert.SerializeObject(data)); - request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); - var response = client.ExecutePost(request); - if((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if(debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest(endPoint); + request.AddHeaders(headers); + request.AddJsonBody(JsonConvert.SerializeObject(data)); + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } /// @@ -551,32 +551,32 @@ public Task comment(string message, Amino.Types.Comment_Types type, string targe /// public Task delete_comment(string commentId, Amino.Types.Comment_Types type, string targetId) { - string endPoint = null; - switch(type) - { - case Types.Comment_Types.Blog: - endPoint = $"/x{communityId}/s/blog/{targetId}/comment/{commentId}"; - break; - case Types.Comment_Types.Wiki: - endPoint = $"/x{communityId}/s/item/{targetId}/comment/{commentId}"; - break; - case Types.Comment_Types.Reply: - break; - case Types.Comment_Types.User: - endPoint = $"/x{communityId}/s/user-profile/{targetId}/comment/{commentId}"; - break; - } + string endPoint = null; + switch (type) + { + case Types.Comment_Types.Blog: + endPoint = $"/x{communityId}/s/blog/{targetId}/comment/{commentId}"; + break; + case Types.Comment_Types.Wiki: + endPoint = $"/x{communityId}/s/item/{targetId}/comment/{commentId}"; + break; + case Types.Comment_Types.Reply: + break; + case Types.Comment_Types.User: + endPoint = $"/x{communityId}/s/user-profile/{targetId}/comment/{commentId}"; + break; + } - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest(endPoint); - request.AddHeaders(headers); - var response = client.Delete(request); - if((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if(debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest(endPoint); + request.AddHeaders(headers); + var response = client.Delete(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } - + /// /// Allows you to like a Post /// @@ -585,23 +585,23 @@ public Task delete_comment(string commentId, Amino.Types.Comment_Types type, str /// public Task like_post(string postId, bool isWiki = false) { - string endPoint = null; + string endPoint = null; - JObject data = new JObject(); - data.Add("value", 4); - data.Add("timestamp", helpers.GetTimestamp() * 1000); - if(!isWiki) { data.Add("eventSource", "UserProfileView"); endPoint = $"/x{communityId}/s/blog/{postId}/vote?cv=1.2"; } else { data.Add("eventSource", "PostDetailView"); endPoint = $"/x{communityId}/s/item/{postId}/vote?cv=1.2"; } + JObject data = new JObject(); + data.Add("value", 4); + data.Add("timestamp", helpers.GetTimestamp() * 1000); + if (!isWiki) { data.Add("eventSource", "UserProfileView"); endPoint = $"/x{communityId}/s/blog/{postId}/vote?cv=1.2"; } else { data.Add("eventSource", "PostDetailView"); endPoint = $"/x{communityId}/s/item/{postId}/vote?cv=1.2"; } + + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest(endPoint); + request.AddHeaders(headers); + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); + request.AddJsonBody(JsonConvert.SerializeObject(data)); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest(endPoint); - request.AddHeaders(headers); - request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); - request.AddJsonBody(JsonConvert.SerializeObject(data)); - var response = client.ExecutePost(request); - if((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if(debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; - } /// @@ -612,15 +612,15 @@ public Task like_post(string postId, bool isWiki = false) /// public Task unlike_post(string postId, bool isWiki = false) { - string endPoint = null; - if(!isWiki) { endPoint = $"/x{communityId}/s/blog/{postId}/vote?eventSource=UserProfileView"; } else { endPoint = $"/x{communityId}/s/item/{postId}/vote?eventSource=PostDetailView"; } - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest(endPoint); - request.AddHeaders(headers); - var response = client.Delete(request); - if((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if(debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + string endPoint = null; + if (!isWiki) { endPoint = $"/x{communityId}/s/blog/{postId}/vote?eventSource=UserProfileView"; } else { endPoint = $"/x{communityId}/s/item/{postId}/vote?eventSource=PostDetailView"; } + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest(endPoint); + request.AddHeaders(headers); + var response = client.Delete(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } /// @@ -630,27 +630,27 @@ public Task unlike_post(string postId, bool isWiki = false) /// /// /// - public Task like_comment(string commentId, string targetId,Types.Comment_Types targetType) - { - string _targetType = null; - string voteType = null; - string targetValue = null; - if(targetType == Types.Comment_Types.User) { _targetType = "UserProfileView"; targetValue = "user-profile"; } else { _targetType = "PostDetailView"; targetValue = "blog"; } - if(targetType == Types.Comment_Types.Wiki) { voteType = "g-vote"; targetValue = "item"; } else { voteType = "vote"; } - JObject data = new JObject(); - data.Add("timestamp", helpers.GetTimestamp() * 1000); - data.Add("value", 1); - data.Add("EventSource", _targetType); - - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/x{communityId}/s/{targetValue}/{targetId}/comment/{commentId}/{voteType}?cv=1.2&value=1"); - request.AddHeaders(headers); - request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); - request.AddJsonBody(JsonConvert.SerializeObject(data)); - var response = client.ExecutePost(request); - if((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if(debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + public Task like_comment(string commentId, string targetId, Types.Comment_Types targetType) + { + string _targetType = null; + string voteType = null; + string targetValue = null; + if (targetType == Types.Comment_Types.User) { _targetType = "UserProfileView"; targetValue = "user-profile"; } else { _targetType = "PostDetailView"; targetValue = "blog"; } + if (targetType == Types.Comment_Types.Wiki) { voteType = "g-vote"; targetValue = "item"; } else { voteType = "vote"; } + JObject data = new JObject(); + data.Add("timestamp", helpers.GetTimestamp() * 1000); + data.Add("value", 1); + data.Add("EventSource", _targetType); + + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/x{communityId}/s/{targetValue}/{targetId}/comment/{commentId}/{voteType}?cv=1.2&value=1"); + request.AddHeaders(headers); + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); + request.AddJsonBody(JsonConvert.SerializeObject(data)); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } @@ -663,20 +663,20 @@ public Task like_comment(string commentId, string targetId,Types.Comment_Types t /// public Task unlike_comment(string commentId, string targetId, Amino.Types.Comment_Types targetType) { - string _targetType = null; - string _eventSource = "PostDetailView"; - if (targetType == Types.Comment_Types.User) { _targetType = "user-profile"; _eventSource = "UserProfileView"; } else if (targetType == Types.Comment_Types.Wiki) { _targetType = "item"; } else { _targetType = "blog"; } - + string _targetType = null; + string _eventSource = "PostDetailView"; + if (targetType == Types.Comment_Types.User) { _targetType = "user-profile"; _eventSource = "UserProfileView"; } else if (targetType == Types.Comment_Types.Wiki) { _targetType = "item"; } else { _targetType = "blog"; } - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/x{communityId}/s/{_targetType}/{targetId}/comment/{commentId}/g-vote?eventSource={_eventSource}"); - request.AddHeaders(headers); - var response = client.Delete(request); - if((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if(debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; - } + + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/x{communityId}/s/{_targetType}/{targetId}/comment/{commentId}/g-vote?eventSource={_eventSource}"); + request.AddHeaders(headers); + var response = client.Delete(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; + } /// /// Allows you to upvote a comment @@ -686,20 +686,20 @@ public Task unlike_comment(string commentId, string targetId, Amino.Types.Commen /// public Task upvote_comment(string commentId, string postId) { - JObject data = new JObject(); - data.Add("value", 1); - data.Add("eventSource", "PostDetailView"); - data.Add("timestamp", helpers.GetTimestamp() * 1000); + JObject data = new JObject(); + data.Add("value", 1); + data.Add("eventSource", "PostDetailView"); + data.Add("timestamp", helpers.GetTimestamp() * 1000); - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/x{communityId}/s/blog/{postId}/comment/{commentId}/vote?cv=1.2&value=1"); - request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); - request.AddHeaders(headers); - request.AddJsonBody(JsonConvert.SerializeObject(data)); - var response = client.ExecutePost(request); - if((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/x{communityId}/s/blog/{postId}/comment/{commentId}/vote?cv=1.2&value=1"); + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); + request.AddHeaders(headers); + request.AddJsonBody(JsonConvert.SerializeObject(data)); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } /// @@ -710,20 +710,20 @@ public Task upvote_comment(string commentId, string postId) /// public Task downvote_comment(string commentId, string postId) { - JObject data = new JObject(); - data.Add("value", -1); - data.Add("eventSource", "PostDetailView"); - data.Add("timestamp", helpers.GetTimestamp() * 1000); + JObject data = new JObject(); + data.Add("value", -1); + data.Add("eventSource", "PostDetailView"); + data.Add("timestamp", helpers.GetTimestamp() * 1000); - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/x{communityId}/s/blog/{postId}/comment/{commentId}/vote?cv=1.2&value=1"); - request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); - request.AddHeaders(headers); - request.AddJsonBody(JsonConvert.SerializeObject(data)); - var response = client.Delete(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/x{communityId}/s/blog/{postId}/comment/{commentId}/vote?cv=1.2&value=1"); + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); + request.AddHeaders(headers); + request.AddJsonBody(JsonConvert.SerializeObject(data)); + var response = client.Delete(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } /// @@ -734,12 +734,12 @@ public Task downvote_comment(string commentId, string postId) /// public Task unvote_comment(string commentId, string postId) { - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/x{communityId}/s/blog/{postId}/comment/{commentId}/vote?eventSource=PostDetailView"); - var response = client.Delete(request); - if((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/x{communityId}/s/blog/{postId}/comment/{commentId}/vote?eventSource=PostDetailView"); + var response = client.Delete(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } /// @@ -751,23 +751,23 @@ public Task unvote_comment(string commentId, string postId) /// public Task reply_wall(string userId, string commentId, string message) { - JObject data = new JObject(); - data.Add("content", message); - data.Add("stackId", null); - data.Add("respondTo", commentId); - data.Add("type", 0); - data.Add("eventSource", "UserProfileView"); - data.Add("timestamp", helpers.GetTimestamp() * 1000); - - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/x{communityId}/s/user-profile/{userId}/comment"); - request.AddHeaders(headers); - request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); - request.AddJsonBody(JsonConvert.SerializeObject(data)); - var response = client.ExecutePost(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + JObject data = new JObject(); + data.Add("content", message); + data.Add("stackId", null); + data.Add("respondTo", commentId); + data.Add("type", 0); + data.Add("eventSource", "UserProfileView"); + data.Add("timestamp", helpers.GetTimestamp() * 1000); + + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/x{communityId}/s/user-profile/{userId}/comment"); + request.AddHeaders(headers); + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); + request.AddJsonBody(JsonConvert.SerializeObject(data)); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } /// @@ -777,20 +777,20 @@ public Task reply_wall(string userId, string commentId, string message) /// public Task set_activity_status(Types.Activity_Status_Types status) { - JObject data = new JObject(); - if (status == Types.Activity_Status_Types.On) { data.Add("onlineStatus", "on"); } else { data.Add("onlineStatus", "off"); } - data.Add("duration", 86400); - data.Add("timestamp", helpers.GetTimestamp() * 1000); + JObject data = new JObject(); + if (status == Types.Activity_Status_Types.On) { data.Add("onlineStatus", "on"); } else { data.Add("onlineStatus", "off"); } + data.Add("duration", 86400); + data.Add("timestamp", helpers.GetTimestamp() * 1000); - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/x{communityId}/s/user-profile/{this.client.userID}/online-status"); - request.AddHeaders(headers); - request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); - request.AddJsonBody(JsonConvert.SerializeObject(data)); - var response = client.ExecutePost(request); - if((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/x{communityId}/s/user-profile/{this.client.userID}/online-status"); + request.AddHeaders(headers); + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); + request.AddJsonBody(JsonConvert.SerializeObject(data)); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } /// @@ -799,13 +799,13 @@ public Task set_activity_status(Types.Activity_Status_Types status) /// public Task check_notification() { - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/x{communityId}/s/notification/checked"); - request.AddHeaders(headers); - var response = client.ExecutePost(request); - if((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if(debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/x{communityId}/s/notification/checked"); + request.AddHeaders(headers); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } /// @@ -815,13 +815,13 @@ public Task check_notification() /// public Task delete_notification(string notificationId) { - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/x{communityId}/s/notification/{notificationId}"); - request.AddHeaders(headers); - var response = client.Delete(request); - if((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if(debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/x{communityId}/s/notification/{notificationId}"); + request.AddHeaders(headers); + var response = client.Delete(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } /// @@ -830,13 +830,13 @@ public Task delete_notification(string notificationId) /// public Task clear_notifications() { - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/x{communityId}/s/notification"); - request.AddHeaders(headers); - var response = client.Delete(request); - if((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if(debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/x{communityId}/s/notification"); + request.AddHeaders(headers); + var response = client.Delete(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } /// @@ -845,36 +845,36 @@ public Task clear_notifications() /// public Task send_activity_time() { - JObject data = new JObject(); - JArray timeData = new JArray(); + JObject data = new JObject(); + JArray timeData = new JArray(); - foreach (Dictionary timer in helpers.getTimeData()) - { - JObject subData = new JObject(); + foreach (Dictionary timer in helpers.getTimeData()) + { + JObject subData = new JObject(); - subData.Add("start", timer["start"]); - subData.Add("end", timer["end"]); + subData.Add("start", timer["start"]); + subData.Add("end", timer["end"]); + + timeData.Add(subData); + } + int optInAdsFlags = 2147483647; + int tzf = helpers.TzFilter(); + data.Add("userActiveTimeChunkList", timeData); + data.Add("OptInAdsFlags", optInAdsFlags); + data.Add("timestamp", (long)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalMilliseconds); + data.Add("timezone", tzf); + + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/x{communityId}/s/community/stats/user-active-time"); + request.AddHeaders(headers); + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); + request.AddJsonBody(JsonConvert.SerializeObject(data)); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; - timeData.Add(subData); - } - int optInAdsFlags = 2147483647; - int tzf = helpers.TzFilter(); - data.Add("userActiveTimeChunkList", timeData); - data.Add("OptInAdsFlags", optInAdsFlags); - data.Add("timestamp", (long)(DateTime.UtcNow.Subtract(new DateTime(1970, 1, 1))).TotalMilliseconds); - data.Add("timezone", tzf); - - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/x{communityId}/s/community/stats/user-active-time"); - request.AddHeaders(headers); - request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); - request.AddJsonBody(JsonConvert.SerializeObject(data)); - var response = client.ExecutePost(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; - } @@ -890,24 +890,24 @@ public Task send_activity_time() /// public Task start_chat(List userIds, string message, string title = null, string content = null, bool isGlobal = false, bool publishToGlobal = false) { - JObject data = new JObject(); - data.Add("title", title); - data.Add("inviteeUids", new JArray(userIds)); - data.Add("initialMessageContent", message); - data.Add("content", content); - data.Add("timestamp", helpers.GetTimestamp() * 1000); - if(isGlobal) { data.Add("type", 2); data.Add("eventSource", "GlobalComposeMenu"); } else { data.Add("type", 0); } - if(publishToGlobal) { data.Add("publishToGlobal", 1); } else { data.Add("publishToGlobal", 0); } - - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/x{communityId}/s/chat/thread"); - request.AddHeaders(headers); - request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); - request.AddJsonBody(JsonConvert.SerializeObject(data)); - var response = client.ExecutePost(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + JObject data = new JObject(); + data.Add("title", title); + data.Add("inviteeUids", new JArray(userIds)); + data.Add("initialMessageContent", message); + data.Add("content", content); + data.Add("timestamp", helpers.GetTimestamp() * 1000); + if (isGlobal) { data.Add("type", 2); data.Add("eventSource", "GlobalComposeMenu"); } else { data.Add("type", 0); } + if (publishToGlobal) { data.Add("publishToGlobal", 1); } else { data.Add("publishToGlobal", 0); } + + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/x{communityId}/s/chat/thread"); + request.AddHeaders(headers); + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); + request.AddJsonBody(JsonConvert.SerializeObject(data)); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } /// @@ -934,19 +934,19 @@ public Task start_chat(string userId, string message, string title = null, strin /// public Task invite_to_chat(List userIds, string chatId) { - JObject data = new JObject(); - data.Add("uids", new JArray(userIds)); - data.Add("timestamp", helpers.GetTimestamp() * 1000); + JObject data = new JObject(); + data.Add("uids", new JArray(userIds)); + data.Add("timestamp", helpers.GetTimestamp() * 1000); - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/x{communityId}/s/chat/thread/{chatId}/member/invite"); - request.AddHeaders(headers); - request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); - request.AddJsonBody(JsonConvert.SerializeObject(data)); - var response = client.ExecutePost(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/x{communityId}/s/chat/thread/{chatId}/member/invite"); + request.AddHeaders(headers); + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); + request.AddJsonBody(JsonConvert.SerializeObject(data)); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } /// @@ -968,13 +968,13 @@ public Task invite_to_chat(string userId, string chatId) /// public Task add_to_favorites(string userId) { - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/x{communityId}/s/user-group/quick-access/{userId}"); - request.AddHeaders(headers); - var response = client.ExecutePost(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/x{communityId}/s/user-group/quick-access/{userId}"); + request.AddHeaders(headers); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } /// @@ -986,186 +986,187 @@ public Task add_to_favorites(string userId) /// The ID of the current transaction, can be left empy /// /// - public Task send_coins(string targetId, int coins,Types.Send_Coin_Targets type, string transactionId = null) + public Task send_coins(string targetId, int coins, Types.Send_Coin_Targets type, string transactionId = null) { - if(transactionId == null) { transactionId = helpers.generate_transaction_id(); } + if (transactionId == null) { transactionId = helpers.generate_transaction_id(); } string endpoint = ""; - JObject data = new JObject(); - JObject sub = new JObject(); - switch(type) - { - case Types.Send_Coin_Targets.Chat: - endpoint = $"/x{communityId}/s/chat/thread/{targetId}/tipping"; - break; - case Types.Send_Coin_Targets.Blog: - endpoint = $"/x{communityId}/s/blog/{targetId}/tipping"; - break; - case Types.Send_Coin_Targets.Wiki: - endpoint = $"/x{communityId}/s/tipping"; - data.Add("objectId", targetId); - data.Add("objectType", 2); - break; - } - data.Add("coins", coins); - data.Add("timestamp", helpers.GetTimestamp() * 1000); - sub.Add("transactionId", transactionId); - data.Add("tippingContext", sub); - - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest(endpoint); - request.AddHeaders(headers); - request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); - request.AddJsonBody(JsonConvert.SerializeObject(data)); - var response = client.ExecutePost(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + JObject data = new JObject(); + JObject sub = new JObject(); + switch (type) + { + case Types.Send_Coin_Targets.Chat: + endpoint = $"/x{communityId}/s/chat/thread/{targetId}/tipping"; + break; + case Types.Send_Coin_Targets.Blog: + endpoint = $"/x{communityId}/s/blog/{targetId}/tipping"; + break; + case Types.Send_Coin_Targets.Wiki: + endpoint = $"/x{communityId}/s/tipping"; + data.Add("objectId", targetId); + data.Add("objectType", 2); + break; + } + data.Add("coins", coins); + data.Add("timestamp", helpers.GetTimestamp() * 1000); + sub.Add("transactionId", transactionId); + data.Add("tippingContext", sub); + + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest(endpoint); + request.AddHeaders(headers); + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); + request.AddJsonBody(JsonConvert.SerializeObject(data)); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } public Task thank_tip(string chatId, string userId) { - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/x{communityId}/s/chat/thread/{chatId}/tipping/tipped-users/{userId}/thank"); - var response = client.ExecutePost(request); - if((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if(debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/x{communityId}/s/chat/thread/{chatId}/tipping/tipped-users/{userId}/thank"); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } public Task follow(List userIds) { - JObject data = new JObject(); - data.Add("timestamp", helpers.GetTimestamp() * 1000); - data.Add("targetUidList", new JArray(userIds)); - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/x{communityId}/s/user-profile/{this.client.userID}/joined"); - request.AddHeaders(headers); - request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); - request.AddJsonBody(JsonConvert.SerializeObject(data)); - var response = client.ExecutePost(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + JObject data = new JObject(); + data.Add("timestamp", helpers.GetTimestamp() * 1000); + data.Add("targetUidList", new JArray(userIds)); + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/x{communityId}/s/user-profile/{this.client.userID}/joined"); + request.AddHeaders(headers); + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); + request.AddJsonBody(JsonConvert.SerializeObject(data)); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } public Task follow(string userId) { - follow(new List() { userId }); - return Task.CompletedTask; + follow(new List() { userId }); + return Task.CompletedTask; } public Task unfollow(string userId) { - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/x{communityId}/s/user-profile/{this.client.userID}/joined/{userId}"); - request.AddHeaders(headers); - var response = client.Delete(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/x{communityId}/s/user-profile/{this.client.userID}/joined/{userId}"); + request.AddHeaders(headers); + var response = client.Delete(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } public Task block(string userId) { - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/x{communityId}/s/block/{userId}"); - request.AddHeaders(headers); - var response = client.ExecutePost(request); - if((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/x{communityId}/s/block/{userId}"); + request.AddHeaders(headers); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } public Task unblock(string userId) { - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/x{communityId}/s/block/{userId}"); - request.AddHeaders(headers); - var response = client.Delete(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/x{communityId}/s/block/{userId}"); + request.AddHeaders(headers); + var response = client.Delete(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } public Task visit(string userId) { - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/x{communityId}/s/user-profile/{userId}?action=visit"); - request.AddHeaders(headers); - var response = client.ExecuteGet(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/x{communityId}/s/user-profile/{userId}?action=visit"); + request.AddHeaders(headers); + var response = client.ExecuteGet(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } public Task flag(string targetId, string reason, Types.Flag_Types flagType, Types.Flag_Targets targetType, bool asGuest = false) { - string flg = asGuest ? "g-flag" : "flag"; - - JObject data = new JObject(); - data.Add("timestamp", helpers.GetTimestamp() * 1000); - data.Add("flagType", (int)flagType); - data.Add("message", reason); - data.Add("objectId", targetId); - data.Add("objectType", (int)targetType); - - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/x{communityId}/s/{flg}"); - request.AddHeaders(headers); - request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); - request.AddJsonBody(JsonConvert.SerializeObject(data)); - var response = client.ExecutePost(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + string flg = asGuest ? "g-flag" : "flag"; + + JObject data = new JObject(); + data.Add("timestamp", helpers.GetTimestamp() * 1000); + data.Add("flagType", (int)flagType); + data.Add("message", reason); + data.Add("objectId", targetId); + data.Add("objectType", (int)targetType); + + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/x{communityId}/s/{flg}"); + request.AddHeaders(headers); + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); + request.AddJsonBody(JsonConvert.SerializeObject(data)); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } public Objects.Message send_message(string message, string chatId, Types.Message_Types messageType = Types.Message_Types.General, string replyTo = null, List mentionUserIds = null) { - List mentions = new List(); - if(mentionUserIds == null) { mentionUserIds = new List(); } else + List mentions = new List(); + if (mentionUserIds == null) { mentionUserIds = new List(); } + else + { + foreach (string user in mentionUserIds) { - foreach(string user in mentionUserIds) - { - JObject _mention = new JObject(); - _mention.Add("uid", user); - mentions.Add(_mention); - } + JObject _mention = new JObject(); + _mention.Add("uid", user); + mentions.Add(_mention); } - message = message.Replace("<$", "").Replace("$>", ""); - JObject data = new JObject(); - JObject attachementSub = new JObject(); - JObject extensionSub = new JObject(); - JObject extensionSuBArray = new JObject(); - data.Add("type", (int)messageType); - data.Add("content", message); - data.Add("clientRefId", helpers.GetTimestamp() / 10 % 1000000000); - data.Add("timestamp", helpers.GetTimestamp() * 1000); - attachementSub.Add("objectId", null); - attachementSub.Add("objectType", null); - attachementSub.Add("link", null); - attachementSub.Add("title", null); - attachementSub.Add("content", null); - attachementSub.Add("mediaList", null); - extensionSuBArray.Add("link", null); - extensionSuBArray.Add("mediaType", 100); - extensionSuBArray.Add("mediaUploadValue", null); - extensionSuBArray.Add("mediaUploadValueContentType", "image/jpg"); - extensionSub.Add("mentionedArray", new JArray(mentions)); - extensionSub.Add("linkSnippetList", new JArray(extensionSuBArray)); - data.Add("attachedObject", attachementSub); - data.Add("extensions", extensionSub); - if(replyTo != null) { data.Add("replyMessageId", replyTo); } - - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/x{communityId}/s/chat/thread/{chatId}/message"); - request.AddHeaders(headers); - request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); - request.AddJsonBody(JsonConvert.SerializeObject(data)); - var response = client.ExecutePost(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return new Objects.Message(JObject.Parse(response.Content)); + } + message = message.Replace("<$", "").Replace("$>", ""); + JObject data = new JObject(); + JObject attachementSub = new JObject(); + JObject extensionSub = new JObject(); + JObject extensionSuBArray = new JObject(); + data.Add("type", (int)messageType); + data.Add("content", message); + data.Add("clientRefId", helpers.GetTimestamp() / 10 % 1000000000); + data.Add("timestamp", helpers.GetTimestamp() * 1000); + attachementSub.Add("objectId", null); + attachementSub.Add("objectType", null); + attachementSub.Add("link", null); + attachementSub.Add("title", null); + attachementSub.Add("content", null); + attachementSub.Add("mediaList", null); + extensionSuBArray.Add("link", null); + extensionSuBArray.Add("mediaType", 100); + extensionSuBArray.Add("mediaUploadValue", null); + extensionSuBArray.Add("mediaUploadValueContentType", "image/jpg"); + extensionSub.Add("mentionedArray", new JArray(mentions)); + extensionSub.Add("linkSnippetList", new JArray(extensionSuBArray)); + data.Add("attachedObject", attachementSub); + data.Add("extensions", extensionSub); + if (replyTo != null) { data.Add("replyMessageId", replyTo); } + + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/x{communityId}/s/chat/thread/{chatId}/message"); + request.AddHeaders(headers); + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); + request.AddJsonBody(JsonConvert.SerializeObject(data)); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return new Objects.Message(JObject.Parse(response.Content)); } public Task send_file_message(string chatId, byte[] file, Types.upload_File_Types fileType) @@ -1192,7 +1193,7 @@ public Task send_file_message(string chatId, byte[] file, Types.upload_File_Type data.Add("attachedObject", attachementSub); data.Add("extensions", extensionSub); - switch(fileType) + switch (fileType) { case Types.upload_File_Types.Image: data.Add("mediaType", 100); @@ -1210,7 +1211,7 @@ public Task send_file_message(string chatId, byte[] file, Types.upload_File_Type break; } data.Add("mediaUploadValue", Encoding.UTF8.GetString(Convert.FromBase64String(Convert.ToBase64String(file)))); - + RestClient client = new RestClient(helpers.BaseUrl); RestRequest request = new RestRequest($"/x{communityId}/s/chat/thread/{chatId}/message"); @@ -1225,15 +1226,15 @@ public Task send_file_message(string chatId, byte[] file, Types.upload_File_Type public Task send_file_message(string chatId, string filePath, Types.upload_File_Types fileType) { - send_file_message(chatId, File.ReadAllBytes(filePath), fileType); - return Task.CompletedTask; + send_file_message(chatId, File.ReadAllBytes(filePath), fileType); + return Task.CompletedTask; } public Task send_embed(string chatId, string content = null, string embedId = null, string embedLink = null, string embedTitle = null, string embedContent = null, byte[] embedImage = null) { - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/x{communityId}/s/chat/thread/{chatId}/message"); - JObject data = new JObject + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/x{communityId}/s/chat/thread/{chatId}/message"); + JObject data = new JObject { { "type", 0 }, { "content", content }, @@ -1257,13 +1258,13 @@ public Task send_embed(string chatId, string content = null, string embedId = nu }; - request.AddHeaders(headers); - request.AddJsonBody(JsonConvert.SerializeObject(data)); - request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); - var response = client.ExecutePost(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + request.AddHeaders(headers); + request.AddJsonBody(JsonConvert.SerializeObject(data)); + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } public Task send_embed(string chatId, string content = null, string embedId = null, string embedLink = null, string embedTitle = null, string embedContent = null, string embedImagePath = null) @@ -1274,259 +1275,260 @@ public Task send_embed(string chatId, string content = null, string embedId = nu public Task send_sticker(string chatId, string stickerId) { - JObject data = new JObject(); - JObject attachementSub = new JObject(); - JObject extensionSub = new JObject(); - JObject extensionSuBArray = new JObject(); - data.Add("type", 3); - data.Add("content", null); - data.Add("clientRefId", helpers.GetTimestamp() / 10 % 1000000000); - data.Add("timestamp", helpers.GetTimestamp() * 1000); - attachementSub.Add("objectId", null); - attachementSub.Add("objectType", null); - attachementSub.Add("link", null); - attachementSub.Add("title", null); - attachementSub.Add("content", null); - attachementSub.Add("mediaList", null); - extensionSuBArray.Add("link", null); - extensionSuBArray.Add("mediaType", 100); - extensionSuBArray.Add("mediaUploadValue", null); - extensionSuBArray.Add("mediaUploadValueContentType", "image/jpg"); - extensionSub.Add("mentionedArray", new JArray()); - extensionSub.Add("linkSnippetList", new JArray(extensionSuBArray)); - data.Add("attachedObject", attachementSub); - data.Add("extensions", extensionSub); - data.Add("stickerId", stickerId); - - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/x{communityId}/s/chat/thread/{chatId}/message"); - request.AddHeaders(headers); - request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); - request.AddJsonBody(JsonConvert.SerializeObject(data)); - var response = client.ExecutePost(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; - } + JObject data = new JObject(); + JObject attachementSub = new JObject(); + JObject extensionSub = new JObject(); + JObject extensionSuBArray = new JObject(); + data.Add("type", 3); + data.Add("content", null); + data.Add("clientRefId", helpers.GetTimestamp() / 10 % 1000000000); + data.Add("timestamp", helpers.GetTimestamp() * 1000); + attachementSub.Add("objectId", null); + attachementSub.Add("objectType", null); + attachementSub.Add("link", null); + attachementSub.Add("title", null); + attachementSub.Add("content", null); + attachementSub.Add("mediaList", null); + extensionSuBArray.Add("link", null); + extensionSuBArray.Add("mediaType", 100); + extensionSuBArray.Add("mediaUploadValue", null); + extensionSuBArray.Add("mediaUploadValueContentType", "image/jpg"); + extensionSub.Add("mentionedArray", new JArray()); + extensionSub.Add("linkSnippetList", new JArray(extensionSuBArray)); + data.Add("attachedObject", attachementSub); + data.Add("extensions", extensionSub); + data.Add("stickerId", stickerId); - public Task delete_message(string chatId, string messageId, bool asStaff = false, string reason = null) - { - string endPoint = $"/x{communityId}/s/chat/thread/{chatId}/message/{messageId}"; - JObject data = new JObject(); - data.Add("adminOpName", 102); - data.Add("timestamp", helpers.GetTimestamp() * 1000); - if((asStaff && reason != null)) { data.Add("adminOpNote", reason); } - if(asStaff) { endPoint = endPoint + "/admin"; } - - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest(endPoint); - request.AddHeaders(headers); - if(asStaff) - { - request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); - request.AddJsonBody(JsonConvert.SerializeObject(data)); - var response = client.ExecutePost(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - } else - { - var response = client.Delete(request); - if((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if(debug) { Trace.WriteLine(response.Content); } - } - return Task.CompletedTask; + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/x{communityId}/s/chat/thread/{chatId}/message"); + request.AddHeaders(headers); + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); + request.AddJsonBody(JsonConvert.SerializeObject(data)); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } - public Task mark_as_read(string chatId, string messageId) + public Task delete_message(string chatId, string messageId, bool asStaff = false, string reason = null) { - JObject data = new JObject(); - data.Add("messageId", messageId); - data.Add("timestamp", helpers.GetTimestamp() * 1000); + string endPoint = $"/x{communityId}/s/chat/thread/{chatId}/message/{messageId}"; + JObject data = new JObject(); + data.Add("adminOpName", 102); + data.Add("timestamp", helpers.GetTimestamp() * 1000); + if ((asStaff && reason != null)) { data.Add("adminOpNote", reason); } + if (asStaff) { endPoint = endPoint + "/admin"; } - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/x{communityId}/s/chat/thread/{chatId}/mark-as-read"); - request.AddHeaders(headers); + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest(endPoint); + request.AddHeaders(headers); + if (asStaff) + { request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); request.AddJsonBody(JsonConvert.SerializeObject(data)); var response = client.ExecutePost(request); if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + } + else + { + var response = client.Delete(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + } + return Task.CompletedTask; + } + + public Task mark_as_read(string chatId, string messageId) + { + JObject data = new JObject(); + data.Add("messageId", messageId); + data.Add("timestamp", helpers.GetTimestamp() * 1000); + + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/x{communityId}/s/chat/thread/{chatId}/mark-as-read"); + request.AddHeaders(headers); + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); + request.AddJsonBody(JsonConvert.SerializeObject(data)); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } public Task transfer_host(string chatId, List userIds) { - JObject data = new JObject(); - data.Add("uidList", new JArray(userIds)); - data.Add("timestamp", helpers.GetTimestamp() * 1000); - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/x{communityId}/s/chat/thread/{chatId}/transfer-organizer"); - request.AddHeaders(headers); - request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); - request.AddJsonBody(JsonConvert.SerializeObject(data)); - var response = client.ExecutePost(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + JObject data = new JObject(); + data.Add("uidList", new JArray(userIds)); + data.Add("timestamp", helpers.GetTimestamp() * 1000); + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/x{communityId}/s/chat/thread/{chatId}/transfer-organizer"); + request.AddHeaders(headers); + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); + request.AddJsonBody(JsonConvert.SerializeObject(data)); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } public Task transfer_host(string chatId, string userId) { - return transfer_host(chatId, new List { userId }); + return transfer_host(chatId, new List { userId }); } public Task accept_host(string chatId, string requestId) { - JObject data = new JObject(); - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/x{communityId}/s/chat/thread/{chatId}/transfer-organizer/{requestId}/accept"); - request.AddHeaders(headers); - request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); - request.AddJsonBody(JsonConvert.SerializeObject(data)); - var response = client.ExecutePost(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + JObject data = new JObject(); + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/x{communityId}/s/chat/thread/{chatId}/transfer-organizer/{requestId}/accept"); + request.AddHeaders(headers); + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); + request.AddJsonBody(JsonConvert.SerializeObject(data)); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } public Task join_chat(string chatId) { - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/x{communityId}/s/chat/thread/{chatId}/member/{this.client.userID}"); - request.AddHeaders(headers); - var response = client.ExecutePost(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/x{communityId}/s/chat/thread/{chatId}/member/{this.client.userID}"); + request.AddHeaders(headers); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } public Task leave_chat(string chatId) { - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/x{communityId}/s/chat/thread/{chatId}/member/{this.client.userID}"); - request.AddHeaders(headers); - var response = client.Delete(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/x{communityId}/s/chat/thread/{chatId}/member/{this.client.userID}"); + request.AddHeaders(headers); + var response = client.Delete(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } public List get_user_following(string userId, int start = 0, int size = 25) { if (start < 0) { throw new Exception("start cannot be lower than 0"); } - List userFollowingsList = new List(); - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/x{communityId}/s/user-profile/{userId}/joined?start={start}&size={size}"); - request.AddHeaders(headers); - var response = client.ExecuteGet(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(response.Content); - JArray userFollowings = jsonObj["userProfileList"]; - foreach (JObject following in userFollowings) - { - Objects.UserFollowings _following = new Objects.UserFollowings(following); - userFollowingsList.Add(_following); - } - return userFollowingsList; + List userFollowingsList = new List(); + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/x{communityId}/s/user-profile/{userId}/joined?start={start}&size={size}"); + request.AddHeaders(headers); + var response = client.ExecuteGet(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(response.Content); + JArray userFollowings = jsonObj["userProfileList"]; + foreach (JObject following in userFollowings) + { + Objects.UserFollowings _following = new Objects.UserFollowings(following); + userFollowingsList.Add(_following); + } + return userFollowingsList; } public List get_user_followers(string userId, int start = 0, int size = 25) { if (start < 0) { throw new Exception("start cannot be lower than 0"); } - List userFollowerList = new List(); - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/x{communityId}/s/user-profile/{userId}/member?start={start}&size={size}"); - request.AddHeaders(headers); - var response = client.ExecuteGet(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(response.Content); - JArray userFollowers = jsonObj["userProfileList"]; - foreach (JObject follower in userFollowers) - { - Objects.UserFollowings _follower = new Objects.UserFollowings(follower); - userFollowerList.Add(_follower); - } - return userFollowerList; + List userFollowerList = new List(); + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/x{communityId}/s/user-profile/{userId}/member?start={start}&size={size}"); + request.AddHeaders(headers); + var response = client.ExecuteGet(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(response.Content); + JArray userFollowers = jsonObj["userProfileList"]; + foreach (JObject follower in userFollowers) + { + Objects.UserFollowings _follower = new Objects.UserFollowings(follower); + userFollowerList.Add(_follower); + } + return userFollowerList; } public Objects.UserProfile get_user_info(string userId) { - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/x{communityId}/s/user-profile/{userId}"); - request.AddHeaders(headers); - var response = client.ExecuteGet(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - Amino.Objects.UserProfile profile = new Amino.Objects.UserProfile((JObject)JObject.Parse(response.Content)["userProfile"]); - return profile; + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/x{communityId}/s/user-profile/{userId}"); + request.AddHeaders(headers); + var response = client.ExecuteGet(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + Amino.Objects.UserProfile profile = new Amino.Objects.UserProfile((JObject)JObject.Parse(response.Content)["userProfile"]); + return profile; } public Task comment(string message, Types.Comment_Types type, string objectId) { string _eventSource; bool _isReply = false; - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest(); - request.AddHeaders(headers); - JObject data = new JObject(); - data.Add("content", message); - data.Add("stickerId", null); - data.Add("type", 0); - data.Add("timestamp", helpers.GetTimestamp() * 1000); + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest(); + request.AddHeaders(headers); + JObject data = new JObject(); + data.Add("content", message); + data.Add("stickerId", null); + data.Add("type", 0); + data.Add("timestamp", helpers.GetTimestamp() * 1000); - switch (type) - { - case Types.Comment_Types.User: - request.Resource = $"/x{communityId}/s/user-profile/{objectId}/g-comment"; - _eventSource = "UserProfileView"; - break; - case Types.Comment_Types.Blog: - request.Resource = $"/x{communityId}/s/blog/{objectId}/g-comment"; - _eventSource = "PostDetailView"; - break; - case Types.Comment_Types.Wiki: - request.Resource = $"/x{communityId}/s/item/{objectId}/g-comment"; - _eventSource = "PostDetailView"; - break; - case Types.Comment_Types.Reply: - _isReply = true; - _eventSource = ""; - break; - default: - request.Resource = $"/x{communityId}/s/user-profile/{objectId}/g-comment"; - _eventSource = "UserProfileView"; - break; - } - if (!_isReply) { data.Add("eventSource", _eventSource); } else { data.Add("respondTo", objectId); } - request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(System.Text.Json.JsonSerializer.Serialize(data.ToString()))); - request.AddJsonBody(data); - var response = client.ExecutePost(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - return Task.CompletedTask; + switch (type) + { + case Types.Comment_Types.User: + request.Resource = $"/x{communityId}/s/user-profile/{objectId}/g-comment"; + _eventSource = "UserProfileView"; + break; + case Types.Comment_Types.Blog: + request.Resource = $"/x{communityId}/s/blog/{objectId}/g-comment"; + _eventSource = "PostDetailView"; + break; + case Types.Comment_Types.Wiki: + request.Resource = $"/x{communityId}/s/item/{objectId}/g-comment"; + _eventSource = "PostDetailView"; + break; + case Types.Comment_Types.Reply: + _isReply = true; + _eventSource = ""; + break; + default: + request.Resource = $"/x{communityId}/s/user-profile/{objectId}/g-comment"; + _eventSource = "UserProfileView"; + break; + } + if (!_isReply) { data.Add("eventSource", _eventSource); } else { data.Add("respondTo", objectId); } + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(System.Text.Json.JsonSerializer.Serialize(data.ToString()))); + request.AddJsonBody(data); + var response = client.ExecutePost(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; } public List get_user_visitors(string userId, int start = 0, int size = 25) { if (start < 0) { throw new Exception("start cannot be lower than 0"); } - List userVisitorList = new List(); - RestClient client = new RestClient(helpers.BaseUrl); - RestRequest request = new RestRequest($"/x{communityId}/s/user-profile/{userId}/visitors?start={start}&size={size}"); - request.AddHeaders(headers); - var response = client.ExecuteGet(request); - if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if (debug) { Trace.WriteLine(response.Content); } - dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(response.Content); - JArray userVisitors = jsonObj["visitors"]; - foreach (JObject visitor in userVisitors) - { - Objects.UserVisitor _visitor = new Objects.UserVisitor(visitor, jsonObj); - userVisitorList.Add(_visitor); - } - return userVisitorList; + List userVisitorList = new List(); + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/x{communityId}/s/user-profile/{userId}/visitors?start={start}&size={size}"); + request.AddHeaders(headers); + var response = client.ExecuteGet(request); + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } + dynamic jsonObj = (JObject)JsonConvert.DeserializeObject(response.Content); + JArray userVisitors = jsonObj["visitors"]; + foreach (JObject visitor in userVisitors) + { + Objects.UserVisitor _visitor = new Objects.UserVisitor(visitor, jsonObj); + userVisitorList.Add(_visitor); + } + return userVisitorList; } public Objects.UserCheckins get_user_checkins(string userId) @@ -1549,7 +1551,7 @@ public Objects.UserCheckins get_user_checkins(string userId) var response = client.ExecuteGet(request); if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } if (debug) { Trace.WriteLine(response.Content); } - foreach(JObject blog in JObject.Parse(response.Content)["blogList"]) + foreach (JObject blog in JObject.Parse(response.Content)["blogList"]) { blogs.Add(new Objects.Blog(blog)); } @@ -1565,7 +1567,7 @@ public Objects.UserCheckins get_user_checkins(string userId) var response = client.ExecuteGet(request); if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } if (debug) { Trace.WriteLine(response.Content); } - foreach(JObject wiki in JObject.Parse(response.Content)["itemList"]) + foreach (JObject wiki in JObject.Parse(response.Content)["itemList"]) { wikis.Add(new Objects.Wiki(wiki)); } @@ -1589,10 +1591,10 @@ public Objects.InfluencerInfo get_influencer_info(string userId, int start = 0, RestRequest request = new RestRequest($"/x{communityId}/s/influencer/{userId}/fans?start={start}&size={size}"); request.AddHeaders(headers); var response = client.ExecuteGet(request); - if((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if(debug) { Trace.WriteLine(response.Content); } + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } return new(JObject.Parse(response.Content)); - + } public Task add_influencer(string userId, int monthlyFee) @@ -1653,9 +1655,9 @@ public Task subscribe(string userId, bool autoRenew = false, string transactionI RestRequest request = new RestRequest($"/x{communityId}/s/block?start={start}&size={size}"); request.AddHeaders(headers); var response = client.ExecuteGet(request); - if((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } if (debug) { Trace.WriteLine(response.Content); } - foreach(JObject user in JObject.Parse(response.Content)["userProfileList"]) + foreach (JObject user in JObject.Parse(response.Content)["userProfileList"]) { blocked.Add(new(user)); } @@ -1670,8 +1672,8 @@ public List get_blocker_users(int start = 0, int size = 25) request.AddHeaders(headers); var response = client.ExecuteGet(request); if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if(debug) { Trace.WriteLine(response.Content); } - foreach(string blocker in JObject.Parse(response.Content)["blockerUidList"]) { blockers.Add(blocker); } + if (debug) { Trace.WriteLine(response.Content); } + foreach (string blocker in JObject.Parse(response.Content)["blockerUidList"]) { blockers.Add(blocker); } return blockers; } @@ -1683,8 +1685,8 @@ public List get_blocker_users(int start = 0, int size = 25) request.AddHeaders(headers); var response = client.ExecuteGet(request); if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if(debug) { Trace.WriteLine(response.Content); } - foreach(JObject user in JObject.Parse(response.Content)["userProfileList"]) { leaderboard.Add(new(user)); } + if (debug) { Trace.WriteLine(response.Content); } + foreach (JObject user in JObject.Parse(response.Content)["userProfileList"]) { leaderboard.Add(new(user)); } return leaderboard; } @@ -1695,8 +1697,8 @@ public Objects.Wiki get_wiki_info(string wikiId) RestRequest request = new RestRequest($"/x{communityId}/s/item/{wikiId}"); request.AddHeaders(headers); var response = client.ExecuteGet(request); - if((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if(debug) { Trace.WriteLine(response.Content); } + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } return new((JObject)JObject.Parse(response.Content)["item"]); } @@ -1708,8 +1710,8 @@ public Task kick_from_chat(string userId, string chatId, bool allowRejoin = true request.AddHeaders(headers); var response = client.Delete(request); - if((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if(debug) { Trace.WriteLine(response.Content); } + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; } @@ -1732,8 +1734,8 @@ public Task handle_promotion(string noticeId, bool accept = true) RestRequest request = new RestRequest($"/x{communityId}/s/notice/{noticeId}/{_type}"); request.AddHeaders(headers); var response = client.ExecutePost(request); - if((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if(debug) { Trace.WriteLine(response.Content); } + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; } @@ -1768,8 +1770,8 @@ public Task play_quiz(string quizId, List questionIdList, List a request.AddJsonBody(JsonConvert.SerializeObject(data)); request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); var response = client.ExecutePost(request); - if((int)response.StatusCode != 200) { throw new Exception(response.Content); } - if(debug) { Trace.WriteLine(response.Content); } + if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if (debug) { Trace.WriteLine(response.Content); } return Task.CompletedTask; } From d6c3f96e62e74bbb0e0df55aaa80b6f006a9cb17 Mon Sep 17 00:00:00 2001 From: Fabio Gaming Date: Tue, 16 Apr 2024 21:46:18 +0200 Subject: [PATCH 05/30] Create tests.yml --- .github/workflows/tests.yml | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..3603326 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,25 @@ +name: Dev Test + +on: + pull_request: + branches: + - dev + +jobs: + test: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup .NET + uses: actions/setup-dotnet@v1 + with: + dotnet-version: '7.x' + + - name: Restore dependencies + run: dotnet restore + + - name: Build and test + run: dotnet build --configuration Release && dotnet test --no-build --verbosity normal From fddc33ba4dc67d877fc8e818b4321dd746901391 Mon Sep 17 00:00:00 2001 From: Fabio Gaming Date: Tue, 16 Apr 2024 21:47:55 +0200 Subject: [PATCH 06/30] Update FUNDING.yml --- .github/FUNDING.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/FUNDING.yml b/.github/FUNDING.yml index bc78310..4fd618a 100644 --- a/.github/FUNDING.yml +++ b/.github/FUNDING.yml @@ -1,13 +1,13 @@ # These are supported funding model platforms github: # Replace with up to 4 GitHub Sponsors-enabled usernames e.g., [user1, user2] -patreon: fabiogaming +patreon: # open_collective: # Replace with a single Open Collective username -ko_fi: # Replace with a single Ko-fi username +ko_fi: fabiothefox tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry liberapay: # Replace with a single Liberapay username issuehunt: # Replace with a single IssueHunt username otechie: # Replace with a single Otechie username lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry -custom: ["https://www.paypal.me/FabioTheFox", ] +custom: [] From dff43a3bad9fb995c80741528a33706206e4c597 Mon Sep 17 00:00:00 2001 From: Fabio Gaming Date: Tue, 16 Apr 2024 23:13:51 +0200 Subject: [PATCH 07/30] Create dev-autopublish --- .github/workflows/dev-autopublish | 35 +++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 .github/workflows/dev-autopublish diff --git a/.github/workflows/dev-autopublish b/.github/workflows/dev-autopublish new file mode 100644 index 0000000..42335be --- /dev/null +++ b/.github/workflows/dev-autopublish @@ -0,0 +1,35 @@ +name: Publish NuGet Package + +on: + push: + branches: + - dev + +jobs: + publish: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup .NET + uses: actions/setup-dotnet@v1 + with: + dotnet-version: '7.x' # or the version you are using + + - name: Restore dependencies + run: dotnet restore + + - name: Build + run: dotnet build --configuration Release + + - name: Determine version + id: version + run: echo "::set-output name=version::0.$((${GITHUB_RUN_NUMBER} / 100)).$((${GITHUB_RUN_NUMBER} % 100))" + + - name: Pack + run: dotnet pack --configuration Release --version-suffix "-dev${{ steps.version.outputs.version }}" --output nupkgs + + - name: Publish to NuGet + run: dotnet nuget push nupkgs/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json From 059fc28968932dddbb60836945b01935fac865a6 Mon Sep 17 00:00:00 2001 From: Fabio Gaming Date: Tue, 16 Apr 2024 23:14:22 +0200 Subject: [PATCH 08/30] Rename dev-autopublish to dev-autopublish.yml --- .github/workflows/{dev-autopublish => dev-autopublish.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{dev-autopublish => dev-autopublish.yml} (100%) diff --git a/.github/workflows/dev-autopublish b/.github/workflows/dev-autopublish.yml similarity index 100% rename from .github/workflows/dev-autopublish rename to .github/workflows/dev-autopublish.yml From d76f4d65a91d144f180f1c303685ee282d60a4bd Mon Sep 17 00:00:00 2001 From: Fabio Gaming Date: Tue, 16 Apr 2024 23:21:06 +0200 Subject: [PATCH 09/30] Update dev-autopublish.yml --- .github/workflows/dev-autopublish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dev-autopublish.yml b/.github/workflows/dev-autopublish.yml index 42335be..22045d2 100644 --- a/.github/workflows/dev-autopublish.yml +++ b/.github/workflows/dev-autopublish.yml @@ -16,7 +16,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v1 with: - dotnet-version: '7.x' # or the version you are using + dotnet-version: '7.x' - name: Restore dependencies run: dotnet restore From e786664ed846e222e7d8dbd520a6097a4a9834d0 Mon Sep 17 00:00:00 2001 From: Fabio Gaming Date: Tue, 16 Apr 2024 23:26:04 +0200 Subject: [PATCH 10/30] Update Amino.NET.csproj --- Amino.NET/Amino.NET.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Amino.NET/Amino.NET.csproj b/Amino.NET/Amino.NET.csproj index 30cb366..ccb7b3a 100644 --- a/Amino.NET/Amino.NET.csproj +++ b/Amino.NET/Amino.NET.csproj @@ -2,7 +2,7 @@ net7.0 - 1.5.1-Dev-7.1.2.8.3.5.0 + 1.5.2 FabioTheFox FabiDev An unofficial C# wrapper for Aminos REST API for making amino bots and tools From 5d43c102d3f792a8db5611e9aed571a2926e46dd Mon Sep 17 00:00:00 2001 From: Fabio Gaming Date: Wed, 17 Apr 2024 11:39:06 +0200 Subject: [PATCH 11/30] testing --- .github/workflows/dev-autopublish.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/dev-autopublish.yml b/.github/workflows/dev-autopublish.yml index 22045d2..ef3007c 100644 --- a/.github/workflows/dev-autopublish.yml +++ b/.github/workflows/dev-autopublish.yml @@ -30,6 +30,9 @@ jobs: - name: Pack run: dotnet pack --configuration Release --version-suffix "-dev${{ steps.version.outputs.version }}" --output nupkgs + + - name: Show-version + run: echo "-dev${{ steps.version.outputs.version }}" - - name: Publish to NuGet - run: dotnet nuget push nupkgs/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json + # - name: Publish to NuGet + # run: dotnet nuget push nupkgs/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json From 745b2efb2de905e0c3c5d710409521650179db4a Mon Sep 17 00:00:00 2001 From: Fabio Gaming Date: Wed, 17 Apr 2024 11:51:31 +0200 Subject: [PATCH 12/30] testing --- .github/workflows/dev-autopublish.yml | 48 +++++++++++++-------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/.github/workflows/dev-autopublish.yml b/.github/workflows/dev-autopublish.yml index ef3007c..9a41003 100644 --- a/.github/workflows/dev-autopublish.yml +++ b/.github/workflows/dev-autopublish.yml @@ -10,29 +10,29 @@ jobs: runs-on: ubuntu-latest steps: - - name: Checkout code - uses: actions/checkout@v2 + - name: Checkout code + uses: actions/checkout@v2 - - name: Setup .NET - uses: actions/setup-dotnet@v1 - with: - dotnet-version: '7.x' + - name: Setup .NET + uses: actions/setup-dotnet@v1 + with: + dotnet-version: '7.x' + + - name: Restore dependencies + run: dotnet restore - - name: Restore dependencies - run: dotnet restore - - - name: Build - run: dotnet build --configuration Release - - - name: Determine version - id: version - run: echo "::set-output name=version::0.$((${GITHUB_RUN_NUMBER} / 100)).$((${GITHUB_RUN_NUMBER} % 100))" - - - name: Pack - run: dotnet pack --configuration Release --version-suffix "-dev${{ steps.version.outputs.version }}" --output nupkgs - - - name: Show-version - run: echo "-dev${{ steps.version.outputs.version }}" - - # - name: Publish to NuGet - # run: dotnet nuget push nupkgs/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json + - name: Build + run: dotnet build --configuration Release + + - name: Determine project name + id: project_name + run: echo "::set-output name=name::$(*.csproj .csproj)" + + - name: Pack + run: | + version=$(dotnet project-file-name ${GITHUB_WORKSPACE}/${{ steps.project_name.outputs.name }}.csproj --version) + version="${version}-dev${GITHUB_RUN_NUMBER}" + dotnet pack --configuration Release /p:Version=$version --output nupkgs + + - name: Publish to NuGet + run: dotnet nuget push nupkgs/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json From 46c89d9550b1dd817c68d76541129d3acf925229 Mon Sep 17 00:00:00 2001 From: Fabio Gaming Date: Wed, 17 Apr 2024 11:59:42 +0200 Subject: [PATCH 13/30] more testing --- .github/workflows/dev-autopublish.yml | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/.github/workflows/dev-autopublish.yml b/.github/workflows/dev-autopublish.yml index 9a41003..499159e 100644 --- a/.github/workflows/dev-autopublish.yml +++ b/.github/workflows/dev-autopublish.yml @@ -26,12 +26,19 @@ jobs: - name: Determine project name id: project_name - run: echo "::set-output name=name::$(*.csproj .csproj)" + run: | + csproj_file=$(find . -name '*.csproj' -print -quit) + project_name=$(basename "$csproj_file" .csproj) + echo "::set-output name=name::$project_name" + - name: Determine version + id: version + run: echo "::set-output name=version::$(dotnet project-file-name ${GITHUB_WORKSPACE}/${{ steps.project_name.outputs.name }}.csproj --version)" + - name: Pack run: | - version=$(dotnet project-file-name ${GITHUB_WORKSPACE}/${{ steps.project_name.outputs.name }}.csproj --version) - version="${version}-dev${GITHUB_RUN_NUMBER}" + base_version="${{ steps.version.outputs.version }}" + version="${base_version}-dev0.$((${GITHUB_RUN_NUMBER} / 100)).$((${GITHUB_RUN_NUMBER} % 100))" dotnet pack --configuration Release /p:Version=$version --output nupkgs - name: Publish to NuGet From d3d534ec6f42d5083519d6506612eb8643d42fb3 Mon Sep 17 00:00:00 2001 From: Fabio Gaming Date: Wed, 17 Apr 2024 12:03:40 +0200 Subject: [PATCH 14/30] even more testing --- .github/workflows/dev-autopublish.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/dev-autopublish.yml b/.github/workflows/dev-autopublish.yml index 499159e..e093d0f 100644 --- a/.github/workflows/dev-autopublish.yml +++ b/.github/workflows/dev-autopublish.yml @@ -33,7 +33,10 @@ jobs: - name: Determine version id: version - run: echo "::set-output name=version::$(dotnet project-file-name ${GITHUB_WORKSPACE}/${{ steps.project_name.outputs.name }}.csproj --version)" + run: | + version=$(dotnet project-file-name ${GITHUB_WORKSPACE}/${{ steps.project_name.outputs.name }}.csproj --version) + version=$(echo "${version}" | tr -d '[:space:]') + echo "::set-output name=version::$version" - name: Pack run: | From 2d886b6c6e98179c7350ac9265eadb68e54e2417 Mon Sep 17 00:00:00 2001 From: Fabio Gaming Date: Wed, 17 Apr 2024 12:06:39 +0200 Subject: [PATCH 15/30] ungodly amounts of testing --- .github/workflows/dev-autopublish.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/dev-autopublish.yml b/.github/workflows/dev-autopublish.yml index e093d0f..6dd4082 100644 --- a/.github/workflows/dev-autopublish.yml +++ b/.github/workflows/dev-autopublish.yml @@ -34,8 +34,7 @@ jobs: - name: Determine version id: version run: | - version=$(dotnet project-file-name ${GITHUB_WORKSPACE}/${{ steps.project_name.outputs.name }}.csproj --version) - version=$(echo "${version}" | tr -d '[:space:]') + version=$(grep -oP '.*?' ${GITHUB_WORKSPACE}/${{ steps.project_name.outputs.name }}.csproj | grep -oP '\d+\.\d+\.\d+') echo "::set-output name=version::$version" - name: Pack From 12837723bbebbea68a74ce7ad6223704b4c934ef Mon Sep 17 00:00:00 2001 From: Fabio Gaming Date: Wed, 17 Apr 2024 12:13:57 +0200 Subject: [PATCH 16/30] idek anymore atp --- .github/workflows/dev-autopublish.yml | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/.github/workflows/dev-autopublish.yml b/.github/workflows/dev-autopublish.yml index 6dd4082..ccdb67d 100644 --- a/.github/workflows/dev-autopublish.yml +++ b/.github/workflows/dev-autopublish.yml @@ -18,16 +18,10 @@ jobs: with: dotnet-version: '7.x' - - name: Restore dependencies - run: dotnet restore - - - name: Build - run: dotnet build --configuration Release - - name: Determine project name id: project_name run: | - csproj_file=$(find . -name '*.csproj' -print -quit) + csproj_file=$(find ${GITHUB_WORKSPACE} -name '*.csproj' -print -quit) project_name=$(basename "$csproj_file" .csproj) echo "::set-output name=name::$project_name" From 5b187b0284551498816ee187d327f0695b621b64 Mon Sep 17 00:00:00 2001 From: Fabio Gaming Date: Wed, 17 Apr 2024 12:30:14 +0200 Subject: [PATCH 17/30] perchance --- .github/workflows/dev-autopublish.yml | 48 +++++++++++++++------------ 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/.github/workflows/dev-autopublish.yml b/.github/workflows/dev-autopublish.yml index ccdb67d..b78ce16 100644 --- a/.github/workflows/dev-autopublish.yml +++ b/.github/workflows/dev-autopublish.yml @@ -6,36 +6,40 @@ on: - dev jobs: - publish: + build_and_determine_base_version: runs-on: ubuntu-latest - + outputs: + base_version: ${{ steps.determine_version.outputs.base_version }} + steps: - name: Checkout code uses: actions/checkout@v2 - - - name: Setup .NET - uses: actions/setup-dotnet@v1 - with: - dotnet-version: '7.x' - - - name: Determine project name - id: project_name - run: | - csproj_file=$(find ${GITHUB_WORKSPACE} -name '*.csproj' -print -quit) - project_name=$(basename "$csproj_file" .csproj) - echo "::set-output name=name::$project_name" - + + - name: Build + run: dotnet build --configuration Release + - name: Determine version - id: version + id: determine_version run: | - version=$(grep -oP '.*?' ${GITHUB_WORKSPACE}/${{ steps.project_name.outputs.name }}.csproj | grep -oP '\d+\.\d+\.\d+') - echo "::set-output name=version::$version" - - - name: Pack + version=$(dotnet project-file-name YourProject.csproj --version) + echo "::set-output name=base_version::$version" + + rebuild_with_dev_version: + needs: build_and_determine_base_version + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v2 + + - name: Restore dependencies + run: dotnet restore + + - name: Rebuild with dev version run: | - base_version="${{ steps.version.outputs.version }}" + base_version="${{ needs.build_and_determine_base_version.outputs.base_version }}" version="${base_version}-dev0.$((${GITHUB_RUN_NUMBER} / 100)).$((${GITHUB_RUN_NUMBER} % 100))" dotnet pack --configuration Release /p:Version=$version --output nupkgs - + - name: Publish to NuGet run: dotnet nuget push nupkgs/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json From 071521386ec20b5bb713da2e5009750cc792ab82 Mon Sep 17 00:00:00 2001 From: Fabio Gaming Date: Wed, 17 Apr 2024 22:01:58 +0200 Subject: [PATCH 18/30] pluh --- .github/workflows/dev-autopublish.yml | 65 +++++++++++++-------------- 1 file changed, 30 insertions(+), 35 deletions(-) diff --git a/.github/workflows/dev-autopublish.yml b/.github/workflows/dev-autopublish.yml index b78ce16..f6b1e20 100644 --- a/.github/workflows/dev-autopublish.yml +++ b/.github/workflows/dev-autopublish.yml @@ -6,40 +6,35 @@ on: - dev jobs: - build_and_determine_base_version: + publish: runs-on: ubuntu-latest - outputs: - base_version: ${{ steps.determine_version.outputs.base_version }} - - steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Build - run: dotnet build --configuration Release - - - name: Determine version - id: determine_version - run: | - version=$(dotnet project-file-name YourProject.csproj --version) - echo "::set-output name=base_version::$version" - - rebuild_with_dev_version: - needs: build_and_determine_base_version - runs-on: ubuntu-latest - + steps: - - name: Checkout code - uses: actions/checkout@v2 - - - name: Restore dependencies - run: dotnet restore - - - name: Rebuild with dev version - run: | - base_version="${{ needs.build_and_determine_base_version.outputs.base_version }}" - version="${base_version}-dev0.$((${GITHUB_RUN_NUMBER} / 100)).$((${GITHUB_RUN_NUMBER} % 100))" - dotnet pack --configuration Release /p:Version=$version --output nupkgs - - - name: Publish to NuGet - run: dotnet nuget push nupkgs/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json + - name: Checkout code + uses: actions/checkout@v2 + + - name: Setup .NET + uses: actions/setup-dotnet@v1 + with: + dotnet-version: '7.x' + + - name: Restore dependencies + run: dotnet restore + + - name: Build + run: dotnet build --configuration Release + + - name: Determine version + id: version + run: echo "::set-output name=version::0.$((${GITHUB_RUN_NUMBER} / 100)).$((${GITHUB_RUN_NUMBER} % 100))" + + - name: Get Project Version + id: base_version + run: version=$(grep '' < .csproj | sed 's/.*\(.*\)<\/Version>/\1/') + echo "::set-output name=version::$version" + + - name: Pack + run: dotnet pack --configuration Release /p:Version="${{ steps.base_version.outputs.version }}-dev${{ steps.version.outputs.version }}" --output nupkgs + + - name: Publish to NuGet + run: dotnet nuget push nupkgs/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json From d6403502736c2315c3178dfc8e78a1ba4b48a3a1 Mon Sep 17 00:00:00 2001 From: Fabio Gaming Date: Wed, 17 Apr 2024 22:04:12 +0200 Subject: [PATCH 19/30] Pluh 2 --- .github/workflows/dev-autopublish.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/dev-autopublish.yml b/.github/workflows/dev-autopublish.yml index f6b1e20..4f704f6 100644 --- a/.github/workflows/dev-autopublish.yml +++ b/.github/workflows/dev-autopublish.yml @@ -26,11 +26,11 @@ jobs: - name: Determine version id: version - run: echo "::set-output name=version::0.$((${GITHUB_RUN_NUMBER} / 100)).$((${GITHUB_RUN_NUMBER} % 100))" + run: echo "::set-output name=version::0.$((${GITHUB_RUN_NUMBER} / 10)).$((${GITHUB_RUN_NUMBER} % 10))" - name: Get Project Version id: base_version - run: version=$(grep '' < .csproj | sed 's/.*\(.*\)<\/Version>/\1/') + run: version=$(grep '' < *.csproj | sed 's/.*\(.*\)<\/Version>/\1/') echo "::set-output name=version::$version" - name: Pack From 61b33dfc510d98bc977a7ed29166e44513c253d5 Mon Sep 17 00:00:00 2001 From: Fabio Gaming Date: Wed, 17 Apr 2024 22:05:45 +0200 Subject: [PATCH 20/30] Update dev-autopublish.yml --- .github/workflows/dev-autopublish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dev-autopublish.yml b/.github/workflows/dev-autopublish.yml index 4f704f6..3fc945d 100644 --- a/.github/workflows/dev-autopublish.yml +++ b/.github/workflows/dev-autopublish.yml @@ -30,7 +30,7 @@ jobs: - name: Get Project Version id: base_version - run: version=$(grep '' < *.csproj | sed 's/.*\(.*\)<\/Version>/\1/') + run: version=$(grep '' < Amino.NET.csproj | sed 's/.*\(.*\)<\/Version>/\1/') echo "::set-output name=version::$version" - name: Pack From 80b88ffea42dcfe62f28f352acc3f0777c70d5c1 Mon Sep 17 00:00:00 2001 From: Fabio Gaming Date: Wed, 17 Apr 2024 22:08:00 +0200 Subject: [PATCH 21/30] testingggg --- .github/workflows/dev-autopublish.yml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/.github/workflows/dev-autopublish.yml b/.github/workflows/dev-autopublish.yml index 3fc945d..47bd61e 100644 --- a/.github/workflows/dev-autopublish.yml +++ b/.github/workflows/dev-autopublish.yml @@ -28,6 +28,11 @@ jobs: id: version run: echo "::set-output name=version::0.$((${GITHUB_RUN_NUMBER} / 10)).$((${GITHUB_RUN_NUMBER} % 10))" + - name: Get Current Path + run: pwd + - name: Get Current dir Files + run: ls + - name: Get Project Version id: base_version run: version=$(grep '' < Amino.NET.csproj | sed 's/.*\(.*\)<\/Version>/\1/') From d6c1d5951a83ed282657f7d1bff4ef8c723de94e Mon Sep 17 00:00:00 2001 From: Fabio Gaming Date: Wed, 17 Apr 2024 22:09:17 +0200 Subject: [PATCH 22/30] testing path --- .github/workflows/dev-autopublish.yml | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/.github/workflows/dev-autopublish.yml b/.github/workflows/dev-autopublish.yml index 47bd61e..894ce05 100644 --- a/.github/workflows/dev-autopublish.yml +++ b/.github/workflows/dev-autopublish.yml @@ -27,15 +27,10 @@ jobs: - name: Determine version id: version run: echo "::set-output name=version::0.$((${GITHUB_RUN_NUMBER} / 10)).$((${GITHUB_RUN_NUMBER} % 10))" - - - name: Get Current Path - run: pwd - - name: Get Current dir Files - run: ls - name: Get Project Version id: base_version - run: version=$(grep '' < Amino.NET.csproj | sed 's/.*\(.*\)<\/Version>/\1/') + run: version=$(grep '' < Amino.NET/Amino.NET.csproj | sed 's/.*\(.*\)<\/Version>/\1/') echo "::set-output name=version::$version" - name: Pack From fef89ba37b52c5691ef2a3fd8d99ebed2d3d76f4 Mon Sep 17 00:00:00 2001 From: Fabio Gaming Date: Wed, 17 Apr 2024 22:14:19 +0200 Subject: [PATCH 23/30] Pluhhh --- .github/workflows/dev-autopublish.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/dev-autopublish.yml b/.github/workflows/dev-autopublish.yml index 894ce05..049dbce 100644 --- a/.github/workflows/dev-autopublish.yml +++ b/.github/workflows/dev-autopublish.yml @@ -30,8 +30,9 @@ jobs: - name: Get Project Version id: base_version - run: version=$(grep '' < Amino.NET/Amino.NET.csproj | sed 's/.*\(.*\)<\/Version>/\1/') - echo "::set-output name=version::$version" + run: | + version=$(grep '' < Amino.NET/Amino.NET.csproj | sed 's/.*\(.*\)<\/Version>/\1/') + echo "::set-output name=version::$version" - name: Pack run: dotnet pack --configuration Release /p:Version="${{ steps.base_version.outputs.version }}-dev${{ steps.version.outputs.version }}" --output nupkgs From 6e0f2813aeca032c93d1d8f234c90fbfda16d8a0 Mon Sep 17 00:00:00 2001 From: Fabio Gaming Date: Fri, 19 Apr 2024 10:51:27 +0200 Subject: [PATCH 24/30] refactored some code and added feature [ # ] SubClient.post_blog now accepts IEnumerable instead of List type [ # ] SubClient.post_wiki now accepts IEnumerable instead of List type [ # ] SubClient.edit_blog now accepts IEnumerable instead of List type [ + ] Added ability to pass Links into Client.upload_media(string), this allows people to pass custom media URLs into Amino Media --- Amino.NET/Client.cs | 8 ++++++-- Amino.NET/SubClient.cs | 6 +++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Amino.NET/Client.cs b/Amino.NET/Client.cs index e4a34e7..61e8a28 100644 --- a/Amino.NET/Client.cs +++ b/Amino.NET/Client.cs @@ -4,11 +4,10 @@ using System.Globalization; using System.IO; using System.Linq; +using System.Net.Http; using System.Text; using System.Threading; using System.Threading.Tasks; -using System.Threading.Tasks.Dataflow; -using Amino.Objects; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using RestSharp; @@ -1416,6 +1415,11 @@ public Task flag_community(string communityId, string reason, Types.Flag_Types f /// string : The URL to the media file you just uploaded public string upload_media(string filePath, Types.upload_File_Types type) { + if(filePath.StartsWith("http")) + { + byte[] fileBytes = new HttpClient().GetAsync(filePath).Result.Content.ReadAsByteArrayAsync().Result; + return upload_media(fileBytes, type); + } return upload_media(File.ReadAllBytes(filePath), type); } diff --git a/Amino.NET/SubClient.cs b/Amino.NET/SubClient.cs index f3c5d84..5c28894 100644 --- a/Amino.NET/SubClient.cs +++ b/Amino.NET/SubClient.cs @@ -147,7 +147,7 @@ public Task delete_invite_code(string inviteId) /// /// /// - public Task post_blog(string title, string content, List imageList = null, bool fansOnly = false, string backgroundColor = null) + public Task post_blog(string title, string content, IEnumerable imageList = null, bool fansOnly = false, string backgroundColor = null) { JArray mediaList = new JArray(); JObject extensionData = new JObject(); @@ -200,7 +200,7 @@ public Task post_blog(string title, string content, List imageList = nul /// /// /// - public Task post_wiki(string title, string content, List imageList = null, bool fansOnly = false, string backgroundColor = null) + public Task post_wiki(string title, string content, IEnumerable imageList = null, bool fansOnly = false, string backgroundColor = null) { JArray mediaList = new JArray(); JObject extensionData = new JObject(); @@ -249,7 +249,7 @@ public Task post_wiki(string title, string content, List imageList = nul /// /// /// - public Task edit_blog(string blogId, string title = null, string content = null, List imageList = null, bool fansOnly = false, string backgroundColor = null) + public Task edit_blog(string blogId, string title = null, string content = null, IEnumerable imageList = null, bool fansOnly = false, string backgroundColor = null) { JArray mediaList = new JArray(); JObject extensionData = new JObject(); From 0bd1bbd858b9bb75d9b4fcc3b9971ef7da31eff6 Mon Sep 17 00:00:00 2001 From: Fabio Gaming Date: Mon, 22 Apr 2024 12:02:50 +0200 Subject: [PATCH 25/30] Added more functions [ + ] Added Client.get_blog_info(string) [ + ] Added Client.get_wiki_info(string) [ + ] Added Client.get_message_info(string,string) --- Amino.NET/Client.cs | 53 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) diff --git a/Amino.NET/Client.cs b/Amino.NET/Client.cs index 61e8a28..4fca005 100644 --- a/Amino.NET/Client.cs +++ b/Amino.NET/Client.cs @@ -2425,6 +2425,59 @@ public Task send_sticker(string chatId, string stickerId) return Task.CompletedTask; } + /// + /// Allows you to get information about a blog post + /// + /// + /// + /// + public Objects.Blog get_blog_info(string blogId) + { + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/g/s/blog/{blogId}"); + request.AddHeaders(headers); + var response = client.ExecuteGet(request); + if((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if(debug) { Trace.WriteLine(response.Content); } + return new Objects.Blog(JObject.Parse(response.Content)); + } + + + /// + /// Allows you to get information about a wiki post + /// + /// + /// + /// + public Objects.Wiki get_wiki_info(string wikiId) + { + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/g/s/item/{wikiId}"); + request.AddHeaders(headers); + var response = client.ExecuteGet(request); + if((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if(debug) { Trace.WriteLine(response.Content); } + return new Objects.Wiki(JObject.Parse(response.Content)); + } + + /// + /// Allows you to get information about a message in a chat + /// + /// + /// + /// + /// + public Objects.Message get_message_info(string chatId, string messageId) + { + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/g/s/chat/thread/{chatId}/message/{messageId}"); + request.AddHeaders(headers); + var response = client.ExecuteGet(request); + if((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if(debug) { Trace.WriteLine(response.Content); } + return new Objects.Message(JObject.Parse(response.Content)); + } + /// /// Sets the SubClient of the Client, not for development use From 9a3d58f5cadfcd818c2b713b166efd6ccdeca1d2 Mon Sep 17 00:00:00 2001 From: Fabio Gaming Date: Mon, 22 Apr 2024 12:28:57 +0200 Subject: [PATCH 26/30] Added function template --- Amino.NET/Client.cs | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/Amino.NET/Client.cs b/Amino.NET/Client.cs index 4fca005..7069aff 100644 --- a/Amino.NET/Client.cs +++ b/Amino.NET/Client.cs @@ -2478,6 +2478,41 @@ public Objects.Message get_message_info(string chatId, string messageId) return new Objects.Message(JObject.Parse(response.Content)); } + /// + /// Allows you to get comments from a blog, THIS FUNCTION IS NOT FINISHED + /// + /// + /// + /// + /// + /// + /// + public List get_blog_comments(string blogId, int start = 0, int size = 25, Types.Sorting_Types sorting = Types.Sorting_Types.Newest) + { + string sortingType = ""; + switch(sorting) + { + case Types.Sorting_Types.Newest: + sortingType = "newest"; + break; + case Types.Sorting_Types.Oldest: + sortingType = "oldest"; + break; + case Types.Sorting_Types.Top: + sortingType = "vote"; + break; + } + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest($"/g/s/blog/{blogId}?sort={sortingType}&start={size}&size={size}"); + request.AddHeaders(headers); + var response = client.ExecuteGet(request); + if((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if(debug) { Trace.WriteLine(response.Content); } + + return null; // FINISH LATER + + } + /// /// Sets the SubClient of the Client, not for development use From 0a0bee23a21d7b08a14bdec84aa42e2ce1eae9ff Mon Sep 17 00:00:00 2001 From: Fabio Gaming Date: Thu, 25 Apr 2024 11:02:01 +0200 Subject: [PATCH 27/30] added functions [ + ] Added Client.register_google(string, string, string, string) [ # ] Client.register() should no longer throw invalid request --- Amino.NET/Client.cs | 43 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 42 insertions(+), 1 deletion(-) diff --git a/Amino.NET/Client.cs b/Amino.NET/Client.cs index 7069aff..69b248a 100644 --- a/Amino.NET/Client.cs +++ b/Amino.NET/Client.cs @@ -388,6 +388,47 @@ public Task login_sid(string sessionId, bool fetchProfile = true, bool connectSo return Task.CompletedTask; } + /// + /// Allows you to register an Amino account using a google account + /// + /// + /// + /// + /// + /// + /// + public Task register_google(string nickname, string googleToken, string password, string deviceId = null) + { + deviceId = deviceId == null ? helpers.generate_device_id() : deviceId; + RestClient client = new RestClient(helpers.BaseUrl); + RestRequest request = new RestRequest("/g/s/auth/login"); + request.AddHeaders(headers); + + Dictionary data = new Dictionary() + { + { "secret", $"12 {googleToken}" }, + { "secret2", $"0 {password}" }, + { "deviceID", deviceId }, + { "clientType", 100 }, + { "nickname", nickname }, + { "latitude", 0 }, + { "longitude", 0 }, + { "address", null }, + { "clientCallbackURL", "narviiapp://relogin" }, + { "timestamp", helpers.GetTimestamp() * 1000 }, + }; + + request.AddJsonBody(System.Text.Json.JsonSerializer.Serialize(data)); + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(System.Text.Json.JsonSerializer.Serialize(data))); + + var response = client.ExecutePost(request); + if((int)response.StatusCode != 200) { throw new Exception(response.Content); } + if(debug) { Trace.WriteLine(response.Content); } + return Task.CompletedTask; + } + + + /// /// Allows you to register an Amino account @@ -427,7 +468,7 @@ public Task register(string _name, string _email, string _password, string _veri RestClient client = new RestClient(helpers.BaseUrl); RestRequest request = new RestRequest("/g/s/auth/register"); request.AddHeaders(headers); - request.AddJsonBody(data); + request.AddJsonBody(JsonConvert.SerializeObject(data)); request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); var response = client.ExecutePost(request); if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } From 53e1b4f4328f333044d6beaad785a140000f23a2 Mon Sep 17 00:00:00 2001 From: Fabio Gaming Date: Thu, 25 Apr 2024 14:02:05 +0200 Subject: [PATCH 28/30] started builder class [ # ] Fixed Client.register() throwing invalid request due to newtonsoft JSON [ # ] Fixed typo in Types class [ + ] Added start of builder class --- Amino.NET/Builders/PostBuilder.cs | 39 +++++++++++++++++++++++++++++++ Amino.NET/Client.cs | 2 +- Amino.NET/Types.cs | 2 +- 3 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 Amino.NET/Builders/PostBuilder.cs diff --git a/Amino.NET/Builders/PostBuilder.cs b/Amino.NET/Builders/PostBuilder.cs new file mode 100644 index 0000000..6c72c80 --- /dev/null +++ b/Amino.NET/Builders/PostBuilder.cs @@ -0,0 +1,39 @@ +using System.Collections.Generic; +using System.IO; + +namespace Amino.NET.Builders +{ + public class PostBuilder + { + public byte[] CoverImage { get; private set; } + public string Content { get; set; } + public string Title { get; set; } + public Dictionary MediaList { get; } = new Dictionary(); + public PostTypes PostType { get; set; } = PostTypes.Blog; + + public void WithCover(byte[] cover) + { + CoverImage = cover; + } + public void WithCover(string coverPath) + { + WithCover(File.ReadAllBytes(coverPath)); + } + public void AddMedia(byte[] media, string mediaKey) + { + MediaList.Add(media, mediaKey); + } + + public void AddMedia(string mediaPath, string mediaKey) + { + AddMedia(File.ReadAllBytes(mediaPath), mediaKey); + } + + public enum PostTypes + { + Blog, + Wiki + } + + } +} diff --git a/Amino.NET/Client.cs b/Amino.NET/Client.cs index 69b248a..f4fed6a 100644 --- a/Amino.NET/Client.cs +++ b/Amino.NET/Client.cs @@ -456,7 +456,7 @@ public Task register(string _name, string _email, string _password, string _veri { "clientCallbackURL", "narviiapp://relogin" }, { "validationContext", new JObject() { - { "data", new JObject() { "code", _verificationCode } }, + { "data", new JObject() { {"code", _verificationCode } } }, { "type", 1 }, { "identity", _email } } diff --git a/Amino.NET/Types.cs b/Amino.NET/Types.cs index 556730d..b6293a3 100644 --- a/Amino.NET/Types.cs +++ b/Amino.NET/Types.cs @@ -127,7 +127,7 @@ public enum User_Types } public enum Featured_Types { - Unfreature, + Unfeature, User, Blog, Wiki, From ae4cecae8233259f7218fd3427f6264e99630dfc Mon Sep 17 00:00:00 2001 From: Fabio Gaming Date: Fri, 3 May 2024 11:02:05 +0200 Subject: [PATCH 29/30] finished demo PostBuilder [ # ] Changed PostBuilder.MediaList from Dictionary 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) --- Amino.NET/Builders/PostBuilder.cs | 35 ++++++++++++++++++++++++++----- Amino.NET/SubClient.cs | 22 ++++++++++++++++++- 2 files changed, 51 insertions(+), 6 deletions(-) diff --git a/Amino.NET/Builders/PostBuilder.cs b/Amino.NET/Builders/PostBuilder.cs index 6c72c80..d27f6cc 100644 --- a/Amino.NET/Builders/PostBuilder.cs +++ b/Amino.NET/Builders/PostBuilder.cs @@ -1,15 +1,22 @@ using System.Collections.Generic; +using System.ComponentModel; using System.IO; +using System.Reflection.Metadata.Ecma335; namespace Amino.NET.Builders { public class PostBuilder { public byte[] CoverImage { get; private set; } + public byte[] BackgroundImage { get; private set; } + public string BackgroundColor { get; private set; } = "#ffffff"; public string Content { get; set; } public string Title { get; set; } - public Dictionary MediaList { get; } = new Dictionary(); + public List<(byte[], string?, string?)> MediaList { get; } = new List<(byte[], string?, string?)>(); public PostTypes PostType { get; set; } = PostTypes.Blog; + public BackgroundTypes BackgroundType { get; set; } = BackgroundTypes.Color; + public bool FansOnly { get; set; } + public void WithCover(byte[] cover) { @@ -19,21 +26,39 @@ public void WithCover(string coverPath) { WithCover(File.ReadAllBytes(coverPath)); } - public void AddMedia(byte[] media, string mediaKey) + + public void WithBackgroundImage(byte[] media) + { + BackgroundImage = media; + } + + public void WithBackgroundImage(string mediaPath) { - MediaList.Add(media, mediaKey); + WithBackgroundImage(File.ReadAllBytes(mediaPath)); } - public void AddMedia(string mediaPath, string mediaKey) + public void AddMedia(byte[] media, string mediaKey = null, string caption = null) { - AddMedia(File.ReadAllBytes(mediaPath), mediaKey); + MediaList.Add((media, mediaKey, caption)); } + public void AddMedia(string mediaPath, string mediaKey = null, string caption = null) + { + AddMedia(File.ReadAllBytes(mediaPath), mediaKey, caption); + } + + public string EmbedImage(string mediaKey) => $"[IMG={mediaKey}]"; + public enum PostTypes { Blog, Wiki } + public enum BackgroundTypes + { + Color, + Image + } } } diff --git a/Amino.NET/SubClient.cs b/Amino.NET/SubClient.cs index 5c28894..7848021 100644 --- a/Amino.NET/SubClient.cs +++ b/Amino.NET/SubClient.cs @@ -1,4 +1,5 @@ -using Newtonsoft.Json; +using Amino.NET.Builders; +using Newtonsoft.Json; using Newtonsoft.Json.Linq; using RestSharp; using System; @@ -6,6 +7,7 @@ using System.Diagnostics; using System.Diagnostics.CodeAnalysis; using System.IO; +using System.Linq; using System.Reactive.Subjects; using System.Runtime.Serialization.Formatters; using System.Text; @@ -191,6 +193,24 @@ public Task post_blog(string title, string content, IEnumerable imageLis return Task.CompletedTask; } + public Task create_post(PostBuilder post) + { + List _media = new List(); + switch(post.PostType) + { + case PostBuilder.PostTypes.Blog: + foreach (var media in post.MediaList) { _media.Add(media.Item1); } + post_blog(post.Title, post.Content, _media, post.FansOnly, post.BackgroundColor); + break; + case PostBuilder.PostTypes.Wiki: + foreach (var media in post.MediaList) { _media.Add(media.Item1); } + post_wiki(post.Title, post.Content, _media, post.FansOnly, post.BackgroundColor); + break; + } + return Task.CompletedTask; + } + + /// /// Allows you to post a Wiki post on the current Community /// From 0ee266788b2be2861eb6100c2bf852bd7c7be0e1 Mon Sep 17 00:00:00 2001 From: Fabio Gaming Date: Mon, 6 May 2024 16:08:57 +0200 Subject: [PATCH 30/30] hopefully fixed send_message [ # ] Adapted the JSON payload to the hopefully proper format --- Amino.NET/SubClient.cs | 48 +----------------------------------------- 1 file changed, 1 insertion(+), 47 deletions(-) diff --git a/Amino.NET/SubClient.cs b/Amino.NET/SubClient.cs index 7848021..6a42e38 100644 --- a/Amino.NET/SubClient.cs +++ b/Amino.NET/SubClient.cs @@ -1155,27 +1155,11 @@ public Objects.Message send_message(string message, string chatId, Types.Message } message = message.Replace("<$", "").Replace("$>", ""); JObject data = new JObject(); - JObject attachementSub = new JObject(); - JObject extensionSub = new JObject(); - JObject extensionSuBArray = new JObject(); data.Add("type", (int)messageType); data.Add("content", message); data.Add("clientRefId", helpers.GetTimestamp() / 10 % 1000000000); data.Add("timestamp", helpers.GetTimestamp() * 1000); - attachementSub.Add("objectId", null); - attachementSub.Add("objectType", null); - attachementSub.Add("link", null); - attachementSub.Add("title", null); - attachementSub.Add("content", null); - attachementSub.Add("mediaList", null); - extensionSuBArray.Add("link", null); - extensionSuBArray.Add("mediaType", 100); - extensionSuBArray.Add("mediaUploadValue", null); - extensionSuBArray.Add("mediaUploadValueContentType", "image/jpg"); - extensionSub.Add("mentionedArray", new JArray(mentions)); - extensionSub.Add("linkSnippetList", new JArray(extensionSuBArray)); - data.Add("attachedObject", attachementSub); - data.Add("extensions", extensionSub); + data.Add("extensions", new JObject() { { "mentionedArray", new JArray(mentions) } }); if (replyTo != null) { data.Add("replyMessageId", replyTo); } RestClient client = new RestClient(helpers.BaseUrl); @@ -1192,26 +1176,10 @@ public Objects.Message send_message(string message, string chatId, Types.Message public Task send_file_message(string chatId, byte[] file, Types.upload_File_Types fileType) { JObject data = new JObject(); - JObject attachementSub = new JObject(); - JObject extensionSub = new JObject(); - JObject extensionSuBArray = new JObject(); data.Add("clientRefId", helpers.GetTimestamp() / 10 % 1000000000); data.Add("timestamp", helpers.GetTimestamp() * 1000); data.Add("content", null); data.Add("type", 0); - attachementSub.Add("objectId", null); - attachementSub.Add("objectType", null); - attachementSub.Add("link", null); - attachementSub.Add("title", null); - attachementSub.Add("content", null); - attachementSub.Add("mediaList", null); - extensionSuBArray.Add("link", null); - extensionSuBArray.Add("mediaType", 100); - extensionSuBArray.Add("mediaUploadValue", null); - extensionSuBArray.Add("mediaUploadValueContentType", "image/jpg"); - extensionSub.Add("linkSnippetList", new JArray(extensionSuBArray)); - data.Add("attachedObject", attachementSub); - data.Add("extensions", extensionSub); switch (fileType) { @@ -1303,20 +1271,6 @@ public Task send_sticker(string chatId, string stickerId) data.Add("content", null); data.Add("clientRefId", helpers.GetTimestamp() / 10 % 1000000000); data.Add("timestamp", helpers.GetTimestamp() * 1000); - attachementSub.Add("objectId", null); - attachementSub.Add("objectType", null); - attachementSub.Add("link", null); - attachementSub.Add("title", null); - attachementSub.Add("content", null); - attachementSub.Add("mediaList", null); - extensionSuBArray.Add("link", null); - extensionSuBArray.Add("mediaType", 100); - extensionSuBArray.Add("mediaUploadValue", null); - extensionSuBArray.Add("mediaUploadValueContentType", "image/jpg"); - extensionSub.Add("mentionedArray", new JArray()); - extensionSub.Add("linkSnippetList", new JArray(extensionSuBArray)); - data.Add("attachedObject", attachementSub); - data.Add("extensions", extensionSub); data.Add("stickerId", stickerId); RestClient client = new RestClient(helpers.BaseUrl);