|
| 1 | +using Newtonsoft.Json; |
| 2 | +using Newtonsoft.Json.Linq; |
| 3 | +using RestSharp; |
| 4 | +using System; |
| 5 | +using System.Collections.Generic; |
| 6 | +using System.Diagnostics; |
| 7 | +using System.Linq; |
| 8 | +using System.Runtime.InteropServices; |
| 9 | +using System.Text; |
| 10 | +using System.Text.Json; |
| 11 | +using System.Threading.Tasks; |
| 12 | + |
| 13 | +namespace Amino |
| 14 | +{ |
| 15 | + public class ACMClient |
| 16 | + { |
| 17 | + |
| 18 | + public Amino.Client Client { get; } |
| 19 | + public int CommunityId { get; } |
| 20 | + |
| 21 | + private RestClient RClient { get; } |
| 22 | + |
| 23 | + public ACMClient(Amino.Client client, string communityId) |
| 24 | + { |
| 25 | + this.Client = client; |
| 26 | + this.CommunityId = Convert.ToInt32(communityId); |
| 27 | + RClient = new RestClient(helpers.BaseUrl); |
| 28 | + RClient.AddDefaultHeaders(Client.headers); |
| 29 | + } |
| 30 | + public ACMClient(Amino.Client client, int communityId) |
| 31 | + { |
| 32 | + this.Client = client; |
| 33 | + this.CommunityId = communityId; |
| 34 | + RClient = new RestClient(helpers.BaseUrl); |
| 35 | + RClient.AddDefaultHeaders(Client.headers); |
| 36 | + } |
| 37 | + |
| 38 | + public ACMClient(Amino.SubClient client) |
| 39 | + { |
| 40 | + this.Client = client.GetClient(); |
| 41 | + this.CommunityId = Convert.ToInt32(client.GetCurrentCommunityId()); |
| 42 | + RClient = new RestClient(helpers.BaseUrl); |
| 43 | + RClient.AddDefaultHeaders(Client.headers); |
| 44 | + } |
| 45 | + |
| 46 | + public Task create_community(string name, string tagline, byte[] icon, string themeColor, Types.Join_Types joinType = Types.Join_Types.Open, Types.Supported_Languages primaryLanguage = Types.Supported_Languages.english) |
| 47 | + { |
| 48 | + string _lang = "en"; |
| 49 | + switch(primaryLanguage) |
| 50 | + { |
| 51 | + case Types.Supported_Languages.english: |
| 52 | + _lang = "en"; |
| 53 | + break; |
| 54 | + case Types.Supported_Languages.spanish: |
| 55 | + _lang = "es"; |
| 56 | + break; |
| 57 | + case Types.Supported_Languages.portuguese: |
| 58 | + _lang = "pt"; |
| 59 | + break; |
| 60 | + case Types.Supported_Languages.arabic: |
| 61 | + _lang = "ar"; |
| 62 | + break; |
| 63 | + case Types.Supported_Languages.russian: |
| 64 | + _lang = "ru"; |
| 65 | + break; |
| 66 | + case Types.Supported_Languages.french: |
| 67 | + _lang = "fr"; |
| 68 | + break; |
| 69 | + case Types.Supported_Languages.german: |
| 70 | + _lang = "de"; |
| 71 | + break; |
| 72 | + } |
| 73 | + JObject data = new JObject() |
| 74 | + { |
| 75 | + { "icon", new JObject() { |
| 76 | + { "height", 512.0 }, |
| 77 | + { "path", this.Client.upload_media(icon, Types.upload_File_Types.Image) }, |
| 78 | + { "width", 512.0 }, |
| 79 | + { "x", 0.0 }, |
| 80 | + { "y", 0.0 }, |
| 81 | + { "imageMatrix", new JArray() { 1.6875, 0.0, 108.0, 0.0, 1.6875, 497.0, 0.0, 0.0, 1.0} } |
| 82 | + } }, |
| 83 | + { "joinType", (int)joinType }, |
| 84 | + { "name", name }, |
| 85 | + { "primaryLanguage", _lang }, |
| 86 | + { "tagline", tagline }, |
| 87 | + { "templateId", 9 }, |
| 88 | + { "themeColor", themeColor }, |
| 89 | + { "timestamp", helpers.GetTimestamp() * 1000 } |
| 90 | + }; |
| 91 | + RestRequest request = new RestRequest("/g/s/community"); |
| 92 | + request.AddHeader("NDC-MSG-SIG", helpers.generate_signiture(JsonConvert.SerializeObject(data))); |
| 93 | + request.AddJsonBody(JsonConvert.SerializeObject(data)); |
| 94 | + |
| 95 | + var response = RClient.ExecutePost(request); |
| 96 | + if(!response.IsSuccessStatusCode) { throw new Exception(response.Content); } |
| 97 | + if(Client.debug) { Trace.WriteLine(response.Content); } |
| 98 | + return Task.CompletedTask; |
| 99 | + |
| 100 | + } |
| 101 | + |
| 102 | + public Task delete_community(string email, string password, string verificationCode) |
| 103 | + { |
| 104 | + |
| 105 | + } |
| 106 | + |
| 107 | + } |
| 108 | +} |
0 commit comments