First Bot List Integration

This commit is contained in:
GregTCLTK 2019-11-03 01:31:32 +01:00
parent c96792f7c9
commit ace8587f96
3 changed files with 63 additions and 0 deletions

View file

@ -5,6 +5,7 @@ package com.bbn.hadder.listener;
*/
import com.bbn.hadder.Rethink;
import com.bbn.hadder.utils.BotList;
import com.bbn.hadder.utils.MessageEditor;
import net.dv8tion.jda.api.EmbedBuilder;
import net.dv8tion.jda.api.entities.User;
@ -34,6 +35,8 @@ public class GuildListener extends ListenerAdapter {
.setFooter(event.getJDA().getSelfUser().getName(), event.getJDA().getSelfUser().getAvatarUrl())
.setTimestamp(Instant.now())
.build()).queue();
BotList.post();
}
public void onGuildLeave(GuildLeaveEvent event) {
@ -46,6 +49,8 @@ public class GuildListener extends ListenerAdapter {
.setFooter(event.getJDA().getSelfUser().getName(), event.getJDA().getSelfUser().getAvatarUrl())
.setTimestamp(Instant.now())
.build()).queue();
BotList.post();
}
public void onGuildMemberJoin(GuildMemberJoinEvent event) {

View file

@ -1,6 +1,7 @@
package com.bbn.hadder.listener;
import com.bbn.hadder.Rethink;
import com.bbn.hadder.utils.BotList;
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.User;
import net.dv8tion.jda.api.events.ReadyEvent;
@ -21,5 +22,7 @@ public class ReadyListener extends ListenerAdapter {
for (Guild g : event.getJDA().getGuilds()) {
Rethink.insertServer(g.getId());
}
BotList.post();
}
}

View file

@ -0,0 +1,55 @@
package com.bbn.hadder.utils;
/*
* @author Skidder / GregTCLTK
*/
import com.bbn.hadder.Hadder;
import okhttp3.MediaType;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import org.json.JSONObject;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
public class BotList {
private static String MythicalBotList = "https://mythicalbots.xyz/api";
private static JSONObject json = new JSONObject();
public static void post() {
json.put("server_count", Hadder.shardManager.getGuilds().size());
RequestBody body = RequestBody.create(MediaType.parse("application/json"), json.toString());
File configfile = new File("./config.json");
JSONObject config = null;
try {
config = new JSONObject(new String(Files.readAllBytes(Paths.get(configfile.toURI()))));
} catch (IOException e) {
e.printStackTrace();
}
// Mythical Bot List
Request mythicalbotlist = new Request.Builder()
.url(MythicalBotList)
.post(body)
.addHeader("Authorization", config.getString("MythicalBotList"))
.build();
try {
new OkHttpClient().newCall(mythicalbotlist).execute().close();
System.out.println("Successfully posted count for the Mythical Bot List!");
} catch (IOException e) {
e.printStackTrace();
}
}
}