Skip to content
This repository was archived by the owner on Jul 26, 2019. It is now read-only.

Commit c74a6c7

Browse files
committed
Initial commit
0 parents  commit c74a6c7

File tree

11 files changed

+1101
-0
lines changed

11 files changed

+1101
-0
lines changed

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) Andre_601
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# JavaBotBlockAPI
2+
JavaBotBlockAPI is a continued and updated Java Wrapper for [BotBlock], a website that makes it possible to update guild counts on multiple lists with one API.
3+
This wrapper is a fork of [BotBlock4J] and was updated and improved to make it as userfriendly as possible.
4+
5+
## Installation
6+
You can install JavaBotBlockAPI through the following methods.
7+
Make sure to replace `{version}` with the above shown version.
8+
9+
### Gradle
10+
Put this code into your `build.gradle`:
11+
```gradle
12+
repositories{
13+
jcenter()
14+
}
15+
16+
dependencies{
17+
compile group: 'com.andre601', name: 'JavaBotBlockAPI', version: '{version}'
18+
}
19+
```
20+
21+
### Maven
22+
For maven use this code snipped:
23+
```xml
24+
<repositories>
25+
<repository>
26+
<id>jcenter</id>
27+
<url>https://jcenter.bintray.com</url>
28+
</repository>
29+
</repositories>
30+
31+
<dependencies>
32+
<dependency>
33+
<groupId>com.andre601</groupId>
34+
<artifactId>JavaBotBlockAPI</artifactId>
35+
<version>{version}</version>
36+
</dependency>
37+
</dependencies>
38+
```
39+
40+
## Usage
41+
To use the Wrapper you have to follow these steps.
42+
43+
### Notes
44+
In the below examples do I use a JDA instance called `jda`.
45+
This will also work with ShardManager.
46+
47+
### Creating a BotBlockAPI instance
48+
You first need to create an instance of the BotBlockAPI class.
49+
This class is the center of everything, including on what sites you want to post your guild counts.
50+
51+
You can use the internal Builder class of BotBlockAPI to create an instance. It would look something like this:
52+
```java
53+
// Creating an instance of BotBlockAPI using BotBlockAPI.Builder
54+
BotBlockAPI api = new BotBlockAPI.Builder(jda) // We can provide either a instance of JDA or ShardManager
55+
.addAuthToken("lbots.org", "MySecretToken123") // Adds a site with the corresponding API token.
56+
.addAuthToken("botlist.space", "MySecretToken456") // The builder allows chaining of the methods.
57+
.build();
58+
```
59+
60+
#### Notes
61+
`new BotBlockAPI.Builder()` allows you to provide either a JDA instance, a ShardManager instance or none at all.
62+
You can define a JDA or ShardManager instance at a later point with `.setJDA(JDA)` or `.setShardManager(ShardManager)` respectively.
63+
64+
Also note that when you don't provide any instance, that you have to use `disableJDA(true)` or else you'll receive an NullPointerException.
65+
There are also a lot of other methods that you can use. Head over to the [wiki] for more information.
66+
67+
### Creating a RequestHandler instance
68+
The next step after creating an instance of the BotBlockAPI is to create an instance of the Request Handler.
69+
70+
This example shows the easiest one to use, but there are much more ways you can set it. Check the [Wiki] for examples.
71+
```java
72+
// We previously created a BotBlockAPI instance called api which we now use here.
73+
RequestHandler handler = new RequestHandler(api);
74+
```
75+
76+
### Posting the guild counts
77+
This step depends on what You previously set for the BotBlockAPI and the RequestHandler since some methods are only available for certain cases.
78+
79+
**All methods require BotBlockAPI to be setup, meaning you have AT LEAST added one site and token!**
80+
81+
#### Auto-posting
82+
The Wrapper comes with an inbuilt auto-post that allows you to easily post the guild counts without worrying too much.
83+
However, this method is limited to JDA and ShardManager only so you have to define them for using this.
84+
85+
To auto-post guild counts you just need to call `RequestHandler#startAutoPosting();`
86+
This would look like this:
87+
```java
88+
// We previously defined a RequestHandler called handler
89+
handler.startAutoPosting();
90+
```
91+
92+
Easy right? But what if you want to stop the auto-posting?
93+
For that simply use `Request#stopAutoPosting();`. Here is another example:
94+
```java
95+
// We previously defined a RequestHandler called handler
96+
handler.stopAutoPosting();
97+
```
98+
99+
Note thet the delay in which you post to the API is defined through the BotBlockAPI.
100+
Use `BotBlockAPI.Builder#setUpdateInterval(Integer)` to define a delay. It is counted in minutes and default is 30.
101+
102+
#### Manual posting
103+
If you want to post the guild counts manually you can use the following method:
104+
```java
105+
// We previously defined a RequestHandler called handler
106+
handler.postGuilds();
107+
```
108+
109+
### Exceptions
110+
When you post the guild counts you could encounter certain Exceptions.
111+
You can receive the following exceptions:
112+
- `IOException`
113+
The Request couldn't be performed properly. This can be f.e. the case when BotBlock.org denies access (403).
114+
- `RatelimitedException`
115+
When we exceed the ratelimit of BotBlock.org
116+
This shouldn't be the case with auto-posting since it has a minimum delay of 1 minute.
117+
- `NullPointerException`
118+
Thrown when BotBlock.org sends an empty response, meaning something got messed up on their side.
119+
120+
## Links
121+
Here are some useful links:
122+
- [BotBlock.org] Site for which this wrapper was made.
123+
- [API] API documentation.
124+
- [Wiki] Contains additional information on how you can use JavaBotBlockAPI.
125+
- [BotBlock4J] Original Wrapper from which this one originates.

