├── .all-contributorsrc
├── .github
├── CONTRIBUTING.md
├── ISSUE_TEMPLATE
│ ├── bug_report.yml
│ ├── config.yml
│ └── feature_request.yml
├── PULL_REQUEST_TEMPLATE
│ └── PULL_REQUEST_TEMPLATE.md
├── dependabot.yml
├── label-commenter-config.yml
├── release-drafter.yml
└── workflows
│ ├── auto-comment.yml
│ ├── auto_approve_pr.yml
│ ├── gen_javadocs.yml
│ ├── generate_javadoc.yml
│ └── release_drafter.yml
├── .gitignore
├── CODE_OF_CONDUCT.md
├── LICENSE
├── README.md
├── SECURITY.md
├── build.gradle
├── contributors.md
├── core
├── build.gradle
└── src
│ └── main
│ └── java
│ └── org
│ └── botblock
│ └── javabotblockapi
│ └── core
│ ├── BotBlockAPI.java
│ ├── CheckUtil.java
│ ├── Info.java
│ ├── Site.java
│ ├── annotations
│ ├── DeprecatedSince.java
│ ├── PlannedRemoval.java
│ └── package-info.java
│ ├── exceptions
│ ├── RateLimitedException.java
│ └── package-info.java
│ └── package-info.java
├── docs
├── assets
│ └── img
│ │ ├── JavaBotBlockAPI.png
│ │ └── jbba.png
└── index.md
├── gradle
└── wrapper
│ ├── gradle-wrapper.jar
│ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
├── javacord
├── build.gradle
└── src
│ └── main
│ └── java
│ └── org
│ └── botblock
│ └── javabotblockapi
│ └── javacord
│ ├── PostAction.java
│ └── package-info.java
├── jda
├── build.gradle
└── src
│ └── main
│ └── java
│ └── org
│ └── botblock
│ └── javabotblockapi
│ └── jda
│ ├── PostAction.java
│ └── package-info.java
├── request
├── build.gradle
└── src
│ └── main
│ └── java
│ └── org
│ └── botblock
│ └── javabotblockapi
│ └── requests
│ ├── GetBotAction.java
│ ├── GetListAction.java
│ ├── PostAction.java
│ ├── handler
│ └── RequestHandler.java
│ └── package-info.java
└── settings.gradle
/.all-contributorsrc:
--------------------------------------------------------------------------------
1 | {
2 | "files": [
3 | "contributors.md"
4 | ],
5 | "imageSize": 100,
6 | "badgeTemplate": "[contributorsBadge]: https://img.shields.io/badge/Contributors_✨-<%= contributors.length %>-green.svg?style=plastic",
7 | "commit": false,
8 | "contributors": [
9 | {
10 | "login": "DavidRockin",
11 | "name": "Dave",
12 | "avatar_url": "https://avatars1.githubusercontent.com/u/1907079?v=4",
13 | "profile": "https://tkachuk.tech",
14 | "contributions": [
15 | "ideas"
16 | ]
17 | },
18 | {
19 | "login": "DV8FromTheWorld",
20 | "name": "Austin Keener",
21 | "avatar_url": "https://avatars1.githubusercontent.com/u/1479909?v=4",
22 | "profile": "http://linkedin.dv8tion.net",
23 | "contributions": [
24 | "plugin"
25 | ]
26 | },
27 | {
28 | "login": "CodeMC",
29 | "name": "CodeMC",
30 | "avatar_url": "https://avatars2.githubusercontent.com/u/37156340?v=4",
31 | "profile": "https://ci.codemc.io/",
32 | "contributions": [
33 | "infra"
34 | ]
35 | },
36 | {
37 | "login": "dependabot",
38 | "name": "Dependabot",
39 | "avatar_url": "https://avatars1.githubusercontent.com/u/27347476?v=4",
40 | "profile": "https://dependabot.com",
41 | "contributions": [
42 | "maintenance"
43 | ]
44 | },
45 | {
46 | "login": "ben-manes",
47 | "name": "Ben Manes",
48 | "avatar_url": "https://avatars3.githubusercontent.com/u/378614?v=4",
49 | "profile": "https://www.linkedin.com/in/benmanes",
50 | "contributions": [
51 | "plugin"
52 | ]
53 | },
54 | {
55 | "login": "square",
56 | "name": "Square",
57 | "avatar_url": "https://avatars0.githubusercontent.com/u/82592?v=4",
58 | "profile": "https://square.github.io",
59 | "contributions": [
60 | "plugin"
61 | ]
62 | },
63 | {
64 | "login": "JetBrains",
65 | "name": "JetBrains",
66 | "avatar_url": "https://avatars2.githubusercontent.com/u/878437?v=4",
67 | "profile": "https://www.jetbrains.com",
68 | "contributions": [
69 | "plugin"
70 | ]
71 | },
72 | {
73 | "login": "stleary",
74 | "name": "Sean Leary",
75 | "avatar_url": "https://avatars3.githubusercontent.com/u/5107558?v=4",
76 | "profile": "http://www.johnjleary.com",
77 | "contributions": [
78 | "plugin"
79 | ]
80 | },
81 | {
82 | "login": "cjbrooks12",
83 | "name": "Casey Brooks",
84 | "avatar_url": "https://avatars2.githubusercontent.com/u/6157866?v=4",
85 | "profile": "https://www.caseyjbrooks.com/",
86 | "contributions": [
87 | "code",
88 | "doc"
89 | ]
90 | },
91 | {
92 | "login": "Ghost-chu",
93 | "name": "Ghost_chu",
94 | "avatar_url": "https://avatars.githubusercontent.com/u/30802565?v=4",
95 | "profile": "http://blog.mcsunnyside.com",
96 | "contributions": [
97 | "code"
98 | ]
99 | }
100 | ],
101 | "contributorsPerLine": 7,
102 | "projectName": "JavaBotBlockAPI",
103 | "projectOwner": "botblock",
104 | "repoType": "github",
105 | "repoHost": "https://github.com",
106 | "skipCi": true
107 | }
108 |
--------------------------------------------------------------------------------
/.github/CONTRIBUTING.md:
--------------------------------------------------------------------------------
1 |
2 | [discord]: https://discord.gg/6dazXp6
3 | [codemc]: https://ci.codemc.io
4 |
5 |
6 | [issues]: https://github.com/botblock/JavaBotBlockAPI/issues
7 | [feature]: https://github.com/botblock/JavaBotBlockAPI/issues/new?labels=Type%3A+Enhancement&template=feature_request.yml
8 | [bug]: https://github.com/botblock/JavaBotBlockAPI/issues/new?labels=Type%3A+Bug+%28Unconfirmed%29&template=bug_report.yml
9 | [discussion]: https://github.com/botblock/JavaBotBlockAPI/discussions
10 | [checkutil]: https://github.com/botblock/JavaBotBlockAPI/blob/master/core/src/main/java/org/botblock/javabotblockapi/core/CheckUtil.java
11 |
12 | # Contributing Guidelines
13 | We welcome any kind of contributions to JavaBotBlockAPI but also expect some level of quality to be followed.
14 |
15 | Please read this guide carefully before either submitting an issue or Pull request to not risk getting them closed without warning.
16 |
17 | ## Issues
18 | Issues should be reported either on our [Discord Server][discord] or through our [Issue tracker][issues] depending on the type of issue.
19 |
20 | ### Feature requests
21 | Feature requests should be made through the [Feature request template][feature] on our Issue tracker.
22 | Alternatively can you also create a [discussion] to suggest a change in the "Suggestions" category.
23 |
24 | ### Security issues
25 | Issues regarding security should always be reported through our [Discord server][discord] since the Issue tracker isn't a save place to do this.
26 | On the Server, head over to the `#javabotblockapi` channel and inform `Andre_601#0601` about ths issue.
27 |
28 | ### Bug reports
29 | Any other bug report should be made through the [Bug report template][bug] on our Issue tracker.
30 |
31 | ## Pull requests
32 | Pull requests to improve JavaBotBlockAPI are always welcome as long as you follow these basic rules.
33 |
34 | ### Target Branch
35 | We have different branches on this repository that all serve a different purpose.
36 |
37 | #### master
38 | The `master` branch is the main branch for new releases.
39 | Whenever enough changes have been accumulated on the [development branch](#development) will it be merged into master through a Pull request which then creates a new release on the Nexus Repository of [CodeMC].
40 |
41 | Only Pull requests from the development branch are allowed to target the master branch and any other PR will be rejected.
42 |
43 | #### development
44 | The `development` branch is the go-to branch for all changes towards JavaBotBlockAPI.
45 | All changes, no matter if directly to project itself or to other parts such as the GitHub Action Workflow files are made on this branch any and Pull request should target it, no matter what.
46 |
47 | #### gh-pages
48 | The `gh-pages` branch is used to display the Javadoc at https://docs.botblock.org/JavaBotBlockAPI.
49 | This branch is only updated through a GitHub Action and any Pull request targeting this branch will be rejected.
50 |
51 | ### Javadoc formatting
52 | We have specific styling Guides when it comes to Javadocs.
53 | A general rule is, that you have to document ANY method that is public and should be used by the end user in some way.
54 |
55 | #### Line breaks and Paragraphs
56 | New lines and paragraphs are made using the `
` and `
` tags.
57 | Both tags don't need to be closed and are always placed at the start of a line.
58 |
59 | While the simple line break only needs to be on a new line will the paragraph have an empty line in-between.
60 |
61 | *Example*:
62 | ```java
63 | /**
64 | * This is a description.
65 | *
This is a new line.
66 | *
67 | *
This is a new paragraph. 68 | */ 69 | ``` 70 | 71 | #### Linking 72 | When linking to methods, Objects, Classes or similar should `{@link}` be used. 73 | 74 | Always use the full path to a class, method, etc. 75 | Only exception is for methods within the same Class in which case you use `{@link #methodName() methodName()}`. 76 | 77 | In all cases should you always add an alternative text to the link, even if it would be the exact same output as without it. 78 | 79 | *Example*: 80 | ```java 81 | /** 82 | * Bad 83 | * {@link BotBlockAPI} 84 | * 85 | * Also Bad (Missing Alternative Text) 86 | * {@link org.botblock.javabotblockapi.core.BotBlockAPI} 87 | * 88 | * Good 89 | * {@link org.botblock.javabotblockapi.core.BotBlockAPI BotBlockAPI} 90 | */ 91 | ``` 92 | 93 | `{@link}` is also used for linking to external dependencies such as Java, JDA or JSON-java. 94 | 95 | When you want to link to external pages that aren't Javadocs should you use the `a` HTML-tag. 96 | When doing so, always close the tag (``) and include `target="_blank"`. 97 | 98 | #### Parameters 99 | Methods with parameters need to have their parameters documented using `@param`. 100 | 101 | The description of the parameter is always on a new line right below the parameter name. 102 | 103 | *Example*: 104 | ```java 105 | /** 106 | * @param foo 107 | * Description goes here. 108 | */ 109 | ``` 110 | 111 | #### Since 112 | We use `@since` to mention since when a specific method, field or class is available. 113 | The mentioned version is always in the format `major.minor.patch` 114 | 115 | Always add `@since` to newly added methods, classes and/or fields but never alter existing ones or add them to already existing methods, classes or fields. 116 | 117 | #### Deprecation 118 | Any deprecation follows a specific deprecation-policy we have. 119 | 120 | Whenever you deprecate a method, object, field or similar will you need to add the `@Deprecated` annotation from Java as-well as the `@DeprecatedSince` and `@PlannedRemoval` annotations from us. 121 | The `@DeprecatedSince` annotation should have the major, minor and patch version mentioned since when the marked object is deprecated and, if available, also mention a replacement that should be used. 122 | `@PlannedRemoval` is used to mark when the object will be removed. The mentioned major, minor and patch version should always be at least 2 patches after the version of the deprecation. This means that a method deprecated in 6.6.0 would have a planned removal of 6.6.2 or higher. 123 | 124 | Whenever an object is marked as deprecated should the Javadoc comment contain the `@deprecated` tag alongside a description explaining why it was deprecated and any mention of alternatives to use. 125 | 126 | At no point should a object be removed without the aforementioned grace-period and setup. 127 | 128 | #### CheckUtil 129 | JavaBotBlockAPI utilizes a [CheckUtil] class to perform certain checks whenever a method is used. 130 | If you use methods of the CheckUtil are you required to add the following part into the Javadoc comment of the method: 131 | ```java 132 | /** 133 | *
Following Exceptions can be thrown from the CheckUtil: 134 | *
Following Exceptions can be thrown from the HTTP request: 151 | *
Following Exceptions can be thrown from the CheckUtil: 187 | *
Use the {@link org.botblock.javabotblockapi.core.BotBlockAPI.Builder BotBlockAPI.Builder} class for easy creation.
29 | */
30 | public class BotBlockAPI{
31 | /**
32 | * Default delay. Used for when no own delay was defined with {@link org.botblock.javabotblockapi.core.BotBlockAPI.Builder#setUpdateDelay(Integer) BotBlock.Builder.setUpdateDelay(Integer)}
33 | */
34 | public static final int DEFAULT_DELAY = 30;
35 |
36 | private final Map Following Exceptions can be thrown from the CheckUtil:
78 | * Following Exceptions can be thrown from the CheckUtil:
111 | * Following Exceptions can be thrown from the CheckUtil:
137 | * Following Exceptions can be thrown from the CheckUtil:
158 | * Following Exceptions can be thrown from the CheckUtil:
175 | * The class can be used for things such as determining the {@link #VERSION used version} or to get some static info
25 | * like the {@link #GITHUB GitHub} or {@link #JENKINS Jenkins CI} URL.
26 | *
27 | * @since 6.6.0
28 | */
29 | public class Info{
30 |
31 | /**
32 | * Major version of the Wrapper.
33 | */
34 | public static final int MAJOR = 6;
35 | /**
36 | * Minor version of the Wrapper.
37 | */
38 | public static final int MINOR = 7;
39 | /**
40 | * Patch version of the Wrapper.
41 | */
42 | public static final int PATCH = 4;
43 |
44 | /**
45 | * Full version in the format {@code major.minor.patch}.
46 | */
47 | public static final String VERSION = String.format("%d.%d.%d", MAJOR, MINOR, PATCH);
48 |
49 | /**
50 | * URL to the GitHub repository.
51 | */
52 | public static final String GITHUB = "https://github.com/botblock/JavaBotBlockAPI";
53 |
54 | public static final String JENKINS = "https://ci.codemc.io/job/botblock/job/JavaBotBlockAPI";
55 | }
56 |
--------------------------------------------------------------------------------
/core/src/main/java/org/botblock/javabotblockapi/core/Site.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 - 2020 Andre601
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
6 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
7 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8 | *
9 | * The above copyright notice and this permission notice shall be included in all copies or substantial
10 | * portions of the Software.
11 | *
12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
14 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
15 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
16 | * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17 | */
18 |
19 | package org.botblock.javabotblockapi.core;
20 |
21 | import org.botblock.javabotblockapi.core.annotations.DeprecatedSince;
22 | import org.botblock.javabotblockapi.core.annotations.PlannedRemoval;
23 |
24 | import java.util.ArrayList;
25 | import java.util.Arrays;
26 | import java.util.List;
27 |
28 | /**
29 | * This class contains all known sites that are supported by BotBlock's APIs for getting Bot info, getting list info or
30 | * posting Bot info to a list.
31 | *
32 | * The static instances of this class allow an easy and quick usage in various methods of JavaBotBlockAPI without the
33 | * need to remember any bot list name.
34 | *
35 | * Trying to use a List for an action it doesn't support (i.e. using a List for POST while it only supports GET) will
42 | * result in exceptions being thrown.
43 | * Supported methods:
55 | * Supported methods:
68 | * Supported methods:
79 | * Supported methods:
90 | * Supported methods:
103 | * Supported methods:
114 | * Supported methods:
130 | * Supported methods:
140 | * Supported methods:
150 | * Supported methods:
161 | * Supported methods:
172 | * Supported methods:
185 | * Supported methods:
196 | * Supported methods:
207 | * Supported methods:
218 | * Supported methods:
229 | * Supported methods:
240 | * Supported methods:
250 | * Supported methods:
260 | * Supported methods:
271 | * Supported methods:
284 | * Supported methods:
295 | * Supported methods:
308 | * Supported methods:
321 | * Supported methods:
334 | * Supported methods:
345 | * Supported methods:
357 | * Supported methods:
368 | * Supported methods:
381 | * Supported methods:
392 | * Supported methods:
403 | * Depending on what Http-Methods a bot list supports can its corresponding entry be used for the GET methods,
455 | * POST methods or both.
456 | */
457 | public enum HttpMethod{
458 | /**
459 | * Bot list supports GET requests.
460 | */
461 | GET,
462 |
463 | /**
464 | * Bot list supports POST requests.
465 | */
466 | POST
467 | }
468 | }
469 |
--------------------------------------------------------------------------------
/core/src/main/java/org/botblock/javabotblockapi/core/annotations/DeprecatedSince.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 - 2020 Andre601
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
6 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
7 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8 | *
9 | * The above copyright notice and this permission notice shall be included in all copies or substantial
10 | * portions of the Software.
11 | *
12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
14 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
15 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
16 | * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17 | */
18 |
19 | package org.botblock.javabotblockapi.core.annotations;
20 |
21 | import java.lang.annotation.*;
22 |
23 | /**
24 | * Annotation used to indicate since when an Object is deprecated.
25 | * A replacement may be mentioned with the {@link #replacements() replacements String array} but is not guaranteed.
28 | * When a removal is planned will a {@link org.botblock.javabotblockapi.core.annotations.PlannedRemoval PlannedRemoval}
31 | * annotation be added to indicate the version of the Object's removal.
32 | *
33 | * @since 3.2.0
34 | */
35 | @Documented
36 | @Retention(RetentionPolicy.RUNTIME)
37 | @Target({ElementType.METHOD, ElementType.FIELD, ElementType.TYPE, ElementType.CONSTRUCTOR})
38 | public @interface DeprecatedSince{
39 |
40 | /**
41 | * The Major version since when the annotated object is deprecated.
42 | *
43 | * @return int representing the major version.
44 | *
45 | * @since 6.3.0
46 | */
47 | int major();
48 |
49 | /**
50 | * The Minor version since when the annotated object is deprecated.
51 | *
52 | * @return int representing the minor version.
53 | *
54 | * @since 6.3.0
55 | */
56 | int minor();
57 |
58 | /**
59 | * The Patch version since when the annotated object is deprecated.
60 | *
61 | * @return int representing the patch version.
62 | *
63 | * @since 6.3.0
64 | */
65 | int patch();
66 |
67 | /**
68 | * Optional String array indicating one or multiple possible replacement Objects to use.
69 | *
70 | * @return The Object(s) to use instead of the deprecated one.
71 | */
72 | String[] replacements() default {""};
73 | }
74 |
--------------------------------------------------------------------------------
/core/src/main/java/org/botblock/javabotblockapi/core/annotations/PlannedRemoval.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 - 2020 Andre601
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
6 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
7 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8 | *
9 | * The above copyright notice and this permission notice shall be included in all copies or substantial
10 | * portions of the Software.
11 | *
12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
14 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
15 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
16 | * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17 | */
18 |
19 | package org.botblock.javabotblockapi.core.annotations;
20 |
21 | import java.lang.annotation.*;
22 |
23 | /**
24 | * Annotation to mark an Object to be planned for removal.
25 | * This annotation will always contain the {@link #major() major}, {@link #minor() minor} and {@link #patch() patch} version
29 | * in which the annotated Object will be removed.
30 | * Note that this Wrapper will do no attempt at delaying any further requests! It is your own responsibility to
30 | * handle rate limits properly in those cases and delay any future requests accordingly.
31 | * If you still want to do it manually, or can't use one of the other option, head over to the
62 | * GitHub releases page and
63 | * download the jar files from there.
64 | *
65 | * Note that you will not receive any support when using this method.
66 | */
67 | package org.botblock.javabotblockapi.core;
--------------------------------------------------------------------------------
/docs/assets/img/JavaBotBlockAPI.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/botblock/JavaBotBlockAPI/5a21d3d14822c24aafbe4474f54f7061db4f4b14/docs/assets/img/JavaBotBlockAPI.png
--------------------------------------------------------------------------------
/docs/assets/img/jbba.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/botblock/JavaBotBlockAPI/5a21d3d14822c24aafbe4474f54f7061db4f4b14/docs/assets/img/jbba.png
--------------------------------------------------------------------------------
/docs/index.md:
--------------------------------------------------------------------------------
1 | # JavaBotBlockAPI
2 | A Java Wrapper for the BotBlock.org API, supporting all API endpoints of it.
3 |
4 | ## Javadocs
5 | Below can you find Javadocs for each module.
6 |
7 | - [Core](https://docs.botblock.org/JavaBotBlockAPI/core/)
8 | - [Javacord](https://docs.botblock.org/JavaBotBlockAPI/javacord/org/botblock/javabotblockapi/javacord/package-summary.html)
9 | - [JDA](https://docs.botblock.org/JavaBotBlockAPI/jda/org/botblock/javabotblockapi/jda/package-summary.html)
10 | - [Request](https://docs.botblock.org/JavaBotBlockAPI/request/org/botblock/javabotblockapi/requests/package-summary.html)
11 |
12 | ## Installation
13 | Please replace `{version}` with the latest build available on [CodeMC](https://ci.codemc.io/job/botblock/job/JavaBotBlockAPI/).
14 |
15 | ### Gradle
16 | ```groovy
17 | repositories{
18 | maven{ url = 'https://repo.codemc.io/repository/maven-public' }
19 | }
20 |
21 | dependencies{
22 | // The Core and Request modules are always required.
23 | compile group: 'org.botblock', name: 'javabotblockapi-core', version: '{version}'
24 | compile group: 'org.botblock', name: 'javabotblockapi-request', version: '{version}'
25 |
26 | // Javacord module for direct support with Javacord.
27 | compile group: 'org.botblock', name: 'javabotblockapi-javacord', version: '{version}'
28 |
29 | // JDA module for direct support with JDA.
30 | compile group: 'org.botblock', name: 'javabotblockapi-jda', version: '{version}'
31 | }
32 | ```
33 |
34 | ### Maven
35 | ```xml
36 | The class offers options to post either {@link #postGuilds(BotBlockAPI, DiscordApi...) manually} or
47 | * {@link #enableAutoPost(BotBlockAPI, DiscordApi...) automatically}.
48 | *
49 | * If you want to post without using Javacord, use the {@link org.botblock.javabotblockapi.requests.PostAction normal PostAction}.
50 | */
51 | public class PostAction{
52 | private final Logger LOG = LoggerFactory.getLogger("JavaBotBlockAPI - PostAction (Javacord)");
53 |
54 | private final RequestHandler requestHandler;
55 | private final ScheduledExecutorService scheduler;
56 |
57 | /**
58 | * Creates a new instance of this class.
59 | * Note that using this method will NOT make the scheduler wait for previously scheduled tasks to complete.
82 | * Passing null as argument will just perform a {@link java.util.concurrent.ScheduledExecutorService#shutdown() ScheduledExecutorService.shutdown()}
97 | * similar to what the disableAutoPost() method does.
98 | *
99 | * If you want to use a different delay than what you've set in the BotBlockAPI instance, can you use
100 | * {@link #disableAutoPost(long, TimeUnit) disableAutoPost(long, TimeUnit)} instead.
101 | *
102 | * This method may throw a {@link java.lang.InterruptedException InterruptedException} in the terminal.
103 | *
104 | * @param botBlockAPI
105 | * The {@link org.botblock.javabotblockapi.core.BotBlockAPI BotBlockAPI instance} or null to just perform a shutdown.
106 | *
107 | * @see java.util.concurrent.ScheduledExecutorService#shutdown()
108 | * @see java.util.concurrent.ScheduledExecutorService#awaitTermination(long, TimeUnit)
109 | */
110 | public void disableAutoPost(@Nullable BotBlockAPI botBlockAPI){
111 | if(botBlockAPI != null){
112 | disableAutoPost(botBlockAPI.getUpdateDelay(), TimeUnit.MINUTES);
113 | return;
114 | }
115 |
116 | scheduler.shutdown();
117 | }
118 |
119 | /**
120 | * Disables the automatic posting of Stats.
121 | * This method may throw a {@link java.lang.InterruptedException InterruptedException} in the terminal.
125 | *
126 | * Following Exceptions can be thrown from the CheckUtil:
127 | * If the post can't be performed - either by getting a {@link org.botblock.javabotblockapi.core.exceptions.RateLimitedException RatelimitedException}
155 | * or by getting an {@link java.io.IOException IOException} - will the exception be caught and a Stacktrace printed.
156 | *
157 | * The scheduler will wait an initial delay of 1 minute and then performs a task every n minutes, where n is the
158 | * time set in {@link org.botblock.javabotblockapi.core.BotBlockAPI.Builder#setUpdateDelay(Integer) BotBlockAPI.Builder.setUpdateDelay(Integer)}
159 | * (default is 30 minutes).
160 | *
161 | * Following Exceptions can be thrown from the CheckUtil:
162 | * If the provided DiscordApi instance is a sharded Bot (Amount of shards is larger than 1) will the request
188 | * contain the {@code shards} array alongside a {@code shard_count} field.
189 | *
190 | * Following Exceptions can be thrown from the CheckUtil:
191 | * If you still want to do it manually, or can't use one of the other option, head over to the
78 | * GitHub releases page and
79 | * download the jar files from there.
80 | *
81 | * Note that you will not receive any support when using this method.
82 | */
83 | package org.botblock.javabotblockapi.javacord;
--------------------------------------------------------------------------------
/jda/build.gradle:
--------------------------------------------------------------------------------
1 | dependencies {
2 | api(group: 'net.dv8tion', name: 'JDA', version: '4.3.0_280'){
3 | exclude(module: 'opus-java')
4 | }
5 | implementation project(":core")
6 | implementation project(":request")
7 | }
8 |
--------------------------------------------------------------------------------
/jda/src/main/java/org/botblock/javabotblockapi/jda/PostAction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 - 2020 Andre601
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
6 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
7 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8 | *
9 | * The above copyright notice and this permission notice shall be included in all copies or substantial
10 | * portions of the Software.
11 | *
12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
14 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
15 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
16 | * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17 | */
18 |
19 | package org.botblock.javabotblockapi.jda;
20 |
21 | import net.dv8tion.jda.api.JDA;
22 | import net.dv8tion.jda.api.sharding.ShardManager;
23 | import org.botblock.javabotblockapi.core.BotBlockAPI;
24 | import org.botblock.javabotblockapi.core.Info;
25 | import org.botblock.javabotblockapi.core.exceptions.RateLimitedException;
26 | import org.botblock.javabotblockapi.core.CheckUtil;
27 | import org.botblock.javabotblockapi.requests.handler.RequestHandler;
28 | import org.json.JSONArray;
29 | import org.json.JSONObject;
30 | import org.slf4j.Logger;
31 | import org.slf4j.LoggerFactory;
32 |
33 | import javax.annotation.Nonnull;
34 | import javax.annotation.Nullable;
35 | import java.io.IOException;
36 | import java.util.ArrayList;
37 | import java.util.Arrays;
38 | import java.util.List;
39 | import java.util.Objects;
40 | import java.util.concurrent.ScheduledExecutorService;
41 | import java.util.concurrent.TimeUnit;
42 |
43 | /**
44 | * Class used to perform POST requests towards the /api/count
45 | * endpoint of BotBlock using the JDA Library.
46 | *
47 | * The class offers options to post either {@link #postGuilds(JDA, BotBlockAPI) manually} or
48 | * {@link #enableAutoPost(JDA, BotBlockAPI) automatically}.
49 | * If you want to post without using either instance, use the {@link org.botblock.javabotblockapi.requests.PostAction normal PostAction}.
53 | */
54 | public class PostAction{
55 | private final Logger LOG = LoggerFactory.getLogger("JavaBotBlockAPI - PostAction (JDA)");
56 |
57 | private final RequestHandler requestHandler;
58 | private final ScheduledExecutorService scheduler;
59 |
60 | /**
61 | * Creates a new instance of this class.
62 | * Note that using this method will NOT make the scheduler wait for previously scheduled tasks to complete.
97 | * Passing null as argument will just perform a {@link java.util.concurrent.ScheduledExecutorService#shutdown() ScheduledExecutorService.shutdown()}
112 | * similar to what the disableAutoPost() method does.
113 | *
114 | * If you want to use a different delay than what you've set in the BotBlockAPI instance, can you use
115 | * {@link #disableAutoPost(long, TimeUnit) disableAutoPost(long, TimeUnit)} instead.
116 | *
117 | * This method may throw a {@link java.lang.InterruptedException InterruptedException} in the terminal.
118 | *
119 | * @param botBlockAPI
120 | * The {@link org.botblock.javabotblockapi.core.BotBlockAPI BotBlockAPI instance} or null to just perform a shutdown.
121 | *
122 | * @since 6.0.0
123 | *
124 | * @see java.util.concurrent.ScheduledExecutorService#shutdown()
125 | * @see java.util.concurrent.ScheduledExecutorService#awaitTermination(long, TimeUnit)
126 | */
127 | public void disableAutoPost(@Nullable BotBlockAPI botBlockAPI){
128 | if(botBlockAPI != null){
129 | disableAutoPost(botBlockAPI.getUpdateDelay(), TimeUnit.MINUTES);
130 | return;
131 | }
132 |
133 | scheduler.shutdown();
134 | }
135 |
136 | /**
137 | * Disables the automatic posting of Stats.
138 | * This method may throw a {@link java.lang.InterruptedException InterruptedException} in the terminal.
142 | *
143 | * Following Exceptions can be thrown from the CheckUtil:
144 | * If the post can't be performed - either by getting a {@link org.botblock.javabotblockapi.core.exceptions.RateLimitedException RatelimitedException}
174 | * or by getting an {@link java.io.IOException IOException} - will the exception be catched and the stacktrace printed.
175 | *
176 | * The scheduler will wait an initial delay of 1 minute and then performs a task every n minutes, where n is the
177 | * time set in {@link org.botblock.javabotblockapi.core.BotBlockAPI.Builder#setUpdateDelay(Integer) BotBlockAPI.Builder.setUpdateDelay(Integer)}
178 | * (default is 30 minutes).
179 | *
180 | * If you have a sharded bot is it recommendet to use {@link #enableAutoPost(ShardManager, BotBlockAPI) enableAutoPost(ShardManager, BotBlockAPI)} instead.
181 | *
182 | * @param jda
183 | * The {@link net.dv8tion.jda.api.JDA JDA instance} to post stats from.
184 | * @param botBlockAPI
185 | * The {@link org.botblock.javabotblockapi.core.BotBlockAPI BotBlockAPI instance} to use.
186 | */
187 | public void enableAutoPost(@Nonnull JDA jda, @Nonnull BotBlockAPI botBlockAPI){
188 | scheduler.scheduleAtFixedRate(() -> {
189 | try{
190 | postGuilds(jda, botBlockAPI);
191 | }catch(IOException | RateLimitedException ex){
192 | LOG.warn("Got an exception while performing a auto-post task!", ex);
193 | }
194 | }, 1, botBlockAPI.getUpdateDelay(), TimeUnit.MINUTES);
195 | }
196 |
197 | /**
198 | * Starts a {@link java.util.concurrent.ScheduledExecutorService#scheduleAtFixedRate(Runnable, long, long, TimeUnit) scheduleAtFixedRate}
199 | * task, which will post the statistics of the provided {@link net.dv8tion.jda.api.sharding.ShardManager ShardManager instance} every n minutes.
200 | *
201 | * If the post can't be performed - either by getting a {@link org.botblock.javabotblockapi.core.exceptions.RateLimitedException RatelimitedException}
202 | * or by getting an {@link java.io.IOException IOException} - will the exception be caught and a Stacktrace printed.
203 | *
204 | * The scheduler will wait an initial delay of 1 minute and then performs a task every n minutes, where n is the
205 | * time set in {@link org.botblock.javabotblockapi.core.BotBlockAPI.Builder#setUpdateDelay(Integer) BotBlockAPI.Builder.setUpdateDelay(Integer)}
206 | * (default is 30 minutes).
207 | *
208 | * @param shardManager
209 | * The {@link net.dv8tion.jda.api.sharding.ShardManager ShardManager instance} to post stats from.
210 | * @param botBlockAPI
211 | * The {@link org.botblock.javabotblockapi.core.BotBlockAPI BotBlockAPI instance} to use.
212 | */
213 | public void enableAutoPost(@Nonnull ShardManager shardManager, @Nonnull BotBlockAPI botBlockAPI){
214 | scheduler.scheduleAtFixedRate(() -> {
215 | try{
216 | postGuilds(shardManager, botBlockAPI);
217 | }catch(IOException | RateLimitedException ex){
218 | LOG.warn("Got an exception while performing a auto-post task!", ex);
219 | }
220 | }, botBlockAPI.getUpdateDelay(), botBlockAPI.getUpdateDelay(), TimeUnit.MINUTES);
221 | }
222 |
223 | /**
224 | * Performs a POST request towards the BotBlock API using the information from the provided
225 | * {@link net.dv8tion.jda.api.JDA JDA} and {@link org.botblock.javabotblockapi.core.BotBlockAPI BotBlockAPI} instances.
226 | *
227 | * If the provided JDA instance also is part of a sharded Bot (Amount of shards is larger than 1) will the request
228 | * also include {@code shard_id} and {@code shard_count}
229 | *
230 | * @param jda
231 | * The {@link net.dv8tion.jda.api.JDA JDA instance} to post stats from.
232 | * @param botBlockAPI
233 | * The {@link org.botblock.javabotblockapi.core.BotBlockAPI BotBlockAPI instance} to use.
234 | *
235 | * @throws java.io.IOException
236 | * When the POST request wasn't successful.
237 | * @throws org.botblock.javabotblockapi.core.exceptions.RateLimitedException
238 | * When we get rate limited by the BotBlock API (returns error code 429).
239 | */
240 | public void postGuilds(@Nonnull JDA jda, @Nonnull BotBlockAPI botBlockAPI) throws IOException, RateLimitedException{
241 | JSONObject json = new JSONObject()
242 | .put("server_count", jda.getGuildCache().size())
243 | .put("bot_id", jda.getSelfUser().getId());
244 |
245 | if(jda.getShardInfo().getShardTotal() > 1)
246 | json.put("shard_id", jda.getShardInfo().getShardId())
247 | .put("shard_count", jda.getShardInfo().getShardTotal());
248 |
249 | botBlockAPI.getTokens().forEach(json::put);
250 |
251 | requestHandler.performPOST(json, botBlockAPI.getTokens().size());
252 | }
253 |
254 | /**
255 | * Performs a POST request towards the BotBlock API using the information from the provided
256 | * {@link net.dv8tion.jda.api.sharding.ShardManager ShardManager} and {@link org.botblock.javabotblockapi.core.BotBlockAPI BotBlockAPI} instances.
257 | *
258 | * The following Exceptions may be thrown by the CheckUtil:
259 | * If you still want to do it manually, or can't use one of the other option, head over to the
79 | * GitHub releases page and
80 | * download the jar files from there.
81 | *
82 | * Note that you will not receive any support when using this method.
83 | */
84 | package org.botblock.javabotblockapi.jda;
--------------------------------------------------------------------------------
/request/build.gradle:
--------------------------------------------------------------------------------
1 | dependencies {
2 | implementation project(":core")
3 | api group: 'com.squareup.okhttp3', name: 'okhttp', version: '4.9.1'
4 | }
5 |
6 | javadoc {
7 | exclude "org/botblock/javabotblockapi/requests/handler"
8 | }
9 |
--------------------------------------------------------------------------------
/request/src/main/java/org/botblock/javabotblockapi/requests/GetBotAction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 - 2020 Andre601
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
6 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
7 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8 | *
9 | * The above copyright notice and this permission notice shall be included in all copies or substantial
10 | * portions of the Software.
11 | *
12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
14 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
15 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
16 | * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17 | */
18 |
19 | package org.botblock.javabotblockapi.requests;
20 |
21 | import org.botblock.javabotblockapi.core.Info;
22 | import org.botblock.javabotblockapi.core.Site;
23 | import org.botblock.javabotblockapi.core.CheckUtil;
24 | import org.botblock.javabotblockapi.core.exceptions.RateLimitedException;
25 | import org.botblock.javabotblockapi.requests.handler.RequestHandler;
26 | import org.json.JSONArray;
27 | import org.json.JSONObject;
28 |
29 | import javax.annotation.Nonnull;
30 | import javax.annotation.Nullable;
31 | import java.util.ArrayList;
32 | import java.util.List;
33 |
34 | /**
35 | * Class used to perform GET actions on the {@code /api/bots/:id} endpoint.
36 | *
37 | * GET requests are cached for 2 minutes unless disabled through either {@link #GetBotAction(boolean, String) GetBotAction(true, String)}
38 | * or {@link #GetBotAction(boolean, String, String) GetBotAction(true, String, String)}.
39 | *
40 | * @since 5.0.0
41 | */
42 | public class GetBotAction{
43 |
44 | private final RequestHandler REQUEST_HANDLER;
45 |
46 | private final boolean disableCache;
47 |
48 | /**
49 | * Constructor to get an instance of GetBotAction.
50 | *
51 | * Using this constructor will set the following default values ({@code {id}} will be replaced with the provided ID):
52 | * Following Exceptions can be thrown from the CheckUtil:
58 | * Using this constructor will set the following default values ({@code {id}} will be replaced with the provided ID):
74 | * Following Exceptions can be thrown from the CheckUtil:
79 | * Note that you can provide {@code {id}} inside the userAgent to get it replaced with the provided id.
102 | *
103 | * Following Exceptions can be thrown from the CheckUtil:
104 | * Following Exceptions can be thrown from the HTTP request:
131 | * Following Exceptions can be thrown from the CheckUtil:
153 | * Following Exceptions can be thrown from the HTTP request:
158 | * This method may also return {@code null} if the request wasn't successful.
164 | *
165 | * @param id
166 | * The id of the bot to get the information from.
167 | *
168 | * @return Possibly-null {@link org.json.JSONObject JSONObject} containing the full information of the bot.
169 | */
170 | @Nullable
171 | public JSONObject getBotInfo(@Nonnull String id){
172 | CheckUtil.notEmpty(id, "id");
173 |
174 | return REQUEST_HANDLER.performGetBot(id, disableCache);
175 | }
176 |
177 | /**
178 | * Gets the information from the various bot lists.
179 | * Following Exceptions can be thrown from the HTTP request:
182 | * This method may also return {@code null} if the request wasn't successful.
188 | *
189 | * @param id
190 | * The bots id to use.
191 | *
192 | * @return Possibly-null {@link org.json.JSONObject JSONObject} containing information from the different bot list.
193 | */
194 | @Nullable
195 | public JSONObject getBotListInfo(long id){
196 | return getBotListInfo(String.valueOf(id));
197 | }
198 |
199 | /**
200 | * Gets the information from the various bot lists.
201 | * Following Exceptions can be thrown from the HTTP request:
204 | * This method may also return {@code null} if the request wasn't successful.
213 | *
214 | * @param id
215 | * The id of the bot to get the bot list info from.
216 | *
217 | * @return Possibly-null {@link org.json.JSONObject JSONObject} containing information from the different bot list.
218 | */
219 | @Nullable
220 | public JSONObject getBotListInfo(@Nonnull String id){
221 | CheckUtil.notEmpty(id, "id");
222 |
223 | JSONObject json = getBotInfo(id);
224 | if(json == null)
225 | return null;
226 |
227 | return json.getJSONObject("list_data");
228 | }
229 |
230 | /**
231 | * Gets the information from the specified bot list.
232 | * Following Exceptions can be thrown from the CheckUtil:
235 | * Following Exceptions can be thrown from the HTTP request:
240 | * This method may also return {@code null} if the request wasn't successful.
246 | *
247 | * @param id
248 | * The id of the bot to get the bot list info from.
249 | * @param site
250 | * The {@link org.botblock.javabotblockapi.core.Site site} to get info from.
251 | *
252 | * @return Possibly-null {@link org.json.JSONArray JSONArray} containing the information of the provided bot list.
253 | */
254 | @Nullable
255 | public JSONArray getBotListInfo(@Nonnull Long id, @Nonnull Site site){
256 | CheckUtil.condition(!site.supportsGet(), site.getName() + " does not support GET requests!");
257 |
258 | return getBotListInfo(String.valueOf(id), site);
259 | }
260 |
261 | /**
262 | * Gets the information from the specified bot list.
263 | * Following Exceptions can be thrown from the CheckUtil:
266 | * Following Exceptions can be thrown from the HTTP request:
271 | * This method may also return {@code null} if the request wasn't successful.
277 | *
278 | * @param id
279 | * The id of the bot to get the bot list info from.
280 | * @param site
281 | * The {@link org.botblock.javabotblockapi.core.Site site} to get info from.
282 | *
283 | * @return Possibly-null {@link org.json.JSONArray JSONArray} containing the information of the provided bot list.
284 | */
285 | @Nullable
286 | public JSONArray getBotListInfo(@Nonnull Long id, @Nonnull String site){
287 | CheckUtil.notEmpty(site, "site");
288 |
289 | return getBotListInfo(String.valueOf(id), site);
290 | }
291 |
292 | /**
293 | * Gets the information from the specified bot list.
294 | * Following Exceptions can be thrown from the CheckUtil:
297 | * Following Exceptions can be thrown from the HTTP request:
303 | * This method may also return {@code null} if the request wasn't successful.
309 | *
310 | * @param id
311 | * The id of the bot to get the bot list info from.
312 | * @param site
313 | * The {@link org.botblock.javabotblockapi.core.Site site} to get info from.
314 | *
315 | * @return Possibly-null {@link org.json.JSONArray JSONArray} containing the information of the provided bot list.
316 | */
317 | @Nullable
318 | public JSONArray getBotListInfo(@Nonnull String id, @Nonnull Site site){
319 | CheckUtil.notEmpty(id, "id");
320 | CheckUtil.condition(!site.supportsGet(), site.getName() + " does not support GET requests!");
321 |
322 | JSONObject json = getBotListInfo(id);
323 | if(json == null)
324 | return null;
325 |
326 | return json.getJSONArray(site.getName());
327 | }
328 |
329 | /**
330 | * Gets the information from the specified bot list.
331 | * Following Exceptions can be thrown from the CheckUtil:
334 | * Following Exceptions can be thrown from the HTTP request:
339 | * This method may also return {@code null} if the request wasn't successful.
345 | *
346 | * @param id
347 | * The id of the bot to get the bot list info from.
348 | * @param site
349 | * The {@link org.botblock.javabotblockapi.core.Site site} to get info from.
350 | *
351 | * @return Possibly-null {@link org.json.JSONArray JSONArray} containing the information of the provided bot list.
352 | */
353 | @Nullable
354 | public JSONArray getBotListInfo(@Nonnull String id, @Nonnull String site){
355 | CheckUtil.notEmpty(id, "id");
356 | CheckUtil.notEmpty(site, "site");
357 |
358 | JSONObject json = getBotListInfo(id);
359 | if(json == null)
360 | return null;
361 |
362 | return json.getJSONArray(site);
363 | }
364 |
365 | /**
366 | * Gets the discriminator (The 4 numbers after the # in the username) of the bot.
367 | * Following Exceptions can be thrown from the HTTP request:
370 | * This method may also return {@code null} if the request wasn't successful.
376 | *
377 | * @param id
378 | * The id of the bot to get the discriminator from.
379 | *
380 | * @return Possibly-null String containing the discriminator of the bot or {@code 0000} if the provided id is invalid.
381 | *
382 | * @since 4.2.0
383 | */
384 | @Nullable
385 | public String getDiscriminator(@Nonnull Long id){
386 | return getDiscriminator(String.valueOf(id));
387 | }
388 |
389 | /**
390 | * Gets the discriminator (The 4 numbers after the # in the username) of the bot.
391 | * Following Exceptions can be thrown from the CheckUtil:
394 | * Following Exceptions can be thrown from the HTTP request:
399 | * This method may also return {@code null} if the request wasn't successful.
405 | *
406 | * @param id
407 | * The id of the bot to get the discriminator from.
408 | *
409 | * @return Possibly-null String containing the discriminator of the bot or {@code 0000} if the provided id is invalid.
410 | *
411 | * @since 4.2.0
412 | */
413 | @Nullable
414 | public String getDiscriminator(@Nonnull String id){
415 | CheckUtil.notEmpty(id, "id");
416 |
417 | JSONObject json = getBotInfo(id);
418 | if(json == null)
419 | return null;
420 |
421 | return json.getString("discriminator");
422 | }
423 |
424 | /**
425 | * Gets the GitHub link of the bot.
426 | * Following Exceptions can be thrown from the HTTP request:
429 | * This method may also return {@code null} if the request wasn't successful.
435 | *
436 | * @param id
437 | * The id of the bot to get the GitHub link from.
438 | *
439 | * @return Possibly-null or possibly-empty String containing the GitHub link of the bot.
440 | *
441 | * @since 4.2.0
442 | */
443 | @Nullable
444 | public String getGitHub(@Nonnull Long id){
445 | return getGitHub(String.valueOf(id));
446 | }
447 |
448 | /**
449 | * Gets the GitHub link of the bot.
450 | * Following Exceptions can be thrown from the CheckUtil:
453 | * Following Exceptions can be thrown from the HTTP request:
458 | * This method may also return {@code null} if the request wasn't successful.
464 | *
465 | * @param id
466 | * The id of the bot to get the GitHub link from.
467 | *
468 | * @return Possibly-null or possibly-empty String containing the GitHub link of the bot.
469 | *
470 | * @since 4.2.0
471 | */
472 | @Nullable
473 | public String getGitHub(@Nonnull String id){
474 | CheckUtil.notEmpty(id, "id");
475 |
476 | JSONObject json = getBotInfo(id);
477 | if(json == null)
478 | return null;
479 |
480 | return json.getString("github");
481 | }
482 |
483 | /**
484 | * Gets the currently used library of the bot.
485 | * Following Exceptions can be thrown from the HTTP request:
488 | * This method may also return {@code null} if the request wasn't successful.
494 | *
495 | * @param id
496 | * The id of the bot to get the library from.
497 | *
498 | * @return Possibly-null or possibly-empty String containing the library of the bot.
499 | *
500 | * @since 4.2.0
501 | */
502 | @Nullable
503 | public String getLibrary(@Nonnull Long id){
504 | return getLibrary(String.valueOf(id));
505 | }
506 |
507 | /**
508 | * Gets the currently used library of the bot.
509 | * Following Exceptions can be thrown from the CheckUtil:
512 | * Following Exceptions can be thrown from the HTTP request:
517 | * This method may also return {@code null} if the request wasn't successful.
523 | *
524 | * @param id
525 | * The id of the bot to get the library from.
526 | *
527 | * @return Possibly-null or possibly-empty String containing the library of the bot.
528 | *
529 | * @since 4.2.0
530 | */
531 | @Nullable
532 | public String getLibrary(@Nonnull String id){
533 | CheckUtil.notEmpty(id, "id");
534 |
535 | JSONObject json = getBotInfo(id);
536 | if(json == null)
537 | return null;
538 |
539 | return json.getString("library");
540 | }
541 |
542 | /**
543 | * Gets the name of the bot.
544 | * Following Exceptions can be thrown from the HTTP request:
547 | * This method may also return {@code null} if the request wasn't successful.
553 | *
554 | * @param id
555 | * The id of the bot to get the name from.
556 | *
557 | * @return Possibly-null String containing the name of the bot or {@code Unknown} if the provided id is invalid.
558 | *
559 | * @since 4.2.0
560 | */
561 | @Nullable
562 | public String getName(@Nonnull Long id){
563 | return getName(String.valueOf(id));
564 | }
565 |
566 | /**
567 | * Gets the name of the bot.
568 | * Following Exceptions can be thrown from the CheckUtil:
571 | * Following Exceptions can be thrown from the HTTP request:
576 | * This method may also return {@code null} if the request wasn't successful.
582 | *
583 | * @param id
584 | * The id of the bot to get the name from.
585 | *
586 | * @return Possibly-null String containing the name of the bot or {@code Unknown} if the provided id is invalid.
587 | *
588 | * @since 4.2.0
589 | */
590 | @Nullable
591 | public String getName(@Nonnull String id){
592 | CheckUtil.notEmpty(id, "id");
593 |
594 | JSONObject json = getBotInfo(id);
595 | if(json == null)
596 | return null;
597 |
598 | return json.getString("username");
599 | }
600 |
601 | /**
602 | * Gets the OAuth invite link of a bot.
603 | * Following Exceptions can be thrown from the HTTP request:
606 | * This method may also return {@code null} if the request wasn't successful.
612 | *
613 | * @param id
614 | * The id of the bot to get the OAuth link from.
615 | *
616 | * @return Possibly-null or possibly-empty String containing the OAuth link for the bot.
617 | *
618 | * @since 5.1.13
619 | */
620 | @Nullable
621 | public String getOAuthInvite(@Nonnull Long id){
622 | return getOAuthInvite(String.valueOf(id));
623 | }
624 |
625 | /**
626 | * Gets the OAuth invite link of a bot.
627 | * Following Exceptions can be thrown from the CheckUtil:
630 | * Following Exceptions can be thrown from the HTTP request:
635 | * This method may also return {@code null} if the request wasn't successful.
641 | *
642 | * @param id
643 | * The id of the bot to get the OAuth link from.
644 | *
645 | * @return Possibly-null or possibly-empty String containing the OAuth link for the bot.
646 | *
647 | * @since 5.1.13
648 | */
649 | @Nullable
650 | public String getOAuthInvite(@Nonnull String id){
651 | CheckUtil.notEmpty(id, "id");
652 |
653 | JSONObject json = getBotInfo(id);
654 | if(json == null)
655 | return null;
656 |
657 | return json.getString("invite");
658 | }
659 |
660 | /**
661 | * Gets an ArrayList with the owner ids of the bot.
662 | * Following Exceptions can be thrown from the HTTP request:
665 | * This method may also return {@code null} if the request wasn't successful.
671 | *
672 | * @param id
673 | * The id of the bot to get the Owners from.
674 | *
675 | * @return Possibly-empty ArrayList containing the owners of the bot.
676 | */
677 | @Nullable
678 | public List Following Exceptions can be thrown from the CheckUtil:
687 | * Following Exceptions can be thrown from the HTTP request:
692 | * This method may also return {@code null} if the request wasn't successful.
698 | *
699 | * @param id
700 | * The id of the bot to get the Owners from.
701 | *
702 | * @return Possibly-empty ArrayList containing the owners of the bot.
703 | */
704 | @Nullable
705 | public List Following Exceptions can be thrown from the HTTP request:
724 | * This method may also return {@code null} if the request wasn't successful.
730 | *
731 | * @param id
732 | * The id of the bot to get the prefix from.
733 | *
734 | * @return Possibly-null or possibly-empty String containing the prefix of the bot.
735 | *
736 | * @since 4.2.0
737 | */
738 | @Nullable
739 | public String getPrefix(@Nonnull Long id){
740 | return getPrefix(String.valueOf(id));
741 | }
742 |
743 | /**
744 | * Gets the prefix of the bot.
745 | * Following Exceptions can be thrown from the CheckUtil:
748 | * Following Exceptions can be thrown from the HTTP request:
753 | * This method may also return {@code null} if the request wasn't successful.
759 | *
760 | * @param id
761 | * The id of the bot to get the prefix from.
762 | *
763 | * @return Possibly-null or possibly-empty String containing the prefix of the bot.
764 | *
765 | * @since v4.2.0
766 | */
767 | @Nullable
768 | public String getPrefix(@Nonnull String id){
769 | CheckUtil.notEmpty(id, "id");
770 |
771 | JSONObject json = getBotInfo(id);
772 | if(json == null)
773 | return null;
774 |
775 | return json.getString("prefix");
776 | }
777 |
778 | /**
779 | * Gets the server count of the bot.
780 | * Following Exceptions can be thrown from the HTTP request:
783 | * This method may also return {@code null} if the request wasn't successful.
789 | *
790 | * @param id
791 | * The id of the bot to get the server count from.
792 | *
793 | * @return Possibly-null Integer containing the server count for the bot.
794 | */
795 | @Nullable
796 | public Integer getServerCount(@Nonnull Long id){
797 | return getServerCount(String.valueOf(id));
798 | }
799 |
800 | /**
801 | * Gets the server count of the bot.
802 | * Following Exceptions can be thrown from the CheckUtil:
805 | * Following Exceptions can be thrown from the HTTP request:
810 | * This method may also return {@code null} if the request wasn't successful.
816 | *
817 | * @param id
818 | * The id of the bot to get the server count from.
819 | *
820 | * @return Possibly-null Integer containing the server count for the bot.
821 | */
822 | @Nullable
823 | public Integer getServerCount(@Nonnull String id){
824 | CheckUtil.notEmpty(id, "id");
825 |
826 | JSONObject json = getBotInfo(id);
827 | if(json == null)
828 | return null;
829 |
830 | return json.getInt("server_count");
831 | }
832 |
833 | /**
834 | * Gets the support link (i.e. Discord invite) from the bot.
835 | * Following Exceptions can be thrown from the HTTP request:
838 | * This method may also return {@code null} if the request wasn't successful.
844 | *
845 | * @param id
846 | * The id of the bot to get the support link from.
847 | *
848 | * @return Possibly-null or possibly-empty String containing the support link.
849 | */
850 | @Nullable
851 | public String getSupportLink(@Nonnull Long id){
852 | return getSupportLink(String.valueOf(id));
853 | }
854 |
855 | /**
856 | * Gets the support link (i.e. Discord invite) from the bot.
857 | * Following Exceptions can be thrown from the CheckUtil:
860 | * Following Exceptions can be thrown from the HTTP request:
865 | * This method may also return {@code null} if the request wasn't successful.
871 | *
872 | * @param id
873 | * The id of the bot to get the support link from.
874 | *
875 | * @return Possibly-null or possibly-empty String containing the support link.
876 | */
877 | @Nullable
878 | public String getSupportLink(@Nonnull String id){
879 | CheckUtil.notEmpty(id, "id");
880 |
881 | JSONObject json = getBotInfo(id);
882 | if(json == null)
883 | return null;
884 |
885 | return json.getString("support");
886 | }
887 |
888 | /**
889 | * Gets the website of the bot.
890 | * Following Exceptions can be thrown from the HTTP request:
893 | * This method may also return {@code null} if the request wasn't successful.
899 | *
900 | * @param id
901 | * The id of the bot to get the website from.
902 | *
903 | * @return Possibly-null or possibly-empty String containing the bot's website.
904 | *
905 | * @since v4.2.0
906 | */
907 | @Nullable
908 | public String getWebsite(@Nonnull Long id){
909 | return getWebsite(String.valueOf(id));
910 | }
911 |
912 | /**
913 | * Gets the website of the bot.
914 | * Following Exceptions can be thrown from the CheckUtil:
917 | * Following Exceptions can be thrown from the HTTP request:
922 | * This method may also return {@code null} if the request wasn't successful.
928 | *
929 | * @param id
930 | * The id of the bot to get the website from.
931 | *
932 | * @return Possibly-null or possibly-empty String containing the bot's website.
933 | *
934 | * @since v4.2.0
935 | */
936 | @Nullable
937 | public String getWebsite(@Nonnull String id){
938 | CheckUtil.notEmpty(id, "id");
939 |
940 | JSONObject json = getBotInfo(id);
941 | if(json == null)
942 | return null;
943 |
944 | return json.getString("website");
945 | }
946 | }
947 |
--------------------------------------------------------------------------------
/request/src/main/java/org/botblock/javabotblockapi/requests/PostAction.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 - 2020 Andre601
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
6 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
7 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8 | *
9 | * The above copyright notice and this permission notice shall be included in all copies or substantial
10 | * portions of the Software.
11 | *
12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
14 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
15 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
16 | * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17 | */
18 |
19 | package org.botblock.javabotblockapi.requests;
20 |
21 | import org.botblock.javabotblockapi.core.BotBlockAPI;
22 | import org.botblock.javabotblockapi.core.Info;
23 | import org.botblock.javabotblockapi.core.exceptions.RateLimitedException;
24 | import org.botblock.javabotblockapi.core.CheckUtil;
25 | import org.botblock.javabotblockapi.requests.handler.RequestHandler;
26 | import org.json.JSONObject;
27 | import org.slf4j.Logger;
28 | import org.slf4j.LoggerFactory;
29 |
30 | import javax.annotation.Nonnull;
31 | import javax.annotation.Nullable;
32 | import java.io.IOException;
33 | import java.util.concurrent.ScheduledExecutorService;
34 | import java.util.concurrent.TimeUnit;
35 |
36 | /**
37 | * Class used to perform POST requests towards the /api/count
38 | * endpoint of BotBlock.
39 | *
40 | * The class offers options to post either {@link #postGuilds(Long, int, BotBlockAPI) manually} or
41 | * {@link #enableAutoPost(Long, int, BotBlockAPI) automatically}.
42 | */
43 | public class PostAction{
44 |
45 | private final Logger LOG = LoggerFactory.getLogger("JavaBotBlockAPI - PostAction");
46 |
47 | private final RequestHandler requestHandler;
48 | private final ScheduledExecutorService scheduler;
49 |
50 | /**
51 | * Constructor to get an instance of PostAction.
52 | *
53 | * Using this constructor will set the following default values:
54 | * Following Exceptions can be thrown from the CheckUtil:
59 | * Note that you can provide {@code {id}} inside the userAgent to get it replaced with the provided id.
78 | *
79 | * Following Exceptions can be thrown from the CheckUtil:
80 | * Note that using this method will NOT make the scheduler wait for previously scheduled tasks to complete.
103 | * Passing null as argument will just perform a {@link java.util.concurrent.ScheduledExecutorService#shutdown() ScheduledExecutorService.shutdown()}
118 | * similar to what the disableAutoPost() method does.
119 | *
120 | * If you want to use a different delay than what you've set in the BotBlockAPI instance, can you use
121 | * {@link #disableAutoPost(long, TimeUnit) disableAutoPost(long, TimeUnit)} instead.
122 | *
123 | * This method may throw a {@link java.lang.InterruptedException InterruptedException} in the terminal.
124 | *
125 | * @param botBlockAPI
126 | * The {@link org.botblock.javabotblockapi.core.BotBlockAPI BotBlockAPI instance} or null to just perform a shutdown.
127 | *
128 | * @since 6.0.0
129 | */
130 | public void disableAutoPost(@Nullable BotBlockAPI botBlockAPI){
131 | if(botBlockAPI != null){
132 | disableAutoPost(botBlockAPI.getUpdateDelay(), TimeUnit.MINUTES);
133 | return;
134 | }
135 |
136 | scheduler.shutdown();
137 | }
138 |
139 | /**
140 | * Disables the automatic posting of Stats.
141 | * This method may throw a {@link java.lang.InterruptedException InterruptedException} in the terminal.
145 | *
146 | * Following Exceptions can be thrown from the CheckUtil:
147 | * If the post can't be performed - either by getting a {@link org.botblock.javabotblockapi.core.exceptions.RateLimitedException RatelimitedException}
175 | * or by getting an {@link java.io.IOException IOException} - will the exception be catched and the stacktrace printed.
176 | * The scheduler will wait an initial delay of 1 minute and then performs a task every n minutes, where n is the
179 | * time set in {@link org.botblock.javabotblockapi.core.BotBlockAPI.Builder#setUpdateDelay(Integer) BotBlockAPI.Builder.setUpdateDelay(Integer)}
180 | * (default is 30 minutes).
181 | *
182 | * @param botId
183 | * The ID of the bot as Long.
184 | * @param guilds
185 | * The guild count.
186 | * @param botBlockAPI
187 | * The {@link org.botblock.javabotblockapi.core.BotBlockAPI BotBlockAPI instance} to use.
188 | */
189 | public void enableAutoPost(@Nonnull Long botId, int guilds, @Nonnull BotBlockAPI botBlockAPI){
190 | scheduler.scheduleAtFixedRate(() -> {
191 | try{
192 | postGuilds(botId, guilds, botBlockAPI);
193 | }catch(IOException | RateLimitedException ex){
194 | LOG.warn("Got an exception while performing a auto-post task!", ex);
195 | }
196 | }, botBlockAPI.getUpdateDelay(), botBlockAPI.getUpdateDelay(), TimeUnit.MINUTES);
197 | }
198 |
199 | /**
200 | * Starts a {@link java.util.concurrent.ScheduledExecutorService#scheduleAtFixedRate(Runnable, long, long, TimeUnit) scheduleAtFixedRate}
201 | * task, which will post the provided guild count to the provided bot lists every n minutes.
202 | *
203 | * If the post can't be performed - either by getting a {@link org.botblock.javabotblockapi.core.exceptions.RateLimitedException RatelimitedException}
204 | * or by getting an {@link java.io.IOException IOException} - will the exception be catched and the stacktrace printed.
205 | * The scheduler will wait an initial delay of 1 minute and then performs a task every n minutes, where n is the
208 | * time set in {@link org.botblock.javabotblockapi.core.BotBlockAPI.Builder#setUpdateDelay(Integer) BotBlockAPI.Builder.setUpdateDelay(Integer)}
209 | * (default is 30 minutes).
210 | *
211 | * @param botId
212 | * The ID of the bot as String.
213 | * @param guilds
214 | * The guild count.
215 | * @param botBlockAPI
216 | * The {@link org.botblock.javabotblockapi.core.BotBlockAPI BotBlockAPI instance} to use.
217 | */
218 | public void enableAutoPost(@Nonnull String botId, int guilds, @Nonnull BotBlockAPI botBlockAPI){
219 | scheduler.scheduleAtFixedRate(() -> {
220 | try{
221 | postGuilds(botId, guilds, botBlockAPI);
222 | }catch(IOException | RateLimitedException ex){
223 | LOG.warn("Got an exception while performing a auto-post task!", ex);
224 | }
225 | }, botBlockAPI.getUpdateDelay(), botBlockAPI.getUpdateDelay(), TimeUnit.MINUTES);
226 | }
227 |
228 | /**
229 | * Posts the guild count with the provided bot id.
230 | *
231 | * @param botId
232 | * The ID of the bot.
233 | * @param guilds
234 | * The guild count.
235 | * @param botBlockAPI
236 | * The {@link org.botblock.javabotblockapi.core.BotBlockAPI BotBlockAPI instance}.
237 | *
238 | * @throws java.io.IOException
239 | * When the post request couldn't be performed.
240 | * @throws org.botblock.javabotblockapi.core.exceptions.RateLimitedException
241 | * When we exceed the rate-limit of the BotBlock API.
242 | */
243 | public void postGuilds(@Nonnull Long botId, int guilds, @Nonnull BotBlockAPI botBlockAPI) throws IOException, RateLimitedException{
244 | postGuilds(Long.toString(botId), guilds, botBlockAPI);
245 | }
246 |
247 | /**
248 | * Posts the guild count with the provided bot id.
249 | *
250 | * Following Exceptions can be thrown from the CheckUtil:
251 | * If you still want to do it manually, or can't use one of the other option, head over to the
68 | * GitHub releases page or to
69 | * the Bintray release page
70 | * and download the jar files from there.
71 | *
72 | * Note that you will not receive any support when using this method.
73 | */
74 | package org.botblock.javabotblockapi.requests;
--------------------------------------------------------------------------------
/settings.gradle:
--------------------------------------------------------------------------------
1 | rootProject.name = 'JavaBotBlockAPI'
2 |
3 | include 'core'
4 | include 'jda'
5 | include 'request'
6 | include 'javacord'
7 |
8 |
--------------------------------------------------------------------------------
Entries with the same key will be overwritten.
70 | *
71 | * @param site
72 | * The {@link org.botblock.javabotblockapi.core.Site Site} to get the name from.
73 | * @param token
74 | * The API token from the corresponding bot list. May not be null or empty.
75 | *
You may receive the API token from the bot list.
76 | *
77 | *
79 | *
82 | *
83 | * @return The Builder after the site and token were set. Useful for chaining.
84 | *
85 | * @since 2.1.0
86 | */
87 | public Builder addAuthToken(@Nonnull Site site, @Nonnull String token){
88 | CheckUtil.notEmpty(token, "Token");
89 | CheckUtil.condition(!site.supportsPost(), site.getName() + " does not support POST requests!");
90 |
91 | // Discordlist.space requires the token to start with "Bot "
92 | if(site.getName().equals("discordlist.space") && !token.startsWith("Bot "))
93 | token = "Bot " + token;
94 |
95 | tokens.put(site.getName(), token);
96 | return this;
97 | }
98 |
99 | /**
100 | * Adds the provided Site name and token to the Map.
101 | *
Entries with the same key will be overwritten.
102 | *
103 | * @param site
104 | * The name of the site. May not be null or empty.
105 | *
A list of supported sites can be found here.
106 | * @param token
107 | * The API token from the corresponding bot list. May not be null or empty.
108 | *
You may receive the API token from the bot list.
109 | *
110 | *
112 | *
114 | *
115 | * @return The Builder after the site and token were set. Useful for chaining.
116 | */
117 | public Builder addAuthToken(@Nonnull String site, @Nonnull String token){
118 | CheckUtil.notEmpty(site, "Site");
119 | CheckUtil.notEmpty(token, "Token");
120 |
121 | // Discordlist.space requires the token to start with "Bot "
122 | if(site.equals("discordlist.space") && !token.startsWith("Bot "))
123 | token = "Bot " + token;
124 |
125 | tokens.put(site, token);
126 | return this;
127 | }
128 |
129 | /**
130 | * Sets the provided Map as the new Map.
131 | *
This will overwrite every previously set entry!
132 | *
133 | * @param tokens
134 | * The Map that should be used. May not be null.
135 | *
136 | *
138 | *
140 | *
141 | * @return The Builder after the Map was set. Useful for chaining.
142 | */
143 | public Builder setAuthTokens(@Nonnull Map
You don't need to set this when not using the auto-post option. Default is 30.
153 | *
154 | * @param updateDelay
155 | * The update interval in minutes that should be used. This can't be less than 2.
156 | *
157 | *
159 | *
161 | *
162 | * @return The Builder after the updateInterval was set. Useful for chaining.
163 | */
164 | public Builder setUpdateDelay(@Nonnull Integer updateDelay){
165 | CheckUtil.condition(updateDelay < 2, "UpdateDelay may not be less than 2.");
166 |
167 | this.updateDelay = updateDelay;
168 | return this;
169 | }
170 |
171 | /**
172 | * Builds the instance of {@link org.botblock.javabotblockapi.core.BotBlockAPI BotBlockAPI}.
173 | *
174 | *
176 | *
178 | *
179 | * @return The built, usable {@link org.botblock.javabotblockapi.core.BotBlockAPI BotBlockAPI}.
180 | */
181 | public BotBlockAPI build(){
182 | CheckUtil.notEmpty(tokens, "Tokens");
183 |
184 | return new BotBlockAPI(tokens, updateDelay);
185 | }
186 | }
187 | }
188 |
--------------------------------------------------------------------------------
/core/src/main/java/org/botblock/javabotblockapi/core/CheckUtil.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 - 2020 Andre601
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
6 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
7 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8 | *
9 | * The above copyright notice and this permission notice shall be included in all copies or substantial
10 | * portions of the Software.
11 | *
12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
14 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
15 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
16 | * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17 | */
18 |
19 | package org.botblock.javabotblockapi.core;
20 |
21 | import java.util.Map;
22 |
23 | public class CheckUtil{
24 |
25 | public static void notEmpty(String value, String name){
26 | if(value.isEmpty())
27 | throw new NullPointerException(name + " may not be empty.");
28 | }
29 |
30 | public static void notEmpty(Map, ?> value, String name){
31 | if(value.isEmpty())
32 | throw new NullPointerException(name + " may not be empty.");
33 | }
34 |
35 | public static void condition(boolean expression, String message){
36 | if(expression)
37 | throw new IllegalStateException(message);
38 | }
39 | }
40 |
--------------------------------------------------------------------------------
/core/src/main/java/org/botblock/javabotblockapi/core/Info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 - 2021 Andre601
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
6 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
7 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8 | *
9 | * The above copyright notice and this permission notice shall be included in all copies or substantial
10 | * portions of the Software.
11 | *
12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
14 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
15 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
16 | * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17 | */
18 |
19 | package org.botblock.javabotblockapi.core;
20 |
21 | /**
22 | * Class containing general information about the project.
23 | *
24 | * Supported HTTP Methods
36 | * The Javadoc comment of each instance lists what HTTP method is supported.
37 | *
If a List supports GET can you use all methods from the GetListAction and GetBotAction classes of the Request module
38 | * while Lists supporting POST also can be utilized within the {@link org.botblock.javabotblockapi.core.BotBlockAPI BotBlockAPI}
39 | * to posts Bot information to that list.
40 | *
41 | *
Instances marked as Deprecated won't support either method type. If a replacement is mentioned using the
44 | * {@link org.botblock.javabotblockapi.core.annotations.DeprecatedSince DeprecatedSince's} replacement value should it
45 | * be used in favour of the deprecated Instance.
46 | *
47 | * @since 6.3.0
48 | */
49 | public class Site{
50 |
51 | /**
52 | * bladebotlist.xyz
53 | *
54 | *
56 | *
59 | *
60 | * @since 6.3.0
61 | */
62 | public static final Site BLADEBOTLIST_XYZ = new Site("bladebotlist.xyz", HttpMethod.GET, HttpMethod.POST);
63 |
64 | /**
65 | * blist.xyz
66 | *
67 | *
69 | *
72 | */
73 | public static final Site BLIST_XYZ = new Site("blist.xyz", HttpMethod.GET, HttpMethod.POST);
74 |
75 | /**
76 | * boatspace.xyz
77 | *
78 | *
80 | *
83 | */
84 | public static final Site BOATSPACE_XYZ = new Site("boatspace.xyz", HttpMethod.GET, HttpMethod.POST);
85 |
86 | /**
87 | * botlist.me
88 | *
89 | *
91 | *
94 | *
95 | * @since 6.7.2
96 | */
97 | public static final Site BOTLIST_ME = new Site("botlist.me", HttpMethod.GET, HttpMethod.POST);
98 |
99 | /**
100 | * bots.discordlabs.org
101 | *
102 | *
104 | *
107 | */
108 | public static final Site BOTS_DISCORDLABS_ORG = new Site("discordlabs.org", HttpMethod.GET, HttpMethod.POST);
109 |
110 | /**
111 | * botsfordiscord.com
112 | *
113 | *
115 | *
118 | *
119 | * @deprecated List was aquired by {@link #DISCORDS_COM discords.com}
120 | */
121 | @Deprecated
122 | @DeprecatedSince(major = 6, minor = 7, patch = 4, replacements = "DISCORDS_COM")
123 | @PlannedRemoval(major = 6, minor = 7, patch = 6)
124 | public static final Site BOTSFORDISCORD_COM = new Site("botsfordiscord.com");
125 |
126 | /**
127 | * bots.ondiscord.xyz
128 | *
129 | *
131 | *
133 | */
134 | public static final Site BOTS_ONDISCORD_XYZ = new Site("bots.ondiscord.xyz", HttpMethod.POST);
135 |
136 | /**
137 | * dblista.pl
138 | *
139 | *
141 | *
143 | */
144 | public static final Site DBLISTA_PL = new Site("dblista.pl", HttpMethod.GET);
145 |
146 | /**
147 | * discord.boats
148 | *
149 | *
151 | *
154 | */
155 | public static final Site DISCORD_BOATS = new Site("discord.boats", HttpMethod.GET, HttpMethod.POST);
156 |
157 | /**
158 | * discordbotlist.com
159 | *
160 | *
162 | *
165 | */
166 | public static final Site DISCORDBOTLIST_COM = new Site("discordbotlist.com", HttpMethod.GET, HttpMethod.POST);
167 |
168 | /**
169 | * discordbots.co
170 | *
171 | *
173 | *
176 | *
177 | * @since 5.2.3
178 | */
179 | public static final Site DISCORDBOTS_CO = new Site("discordbots.co", HttpMethod.GET, HttpMethod.POST);
180 |
181 | /**
182 | * discord.bots.gg
183 | *
184 | *
186 | *
189 | */
190 | public static final Site DISCORD_BOTS_GG = new Site("discord.bots.gg", HttpMethod.GET, HttpMethod.POST);
191 |
192 | /**
193 | * discordextremelist.xyz
194 | *
195 | *
197 | *
200 | */
201 | public static final Site DISCORDEXTREMELIST_XYZ = new Site("discordextremelist.xyz", HttpMethod.GET, HttpMethod.POST);
202 |
203 | /**
204 | * discordlistology.com
205 | *
206 | *
208 | *
211 | */
212 | public static final Site DISCORDLISTOLOGY_COM = new Site("discordlistology.com", HttpMethod.GET, HttpMethod.POST);
213 |
214 | /**
215 | * discordlist.space (Formerly botlist.space)
216 | *
217 | *
219 | *
222 | */
223 | public static final Site DISCORDLIST_SPACE = new Site("discordlist.space", HttpMethod.GET, HttpMethod.POST);
224 |
225 | /**
226 | * discords.com formerly botsfordiscord.com
227 | *
228 | *
230 | *
233 | */
234 | public static final Site DISCORDS_COM = new Site("discords.com", HttpMethod.GET, HttpMethod.POST);
235 |
236 | /**
237 | * discordservices.net
238 | *
239 | *
241 | *
243 | */
244 | public static final Site DISCORDSERVICES_NET = new Site("discordservices.net", HttpMethod.POST);
245 |
246 | /**
247 | * disforge.com
248 | *
249 | *
251 | *
253 | */
254 | public static final Site DISFORGE_COM = new Site("disforge.com", HttpMethod.POST);
255 |
256 | /**
257 | * fateslist.xyz
258 | *
259 | *
261 | *
264 | */
265 | public static final Site FATESLIST_XYZ = new Site("fateslist.xyz", HttpMethod.GET, HttpMethod.POST);
266 |
267 | /**
268 | * infinitybotlist.xyz
269 | *
270 | *
272 | *
275 | *
276 | * @since 6.6.2
277 | */
278 | public static final Site INFINITYBOTLIST_XYZ = new Site("infinitybotlist.xyz", HttpMethod.GET, HttpMethod.POST);
279 |
280 | /**
281 | * listcord.gg
282 | *
283 | *
285 | *
288 | */
289 | public static final Site LISTCORD_GG = new Site("listcord.gg", HttpMethod.GET, HttpMethod.POST);
290 |
291 | /**
292 | * motiondevelopment.top
293 | *
294 | *
296 | *
299 | *
300 | * @since 6.7.2
301 | */
302 | public static final Site MOTIONDEVELOPMENT_TOP = new Site("motiondevelopment.top", HttpMethod.GET, HttpMethod.POST);
303 |
304 | /**
305 | * paradisebots.net
306 | *
307 | *
309 | *
312 | *
313 | * @since 6.4.2
314 | */
315 | public static final Site PARADISEBOTS_NET = new Site("paradisebots.net", HttpMethod.GET, HttpMethod.POST);
316 |
317 | /**
318 | * radarbotdirectory.xyz
319 | *
320 | *
322 | *
325 | *
326 | * @since 6.7.2
327 | */
328 | public static final Site RADARBOTDIRECTORY_XYZ = new Site("radarbotdirectory.xyz", HttpMethod.GET, HttpMethod.POST);
329 |
330 | /**
331 | * space-bot-list.xyz
332 | *
333 | *
335 | *
338 | */
339 | public static final Site SPACE_BOT_LIST_XYZ = new Site("space-bot-list.xyz", HttpMethod.GET, HttpMethod.POST);
340 |
341 | /**
342 | * stellarbotlist.com
343 | *
344 | *
346 | *
348 | *
349 | * @since 6.7.2
350 | */
351 | public static final Site STELLARBOTLIST_COM = new Site("stellarbotlist.com", HttpMethod.GET);
352 |
353 | /**
354 | * topcord.xyz
355 | *
356 | *
358 | *
361 | */
362 | public static final Site TOPCORD_XYZ = new Site("topcord.xyz", HttpMethod.GET, HttpMethod.POST);
363 |
364 | /**
365 | * vcodes.xyz
366 | *
367 | *
369 | *
372 | *
373 | * @since 6.7.2
374 | */
375 | public static final Site VCODES_XYZ = new Site("vcodes.xyz", HttpMethod.GET, HttpMethod.POST);
376 |
377 | /**
378 | * voidbots.net
379 | *
380 | *
382 | *
385 | */
386 | public static final Site VOIDBOTS_NET = new Site("voidbots.net", HttpMethod.GET, HttpMethod.POST);
387 |
388 | /**
389 | * wonderbotlist.com
390 | *
391 | *
393 | *
396 | */
397 | public static final Site WONDERBOTLIST_COM = new Site("wonderbotlist.com", HttpMethod.GET, HttpMethod.POST);
398 |
399 | /**
400 | * yabl.xyz
401 | *
402 | *
404 | *
407 | */
408 | public static final Site YABL_XYZ = new Site("yabl.xyz", HttpMethod.GET, HttpMethod.POST);
409 |
410 | private final String name;
411 | private final List
The name usually represents the domain of the bot list without the https in front of it.
426 | *
427 | * @return The name of the site used for the BotBlock API.
428 | */
429 | public String getName(){
430 | return name;
431 | }
432 |
433 | /**
434 | * Whether the site supports GET requests towards itself or not.
435 | *
436 | * @return True if the site supports GET request, otherwise false.
437 | */
438 | public boolean supportsGet(){
439 | return !methods.isEmpty() && methods.contains(HttpMethod.GET);
440 | }
441 |
442 | /**
443 | * Whether the site supports POST requests towards itself or not.
444 | *
445 | * @return True if the site supports POST request, otherwise false.
446 | */
447 | public boolean supportsPost(){
448 | return !methods.isEmpty() && methods.contains(HttpMethod.POST);
449 | }
450 |
451 | /**
452 | * Nested enum for the Http-methods supported by the bot lists.
453 | *
454 | *
This is always paired with the {@link java.lang.Deprecated @Deprecated} annotation.
26 | *
27 | *
Anything annotated with this should be avoided as it may be removed in a future release.
29 | *
30 | *
This is paired with the {@link java.lang.Deprecated Deprecated} and
26 | * {@link org.botblock.javabotblockapi.core.annotations.DeprecatedSince DeprecatedSince} annotations.
27 | *
28 | *
For example will {@code @PlannedRemoval(major = 6, minor = 5, patch = 0)} indicate an Object for removal on version
31 | * 6.5.0.
32 | *
33 | * @since 5.2.2
34 | */
35 | @Documented
36 | @Retention(RetentionPolicy.RUNTIME)
37 | @Target({ElementType.METHOD, ElementType.FIELD, ElementType.TYPE, ElementType.CONSTRUCTOR})
38 | public @interface PlannedRemoval{
39 |
40 | /**
41 | * The major version for when the annotated Object will be removed.
42 | *
43 | * @return The major version for when this Object will be removed.
44 | */
45 | int major();
46 |
47 | /**
48 | * The minor version for when the annotated Object will be removed.
49 | *
50 | * @return The minor version for when this Object will be removed.
51 | */
52 | int minor();
53 |
54 | /**
55 | * The patch version for when the annotated Object will be removed.
56 | *
57 | * @return The path version for when this Object will be removed.
58 | */
59 | int patch();
60 | }
61 |
--------------------------------------------------------------------------------
/core/src/main/java/org/botblock/javabotblockapi/core/annotations/package-info.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 - 2020 Andre601
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
6 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
7 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8 | *
9 | * The above copyright notice and this permission notice shall be included in all copies or substantial
10 | * portions of the Software.
11 | *
12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
14 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
15 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
16 | * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17 | */
18 |
19 | /**
20 | * The different annotations used to mark various Objects with it.
21 | */
22 | package org.botblock.javabotblockapi.core.annotations;
--------------------------------------------------------------------------------
/core/src/main/java/org/botblock/javabotblockapi/core/exceptions/RateLimitedException.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 - 2020 Andre601
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
6 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
7 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8 | *
9 | * The above copyright notice and this permission notice shall be included in all copies or substantial
10 | * portions of the Software.
11 | *
12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
14 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
15 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
16 | * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17 | */
18 | package org.botblock.javabotblockapi.core.exceptions;
19 |
20 | import org.json.JSONObject;
21 |
22 | import javax.annotation.Nullable;
23 |
24 | /**
25 | * Indicates that the Wrapper got rate limited by the BotBlock API.
26 | *
Use {@link #getDelay() getDelay()} to find out how long you have to wait until you can perform another request
27 | * towards {@link #getRoute() the targeted route}.
28 | *
29 | *
Any automated POSTing method of this Wrapper should not get rate limited due to keeping a minimal delay between each
32 | * request that is more than enough.
33 | */
34 | public class RateLimitedException extends RuntimeException{
35 | private final int delay;
36 | private final String botId;
37 | private final String ip;
38 | private final String route;
39 |
40 | public RateLimitedException(JSONObject json){
41 | this(json.optInt("retry_after", -1), json.optString("ratelimit_bot_id", null),
42 | json.optString("ratelimit_ip", null), json.optString("ratelimit_route", null));
43 | }
44 |
45 | private RateLimitedException(int delay, String botId, String ip, String route){
46 | super("Got rate limited on route " + route + " with bot id " + botId + " (ip: " + ip + "). Retry after: " + delay);
47 |
48 | this.delay = delay;
49 | this.botId = botId;
50 | this.ip = ip;
51 | this.route = route;
52 | }
53 |
54 | /**
55 | * Returns the delay - in milliseconds - you have to wait to perform a request again.
56 | *
When no delay could be extracted from the received JSON (The JSON was malformed) then {@code -1} will be returned.
57 | *
58 | * @return The delay you have to wait in milliseconds or {@code -1}.
59 | */
60 | public int getDelay(){
61 | return delay;
62 | }
63 |
64 | /**
65 | * Returns the bot id that was rate limited.
66 | *
When no botId could be extracted from the received JSON (The JSON was malformed) then {@code null} will be returned.
67 | *
68 | * @return Possibly-null String representing the id of the rate limited bot.
69 | */
70 | @Nullable
71 | public String getBotId(){
72 | return botId;
73 | }
74 |
75 | /**
76 | * Returns the ip that was rate limited.
77 | *
When no ip could be extracted from the received JSON (The JSON was malformed) then {@code null} will be returned.
78 | *
79 | * @return Possibly-null String representing the ip of the rate limited bot.
80 | */
81 | public String getIp(){
82 | return ip;
83 | }
84 |
85 | /**
86 | * Returns the route on which the bot was rate limited.
87 | *
When no route could be extracted from the received JSON (The JSON was malformed) then {@code null} will be returned.
88 | *
89 | * @return Possibly-null String representing the route on which the bot got rate limited.
90 | */
91 | public String getRoute(){
92 | return route;
93 | }
94 |
95 | /**
96 | * Returns this class formatted to a String.
97 | *
98 | * @return {@code RatelimitedException{delay=
When using either of the other modules is this one here required to be installed too.
22 | *
23 | * Installation
24 | * Please replace {@code API_VERSION} with the latest release on Bintray.
25 | *
26 | * Gradle (recommended)
27 | *
28 | *
37 | *
38 | *
29 | * repositories{
30 | * maven{ url = 'https://repo.codemc.io/repository/maven-public' }
31 | * }
32 | *
33 | * dependencies{
34 | * compile group: 'org.botblock', name: 'javabotblockapi-core', version: API_VERSION
35 | * }
36 | *
Maven
39 | *
40 | *
57 | *
58 | * {@literal
41 | *
Manual
59 | * We do not recommend using jar files directly and instead use one of the above dependency management systems.
60 | *
61 | *
This will set the UserAgent used for POST request to {@code
This essentially just performs a {@link java.util.concurrent.ScheduledExecutorService#shutdown() ScheduledExecutorService.shutdown()}
79 | * by calling the {@link #disableAutoPost(BotBlockAPI) disableAutoPost(null)} method.
80 | *
81 | *
If you want to wait for the tasks to complete use {@link #disableAutoPost(BotBlockAPI) disableAutoPost(BotBlockAPI)} or
83 | * {@link #disableAutoPost(long, TimeUnit) disableAutoPost(long, TimeUnit)} instead.
84 | *
85 | * @see java.util.concurrent.ScheduledExecutorService#shutdown()
86 | */
87 | public void disableAutoPost(){
88 | disableAutoPost(null);
89 | }
90 |
91 | /**
92 | * Disables the automatic posting of Stats.
93 | *
Unlike {@link #disableAutoPost() disableAutoPost()} can you make the scheduler wait for all scheduled tasks to
94 | * finish, or to time out after n minutes by providing the {@link org.botblock.javabotblockapi.core.BotBlockAPI BotBlock instance}.
95 | *
96 | *
Unlike {@link #disableAutoPost() disableAutoPost()} can you make the scheduler wait for all scheduled tasks to
122 | * finish, or to time out after a specified time frame.
123 | *
124 | *
128 | *
130 | *
131 | * @param time
132 | * The amount of time to wait for scheduled executions to finish before the Scheduler would time out.
133 | * @param timeUnit
134 | * The {@link java.util.concurrent.TimeUnit TimeUnit} to use.
135 | *
136 | * @see java.util.concurrent.ScheduledExecutorService#awaitTermination(long, TimeUnit)
137 | */
138 | public void disableAutoPost(long time, @Nonnull TimeUnit timeUnit){
139 | CheckUtil.condition(time <= 0, "time may not be less or equal to 0!");
140 |
141 | try{
142 | scheduler.shutdown();
143 | if(!scheduler.awaitTermination(time, timeUnit))
144 | LOG.warn("Scheduler couldn't properly wait for termination.");
145 | }catch(InterruptedException ex){
146 | LOG.warn("Got interrupted while shutting down the Scheduler!", ex);
147 | }
148 | }
149 |
150 | /**
151 | * Starts a {@link java.util.concurrent.ScheduledExecutorService#scheduleAtFixedRate(Runnable, long, long, TimeUnit) scheduleAtFixedRate}
152 | * task, which will post the statistics of the provided {@link org.javacord.api.DiscordApi DiscordApi instance} every n minutes.
153 | *
154 | *
163 | *
165 | *
166 | * @param discordApis
167 | * The {@link org.javacord.api.DiscordApi DiscordApi instances} to post stats from.
168 | * @param botBlockAPI
169 | * The {@link org.botblock.javabotblockapi.core.BotBlockAPI BotBlockAPI instance} to use.
170 | */
171 | public void enableAutoPost(@Nonnull BotBlockAPI botBlockAPI, @Nonnull DiscordApi... discordApis){
172 | CheckUtil.condition(discordApis.length <= 0, "At least one DiscordApi instance needs to be provided!");
173 |
174 | scheduler.scheduleAtFixedRate(() -> {
175 | try{
176 | postGuilds(botBlockAPI, discordApis);
177 | }catch(IOException | RateLimitedException ex){
178 | LOG.warn("Got an exception while performing a auto-post task!", ex);
179 | }
180 | }, 1, botBlockAPI.getUpdateDelay(), TimeUnit.MINUTES);
181 | }
182 |
183 | /**
184 | * Performs a POST request towards the BotBlock API using the information from the provided
185 | * {@link org.javacord.api.DiscordApi DiscordApi} and {@link org.botblock.javabotblockapi.core.BotBlockAPI BotBlock} instances.
186 | *
187 | *
192 | *
194 | *
195 | * @param discordApis
196 | * The {@link org.javacord.api.DiscordApi DiscordApi instances} to post stats from.
197 | * @param botBlockAPI
198 | * The {@link org.botblock.javabotblockapi.core.BotBlockAPI BotBlockAPI instance} to use.
199 | *
200 | * @throws java.io.IOException
201 | * When the POST request wasn't successful.
202 | * @throws org.botblock.javabotblockapi.core.exceptions.RateLimitedException
203 | * When we get rate limited by the BotBlock API (returns error code 429).
204 | */
205 | public void postGuilds(@Nonnull BotBlockAPI botBlockAPI, @Nonnull DiscordApi... discordApis) throws IOException, RateLimitedException{
206 | CheckUtil.condition(discordApis.length <= 0, "At least one DiscordApi instance needs to be provided!");
207 |
208 | JSONObject json = new JSONObject()
209 | .put("bot_id", discordApis[0].getYourself().getId());
210 |
211 | if(discordApis.length > 1){
212 | int guilds = Arrays.stream(discordApis).map(DiscordApi::getServers).mapToInt(Collection::size).sum();
213 | json.put("server_count", guilds)
214 | .put("shard_count", discordApis.length);
215 |
216 | List
Make sure to install both the request library and the core library for this one to work!
22 | *
23 | * Installation
24 | * Please replace {@code API_VERSION} with the latest release on Bintray.
25 | *
26 | * Gradle (recommended)
27 | *
28 | *
41 | *
42 | *
29 | * repositories{
30 | * maven{ url = 'https://repo.codemc.io/repository/maven-public' }
31 | * }
32 | *
33 | * dependencies{
34 | * // Those two are required
35 | * compile group: 'org.botblock', name: 'javabotblockapi-core', version: 'API_VERSION'
36 | * compile group: 'org.botblock', name: 'javabotblockapi-request', version: 'API_VERSION'
37 | *
38 | * compile group: 'org.botblock', name: 'javabotblockapi-javacord', version: 'API_VERSION'
39 | * }
40 | *
Maven
43 | *
44 | *
73 | *
74 | * {@literal
45 | *
Manual
75 | * We do not recommend using jar files directly and instead use one of the above dependency management systems.
76 | *
77 | *
It also allows you to choose, if you want to use a {@link net.dv8tion.jda.api.JDA JDA instance} or a
50 | * {@link net.dv8tion.jda.api.sharding.ShardManager ShardManager instance}.
51 | *
52 | *
This will set the UserAgent used for POST requests to {@code
This will set the UserAgent used for POST requests to {@code
This essentially just performs a {@link java.util.concurrent.ScheduledExecutorService#shutdown() ScheduledExecutorService.shutdown()}
94 | * by calling the {@link #disableAutoPost(BotBlockAPI) disableAutoPost(null)} method.
95 | *
96 | *
If you want to wait for the tasks to complete use {@link #disableAutoPost(BotBlockAPI) disableAutoPost(BotBlockAPI)} or
98 | * {@link #disableAutoPost(long, TimeUnit) disableAutoPost(long, TimeUnit)} instead.
99 | *
100 | * @see java.util.concurrent.ScheduledExecutorService#shutdown()
101 | */
102 | public void disableAutoPost(){
103 | disableAutoPost(null);
104 | }
105 |
106 | /**
107 | * Disables the automatic posting of Stats.
108 | *
Unlike {@link #disableAutoPost() disableAutoPost()} can you make the scheduler wait for all scheduled tasks to
109 | * finish, or to time out after n minutes by providing the {@link org.botblock.javabotblockapi.core.BotBlockAPI BotBlock instance}.
110 | *
111 | *
Unlike {@link #disableAutoPost() disableAutoPost()} can you make the scheduler wait for all scheduled tasks to
139 | * finish, or to time out after a specified time frame.
140 | *
141 | *
145 | *
147 | *
148 | * @param time
149 | * The amount of time to wait for scheduled executions to finish before the Scheduler would time out.
150 | * @param timeUnit
151 | * The {@link java.util.concurrent.TimeUnit TimeUnit} to use.
152 | *
153 | * @since 6.0.0
154 | *
155 | * @see java.util.concurrent.ScheduledExecutorService#awaitTermination(long, TimeUnit)
156 | */
157 | public void disableAutoPost(long time, @Nonnull TimeUnit timeUnit){
158 | CheckUtil.condition(time <= 0, "Time may not be less or equal to 0");
159 |
160 | try{
161 | scheduler.shutdown();
162 | if(!scheduler.awaitTermination(time, timeUnit))
163 | LOG.warn("Scheduler couldn't properly wait for termination.");
164 | }catch(InterruptedException ex){
165 | LOG.warn("Got interrupted while shutting down the Scheduler!", ex);
166 | }
167 | }
168 |
169 | /**
170 | * Starts a {@link java.util.concurrent.ScheduledExecutorService#scheduleAtFixedRate(Runnable, long, long, TimeUnit) scheduleAtFixedRate}
171 | * task, which will post the statistics of the provided {@link net.dv8tion.jda.api.JDA JDA instance} every n minutes.
172 | *
173 | *
260 | *
262 | *
263 | * @param shardManager
264 | * The {@link net.dv8tion.jda.api.sharding.ShardManager ShardManager instance} to post stats from.
265 | * @param botBlockAPI
266 | * The {@link org.botblock.javabotblockapi.core.BotBlockAPI BotBlockAPI instance} to use.
267 | *
268 | * @throws java.io.IOException
269 | * When the POST request wasn't successful.
270 | * @throws org.botblock.javabotblockapi.core.exceptions.RateLimitedException
271 | * When we get rate limited by the BotBlock API (returns error code 429).
272 | */
273 | public void postGuilds(@Nonnull ShardManager shardManager, @Nonnull BotBlockAPI botBlockAPI) throws IOException, RateLimitedException{
274 | JDA shard = shardManager.getShardById(0);
275 | CheckUtil.condition(shard == null, "Shard 0 of ShardManager was invalid (null).");
276 |
277 | JSONObject json = new JSONObject()
278 | .put("server_count", shardManager.getGuildCache().size())
279 | .put("bot_id", shard.getSelfUser().getId())
280 | .put("shard_count", shardManager.getShardCache().size());
281 |
282 | List
Make sure to install both the request library and the core library for this one to work!
23 | *
24 | * Installation
25 | * Please replace {@code API_VERSION} with the latest release on Bintray.
26 | *
27 | * Gradle (recommended)
28 | *
29 | *
42 | *
43 | *
30 | * repositories{
31 | * maven{ url = 'https://repo.codemc.io/repository/maven-public' }
32 | * }
33 | *
34 | * dependencies{
35 | * // Those two are required
36 | * compile group: 'org.botblock', name: 'javabotblockapi-core', version: 'API_VERSION'
37 | * compile group: 'org.botblock', name: 'javabotblockapi-request', version: 'API_VERSION'
38 | *
39 | * compile group: 'org.botblock', name: 'javabotblockapi-jda', version: 'API_VERSION'
40 | * }
41 | *
Maven
44 | *
45 | *
74 | *
75 | * {@literal
46 | *
Manual
76 | * We do not recommend using jar files directly and instead use one of the above dependency management systems.
77 | *
78 | *
53 | *
56 | *
57 | *
59 | *
61 | *
62 | * @param id
63 | * The id of the bot. This is required for the internal User-Agent.
64 | */
65 | public GetBotAction(@Nonnull String id){
66 | this(false, id);
67 | }
68 |
69 | /**
70 | * Constructor to get an instance of GetBotAction.
71 | *
This constructor allows you to disable the internal caching, by providing {@code true} as the first argument.
72 | *
73 | *
75 | *
77 | *
78 | *
80 | *
82 | *
83 | * @param disableCache
84 | * If the cache should be disabled.
85 | *
{@code true} means the cache is disabled.
86 | * @param id
87 | * The id of the bot. This is required for the internal User-Agent.
88 | */
89 | public GetBotAction(boolean disableCache, @Nonnull String id){
90 | this(disableCache, String.format(
91 | "JavaBotBlockAPI-0000/%s (Unknown; +https://jbba.dev) DBots/{id}",
92 | Info.VERSION
93 | ), id);
94 | }
95 |
96 | /**
97 | * Constructor to get the instance of GetBotAction.
98 | *
This constructor allows you to disable the internal caching, by providing {@code true} as the first argument
99 | * and also set a own User-Agent for the requests by providing any String as the second argument.
100 | *
101 | *
105 | *
107 | *
108 | * @param disableCache
109 | * If the cache should be disabled.
110 | *
{@code true} means the cache is disabled.
111 | * @param userAgent
112 | * The Name that should be used as User-Agent.
113 | * @param id
114 | * The id of the bot. This is required for the internal User-Agent.
115 | */
116 | public GetBotAction(boolean disableCache, @Nonnull String userAgent, @Nonnull String id){
117 | CheckUtil.notEmpty(userAgent, "UserAgent");
118 | CheckUtil.notEmpty(id, "ID");
119 |
120 | this.disableCache = disableCache;
121 | this.REQUEST_HANDLER = new RequestHandler(userAgent.replace("{id}", id));
122 | }
123 |
124 | /**
125 | * Gets the full information of a bot.
126 | *
127 | * An example of how the returned JSON may look like can be found here:
128 | * https://gist.github.com/Andre601/b18b1c4e88e9a405806ce7b6c29a0136
129 | *
130 | *
132 | *
135 | *
136 | * @param id
137 | * The id of the bot to get the information from.
138 | *
139 | * @return Possibly-null {@link org.json.JSONObject JSONObject} containing the full information of the bot.
140 | */
141 | @Nullable
142 | public JSONObject getBotInfo(long id){
143 | return getBotInfo(String.valueOf(id));
144 | }
145 |
146 | /**
147 | * Gets the full information of a bot.
148 | *
149 | * An example of how the returned JSON may look like can be found here:
150 | * https://gist.github.com/Andre601/b18b1c4e88e9a405806ce7b6c29a0136
151 | *
152 | *
154 | *
156 | *
157 | *
159 | *
162 | *
163 | *
The returned data is entirely dependant on the bot list itself and is therefore unique.
180 | *
181 | *
183 | *
186 | *
187 | *
The returned data is entirely dependant on the bot list itself and is therefore unique.
202 | *
203 | *
205 | *
208 | *
209 | * A {@link RateLimitedException RatelimitedException} may be thrown
210 | * from the RequestHandler, if the HTTP request was rate limited.
211 | *
212 | *
The returned data is entirely dependant on the bot list itself and is therefore unique.
233 | *
234 | *
236 | *
238 | *
239 | *
241 | *
244 | *
245 | *
The returned data is entirely dependant on the bot list itself and is therefore unique.
264 | *
265 | *
267 | *
269 | *
270 | *
272 | *
275 | *
276 | *
The returned data is entirely dependant on the bot list itself and is therefore unique.
295 | *
296 | *
298 | *
301 | *
302 | *
304 | *
307 | *
308 | *
The returned data is entirely dependant on the bot list itself and is therefore unique.
332 | *
333 | *
335 | *
337 | *
338 | *
340 | *
343 | *
344 | *
The discriminator is based on the most common appearance of it across the bot lists.
368 | *
369 | *
371 | *
374 | *
375 | *
The discriminator is based on the most common appearance of it.
392 | *
393 | *
395 | *
397 | *
398 | *
400 | *
403 | *
404 | *
The GitHub link is based on the most common appearance of it.
427 | *
428 | *
430 | *
433 | *
434 | *
The GitHub link is based on the most common appearance of it.
451 | *
452 | *
454 | *
456 | *
457 | *
459 | *
462 | *
463 | *
The library is based on the most common appearance of it.
486 | *
487 | *
489 | *
492 | *
493 | *
The library is based on the most common appearance of it.
510 | *
511 | *
513 | *
515 | *
516 | *
518 | *
521 | *
522 | *
The name is based on the most common appearance of it.
545 | *
546 | *
548 | *
551 | *
552 | *
The name is based on the most common appearance of it.
569 | *
570 | *
572 | *
574 | *
575 | *
577 | *
580 | *
581 | *
The OAuth invite is used to add a bot to a Discord server.
604 | *
605 | *
607 | *
610 | *
611 | *
The OAuth invite is used to add a bot to a Discord server.
628 | *
629 | *
631 | *
633 | *
634 | *
636 | *
639 | *
640 | *
The IDs listed are based on how often they appear on the different bot lists.
663 | *
664 | *
666 | *
669 | *
670 | *
The IDs listed are based on how often they appear on the different bot lists.
685 | *
686 | *
688 | *
690 | *
691 | *
693 | *
696 | *
697 | *
The prefix is based on the most common appearance of it.
722 | *
723 | *
725 | *
728 | *
729 | *
The prefix is based on the most common appearance of it.
746 | *
747 | *
749 | *
751 | *
752 | *
754 | *
757 | *
758 | *
The server count is based on the most common appearance of it.
781 | *
782 | *
784 | *
787 | *
788 | *
The server count is based on the most common appearance of it.
803 | *
804 | *
806 | *
808 | *
809 | *
811 | *
814 | *
815 | *
The link is based on the most common appearance of it.
836 | *
837 | *
839 | *
842 | *
843 | *
The link is based on the most common appearance of it.
858 | *
859 | *
861 | *
863 | *
864 | *
866 | *
869 | *
870 | *
The website is based on the most common appearance of it.
891 | *
892 | *
894 | *
897 | *
898 | *
The website is based on the most common appearance of it.
915 | *
916 | *
918 | *
920 | *
921 | *
923 | *
926 | *
927 | *
55 | *
57 | *
58 | *
60 | *
62 | *
63 | * @param id
64 | * The id of the bot. This is required for the internal User-Agent.
65 | */
66 | public PostAction(@Nonnull String id){
67 | this(String.format(
68 | "JavaBotBlockAPI-0000/%s (Unknown; +https://jbba.dev) DBots/{id}",
69 | Info.VERSION
70 | ), id);
71 | }
72 |
73 | /**
74 | * Constructor to get an instance of PostAction.
75 | *
This constructor allows you to set a own User-Agent by providing any String as the first argument.
76 | *
77 | *
81 | *
83 | *
84 | * @param userAgent
85 | * The Name to use as User-Agent.
86 | * @param id
87 | * The id of the bot. This is required for the internal User-Agent.
88 | */
89 | public PostAction(@Nonnull String userAgent, @Nonnull String id){
90 | CheckUtil.notEmpty(userAgent, "UserAgent");
91 | CheckUtil.notEmpty(id, "ID");
92 |
93 | this.requestHandler = new RequestHandler(userAgent.replace("{id}", id));
94 | this.scheduler = requestHandler.getScheduler();
95 | }
96 |
97 | /**
98 | * Disables the automatic posting of Stats.
99 | *
This essentially just performs a {@link java.util.concurrent.ScheduledExecutorService#shutdown() ScheduledExecutorService.shutdown()}
100 | * by calling the {@link #disableAutoPost(BotBlockAPI) disableAutoPost(null)} method.
101 | *
102 | *
If you want to wait for the tasks to complete use {@link #disableAutoPost(BotBlockAPI) disableAutoPost(BotBlockAPI)} or
104 | * {@link #disableAutoPost(long, TimeUnit) disableAutoPost(long, TimeUnit)} instead.
105 | *
106 | * @see java.util.concurrent.ScheduledExecutorService#shutdown()
107 | */
108 | public void disableAutoPost(){
109 | disableAutoPost(null);
110 | }
111 |
112 | /**
113 | * Disables the automatic posting of Stats.
114 | *
Unlike {@link #disableAutoPost() disableAutoPost()} can you make the scheduler wait for all scheduled tasks to
115 | * finish, or to time out after n minutes by providing the {@link org.botblock.javabotblockapi.core.BotBlockAPI BotBlock instance}.
116 | *
117 | *
Unlike {@link #disableAutoPost() disableAutoPost()} can you make the scheduler wait for all scheduled tasks to
142 | * finish, or to time out after a specified time frame.
143 | *
144 | *
148 | *
150 | *
151 | * @param time
152 | * The amount of time to wait for scheduled executions to finish before the Scheduler would time out.
153 | * @param timeUnit
154 | * The {@link java.util.concurrent.TimeUnit TimeUnit} to use.
155 | *
156 | * @since 6.0.0
157 | */
158 | public void disableAutoPost(long time, @Nonnull TimeUnit timeUnit){
159 | CheckUtil.condition(time <= 0, "time may not be less or equal to 0!");
160 |
161 | try{
162 | scheduler.shutdown();
163 | if(!scheduler.awaitTermination(time, timeUnit))
164 | LOG.warn("Scheduler couldn't properly wait for termination.");
165 | }catch(InterruptedException ex){
166 | LOG.warn("Got interrupted while shutting down the Scheduler!", ex);
167 | }
168 | }
169 |
170 | /**
171 | * Starts a {@link java.util.concurrent.ScheduledExecutorService#scheduleAtFixedRate(Runnable, long, long, TimeUnit) scheduleAtFixedRate}
172 | * task, which will post the provided guild count to the provided bot lists every n minutes.
173 | *
174 | *
The scheduler may be canceled by this.
177 | *
178 | *
The scheduler may be canceled by this.
206 | *
207 | *
252 | *
254 | *
255 | * @param botId
256 | * The ID of the bot.
257 | * @param guilds
258 | * The guild count.
259 | * @param botBlockAPI
260 | * The {@link org.botblock.javabotblockapi.core.BotBlockAPI BotBlockAPI instance}.
261 | *
262 | * @throws java.io.IOException
263 | * When the post request couldn't be performed.
264 | * @throws org.botblock.javabotblockapi.core.exceptions.RateLimitedException
265 | * When we exceed the rate-limit of the BotBlock API.
266 | */
267 | public void postGuilds(@Nonnull String botId, int guilds, @Nonnull BotBlockAPI botBlockAPI) throws IOException, RateLimitedException{
268 | CheckUtil.notEmpty(botId, "botId");
269 |
270 | JSONObject json = new JSONObject()
271 | .put("server_count", guilds)
272 | .put("bot_id", botId);
273 |
274 | botBlockAPI.getTokens().forEach(json::put);
275 |
276 | requestHandler.performPOST(json, botBlockAPI.getTokens().size());
277 | }
278 | }
279 |
--------------------------------------------------------------------------------
/request/src/main/java/org/botblock/javabotblockapi/requests/handler/RequestHandler.java:
--------------------------------------------------------------------------------
1 | /*
2 | * Copyright 2019 - 2020 Andre601
3 | *
4 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
5 | * documentation files (the "Software"), to deal in the Software without restriction, including without limitation
6 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software,
7 | * and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
8 | *
9 | * The above copyright notice and this permission notice shall be included in all copies or substantial
10 | * portions of the Software.
11 | *
12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
13 | * INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
14 | * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
15 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
16 | * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
17 | */
18 |
19 | package org.botblock.javabotblockapi.requests.handler;
20 |
21 | import com.github.benmanes.caffeine.cache.Cache;
22 | import com.github.benmanes.caffeine.cache.Caffeine;
23 | import okhttp3.*;
24 | import org.botblock.javabotblockapi.core.exceptions.RateLimitedException;
25 | import org.botblock.javabotblockapi.core.CheckUtil;
26 | import org.json.JSONArray;
27 | import org.json.JSONException;
28 | import org.json.JSONObject;
29 | import org.slf4j.Logger;
30 | import org.slf4j.LoggerFactory;
31 |
32 | import javax.annotation.Nonnull;
33 | import javax.annotation.Nullable;
34 | import java.io.IOException;
35 | import java.util.concurrent.Executors;
36 | import java.util.concurrent.ScheduledExecutorService;
37 | import java.util.concurrent.TimeUnit;
38 |
39 | public class RequestHandler{
40 |
41 | private final Logger LOG = LoggerFactory.getLogger("JavaBotBlockAPI - RequestHandler");
42 | private final OkHttpClient CLIENT = new OkHttpClient();
43 | private final ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
44 |
45 | private final String BASE_URL = "https://botblock.org/api/";
46 | private final String userAgent;
47 |
48 | private final Cache
When posting the Guild count is this module a requirement! It depends on the core module.
22 | *
23 | * Installation
24 | * Please replace {@code API_VERSION} with the latest release on Bintray.
25 | *
26 | * Gradle (recommended)
27 | *
28 | *
38 | *
39 | *
29 | * repositories{
30 | * maven{ url = 'https://repo.codemc.io/repository/maven-public' }
31 | * }
32 | *
33 | * dependencies{
34 | * compile group: 'org.botblock', name: 'javabotblockapi-core', version: 'API_VERSION'
35 | * compile group: 'org.botblock', name: 'javabotblockapi-request', version: 'API_VERSION'
36 | * }
37 | *
Maven
40 | *
41 | *
63 | *
64 | * {@literal
42 | *
Manual
65 | * We do not recommend using jar files directly and instead use one of the above dependency management systems.
66 | *
67 | *