Merge pull request #41 from BigBotNetwork/greg-dev

Merge greg into master
This commit is contained in:
Skidder 2019-11-03 01:32:30 +01:00 committed by GitHub
commit c4ffa1b9a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 66 additions and 1 deletions

View file

@ -24,6 +24,8 @@ import java.util.List;
public class Hadder {
public static ShardManager shardManager;
public static void main(String[] args) {
startBot();
}
@ -61,7 +63,7 @@ public class Hadder {
new ReadyListener());
try {
ShardManager shardManager = builder.build();
shardManager = builder.build();
} catch (LoginException e) {
e.printStackTrace();
}

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();
}
}
}