build.gradle

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
plugins{
2+
id 'com.jfrog.bintray' version '1.8.4'
3+
id 'java-library'
4+
id 'idea'
5+
id 'maven-publish'
6+
}
7+
8+
group = 'com.andre601'
9+
version = '1.0.0'
10+
11+
sourceCompatibility = 1.8
12+
13+
jar{
14+
baseName = 'JavaBotBlockAPI'
15+
}
16+
17+
repositories{
18+
mavenCentral()
19+
jcenter()
20+
}
21+
22+
dependencies{
23+
implementation group: 'com.squareup.okhttp3', name: 'okhttp', version: '3.11.0'
24+
implementation group: 'org.json', name: 'json', version: '20180813'
25+
implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.9'
26+
implementation group: 'org.jetbrains', name: 'annotations', version: '16.0.2'
27+
api(group: 'net.dv8tion', name: 'JDA', version: '3.8.3_463'){
28+
exclude(module: 'opus-java')
29+
}
30+
}
31+
32+
task sourcesJar(type: Jar, dependsOn: classes) {
33+
classifier = 'sources'
34+
from sourceSets.main.allSource
35+
}
36+
37+
task javadocJar(type: Jar, dependsOn: javadoc) {
38+
classifier = 'javadoc'
39+
from javadoc.destinationDir
40+
}
41+
42+
artifacts{
43+
archives sourcesJar
44+
archives javadocJar
45+
}
46+
47+
bintray{
48+
publications = ['JavaBotBlockAPIRelease']
49+
pkg{
50+
repo = 'maven'
51+
name = 'JavaBotBlockAPI'
52+
licenses = ['MIT']
53+
vcsUrl = 'https://github.com/Andre601/JavaBotBlockAPI'
54+
version{
55+
name = project.version
56+
released = new Date()
57+
}
58+
}
59+
}
60+
61+
publishing{
62+
publications{
63+
JavaBotBlockAPIRelease(MavenPublication){
64+
from = components.java
65+
groupId = group
66+
artifactId = archivesBaseName
67+
version = version
68+
artifact = javadocJar
69+
artifact = sourcesJar
70+
}
71+
}
72+
}

gradle/wrapper/gradle-wrapper.jar

53.1 KB
Binary file not shown.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#Sat Jun 22 13:52:50 CEST 2019
2+
distributionBase=GRADLE_USER_HOME
3+
distributionPath=wrapper/dists
4+
zipStoreBase=GRADLE_USER_HOME
5+
zipStorePath=wrapper/dists
6+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-all.zip

0 commit comments

Comments
 (0)