Last active
February 12, 2018 16:25
-
-
Save duncte123/d3ebf090cadddd3d91eff1da112960b4 to your computer and use it in GitHub Desktop.
A simple util class to post stats
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import net.dv8tion.jda.core.JDA; | |
import okhttp3.*; | |
import org.json.JSONObject; | |
import java.io.IOException; | |
public class PostStats { | |
private static final OkHttpClient CLIENT = new OkHttpClient(); | |
public static void toDiscordBots(JDA jda, String api_key) { | |
System.out.println("Posting servercount to discordbots"); | |
String url = "https://discordbots.org/api/bots/"+jda.getSelfUser().getId()+"/stats"; | |
JSONObject data = new JSONObject(); | |
data.put("server_count", jda.getGuildCache().size()); | |
RequestBody body = RequestBody.create(MediaType.parse("application/json"), data.toString()); | |
Request request = new Request.Builder() | |
.url(url) | |
.post(body) | |
.addHeader("User-Agent", "DiscordBot " + jda.getSelfUser().getName()) | |
.addHeader("Authorization", api_key) | |
.build(); | |
try { | |
Response r = CLIENT.newCall(request).execute(); | |
System.out.println("Posted server count, response: " + r.body().string()); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment