Advertisement
Guest User

Untitled

a guest
Feb 16th, 2017
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.83 KB | None | 0 0
  1. var Discordie = require("discordie");
  2. var XMLHttpRequest = require('w3c-xmlhttprequest').XMLHttpRequest;
  3. var client = new Discordie();
  4.  
  5. client.connect({
  6. // replace this sample token
  7. token: 'MjgxNjAxMjY5OTAxMTY0NTQ0.C4aVYA.Wd7gIWKlm1m1Tv2xh3rTHlp1DRc'
  8. });
  9.  
  10. client.Dispatcher.on("GATEWAY_READY", e => {
  11. console.log("Connected as: " + client.User.username);
  12. });
  13.  
  14. client.Dispatcher.on("MESSAGE_CREATE", e => {
  15. if (e.message.content == "king")
  16. e.message.channel.sendMessage("brutus");
  17. if (e.message.content == "fuck")
  18. e.message.channel.sendMessage("geren");
  19. if (e.message.content == "What role is AlmightBrutus?"){
  20. //e.message.channel.sendMessage("start");
  21. postJSON("http://geist-ro.shivtr.com/users/sign_in.json",
  22. function(err,data){
  23. if (err != null) {
  24. //alert("Something went wrong: " + err);
  25. e.message.channel.sendMessage("wrong");
  26. } else {
  27. //alert("Your query count: " + data.query.count);
  28. //e.message.channel.sendMessage("post");
  29. //e.message.channel.sendMessage(data);
  30. //e.message.channel.sendMessage(data.user_session.id);
  31. var link = "http://geist-ro.shivtr.com/characters.json";
  32. link = link.concat("?auth_token=")
  33. link = link.concat(data.user_session.authentication_token)
  34.  
  35.  
  36. //e.message.channel.sendMessage(link);
  37. //getJSON("http://enmity.shivtr.com/characters.json",
  38. getJSON(link,
  39. function(err, data) {
  40. if (err != null) {
  41. //alert("Something went wrong: " + err);
  42. e.message.channel.sendMessage("wrong");
  43. } else {
  44. //alert("Your query count: " + data.query.count);
  45. //e.message.channel.sendMessage("get");
  46. var text = data.characters[0].name
  47. text = text.concat(": ")
  48. text = text.concat(data.characters[0].spec1)
  49. e.message.channel.sendMessage(text);
  50. //e.message.channel.sendMessage(data.query.created);
  51.  
  52. }
  53. });
  54. //e.message.channel.sendMessage(data.characters[0].id);
  55.  
  56. }
  57.  
  58. });
  59.  
  60. //e.message.channel.sendMessage(":girlgeist:");
  61.  
  62. }
  63. });
  64.  
  65. var getJSON = function(url, callback) {
  66. var xhr = new XMLHttpRequest();
  67. xhr.open("get", url, true);
  68. xhr.responseType = "json";
  69. xhr.onload = function() {
  70. var status = xhr.status;
  71. if (status == 200) {
  72. callback(null, xhr.response);
  73. } else {
  74. callback(status);
  75. }
  76. };
  77. xhr.send();
  78. };
  79.  
  80. var postJSON = function(url, callback) {
  81. //e.message.channel.sendMessage("startpost");
  82. var xhr = new XMLHttpRequest();
  83. xhr.open("POST", url, true);
  84. xhr.responseType = "json";
  85. //Send the proper header information along with the request
  86. xhr.setRequestHeader("Content-type", "application/json");
  87.  
  88. xhr.onreadystatechange = function() {//Call a function when the state changes.
  89. var status = xhr.status;
  90. if(xhr.readyState == XMLHttpRequest.DONE && xhr.status == 200) {
  91. // Request finished. Do processing here.
  92. //var json = JSON.parse(xhr.responseText);
  93. //e.message.channel.sendMessage("hit");
  94. //e.message.channel.sendMessage(xhr.responseText);
  95. console.log(xhr.responseText);
  96. callback(null, xhr.response);
  97. //console.log(json.email + ", " + json.password)
  98. }
  99. }
  100. // xhr.send('user:email=alyssamdev@gmail.com&password=deathnote');
  101. // xhr.send(JSON.stringify({user:{email:alyssamdev@gmail.com,password:deathnote}}
  102. //xhr.send('email=alyssamdev@gmail.com&password=deathnote');
  103. //xhr.send('{"user":{"email":"alyssamdev@gmail.com","password":"deathnote"}}');
  104. xhr.send('{"user":{"email":"alyssamdev@gmail.com","password":"deathnote"}}');
  105. //'user":{"email":"alyssamdev@gmail.com","password":"deathnote'
  106.  
  107.  
  108. //user":{"email":"snafzg@email.com","password":"xyz789
  109.  
  110. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement