Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if(message.Text.StartsWith("/start"))
- {
- try
- {
- var factory = new ConnectionFactory() { HostName = "api.chatwars.me", Port = 5673, UserName = "****", Password = "******" };
- factory.Ssl.Version = SslProtocols.Tls12;
- factory.Ssl.Enabled = true;
- factory.Ssl.AcceptablePolicyErrors |= System.Net.Security.SslPolicyErrors.RemoteCertificateNameMismatch;
- using (var connection = factory.CreateConnection())
- using (var channel = connection.CreateModel())
- {
- byte[] messageBodyBytes = System.Text.Encoding.UTF8.GetBytes("{\"action\": \"createAuthCode\", \"payload\": {\"userId\": "+ message.From.Id + "}}");
- IBasicProperties props = channel.CreateBasicProperties();
- props.ContentType = "application/json";
- props.DeliveryMode = 2;
- channel.BasicPublish("darkmane_battle_informer_ex",
- "darkmane_battle_informer_o", props,
- messageBodyBytes);
- Console.WriteLine("sent message");
- await Bot.SendTextMessageAsync(message.Chat.Id, "Please check chat wars for an auth code, then enter it here. @chtwrsbot");
- await Bot.SendTextMessageAsync(message.Chat.Id, "Example: /auth 123456");
- }
- using (IConnection connection = factory.CreateConnection())
- {
- using (IModel model = connection.CreateModel())
- {
- var subscription = new Subscription(model, "darkmane_battle_informer_i", false);
- get = 1;
- while (get == 1)
- {
- BasicDeliverEventArgs basicDeliveryEventArgs =
- subscription.Next();
- string messageContent =
- Encoding.UTF8.GetString(basicDeliveryEventArgs.Body);
- var json = JObject.Parse(messageContent); //Reads the json from the html (?)
- Console.WriteLine(json);
- await Bot.SendTextMessageAsync(-1001279937491, "Battle Informer: | CW API | " + messageContent);
- subscription.Ack(basicDeliveryEventArgs);
- get = 0;
- }
- }
- }
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex);
- }
- }
- if (message.Text.StartsWith("/auth"))
- {
- int authcode = 0;
- try
- {
- authcode = Convert.ToInt32(Regex.Match(message.Text, @"\d+").Value);
- }
- catch
- {
- try
- {
- await Bot.SendTextMessageAsync(message.Chat.Id, "Your code appears invalid..");
- return;
- }
- catch
- {
- return;
- }
- }
- try
- {
- var factory = new ConnectionFactory() { HostName = "api.chatwars.me", Port = 5673, UserName = "*******", Password = "******" };
- factory.Ssl.Version = SslProtocols.Tls12;
- factory.Ssl.Enabled = true;
- factory.Ssl.AcceptablePolicyErrors |= System.Net.Security.SslPolicyErrors.RemoteCertificateNameMismatch;
- using (var connection = factory.CreateConnection())
- using (var channel = connection.CreateModel())
- {
- byte[] messageBodyBytes = System.Text.Encoding.UTF8.GetBytes("{\"action\": \"grantToken\", \"payload\": {\"userId\":" + message.From.Id + ", \"authCode\":\"" + authcode + "\"}}");
- IBasicProperties props = channel.CreateBasicProperties();
- props.ContentType = "application/json";
- props.DeliveryMode = 2;
- channel.BasicPublish("darkmane_battle_informer_ex",
- "darkmane_battle_informer_o", props,
- messageBodyBytes);
- }
- using (IConnection connection = factory.CreateConnection())
- {
- using (IModel model = connection.CreateModel())
- {
- var subscription = new Subscription(model, "darkmane_battle_informer_i", false);
- get = 1;
- while (get == 1)
- {
- BasicDeliverEventArgs basicDeliveryEventArgs =
- subscription.Next();
- string messageContent =
- Encoding.UTF8.GetString(basicDeliveryEventArgs.Body);
- var json = JObject.Parse(messageContent); //Reads the json from the html (?)
- Console.WriteLine(messageContent);
- try
- {
- token = json["payload"]["token"].ToString();
- Console.WriteLine("Token = " + token);
- await Bot.SendTextMessageAsync(-1001279937491, "Battle Informer: | CW API | " + messageContent);
- }
- catch
- {
- await Bot.SendTextMessageAsync(-1001279937491, "Battle Informer: | WARN | Failed getting token -- " + messageContent);
- }
- subscription.Ack(basicDeliveryEventArgs);
- get = 0;
- }
- }
- }
- using (var connection = factory.CreateConnection())
- using (var channel = connection.CreateModel())
- {
- byte[] messageBodyBytes = System.Text.Encoding.UTF8.GetBytes("{\"token\": \"" + token + "\",\"action\": \"requestProfile\"}");
- IBasicProperties props = channel.CreateBasicProperties();
- props.ContentType = "application/json";
- props.DeliveryMode = 2;
- channel.BasicPublish("darkmane_battle_informer_ex",
- "darkmane_battle_informer_o", props,
- messageBodyBytes);
- }
- using (IConnection connection = factory.CreateConnection())
- {
- using (IModel model = connection.CreateModel())
- {
- var subscription = new Subscription(model, "darkmane_battle_informer_i", false);
- get = 1;
- while (get == 1)
- {
- BasicDeliverEventArgs basicDeliveryEventArgs =
- subscription.Next();
- string messageContent =
- Encoding.UTF8.GetString(basicDeliveryEventArgs.Body);
- var json = JObject.Parse(messageContent); //Reads the json from the html (?)
- try {
- string castle = json["payload"]["profile"]["castle"].ToString();
- string username = json["payload"]["profile"]["userName"].ToString();
- int ulevel = (int)json["payload"]["profile"]["lvl"];
- Console.WriteLine("Castle = " + castle);
- Console.WriteLine("Username = " + username);
- Console.WriteLine("Level = " + ulevel);
- if (castle.Contains("🐉"))
- {
- Console.WriteLine("User is from dragonscale.");
- Database.InsertUser(message.From.Id, username, ulevel);
- await Bot.SendTextMessageAsync(message.Chat.Id, "Registered you in the database");
- }
- else
- {
- Console.WriteLine("User is a skrub from another castle");
- await Bot.SendTextMessageAsync(message.Chat.Id, "Thanks for the free information. \n\nI have forwarded it to @dx_tr");
- }
- await Bot.SendTextMessageAsync(-1001279937491, "Battle Informer: | CW API | Got details for " + username);
- subscription.Ack(basicDeliveryEventArgs);
- get = 0;
- }
- catch
- {
- Console.WriteLine(messageContent);
- await Bot.SendTextMessageAsync(message.Chat.Id, "Something went wrong, please generate a new auth code and try again.");
- await Bot.SendTextMessageAsync(-1001279937491, "Battle Informer: | WARN | Failed to get details for " + message.From.Id);
- get = 0;
- }
- }
- }
- }
- }
- catch (Exception ex)
- {
- Console.WriteLine(ex);
- }
- }
Add Comment
Please, Sign In to add comment