├── .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 | *

138 | */ 139 | ``` 140 | 141 | When using `notEmpty(String, String)` or `notEmpty(Map, String)` will you need to mention the NullPointerException and when using `condition(boolean, String)` will you need to mention the IllegalStateException. 142 | 143 | Unless the [RequestHandler notice](#requesthandler) is used should this paragraph be the last section of the description (right before the param section). 144 | 145 | #### RequestHandler 146 | JavaBotBlockAPI performs HTTP requests through a [RequestHandler] in the request module. 147 | If you implement a method that uses methods from the RequestHandler will you need to add the following lines to the Javadoc of the method: 148 | ```java 149 | /** 150 | *

Following Exceptions can be thrown from the HTTP request: 151 | *

155 | */ 156 | ``` 157 | 158 | This paragraph should always be the last section of the description. 159 | 160 | #### Padding 161 | `@param` names and descriptions, `@since` text and `@return` text should always be on the same vertical line. 162 | 163 | If `@return` is used should `@param` and `@since` have 2 spaces instead of one. 164 | 165 | #### Order 166 | Here is a full example showing the order of all mentioned parts. 167 | 168 | ```java 169 | /** 170 | * Returns "foobar". 171 | * 172 | * @return "foobar" 173 | * 174 | * @deprecated Use {@link #getFooBar(String) getFooBar(String)} instead. 175 | */ 176 | @Deprecated 177 | @DeprecatedSince(major = 6, minor = 0, patch = 0, replacements = {"#getFooBar(String)"}) 178 | @PlannedRemoval(major = 6, minor = 0, patch = 2) 179 | public String getFooBar(){ 180 | return "foobar"; 181 | } 182 | 183 | /** 184 | * Adds the provided String to "foo". 185 | * 186 | *

Following Exceptions can be thrown from the CheckUtil: 187 | *

190 | * 191 | * @param bar 192 | * The String to add to "foo". 193 | * 194 | * @return "foo" with the provided String appended to it. 195 | * 196 | * @since 6.0.0 197 | */ 198 | public String getFooBar(String bar){ 199 | return "foo" + bar; 200 | } 201 | ``` 202 | 203 | ---- 204 | ### Code Styling 205 | The Code follows a basic styling Guide that you need to follow when making a Pull request. 206 | 207 | #### spaces 208 | There are no spaces before parantheses and braces. 209 | 210 | *Example*: 211 | ```java 212 | // Wrong 213 | public void doSomething (boolean yes) { 214 | if (yes) { 215 | System.out.println("Yes"); 216 | return; 217 | } 218 | 219 | System.out.println("No"); 220 | } 221 | 222 | // Right 223 | public void doSomething(boolean yes){ 224 | if(yes){ 225 | System.out.println("Yes"); 226 | return; 227 | } 228 | 229 | System.out.println("No"); 230 | } 231 | ``` 232 | 233 | #### Single-line If-Statement 234 | Whenever a true if statement would result in a single line being executed should the braces be left away. 235 | 236 | *Example*: 237 | ```java 238 | // Wrong 239 | public void doSomething(boolean yes){ 240 | if(yes){ 241 | System.out.println("Yes"); 242 | } 243 | 244 | System.out.println("No"); 245 | } 246 | 247 | // Right 248 | public void doSomething(boolean yes){ 249 | if(yes) 250 | System.out.println("Yes"); 251 | 252 | System.out.println("No"); 253 | } 254 | ``` 255 | 256 | #### Parameter annotation 257 | Non-primitive Parameters should always be annotated with `@Nonnull` or `@Nullable` depending on whether they can be null or not. 258 | 259 | *Example*: 260 | ```java 261 | // Wrong 262 | public void doSomething(String text){ 263 | if(text == null){ 264 | System.out.println("No text provided!"); 265 | return; 266 | } 267 | 268 | System.out.println("Provided Text: " + text); 269 | } 270 | 271 | // Right 272 | public void doSomething(@Nullable String text){ 273 | if(text == null){ 274 | System.out.println("No text provided!"); 275 | return; 276 | } 277 | 278 | System.out.println("Provided Text: " + text); 279 | } 280 | ``` 281 | 282 | #### Empty Check for Nonnull annotated Objects 283 | Whenever an Object is annotated as Nonnull (See [previous part](#parameter-annotation)) should you use the `notEmpty` methods from the [CheckUtil] to make sure the parameter is actually not null nor empty. 284 | 285 | *Example*: 286 | ```java 287 | // Wrong 288 | public void doSomething(@Nonnull String text){ 289 | System.out.println("Provided Text: " + text); 290 | } 291 | 292 | // Right 293 | public void doSomething(@Nonnull String text){ 294 | CheckUtil.notEmpty(text, "Text"); 295 | 296 | System.out.println("Provided Text: " + text); 297 | } 298 | ``` -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.yml: -------------------------------------------------------------------------------- 1 | name: Bug Report 2 | description: Found a Bug about JavaBotBlockAPI? Use this template to report it! 3 | labels: "Type: Bug (Unconfirmed)" 4 | body: 5 | - type: markdown 6 | attributes: 7 | value: |- 8 | **BEFORE YOU OPEN THIS BUG REPORT!** 9 | 10 | In order to help you as good as possible with your issue will we ask you to fill out all required fields (Marked with a `*`) and to provide as much information as possible. 11 | - type: checkboxes 12 | attributes: 13 | label: Confirmation 14 | description: Please make sure to have followed these checks. 15 | options: 16 | - label: My issue isn't already found on the Issue tracker. 17 | required: true 18 | - label: My issue is about **JavaBotBlockAPI** and not any other library or BotBlock.org itself. 19 | required: true 20 | - label: I use the latest available version. 21 | required: true 22 | - type: dropdown 23 | attributes: 24 | label: "Modules" 25 | description: |- 26 | What modules are you currently using? 27 | 28 | Currently available: 29 | - `Core` 30 | - `Javacord` 31 | - `JDA` 32 | - `Request` 33 | multiple: true 34 | options: 35 | - "Core" 36 | - "Javacord" 37 | - "JDA" 38 | - "Request" 39 | validations: 40 | required: true 41 | - type: textarea 42 | attributes: 43 | label: "What happens?" 44 | description: "What bug are you encountering? Try to explain it as detailed as possible." 45 | placeholder: "JavaBotBlockAPI does this when I do that..." 46 | validations: 47 | required: true 48 | - type: textarea 49 | attributes: 50 | label: "Expected Behaviour" 51 | description: "What behaviour did you expect from JavaBotBlockAPI?" 52 | placeholder: "JavaBotBlockAPI should actually do..." 53 | validations: 54 | required: true 55 | - type: textarea 56 | attributes: 57 | label: "How to Reproduce" 58 | description: |- 59 | List the steps on how to reproduce this Bug. 60 | Make sure to also show any code-examples in `Code` to reproduce this bug. 61 | placeholder: |- 62 | 1. Do this 63 | 2. ... 64 | 3. Profit! 65 | validations: 66 | required: true 67 | - type: textarea 68 | attributes: 69 | label: "Code" 70 | description: |- 71 | Put your code here. 72 | This code needs to be able to reproduce the bug consistently! 73 | value: | 74 | ```java 75 | 76 | ``` 77 | render: "java" 78 | validations: 79 | required: true 80 | - type: input 81 | attributes: 82 | label: "Errors" 83 | description: |- 84 | Use a hastebin or pastebin site to share errors, stacktraces and similar. 85 | We recommend to use https://paste.gg 86 | placeholder: "https://paste.gg/p/anonymous/..." 87 | validations: 88 | required: true 89 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | contact_links: 3 | - name: Discord 4 | url: https://discord.gg/6dazXp6 5 | about: Join my Discord for receiving faster support. 6 | - name: Javadoc 7 | url: https://jbba.dev/docs 8 | about: Check the Javadocs for additional information. 9 | - name: CI Server 10 | url: https://ci.codemc.io/job/botblock/job/JavaBotBlockAPI/ 11 | about: You can find development builds on our CI Server. 12 | - name: Releases 13 | url: https://bintray.com/andre601/maven/JavaBotBlockAPI 14 | about: Latest releases can be found on Bintray. 15 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.yml: -------------------------------------------------------------------------------- 1 | name: Feature Request 2 | description: Suggest a new Feature for JavaBotBlockAPI 3 | labels: 'Type: Enhancement' 4 | body: 5 | - type: markdown 6 | attributes: 7 | value: |- 8 | Thank you for taking the time in creating this Feature Request. 9 | In order to process your feature request as fast and efficiently as possible do we ask you to fill out any required fields (Indicated with a `*`) with the requested information. 10 | - type: checkboxes 11 | attributes: 12 | label: Confirmation 13 | description: Please make sure to have followed these checks. 14 | options: 15 | - label: I checked the Issues and Pull request tab for any existing issues or PRs. 16 | required: true 17 | - label: My Feature Request is for **JavaBotBlockAPI** and not any external library or BotBlock.org itself. 18 | required: true 19 | - type: textarea 20 | attributes: 21 | label: "Description" 22 | description: |- 23 | Give a detailed explanation about your Feature request and why it would be beneficial for JavaBotBlockAPI. 24 | Just saying "It's cool!" or "I need it" don't count as valid reasons. It needs to have a clear benefit for **other** users too. 25 | validations: 26 | required: true 27 | - type: textarea 28 | attributes: 29 | label: "Code Example" 30 | description: |- 31 | Do you have any Code Snippets that you want to share with us? 32 | Remember to use Code blocks for smaller snippets and https://paste.gg for larger ones. 33 | placeholder: |- 34 | ```java 35 | public boolean method(){ return true; } 36 | ``` 37 | render: "java" 38 | - type: textarea 39 | attributes: 40 | label: "Additional Information" 41 | description: "Add any extra info you think is nessesary for this Feature request." 42 | placeholder: "Put any extra info you like into this field..." 43 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | [Pull requests]: https://github.com/botblock/JavaBotBlockAPI/pulls 2 | [guidelines]: https://github.com/botblock/JavaBotBlockAPI/blob/master/.github/CONTRIBUTING.md 3 | 4 | ## Check 5 | Please make sure you checked the following things first: 6 | 7 | - [ ] There is no open PR in the [Pull requests] page containing your changes. 8 | - [ ] You follow the [Contributing Guidelines][guidelines] about comments and such. 9 | 10 | ## Summary 11 | 12 | 13 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | version: 2 2 | updates: 3 | - package-ecosystem: github-actions 4 | target-branch: development 5 | directory: "/" 6 | schedule: 7 | interval: daily 8 | open-pull-requests-limit: 10 9 | labels: 10 | - 'Type: Dependency update' 11 | - package-ecosystem: gradle 12 | target-branch: development 13 | directory: "/" 14 | schedule: 15 | interval: daily 16 | open-pull-requests-limit: 10 17 | labels: 18 | - 'Type: Dependency update' 19 | -------------------------------------------------------------------------------- /.github/label-commenter-config.yml: -------------------------------------------------------------------------------- 1 | labels: 2 | - name: 'Type: Question' 3 | labeled: 4 | issue: 5 | body: |- 6 | Hello @{{ issue.user.login }}, 7 | 8 | We sadly do not provide support through Issues. 9 | Please join the [Discord Server](https://discord.gg/6dazXp6) and ask in the `#javabotblockapi` channel to receive support. 10 | *This issue has been automatically closed.* 11 | action: close 12 | - name: 'Type: Duplicate' 13 | labeled: 14 | issue: 15 | body: |- 16 | Your issue is already known and a separate issue with the exact same report/feature request already exist. 17 | 18 | Please comment on the already existing issue with your information instead of opening your own. 19 | *This issue has been automatically closed.* 20 | action: close 21 | - name: 'Type: JDA issue' 22 | labeled: 23 | issue: 24 | body: |- 25 | Hello @{{ issue.user.login }}, 26 | 27 | The issue you encounter is caused by JDA and not JavaBotBlockAPI. 28 | Please [join the JDA Discord](https://discord.gg/0hMr4ce0tIk3pSjp) and ask there for support. 29 | *This issue has been automatically closed.* 30 | - name: 'Type: BotBlock issue' 31 | labeled: 32 | issue: 33 | body: |- 34 | Hello @{{ issue.user.login }}, 35 | 36 | The issue you encounter is caused by BotBlock and not JavaBotBlockAPI. 37 | Please [join the BotBlock Discord](https://botblock.org/discord) and ask there for support. 38 | *This issue has been automatically closed.* 39 | - name: 'Result: Invalid' 40 | labeled: 41 | issue: 42 | body: |- 43 | Hello @{{ issue.user.login }}, 44 | 45 | Your Issue has beeen marked as invalid. 46 | Make sure to use and follow the provided Issue templates. Issues not following the templates get closed. 47 | action: close 48 | pr: 49 | body: |- 50 | Hello @{{ issue.user.login }}, 51 | 52 | Your Pull request has beeen marked as invalid. 53 | Make sure to use and follow the provided Pull request templates. Pull requests not following the templates get closed. 54 | action: close 55 | unlabeled: 56 | issue: 57 | body: |- 58 | Thank you @{{ issue.user.login }} for following the Issue Template. 59 | Your Issue has been re-opened and the dev will look into it. 60 | action: open 61 | pr: 62 | body: |- 63 | Thank you @{{ issue.user.login }} for following the Pull request Template. 64 | Your Pull request has been re-opened and the dev will look into it. 65 | action: open 66 | - name: 'Status: Requires more info' 67 | labeled: 68 | issue: 69 | body: |- 70 | Hello @{{ issue.user.login }}, 71 | 72 | Your issue doesn't provide enough information for us to help you. 73 | Please make sure to provide as much information as possible, including the version of JavaBotBlockAPI, any configuration you made and what steps you took. 74 | unlabeled: 75 | issue: 76 | body: |- 77 | Thank you @{{ issue.user.login }} for providing additional information. 78 | The developer will take a look at your issue and try to find a solution for it, so stay tight. 79 | -------------------------------------------------------------------------------- /.github/release-drafter.yml: -------------------------------------------------------------------------------- 1 | name-template: "v$RESOLVED_VERSION: " 2 | tag-template: "$RESOLVED_VERSION" 3 | prerelease: false 4 | publish: false 5 | exclude-labels: 6 | - "Action: No Changelog" 7 | 8 | category_template: "### $TITLE" 9 | categories: 10 | - title: "🚀 Features" 11 | labels: 12 | - "Type: Enhancement" 13 | - title: "🐛 Bug fixes" 14 | labels: 15 | - "Type: Bug (Confirmed)" 16 | - title: "🔧 Dependencies" 17 | labels: 18 | - "Type: Dependency update" 19 | 20 | change-template: "- [#$NUMBER]: **$TITLE**" 21 | 22 | version-resolver: 23 | major: 24 | labels: 25 | - "Action: Update Major" 26 | minor: 27 | labels: 28 | - "Action: Update Minor" 29 | patch: 30 | labels: 31 | - "Action: Update Patch" 32 | default: patch 33 | template: | 34 | ## Release Notes 35 | $CHANGES 36 | -------------------------------------------------------------------------------- /.github/workflows/auto-comment.yml: -------------------------------------------------------------------------------- 1 | name: Rebase Action 2 | 3 | on: 4 | issues: 5 | types: 6 | - labeled 7 | - unlabeled 8 | pull_request: 9 | types: 10 | - labeled 11 | - unlabeled 12 | 13 | jobs: 14 | rebase: 15 | name: Auto Comment 16 | runs-on: ubuntu-latest 17 | steps: 18 | - name: Checkout Code 19 | uses: actions/checkout@v2.3.4 20 | with: 21 | ref: master 22 | - name: Comment on (un)labeled issue/Pull request 23 | uses: peaceiris/actions-label-commenter@v1.9.1 24 | with: 25 | github_token: ${{ secrets.GITHUB_TOKEN }} 26 | -------------------------------------------------------------------------------- /.github/workflows/auto_approve_pr.yml: -------------------------------------------------------------------------------- 1 | name: Automatically approve Pull requests 2 | 3 | on: 4 | pull_request_target: 5 | types: 6 | - opened 7 | branches: 8 | - master 9 | 10 | jobs: 11 | auto-approve: 12 | runs-on: ubuntu-latest 13 | if: ${{ github.actor == 'Andre601' }} 14 | steps: 15 | - uses: hmarr/auto-approve-action@v2 16 | with: 17 | github-token: "${{ secrets.GITHUB_TOKEN }}" 18 | -------------------------------------------------------------------------------- /.github/workflows/gen_javadocs.yml: -------------------------------------------------------------------------------- 1 | name: Build Javadocs 2 | 3 | on: 4 | workflow_dispatch: 5 | 6 | jobs: 7 | generateJavadoc: 8 | runs-on: ubuntu-latest 9 | steps: 10 | - name: Checkout Code 11 | uses: actions/checkout@v2.3.4 12 | with: 13 | ref: 'master' 14 | - name: Set up Java 11 15 | uses: actions/setup-java@v2 16 | with: 17 | distribution: 'temurin' 18 | java-version: '11' 19 | - name: Generate Javadoc 20 | run: ./gradlew javadoc 21 | - name: Push changes 22 | uses: peaceiris/actions-gh-pages@v3.8.0 23 | with: 24 | github_token: ${{ secrets.GITHUB_TOKEN }} 25 | publish_dir: ./docs 26 | commit_message: "Update Docs" 27 | enable_jekyll: true 28 | -------------------------------------------------------------------------------- /.github/workflows/generate_javadoc.yml: -------------------------------------------------------------------------------- 1 | name: Publication task 2 | 3 | on: 4 | release: 5 | types: [published] 6 | branches: 7 | - master 8 | 9 | jobs: 10 | generateJavadoc: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - name: Checkout Code 14 | uses: actions/checkout@v2.3.4 15 | with: 16 | ref: 'master' 17 | - name: Set up Java 11 18 | uses: actions/setup-java@v2 19 | with: 20 | distribution: 'adopt' 21 | java-version: '11.0.10+9' 22 | - name: Generate Javadoc 23 | run: ./gradlew javadoc 24 | - name: Push changes 25 | uses: peaceiris/actions-gh-pages@v3.8.0 26 | with: 27 | github_token: ${{ secrets.GITHUB_TOKEN }} 28 | publish_dir: ./docs 29 | commit_message: "Update Docs" 30 | generateJars: 31 | needs: [generateJavadoc] 32 | if: success() 33 | runs-on: ubuntu-latest 34 | steps: 35 | - name: Checkout Code 36 | uses: actions/checkout@v2.3.4 37 | - name: Set up Java 11 38 | uses: actions/setup-java@v2 39 | with: 40 | distribution: 'adopt' 41 | java-version: '11.0.10+9' 42 | - name: Generate Jars 43 | run: ./gradlew build 44 | - name: Zip files 45 | working-directory: ./build/libs 46 | run: zip JavaBotBlockAPI-${{ github.event.release.tag_name }}.zip *.jar 47 | - name: Upload files 48 | uses: AButler/upload-release-assets@v2.0 49 | with: 50 | files: 'build/libs/JavaBotBlockAPI-${{ github.event.release.tag_name }}.zip;build/libs/*.jar' 51 | repo-token: ${{ secrets.GITHUB_TOKEN }} 52 | sendMessage: 53 | needs: [generateJars] 54 | if: success() 55 | runs-on: ubuntu-latest 56 | steps: 57 | - name: Discord notification 58 | uses: rjstone/discord-webhook-notify@v1 59 | with: 60 | webhookUrl: ${{ secrets.DISCORD_WEBHOOK }} 61 | severity: info 62 | avatarUrl: 'https://docs.botblock.org/JavaBotBlockAPI/assets/img/jbba.png' 63 | username: 'New release' 64 | text: '${{ github.event.release.name }}' 65 | description: '[**Release Information**](${{ github.event.release.html_url }})' 66 | details: '${{ github.event.release.body }}' 67 | footer: 'Version ${{github.event.release.tag_name}}' 68 | -------------------------------------------------------------------------------- /.github/workflows/release_drafter.yml: -------------------------------------------------------------------------------- 1 | 2 | name: Release notes 3 | 4 | on: 5 | push: 6 | branches: 7 | - master 8 | pull_request_target: 9 | branches: 10 | - master 11 | 12 | jobs: 13 | update_release_draft: 14 | runs-on: ubuntu-latest 15 | steps: 16 | - uses: release-drafter/release-drafter@v5 17 | env: 18 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 19 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by https://www.gitignore.io/api/intellij 2 | # Edit at https://www.gitignore.io/?templates=intellij 3 | 4 | ### Intellij ### 5 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm 6 | # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 7 | 8 | # User-specific stuff 9 | .idea/**/workspace.xml 10 | .idea/**/tasks.xml 11 | .idea/**/usage.statistics.xml 12 | .idea/**/dictionaries 13 | .idea/**/shelf 14 | 15 | # Generated files 16 | .idea/**/contentModel.xml 17 | 18 | # Sensitive or high-churn files 19 | .idea/**/dataSources/ 20 | .idea/**/dataSources.ids 21 | .idea/**/dataSources.local.xml 22 | .idea/**/sqlDataSources.xml 23 | .idea/**/dynamic.xml 24 | .idea/**/uiDesigner.xml 25 | .idea/**/dbnavigator.xml 26 | 27 | # Gradle 28 | .idea/**/gradle.xml 29 | .idea/**/libraries 30 | 31 | # Gradle and Maven with auto-import 32 | # When using Gradle or Maven with auto-import, you should exclude module files, 33 | # since they will be recreated, and may cause churn. Uncomment if using 34 | # auto-import. 35 | .idea/modules.xml 36 | .idea/*.iml 37 | .idea/modules 38 | *.iml 39 | *.ipr 40 | 41 | # CMake 42 | cmake-build-*/ 43 | 44 | # Mongo Explorer plugin 45 | .idea/**/mongoSettings.xml 46 | 47 | # File-based project format 48 | *.iws 49 | 50 | # IntelliJ 51 | out/ 52 | 53 | # mpeltonen/sbt-idea plugin 54 | .idea_modules/ 55 | 56 | # JIRA plugin 57 | atlassian-ide-plugin.xml 58 | 59 | # Cursive Clojure plugin 60 | .idea/replstate.xml 61 | 62 | # Crashlytics plugin (for Android Studio and IntelliJ) 63 | com_crashlytics_export_strings.xml 64 | crashlytics.properties 65 | crashlytics-build.properties 66 | fabric.properties 67 | 68 | # Editor-based Rest Client 69 | .idea/httpRequests 70 | 71 | # Android studio 3.1+ serialized cache file 72 | .idea/caches/build_file_checksums.ser 73 | 74 | ### Intellij Patch ### 75 | # Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 76 | 77 | # *.iml 78 | # modules.xml 79 | # .idea/misc.xml 80 | # *.ipr 81 | 82 | # Sonarlint plugin 83 | .idea/**/sonarlint/ 84 | 85 | # SonarQube Plugin 86 | .idea/**/sonarIssues.xml 87 | 88 | # Markdown Navigator plugin 89 | .idea/**/markdown-navigator.xml 90 | .idea/**/markdown-navigator/ 91 | 92 | # End of https://www.gitignore.io/api/intellij 93 | build/ 94 | /.idea/ 95 | 96 | .gradle/ 97 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Code of Conduct 2 | 3 | ## Our Goal 4 | We want to create a welcoming community in this project. 5 | To achieve this did we create this Code of Conduct which apply accross the project. 6 | 7 | ## Our standards 8 | We encourage and accept the following positive behaviours towards the project and others: 9 | - A positive and welcoming language 10 | - Helpful and supportive messages 11 | - Giving but also accepting constructive criticism 12 | 13 | We **don't** encourage nor allow the following behaviours towards the project and others: 14 | - Any speach that contains insults or attacks towards race, religion, sexuality, gender or similar 15 | - Public or private harassment 16 | - Publishing any kind of private information (physical or electronic addresses) without any permission 17 | - Publishing sexual content including but not limited to links or images 18 | - Any other conduct that could be considered inappropriate 19 | 20 | Those are by no means full lists of what is and is not allowed. 21 | 22 | ## What we do 23 | We will delete any messages, opened issues or pull requests that may be against this code of coduct and revoke access to the project. 24 | 25 | ## Scope 26 | This Code of Conduct applies to the full project and any public spaces when an individual represents this project or its community. 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) Andre_601 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | [BotBlock]: https://botblock.org 2 | [API]: https://botblock.org/api/docs 3 | [list]: https://botblock.org/api/docs#count 4 | 5 | [BotBlock4J]: https://github.com/spide-r/BotBlock4J 6 | 7 | [wiki]: https://jbba.dev/docs 8 | 9 | [CodeMCBadge]: https://img.shields.io/jenkins/build?jobUrl=https%3A%2F%2Fci.codemc.io%2Fjob%2Fbotblock%2Fjob%2FJavaBotBlockAPI%2F&label=Dev%20Builds&style=plastic 10 | [CodeMC]: https://ci.codemc.io/job/botblock/job/JavaBotBlockAPI/ 11 | 12 | [DownloadBadge]: https://img.shields.io/nexus/maven-public/org.botblock/javabotblockapi-core?label=Release&server=https%3A%2F%2Frepo.codemc.io&style=plastic 13 | [Download]: https://ci.codemc.io/job/botblock/job/JavaBotBlockAPI/lastSuccessfulBuild 14 | 15 | [JDA]: https://github.com/DV8FromTheWorld/JDA 16 | [Javacord]: https://github.com/javacord/Javacord 17 | 18 | [OkHttp]: https://github.com/square/okhttp/ 19 | [JSON]: https://github.com/stleary/JSON-java 20 | [Caffeine]: https://github.com/ben-manes/caffeine 21 | 22 | [contributors.md]: https://github.com/botblock/JavaBotBlockAPI/blob/master/contributors.md 23 | 24 | [Javadoc]: https://docs.botblock.org/JavaBotBlockAPI 25 | [image]: https://docs.botblock.org/JavaBotBlockAPI/assets/img/JavaBotBlockAPI.png 26 | [site]: https://docs.botblock.org/JavaBotBlockAPI/core/org/botblock/javabotblockapi/core/Site.html 27 | 28 | ![image] 29 | 30 | JavaBotBlockAPI is a continued and updated Java Wrapper for [BotBlock], a website that makes it possible to update guild counts on multiple lists with one API. 31 | This wrapper is a fork of [BotBlock4J] and was updated and improved to make it as userfriendly as possible. 32 | 33 | # Installation 34 | [![DownloadBadge]][Download] [![CodeMCBadge]][CodeMC] 35 | 36 | You can install JavaBotBlockAPI through the following methods. 37 | Make sure to replace `{version}` with the above shown version. 38 | 39 | ## Gradle 40 | To download the different modules will you need to add the following snippets to your `build.gradle`: 41 | 42 | ```groovy 43 | repositories{ 44 | maven{ url = 'https://repo.codemc.io/repository/maven-public' } 45 | } 46 | 47 | dependencies{ 48 | // Core Module. Always needed 49 | compile group: 'org.botblock', name: 'javabotblockapi-core', version: '{version}' 50 | 51 | // Request Module. Depends on Core 52 | compile group: 'org.botblock', name: 'javabotblockapi-request', version: '{version}' 53 | 54 | // JDA Module. Depends on Core and Request 55 | compile group: 'org.botblock', name: 'javabotblockapi-jda', version: '{version}' 56 | 57 | // Javacord Module. Depends on Core and Request 58 | compile group: 'org.botblock', name: 'javabotblockapi-javacord', version: '{version}' 59 | } 60 | ``` 61 | 62 | ## Maven 63 | To download the different modules will you need to add the following snippets to your `pom.xml`: 64 | 65 | ```xml 66 | 67 | 68 | codemc 69 | https://repo.codemc.io/repository/maven-public 70 | 71 | 72 | 73 | 74 | 75 | 76 | org.botblock 77 | javabotblockapi-core 78 | {version} 79 | 80 | 81 | 82 | 83 | org.botblock 84 | javabotblockapi-request 85 | {version} 86 | 87 | 88 | 89 | 90 | org.botblock 91 | javabotblockapi-jda 92 | {version} 93 | 94 | 95 | 96 | 97 | org.botblock 98 | javabotblockapi-javacord 99 | {version} 100 | 101 | 102 | ``` 103 | 104 | # Usage Examples 105 | Below will you find a few examples on how JavaBotBlockAPI can/should be used. 106 | Please make sure to also take a look at the [Javadoc] for any additional information. 107 | 108 | ## BotBlockAPI 109 | > **Required Modules**: 110 | > - `core` 111 | 112 | If you want to POST guild counts to the various bot lists should you first create a BotBlockAPI instance. 113 | The BotBlockAPI class contains a nested Builder class which allows a more streamlined creation of a BotBlockAPI instance. 114 | 115 | **Example**: 116 | ```java 117 | BotBlockAPI api = new BotBlockAPI.Builder() 118 | .addAuthToken("discordextremelist.xyz", "my_s3cr3t_t0k3n") 119 | .addAuthToken(Site.DISCORDLIST_SPACE, "my_53cret_tok3n") 120 | .build(); 121 | ``` 122 | 123 | As you can see can you provide either a String with the id you can find [here][list] or use one of the many static [Site] instances that are offered. 124 | The Builder has some extra methods that can be used to further customize specific behaviours. Take a look on the [Javadoc] for those. 125 | 126 | Next would you need to choose, which type of PostAction you want to use. Depending on your selection will you need to have the right module(s) downloaded. 127 | 128 | ## Default PostAction 129 | > **Required Modules**: 130 | > - `request` 131 | > 132 | > *In the following examples will `botId` and `guilds` be used. Those are placeholders for your bot's ID and Guild count respectively.* 133 | 134 | ```java 135 | // Create PostAction instance 136 | PostAction postAction = new PostAction("botId"); 137 | 138 | // Post manually 139 | postAction.postGuilds("botId", guilds, api); 140 | 141 | // Post automatically 142 | postAction.enableAutoPost("botId", guilds, api); 143 | 144 | // Disable automatic posting 145 | postAction.disableAutoPost(); // Disable with no delay 146 | postAction.disableAutoPost(api); // Disable with BotBlockAPI#getUpdateDelay() delay 147 | postAction.disableAutoPost(1, TimeUnit.MINUTES); // Disable with 1 Minute delay. 148 | ``` 149 | 150 | ## JDA PostAction 151 | > **Required Modules**: 152 | > - `request` 153 | > - `jda` 154 | 155 | ```java 156 | /* 157 | * Get your JDA instance. 158 | * This can also be a ShardManager instance 159 | * for sharded Bots. 160 | */ 161 | JDA jda = getJDA(); 162 | 163 | // Create PostAction instance 164 | PostAction postAction = new PostAction(jda); 165 | 166 | 167 | // Post manually 168 | postAction.postGuilds(jda, api); 169 | 170 | // Post automatically 171 | postAction.enableAutoPost(jda, api); 172 | 173 | // Disable automatic posting 174 | postAction.disableAutoPost(); // Disable with no delay 175 | postAction.disableAutoPost(api); // Disable with BotBlockAPI#getUpdateDelay() delay 176 | postAction.disableAutoPost(1, TimeUnit.MINUTES); // Disable with 1 Minute delay. 177 | ``` 178 | 179 | ## Javacord PostAction 180 | > **Required Modules**: 181 | > - `request` 182 | > - `javacord` 183 | 184 | ```java 185 | /* 186 | * Get your DiscordApi instances. 187 | */ 188 | DiscordApi[] discordApis = getDiscordApis(); 189 | 190 | // Create PostAction instance 191 | PostAction postAction = new PostAction(discordApis[0]); 192 | 193 | // Post manually 194 | postAction.postGuilds(api, discordApis); 195 | 196 | // Post automatically 197 | postAction.enableAutoPost(api, discordApis); 198 | 199 | // Disable automatic posting 200 | postAction.disableAutoPost(); // Disable with no delay 201 | postAction.disableAutoPost(api); // Disable with BotBlockAPI#getUpdateDelay() delay 202 | postAction.disableAutoPost(1, TimeUnit.MINUTES); // Disable with 1 Minute delay. 203 | ``` 204 | 205 | ---- 206 | ## Get Bot Information 207 | > **Required Modules**: 208 | > - `core` 209 | > - `request` 210 | 211 | You can use the GetBotAction class to retrieve information about a bot on the different Bot lists. 212 | The class offers options for either getting the full information as JSONObject, or to retrieve specific information such as the authors of the bot. 213 | 214 | Due to the huge amount of methods offered by this class are we not showing any examples here. 215 | A look into the [Javadoc] is highly recommendet. 216 | 217 | ---- 218 | ## Get List Information 219 | > **Required Modules**: 220 | > - `core` 221 | > - `request` 222 | 223 | Similar to [Getting Bot Information](#get-bot-information) can you also retrieve information known by BotBlock about either all or specific bot lists. 224 | The GetListAction allows the retrieval of all Bot Lists and their information as a JSONObject, or a specific info such as the URL used for seeing a Bot's list entry for a specific bot list. 225 | 226 | Due to the huge amount of methods offered by this class are we not showing any examples here. 227 | A look into the [Javadoc] is highly recommendet. 228 | 229 | # Libraries/Dependencies 230 | JavaBotBlockAPI utilizes different APIs to provide the functionality it offers right now. 231 | We have a list of those libraries listed here. 232 | 233 | - **Javacord Module** 234 | - [Javacord] - Java Wrapper for making Discord Bots. 235 | - **JDA Module** 236 | - [JDA] - Java library used for creating bots. 237 | - **Request Module** 238 | - [OkHttp] - Library for creating and managing http requests. 239 | - [JSON] - Used for JSON management. 240 | - [Caffeine] - Library used for caching. 241 | 242 | 243 | # Links 244 | Here are some useful links: 245 | - [BotBlock.org][BotBlock] Site for which this wrapper was made. 246 | - [API] API documentation. 247 | - [Javadoc] Java documentation of the Wrapper. 248 | - [CodeMC] CI server for dev builds. Those jar files may differ from the ones on bintray. 249 | - [BotBlock4J] Original Wrapper from which this one originates. 250 | 251 | # Contributors 252 | We appreciate any contribution from others towards this project. 253 | All contributors are listed on the [contributors.md] file. 254 | -------------------------------------------------------------------------------- /SECURITY.md: -------------------------------------------------------------------------------- 1 | [discord]: https://discord.gg/6dazXp6 2 | [issue]: https://github.com/botblock/JavaBotBlockAPI/issues/new?labels=Type%3A+Bug+%28Unconfirmed%29&template=bug_report.yml 3 | [contributing]: https://github.com/botblock/JavaBotBlockAPI/blob/master/.github/CONTRIBUTING.md 4 | 5 | [version]: https://img.shields.io/nexus/maven-public/org.botblock/javabotblockapi-core?label=Release&server=https%3A%2F%2Frepo.codemc.io&style=plastic 6 | 7 | # Security Policy 8 | Security is important to us. 9 | To make sure that there aren't any vulnerabilities in our library to we ask you to report any issues to us that could affect the security of this library and its connections. 10 | 11 | ## Before sumbitting 12 | Before you submit a bug report or similar to us would we like to ask you to make sure, that you use the latest version. 13 | We can't and won't fix bugs that exist in older versions and aren't present on newer ones. 14 | 15 | We support all minor and patch-versions of the latest major version which currently is Version **6** (Last updated: 11th of March 2021). 16 | 17 | The latest available version is seen below: 18 | ![version] 19 | 20 | ## How to report 21 | If your issue is in fact a security-issue/vulnerability would we like to ask you, to report to in our [Discord Server][discord] directly. 22 | Issues are not the right place to report these kinds of problems as they would allow people to find out about them and use it to their malicious benefit. 23 | 24 | If your issue is just a regular bug can you open a normal [Bug Report][issue] on our Issue tracker. 25 | Please make sure to follow our [Contributing Guidelines][contributing] while doing so. -------------------------------------------------------------------------------- /build.gradle: -------------------------------------------------------------------------------- 1 | plugins{ 2 | id 'java' 3 | id 'java-library' 4 | id 'idea' 5 | id 'maven-publish' 6 | id 'maven' 7 | id 'com.github.johnrengelman.shadow' version '5.2.0' 8 | } 9 | 10 | def ver = new Version(major: 6, minor: 7, patch: 4) 11 | 12 | allprojects { 13 | apply plugin: 'maven-publish' 14 | apply plugin: 'java-library' 15 | apply plugin: 'com.github.johnrengelman.shadow' 16 | 17 | group = "org.botblock" 18 | version = "$ver" 19 | 20 | ext { 21 | 22 | dependencies { 23 | api group: 'org.json', name: 'json', version: '20210307' 24 | api group: 'com.github.ben-manes.caffeine', name: 'caffeine', version: '3.0.2' 25 | api group: 'com.google.code.findbugs', name: 'jsr305', version: '3.0.2' 26 | api group: 'org.slf4j', name: 'slf4j-api', version: '1.7.30' 27 | 28 | artifactId = (rootProject == project? project.name : "$rootProject.name-$project.name").toLowerCase() 29 | moduleName = "${group}.javabotblockapi${rootProject == project? "" : ".${project.name.toLowerCase()}"}" 30 | } 31 | 32 | 33 | configureJar = { Object jarConfig, String classifier = '' -> 34 | jarConfig.baseName = "$project.artifactId" 35 | jarConfig.version = "$project.version" 36 | jarConfig.classifier = classifier 37 | jarConfig.extension = 'jar' 38 | 39 | jarConfig.manifest { 40 | it.attributes( 41 | 'Implementation-Title': project.artifactId, 42 | 'Implementation-Version': project.version, 43 | 'Automatic-Module-Name': "${project.moduleName}" 44 | ) 45 | } 46 | } 47 | 48 | configureJavadoc = { Object jDocConfig -> 49 | jDocConfig.options { 50 | it.author() 51 | it.encoding = 'UTF-8' 52 | it.memberLevel = JavadocMemberLevel.PUBLIC 53 | 54 | if (it instanceof StandardJavadocDocletOptions) { 55 | def opt = it as StandardJavadocDocletOptions 56 | 57 | opt.links( 58 | // JSON Lib 59 | "https://stleary.github.io/JSON-java/", 60 | 61 | // Discord Libs 62 | "https://ci.dv8tion.net/job/JDA/javadoc/", 63 | 64 | // Java 8 65 | "https://docs.oracle.com/javase/8/docs/api/", 66 | 67 | // BotBlock Docs 68 | "https://docs.botblock.org/JavaBotBlockAPI/core/", 69 | "https://docs.botblock.org/JavaBotBlockAPI/jda/", 70 | //"https://docs.botblock.org/JavaBotBlockAPI/javacord/", 71 | "https://docs.botblock.org/JavaBotBlockAPI/request/" 72 | ) 73 | 74 | if (JavaVersion.current().isJava9Compatible()) { 75 | opt.addBooleanOption("html5", true) 76 | opt.addStringOption("-release", "8") 77 | } 78 | 79 | if (JavaVersion.current().isJava11Compatible()) { 80 | opt.addBooleanOption("-no-module-directories", true) 81 | } 82 | } 83 | } 84 | } 85 | } 86 | 87 | repositories { 88 | mavenCentral() 89 | jcenter() 90 | maven { url = 'https://m2.dv8tion.net/releases' } 91 | } 92 | 93 | build { 94 | dependsOn { jar } 95 | dependsOn { javadocJar } 96 | dependsOn { sourcesJar } 97 | dependsOn { shadowJar } 98 | } 99 | 100 | } 101 | 102 | subprojects { 103 | apply plugin: 'java' 104 | 105 | ext { 106 | includeInParent = true 107 | } 108 | 109 | compileJava { 110 | source = sourceSets.main.allJava 111 | classpath = sourceSets.main.compileClasspath 112 | } 113 | 114 | javadoc { 115 | destinationDir = file("$rootDir/docs/$project.name/") 116 | 117 | configureJavadoc(it) 118 | } 119 | 120 | jar { 121 | destinationDirectory = file("$rootDir/build/libs/") 122 | configureJar(it) 123 | } 124 | 125 | shadowJar { 126 | destinationDirectory = file("$rootDir/build/libs/") 127 | configureJar(it, 'all') 128 | } 129 | 130 | task javadocJar(type: Jar) { 131 | group = 'build' 132 | dependsOn javadoc 133 | from javadoc.destinationDir 134 | configureJar(it, 'javadoc') 135 | destinationDirectory = file("$rootDir/build/libs/") 136 | } 137 | 138 | task sourceJar(type: Jar) { 139 | group = 'build' 140 | dependsOn classes 141 | from sourceSets.main.allSource 142 | configureJar(it, 'sources') 143 | destinationDirectory = file("$rootDir/build/libs/") 144 | } 145 | 146 | afterEvaluate { 147 | if(project.includeInParent) { 148 | rootProject.dependencies.compile project 149 | } 150 | } 151 | 152 | publishing { 153 | publications { 154 | mavenJava(MavenPublication) { 155 | groupId = rootProject.group 156 | artifactId = "javabotblockapi-"+project.name 157 | version = rootProject.version 158 | 159 | from components.java 160 | artifact javadocJar 161 | artifact sourceJar 162 | } 163 | } 164 | repositories { 165 | maven { 166 | url = "https://repo.codemc.io/repository/maven-releases/" 167 | 168 | def mavenUsername = System.getenv("ORG_GRADLE_PROJECT_mavenUsername") ? System.getenv("ORG_GRADLE_PROJECT_mavenUsername") : 169 | System.getProperty("ORG_GRADLE_PROJECT_mavenUsername") ? System.getProperty("ORG_GRADLE_PROJECT_mavenUsername") : null 170 | def mavenPassword = System.getenv("ORG_GRADLE_PROJECT_mavenPassword") ? System.getenv("ORG_GRADLE_PROJECT_mavenPassword") : 171 | System.getProperty("ORG_GRADLE_PROJECT_mavenPassword") ? System.getProperty("ORG_GRADLE_PROJECT_mavenPassword") : null 172 | 173 | if(mavenUsername != null && mavenPassword != null) { 174 | credentials { 175 | username = mavenUsername 176 | password = mavenPassword 177 | } 178 | } 179 | } 180 | } 181 | } 182 | 183 | } 184 | 185 | configurations { 186 | compile { 187 | description = 'compile' 188 | transitive = true 189 | } 190 | } 191 | 192 | shadowJar{ 193 | configureJar(it, 'all') 194 | 195 | from { subprojects*.jar } 196 | destinationDirectory = file("$rootDir/build/libs/") 197 | } 198 | 199 | task javadocJar(type: Jar, dependsOn: javadoc){ 200 | configureJar(it, 'javadoc') 201 | 202 | from { javadoc.destinationDir } 203 | destinationDirectory = file("$rootDir/build/libs/") 204 | } 205 | 206 | 207 | task sourcesJar(type: Jar, dependsOn: classes){ 208 | group = 'build' 209 | dependsOn { rootProject.getTasksByName('classes', true) } 210 | 211 | configureJar(it, 'sources') 212 | 213 | from { subprojects*.sourceSets.main.allSource } 214 | destinationDirectory = file("$rootDir/build/libs/") 215 | } 216 | 217 | 218 | class Version{ 219 | String major, minor, patch 220 | 221 | static String getBuild(){ 222 | System.getenv("BUILD_NUMBER") ? "_" + System.getenv("BUILD_NUMBER") : 223 | System.getProperty("BUILD_NUMBER") ? "_" + System.getProperty("BUILD_NUMBER") : "" 224 | } 225 | 226 | String toString(){ 227 | "$major.$minor.${patch}$build" 228 | } 229 | } 230 | -------------------------------------------------------------------------------- /contributors.md: -------------------------------------------------------------------------------- 1 | [all-contributors]: https://allcontributors.org 2 | [emojis]: https://allcontributors.org/docs/en/emoji-key 3 | 4 | 5 | [dv8fromtheworld]: https://github.com/DV8FromTheWorld 6 | [jda]: https://github.com/DV8FromTheWorld/JDA 7 | 8 | 9 | [benmanes]: https://github.com/ben-manes 10 | [caffeine]: https://github.com/ben-manes/Caffeine 11 | 12 | 13 | [codemc]: https://github.com/codemc 14 | 15 | 16 | [davidrockin]: https://github.com/DavidRockin 17 | [david_comment]: https://github.com/botblock/JavaBotBlockAPI/pull/3#issuecomment-522036554 18 | 19 | 20 | [dependabot]: https://github.com/Dependabot 21 | 22 | 23 | [ghostchu]: https://github.com/ghost-chu 24 | [ghostchu_commits]: https://github.com/botblock/JavaBotBlockAPI/commits?author=ghost-chu 25 | 26 | 27 | [javacord]: https://github.com/javacord 28 | [javacord-lib]: https://github.com/javacord/Javacord 29 | 30 | 31 | [stleary]: https://github.com/stleary 32 | [json-java]: https://github.com/stleary/JSON-java 33 | 34 | 35 | [square]: https://github.com/square 36 | [okhttp]: https://github.com/square/OkHttp 37 | 38 | # Contributors 39 | We aknowledge all contributions made to the project, be it Pull requests or even something simple like feedback and/or suggestions. 40 | 41 | To thank every contributor did we adobt the [All Contributors][all-contributors] system and adjusted it slightly. 42 | This page lists every user/organisation who contributed to the project in some way. Please see the [Categories](#categories) below for an explanation about the different Emojis and their meaning. 43 | 44 | ## Categories 45 | This file follows a similar system like the All Contributors [Emoji Key System][emojis]. 46 | Each Category has their own emoji which is listed here. 47 | 48 | ### 💻 Code 49 | Contributed code towards the project. 50 | This can be through Pull requests or, if having the rights for, through direct commits. 51 | 52 | Will have a link to all commits made by this User/Bot/Organisation. 53 | 54 | ### 🤔 Feedback/Ideas 55 | Gave Ideas and or general feedback to improve the project. 56 | Will have links to all issues, Pull requests, Discussions and general comments the User/Organisation made. 57 | 58 | ### 🚇 Infrastructure 59 | Provides a place to host the project, jar files, documentation or similar. 60 | A common example would be a CI (Jenkins) Server. 61 | 62 | ### 🚧 Maintenance 63 | Helps keeping the project running through actions such as keeping dependencies up to date. 64 | 65 | ### 🔌 Plugin(s) 66 | Provides one or multiple dependencies used by the project. 67 | A link to the Project(s) will be provided. 68 | 69 | ## Contributors 70 | Here is a list of all the Contributors to our project and how they contributed to this project. 71 | 72 | ### [Austin Keener][dv8fromtheworld] 73 | 74 | > Contributions: [🔌](#-plugins "Plugin(s)") ([JDA]) 75 | 76 | ---- 77 | ### [Ben Manes][benmanes] 78 | 79 | > Contribution: [🔌](#-plugins "Plugin(s)") ([Caffeine]) 80 | 81 | ---- 82 | ### [CodeMC][codemc] 83 | 84 | > Contributions: [🚇](#-infrastructure "Infrastructure") 85 | 86 | ---- 87 | ### [Dave][davidrockin] 88 | 89 | > Contributions: [🤔](#-feedbackideas "Feedback/Ideas") ([#3 (Comment)][david_comment]) 90 | 91 | ---- 92 | ### [Dependabot] 93 | 94 | > Contributions: [🚧](#-maintenance "Maintenance") 95 | 96 | ---- 97 | ### [Ghost_chu][ghostchu] 98 | 99 | > Contributions: [💻](#-code "Code") ([Commits][ghostchu_commits]) 100 | 101 | ---- 102 | ### [Javacord] 103 | 104 | > Contribution: [🔌](#-plugins "Plugin(s)") ([Javacord][javacord-lib]) 105 | 106 | ---- 107 | ### [Sean Leary][stleary] 108 | 109 | > Contribution: [🔌](#-plugins "Plugin(s)") ([JSON-java][json-java]) 110 | 111 | ---- 112 | ### [Square][square] 113 | 114 | > Contribution: [🔌](#-plugins "Plugin(s)") ([OkHttp]) 115 | -------------------------------------------------------------------------------- /core/build.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * This module surprisingly enough doesn't have any dependencies whe have to implement, so this build.gradle is empty... 3 | */ 4 | 5 | javadoc{ 6 | exclude "org/botblock/javabotblockAPI/core/CheckUtil.java" 7 | } -------------------------------------------------------------------------------- /core/src/main/java/org/botblock/javabotblockapi/core/BotBlockAPI.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 javax.annotation.Nonnull; 22 | import java.util.HashMap; 23 | import java.util.Map; 24 | 25 | /** 26 | * Class used to define the auth-tokens used for the different sites. 27 | * 28 | *

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 tokens; 37 | private final int updateDelay; 38 | 39 | private BotBlockAPI(@Nonnull Map tokens, int updateDelay){ 40 | CheckUtil.notEmpty(tokens, "Tokens"); 41 | CheckUtil.condition(updateDelay < 2, "UpdateDelay may not be less than 2"); 42 | 43 | this.tokens = tokens; 44 | this.updateDelay = updateDelay; 45 | } 46 | 47 | public Map getTokens(){ 48 | return tokens; 49 | } 50 | 51 | public int getUpdateDelay(){ 52 | return updateDelay; 53 | } 54 | 55 | /** 56 | * Builder class to create an instance of {@link org.botblock.javabotblockapi.core.BotBlockAPI BotBlockAPI} 57 | */ 58 | public static class Builder{ 59 | private Map tokens = new HashMap<>(); 60 | private int updateDelay = DEFAULT_DELAY; 61 | 62 | /** 63 | * Empty constructor to get the class. 64 | */ 65 | public Builder(){} 66 | 67 | /** 68 | * Adds the provided {@link org.botblock.javabotblockapi.core.Site Site name} and token to the Map. 69 | *
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 | *

Following Exceptions can be thrown from the CheckUtil: 78 | *

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 | *

Following Exceptions can be thrown from the CheckUtil: 111 | *

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 | *

Following Exceptions can be thrown from the CheckUtil: 137 | *

140 | * 141 | * @return The Builder after the Map was set. Useful for chaining. 142 | */ 143 | public Builder setAuthTokens(@Nonnull Map tokens){ 144 | CheckUtil.notEmpty(tokens, "Tokens"); 145 | 146 | this.tokens = tokens; 147 | return this; 148 | } 149 | 150 | /** 151 | * Sets the update delay (in minutes) for the auto-posting. 152 | *
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 | *

Following Exceptions can be thrown from the CheckUtil: 158 | *

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 | *

Following Exceptions can be thrown from the CheckUtil: 175 | *

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 | *

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 | *

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 | *

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 | *
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 | *

Supported methods: 55 | *

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 | *

Supported methods: 68 | *

72 | */ 73 | public static final Site BLIST_XYZ = new Site("blist.xyz", HttpMethod.GET, HttpMethod.POST); 74 | 75 | /** 76 | * boatspace.xyz 77 | * 78 | *

Supported methods: 79 | *

83 | */ 84 | public static final Site BOATSPACE_XYZ = new Site("boatspace.xyz", HttpMethod.GET, HttpMethod.POST); 85 | 86 | /** 87 | * botlist.me 88 | * 89 | *

Supported methods: 90 | *

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 | *

Supported methods: 103 | *

107 | */ 108 | public static final Site BOTS_DISCORDLABS_ORG = new Site("discordlabs.org", HttpMethod.GET, HttpMethod.POST); 109 | 110 | /** 111 | * botsfordiscord.com 112 | * 113 | *

Supported methods: 114 | *

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 | *

Supported methods: 130 | *

133 | */ 134 | public static final Site BOTS_ONDISCORD_XYZ = new Site("bots.ondiscord.xyz", HttpMethod.POST); 135 | 136 | /** 137 | * dblista.pl 138 | * 139 | *

Supported methods: 140 | *

143 | */ 144 | public static final Site DBLISTA_PL = new Site("dblista.pl", HttpMethod.GET); 145 | 146 | /** 147 | * discord.boats 148 | * 149 | *

Supported methods: 150 | *

154 | */ 155 | public static final Site DISCORD_BOATS = new Site("discord.boats", HttpMethod.GET, HttpMethod.POST); 156 | 157 | /** 158 | * discordbotlist.com 159 | * 160 | *

Supported methods: 161 | *

165 | */ 166 | public static final Site DISCORDBOTLIST_COM = new Site("discordbotlist.com", HttpMethod.GET, HttpMethod.POST); 167 | 168 | /** 169 | * discordbots.co 170 | * 171 | *

Supported methods: 172 | *

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 | *

Supported methods: 185 | *

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 | *

Supported methods: 196 | *

200 | */ 201 | public static final Site DISCORDEXTREMELIST_XYZ = new Site("discordextremelist.xyz", HttpMethod.GET, HttpMethod.POST); 202 | 203 | /** 204 | * discordlistology.com 205 | * 206 | *

Supported methods: 207 | *

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 | *

Supported methods: 218 | *

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 | *

Supported methods: 229 | *

233 | */ 234 | public static final Site DISCORDS_COM = new Site("discords.com", HttpMethod.GET, HttpMethod.POST); 235 | 236 | /** 237 | * discordservices.net 238 | * 239 | *

Supported methods: 240 | *

243 | */ 244 | public static final Site DISCORDSERVICES_NET = new Site("discordservices.net", HttpMethod.POST); 245 | 246 | /** 247 | * disforge.com 248 | * 249 | *

Supported methods: 250 | *

253 | */ 254 | public static final Site DISFORGE_COM = new Site("disforge.com", HttpMethod.POST); 255 | 256 | /** 257 | * fateslist.xyz 258 | * 259 | *

Supported methods: 260 | *

264 | */ 265 | public static final Site FATESLIST_XYZ = new Site("fateslist.xyz", HttpMethod.GET, HttpMethod.POST); 266 | 267 | /** 268 | * infinitybotlist.xyz 269 | * 270 | *

Supported methods: 271 | *

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 | *

Supported methods: 284 | *

288 | */ 289 | public static final Site LISTCORD_GG = new Site("listcord.gg", HttpMethod.GET, HttpMethod.POST); 290 | 291 | /** 292 | * motiondevelopment.top 293 | * 294 | *

Supported methods: 295 | *

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 | *

Supported methods: 308 | *

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 | *

Supported methods: 321 | *

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 | *

Supported methods: 334 | *

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 | *

Supported methods: 345 | *

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 | *

Supported methods: 357 | *

361 | */ 362 | public static final Site TOPCORD_XYZ = new Site("topcord.xyz", HttpMethod.GET, HttpMethod.POST); 363 | 364 | /** 365 | * vcodes.xyz 366 | * 367 | *

Supported methods: 368 | *

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 | *

Supported methods: 381 | *

385 | */ 386 | public static final Site VOIDBOTS_NET = new Site("voidbots.net", HttpMethod.GET, HttpMethod.POST); 387 | 388 | /** 389 | * wonderbotlist.com 390 | * 391 | *

Supported methods: 392 | *

396 | */ 397 | public static final Site WONDERBOTLIST_COM = new Site("wonderbotlist.com", HttpMethod.GET, HttpMethod.POST); 398 | 399 | /** 400 | * yabl.xyz 401 | * 402 | *

Supported methods: 403 | *

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 methods; 412 | 413 | private Site(String name, HttpMethod... methods){ 414 | this.name = name; 415 | this.methods = Arrays.asList(methods); 416 | } 417 | 418 | private Site(String name){ 419 | this.name = name; 420 | this.methods = new ArrayList<>(); 421 | } 422 | 423 | /** 424 | * The name used by the BotBlock API to identify the site. 425 | *
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 | *

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 | *
This is always paired with the {@link java.lang.Deprecated @Deprecated} annotation. 26 | * 27 | *

A replacement may be mentioned with the {@link #replacements() replacements String array} but is not guaranteed. 28 | *
Anything annotated with this should be avoided as it may be removed in a future release. 29 | * 30 | *

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 is paired with the {@link java.lang.Deprecated Deprecated} and 26 | * {@link org.botblock.javabotblockapi.core.annotations.DeprecatedSince DeprecatedSince} annotations. 27 | * 28 | *

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 | *
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 | *

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 | *
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=, botId=, ip=, route=}} 99 | */ 100 | @Override 101 | public String toString(){ 102 | return "RatelimitedException{" 103 | + "delay=" + delay + ", " 104 | + "botId=" + botId + ", " 105 | + "ip=" + ip + ", " 106 | + "route=" + route + ", " 107 | + "}"; 108 | } 109 | 110 | /** 111 | * Returns a message informing us about {@link #getRoute() where} we got rate limited, {@link #getDelay() for how long} and 112 | * on what {@link #getBotId() bot id} and {@link #getIp() ip}. 113 | * 114 | * @return String containing a message with route, delay, bot id and IP. 115 | */ 116 | @Override 117 | public String getMessage(){ 118 | return "Got rate limited on route " + route + " with bot id " + botId + " (ip: " + ip + "). Retry after: " + delay; 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /core/src/main/java/org/botblock/javabotblockapi/core/exceptions/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 | * Contains custom exceptions this API may throw. 21 | */ 22 | package org.botblock.javabotblockapi.core.exceptions; -------------------------------------------------------------------------------- /core/src/main/java/org/botblock/javabotblockapi/core/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 | * This is the core module used across all other modules. 21 | *
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 | *

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 |  * 
37 | * 38 | *

Maven

39 | * 40 | *
{@literal
41 |  * 
42 |  *     
43 |  *         codemc
44 |  *         CodeMC-Nexus
45 |  *         https://repo.codemc.io/repository/maven-public
46 |  *     
47 |  * 
48 |  *
49 |  * 
50 |  *     
51 |  *         org.botblock
52 |  *         javabotblockapi-core
53 |  *         API_VERSION
54 |  *     
55 |  * 
56 |  * }
57 | * 58 | *

Manual

59 | * We do not recommend using jar files directly and instead use one of the above dependency management systems. 60 | * 61 | *

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 | 37 | 38 | codemc 39 | https://repo.codemc.io/repository/maven-public/ 40 | 41 | 42 | 43 | 44 | 45 | 46 | org.botblock 47 | javabotblockapi-core 48 | {version} 49 | 50 | 51 | 52 | org.botblock 53 | javabotblockapi-request 54 | {version} 55 | 56 | 57 | 58 | org.botblock 59 | javabotblockapi-javacord 60 | {version} 61 | 62 | 63 | 64 | org.botblock 65 | javabotblockapi-jda 66 | {version} 67 | 68 | 69 | ``` 70 | 71 | ## Links 72 | 73 | - [BotBlock Documentation](https://botblock.org/docs) 74 | - [BotBlock Discord](https://botblock.org/discord) (**Do NOT ask BotBlock-Staff for help with this API Wrapper**) 75 | - [Andre's Support Discord](https://discord.gg/6dazXp6) (Ask in the `#javabotblockapi` channel) 76 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/botblock/JavaBotBlockAPI/5a21d3d14822c24aafbe4474f54f7061db4f4b14/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Mon Sep 30 17:27:13 CEST 2019 2 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.5-all.zip 3 | distributionBase=GRADLE_USER_HOME 4 | distributionPath=wrapper/dists 5 | zipStorePath=wrapper/dists 6 | zipStoreBase=GRADLE_USER_HOME 7 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS="" 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS= 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /javacord/build.gradle: -------------------------------------------------------------------------------- 1 | dependencies { 2 | api group: 'org.javacord', name: 'javacord', version: '3.3.0' 3 | implementation project(":core") 4 | implementation project(":request") 5 | } 6 | -------------------------------------------------------------------------------- /javacord/src/main/java/org/botblock/javabotblockapi/javacord/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.javacord; 20 | 21 | import org.botblock.javabotblockapi.core.BotBlockAPI; 22 | import org.botblock.javabotblockapi.core.CheckUtil; 23 | import org.botblock.javabotblockapi.core.Info; 24 | import org.botblock.javabotblockapi.core.exceptions.RateLimitedException; 25 | import org.botblock.javabotblockapi.requests.handler.RequestHandler; 26 | import org.javacord.api.DiscordApi; 27 | import org.json.JSONArray; 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.ArrayList; 36 | import java.util.Arrays; 37 | import java.util.Collection; 38 | import java.util.List; 39 | import java.util.concurrent.ScheduledExecutorService; 40 | import java.util.concurrent.TimeUnit; 41 | 42 | /** 43 | * Class used to perform POST requests towards the /api/count 44 | * endpoint of BotBlock using the Javacord Library. 45 | * 46 | *

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 | *
This will set the UserAgent used for POST request to {@code -/ (Javacord) DBots/} 60 | * using the provided {@link org.javacord.api.DiscordApi DiscordApi instance}. 61 | * 62 | * @param api 63 | * The {@link org.javacord.api.DiscordApi DiscordApi instance} used to set the UserAgent. 64 | */ 65 | public PostAction(DiscordApi api){ 66 | this.requestHandler = new RequestHandler(String.format( 67 | "%s-%s/%s (Javacord) DBots/%s", 68 | api.getYourself().getName(), 69 | api.getYourself().getDiscriminator(), 70 | Info.VERSION, 71 | api.getYourself().getId() 72 | )); 73 | this.scheduler = requestHandler.getScheduler(); 74 | } 75 | 76 | /** 77 | * Disables the automatic posting of Stats. 78 | *
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 | *

Note that using this method will NOT make the scheduler wait for previously scheduled tasks to complete. 82 | *
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 | *

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 | *
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 | *

This method may throw a {@link java.lang.InterruptedException InterruptedException} in the terminal. 125 | * 126 | *

Following Exceptions can be thrown from the CheckUtil: 127 | *

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 | *

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 | *

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 | *

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 | *

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 shards = new ArrayList<>(); 217 | for(DiscordApi api : discordApis) 218 | shards.add(api.getServers().size()); 219 | 220 | json.put("shards", new JSONArray(Arrays.deepToString(shards.toArray()))); 221 | }else{ 222 | json.put("server_count", discordApis[0].getServers().size()); 223 | } 224 | 225 | botBlockAPI.getTokens().forEach(json::put); 226 | 227 | requestHandler.performPOST(json, botBlockAPI.getTokens().size()); 228 | } 229 | } 230 | -------------------------------------------------------------------------------- /javacord/src/main/java/org/botblock/javabotblockapi/javacord/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 | * This is the Javacord module which is used to provide support for the Javacord Library. 21 | *
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 | *

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 |  * 
41 | * 42 | *

Maven

43 | * 44 | *
{@literal
45 |  * 
46 |  *     
47 |  *         codemc
48 |  *         CodeMC-Nexus
49 |  *         https://repo.codemc.io/repository/maven-public
50 |  *     
51 |  * 
52 |  *
53 |  * 
54 |  *     
55 |  *     
56 |  *         org.botblock
57 |  *         javabotblockapi-core
58 |  *         API_VERSION
59 |  *     
60 |  *     
61 |  *         org.botblock
62 |  *         javabotblockapi-request
63 |  *         API_VERSION
64 |  *     
65 |  *     
66 |  *     
67 |  *         org.botblock
68 |  *         javabotblockapi-javacord
69 |  *         API_VERSION
70 |  *     
71 |  * 
72 |  * }
73 | * 74 | *

Manual

75 | * We do not recommend using jar files directly and instead use one of the above dependency management systems. 76 | * 77 | *

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 | *
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 | *

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 | *
This will set the UserAgent used for POST requests to {@code -/ (JDA) DBots/} 63 | * using the provided {@link net.dv8tion.jda.api.sharding.ShardManager ShardManager instance}. 64 | * 65 | * @param shardManager 66 | * The {@link net.dv8tion.jda.api.sharding.ShardManager ShardManager instance} used to set the UserAgent. 67 | */ 68 | public PostAction(@Nonnull ShardManager shardManager){ 69 | this(Objects.requireNonNull(shardManager.getShardById(0))); 70 | } 71 | 72 | /** 73 | * Creates a new instance of this class. 74 | *
This will set the UserAgent used for POST requests to {@code -/ (JDA) DBots/} 75 | * using the provided {@link net.dv8tion.jda.api.JDA JDA instance}. 76 | * 77 | * @param jda 78 | * The {@link net.dv8tion.jda.api.JDA JDA instance} used to set the UserAgent. 79 | */ 80 | public PostAction(@Nonnull JDA jda){ 81 | this.requestHandler = new RequestHandler(String.format( 82 | "%s-%s/%s (JDA) DBots/%s", 83 | jda.getSelfUser().getName(), 84 | jda.getSelfUser().getDiscriminator(), 85 | Info.VERSION, 86 | jda.getSelfUser().getId() 87 | )); 88 | this.scheduler = requestHandler.getScheduler(); 89 | } 90 | 91 | /** 92 | * Disables the automatic posting of Stats. 93 | *
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 | *

Note that using this method will NOT make the scheduler wait for previously scheduled tasks to complete. 97 | *
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 | *

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 | *
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 | *

This method may throw a {@link java.lang.InterruptedException InterruptedException} in the terminal. 142 | * 143 | *

Following Exceptions can be thrown from the CheckUtil: 144 | *

    145 | *
  • {@link java.lang.IllegalStateException IllegalStateException} - When the provided time param is 0 or lower.
  • 146 | *
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 | *

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 | *

    260 | *
  • {@link java.lang.IllegalStateException IllegalStateException} - if the first shard of the provided ShardManager is null.
  • 261 | *
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 shards = new ArrayList<>(); 283 | for(JDA jda : shardManager.getShardCache()) 284 | shards.add(jda.getGuildCache().size()); 285 | 286 | json.put("shards", new JSONArray(Arrays.deepToString(shards.toArray()))); 287 | botBlockAPI.getTokens().forEach(json::put); 288 | 289 | requestHandler.performPOST(json, botBlockAPI.getTokens().size()); 290 | } 291 | } 292 | -------------------------------------------------------------------------------- /jda/src/main/java/org/botblock/javabotblockapi/jda/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 | /** 21 | * This is the JDA module which is used to provide support for the Java Discord API (JDA) Library. 22 | *
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 | *

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 |  * 
42 | * 43 | *

Maven

44 | * 45 | *
{@literal
46 |  * 
47 |  *     
48 |  *         codemc
49 |  *         CodeMC-Nexus
50 |  *         https://repo.codemc.io/repository/maven-public
51 |  *     
52 |  * 
53 |  *
54 |  * 
55 |  *     
56 |  *     
57 |  *         org.botblock
58 |  *         javabotblockapi-core
59 |  *         API_VERSION
60 |  *     
61 |  *     
62 |  *         org.botblock
63 |  *         javabotblockapi-request
64 |  *         API_VERSION
65 |  *     
66 |  *     
67 |  *     
68 |  *         org.botblock
69 |  *         javabotblockapi-jda
70 |  *         API_VERSION
71 |  *     
72 |  * 
73 |  * }
74 | * 75 | *

Manual

76 | * We do not recommend using jar files directly and instead use one of the above dependency management systems. 77 | * 78 | *

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 | *

    53 | *
  • Cache: {@code Enabled}
  • 54 | *
  • User-Agent: {@code "JavaBotBlockAPI-0000/API_VERSION (Unknown; +https://jbba.dev) DBots/{id}"}
  • 55 | *
56 | * 57 | *

Following Exceptions can be thrown from the CheckUtil: 58 | *

    59 | *
  • {@link java.lang.NullPointerException NullPointerException} - When the provided id is empty.
  • 60 | *
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 | *

Using this constructor will set the following default values ({@code {id}} will be replaced with the provided ID): 74 | *

    75 | *
  • User-Agent: {@code "JavaBotBlockAPI-0000/API_VERSION (Unknown; +https://jbba.dev) DBots/{id}"}
  • 76 | *
77 | * 78 | *

Following Exceptions can be thrown from the CheckUtil: 79 | *

    80 | *
  • {@link java.lang.NullPointerException NullPointerException} - When the provided id is empty.
  • 81 | *
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 | *

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 | *

    105 | *
  • {@link java.lang.NullPointerException NullPointerException} - When the provided userAgent or id is empty.
  • 106 | *
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 | *

Following Exceptions can be thrown from the HTTP request: 131 | *

    132 | *
  • {@link java.io.IOException IOException} - When the request was non-successful.
  • 133 | *
  • {@link org.botblock.javabotblockapi.core.exceptions.RateLimitedException RatelimitedException} - When the request got rate limited.
  • 134 | *
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 | *

Following Exceptions can be thrown from the CheckUtil: 153 | *

    154 | *
  • {@link java.lang.NullPointerException NullPointerException} - When the provided id is empty.
  • 155 | *
156 | * 157 | *

Following Exceptions can be thrown from the HTTP request: 158 | *

    159 | *
  • {@link java.io.IOException IOException} - When the request was non-successful.
  • 160 | *
  • {@link org.botblock.javabotblockapi.core.exceptions.RateLimitedException RatelimitedException} - When the request got rate limited.
  • 161 | *
162 | * 163 | *

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 | *
The returned data is entirely dependant on the bot list itself and is therefore unique. 180 | * 181 | *

Following Exceptions can be thrown from the HTTP request: 182 | *

    183 | *
  • {@link java.io.IOException IOException} - When the request was non-successful.
  • 184 | *
  • {@link org.botblock.javabotblockapi.core.exceptions.RateLimitedException RatelimitedException} - When the request got rate limited.
  • 185 | *
186 | * 187 | *

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 | *
The returned data is entirely dependant on the bot list itself and is therefore unique. 202 | * 203 | *

Following Exceptions can be thrown from the HTTP request: 204 | *

    205 | *
  • {@link java.io.IOException IOException} - When the request was non-successful.
  • 206 | *
  • {@link org.botblock.javabotblockapi.core.exceptions.RateLimitedException RatelimitedException} - When the request got rate limited.
  • 207 | *
208 | * 209 | * A {@link RateLimitedException RatelimitedException} may be thrown 210 | * from the RequestHandler, if the HTTP request was rate limited. 211 | * 212 | *

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 | *
The returned data is entirely dependant on the bot list itself and is therefore unique. 233 | * 234 | *

Following Exceptions can be thrown from the CheckUtil: 235 | *

    236 | *
  • {@link java.lang.IllegalStateException IllegalStateException} - When the provided Site does not support GET requests.
  • 237 | *
238 | * 239 | *

Following Exceptions can be thrown from the HTTP request: 240 | *

    241 | *
  • {@link java.io.IOException IOException} - When the request was non-successful.
  • 242 | *
  • {@link org.botblock.javabotblockapi.core.exceptions.RateLimitedException RatelimitedException} - When the request got rate limited.
  • 243 | *
244 | * 245 | *

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 | *
The returned data is entirely dependant on the bot list itself and is therefore unique. 264 | * 265 | *

Following Exceptions can be thrown from the CheckUtil: 266 | *

    267 | *
  • {@link java.lang.NullPointerException NullPointerException} - When the provided site is empty.
  • 268 | *
269 | * 270 | *

Following Exceptions can be thrown from the HTTP request: 271 | *

    272 | *
  • {@link java.io.IOException IOException} - When the request was non-successful.
  • 273 | *
  • {@link org.botblock.javabotblockapi.core.exceptions.RateLimitedException RatelimitedException} - When the request got rate limited.
  • 274 | *
275 | * 276 | *

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 | *
The returned data is entirely dependant on the bot list itself and is therefore unique. 295 | * 296 | *

Following Exceptions can be thrown from the CheckUtil: 297 | *

    298 | *
  • {@link java.lang.NullPointerException NullPointerException} - When the provided id is empty.
  • 299 | *
  • {@link java.lang.IllegalStateException IllegalStateException} - When the provided Site does not support GET requests.
  • 300 | *
301 | * 302 | *

Following Exceptions can be thrown from the HTTP request: 303 | *

    304 | *
  • {@link java.io.IOException IOException} - When the request was non-successful.
  • 305 | *
  • {@link org.botblock.javabotblockapi.core.exceptions.RateLimitedException RatelimitedException} - When the request got rate limited.
  • 306 | *
307 | * 308 | *

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 | *
The returned data is entirely dependant on the bot list itself and is therefore unique. 332 | * 333 | *

Following Exceptions can be thrown from the CheckUtil: 334 | *

    335 | *
  • {@link java.lang.NullPointerException NullPointerException} - When the provided id or site is empty.
  • 336 | *
337 | * 338 | *

Following Exceptions can be thrown from the HTTP request: 339 | *

    340 | *
  • {@link java.io.IOException IOException} - When the request was non-successful.
  • 341 | *
  • {@link org.botblock.javabotblockapi.core.exceptions.RateLimitedException RatelimitedException} - When the request got rate limited.
  • 342 | *
343 | * 344 | *

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 | *
The discriminator is based on the most common appearance of it across the bot lists. 368 | * 369 | *

Following Exceptions can be thrown from the HTTP request: 370 | *

    371 | *
  • {@link java.io.IOException IOException} - When the request was non-successful.
  • 372 | *
  • {@link org.botblock.javabotblockapi.core.exceptions.RateLimitedException RatelimitedException} - When the request got rate limited.
  • 373 | *
374 | * 375 | *

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 | *
The discriminator is based on the most common appearance of it. 392 | * 393 | *

Following Exceptions can be thrown from the CheckUtil: 394 | *

    395 | *
  • {@link java.lang.NullPointerException NullPointerException} - When the provided id is empty.
  • 396 | *
397 | * 398 | *

Following Exceptions can be thrown from the HTTP request: 399 | *

    400 | *
  • {@link java.io.IOException IOException} - When the request was non-successful.
  • 401 | *
  • {@link org.botblock.javabotblockapi.core.exceptions.RateLimitedException RatelimitedException} - When the request got rate limited.
  • 402 | *
403 | * 404 | *

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 | *
The GitHub link is based on the most common appearance of it. 427 | * 428 | *

Following Exceptions can be thrown from the HTTP request: 429 | *

    430 | *
  • {@link java.io.IOException IOException} - When the request was non-successful.
  • 431 | *
  • {@link org.botblock.javabotblockapi.core.exceptions.RateLimitedException RatelimitedException} - When the request got rate limited.
  • 432 | *
433 | * 434 | *

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 | *
The GitHub link is based on the most common appearance of it. 451 | * 452 | *

Following Exceptions can be thrown from the CheckUtil: 453 | *

    454 | *
  • {@link java.lang.NullPointerException NullPointerException} - When the provided id is empty.
  • 455 | *
456 | * 457 | *

Following Exceptions can be thrown from the HTTP request: 458 | *

    459 | *
  • {@link java.io.IOException IOException} - When the request was non-successful.
  • 460 | *
  • {@link org.botblock.javabotblockapi.core.exceptions.RateLimitedException RatelimitedException} - When the request got rate limited.
  • 461 | *
462 | * 463 | *

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 | *
The library is based on the most common appearance of it. 486 | * 487 | *

Following Exceptions can be thrown from the HTTP request: 488 | *

    489 | *
  • {@link java.io.IOException IOException} - When the request was non-successful.
  • 490 | *
  • {@link org.botblock.javabotblockapi.core.exceptions.RateLimitedException RatelimitedException} - When the request got rate limited.
  • 491 | *
492 | * 493 | *

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 | *
The library is based on the most common appearance of it. 510 | * 511 | *

Following Exceptions can be thrown from the CheckUtil: 512 | *

    513 | *
  • {@link java.lang.NullPointerException NullPointerException} - When the provided id is empty.
  • 514 | *
515 | * 516 | *

Following Exceptions can be thrown from the HTTP request: 517 | *

    518 | *
  • {@link java.io.IOException IOException} - When the request was non-successful.
  • 519 | *
  • {@link org.botblock.javabotblockapi.core.exceptions.RateLimitedException RatelimitedException} - When the request got rate limited.
  • 520 | *
521 | * 522 | *

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 | *
The name is based on the most common appearance of it. 545 | * 546 | *

Following Exceptions can be thrown from the HTTP request: 547 | *

    548 | *
  • {@link java.io.IOException IOException} - When the request was non-successful.
  • 549 | *
  • {@link org.botblock.javabotblockapi.core.exceptions.RateLimitedException RatelimitedException} - When the request got rate limited.
  • 550 | *
551 | * 552 | *

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 | *
The name is based on the most common appearance of it. 569 | * 570 | *

Following Exceptions can be thrown from the CheckUtil: 571 | *

    572 | *
  • {@link java.lang.NullPointerException NullPointerException} - When the provided id is empty.
  • 573 | *
574 | * 575 | *

Following Exceptions can be thrown from the HTTP request: 576 | *

    577 | *
  • {@link java.io.IOException IOException} - When the request was non-successful.
  • 578 | *
  • {@link org.botblock.javabotblockapi.core.exceptions.RateLimitedException RatelimitedException} - When the request got rate limited.
  • 579 | *
580 | * 581 | *

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 | *
The OAuth invite is used to add a bot to a Discord server. 604 | * 605 | *

Following Exceptions can be thrown from the HTTP request: 606 | *

    607 | *
  • {@link java.io.IOException IOException} - When the request was non-successful.
  • 608 | *
  • {@link org.botblock.javabotblockapi.core.exceptions.RateLimitedException RatelimitedException} - When the request got rate limited.
  • 609 | *
610 | * 611 | *

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 | *
The OAuth invite is used to add a bot to a Discord server. 628 | * 629 | *

Following Exceptions can be thrown from the CheckUtil: 630 | *

    631 | *
  • {@link java.lang.NullPointerException NullPointerException} - When the provided id is empty.
  • 632 | *
633 | * 634 | *

Following Exceptions can be thrown from the HTTP request: 635 | *

    636 | *
  • {@link java.io.IOException IOException} - When the request was non-successful.
  • 637 | *
  • {@link org.botblock.javabotblockapi.core.exceptions.RateLimitedException RatelimitedException} - When the request got rate limited.
  • 638 | *
639 | * 640 | *

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 | *
The IDs listed are based on how often they appear on the different bot lists. 663 | * 664 | *

Following Exceptions can be thrown from the HTTP request: 665 | *

    666 | *
  • {@link java.io.IOException IOException} - When the request was non-successful.
  • 667 | *
  • {@link org.botblock.javabotblockapi.core.exceptions.RateLimitedException RatelimitedException} - When the request got rate limited.
  • 668 | *
669 | * 670 | *

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 getOwners(@Nonnull Long id){ 679 | return getOwners(String.valueOf(id)); 680 | } 681 | 682 | /** 683 | * Gets an ArrayList with the owner ids of the bot. 684 | *
The IDs listed are based on how often they appear on the different bot lists. 685 | * 686 | *

Following Exceptions can be thrown from the CheckUtil: 687 | *

    688 | *
  • {@link java.lang.NullPointerException NullPointerException} - When the provided id is empty.
  • 689 | *
690 | * 691 | *

Following Exceptions can be thrown from the HTTP request: 692 | *

    693 | *
  • {@link java.io.IOException IOException} - When the request was non-successful.
  • 694 | *
  • {@link org.botblock.javabotblockapi.core.exceptions.RateLimitedException RatelimitedException} - When the request got rate limited.
  • 695 | *
696 | * 697 | *

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 getOwners(@Nonnull String id){ 706 | CheckUtil.notEmpty(id, "id"); 707 | 708 | JSONObject json = getBotInfo(id); 709 | if(json == null) 710 | return new ArrayList<>(); 711 | 712 | List owners = new ArrayList<>(); 713 | for(int i = 0; i < json.getJSONArray("owners").length(); i++) 714 | owners.add(json.getJSONArray("owners").getString(i)); 715 | 716 | return owners; 717 | } 718 | 719 | /** 720 | * Gets the prefix of the bot. 721 | *
The prefix is based on the most common appearance of it. 722 | * 723 | *

Following Exceptions can be thrown from the HTTP request: 724 | *

    725 | *
  • {@link java.io.IOException IOException} - When the request was non-successful.
  • 726 | *
  • {@link org.botblock.javabotblockapi.core.exceptions.RateLimitedException RatelimitedException} - When the request got rate limited.
  • 727 | *
728 | * 729 | *

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 | *
The prefix is based on the most common appearance of it. 746 | * 747 | *

Following Exceptions can be thrown from the CheckUtil: 748 | *

    749 | *
  • {@link java.lang.NullPointerException NullPointerException} - When the provided id is empty.
  • 750 | *
751 | * 752 | *

Following Exceptions can be thrown from the HTTP request: 753 | *

    754 | *
  • {@link java.io.IOException IOException} - When the request was non-successful.
  • 755 | *
  • {@link org.botblock.javabotblockapi.core.exceptions.RateLimitedException RatelimitedException} - When the request got rate limited.
  • 756 | *
757 | * 758 | *

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 | *
The server count is based on the most common appearance of it. 781 | * 782 | *

Following Exceptions can be thrown from the HTTP request: 783 | *

    784 | *
  • {@link java.io.IOException IOException} - When the request was non-successful.
  • 785 | *
  • {@link org.botblock.javabotblockapi.core.exceptions.RateLimitedException RatelimitedException} - When the request got rate limited.
  • 786 | *
787 | * 788 | *

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 | *
The server count is based on the most common appearance of it. 803 | * 804 | *

Following Exceptions can be thrown from the CheckUtil: 805 | *

    806 | *
  • {@link java.lang.NullPointerException NullPointerException} - When the provided id is empty.
  • 807 | *
808 | * 809 | *

Following Exceptions can be thrown from the HTTP request: 810 | *

    811 | *
  • {@link java.io.IOException IOException} - When the request was non-successful.
  • 812 | *
  • {@link org.botblock.javabotblockapi.core.exceptions.RateLimitedException RatelimitedException} - When the request got rate limited.
  • 813 | *
814 | * 815 | *

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 | *
The link is based on the most common appearance of it. 836 | * 837 | *

Following Exceptions can be thrown from the HTTP request: 838 | *

    839 | *
  • {@link java.io.IOException IOException} - When the request was non-successful.
  • 840 | *
  • {@link org.botblock.javabotblockapi.core.exceptions.RateLimitedException RatelimitedException} - When the request got rate limited.
  • 841 | *
842 | * 843 | *

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 | *
The link is based on the most common appearance of it. 858 | * 859 | *

Following Exceptions can be thrown from the CheckUtil: 860 | *

    861 | *
  • {@link java.lang.NullPointerException NullPointerException} - When the provided id is empty.
  • 862 | *
863 | * 864 | *

Following Exceptions can be thrown from the HTTP request: 865 | *

    866 | *
  • {@link java.io.IOException IOException} - When the request was non-successful.
  • 867 | *
  • {@link org.botblock.javabotblockapi.core.exceptions.RateLimitedException RatelimitedException} - When the request got rate limited.
  • 868 | *
869 | * 870 | *

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 | *
The website is based on the most common appearance of it. 891 | * 892 | *

Following Exceptions can be thrown from the HTTP request: 893 | *

    894 | *
  • {@link java.io.IOException IOException} - When the request was non-successful.
  • 895 | *
  • {@link org.botblock.javabotblockapi.core.exceptions.RateLimitedException RatelimitedException} - When the request got rate limited.
  • 896 | *
897 | * 898 | *

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 | *
The website is based on the most common appearance of it. 915 | * 916 | *

Following Exceptions can be thrown from the CheckUtil: 917 | *

    918 | *
  • {@link java.lang.NullPointerException NullPointerException} - When the provided id is empty.
  • 919 | *
920 | * 921 | *

Following Exceptions can be thrown from the HTTP request: 922 | *

    923 | *
  • {@link java.io.IOException IOException} - When the request was non-successful.
  • 924 | *
  • {@link org.botblock.javabotblockapi.core.exceptions.RateLimitedException RatelimitedException} - When the request got rate limited.
  • 925 | *
926 | * 927 | *

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 | *

    55 | *
  • User-Agent: {@code "JavaBotBlockAPI-0000/API_VERSION (Unknown; +https://jbba.dev) DBots/{id}"}
  • 56 | *
57 | * 58 | *

Following Exceptions can be thrown from the CheckUtil: 59 | *

    60 | *
  • {@link java.lang.NullPointerException NullPointerException} - When the provided ID is empty.
  • 61 | *
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 | *

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 | *

    81 | *
  • {@link java.lang.NullPointerException NullPointerException} - When the provided ID or User Agent are empty.
  • 82 | *
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 | *

Note that using this method will NOT make the scheduler wait for previously scheduled tasks to complete. 103 | *
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 | *

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 | *
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 | *

This method may throw a {@link java.lang.InterruptedException InterruptedException} in the terminal. 145 | * 146 | *

Following Exceptions can be thrown from the CheckUtil: 147 | *

    148 | *
  • {@link java.lang.IllegalStateException IllegalStateException} - When the provided time param is 0 or lower.
  • 149 | *
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 | *

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 may be canceled by this. 177 | * 178 | *

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 may be canceled by this. 206 | * 207 | *

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 | *

    252 | *
  • {@link java.lang.NullPointerException NullPointerException} - When the provided id is empty.
  • 253 | *
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 botCache = Caffeine.newBuilder() 49 | .expireAfterWrite(2, TimeUnit.MINUTES) 50 | .build(); 51 | private final Cache listCache = Caffeine.newBuilder() 52 | .expireAfterWrite(2, TimeUnit.MINUTES) 53 | .build(); 54 | 55 | public RequestHandler(String userAgent){ 56 | this.userAgent = userAgent; 57 | } 58 | 59 | public JSONObject performGetBot(@Nonnull String id, boolean disableCache){ 60 | String url = BASE_URL + "bots/" + id; 61 | 62 | if(!disableCache) 63 | return botCache.get(id, k -> { 64 | try{ 65 | return performGET(url, userAgent); 66 | }catch(IOException | RateLimitedException ex){ 67 | LOG.error("Exception while performing a GET request. Type: Get Bot, Cache: Enabled", ex); 68 | return null; 69 | } 70 | }); 71 | 72 | try{ 73 | return performGET(url, userAgent); 74 | }catch(IOException ex){ 75 | LOG.error("Exception while performing a GET request. Type: Get Bot, Cache: Disabled", ex); 76 | return null; 77 | } 78 | } 79 | 80 | public JSONObject performGetList(@Nonnull String id, boolean disableCache, boolean filtered){ 81 | return performGetList(id, null, disableCache, filtered); 82 | } 83 | 84 | public JSONObject performGetList(@Nonnull String id, @Nullable String site, boolean disableCache){ 85 | return performGetList(id, site, disableCache, false); 86 | } 87 | 88 | public JSONObject performGetList(@Nonnull String id, @Nullable String site, boolean disableCache, boolean filtered){ 89 | String url = BASE_URL + "lists" + (site == null ? "" : "/" + site); 90 | if(filtered) 91 | url += "?filter=true"; 92 | 93 | if(!disableCache){ 94 | String finalUrl = url; 95 | return listCache.get(id, k -> { 96 | try{ 97 | return performGET(finalUrl, userAgent); 98 | }catch(IOException ex){ 99 | LOG.error("IOException while performing a GET request. Type: Get list, Cache: Enabled", ex); 100 | return null; 101 | } 102 | }); 103 | } 104 | 105 | try{ 106 | return performGET(url, userAgent); 107 | }catch(IOException ex){ 108 | LOG.error("IOException while performing a GET request. Type: Get list, Cache: Disabled", ex); 109 | return null; 110 | } 111 | 112 | } 113 | 114 | public void performPOST(@Nonnull JSONObject json, int sites) throws IOException{ 115 | CheckUtil.condition(sites < 1, "The POST action requires at least 1 site!"); 116 | 117 | String url = BASE_URL + "count"; 118 | final long timeout = sites * 10L; 119 | 120 | OkHttpClient postClient = CLIENT.newBuilder() 121 | .callTimeout(timeout, TimeUnit.SECONDS) 122 | .readTimeout(timeout, TimeUnit.SECONDS) 123 | .writeTimeout(timeout, TimeUnit.SECONDS) 124 | .build(); 125 | 126 | RequestBody body = RequestBody.create(json.toString(), null); 127 | Request request = new Request.Builder() 128 | .url(url) 129 | .addHeader("Content-Type", "application/json") 130 | .addHeader("User-Agent", userAgent) 131 | .post(body) 132 | .build(); 133 | 134 | try(Response response = postClient.newCall(request).execute()){ 135 | ResponseBody responseBody = response.body(); 136 | if(responseBody == null){ 137 | LOG.error("Received empty Response from BotBlock API!"); 138 | LOG.error( 139 | "Response{timestamp={}, protocol={}, code={}, message={}, headers={}}", 140 | System.currentTimeMillis(), 141 | response.protocol(), 142 | response.code(), 143 | response.message(), 144 | response.headers() 145 | ); 146 | return; 147 | } 148 | 149 | String bodyString = responseBody.string(); 150 | if(bodyString.isEmpty()){ 151 | LOG.error("Received empty Response from BotBlock API!"); 152 | LOG.error( 153 | "Response{timestamp={}, protocol={}, code={}, message={}, headers={}}", 154 | System.currentTimeMillis(), 155 | response.protocol(), 156 | response.code(), 157 | response.message(), 158 | response.headers() 159 | ); 160 | return; 161 | } 162 | 163 | if(!response.isSuccessful()){ 164 | if(response.code() == 429){ 165 | JSONObject errorJson = new JSONObject(bodyString); 166 | throw new RateLimitedException(errorJson); 167 | } 168 | 169 | throw new IOException(String.format( 170 | "Could not post Guild count. The API responded with error code %d (%s)", 171 | response.code(), 172 | response.message() 173 | )); 174 | } 175 | 176 | JSONObject responseJson = new JSONObject(bodyString); 177 | if(!responseJson.getJSONObject("failure").isEmpty()){ 178 | JSONObject failure = responseJson.getJSONObject("failure"); 179 | JSONArray failures = new JSONArray(); 180 | 181 | for(String key : failure.keySet()){ 182 | try{ 183 | JSONArray array = failure.getJSONArray(key); 184 | failures.put(getJson(key, array)); 185 | }catch(JSONException ex){ 186 | failures.put(getJson(key, null)); 187 | } 188 | } 189 | 190 | LOG.warn("One or more POST requests returned a non-successful response. JSON with failed sites below."); 191 | LOG.warn(failures.toString()); 192 | } 193 | } 194 | } 195 | 196 | public ScheduledExecutorService getScheduler(){ 197 | return scheduler; 198 | } 199 | 200 | private JSONObject performGET(@Nonnull String url, String header) throws IOException{ 201 | Request request = new Request.Builder() 202 | .url(url) 203 | .addHeader("User-Agent", header) 204 | .build(); 205 | 206 | try(Response response = CLIENT.newCall(request).execute()){ 207 | ResponseBody body = response.body(); 208 | if(body == null){ 209 | LOG.error("Received empty Response from BotBlock API!"); 210 | LOG.error( 211 | "Response{timestamp={}, protocol={}, code={}, message={}, headers={}}", 212 | System.currentTimeMillis(), 213 | response.protocol(), 214 | response.code(), 215 | response.message(), 216 | response.headers() 217 | ); 218 | return null; 219 | } 220 | 221 | String bodyString = body.string(); 222 | if(bodyString.isEmpty()){ 223 | LOG.error("Received empty Response from BotBlock API!"); 224 | LOG.error( 225 | "Response{timestamp={}, protocol={}, code={}, message={}, headers={}}", 226 | System.currentTimeMillis(), 227 | response.protocol(), 228 | response.code(), 229 | response.message(), 230 | response.headers() 231 | ); 232 | return null; 233 | } 234 | 235 | if(!response.isSuccessful()){ 236 | if(response.code() == 429){ 237 | JSONObject errorJson = new JSONObject(bodyString); 238 | throw new RateLimitedException(errorJson); 239 | } 240 | 241 | throw new IOException(String.format( 242 | "Could not retrieve information. The API responded with error code %d (%s).", 243 | response.code(), 244 | response.message() 245 | )); 246 | } 247 | 248 | return new JSONObject(bodyString); 249 | } 250 | } 251 | 252 | JSONObject getJson(String key, JSONArray array){ 253 | JSONObject json = new JSONObject() 254 | .put("code", array == null ? "?" : array.get(0)) 255 | .put("message", array == null ? "?" : array.get(1)); 256 | 257 | return new JSONObject().put(key, json); 258 | } 259 | } 260 | -------------------------------------------------------------------------------- /request/src/main/java/org/botblock/javabotblockapi/requests/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 | * This is the Request module which is used to provide support for POST and GET requests to/from the BotBlock API. 21 | *
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 | *

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 |  * 
38 | * 39 | *

Maven

40 | * 41 | *
{@literal
42 |  * 
43 |  *     
44 |  *         codemc
45 |  *         CodeMC-Nexus
46 |  *         https://repo.codemc.io/repository/maven-public
47 |  *     
48 |  * 
49 |  *
50 |  * 
51 |  *     
52 |  *         org.botblock
53 |  *         javabotblockapi-core
54 |  *         API_VERSION
55 |  *     
56 |  *     
57 |  *         org.botblock
58 |  *         javabotblockapi-request
59 |  *         API_VERSION
60 |  *     
61 |  * 
62 |  * }
63 | * 64 | *

Manual

65 | * We do not recommend using jar files directly and instead use one of the above dependency management systems. 66 | * 67 | *

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 | --------------------------------------------------------------------------------