greatman/legendarybot

Log Elasticsearch Configuration/battle.net API key changes

Closed this issue · 2 comments

Hello Greatman,

I'm in the process of trying to set this up for my own guild server, with a few modifications. Ideally, I'd like to start committing back to the repo, and helping with some development. The issue I'm having currently is elastic search is not documented nor mentioned virtually everywhere, but it appears to be a required step for setting up the bot.

Can you tell me how you've populated elasticsearch with the realm information (And any other information that needs to be pre-populated into elasticsearch), so that I may setup the bot? Additionally, can you update the README.md file with information about elasticsearch, as well as updating the API key information for battle.net (It appears to now use the following fields: battlenet.us.key, battlenet.us.secret, battlenet.eu.key, battlenet.eu.secret).

Hello!

Indeed, I use ES for several parts of the bot to search stuff related to wow (and not murder my API limit).

backup.zip

I exported my ES index with elasticdump, which you can find here: https://www.npmjs.com/package/elasticdump
To import it in your ES cluster, simply use this command elasticdump --input backup.json --output=http://localhost:9200/wow

I will update the README with the info you said. Indeed I changed the b.net API key system lately in the bot.

The code to import the realm info into the ES was the following (It is not in the repo, it was a one-off, I might add it in it for simplicy sake for other users)

RestClient restClient = RestClient.builder(
                new HttpHost("localhost", 9200, "http")).build();
            String response = doRequest("https://us.api.battle.net/wow/realm/status?locale=en_US", KEY1);
        JSONObject json = (JSONObject) new JSONParser().parse(response);
        JSONArray array = (JSONArray) json.get("realms");
        array.forEach(v -> {

            HttpEntity entity = new NStringEntity(((JSONObject)v).toJSONString(), ContentType.APPLICATION_JSON);
            try {
                Response indexResponse = restClient.performRequest(
                        "POST",
                        "/wow/realm_us/",
                        Collections.<String, String>emptyMap(),
                        entity);
                System.out.println(EntityUtils.toString(indexResponse.getEntity()));
            } catch (IOException e) {
                e.printStackTrace();
            }
        });

Oh, also, you might want to use the https://github.com/greatman/legendarybot/tree/MongoDBBackend branch, it will become master today after the maintenance of the main bot. The bot will use MongoDB instead of MySQL for it's database backend.