diff --git a/Amino.NET/Amino.NET.csproj b/Amino.NET/Amino.NET.csproj index 572d942..c3f5bed 100644 --- a/Amino.NET/Amino.NET.csproj +++ b/Amino.NET/Amino.NET.csproj @@ -2,7 +2,7 @@ net5.0 - 1.3.0 + 1.4.0-Dev-7.1.2.8.3.2.4 FabioTheFox FabiDev An unofficial C# wrapper for Aminos REST API for making amino bots and tools diff --git a/Amino.NET/SubClient.cs b/Amino.NET/SubClient.cs index e1a02cf..a2f1ae6 100644 --- a/Amino.NET/SubClient.cs +++ b/Amino.NET/SubClient.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Diagnostics; +using System.IO; using System.Threading.Tasks; namespace Amino @@ -1091,6 +1092,339 @@ public Task add_to_favorites(string userId) catch(Exception e) { throw new Exception(e.Message); } } + public Task send_coins(string targetId, int coins,Types.Send_Coin_Targets type, string transactionId = null) + { + if(transactionId == null) { transactionId = helpers.generate_transaction_id(); } + string endpoint = ""; + try + { + 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; + } + 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)); + 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; + } + 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); + 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 block(string userId) + { + try + { + 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; + } + 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); + 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 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); + 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); } + } + + 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; + } + + JObject data = new JObject(); + data.Add("timestamp", helpers.GetTimestamp() * 1000); + data.Add("flagType", _flagType); + data.Add("message", reason); + data.Add("objectId", targetId); + data.Add("objectType", _objectType); + + 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; + + } + catch (Exception e) { throw new Exception(e.Message); } + } + + public Task 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 + { + foreach(string user in mentionUserIds) + { + 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 Task.CompletedTask; + } + catch (Exception e) { throw new Exception(e.Message); } + } + + public Task send_file_message(byte[] file, Types.upload_File_Types fileType) + { + return Task.CompletedTask; + } + + public Task send_file_message(string filePath, Types.upload_File_Types fileType) + { + try + { + send_file_message(File.ReadAllBytes(filePath), fileType); + return Task.CompletedTask; + } catch (Exception e) { throw new Exception(e.Message); } + + } + + public Task send_embed(string replyTo = null, string embedId = null, string embedLink = null, string embedTitle = null, string embedContent = null, byte[] embedImage = null, string linkSnipped = null, byte[] linkSnippedImage = null) + { + return Task.CompletedTask; + } + + public Task send_sticker(string chatId, string stickerId) + { + try + { + 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; + + } + catch(Exception e) { throw new Exception(e.Message); } + } + + + /// /// Not to be used in general use (THIS FUNCTION WILL DISPOSE THE SUBCLIENT) /// diff --git a/Amino.NET/Types.cs b/Amino.NET/Types.cs index 54657e6..201c654 100644 --- a/Amino.NET/Types.cs +++ b/Amino.NET/Types.cs @@ -85,6 +85,13 @@ public enum Repair_Types Membeership = 2 } + public enum Send_Coin_Targets + { + Chat, + Blog, + Wiki + } + /// /// Activity status types. /// @@ -169,52 +176,52 @@ public enum Object_Types } public enum Message_Types { - General, - Strike, - Voice, - Sticker, - Video, - Share_EXURL, - Share_User, - Call_Not_Answered, - Call_Cancelled, - Call_Declined, - Video_Call_Not_Answered, - Video_Call_Cancelled, - Video_Call_Declined, - Deleted, - Member_Join, - Member_Quit, - Private_Chat_Init, - Background_Change, - Title_Change, - Icon_Change, - Start_Voice_Chat, - Start_Video_Chat, - Start_Avatar_Chat, - End_Voice_Chat, - End_Video_Chat, - End_Avatar_Chat, - Content_Change, - Start_Screening_Room, - End_Screening_Room, - Organizer_Transferred, - Force_Removed_From_Chat, - Chat_Removed, - Deleted_By_Admin, - Send_Coins, - Pin_Announcement, - VV_Chat_Permission_Open_To_Everyone, - VV_Chat_Permission_Invited, - VV_Chat_Permission_Invite_Only, - Enable_View_Only, - Disable_View_Only, - Unpin_Announcement, - Enable_Tip_Permission, - Disable_Tip_Permission, - Timestamp, - Welcome_Message, - Invite_Message + General = 0, + Strike = 1, + Voice = 2, + Sticker = 3, + Video = 4, + Share_EXURL = 50, + Share_User = 51, + Call_Not_Answered = 55, + Call_Cancelled = 53, + Call_Declined = 54, + Video_Call_Not_Answered = 55, + Video_Call_Cancelled = 56, + Video_Call_Declined = 57, + Deleted = 100, + Member_Join = 101, + Member_Quit = 102, + Private_Chat_Init = 103, + Background_Change = 104, + Title_Change = 105, + Icon_Change = 106, + Start_Voice_Chat = 107, + Start_Video_Chat = 108, + Start_Avatar_Chat = 109, + End_Voice_Chat = 110, + End_Video_Chat = 111, + End_Avatar_Chat = 112, + Content_Change = 113, + Start_Screening_Room = 114, + End_Screening_Room = 115, + Organizer_Transferred = 116, + Force_Removed_From_Chat = 117, + Chat_Removed = 118, + Deleted_By_Admin = 119, + Send_Coins = 120, + Pin_Announcement = 121, + VV_Chat_Permission_Open_To_Everyone = 122, + VV_Chat_Permission_Invited = 123, + VV_Chat_Permission_Invite_Only = 124, + Enable_View_Only = 125, + Disable_View_Only = 126, + Unpin_Announcement = 127, + Enable_Tip_Permission = 128, + Disable_Tip_Permission = 129, + Timestamp = 65281, + Welcome_Message = 65282, + Invite_Message = 65283 } public enum Post_Types { diff --git a/Amino.NET/helpers.cs b/Amino.NET/helpers.cs index fc5b484..8b43369 100644 --- a/Amino.NET/helpers.cs +++ b/Amino.NET/helpers.cs @@ -13,7 +13,7 @@ public class helpers /// /// This value represents the baseURL to Aminos REST backend /// - public static string BaseUrl = "https://service.narvii.com/api/v1"; + public static string BaseUrl = "https://service.aminoapps.com/api/v1"; private static T[] CombineTwoArrays(T[] a1, T[] a2) { @@ -48,6 +48,19 @@ public static string generate_signiture(string data) return Convert.ToBase64String(CombineTwoArrays(StringToByteArray(prefix), result)); } + + + public static string generate_transaction_id() + { + var rng = new RNGCryptoServiceProvider(); + var buffer = new byte[16]; + rng.GetBytes(buffer); + var hex = BitConverter.ToString(buffer).Replace("-", "").ToLower(); + var uuid = Guid.ParseExact(hex, "N"); + return uuid.ToString(); + } + + /// /// Returns the current Amino compatible Timezone /// diff --git a/README.md b/README.md index 1ce8d83..47564a2 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ Amino.Net has a lot of functionality that allow you to develop Amino tools and b - Please note that this library is built for an easy and dynamic start into making Amino bots and tools, it is **not** made for spam bots or any sort of harmful tools, so use it the way it's intended for. - This is a non profit project, however, if you do want to support me and my **general** work, you can refer to the GitHub sponsor options linked to this repository - I will not take any responsibilty for harm being done using this library, as this is only a free and **open** library, therefore I can't prevent any harm! -- If you run into issues or want to talk to other Amino.Net developers, you can check out the official Amino.Net discord server [HERE](https://discord.gg/gNnBnADQkz) +- If you run into issues or want to talk to other Amino.Net developers, you can check out the official Amino.Net discord server [HERE](https://discord.gg/qyv8P2gegK) ## Important Notice By using this library you agree that you are aware of the fact that you are breaking the App services Terms of Service - as Team Amino strictly forbids the use of any sort of third party software / scripting to gain an advantage over other members, any activity by third party tools found by Team Amino may result in your account getting banned from their services!