Advertisement
gtblack

Sample Granblue Bot Script

Jul 4th, 2020
1,357
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function granblue(commands) {
  2.   const subCommand = commands[1];
  3.   const memberCount = 5;
  4.   switch (subCommand) {
  5.     case ("캐릭터"): {
  6.       const charProperty = commands[2];
  7.       if (charProperty === "도움") {
  8.         return "캐릭터 속성과 이름을 입력해주기 바라네. 예를 들자면 !퐞 캐릭터 암속 오키스 그랜드 와 같은 식이네.";
  9.       }
  10.       if (charProperty === undefined || charProperty === null ||
  11.         ["화속", "수속", "토속", "풍속", "광속", "암속"].indexOf(charProperty) < 0) {
  12.         return "캐릭터 속성을 지정해주기 바라네.";
  13.       }
  14.       const charName = commands[3];
  15.       if (charName === undefined || charName === null) {
  16.         return "캐릭터 이름을 입력해주기 바라네.";
  17.       }
  18.       const charType = commands[4];
  19.       if (charType !== undefined && Object.keys(characterTypeColorData).indexOf(charType) < 0) {
  20.         let message = "올바른 캐틱터 유형을 지정해주기 바라네. 지원하는 유형은";
  21.         for (supportedType of Object.keys(characterTypeColorData)) {
  22.           message = message.concat(supportedType, ", ");
  23.         }
  24.         return message.slice(0, -2).concat("일세.");
  25.       }
  26.       let url = "https://sheets.googleapis.com/v4/spreadsheets/" + granblueSheetID
  27.         + "/values/'" + charProperty + "'!A2:I100?key=" + googleSpreadsheetAPIKey;
  28.       let apiResponse = org.jsoup.Jsoup.connect(url).ignoreContentType(true).get();
  29.       let data = JSON.parse(apiResponse.body().text()).values;
  30.       let cellUrl = "https://sheets.googleapis.com/v4/spreadsheets/" + granblueSheetID;
  31.       cellUrl += "?includeGridData=true&ranges='" + charProperty + "'!A2:A100&key=";
  32.       cellUrl += googleSpreadsheetAPIKey;
  33.       let apiCellResponse = org.jsoup.Jsoup.connect(cellUrl).ignoreContentType(true).get();
  34.       let cellData = JSON.parse(apiCellResponse.body().text()).sheets[0].data;
  35.       let message = "";
  36.       for (let i = 1; i < data.length; i++) {
  37.         if (charName === data[i][0]) {
  38.           let colorInfo = cellData[0].rowData[i].values[0].userEnteredFormat.textFormat.foregroundColor;
  39.           if (charType !== undefined) {
  40.             if (colorInfo.red !== characterTypeColorData[charType].red
  41.               || colorInfo.green !== characterTypeColorData[charType].green
  42.               || colorInfo.blue !== characterTypeColorData[charType].blue) {
  43.               continue;
  44.             }
  45.             message = message.concat(charType, " ");
  46.           } else if (colorInfo !== undefined && Object.keys(colorInfo).length > 0) {
  47.             continue;
  48.           }
  49.           message = message.concat(charName, "을(를) 보유하고 있는 기공사는 ");
  50.           let anyoneHasChar = false;
  51.           for (let j = 1; j < memberCount + 1; j++) {
  52.             if (data[i][j] === "X") {
  53.               message = message.concat(data[0][j], ", ");
  54.               anyoneHasChar = true;
  55.             }
  56.           }
  57.           if (!anyoneHasChar) {
  58.             message = message.concat("없네.");
  59.           } else {
  60.             message = message.slice(0, -2);
  61.             message = message.concat("일세.");
  62.           }
  63.           message = message.concat("\n이 캐릭터의 게임위드 평점은 ", data[i][7],
  64.             ", 갤러리 평점은 ", data[i][8], "일세.");
  65.           return message;
  66.         }
  67.       }
  68.       return "캐릭터를 찾을 수 없었네. 시트에 등록되어 있는 대로 이름을 입력했는지 확인해주기 바라네.";
  69.       break;
  70.     }
  71.     case ("십천중"): {
  72.       const eternalName = commands[2];
  73.       if (eternalName === undefined || eternalName === null) {
  74.         return "보유 상태를 확인할 십천중의 이름을 입력해주게.";
  75.       }
  76.       let url = "https://sheets.googleapis.com/v4/spreadsheets/" + granblueSheetID;
  77.       url += "/values/'십천중%2F아카룸'!A2:G100?key=" + googleSpreadsheetAPIKey;
  78.       Log.d(url);
  79.       let apiResponse = org.jsoup.Jsoup.connect(url).ignoreContentType(true).get();
  80.       let data = JSON.parse(apiResponse.body().text()).values;
  81.       let message = "";
  82.       for (let i = 1; i < data.length; i++) {
  83.         if (eternalName === data[i][0]) {
  84.           message = message.concat(eternalName + "을(를) 보유하고 있는 기공사는 ");
  85.           let anyoneHasChar = false;
  86.           for (let j = 1; j < memberCount + 1; j++) {
  87.             if (data[i][j] === "X") {
  88.               message = message.concat(data[0][j], ", ");
  89.               anyoneHasChar = true;
  90.             } else if (data[i][j] === "XX") {
  91.               message = message.concat(data[0][j], "(최종), ");
  92.               anyoneHasChar = true;
  93.             }
  94.           }
  95.           if (!anyoneHasChar) {
  96.             message = message.concat("없네.");
  97.           } else {
  98.             message = message.slice(0, -2);
  99.             message = message.concat("일세.");
  100.           }
  101.           return message;
  102.         }
  103.       }
  104.       return "십천중을 찾을 수 없었네. 십천중의 이름을 제대로 입력했는지 확인해주기 바라네.";
  105.       break;
  106.     }
  107.     case ("도움"): {
  108.       return "현재 지원하는 명령어는 다음과 같네: 캐릭터, 십천중";
  109.     }
  110.     default: {
  111.       return "지원하지 않는 명령어라네. !퐞 도움 을 통해 가능한 명령어를 확인해 보게.";
  112.     }
  113.   }
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement