Advertisement
Guest User

Untitled

a guest
Nov 20th, 2019
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. const fetch = require("node-fetch");
  2. const Discord = require('discord.js');
  3. const url = "http://gamepatch.elswordonline.com/PatchPath.dat";
  4. const sgame = "https://api.koggames.com/Server/CheckGameStat.ashx";
  5. const getData = async url => {
  6. try {
  7. const response = await fetch(url);
  8. const content = await response.text();
  9. return content;
  10. } catch (error) {
  11. console.log(error);
  12. return error;
  13. }
  14. };
  15. const getWiki = async wikiurl => {
  16. try {
  17. const response = await fetch(wikiurl);
  18. const json = await response.json();
  19. return json;
  20. } catch (error) {
  21. console.log(error);
  22. return error;
  23. }
  24. };
  25. const getServer = async sgame =>{
  26. try {
  27. const reply = await fetch(sgame);
  28. const rjson = await reply.json;
  29. return rjson;
  30. } catch (error) {
  31. console.log(error);
  32. return error;
  33.  
  34. }
  35.  
  36.  
  37. };
  38.  
  39.  
  40.  
  41. module.exports = function (bot, message) {
  42. if (message.author.bot) return;
  43. else if (message.content.startsWith("/kom")) {
  44. var prom1 = getData(url);
  45. prom1.then(function(msg){
  46. var nmsg = msg.slice(1,-1);
  47. var fmsg = nmsg + "/data/data001.kom";
  48. const exampleEmbed = new Discord.RichEmbed()
  49. .setColor('#0099ff')
  50. .setTitle('LINK TO DOWNLOAD INDIVIDUAL .KOM FILES')
  51. .setDescription(fmsg)
  52. .setFooter('Replace data001.kom with the file you need')
  53. message.channel.send(exampleEmbed);
  54. }
  55. );
  56. }
  57. else if (message.content.startsWith("/wiki ")){
  58. const term = message.content.slice(6);
  59. console.log(term);
  60. var splitStr = term.toLowerCase().split(' ');
  61. for (var i = 0; i < splitStr.length; i++) {
  62. // You do not need to check if i is larger than splitStr length, as your for does that for you
  63. // Assign it back to the array
  64. splitStr[i] = splitStr[i].charAt(0).toUpperCase() + splitStr[i].substring(1);
  65. }
  66. // Directly return the joined string
  67. var nterm = splitStr.join(' ');
  68. const bwikiurl = "https://elwiki.net/wiki/api.php?action=opensearch&format=json&search=" + nterm + "&limit=3";
  69. const wikiurl = encodeURI(bwikiurl);
  70. var prom2 = getWiki(wikiurl);
  71. var i=0;
  72. var sterm = "Elwiki Results for " + term;
  73. var sresult;
  74. var nresult = "No results found";
  75.  
  76. prom2.then(function(res){
  77. const wikiEmbed = new Discord.RichEmbed()
  78. .setColor('#fffc2e')
  79. .setTitle(sterm)
  80. .setDescription("")
  81. .setFooter('DM errors/bugs to Ruru#9278.');
  82. if(res[3].length === 0) {
  83. wikiEmbed.description += nresult;
  84. }
  85. else{
  86. for(i=0;i<res[3].length; i++){
  87. var x = res[3][i];
  88. console.log(x);
  89. wikiEmbed.description += x + "\n";
  90.  
  91. }
  92.  
  93.  
  94. }
  95.  
  96. message.channel.send(wikiEmbed);
  97. }
  98. );
  99.  
  100.  
  101.  
  102.  
  103.  
  104. }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement