Exemple #1
0
//		public async void createUser() {
//			using (var client2 = new HttpClient ()) {
//				client2.BaseAddress = new Uri ("http://ihbiproject.azurewebsites.net/");
//				client2.DefaultRequestHeaders.Accept.Clear ();
//				client2.DefaultRequestHeaders.Accept.Add (new MediaTypeWithQualityHeaderValue ("application/json"));
//
//				RestUser testUser = new RestUser ();
//
//				testUser.id = null;
//				testUser.email = "a@a";
//				testUser.password = "******";
//				testUser.username = "******";
//
//
//
//				HttpResponseMessage response;
//				response = await client2.PostAsJsonAsync ("api/Users", testUser);
//				if (response.IsSuccessStatusCode) {
//					System.Diagnostics.Debug.WriteLine ("======>in getUsers: " + response.Content.ReadAsStringAsync ());
//				}
//			}
//		}



        public async void createUser()
        {
            RestUser rUser = new RestUser();

            rUser.email    = "*****@*****.**";
            rUser.password = "******";
            rUser.username = "******";
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(new Uri("http://ihbiproject.azurewebsites.net/api/Users"));

            request.ContentType = "application/json";
            request.Method      = "POST";
            using (Stream sendStream = await request.GetRequestStreamAsync())
            {
                using (StreamWriter sw = new StreamWriter(sendStream))
                {
                    JsonSerializer jsOut = new JsonSerializer();
                    jsOut.NullValueHandling = NullValueHandling.Ignore;
                    jsOut.Serialize(sw, rUser);
                }
            }

            using (WebResponse response = await request.GetResponseAsync())
            {
                using (Stream stream = response.GetResponseStream())
                {
                    using (StreamReader reader = new StreamReader(stream)){
                        //String result = reader.ReadToEnd ();
                        JsonSerializer serializer = new JsonSerializer();
                        RestUser       result     = (RestUser)serializer.Deserialize(reader, typeof(RestUser));
                        System.Diagnostics.Debug.WriteLine("===> Users: " + result.ToString());
                    }
                }
            }
        }
Exemple #2
0
        private async void OnDiscordBotsUpvote(RemoteProcess proc, DiscordBotsVote vote)
        {
            if (vote.BotId != Config.Instance.Discord.BotID)
            {
                return;
            }
            if (vote.UserId == Config.Instance.Discord.OwnerID)
            {
                return;
            }

            string multiplier = vote.IsWeekend ? "(x2)" : string.Empty;

            this.Log($"New upvote {multiplier} by {vote.UserId}");

            SocketChannel chan = this.DiscordClient.GetChannel(Config.Instance.Discord.FeedbackChannelID);

            if (chan != null)
            {
                RestUser user = await this.DiscordRestClient.GetUserAsync(vote.UserId);

                EmbedBuilder builder = new EmbedBuilder();
                builder
                .WithColorType(EmbedColorType.Special)
                .WithDescription($"💎 New upvote {multiplier}")
                .WithField("User", user == null ? $"Unknown ({vote.UserId})" : user.ToString());

                await this.MessageSender.SendAsync(chan, builder.Build());
            }
        }