├── .gitignore ├── LICENSE ├── README.md ├── pom.xml └── src └── main └── java └── fr └── blueberry └── studio └── hermes └── api ├── app ├── Hermes.java ├── HermesConfig.java ├── Logger.java └── Sender.java ├── audio └── AudioPriority.java ├── bots ├── Bot.java ├── BotAudioController.java ├── BotManager.java └── JDAListenerManager.java ├── commands ├── Command.java ├── CommandRegistry.java └── ICommand.java ├── data └── sql │ ├── DatabaseCredentials.java │ ├── DatabaseManager.java │ └── QueryHandler.java ├── jobs └── Job.java ├── permissions └── PermissionManager.java ├── plugins ├── EventPriority.java ├── ExecutableListener.java ├── HermesListen.java ├── Listener.java ├── Plugin.java ├── PluginBase.java ├── PluginManager.java ├── PluginMeta.java └── events │ ├── BeforeCommandEvent.java │ ├── BotCreateEvent.java │ ├── BotDeleteEvent.java │ ├── BotEvent.java │ ├── BotReadyEvent.java │ ├── BotStartEvent.java │ ├── BotStopEvent.java │ ├── BotTriggererDefinedEvent.java │ ├── Event.java │ ├── HermesEvent.java │ ├── HermesNoTriggererEvent.java │ └── HermesReadyEvent.java └── utils ├── AnnotationHelper.java ├── ColorHelper.java ├── CommandHelper.java ├── FileHelper.java ├── MessageEmbedHelper.java ├── PermissionHelper.java ├── RandomHelper.java ├── ReflectionHelper.java ├── StringHelper.java └── VoiceHelper.java /.gitignore: -------------------------------------------------------------------------------- 1 | .classpath 2 | .project 3 | .vscode/ 4 | .settings/ 5 | .factorypath 6 | target/ 7 | docker/ 8 | docker* 9 | .dockerignore 10 | Dockerfile 11 | pom.xml.tag 12 | pom.xml.releaseBackup 13 | pom.xml.versionsBackup 14 | pom.xml.next 15 | release.properties 16 | dependency-reduced-pom.xml 17 | buildNumber.properties 18 | .mvn/timing.properties 19 | .mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Hermes API 2 | 3 | Hermes API is a programming interface to allow developers to write some plugins for Hermes Discord bots. 4 | 5 | ## Installation 6 | 7 | [![Maven Central](https://img.shields.io/maven-central/v/fr.blueberry-studio.hermes/hermes-api.svg?label=Maven%20Central)](https://search.maven.org/search?q=g:%22fr.blueberry-studio.hermes%22%20AND%20a:%22hermes-api%22) 8 | 9 | **You need Java Environment 15 to compile your plugin.** 10 | 11 | ### Maven 12 | 13 | ```xml 14 | 15 | fr.blueberry-studio.hermes 16 | hermes-api 17 | 0.10.1-ALPHA 18 | provided 19 | 20 | ``` 21 | 22 | ## Usage 23 | 24 | Create a Java project in your favorite IDE. We recommand you to setup your project with Maven for facilities. 25 | 26 | ### Adding plugin.yml 27 | 28 | Add a file named `plugin.yml` at the top root of your project or in the resources folder if you are using Maven, and fill it with your plugin informations. 29 | 30 | ```yml 31 | name: 32 | main: . 33 | version: 34 | author: 35 | description: 36 | ``` 37 | 38 | ### Creating your plugin main class 39 | 40 | Create a Java Class and extends it with Plugin class from the API package. 41 | By example : 42 | 43 | ```java 44 | import fr.blueberry.studio.hermes.api.plugins.Plugin; 45 | 46 | public class MyPlugin extends Plugin { 47 | } 48 | ``` 49 | 50 | ### Start coding ! 51 | 52 | Once your main is created, you've several methods to get started. 53 | 54 | ```java 55 | import fr.blueberry.studio.hermes.api.plugins.Plugin; 56 | 57 | public class MyPlugin extends Plugin { 58 | 59 | //When the plugin is loaded by Hermes 60 | public void onLoad() {} 61 | 62 | //When the plugin is enabled by Hermes 63 | public void onEnable() {} 64 | 65 | //When the plugin is disabled by Hermes 66 | public void onDisable() {} 67 | 68 | //When Hermes has no connected bots to serve your events and commands. 69 | public void onNoTriggerer() {} 70 | 71 | //When all the others plugins are enabled and everything is working fine. Usefull to hook into others plugins. 72 | public void onPostStart() {} 73 | } 74 | ``` 75 | 76 | ### Documentation 77 | 78 | The documentation is in progress. You can find all the documented methods in the javadoc of the project. 79 | 80 | 81 | ## Contributing 82 | Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change. 83 | 84 | Please make sure to update tests as appropriate. 85 | 86 | ## License 87 | [GPL-3.0](https://choosealicense.com/licenses/gpl-3.0) 88 | 89 | ## Thank you ! 90 | 91 | Massive thank you to everyone using Hermes ! Happy coding ! -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4.0.0 4 | 5 | fr.blueberry-studio.hermes 6 | hermes-api 7 | 0.10.1-ALPHA 8 | jar 9 | 10 | hermes-api 11 | https://gitlab.com/blueberry-studio/hermes/hermes-api 12 | API to program Hermes bot plugins for Discord. 13 | 14 | 15 | UTF-8 16 | 15 17 | 15 18 | 15 19 | 20 | 21 | 22 | 23 | GPLv3 24 | https://www.gnu.org/licenses/gpl-3.0.txt 25 | 26 | 27 | 28 | 29 | 30 | Mickaël Dhainaut 31 | hello@grimille.fr 32 | Blueberry-Studio 33 | https://www.blueberry-studio.fr 34 | 35 | 36 | 37 | 38 | scm:git:git://gitlab.com/blueberry-studio/hermes/hermes-api.git 39 | scm:git:ssh://gitlab.com/blueberry-studio/hermes/hermes-api.git 40 | https://gitlab.com/blueberry-studio/hermes/hermes-api 41 | 42 | 43 | 44 | 45 | jcenter 46 | jcenter-bintray 47 | https://jcenter.bintray.com 48 | 49 | 50 | jitpack.io 51 | https://jitpack.io 52 | 53 | 54 | 55 | 56 | 57 | 58 | net.dv8tion 59 | JDA 60 | 4.2.0_231 61 | 62 | 63 | 64 | com.sedmelluq 65 | lavaplayer 66 | 1.3.73 67 | 68 | 69 | 70 | com.google.code.gson 71 | gson 72 | 2.8.6 73 | 74 | 75 | 76 | com.github.Carleslc 77 | Simple-YAML 78 | 1.2 79 | 80 | 81 | 82 | commons-io 83 | commons-io 84 | 2.7 85 | 86 | 87 | 88 | com.zaxxer 89 | HikariCP 90 | 3.4.5 91 | 92 | 93 | 94 | com.kcthota 95 | emoji4j 96 | 6.0 97 | 98 | 99 | 100 | org.mariadb.jdbc 101 | mariadb-java-client 102 | 2.6.2 103 | 104 | 105 | 106 | 107 | 108 | ossrh 109 | https://oss.sonatype.org/content/repositories/snapshots 110 | 111 | 112 | ossrh 113 | https://oss.sonatype.org/service/local/staging/deploy/maven2/ 114 | 115 | 116 | 117 | 118 | 119 | 120 | maven-compiler-plugin 121 | 3.8.1 122 | 123 | 124 | 125 | org.sonatype.plugins 126 | nexus-staging-maven-plugin 127 | 1.6.7 128 | true 129 | 130 | ossrh 131 | https://oss.sonatype.org/ 132 | true 133 | 134 | 135 | 136 | 137 | org.apache.maven.plugins 138 | maven-source-plugin 139 | 2.2.1 140 | 141 | 142 | attach-sources 143 | 144 | jar-no-fork 145 | 146 | 147 | 148 | 149 | 150 | org.apache.maven.plugins 151 | maven-javadoc-plugin 152 | 3.2.0 153 | 154 | 155 | attach-javadocs 156 | 157 | jar 158 | 159 | 160 | none 161 | 162 | 163 | 164 | 165 | 166 | org.apache.maven.plugins 167 | maven-gpg-plugin 168 | 1.5 169 | 170 | 171 | sign-artifacts 172 | verify 173 | 174 | sign 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | -------------------------------------------------------------------------------- /src/main/java/fr/blueberry/studio/hermes/api/app/Hermes.java: -------------------------------------------------------------------------------- 1 | package fr.blueberry.studio.hermes.api.app; 2 | 3 | import com.sedmelluq.discord.lavaplayer.player.AudioPlayerManager; 4 | 5 | import fr.blueberry.studio.hermes.api.bots.BotManager; 6 | import fr.blueberry.studio.hermes.api.commands.CommandRegistry; 7 | import fr.blueberry.studio.hermes.api.data.sql.DatabaseManager; 8 | import fr.blueberry.studio.hermes.api.permissions.PermissionManager; 9 | import fr.blueberry.studio.hermes.api.plugins.PluginManager; 10 | 11 | /** 12 | * Hermes Discord main 13 | */ 14 | public abstract class Hermes { 15 | private static Hermes INSTANCE; 16 | 17 | public Hermes() { 18 | INSTANCE = this; 19 | } 20 | 21 | /** 22 | * Get the command registry where all the command are registered for this 23 | * Hermes application. 24 | * @return - The command registry to register / unregister commands. 25 | */ 26 | public abstract CommandRegistry getCommandRegistry(); 27 | 28 | /** 29 | * Get the bot manager responsible of managing all this Hermes application bots. 30 | * @return - The bot manager where are the bots. 31 | */ 32 | public abstract BotManager getBotManager(); 33 | 34 | /** 35 | * Get the logger of this Hermes Application 36 | * @return - The logger of this application. 37 | */ 38 | public abstract Logger getLogger(); 39 | 40 | /** 41 | * Get the plugin manager where are all the plugins. 42 | * @return - The plugin manager to load / unload plugins. 43 | */ 44 | public abstract PluginManager getPluginManager(); 45 | 46 | /** 47 | * Stop this hermes application. 48 | */ 49 | public abstract void shutdown(); 50 | 51 | /** 52 | * Get the execution time in milliseconds (ms) of this application. 53 | * @return - The time since the app started in milliseconds. 54 | */ 55 | public abstract long getUptime(); 56 | 57 | /** 58 | * Get the Hermes Configuration Java interface. 59 | * @return - Retrieve some custom configuration from Hermes main configuration file. 60 | */ 61 | public abstract HermesConfig getHermesConfig(); 62 | 63 | /** 64 | * Get the permission manager for this Hermes application. 65 | * @return - The permission manager responsible for holding permissions. 66 | */ 67 | public abstract PermissionManager getPermissionManager(); 68 | 69 | /** 70 | * Get the sedmelluq Discord audio player manager. 71 | * @return - The Audio player manager which manage audio 72 | */ 73 | public abstract AudioPlayerManager getAudioPlayerManager(); 74 | 75 | public abstract DatabaseManager getDatabaseManager(); 76 | 77 | /** 78 | * Get this Hermes application main core. 79 | * @return - This Hermes application. 80 | */ 81 | public static final Hermes getHermes() { 82 | return Hermes.INSTANCE; 83 | } 84 | } -------------------------------------------------------------------------------- /src/main/java/fr/blueberry/studio/hermes/api/app/HermesConfig.java: -------------------------------------------------------------------------------- 1 | package fr.blueberry.studio.hermes.api.app; 2 | 3 | import java.util.List; 4 | 5 | /** 6 | * Interface to handle hermes configuration 7 | */ 8 | public interface HermesConfig { 9 | 10 | /** 11 | * Get the log level for this Hermes application. 12 | * @return - A String representating the log level (TRACE, DEBUG, INFO, WARN, ERROR, FATAL) 13 | */ 14 | public String getLogLevel(); 15 | 16 | /** 17 | * Get the list of operators. 18 | * @return - The list of discord user ids which are operators. 19 | */ 20 | public List getOps(); 21 | 22 | /** 23 | * Get the custom user message when a user doesn't have a permission to 24 | * execute something on this Hermes Application. 25 | * @return - The error message in String. 26 | */ 27 | public String getNoPermissionMessage(); 28 | 29 | /** 30 | * Get the custom user message when a user is executing a command 31 | * that doesn not exist yet on this Hermes Application. 32 | * @return - The no command message in String. 33 | */ 34 | public String getNoCommandMessage(); 35 | 36 | /** 37 | * Get the custom user message when a user is badly executing a command 38 | * with wrong arguments on this Hermes Application. 39 | * @return - The wrong command message in String. 40 | */ 41 | public String getWrongMessage(); 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/fr/blueberry/studio/hermes/api/app/Logger.java: -------------------------------------------------------------------------------- 1 | package fr.blueberry.studio.hermes.api.app; 2 | 3 | /** 4 | * Logger 5 | */ 6 | public interface Logger { 7 | 8 | /** 9 | * Trace log a message. 10 | * @param message - The message to log. 11 | */ 12 | void trace(String message); 13 | 14 | /** 15 | * Trace log a message and a Throwable 16 | * @param message - The message to log. 17 | */ 18 | void trace(String message, Throwable t); 19 | 20 | /** 21 | * Debug log a message. 22 | * @param message - The message to log 23 | */ 24 | void debug(String message); 25 | 26 | /** 27 | * Debug log a message and a Throwable 28 | * @param message - The message to log. 29 | */ 30 | void debug(String message, Throwable t); 31 | 32 | /** 33 | * Info log a message. 34 | * @param message - The message to log 35 | */ 36 | void info(String message); 37 | 38 | /** 39 | * Info log a message and a Throwable 40 | * @param message - The message to log. 41 | */ 42 | void info(String message, Throwable t); 43 | 44 | /** 45 | * Warn log a message. 46 | * @param message - The message to log 47 | */ 48 | void warn(String message); 49 | 50 | /** 51 | * Warn log a message and a Throwable 52 | * @param message - The message to log. 53 | */ 54 | void warn(String message, Throwable t); 55 | 56 | /** 57 | * Error log a message. 58 | * @param message - The message to log 59 | */ 60 | void error(String message); 61 | 62 | /** 63 | * Error log a message and a Throwable 64 | * @param message - The message to log. 65 | */ 66 | void error(String message, Throwable t); 67 | 68 | /** 69 | * Fatal log a message. 70 | * @param message - The message to log 71 | */ 72 | void fatal(String message); 73 | 74 | /** 75 | * Fatal log a message and a Throwable 76 | * @param message - The message to log. 77 | */ 78 | void fatal(String message, Throwable t); 79 | } -------------------------------------------------------------------------------- /src/main/java/fr/blueberry/studio/hermes/api/app/Sender.java: -------------------------------------------------------------------------------- 1 | package fr.blueberry.studio.hermes.api.app; 2 | 3 | import fr.blueberry.studio.hermes.api.bots.Bot; 4 | import net.dv8tion.jda.api.entities.Member; 5 | import net.dv8tion.jda.api.entities.Message; 6 | import net.dv8tion.jda.api.entities.MessageChannel; 7 | import net.dv8tion.jda.api.entities.MessageEmbed; 8 | import net.dv8tion.jda.api.entities.User; 9 | 10 | /** 11 | * Sender 12 | */ 13 | public interface Sender { 14 | 15 | /** 16 | * Return whether a sender is operator or not. 17 | * @return - True if the sender is operator. 18 | */ 19 | boolean isOp(); 20 | 21 | /** 22 | * Return whether a sender has the permission to execute something or not. 23 | * @param permissionNode - The permission node to check. 24 | * @return - True if the sender depends of the permission node groups. 25 | */ 26 | boolean hasPermission(String permissionNode); 27 | 28 | /** 29 | * Get a String representation of the sender. 30 | * @return - The identifier in String 31 | */ 32 | String getIdentifier(); 33 | 34 | /** 35 | * Get the Discord member associated with the sender. 36 | * @return - The JDA member 37 | */ 38 | Member getMember(); 39 | 40 | /** 41 | * Get the Discord User associated with the sender. 42 | * @return - The JDA user. 43 | */ 44 | User getUser(); 45 | 46 | /** 47 | * Get the message channel from where comes the sender. 48 | * @return - The Discord message channel. 49 | */ 50 | MessageChannel getMessageChannel(); 51 | 52 | /** 53 | * Get the Discord message from where comes the sender. 54 | * @return - The Discord message. 55 | */ 56 | Message getMessage(); 57 | 58 | /** 59 | * Send back a message to the location (TextChannel / Console / etc..) where the sender come from. 60 | * @param message - The message in String 61 | */ 62 | void reply(String message); 63 | 64 | /** 65 | * Send back a message to the location (TextChannel / Console / etc..) where the sender come from. 66 | * @param messageEmbed - The message embed to reply 67 | */ 68 | void reply(MessageEmbed messageEmbed); 69 | 70 | /** 71 | * Send back a message to the location (TextChannel / Console / etc..) where the sender come from. 72 | * @param messageEmbed - The messages embeds to reply 73 | */ 74 | void reply(MessageEmbed... messageEmbed); 75 | 76 | /** 77 | * Send back a message to the location (TextChannel / Console / etc..) where the sender come from. 78 | * @param message - The message to reply 79 | * @param bot - The bot to use to reply 80 | */ 81 | void reply(String message, Bot bot); 82 | 83 | /** 84 | * Send back a message to the location (TextChannel / Console / etc..) where the sender come from. 85 | * @param messageEmbed - The message embed to reply 86 | * @param bot - The bot to use to reply 87 | */ 88 | void reply(MessageEmbed messageEmbed, Bot bot); 89 | } -------------------------------------------------------------------------------- /src/main/java/fr/blueberry/studio/hermes/api/audio/AudioPriority.java: -------------------------------------------------------------------------------- 1 | package fr.blueberry.studio.hermes.api.audio; 2 | 3 | /** 4 | * Not implemented yet. 5 | * @hidden 6 | */ 7 | public enum AudioPriority { 8 | LOWEST, // 9 | LOW, // 10 | NORMAL, // 11 | HIGH, // 12 | HIGHEST // 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/fr/blueberry/studio/hermes/api/bots/Bot.java: -------------------------------------------------------------------------------- 1 | package fr.blueberry.studio.hermes.api.bots; 2 | 3 | import java.io.IOException; 4 | 5 | import javax.security.auth.login.LoginException; 6 | 7 | import net.dv8tion.jda.api.JDA; 8 | import net.dv8tion.jda.api.OnlineStatus; 9 | import net.dv8tion.jda.api.entities.Emote; 10 | import net.dv8tion.jda.api.entities.Guild; 11 | import net.dv8tion.jda.api.entities.Message; 12 | import net.dv8tion.jda.api.entities.MessageChannel; 13 | import net.dv8tion.jda.api.entities.MessageEmbed; 14 | import net.dv8tion.jda.api.entities.TextChannel; 15 | import net.dv8tion.jda.api.entities.User; 16 | import net.dv8tion.jda.api.entities.VoiceChannel; 17 | 18 | /** 19 | * Interface to handle bots 20 | */ 21 | public interface Bot { 22 | /** 23 | * Get the bot JDA Gateway API. 24 | * @return - The classical JDA API. 25 | */ 26 | JDA getJDA(); 27 | 28 | /** 29 | * Return whether a bot is connected (started) on Hermes or not. 30 | * /!\ WARNING : This does not determine if a bot is linked to Discord (i.e online), use 31 | * @see isGatewayConnected instead. 32 | * @return - True if a bot is connected to Hermes. 33 | */ 34 | boolean isConnected(); 35 | 36 | /** 37 | * Is a bot the triggerer or not. 38 | * The triggerer is one of the bots which handle all incoming commands and events 39 | * in an Hermes application to avoid all sort of duplications. Only one triggerer is 40 | * defined at once. If a triggerer disconnect from Hermes, another one is defined if possible. 41 | * @return 42 | */ 43 | boolean isTriggerer(); 44 | 45 | /** 46 | * Get the name of the bot. 47 | * @return - The name of the bot (Hermes representation) 48 | */ 49 | String getName(); 50 | 51 | /** 52 | * Get the Discord user name 53 | * @return - The Discord user name of the bot. 54 | */ 55 | String getDiscordName(); 56 | 57 | /** 58 | * Get the type of the bot (Console, User, Broker) 59 | * @return - The String representation of the type. 60 | */ 61 | String getType(); 62 | 63 | /** 64 | * Get the status of the bot. 65 | * @return - The status of the bot. 66 | */ 67 | String getStatusString(); 68 | 69 | /** 70 | * Get the guild of the bot. 71 | * @return - The guild of the bot. 72 | */ 73 | Guild getGuild(); 74 | 75 | /** 76 | * Get the text channel given by id. 77 | * @param id - The id of the text channel. 78 | * @return - The TextChannel required. 79 | */ 80 | TextChannel getTextChannel(long id); 81 | 82 | /** 83 | * Get whether the bot is connected to the Discord Gateway 84 | * @return - True if the bot is connected to Discord. 85 | */ 86 | boolean isGatewayConnected(); 87 | 88 | /** 89 | * Get the online status of this bot (ONLINE / DND / AWAY...) 90 | * @return - The online status of the bot 91 | */ 92 | OnlineStatus getOnlineStatus(); 93 | 94 | /** 95 | * Get whether the bot is available in voice chat. 96 | * @return - True if the bot is available for voice chat. 97 | */ 98 | boolean isVoiceAvalaible(); 99 | 100 | /** 101 | * Set the online status of the bot. 102 | * @param status - The online status to set. 103 | */ 104 | void setOnlineStatus(OnlineStatus status); 105 | 106 | /** 107 | * Set the status of the bot. 108 | * @param status - The status to string 109 | */ 110 | void setStatusString(String status); 111 | 112 | /** 113 | * Start a bot and connect to JDA Gateway. 114 | * @throws LoginException - If something is wrong while connecting. 115 | */ 116 | void start() throws LoginException; 117 | 118 | /** 119 | * Stop a bot and disconnect from JDA. 120 | */ 121 | void stop(); 122 | 123 | /** 124 | * Save the bot in config 125 | * @throws IOException - If something is wrong while writing config. 126 | */ 127 | void save() throws IOException; 128 | 129 | /** 130 | * Connect the bot to a voice channel. 131 | * @param voiceChannel - The target voice channel. 132 | */ 133 | void connect(VoiceChannel voiceChannel); 134 | 135 | /** 136 | * Disconnect the bot from the voice channel he 137 | * is currently in. This is ignored if the bot is 138 | * already disconnected from voice chat. 139 | */ 140 | void disconnect(); 141 | 142 | /** 143 | * Send a message embed to the given channel. 144 | * @param messageChannel - The message channel where to send the message. 145 | * @param messageEmbed - The message embed to send. 146 | */ 147 | void sendMessageTo(MessageChannel messageChannel, MessageEmbed messageEmbed); 148 | 149 | /** 150 | * Send a message embed to the given channel. 151 | * @param messageChannel - The message channel where to send the message. 152 | * @param message - The message to send. 153 | */ 154 | void sendMessageTo(MessageChannel messageChannel, String message); 155 | 156 | /** 157 | * Send a message embed to the given user. 158 | * @param user - The user which will receive a message. 159 | * @param message - The message to send. 160 | */ 161 | void sendMessageTo(User user, String message); 162 | 163 | /** 164 | * Send a message embed to the given user. 165 | * @param user - The user which will receive a message. 166 | * @param messageEmbed - The message embed to send. 167 | */ 168 | void sendMessageTo(User user, MessageEmbed messageEmbed); 169 | 170 | /** 171 | * Add a reaction on a message 172 | * @param message - The message where to add the reaction. 173 | * @param emote - The emote to add 174 | */ 175 | void addReaction(Message message, Emote emote); 176 | 177 | /** 178 | * Get the bot audio audio controller 179 | * @return - The bot audio controller. 180 | */ 181 | BotAudioController getAudioController(); 182 | } -------------------------------------------------------------------------------- /src/main/java/fr/blueberry/studio/hermes/api/bots/BotAudioController.java: -------------------------------------------------------------------------------- 1 | package fr.blueberry.studio.hermes.api.bots; 2 | 3 | import com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler; 4 | import com.sedmelluq.discord.lavaplayer.player.AudioPlayer; 5 | import com.sedmelluq.discord.lavaplayer.player.event.AudioEventAdapter; 6 | 7 | import fr.blueberry.studio.hermes.api.audio.AudioPriority; 8 | 9 | /** 10 | * 11 | */ 12 | public interface BotAudioController { 13 | /** 14 | * Create an audio player with given name. 15 | * @param name - The name of the audio player. 16 | * @return - The Audio player freshly created. 17 | */ 18 | public AudioPlayer createAudioPlayer(String name); 19 | 20 | /** 21 | * Create an audio player with given name and custom audio event adapter. 22 | * @param name - The name of the audio player. 23 | * @param audioEventAdapter - The custom audio event adapter where to handle player events. 24 | * @return - The Audio player freshly created. 25 | */ 26 | public AudioPlayer createAudioPlayer(String name, AudioEventAdapter audioEventAdapter); 27 | 28 | /** 29 | * Create an audio player with given name, audip priority and custom audio event adapter. 30 | * @param name - The name of the audio player. 31 | * @param priority - The priority of the audio player used to define which player play on the top. 32 | * @param audioEventAdapter - The custom audio event adapter where to handle player events. 33 | * @return - The Audio player freshly created. 34 | */ 35 | public AudioPlayer createAudioPlayer(String name, AudioPriority priority, AudioEventAdapter audioEventAdapter); 36 | 37 | /** 38 | * Check if the bot has an audio player given by name. 39 | * @param name - The name of the audio player. 40 | * @return - True if an audio player with given name is found. 41 | */ 42 | public boolean hasAudioPlayer(String name); 43 | 44 | /** 45 | * Remove an audio player 46 | * @param name - The name of the audio player to remove. 47 | */ 48 | public void removeAudioPlayer(String name); 49 | 50 | /** 51 | * Get the audio player by name. 52 | * @param name - The name of the audio player. 53 | * @return - The audio player. 54 | */ 55 | public AudioPlayer getAudioPlayer(String name); 56 | 57 | /** 58 | * Load an audio into an audio player with custom AudioLoadResultHandler 59 | * @param identifier - The identifier of the audio (filename,url...) 60 | * @param audioPlayer - The audio player name which will play audio. 61 | * @param handler - The handler result of audio loading. 62 | */ 63 | public void loadAudio(String identifier, String audioPlayer, AudioLoadResultHandler handler); 64 | 65 | /** 66 | * Load an audio into an audio player with custom AudioLoadResultHandler 67 | * @param identifier - The identifier of the audio (filename,url...) 68 | * @param audioPlayer - The audio player which will play audio. 69 | * @param handler - The handler result of audio loading. 70 | */ 71 | public void loadAudio(String identifier, AudioPlayer audioPlayer, AudioLoadResultHandler handler); 72 | 73 | /** 74 | * Get if the bot is broadcasting audio. 75 | * @return - True if the bot is broadcasting audio. 76 | */ 77 | public boolean isBroadcasting(); 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/fr/blueberry/studio/hermes/api/bots/BotManager.java: -------------------------------------------------------------------------------- 1 | package fr.blueberry.studio.hermes.api.bots; 2 | 3 | import java.io.IOException; 4 | import java.util.ArrayList; 5 | 6 | /** 7 | * Interface to manage hermes bots 8 | */ 9 | public interface BotManager { 10 | /** 11 | * Create an hermes bot 12 | * @param name - The hermes name of the bot (acts like an identifier) 13 | * @param token - The Discord token of the bot 14 | * @see Visit https://discord.com/developers/applications to get a token 15 | * @throws IOException - If something is wrong while reading / writing files. 16 | */ 17 | void createBot(String name, String token) throws IOException; 18 | 19 | /** 20 | * Delete a bot 21 | * @param name - The name of the bot to delete. (Hermes identifier) 22 | */ 23 | void deleteBot(String name); 24 | 25 | /** 26 | * Check if a bot exists with given name (Hermes identifier) 27 | * @param name - The name of the bot 28 | * @return - True if the bot exists 29 | */ 30 | boolean nameExist(String name); 31 | 32 | /** 33 | * Check if a bot exists with given token (Discord token) 34 | * @param token - The token of the bot 35 | * @return - True if the bot exists 36 | */ 37 | boolean tokenExist(String token); 38 | 39 | /** 40 | * Check if a bot exists with given name (Hermes identifier) and 41 | * given token. 42 | * @param name - The name of the bot 43 | * @param token - The token of the bot 44 | * @return - True if the bot exists 45 | */ 46 | boolean exist(String name, String token); 47 | 48 | /** 49 | * Pick a random bot in the list of Hermes bots. 50 | * @param connectedConstraint - Should it pick connected to JDA only ? 51 | * @return - The random picked bot. 52 | */ 53 | Bot pickRandomBot(boolean connectedConstraint); 54 | 55 | /** 56 | * Pick a random bot in the list of voice available Hermes bots. 57 | * @return - The random picked bot. 58 | */ 59 | Bot pickRandomVoiceAvalaibleBot(); 60 | 61 | /** 62 | * Get a bot by name 63 | * @param name - The name of the bot (Hermes identifier) 64 | * @return - The bot or null 65 | */ 66 | Bot getBot(String name); 67 | 68 | /** 69 | * Get a bot by its discord user id 70 | * @param id - The discord user id of the bot 71 | * @return - The bot or null 72 | */ 73 | Bot getBot(long id); 74 | 75 | /** 76 | * Get all the bots of the bot manager regardless 77 | * of the states. 78 | * @return - A list of all known bots on this hermes application. 79 | */ 80 | ArrayList getAllBots(); 81 | 82 | /** 83 | * Get all connected bots (JDA connected) of the bot manager. 84 | * @return - A list containing all connected bots on this hermes application 85 | */ 86 | ArrayList getAllConnectedBots(); 87 | 88 | /** 89 | * Get the triggerer of this hermes application. 90 | * @see Bot.getTriggerer() 91 | * @return - The bot triggerer of this hermes application. 92 | */ 93 | Bot getTriggerer(); 94 | 95 | /** 96 | * Get the bot count of this hermes application regardless of their states. 97 | * @return - The bot count of the application. 98 | */ 99 | int getBotCount(); 100 | 101 | /** 102 | * Get the connected bot count of this hermes application. 103 | * @return - The bot count of the application. 104 | */ 105 | int getConnectedBotCount(); 106 | 107 | /** 108 | * Get the JDA Listener manager of this Hermes application 109 | * @return - The JDA Listener manager. 110 | */ 111 | JDAListenerManager getJDAListenerManager(); 112 | 113 | /** 114 | * Shutdown all the connected bots. 115 | */ 116 | void shutdownAll(); 117 | } -------------------------------------------------------------------------------- /src/main/java/fr/blueberry/studio/hermes/api/bots/JDAListenerManager.java: -------------------------------------------------------------------------------- 1 | package fr.blueberry.studio.hermes.api.bots; 2 | 3 | import net.dv8tion.jda.api.hooks.ListenerAdapter; 4 | 5 | /** 6 | * WARNING: All your Discord listeners have to be registered 7 | * from this interface to get tracked by Hermes. You may result in 8 | * event and command duplication if you register your listeners directly in JDA. 9 | */ 10 | public interface JDAListenerManager { 11 | /** 12 | * Register a JDA event to Hermes. 13 | * @param listenerAdapter - The listener of the event 14 | */ 15 | void registerJDAListener(ListenerAdapter listenerAdapter); 16 | 17 | /** 18 | * Unregister a JDA event from Hermes. 19 | * @param listenerAdapter - The listener of the event 20 | */ 21 | void unRegisterJDAListener(ListenerAdapter listenerAdapter); 22 | 23 | /** 24 | * Get the triggerer of this hermes application. 25 | * @see Bot.getTriggerer() 26 | * @return - The bot triggerer of this hermes application. 27 | */ 28 | Bot getTriggerer(); 29 | } -------------------------------------------------------------------------------- /src/main/java/fr/blueberry/studio/hermes/api/commands/Command.java: -------------------------------------------------------------------------------- 1 | package fr.blueberry.studio.hermes.api.commands; 2 | 3 | import fr.blueberry.studio.hermes.api.app.Hermes; 4 | import fr.blueberry.studio.hermes.api.app.Logger; 5 | 6 | /** 7 | * Command 8 | */ 9 | public abstract class Command implements ICommand { 10 | protected Hermes hermes; 11 | protected Logger logger; 12 | 13 | public Command() { 14 | this.hermes = Hermes.getHermes(); 15 | this.logger = hermes.getLogger(); 16 | } 17 | 18 | @Override 19 | public String[] getAliases() { 20 | return new String[]{}; 21 | } 22 | 23 | @Override 24 | public String getDescription() { 25 | return ""; 26 | } 27 | 28 | @Override 29 | public String getUsage() { 30 | return ""; 31 | } 32 | 33 | @Override 34 | public boolean isOpRestricted() { 35 | return true; 36 | } 37 | 38 | @Override 39 | public Hermes getHermes() { 40 | return hermes; 41 | } 42 | 43 | @Override 44 | public Logger getLogger() { 45 | return logger; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/fr/blueberry/studio/hermes/api/commands/CommandRegistry.java: -------------------------------------------------------------------------------- 1 | package fr.blueberry.studio.hermes.api.commands; 2 | 3 | import java.util.Set; 4 | 5 | import fr.blueberry.studio.hermes.api.plugins.Plugin; 6 | 7 | /** 8 | * Command registry for hermes 9 | */ 10 | public interface CommandRegistry { 11 | 12 | /** 13 | * Register a command to Hermes application. 14 | * @param command - The command to register. 15 | * @param plugin - The plugin which holds the command. 16 | */ 17 | void registerCommand(Command command, Plugin plugin); 18 | 19 | /** 20 | * Unregister a command from Hermes application. 21 | * @param label - The label of the command to unregister. 22 | */ 23 | void unRegisterCommand(String label); 24 | 25 | /** 26 | * Get whether a command is registered or not. 27 | * @param label - The label of the command. 28 | * @return - True if the command is found in Hermes. 29 | */ 30 | boolean hasRegisteredCommand(String label); 31 | 32 | /** 33 | * Get the command by given label. 34 | * @param label - The label of the command to get. 35 | * @return - The command or null. 36 | */ 37 | Command getCommand(String label); 38 | 39 | /** 40 | * Get a command by one of its alias 41 | * @param alias - The alias of the command to get. 42 | * @return - The command or null. 43 | */ 44 | Command getCommandByAlias(String alias); 45 | 46 | /** 47 | * Get the command list. 48 | * @return - A string representation of the command list. 49 | */ 50 | String getCommandList(); 51 | 52 | /** 53 | * Get all the commands for a plugin. 54 | * @param plugin - The plugin to get the commands from. 55 | * @return - A list containing all the commands for a plugin. 56 | */ 57 | Set getPluginCommands(Plugin plugin); 58 | 59 | /** 60 | * Get all the implemented by default hermes commands. 61 | * @return - A list containing all the hermes commands. 62 | */ 63 | Set getHermesCommands(); 64 | } -------------------------------------------------------------------------------- /src/main/java/fr/blueberry/studio/hermes/api/commands/ICommand.java: -------------------------------------------------------------------------------- 1 | package fr.blueberry.studio.hermes.api.commands; 2 | 3 | import fr.blueberry.studio.hermes.api.app.Hermes; 4 | import fr.blueberry.studio.hermes.api.app.Logger; 5 | import fr.blueberry.studio.hermes.api.app.Sender; 6 | 7 | /** 8 | * Interface for commands 9 | */ 10 | public interface ICommand { 11 | /** 12 | * Get the command label. 13 | * @return - The command label. 14 | */ 15 | String getLabel(); 16 | 17 | /** 18 | * Get the command aliases. 19 | * @return - The list of command aliases. 20 | */ 21 | String[] getAliases(); 22 | 23 | /** 24 | * Get the command description. 25 | * @return - The command description 26 | */ 27 | String getDescription(); 28 | 29 | /** 30 | * Get the command usage. 31 | * @return - The usage of the command. 32 | */ 33 | String getUsage(); 34 | 35 | /** 36 | * Get whether the command is restricted to operators 37 | * member only or not. All commands are op restricted by default for security purposes, you 38 | * might have to un-restrict your command yourself. 39 | * @return 40 | */ 41 | boolean isOpRestricted(); 42 | 43 | /** 44 | * Execute the command 45 | * @param sender - The sender of the command. 46 | * @param args - The args of the command without label or aliases. 47 | */ 48 | void execute(Sender sender, String[] args); 49 | 50 | /** 51 | * Get Hermes application 52 | * @return - Hermes application 53 | */ 54 | Hermes getHermes(); 55 | 56 | /** 57 | * Get the Logger of the application. 58 | * @return - The logger of the application. 59 | */ 60 | Logger getLogger(); 61 | } -------------------------------------------------------------------------------- /src/main/java/fr/blueberry/studio/hermes/api/data/sql/DatabaseCredentials.java: -------------------------------------------------------------------------------- 1 | package fr.blueberry.studio.hermes.api.data.sql; 2 | 3 | /** 4 | * 5 | */ 6 | public class DatabaseCredentials { 7 | private final String url; 8 | private final String user; 9 | private final String pass; 10 | private final String databaseName; 11 | private final int port; 12 | 13 | public DatabaseCredentials(String url, String user, String pass, String databaseName) { 14 | this(url, user, pass, databaseName, 3306); 15 | } 16 | 17 | public DatabaseCredentials(String url, String user, String pass, String databaseName, int port) { 18 | this.url = url; 19 | this.user = user; 20 | this.pass = pass; 21 | this.databaseName = databaseName; 22 | this.port = port; 23 | } 24 | 25 | public String getDatabaseName() { 26 | return databaseName; 27 | } 28 | 29 | public String getPass() { 30 | return pass; 31 | } 32 | 33 | public int getPort() { 34 | return port; 35 | } 36 | 37 | public String getUrl() { 38 | return url; 39 | } 40 | 41 | public String getUser() { 42 | return user; 43 | } 44 | } -------------------------------------------------------------------------------- /src/main/java/fr/blueberry/studio/hermes/api/data/sql/DatabaseManager.java: -------------------------------------------------------------------------------- 1 | package fr.blueberry.studio.hermes.api.data.sql; 2 | 3 | import java.sql.Connection; 4 | import com.zaxxer.hikari.HikariConfig; 5 | import com.zaxxer.hikari.HikariDataSource; 6 | 7 | /** 8 | * 9 | */ 10 | public interface DatabaseManager { 11 | /** 12 | * Create a connection pool with default configuration. 13 | * @param name - The name of the connection. 14 | * @param credentials - The credentials of the connection to authenticate to database. 15 | * @return - The HikariDataSource of the connection 16 | */ 17 | HikariDataSource createConnectionPool(String name, DatabaseCredentials credentials); 18 | 19 | /** 20 | * Create a connection pool with custom configuration. 21 | * @param name - The name of the connection. 22 | * @param credentials - The credentials of the connection to authenticate to database. 23 | * @param config - The configuration of the database pool. 24 | * @return - The HikariDataSource of the connection 25 | */ 26 | HikariDataSource createConnectionPool(String name, DatabaseCredentials credentials, HikariConfig config); 27 | 28 | /** 29 | * Close a connection silently 30 | * @param connection 31 | */ 32 | void closeSilently(Connection connection); 33 | } -------------------------------------------------------------------------------- /src/main/java/fr/blueberry/studio/hermes/api/data/sql/QueryHandler.java: -------------------------------------------------------------------------------- 1 | package fr.blueberry.studio.hermes.api.data.sql; 2 | 3 | import java.math.BigDecimal; 4 | import java.sql.Connection; 5 | import java.sql.Date; 6 | import java.sql.PreparedStatement; 7 | import java.sql.ResultSet; 8 | import java.sql.SQLException; 9 | import java.sql.Statement; 10 | import java.sql.Timestamp; 11 | import java.sql.Types; 12 | import java.util.HashSet; 13 | 14 | /** 15 | * 16 | */ 17 | public class QueryHandler { 18 | private final Connection connection; 19 | 20 | public QueryHandler(Connection connection) { 21 | this.connection = connection; 22 | } 23 | 24 | /** 25 | * Execute an update with given data 26 | * @param query - The query to execute 27 | * @param data - The data of the query 28 | * @return - The result of the query 29 | * @throws SQLException - If something went wrong from Database 30 | */ 31 | public ResultSet executeUpdate(String query, Object[] data) throws SQLException { 32 | final PreparedStatement statement = this.connection.prepareStatement(query, Statement.RETURN_GENERATED_KEYS); 33 | 34 | for(int i = 0; i < data.length; i++) { 35 | bindData(statement, i + 1, data[i]); 36 | } 37 | 38 | statement.executeUpdate(); 39 | 40 | return statement.getGeneratedKeys(); 41 | } 42 | 43 | /** 44 | * Construct and execute a batch for the same query 45 | * @param query - The query to batch 46 | * @param data - the data to bind 47 | * @return - The count holding the returned values 48 | * @throws SQLException - If something went wrong from Database 49 | */ 50 | public int[] executeBatch(String query, Object[][] data) throws SQLException { 51 | final PreparedStatement statement = this.connection.prepareStatement(query, Statement.RETURN_GENERATED_KEYS); 52 | int[] count; 53 | 54 | connection.setAutoCommit(false); 55 | 56 | for(int i = 0; i < data.length; i++) { 57 | for(int j = 0; j < data[i].length; j++) { 58 | bindData(statement, j + 1, data[i][j]); 59 | } 60 | 61 | statement.addBatch(); 62 | } 63 | 64 | count = statement.executeBatch(); 65 | connection.commit(); 66 | connection.setAutoCommit(true); 67 | 68 | return count; 69 | } 70 | 71 | /** 72 | * Execute a query without binding data 73 | * @param query - The query to execute 74 | * @return - The result of the query 75 | * @throws SQLException - If something went wrong from Database 76 | */ 77 | public ResultSet executeQuery(String query) throws SQLException { 78 | return executeQuery(query, null); 79 | } 80 | 81 | /** 82 | * Execute a query with given data 83 | * @param query - The query to execute 84 | * @param data - The data of the query 85 | * @return - The result of the query 86 | * @throws SQLException - If something went wrong from Database 87 | */ 88 | public ResultSet executeQuery(String query, Object[] data) throws SQLException { 89 | final PreparedStatement statement = this.connection.prepareStatement(query); 90 | 91 | if(data != null) { 92 | for(int i = 0; i < data.length; i++) { 93 | bindData(statement, i + 1, data[i]); 94 | } 95 | } 96 | 97 | return statement.executeQuery(); 98 | } 99 | 100 | /** 101 | * Execute a grouped sql commit 102 | * @param queries - The queries to perform 103 | * @throws SQLException - If something went wrong from Database 104 | */ 105 | public void executeCommit(String[] queries, Object[][] data) throws SQLException { 106 | final PreparedStatement[] preparedStatements = new PreparedStatement[queries.length]; 107 | 108 | connection.setAutoCommit(false); 109 | 110 | for(int i = 0; i < queries.length; i++) { 111 | preparedStatements[i] = connection.prepareStatement(queries[i]); 112 | } 113 | 114 | for(int i = 0; i < preparedStatements.length; i++) { 115 | if(data != null) { 116 | for(int j = 0; j < data[i].length; j++) { 117 | bindData(preparedStatements[i], j + 1, data[i][j]); 118 | } 119 | } 120 | preparedStatements[i].execute(); 121 | } 122 | 123 | connection.commit(); 124 | connection.setAutoCommit(true); 125 | } 126 | 127 | /** 128 | * Check for a table existences in database 129 | * @param table - The table to check 130 | * @return - True if a table is found in database 131 | * @throws SQLException - If something went wrong from Database 132 | */ 133 | public boolean tableExists(String table) throws SQLException { 134 | final ResultSet tables = this.executeQuery("SHOW TABLES"); 135 | final HashSet tablesName = new HashSet<>(); 136 | 137 | while(tables.next()) { 138 | tablesName.add(tables.getString(1)); 139 | } 140 | 141 | return tablesName.contains(table); 142 | } 143 | 144 | /** 145 | * Bind a sql data to a prepared statement with given index. 146 | * @param statement - The sql statement where to parse data 147 | * @param index - The index of the statement where to bind data 148 | * @param primitive - The primitive data to bind 149 | * @throws SQLException - If something went wrong from Database 150 | */ 151 | private void bindData(PreparedStatement statement, int index, Object primitive) throws SQLException { 152 | if(primitive instanceof Integer) { 153 | statement.setInt(index, (Integer)primitive); 154 | } else if(primitive instanceof Long) { 155 | statement.setLong(index, (Long)primitive); 156 | } else if(primitive instanceof String) { 157 | statement.setString(index, (String)primitive); 158 | } else if(primitive instanceof Boolean) { 159 | statement.setBoolean(index, (Boolean)primitive); 160 | } else if(primitive instanceof Timestamp) { 161 | statement.setTimestamp(index, (Timestamp)primitive); 162 | } else if(primitive instanceof Byte) { 163 | statement.setByte(index, (Byte)primitive); 164 | } else if(primitive instanceof Date) { 165 | statement.setDate(index, (Date)primitive); 166 | } else if(primitive instanceof Double) { 167 | statement.setDouble(index, (Double)primitive); 168 | } else if(primitive instanceof Float) { 169 | statement.setFloat(index, (Float)primitive); 170 | } else if(primitive instanceof BigDecimal) { 171 | statement.setBigDecimal(index, (BigDecimal)primitive); 172 | } else if(primitive == null) { 173 | statement.setNull(index, Types.NULL); 174 | } else { 175 | statement.setObject(index, primitive); 176 | } 177 | } 178 | 179 | /** 180 | * Compact a list a query as argument in a java array. 181 | * @param query - The queries inlined as args. 182 | * @return - The queries in an array 183 | */ 184 | public String[] compactQueries(String... query) { 185 | return query; 186 | } 187 | 188 | /** 189 | * Compact a list of data (Java objects) in a java array. 190 | * @param o - The data inlined as args in Java Object type. 191 | * @return - The data in an array. 192 | */ 193 | public Object[] compactData(Object... o) { 194 | return o; 195 | } 196 | 197 | /** 198 | * Close the connection associated to this query handler 199 | * @throws SQLException - If something is wrong with SQL 200 | */ 201 | public void close() throws SQLException { 202 | if(this.connection != null) { 203 | this.connection.close(); 204 | } 205 | } 206 | } -------------------------------------------------------------------------------- /src/main/java/fr/blueberry/studio/hermes/api/jobs/Job.java: -------------------------------------------------------------------------------- 1 | package fr.blueberry.studio.hermes.api.jobs; 2 | 3 | import fr.blueberry.studio.hermes.api.app.Hermes; 4 | import fr.blueberry.studio.hermes.api.app.Logger; 5 | 6 | /** 7 | * Job 8 | */ 9 | public abstract class Job { 10 | 11 | private final Hermes hermes; 12 | private final Logger logger; 13 | 14 | public Job() { 15 | this.hermes = Hermes.getHermes(); 16 | this.logger = hermes.getLogger(); 17 | } 18 | /** 19 | * Run the job. 20 | */ 21 | public abstract void run(); 22 | 23 | /** 24 | * Get Hermes application. 25 | * @return - Hermes app 26 | */ 27 | public Hermes getHermes() { 28 | return this.hermes; 29 | } 30 | 31 | /** 32 | * Get the logger of the application. 33 | * @return - The logger of the application. 34 | */ 35 | public Logger getLogger() { 36 | return this.logger; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/fr/blueberry/studio/hermes/api/permissions/PermissionManager.java: -------------------------------------------------------------------------------- 1 | package fr.blueberry.studio.hermes.api.permissions; 2 | 3 | import fr.blueberry.studio.hermes.api.app.Sender; 4 | import net.dv8tion.jda.api.entities.Member; 5 | import net.dv8tion.jda.api.entities.Role; 6 | 7 | /** 8 | * Permission manager for Hermes 9 | */ 10 | public interface PermissionManager { 11 | 12 | /** 13 | * Refresh the permissions 14 | */ 15 | public void refreshPermissions(); 16 | 17 | /** 18 | * Check if a sender has the given permission. 19 | * @param sender - The sender to check permissions 20 | * @param permission - The permission node 21 | * @return - True if the sender has the permission. 22 | */ 23 | public boolean hasPermission(Sender sender, String permission); 24 | 25 | /** 26 | * Check if a member has the given permission. 27 | * @param member - The member to check permissions 28 | * @param permission - The permission node 29 | * @return - True if the member has the permission. 30 | */ 31 | public boolean hasPermission(Member member, String permission); 32 | 33 | /** 34 | * Check if a role has the given permission. 35 | * @param role - The role to check permissions 36 | * @param permission - The permission node 37 | * @return - True if the role has the permission. 38 | */ 39 | public boolean hasPermission(Role role, String permission); 40 | 41 | /** 42 | * Check if a role has the given permission. 43 | * @param roleId - The id of the role to check permissions 44 | * @param permission - The permission node 45 | * @return - True if the role has the permission. 46 | */ 47 | public boolean hasPermission(long roleId, String permission); 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/fr/blueberry/studio/hermes/api/plugins/EventPriority.java: -------------------------------------------------------------------------------- 1 | package fr.blueberry.studio.hermes.api.plugins; 2 | 3 | public enum EventPriority { 4 | LOWEST, 5 | LOW, 6 | NORMAL, 7 | HIGH, 8 | HIGHEST; 9 | } -------------------------------------------------------------------------------- /src/main/java/fr/blueberry/studio/hermes/api/plugins/ExecutableListener.java: -------------------------------------------------------------------------------- 1 | package fr.blueberry.studio.hermes.api.plugins; 2 | 3 | import java.lang.reflect.InvocationTargetException; 4 | import java.lang.reflect.Method; 5 | 6 | import fr.blueberry.studio.hermes.api.plugins.events.Event; 7 | 8 | public class ExecutableListener implements Comparable { 9 | private final Plugin plugin; 10 | private final EventPriority eventPriority; 11 | private final Listener listener; 12 | private final boolean ignoreCancel; 13 | private final Method method; 14 | 15 | public ExecutableListener(Plugin plugin, EventPriority eventPriority, Listener listener, boolean ignoreCancel, Method method) { 16 | this.plugin = plugin; 17 | this.eventPriority = eventPriority; 18 | this.listener = listener; 19 | this.ignoreCancel = ignoreCancel; 20 | this.method = method; 21 | } 22 | 23 | public void execute(Event event) { 24 | try { 25 | method.invoke(listener, event); 26 | } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { 27 | e.printStackTrace(); 28 | } 29 | } 30 | 31 | @Override 32 | public int compareTo(ExecutableListener o) { 33 | return Integer.compare(eventPriority.ordinal(), o.eventPriority.ordinal()); 34 | } 35 | 36 | public Plugin getPlugin() { 37 | return this.plugin; 38 | } 39 | 40 | public boolean isCancelIgnored() { 41 | return this.ignoreCancel; 42 | } 43 | } -------------------------------------------------------------------------------- /src/main/java/fr/blueberry/studio/hermes/api/plugins/HermesListen.java: -------------------------------------------------------------------------------- 1 | package fr.blueberry.studio.hermes.api.plugins; 2 | 3 | import java.lang.annotation.ElementType; 4 | import java.lang.annotation.Retention; 5 | import java.lang.annotation.RetentionPolicy; 6 | import java.lang.annotation.Target; 7 | 8 | @Target(ElementType.METHOD) 9 | @Retention(RetentionPolicy.RUNTIME) 10 | public @interface HermesListen { 11 | EventPriority priority() default EventPriority.NORMAL; 12 | boolean ignoreCancel() default false; 13 | } -------------------------------------------------------------------------------- /src/main/java/fr/blueberry/studio/hermes/api/plugins/Listener.java: -------------------------------------------------------------------------------- 1 | package fr.blueberry.studio.hermes.api.plugins; 2 | 3 | public interface Listener {} -------------------------------------------------------------------------------- /src/main/java/fr/blueberry/studio/hermes/api/plugins/Plugin.java: -------------------------------------------------------------------------------- 1 | package fr.blueberry.studio.hermes.api.plugins; 2 | 3 | import java.io.File; 4 | import java.io.IOException; 5 | 6 | import org.simpleyaml.configuration.file.YamlFile; 7 | import org.simpleyaml.exceptions.InvalidConfigurationException; 8 | 9 | import fr.blueberry.studio.hermes.api.app.Hermes; 10 | import fr.blueberry.studio.hermes.api.app.Logger; 11 | import fr.blueberry.studio.hermes.api.commands.CommandRegistry; 12 | 13 | public abstract class Plugin implements PluginBase { 14 | protected PluginMeta pluginMeta; 15 | protected Hermes hermes; 16 | protected YamlFile config; 17 | private boolean enabled; 18 | 19 | public Plugin() { 20 | this.pluginMeta = null; 21 | this.hermes= Hermes.getHermes(); 22 | this.config = null; 23 | this.enabled = false; 24 | } 25 | 26 | public void onLoad() {} 27 | 28 | public void onEnable() {} 29 | 30 | public void onPostStart() {} 31 | 32 | public void onDisable() {} 33 | 34 | public void onNoTriggerer() {} 35 | 36 | @Override 37 | public File getDataFolder() { 38 | return new File(PluginManager.PLUGINS_FOLDER, pluginMeta.getName()); 39 | } 40 | 41 | @Override 42 | public Logger getLogger() { 43 | return hermes.getLogger(); 44 | } 45 | 46 | public Hermes getHermes() { 47 | return hermes; 48 | } 49 | 50 | public CommandRegistry getCommandRegistry() { 51 | return hermes.getCommandRegistry(); 52 | } 53 | 54 | @Override 55 | public PluginMeta getPluginMeta() { 56 | return this.pluginMeta; 57 | } 58 | 59 | public YamlFile getConfiguration() { 60 | if(this.config != null) { 61 | return this.config; 62 | } 63 | return new YamlFile(); 64 | } 65 | 66 | public void setEnabled(boolean enabled) { 67 | this.enabled = enabled; 68 | } 69 | 70 | public boolean isEnabled() { 71 | return this.enabled; 72 | } 73 | 74 | public void addPluginMeta(PluginMeta pluginMeta) { 75 | this.pluginMeta = pluginMeta; 76 | } 77 | 78 | public void loadConfiguration(YamlFile config) throws InvalidConfigurationException, IOException { 79 | this.config = config; 80 | this.config.load(); 81 | } 82 | } -------------------------------------------------------------------------------- /src/main/java/fr/blueberry/studio/hermes/api/plugins/PluginBase.java: -------------------------------------------------------------------------------- 1 | package fr.blueberry.studio.hermes.api.plugins; 2 | 3 | import java.io.File; 4 | 5 | import fr.blueberry.studio.hermes.api.app.Hermes; 6 | import fr.blueberry.studio.hermes.api.app.Logger; 7 | import fr.blueberry.studio.hermes.api.commands.CommandRegistry; 8 | 9 | public interface PluginBase { 10 | 11 | File getDataFolder(); 12 | 13 | Logger getLogger(); 14 | 15 | Hermes getHermes(); 16 | 17 | PluginMeta getPluginMeta(); 18 | 19 | CommandRegistry getCommandRegistry(); 20 | 21 | boolean isEnabled(); 22 | } -------------------------------------------------------------------------------- /src/main/java/fr/blueberry/studio/hermes/api/plugins/PluginManager.java: -------------------------------------------------------------------------------- 1 | package fr.blueberry.studio.hermes.api.plugins; 2 | 3 | import java.io.File; 4 | import java.util.HashSet; 5 | import java.util.Set; 6 | 7 | import fr.blueberry.studio.hermes.api.plugins.events.Event; 8 | 9 | public interface PluginManager { 10 | public static final String PLUGINS_FOLDER = System.getProperty("user.dir") + "/plugins/"; 11 | 12 | File getPluginFolder(); 13 | 14 | void registerEventListener(Plugin plugin, Listener listener); 15 | 16 | void unRegisterEventListeners(Plugin plugin, Class clazz); 17 | 18 | void unRegisterAllEventsListener(Plugin plugin); 19 | 20 | boolean isEventListenerActive(Class clazz); 21 | 22 | boolean isPluginEnabled(String name); 23 | 24 | boolean hasPlugin(String name); 25 | 26 | boolean hasPlugin(String name, boolean ignoreCase); 27 | 28 | boolean hasPlugin(Plugin plugin); 29 | 30 | Plugin getPlugin(String name); 31 | 32 | Plugin getPlugin(String name, boolean ignoreCase); 33 | 34 | void callEvent(Event event); 35 | 36 | void unloadPlugin(Plugin plugin); 37 | 38 | HashSet getListeners(Class clazz); 39 | 40 | HashSet getListeners(Event event); 41 | 42 | Set getPlugins(); 43 | 44 | void reload(); 45 | } -------------------------------------------------------------------------------- /src/main/java/fr/blueberry/studio/hermes/api/plugins/PluginMeta.java: -------------------------------------------------------------------------------- 1 | package fr.blueberry.studio.hermes.api.plugins; 2 | 3 | public class PluginMeta { 4 | private final String name; 5 | private final String main; 6 | private final String version; 7 | private final String author; 8 | private final String description; 9 | 10 | public PluginMeta(String name, String main, String version, String author, String description) { 11 | this.name = name; 12 | this.main = main; 13 | this.version = version; 14 | this.author = author; 15 | this.description = description; 16 | } 17 | 18 | public String getAuthor() { 19 | return author; 20 | } 21 | 22 | public String getDescription() { 23 | return description; 24 | } 25 | 26 | public String getMain() { 27 | return main; 28 | } 29 | 30 | public String getName() { 31 | return name; 32 | } 33 | 34 | public String getVersion() { 35 | return version; 36 | } 37 | } -------------------------------------------------------------------------------- /src/main/java/fr/blueberry/studio/hermes/api/plugins/events/BeforeCommandEvent.java: -------------------------------------------------------------------------------- 1 | package fr.blueberry.studio.hermes.api.plugins.events; 2 | 3 | import fr.blueberry.studio.hermes.api.app.Sender; 4 | import fr.blueberry.studio.hermes.api.commands.ICommand; 5 | 6 | public class BeforeCommandEvent extends Event { 7 | private ICommand command; 8 | private Sender sender; 9 | private String input; 10 | private String[] args; 11 | 12 | public BeforeCommandEvent(ICommand command, Sender sender, String input, String[] args) { 13 | this.command = command; 14 | this.sender = sender; 15 | this.input = input; 16 | this.args = args; 17 | } 18 | 19 | public ICommand getCommand() { 20 | return command; 21 | } 22 | 23 | public String getInput() { 24 | return input; 25 | } 26 | 27 | public Sender getSender() { 28 | return sender; 29 | } 30 | 31 | public String[] getArgs() { 32 | return args; 33 | } 34 | } -------------------------------------------------------------------------------- /src/main/java/fr/blueberry/studio/hermes/api/plugins/events/BotCreateEvent.java: -------------------------------------------------------------------------------- 1 | package fr.blueberry.studio.hermes.api.plugins.events; 2 | 3 | public class BotCreateEvent extends BotEvent { 4 | private String name; 5 | private final String token; 6 | 7 | public BotCreateEvent(String name, String token) { 8 | this.name = name; 9 | this.token = token; 10 | } 11 | 12 | public String getName() { 13 | return this.name; 14 | } 15 | 16 | public String getToken() { 17 | return this.token; 18 | } 19 | 20 | public void setName(String name) { 21 | this.name = name; 22 | } 23 | } -------------------------------------------------------------------------------- /src/main/java/fr/blueberry/studio/hermes/api/plugins/events/BotDeleteEvent.java: -------------------------------------------------------------------------------- 1 | package fr.blueberry.studio.hermes.api.plugins.events; 2 | 3 | public class BotDeleteEvent extends BotEvent { 4 | private String name; 5 | 6 | public BotDeleteEvent(String name) { 7 | this.name = name; 8 | } 9 | 10 | public String getName() { 11 | return this.name; 12 | } 13 | } -------------------------------------------------------------------------------- /src/main/java/fr/blueberry/studio/hermes/api/plugins/events/BotEvent.java: -------------------------------------------------------------------------------- 1 | package fr.blueberry.studio.hermes.api.plugins.events; 2 | 3 | import fr.blueberry.studio.hermes.api.bots.Bot; 4 | 5 | public class BotEvent extends Event { 6 | private final Bot bot; 7 | 8 | public BotEvent() { 9 | this.bot = null; 10 | } 11 | 12 | public BotEvent(Bot bot) { 13 | this.bot = bot; 14 | } 15 | 16 | public Bot getBot() { 17 | return this.bot; 18 | } 19 | } -------------------------------------------------------------------------------- /src/main/java/fr/blueberry/studio/hermes/api/plugins/events/BotReadyEvent.java: -------------------------------------------------------------------------------- 1 | package fr.blueberry.studio.hermes.api.plugins.events; 2 | 3 | import fr.blueberry.studio.hermes.api.bots.Bot; 4 | 5 | public class BotReadyEvent extends BotEvent { 6 | public BotReadyEvent(Bot bot) { 7 | super(bot); 8 | } 9 | } -------------------------------------------------------------------------------- /src/main/java/fr/blueberry/studio/hermes/api/plugins/events/BotStartEvent.java: -------------------------------------------------------------------------------- 1 | package fr.blueberry.studio.hermes.api.plugins.events; 2 | 3 | import fr.blueberry.studio.hermes.api.bots.Bot; 4 | 5 | public class BotStartEvent extends BotEvent { 6 | 7 | public BotStartEvent(Bot bot) { 8 | super(bot); 9 | } 10 | } -------------------------------------------------------------------------------- /src/main/java/fr/blueberry/studio/hermes/api/plugins/events/BotStopEvent.java: -------------------------------------------------------------------------------- 1 | package fr.blueberry.studio.hermes.api.plugins.events; 2 | 3 | import fr.blueberry.studio.hermes.api.bots.Bot; 4 | 5 | public class BotStopEvent extends BotEvent { 6 | 7 | public BotStopEvent(Bot bot) { 8 | super(bot); 9 | } 10 | } -------------------------------------------------------------------------------- /src/main/java/fr/blueberry/studio/hermes/api/plugins/events/BotTriggererDefinedEvent.java: -------------------------------------------------------------------------------- 1 | package fr.blueberry.studio.hermes.api.plugins.events; 2 | 3 | import fr.blueberry.studio.hermes.api.bots.Bot; 4 | 5 | public class BotTriggererDefinedEvent extends BotEvent { 6 | public BotTriggererDefinedEvent(Bot bot) { 7 | super(bot); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/fr/blueberry/studio/hermes/api/plugins/events/Event.java: -------------------------------------------------------------------------------- 1 | package fr.blueberry.studio.hermes.api.plugins.events; 2 | 3 | public abstract class Event { 4 | protected boolean canceled = false; 5 | 6 | public boolean isCanceled() { 7 | return canceled; 8 | } 9 | 10 | public void setCanceled(boolean canceled) { 11 | this.canceled = canceled; 12 | } 13 | } -------------------------------------------------------------------------------- /src/main/java/fr/blueberry/studio/hermes/api/plugins/events/HermesEvent.java: -------------------------------------------------------------------------------- 1 | package fr.blueberry.studio.hermes.api.plugins.events; 2 | 3 | import fr.blueberry.studio.hermes.api.app.Hermes; 4 | 5 | public class HermesEvent extends Event { 6 | protected final Hermes hermes; 7 | 8 | public HermesEvent(Hermes hermes) { 9 | this.hermes = hermes; 10 | } 11 | 12 | public Hermes getHermes() { 13 | return this.hermes; 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/fr/blueberry/studio/hermes/api/plugins/events/HermesNoTriggererEvent.java: -------------------------------------------------------------------------------- 1 | package fr.blueberry.studio.hermes.api.plugins.events; 2 | 3 | import fr.blueberry.studio.hermes.api.app.Hermes; 4 | 5 | public class HermesNoTriggererEvent extends HermesEvent { 6 | 7 | public HermesNoTriggererEvent(Hermes hermes) { 8 | super(hermes); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/fr/blueberry/studio/hermes/api/plugins/events/HermesReadyEvent.java: -------------------------------------------------------------------------------- 1 | package fr.blueberry.studio.hermes.api.plugins.events; 2 | 3 | import fr.blueberry.studio.hermes.api.app.Hermes; 4 | import fr.blueberry.studio.hermes.api.bots.Bot; 5 | 6 | public class HermesReadyEvent extends HermesEvent { 7 | private final Bot triggerer; 8 | 9 | public HermesReadyEvent(Hermes hermes, Bot triggerer) { 10 | super(hermes); 11 | this.triggerer = triggerer; 12 | } 13 | 14 | public Bot getTriggerer() { 15 | return this.triggerer; 16 | } 17 | } -------------------------------------------------------------------------------- /src/main/java/fr/blueberry/studio/hermes/api/utils/AnnotationHelper.java: -------------------------------------------------------------------------------- 1 | package fr.blueberry.studio.hermes.api.utils; 2 | 3 | import java.lang.annotation.Annotation; 4 | import java.lang.reflect.InvocationTargetException; 5 | import java.lang.reflect.Method; 6 | 7 | public class AnnotationHelper { 8 | /** 9 | * Get an annotation value from a class 10 | * 11 | * @param annotationMethodName - The method name to get value in the annotation. 12 | * @param clazz - The class where the annotation is fixed. 13 | * @return - The annotation value or null if none is found. 14 | */ 15 | public static Object getAnnotationValue(final String annotationMethodName, final Class clazz) { 16 | for (final Annotation annotation : clazz.getAnnotations()) { 17 | final Class annotationType = annotation.annotationType(); 18 | 19 | for (final Method method : annotationType.getDeclaredMethods()) { 20 | if (method.getName().equals(annotationMethodName)) { 21 | try { 22 | return method.invoke(annotation, (Object[]) null); 23 | } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { 24 | e.printStackTrace(); 25 | } 26 | } 27 | } 28 | } 29 | return null; 30 | } 31 | 32 | /** 33 | * Get an annotation value from annotation 34 | * @param annotationMethodName - The method name to get value in the annotation. 35 | * @return - The annotation value or null if none is found. 36 | */ 37 | public static Object getAnnotationValue(final String annotationMethodName, final Annotation annotation) { 38 | 39 | for(final Method method : annotation.annotationType().getDeclaredMethods()) { 40 | if(method.getName().equals(annotationMethodName)) { 41 | try { 42 | return method.invoke(annotation, (Object[])null); 43 | } catch (IllegalAccessException | InvocationTargetException e) { 44 | e.printStackTrace(); 45 | } 46 | } 47 | } 48 | 49 | return null; 50 | } 51 | 52 | } -------------------------------------------------------------------------------- /src/main/java/fr/blueberry/studio/hermes/api/utils/ColorHelper.java: -------------------------------------------------------------------------------- 1 | package fr.blueberry.studio.hermes.api.utils; 2 | 3 | import java.awt.Color; 4 | 5 | public class ColorHelper { 6 | public static final String ANSI_RESET = "\u001B[0m"; 7 | 8 | /** 9 | * Convert an hexa color to RGB Color 10 | * @param hexa - The String of the hexadecimal color. 11 | * @return - The RGB Color 12 | */ 13 | public static Color toRGB(String hexa) { 14 | return new Color( 15 | Integer.valueOf(hexa.substring(1, 3), 16), 16 | Integer.valueOf(hexa.substring(3, 5), 16), 17 | Integer.valueOf(hexa.substring(5, 7), 16) 18 | ); 19 | } 20 | 21 | /** 22 | * Convert a Color to ANSI Foreground 23 | * @param color - The Color to convert 24 | * @return - The String representation of the ANSI Foreground color 25 | */ 26 | public static String toAnsiForeground(Color color) { 27 | return "\u001B[38;2;" + color.getRed() + ";" + color.getGreen() + ";" + color.getBlue() + "m"; 28 | } 29 | 30 | /** 31 | * Convert a Color to ANSI Background 32 | * @param color - The Color to convert 33 | * @return - The String representation of the ANSI Background color 34 | */ 35 | public static String toAnsiBackground(Color color) { 36 | return "\u001B[48;2;" + color.getRed() + ";" + color.getGreen() + ";" + color.getBlue() + "m"; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/fr/blueberry/studio/hermes/api/utils/CommandHelper.java: -------------------------------------------------------------------------------- 1 | package fr.blueberry.studio.hermes.api.utils; 2 | 3 | import fr.blueberry.studio.hermes.api.app.Hermes; 4 | import fr.blueberry.studio.hermes.api.app.Sender; 5 | import net.dv8tion.jda.api.entities.MessageEmbed; 6 | 7 | public class CommandHelper { 8 | public static void sendCommandWrongArgs(Sender sender) { 9 | final String message = Hermes.getHermes().getHermesConfig().getWrongMessage(); 10 | final MessageEmbed embed = MessageEmbedHelper.getBuilder().setDescription(message).build(); 11 | 12 | sender.reply(embed); 13 | } 14 | 15 | public static void sendNoPermissions(Sender sender) { 16 | final String message = Hermes.getHermes().getHermesConfig().getNoPermissionMessage(); 17 | final MessageEmbed embed = MessageEmbedHelper.getBuilder().setDescription(message).build(); 18 | 19 | sender.reply(embed); 20 | } 21 | 22 | public static void sendNoCommand(Sender sender) { 23 | final String message = Hermes.getHermes().getHermesConfig().getNoCommandMessage(); 24 | final MessageEmbed embed = MessageEmbedHelper.getBuilder().setDescription(message).build(); 25 | 26 | sender.reply(embed); 27 | } 28 | } -------------------------------------------------------------------------------- /src/main/java/fr/blueberry/studio/hermes/api/utils/FileHelper.java: -------------------------------------------------------------------------------- 1 | package fr.blueberry.studio.hermes.api.utils; 2 | 3 | import java.io.File; 4 | import java.io.FileOutputStream; 5 | import java.io.IOException; 6 | import java.io.InputStream; 7 | import java.util.jar.JarEntry; 8 | import java.util.jar.JarFile; 9 | 10 | import org.apache.commons.io.IOUtils; 11 | import org.simpleyaml.configuration.file.YamlFile; 12 | 13 | public class FileHelper { 14 | 15 | /** 16 | * Copy a file inside the jar application to a destination file 17 | * @param src - The source file to copy 18 | * @param dest - The destination file 19 | * @throws IOException - If something went wrong while manipulating IOs 20 | */ 21 | public static final void copyFileFromJar(String src, String dest) throws IOException { 22 | final InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(src); 23 | final FileOutputStream out = new FileOutputStream(dest); 24 | 25 | IOUtils.copy(is, out); 26 | } 27 | 28 | /** 29 | * Copy a file from the jar. 30 | * @param src - The jar source? 31 | * @param path - The file source path in jar. 32 | * @param dest - The destination file. 33 | * @return - A copy of the jar file in destination file. 34 | * @throws IOException - If there is something wrong with I/O. 35 | */ 36 | public static final File copyFileFromJar(File src, String path, File dest) throws IOException { 37 | final JarFile jarFile = new JarFile(src); 38 | final JarEntry jarEntry = jarFile.getJarEntry(path); 39 | final InputStream is = jarFile.getInputStream(jarEntry); 40 | final FileOutputStream out = new FileOutputStream(dest); 41 | 42 | IOUtils.copy(is, out); 43 | out.close(); 44 | is.close(); 45 | jarFile.close(); 46 | 47 | return dest; 48 | } 49 | 50 | /** 51 | * Get a jar entry in a jar file. 52 | * @param jar - The jar where to get entry. 53 | * @param file - The path of the file inside the jar 54 | * @return - The file entry in jar 55 | * @throws IOException - If there is something wrong with I/O 56 | */ 57 | public static final JarEntry getFileEntry(File jar, String file) throws IOException { 58 | final JarFile jarFile = new JarFile(jar); 59 | final JarEntry jarEntry = jarFile.getJarEntry(file); 60 | 61 | jarFile.close(); 62 | 63 | return jarEntry; 64 | } 65 | 66 | /** 67 | * Parse a plugin meta file. 68 | * @param pluginFile - The plugin file to parse 69 | * @return - A yaml with all the parsed data 70 | */ 71 | public static final YamlFile parsePluginMeta(File pluginFile) throws IOException { 72 | final File tempOutFile = File.createTempFile(pluginFile.getName(), ".yml"); 73 | tempOutFile.deleteOnExit(); 74 | 75 | return new YamlFile(copyFileFromJar(pluginFile, "plugin.yml", tempOutFile)); 76 | } 77 | } -------------------------------------------------------------------------------- /src/main/java/fr/blueberry/studio/hermes/api/utils/MessageEmbedHelper.java: -------------------------------------------------------------------------------- 1 | package fr.blueberry.studio.hermes.api.utils; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | import java.awt.Color; 6 | import org.simpleyaml.configuration.file.YamlFile; 7 | 8 | import net.dv8tion.jda.api.EmbedBuilder; 9 | import net.dv8tion.jda.api.entities.MessageEmbed; 10 | 11 | public final class MessageEmbedHelper { 12 | private MessageEmbedHelper() throws IllegalAccessException { 13 | throw new IllegalAccessException(); 14 | } 15 | 16 | public static EmbedBuilder getBuilder() { 17 | return new EmbedBuilder(); 18 | } 19 | 20 | /** 21 | * Craft a fast embed message with only description. 22 | * @param description - The description of the embed 23 | * @return - The MessageEmbed freshly created 24 | */ 25 | public static MessageEmbed fastEmbed(String description) { 26 | return new EmbedBuilder().setDescription(description).build(); 27 | } 28 | 29 | /** 30 | * Craft a fast embed message with only title and description. 31 | * @param title - The title of the embed. 32 | * @param description - The description of the embed 33 | * @return - The MessageEmbed freshly created 34 | */ 35 | public static MessageEmbed fastEmbed(String title, String description) { 36 | return new EmbedBuilder().setTitle(title).setDescription(description).build(); 37 | } 38 | 39 | /** 40 | * Craft an embed from a config file with a given key 41 | * @param configKey - The base config key 42 | * @param config - The config file 43 | * @param replacements - The replacement double array 44 | * @return - The message embed freshly crafted 45 | */ 46 | public static MessageEmbed craftEmbedFromConfig(String configKey, YamlFile config, String[][] replacements) { 47 | final Map replacementsMapping = buildReplacementMap(replacements); 48 | 49 | return craftEmbedFromConfig(configKey, config, replacementsMapping); 50 | } 51 | 52 | /** 53 | * Craft an embed from a config file with a given key 54 | * @param configKey - The base config key 55 | * @param config - The config file 56 | * @param replacements - The replacement map 57 | * @return - The message embed freshly crafted 58 | */ 59 | public static MessageEmbed craftEmbedFromConfig(String configKey, YamlFile config, Map replacements) { 60 | final String title = replaceVars(config.getString(configKey + ".title"), replacements); 61 | final String description = replaceVars(config.getString(configKey + ".description"), replacements); 62 | final String image = config.getString(configKey + ".image"); 63 | final String thumbnail = config.getString(configKey + ".thumbnail"); 64 | final int r = config.getInt(configKey + ".color.r"); 65 | final int g = config.getInt(configKey + ".color.g"); 66 | final int b = config.getInt(configKey + ".color.b"); 67 | final Color color = new Color(r,g,b); 68 | 69 | final MessageEmbed embed = getBuilder() 70 | .setTitle(title) 71 | .setDescription(description) 72 | .setColor(color) 73 | .setImage(image) 74 | .setThumbnail(thumbnail) 75 | .build(); 76 | 77 | return embed; 78 | } 79 | 80 | /** 81 | * Craft an embed from a config file with a given key 82 | * @param configKey - The base config key 83 | * @param config - The config file 84 | * @return - The message embed freshly crafted 85 | */ 86 | public static MessageEmbed craftEmbedFromConfig(String configKey, YamlFile config) { 87 | return craftEmbedFromConfig(configKey, config, new HashMap<>()); 88 | } 89 | 90 | /** 91 | * Build the replacement map from a couple of String array 92 | * @param array - The array of the replacement map 93 | * @return - The replacement map ready to go 94 | */ 95 | public static Map buildReplacementMap(String[][] array) { 96 | final HashMap replacements = new HashMap<>(); 97 | 98 | for(int i = 0; i < array.length; i++) { 99 | replacements.put(array[i][0], array[i][1]); 100 | } 101 | 102 | return replacements; 103 | } 104 | 105 | /** 106 | * Replace dynamics var in a String (%var%) 107 | * @param var - The String to replace variables in 108 | * @param replacements - 109 | * @return 110 | */ 111 | private static String replaceVars(String var, Map replacements) { 112 | if(var != null) { 113 | for(String tag : replacements.keySet()) { 114 | var = var.replaceAll(tag, replacements.get(tag)); 115 | } 116 | } 117 | 118 | return var; 119 | } 120 | } -------------------------------------------------------------------------------- /src/main/java/fr/blueberry/studio/hermes/api/utils/PermissionHelper.java: -------------------------------------------------------------------------------- 1 | package fr.blueberry.studio.hermes.api.utils; 2 | 3 | import fr.blueberry.studio.hermes.api.app.Hermes; 4 | import net.dv8tion.jda.api.entities.User; 5 | 6 | public class PermissionHelper { 7 | /** 8 | * Check if a user is an operator. 9 | * @param user - The user to check 10 | * @return - True if the user id is found in operators list. 11 | */ 12 | public static boolean isOp(User user) { 13 | if(user != null) { 14 | return Hermes.getHermes().getHermesConfig().getOps().contains(user.getIdLong()); 15 | } 16 | return false; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/fr/blueberry/studio/hermes/api/utils/RandomHelper.java: -------------------------------------------------------------------------------- 1 | package fr.blueberry.studio.hermes.api.utils; 2 | 3 | import java.util.List; 4 | import java.util.concurrent.ThreadLocalRandom; 5 | 6 | public class RandomHelper { 7 | 8 | /** 9 | * Get a random value as integer and between bounds. 10 | * @param min - The min bound value 11 | * @param max - The max bound value 12 | * @return - A random number between bounds. 13 | */ 14 | public static int getRandom(int min, int max) { 15 | return ThreadLocalRandom.current().nextInt(min, max); 16 | } 17 | 18 | /** 19 | * Get a random index from a list 20 | * @param list - The list where to get random index 21 | * @return - The randomized index. 22 | */ 23 | public static int getRandomIndex(List list) { 24 | if(list.size() <= 0) { 25 | return 0; 26 | } 27 | return ThreadLocalRandom.current().nextInt(list.size()); 28 | } 29 | } -------------------------------------------------------------------------------- /src/main/java/fr/blueberry/studio/hermes/api/utils/ReflectionHelper.java: -------------------------------------------------------------------------------- 1 | package fr.blueberry.studio.hermes.api.utils; 2 | 3 | public class ReflectionHelper { 4 | 5 | /** 6 | * Get the top superclass of a class excluding 7 | * java.lang.Object 8 | */ 9 | public static Class getMaxSuperClass(Class clazz) { 10 | Class lastClass = clazz; 11 | 12 | while(clazz != Object.class) { 13 | clazz = clazz.getSuperclass(); 14 | if(clazz != Object.class) { 15 | lastClass = clazz; 16 | } 17 | } 18 | 19 | return lastClass; 20 | } 21 | } -------------------------------------------------------------------------------- /src/main/java/fr/blueberry/studio/hermes/api/utils/StringHelper.java: -------------------------------------------------------------------------------- 1 | package fr.blueberry.studio.hermes.api.utils; 2 | 3 | import java.util.ArrayList; 4 | import java.util.regex.Matcher; 5 | import java.util.regex.Pattern; 6 | 7 | public class StringHelper { 8 | /** 9 | * Split an input into args and remove the split tag. 10 | * Manage to get Strings in quote into a single arg. 11 | * @param input - The input to process 12 | * @param splitTag - The split tag to remove if exists. 13 | * @return - An array containing the splitted args. 14 | */ 15 | 16 | public static String[] argumentify(String input, char splitTag) { 17 | final String[] originalArgs = input.split(" "); 18 | final Pattern pattern = Pattern.compile("\"(.*?)\""); 19 | final Matcher matcher = pattern.matcher(input); 20 | final ArrayList matches = new ArrayList<>(); 21 | 22 | while(matcher.find()) { 23 | matches.add(matcher.group()); 24 | } 25 | 26 | for(String match : matches) { 27 | input = input.replace(match, ""); 28 | } 29 | 30 | final ArrayList finalArgs = new ArrayList<>(); 31 | 32 | int skip = 0; 33 | 34 | for (String originalArg : originalArgs) { 35 | boolean matched = false; 36 | 37 | for (String match : matches) { 38 | if (match.startsWith(originalArg)) { 39 | finalArgs.add(match.replace("\"", "")); 40 | matches.remove(match); 41 | matched = true; 42 | skip = match.split(" ").length - 1; 43 | break; 44 | } 45 | } 46 | 47 | if (!matched) { 48 | if (skip == 0) { 49 | finalArgs.add(originalArg); 50 | } else { 51 | skip--; 52 | } 53 | } 54 | } 55 | 56 | return finalArgs.toArray(String[]::new); 57 | } 58 | 59 | /** 60 | * Concatenate args into one string after a given index (including index). 61 | * @param index - The index to concat after. 62 | * @param args - The args array 63 | * @return - A string of the args with spaces. 64 | */ 65 | public static String stringify(int index, String[] args) { 66 | final StringBuilder sb = new StringBuilder(); 67 | 68 | for(int i = 0; i < args.length; i++) { 69 | if(i >= index) { 70 | sb.append(args[i]).append(" "); 71 | } 72 | } 73 | 74 | return sb.toString(); 75 | } 76 | 77 | /** 78 | * Convert a full command args with label to command args without label. 79 | * @param plainArgs - The full command args & label 80 | * @return - The args of the command without label. 81 | */ 82 | public static String[] removeCommandLabel(String[] plainArgs) { 83 | final String[] args = new String[plainArgs.length - 1]; 84 | 85 | System.arraycopy(plainArgs, 1, args, 0, args.length); 86 | 87 | return args; 88 | } 89 | 90 | /** 91 | * Capitalize the first letter of a word. 92 | * @param word - The word to capitalize 93 | * @return - The capitalized word. 94 | */ 95 | public static String capitalizeFirst(String word) { 96 | final String firstLetter = word.substring(0, 1).toUpperCase(); 97 | 98 | return firstLetter + word.substring(1); 99 | } 100 | 101 | } -------------------------------------------------------------------------------- /src/main/java/fr/blueberry/studio/hermes/api/utils/VoiceHelper.java: -------------------------------------------------------------------------------- 1 | package fr.blueberry.studio.hermes.api.utils; 2 | 3 | import fr.blueberry.studio.hermes.api.app.Hermes; 4 | import fr.blueberry.studio.hermes.api.bots.Bot; 5 | import fr.blueberry.studio.hermes.api.bots.BotManager; 6 | import net.dv8tion.jda.api.entities.Guild; 7 | import net.dv8tion.jda.api.entities.Member; 8 | import net.dv8tion.jda.api.entities.User; 9 | import net.dv8tion.jda.api.entities.VoiceChannel; 10 | 11 | public class VoiceHelper { 12 | 13 | /** 14 | * Get whether a member is in a voice channel 15 | * @param userId - The user id of the member 16 | * @param guild - The guild where to check the member voice state 17 | * @return - True if the member is connected in a voice channel 18 | */ 19 | public static boolean isInVoice(long userId, Guild guild) { 20 | return getMemberVoiceChannel(String.valueOf(userId), guild) != null; 21 | } 22 | 23 | /** 24 | * Get whether a member is in a voice channel 25 | * @param userId - The user id of the member 26 | * @param guild - The guild where to check the member voice state 27 | * @return - True if the member is connected in a voice channel 28 | */ 29 | public static boolean isInVoice(String userId, Guild guild) { 30 | return getMemberVoiceChannel(userId, guild) != null; 31 | } 32 | 33 | /** 34 | * Get the voice channel a member is currently in. 35 | * @param userId - The user id of the member 36 | * @param guild - The guild where to get voice channel from 37 | * @return - The voice channel or null 38 | */ 39 | public static VoiceChannel getMemberVoiceChannel(String userId, Guild guild) { 40 | final Member member = guild.getMemberById(userId); 41 | 42 | if(member != null) { 43 | return member.getVoiceState().getChannel(); 44 | } 45 | 46 | return null; 47 | } 48 | 49 | /** 50 | * Get the voice channel a member is currently in. 51 | * @param member - The member 52 | * @return - The voice channel or null 53 | */ 54 | public static VoiceChannel getMemberVoiceChannel(Member member) { 55 | if(member != null) { 56 | return member.getVoiceState().getChannel(); 57 | } 58 | 59 | return null; 60 | } 61 | 62 | /** 63 | * Return whether a member is in a given voice channel or not 64 | * @param member - The member to get the channel 65 | * @param voiceChannel - The voice channel to check 66 | * @return - True if the member is in this specific channel 67 | */ 68 | public static boolean isInChannel(Member member, VoiceChannel voiceChannel) { 69 | final VoiceChannel memberVoiceChannel = getMemberVoiceChannel(member); 70 | 71 | if(memberVoiceChannel != null) { 72 | return memberVoiceChannel.equals(voiceChannel); 73 | } 74 | 75 | return false; 76 | } 77 | 78 | /** 79 | * Return whether a member is in a given voice channel or not 80 | * @param user - The member to get the channel 81 | * @param voiceChannel - The voice channel to check 82 | * @return - True if the member is in this specific channel 83 | */ 84 | public static boolean isInChannel(User user, VoiceChannel voiceChannel) { 85 | if(voiceChannel != null) { 86 | final Member member = voiceChannel.getGuild().getMember(user); 87 | 88 | if(member != null) { 89 | return isInChannel(member, voiceChannel); 90 | } 91 | } 92 | 93 | return false; 94 | } 95 | 96 | /** 97 | * Return whether a bot is in given voice channel or not. 98 | * @param voiceChannel - The voice channel to ask for the bot presence. 99 | * @return - True if there is a bot inside the voice channel. 100 | */ 101 | public static boolean hasBotInChannel(VoiceChannel voiceChannel) { 102 | return getBotInChannel(voiceChannel) != null; 103 | } 104 | 105 | /** 106 | * Get the bot in the given voice channel 107 | * @param voiceChannel - The voice channel to ask for the bot. 108 | * @return - The bot or null if none is found. 109 | */ 110 | public static Bot getBotInChannel(VoiceChannel voiceChannel) { 111 | final BotManager botManager = Hermes.getHermes().getBotManager(); 112 | 113 | for(Bot bot : botManager.getAllConnectedBots()) { 114 | if(isInChannel(bot.getJDA().getSelfUser(), voiceChannel)) { 115 | return bot; 116 | } 117 | } 118 | return null; 119 | } 120 | } 121 | --------------------------------------------------------------------------------