First Bot List Integration
This commit is contained in:
parent
c96792f7c9
commit
ace8587f96
3 changed files with 63 additions and 0 deletions
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
55
src/main/java/com/bbn/hadder/utils/BotList.java
Normal file
55
src/main/java/com/bbn/hadder/utils/BotList.java
Normal 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();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue