Top-gg-Community/java-sdk


An API wrapper for https://top.gg/api/docs that works in Java

Download


Step 1. Add the JitPack repository to your build file

Add it in your root build.gradle at the end of repositories:

	dependencyResolutionManagement {
		repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
		repositories {
			mavenCentral()
			maven { url 'https://jitpack.io' }
		}
	}
	<repositories>
		<repository>
		    <id>jitpack.io</id>
		    <url>https://jitpack.io</url>
		</repository>
	</repositories>

Add it in your build.sbt at the end of resolvers:

 
    resolvers += "jitpack" at "https://jitpack.io"
        
    

Add it in your project.clj at the end of repositories:

 
    :repositories [["jitpack" "https://jitpack.io"]]
        
    

Step 2. Add the dependency

	dependencies {
		implementation 'com.github.discordbotlist:dbl-java-library:2.1.2'
	}
	<dependency>
	    <groupId>com.github.discordbotlist</groupId>
	    <artifactId>dbl-java-library</artifactId>
	    <version>2.1.2</version>
	</dependency>

                            
    libraryDependencies += "com.github.discordbotlist" % "dbl-java-library" % "2.1.2"
        
        

                            
    :dependencies [[com.github.discordbotlist/dbl-java-library "2.1.2"]]
        
        

Readme


DBL Java Library

A Java wrapper for the top.gg API

Usage

First, build a DiscordBotListAPI object.

DiscordBotListAPI api = new DiscordBotListAPI.Builder()
	.token("token")
	.botId("botId")
	.build();

Posting stats

DBL provides three ways to post your bots stats.

#1 Posts the server count for the whole bot.

int serverCount = ...; // the total amount of servers across all shards

api.setStats(serverCount);

#2 Posts the server count for an individual shard.

int shardId = ...; // the id of this shard
int shardCount = ...; // the amount of shards
int serverCount = ...; // the server count of this shard

api.setStats(shardId, shardCount, serverCount);

#3 Posts the server counts for every shard in one request.

List<Integer> shardServerCounts = ...; // a list of all the shards' server counts

api.setStats(shardServerCounts);

Checking votes

String userId = ...; // ID of the user you're checking
api.hasVoted(userId).whenComplete((hasVoted, e) -> {
	if(hasVoted)
		System.out.println("This person has voted!");
	else
		System.out.println("This person has not voted!");
});

Getting voting multiplier

api.getVotingMultiplier().whenComplete((multiplier, e) -> {
	if(multiplier.isWeekend())
		System.out.println("It's the weekend, so votes are worth 2x!");
	else
		System.out.println("It's not the weekend :pensive:");
});

Download

Release

Replace VERSION with the latest version or commit hash. The latest version can be found under releases.

Maven

<repositories>
    <repository>
        <id>jitpack.io</id>
        <url>https://jitpack.io</url>
    </repository>
</repositories>
<dependencies>
    <dependency>
        <groupId>com.github.top-gg</groupId>
        <artifactId>java-sdk</artifactId>
        <version>VERSION</version>
    </dependency>
</dependencies>

Gradle

repositories {
    maven { url 'https://jitpack.io' }
}
dependencies {
    compile 'com.github.top-gg:java-sdk:VERSION'
}