Advertisement
Baoulettes

Dok_ev_list_test

Mar 17th, 2020
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.48 KB | None | 0 0
  1. #include <restclient-cpp/restclient.h>
  2. #include <parallel_hashmap/phmap.h>
  3. #include <unidokkan/database.h>
  4. #include <nlohmann/json.hpp>
  5. #include <unidokkan/hook.h>
  6. #include <unidokkan/log.h>
  7. #include <dokkan/crypto.h>
  8. #include <string>
  9. bool ShowEventsBanners(NetworkResponse *response) {
  10.     using namespace std::string_view_literals;
  11.     using json = nlohmann::json;   
  12.     UD_LOGI("Translation Event List : Loading . . .");
  13.     constexpr std::string_view kGetQuests = R"SQL(SELECT
  14.         quests.id,
  15.         quests.name
  16.     FROM
  17.         quests)SQL"sv;
  18.     phmap::parallel_flat_hash_map<int, json> Quests_List_Keyed = UniDokkan::Database::selectKeyedInt(kGetQuests, 0);
  19.     for (auto &EventList_Kagi : response->jsonBody["eventkagi_events"]) {
  20.         auto Event_ID_int               =   EventList_Kagi["id"];
  21.         std::string Event_ID_long       =   to_string(EventList_Kagi["id"]);
  22.         std::string Event_ID            =   Event_ID_long.substr(0, 3);
  23.         for (auto &Quests_Name_Kagi : EventList_Kagi["quests"]) {
  24.             int Quest_ID        =   Quests_Name_Kagi["id"];
  25.             std::string Quest_Name      =   Quests_List_Keyed[Quest_ID]["name"].get<std::string>();
  26.             Quests_Name_Kagi["name"]    =   Quest_Name;
  27.         }
  28.         bool Need_to_check  =   false;
  29.  
  30.         if (Event_ID_int >= 200) {if (Event_ID_int <= 299) {Need_to_check   = true;}}
  31.         if (Event_ID_int >= 377) {if (Event_ID_int <= 399) {Need_to_check   = true;}}
  32.         if (Event_ID_int >= 422) {if (Event_ID_int <= 499) {Need_to_check   = true;}}
  33.         if (Event_ID_int >= 557) {if (Event_ID_int <= 599) {Need_to_check   = true;}}
  34.         if (Event_ID_int >= 605) {if (Event_ID_int <= 699) {Need_to_check   = true;}}
  35.         if (Event_ID_int >= 710) {if (Event_ID_int <= 799) {Need_to_check   = true;}}
  36.        
  37.        
  38.         auto urlcheck = RestClient::head("https://www.baoulettes.fr/DokkanEvent/image/quest_list_banner_" + Event_ID + ".png");
  39.         if (Need_to_check == true && urlcheck.code == 200) {
  40.             EventList_Kagi["banner_image"]      =   "https://www.baoulettes.fr/DokkanEvent/image/quest_list_banner_" + Event_ID + ".png";
  41.         } else {
  42.             std::string logstring = "quest_list_banner_" + Event_ID + ".png";
  43.             UD_LOGI("Translation Event List : Error 404 : %s", logstring.c_str());
  44.         }
  45.         auto urlcheck1 = RestClient::get("https://www.baoulettes.fr/DokkanEvent/image/quest_top_banner_" + Event_ID + ".png");
  46.         if (urlcheck1.code == 200) {
  47.             EventList_Kagi["event_image"]       =   "https://www.baoulettes.fr/DokkanEvent/image/quest_top_banner_" + Event_ID + ".png";
  48.         } else {
  49.             std::string logstring = "quest_top_banner_" + Event_ID + ".png";
  50.             UD_LOGI("Translation Event List : Error 404 : %s", logstring.c_str());
  51.         }
  52.         auto urlcheck2 = RestClient::get("https://www.baoulettes.fr/DokkanEvent/image/quest_event_banner_" + Event_ID + ".png");
  53.         if (urlcheck2.code == 200) {
  54.             EventList_Kagi["minibanner_image"]  =   "https://www.baoulettes.fr/DokkanEvent/image/quest_event_banner_" + Event_ID + ".png";
  55.         } else {
  56.             std::string logstring = "quest_event_banner_" + Event_ID + ".png";
  57.             UD_LOGI("Translation Event List : Error 404 : %s", logstring.c_str());         
  58.         }
  59.     }
  60.     for (auto &EZAList_Kagi : response->jsonBody["eventkagi_z_battle_stages"]) {
  61.         std::string EZA_ID              =   to_string(EZAList_Kagi["id"]);
  62.         auto urlcheck3 = RestClient::get("https://www.baoulettes.fr/DokkanEvent/image/zbattle_list_banner_" + EZA_ID + ".png");
  63.         if (urlcheck3.code == 200) {
  64.             EZAList_Kagi["banner_image"]    =   "https://www.baoulettes.fr/DokkanEvent/image/zbattle_list_banner_" + EZA_ID + ".png";
  65.         } else {
  66.             std::string logstring = "zbattle_list_banner_" + EZA_ID + ".png";
  67.             UD_LOGI("Translation Event List : Error 404 : %s", logstring.c_str());             
  68.         }
  69.     }
  70.     for (auto &EventList : response->jsonBody["events"]) {
  71.         std::string Event_ID_long       =   to_string(EventList["id"]);
  72.         std::string Event_ID            =   Event_ID_long.substr(0, 3);
  73.         for (auto &Quests_Name : EventList["quests"]) {
  74.             int Quest_ID            =   Quests_Name["id"];
  75.             std::string Quest_Name  =   Quests_List_Keyed[Quest_ID]["name"].get<std::string>();
  76.             Quests_Name["name"]     =   Quest_Name;
  77.             auto LimitedEvent       =   Quests_Name.find("limitations");
  78.             if (LimitedEvent != Quests_Name.end()) {
  79.                 for (auto &Limitations : Quests_Name["limitations"]) {
  80.                     std::string LimiType    =   Limitations["type"].get<std::string>();
  81.                     if (LimiType == "QuestLimitation::CardQuestLimitation::OnlyCardQuestLimitation") {
  82.                         Limitations["description"]  = "{relatedCharacterListBtn: card_id:1015141}";
  83.                     }
  84.                 }
  85.             }
  86.            
  87.            
  88.         }
  89.         auto urlcheck4 = RestClient::get("https://www.baoulettes.fr/DokkanEvent/image/quest_list_banner_" + Event_ID + ".png");
  90.         if (urlcheck4.code == 200) {
  91.             EventList["banner_image"]   =   "https://www.baoulettes.fr/DokkanEvent/image/quest_list_banner_" + Event_ID + ".png";
  92.         } else {
  93.             std::string logstring = "quest_list_banner_" + Event_ID + ".png";
  94.             UD_LOGI("Translation Event List : Error 404 : %s", logstring.c_str());     
  95.         }
  96.         auto urlcheck5 = RestClient::get("https://www.baoulettes.fr/DokkanEvent/image/quest_top_banner_" + Event_ID + ".png");
  97.         if (urlcheck5.code == 200) {
  98.             EventList["event_image"]    =   "https://www.baoulettes.fr/DokkanEvent/image/quest_top_banner_" + Event_ID + ".png";
  99.         } else {
  100.             std::string logstring = "quest_top_banner_" + Event_ID + ".png";
  101.             UD_LOGI("Translation Event List : Error 404 : %s", logstring.c_str());     
  102.         }
  103.         auto urlcheck6 = RestClient::get("https://www.baoulettes.fr/DokkanEvent/image/quest_event_banner_" + Event_ID + ".png");
  104.         if (urlcheck6.code == 200) {
  105.             EventList["minibanner_image"]   =   "https://www.baoulettes.fr/DokkanEvent/image/quest_event_banner_" + Event_ID + ".png";
  106.         } else {
  107.             std::string logstring = "quest_event_banner_" + Event_ID + ".png";
  108.             UD_LOGI("Translation Event List : Error 404 : %s", logstring.c_str());                 
  109.         }
  110.     }
  111.     for (auto &EZAList : response->jsonBody["z_battle_stages"]) {
  112.         std::string EZA_ID              =   to_string(EZAList["id"]);
  113.         auto urlcheck7 = RestClient::get("https://www.baoulettes.fr/DokkanEvent/image/zbattle_list_banner_" + EZA_ID + ".png");
  114.         if (urlcheck7.code == 200) {
  115.             EZAList["banner_image"] =   "https://www.baoulettes.fr/DokkanEvent/image/zbattle_list_banner_" + EZA_ID + ".png";
  116.         } else {
  117.             std::string logstring = "zbattle_list_banner_" + EZA_ID + ".png";
  118.             UD_LOGI("Translation Event List : Error 404 : %s", logstring.c_str()); 
  119.         }
  120.     }
  121.     return true;
  122. }
  123. extern "C" {
  124.     int unidokkan_init_v2(HookLib* hook_lib) {
  125.         hook_lib->addResponseHook("^/events$", ShowEventsBanners);
  126.         if (!hook_lib) {
  127.             UD_LOGI("Translation Event List : Not Loaded");
  128.             return 1;
  129.         }
  130.         UD_LOGI("Translation Event List : Loaded");
  131.         return 0;
  132.     }
  133. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement