├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── build.gradle.kts ├── buildSrc ├── build.gradle.kts ├── settings.gradle.kts └── src │ └── main │ └── kotlin │ └── net │ └── kautler │ ├── DependencyOutdatedExtension.kt │ ├── MapExtension.kt │ ├── NodeExtension.kt │ ├── NodeListExtension.kt │ ├── Properties.kt │ ├── PropertyExtension.kt │ ├── ReleaseExtensionExtension.kt │ ├── ResultExtension.kt │ ├── antlr.gradle.kts │ ├── codenarc.gradle.kts │ ├── idea.gradle.kts │ ├── jars.gradle.kts │ ├── java.gradle.kts │ ├── java9.gradle.kts │ ├── javadoc.gradle.kts │ ├── osgi.gradle.kts │ ├── pmd.gradle.kts │ ├── publishing.gradle.kts │ ├── readme.gradle.kts │ ├── spotbugs.gradle.kts │ ├── tests.gradle.kts │ └── versions.gradle.kts ├── config ├── codenarc │ └── codenarc.groovy ├── pmd │ └── pmd.xml └── spotbugs │ └── spotbugs-exclude.xml ├── examples ├── simplePingBotJavacord │ ├── .gitattributes │ ├── .gitignore │ ├── build.gradle.kts │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── settings.gradle.kts │ └── src │ │ └── main │ │ ├── java │ │ └── net │ │ │ └── kautler │ │ │ └── command │ │ │ └── example │ │ │ └── ping │ │ │ ├── CombinedPingCommand.java │ │ │ ├── JavacordProducer.java │ │ │ ├── LoggerProducer.java │ │ │ ├── PingBot.java │ │ │ ├── PingCommand.java │ │ │ ├── PingSlashCommand.java │ │ │ └── SlashCommandRegisterer.java │ │ └── resources │ │ ├── log4j2.component.properties │ │ └── log4j2.xml └── simplePingBotJda │ ├── .gitattributes │ ├── .gitignore │ ├── build.gradle.kts │ ├── gradle │ └── wrapper │ │ ├── gradle-wrapper.jar │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ ├── settings.gradle.kts │ └── src │ └── main │ ├── java │ └── net │ │ └── kautler │ │ └── command │ │ └── example │ │ └── ping │ │ ├── JdaProducer.java │ │ ├── LoggerProducer.java │ │ ├── PingBot.java │ │ └── PingCommand.java │ └── resources │ ├── log4j2.component.properties │ └── log4j2.xml ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── readme ├── README.md.sha256 └── README_template.md ├── settings.gradle.kts └── src ├── integTestCommon ├── groovy │ └── net │ │ └── kautler │ │ └── command │ │ └── integ │ │ └── test │ │ ├── ManualTests.groovy │ │ └── spock │ │ ├── AddBean.groovy │ │ ├── AddBeans.groovy │ │ ├── AddBeansExtension.groovy │ │ ├── CDIExtension.groovy │ │ ├── GlobalRetryExtension.groovy │ │ ├── VetoBean.groovy │ │ ├── VetoBeans.groovy │ │ └── VetoBeansExtension.groovy └── resources │ ├── META-INF │ └── services │ │ └── org.spockframework.runtime.extension.IGlobalExtension │ ├── log4j2-test.xml │ └── log4j2.component.properties ├── javacordIntegTest ├── groovy │ └── net │ │ └── kautler │ │ └── command │ │ └── integ │ │ └── test │ │ ├── VersionIntegTest.groovy │ │ └── javacord │ │ ├── CommandContextTransformerIntegTest.groovy │ │ ├── PingIntegTest.groovy │ │ ├── PingSlashIntegTest.groovy │ │ ├── event │ │ ├── CommandNotAllowedEventJavacordIntegTest.groovy │ │ ├── CommandNotAllowedEventJavacordSlashIntegTest.groovy │ │ ├── CommandNotFoundEventJavacordIntegTest.groovy │ │ └── CommandNotFoundEventJavacordSlashIntegTest.groovy │ │ ├── parameter │ │ ├── MissingDependencyParameterParserIntegTest.groovy │ │ ├── TypedParameterParserIntegTest.groovy │ │ └── UntypedParameterParserIntegTest.groovy │ │ ├── prefix │ │ └── MentionPrefixTransformerJavacordIntegTest.groovy │ │ ├── restriction │ │ ├── AllOfIntegTest.groovy │ │ ├── AnyOfIntegTest.groovy │ │ ├── BotOwnerJavacordIntegTest.groovy │ │ ├── ChannelJavacordIntegTest.groovy │ │ ├── EveryoneIntegTest.groovy │ │ ├── NoneOfIntegTest.groovy │ │ ├── NsfwChannelJavacordIntegTest.groovy │ │ ├── PrivateMessageJavacordIntegTest.groovy │ │ ├── ProducedRestrictionIntegTest.groovy │ │ ├── RegularUserJavacordIntegTest.groovy │ │ ├── RestrictionChainElementIntegTest.groovy │ │ ├── RestrictionPolicyIntegTest.groovy │ │ ├── RoleJavacordIntegTest.groovy │ │ ├── ServerJavacordIntegTest.groovy │ │ ├── ServerManagerJavacordIntegTest.groovy │ │ ├── ServerOwnerJavacordIntegTest.groovy │ │ ├── UserJavacordIntegTest.groovy │ │ └── slash │ │ │ ├── BotOwnerJavacordSlashIntegTest.groovy │ │ │ ├── ChannelJavacordSlashIntegTest.groovy │ │ │ ├── NsfwChannelJavacordSlashIntegTest.groovy │ │ │ ├── PrivateMessageJavacordSlashIntegTest.groovy │ │ │ ├── RoleJavacordSlashIntegTest.groovy │ │ │ ├── ServerJavacordSlashIntegTest.groovy │ │ │ ├── ServerManagerJavacordSlashIntegTest.groovy │ │ │ ├── ServerOwnerJavacordSlashIntegTest.groovy │ │ │ └── UserJavacordSlashIntegTest.groovy │ │ └── spock │ │ └── JavacordExtension.groovy └── resources │ └── META-INF │ └── services │ └── org.spockframework.runtime.extension.IGlobalExtension ├── jdaIntegTest ├── groovy │ └── net │ │ └── kautler │ │ └── command │ │ └── integ │ │ └── test │ │ └── jda │ │ ├── CommandContextTransformerIntegTest.groovy │ │ ├── PingIntegTest.groovy │ │ ├── event │ │ ├── CommandNotAllowedEventJdaIntegTest.groovy │ │ └── CommandNotFoundEventJdaIntegTest.groovy │ │ ├── parameter │ │ ├── MissingDependencyParameterParserIntegTest.groovy │ │ ├── TypedParameterParserIntegTest.groovy │ │ └── UntypedParameterParserIntegTest.groovy │ │ ├── prefix │ │ └── MentionPrefixTransformerJdaIntegTest.groovy │ │ ├── restriction │ │ ├── AllOfIntegTest.groovy │ │ ├── AnyOfIntegTest.groovy │ │ ├── BotOwnerJdaIntegTest.groovy │ │ ├── ChannelJdaIntegTest.groovy │ │ ├── EveryoneIntegTest.groovy │ │ ├── GuildJdaIntegTest.groovy │ │ ├── GuildOwnerJdaIntegTest.groovy │ │ ├── NoneOfIntegTest.groovy │ │ ├── NsfwChannelJdaIntegTest.groovy │ │ ├── PrivateMessageJdaIntegTest.groovy │ │ ├── RegularUserJdaIntegTest.groovy │ │ ├── RestrictionChainElementIntegTest.groovy │ │ ├── RestrictionPolicyIntegTest.groovy │ │ ├── RoleJdaIntegTest.groovy │ │ ├── ServerManagerJdaIntegTest.groovy │ │ └── UserJdaIntegTest.groovy │ │ └── spock │ │ └── JdaExtension.groovy └── resources │ └── META-INF │ └── services │ └── org.spockframework.runtime.extension.IGlobalExtension ├── main ├── antlr │ └── net │ │ └── kautler │ │ └── command │ │ └── usage │ │ └── Usage.g4 ├── java │ └── net │ │ └── kautler │ │ └── command │ │ ├── Internal.java │ │ ├── InvalidAnnotationCombinationException.java │ │ ├── LoggerProducer.java │ │ ├── api │ │ ├── Command.java │ │ ├── CommandContext.java │ │ ├── CommandContextTransformer.java │ │ ├── CommandHandler.java │ │ ├── Version.java │ │ ├── annotation │ │ │ ├── Alias.java │ │ │ ├── Aliases.java │ │ │ ├── Asynchronous.java │ │ │ ├── Description.java │ │ │ ├── RestrictedTo.java │ │ │ ├── RestrictionPolicy.java │ │ │ ├── Restrictions.java │ │ │ └── Usage.java │ │ ├── event │ │ │ ├── CommandEvent.java │ │ │ ├── javacord │ │ │ │ ├── CommandNotAllowedEventJavacord.java │ │ │ │ ├── CommandNotAllowedEventJavacordSlash.java │ │ │ │ ├── CommandNotFoundEventJavacord.java │ │ │ │ └── CommandNotFoundEventJavacordSlash.java │ │ │ └── jda │ │ │ │ ├── CommandNotAllowedEventJda.java │ │ │ │ └── CommandNotFoundEventJda.java │ │ ├── parameter │ │ │ ├── InvalidParameterFormatException.java │ │ │ ├── InvalidParameterValueException.java │ │ │ ├── ParameterConverter.java │ │ │ ├── ParameterParseException.java │ │ │ ├── ParameterParser.java │ │ │ ├── ParameterType.java │ │ │ ├── ParameterTypes.java │ │ │ └── Parameters.java │ │ ├── prefix │ │ │ ├── javacord │ │ │ │ └── MentionPrefixTransformerJavacord.java │ │ │ └── jda │ │ │ │ └── MentionPrefixTransformerJda.java │ │ ├── restriction │ │ │ ├── AllOf.java │ │ │ ├── AnyOf.java │ │ │ ├── Everyone.java │ │ │ ├── NoneOf.java │ │ │ ├── Restriction.java │ │ │ ├── RestrictionChainElement.java │ │ │ ├── javacord │ │ │ │ ├── BotOwnerJavacord.java │ │ │ │ ├── ChannelJavacord.java │ │ │ │ ├── NsfwChannelJavacord.java │ │ │ │ ├── PrivateMessageJavacord.java │ │ │ │ ├── RegularUserJavacord.java │ │ │ │ ├── RoleJavacord.java │ │ │ │ ├── ServerJavacord.java │ │ │ │ ├── ServerManagerJavacord.java │ │ │ │ ├── ServerOwnerJavacord.java │ │ │ │ ├── UserJavacord.java │ │ │ │ └── slash │ │ │ │ │ ├── BotOwnerJavacordSlash.java │ │ │ │ │ ├── ChannelJavacordSlash.java │ │ │ │ │ ├── NsfwChannelJavacordSlash.java │ │ │ │ │ ├── PrivateMessageJavacordSlash.java │ │ │ │ │ ├── RoleJavacordSlash.java │ │ │ │ │ ├── ServerJavacordSlash.java │ │ │ │ │ ├── ServerManagerJavacordSlash.java │ │ │ │ │ ├── ServerOwnerJavacordSlash.java │ │ │ │ │ └── UserJavacordSlash.java │ │ │ └── jda │ │ │ │ ├── BotOwnerJda.java │ │ │ │ ├── ChannelJda.java │ │ │ │ ├── GuildJda.java │ │ │ │ ├── GuildOwnerJda.java │ │ │ │ ├── NsfwChannelJda.java │ │ │ │ ├── PrivateMessageJda.java │ │ │ │ ├── RegularUserJda.java │ │ │ │ ├── RoleJda.java │ │ │ │ ├── ServerManagerJda.java │ │ │ │ └── UserJda.java │ │ └── slash │ │ │ └── javacord │ │ │ └── SlashCommandJavacord.java │ │ ├── handler │ │ ├── CommandHandlerJavacord.java │ │ ├── CommandHandlerJavacordSlash.java │ │ └── CommandHandlerJda.java │ │ ├── parameter │ │ ├── ParametersImpl.java │ │ ├── converter │ │ │ ├── DecimalConverter.java │ │ │ ├── NumberConverter.java │ │ │ ├── StringConverter.java │ │ │ ├── javacord │ │ │ │ ├── ChannelMentionConverterJavacord.java │ │ │ │ ├── RoleMentionConverterJavacord.java │ │ │ │ └── UserMentionConverterJavacord.java │ │ │ └── jda │ │ │ │ ├── ChannelMentionConverterJda.java │ │ │ │ ├── RoleMentionConverterJda.java │ │ │ │ └── UserMentionConverterJda.java │ │ └── parser │ │ │ ├── BaseParameterParser.java │ │ │ ├── TypedParameterParser.java │ │ │ ├── UntypedParameterParser.java │ │ │ └── missingdependency │ │ │ └── MissingDependencyParameterParser.java │ │ ├── usage │ │ ├── UsageErrorListener.java │ │ ├── UsageParserRuleContext.java │ │ └── UsagePatternBuilder.java │ │ └── util │ │ ├── ExceptionUtil.java │ │ ├── SlashCommandBuilderProducer.java │ │ └── lazy │ │ ├── LazyReference.java │ │ ├── LazyReferenceByFunction.java │ │ └── LazyReferenceBySupplier.java └── resources │ ├── META-INF │ └── beans.xml │ └── net │ └── kautler │ └── command │ └── api │ └── version.properties ├── pitest ├── java │ └── net │ │ └── kautler │ │ └── test │ │ └── pitest │ │ ├── DuplicateMutationFilter.java │ │ ├── ExplicitMutationFilter.java │ │ ├── ExplicitMutationFilterDetails.java │ │ ├── MutationFilterFactory.java │ │ ├── SpockConfiguration.java │ │ ├── SpockTestPlugin.java │ │ ├── SpockTestUnitFinder.java │ │ ├── SurvivorDetector.java │ │ ├── SurvivorDetectorFactory.java │ │ ├── UncoveredDetector.java │ │ └── UncoveredDetectorFactory.java └── resources │ └── META-INF │ └── services │ ├── org.pitest.mutationtest.MutationResultListenerFactory │ ├── org.pitest.mutationtest.build.MutationInterceptorFactory │ └── org.pitest.testapi.TestPluginFactory ├── spock ├── java │ └── net │ │ └── kautler │ │ └── test │ │ └── spock │ │ ├── AnonymousClassTransform.java │ │ ├── EagerExceptionRenderer.java │ │ └── TestAppenderClearer.java └── resources │ └── META-INF │ └── services │ ├── org.codehaus.groovy.transform.ASTTransformation │ └── org.spockframework.runtime.extension.IGlobalExtension └── test ├── groovy └── net │ └── kautler │ ├── command │ ├── InvalidAnnotationCombinationExceptionTest.groovy │ ├── LoggerProducerTest.groovy │ ├── api │ │ ├── CommandContextBuilderTest.groovy │ │ ├── CommandContextTest.groovy │ │ ├── CommandHandlerTest.groovy │ │ ├── CommandTest.groovy │ │ ├── VersionTest.groovy │ │ ├── event │ │ │ ├── CommandEventTest.groovy │ │ │ ├── javacord │ │ │ │ ├── CommandNotAllowedEventJavacordSlashTest.groovy │ │ │ │ ├── CommandNotAllowedEventJavacordTest.groovy │ │ │ │ ├── CommandNotFoundEventJavacordSlashTest.groovy │ │ │ │ └── CommandNotFoundEventJavacordTest.groovy │ │ │ └── jda │ │ │ │ ├── CommandNotAllowedEventJdaTest.groovy │ │ │ │ └── CommandNotFoundEventJdaTest.groovy │ │ ├── parameter │ │ │ ├── InvalidParameterFormatExceptionTest.groovy │ │ │ ├── InvalidParameterValueExceptionTest.groovy │ │ │ └── ParameterParseExceptionTest.groovy │ │ ├── prefix │ │ │ ├── javacord │ │ │ │ └── MentionPrefixTransformerJavacordTest.groovy │ │ │ └── jda │ │ │ │ └── MentionPrefixTransformerJdaTest.groovy │ │ ├── restriction │ │ │ ├── AllOfTest.groovy │ │ │ ├── AnyOfTest.groovy │ │ │ ├── EveryoneTest.groovy │ │ │ ├── NoneOfTest.groovy │ │ │ ├── RestrictionChainElementTest.groovy │ │ │ ├── javacord │ │ │ │ ├── BotOwnerJavacordTest.groovy │ │ │ │ ├── ChannelJavacordTest.groovy │ │ │ │ ├── NsfwChannelJavacordTest.groovy │ │ │ │ ├── PrivateMessageJavacordTest.groovy │ │ │ │ ├── RegularUserJavacordTest.groovy │ │ │ │ ├── RoleJavacordTest.groovy │ │ │ │ ├── ServerJavacordTest.groovy │ │ │ │ ├── ServerManagerJavacordTest.groovy │ │ │ │ ├── ServerOwnerJavacordTest.groovy │ │ │ │ ├── UserJavacordTest.groovy │ │ │ │ └── slash │ │ │ │ │ ├── BotOwnerJavacordSlashTest.groovy │ │ │ │ │ ├── ChannelJavacordSlashTest.groovy │ │ │ │ │ ├── NsfwChannelJavacordSlashTest.groovy │ │ │ │ │ ├── PrivateMessageJavacordSlashTest.groovy │ │ │ │ │ ├── RoleJavacordSlashTest.groovy │ │ │ │ │ ├── ServerJavacordSlashTest.groovy │ │ │ │ │ ├── ServerManagerJavacordSlashTest.groovy │ │ │ │ │ ├── ServerOwnerJavacordSlashTest.groovy │ │ │ │ │ └── UserJavacordSlashTest.groovy │ │ │ └── jda │ │ │ │ ├── BotOwnerJdaTest.groovy │ │ │ │ ├── ChannelJdaTest.groovy │ │ │ │ ├── GuildJdaTest.groovy │ │ │ │ ├── GuildOwnerJdaTest.groovy │ │ │ │ ├── NsfwChannelJdaTest.groovy │ │ │ │ ├── PrivateMessageJdaTest.groovy │ │ │ │ ├── RegularUserJdaTest.groovy │ │ │ │ ├── RoleJdaTest.groovy │ │ │ │ ├── ServerManagerJdaTest.groovy │ │ │ │ └── UserJdaTest.groovy │ │ └── slash │ │ │ └── javacord │ │ │ └── SlashCommandJavacordTest.groovy │ ├── handler │ │ ├── CommandHandlerJavacordSlashTest.groovy │ │ ├── CommandHandlerJavacordTest.groovy │ │ └── CommandHandlerJdaTest.groovy │ ├── parameter │ │ ├── ParametersImplTest.groovy │ │ ├── converter │ │ │ ├── DecimalConverterTest.groovy │ │ │ ├── NumberConverterTest.groovy │ │ │ ├── StringConverterTest.groovy │ │ │ ├── javacord │ │ │ │ ├── ChannelMentionConverterJavacordTest.groovy │ │ │ │ ├── RoleMentionConverterJavacordTest.groovy │ │ │ │ └── UserMentionConverterJavacordTest.groovy │ │ │ └── jda │ │ │ │ ├── ChannelMentionConverterJdaTest.groovy │ │ │ │ ├── RoleMentionConverterJdaTest.groovy │ │ │ │ └── UserMentionConverterJdaTest.groovy │ │ └── parser │ │ │ ├── BaseParameterParserTest.groovy │ │ │ ├── TypedParameterParserTest.groovy │ │ │ ├── UntypedParameterParserTest.groovy │ │ │ └── missingdependency │ │ │ └── MissingDependencyParameterParserTest.groovy │ ├── usage │ │ ├── UsageErrorListenerTest.groovy │ │ ├── UsageParserRuleContextTest.groovy │ │ └── UsagePatternBuilderTest.groovy │ └── util │ │ ├── ExceptionUtilTest.groovy │ │ ├── SlashCommandBuilderProducerTest.groovy │ │ ├── SlashCommandBuilderProducerWithoutCommandsTest.groovy │ │ └── lazy │ │ ├── LazyReferenceByFunctionTest.groovy │ │ ├── LazyReferenceBySupplierTest.groovy │ │ └── LazyReferenceTest.groovy │ └── test │ ├── ContextualInstanceCategory.groovy │ ├── PrivateFinalFieldSetterCategory.groovy │ └── protocol │ └── testproperties │ └── Handler.groovy └── resources ├── log4j2-test.xml ├── log4j2.component.properties └── weld.properties /.gitattributes: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Björn Kautler 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | * text=auto 16 | /gradlew eol=lf 17 | /gradlew.bat eol=crlf 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Björn Kautler 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | /.gradle/ 16 | /.idea/ 17 | /build/ 18 | /buildSrc/.gradle/ 19 | /buildSrc/build/ 20 | /command-framework.iml 21 | -------------------------------------------------------------------------------- /build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | plugins { 18 | net.kautler.idea 19 | net.kautler.versions 20 | net.kautler.java 21 | net.kautler.jars 22 | net.kautler.antlr 23 | net.kautler.osgi 24 | net.kautler.tests 25 | net.kautler.codenarc 26 | net.kautler.pmd 27 | net.kautler.spotbugs 28 | net.kautler.java9 29 | net.kautler.javadoc 30 | net.kautler.readme 31 | net.kautler.publishing 32 | } 33 | 34 | defaultTasks("build") 35 | tasks.register("generate") 36 | -------------------------------------------------------------------------------- /buildSrc/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/net/kautler/DependencyOutdatedExtension.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler 18 | 19 | import com.github.benmanes.gradle.versions.reporter.result.DependencyOutdated 20 | 21 | fun DependencyOutdated.matches(group: String, name: String, oldVersion: String? = null, newVersion: String? = null) = 22 | (this.group == group) 23 | && (this.name == name) 24 | && oldVersion?.let { it == version } ?: true 25 | && newVersion?.let { it == this.available.milestone } ?: true 26 | -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/net/kautler/MapExtension.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler 18 | 19 | fun Map.safeGet(key: K): V = get(key) ?: error("Key '$key' is missing") 20 | -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/net/kautler/NodeExtension.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler 18 | 19 | import org.w3c.dom.Node 20 | import org.w3c.dom.Node.TEXT_NODE 21 | 22 | fun T.removeEmptyTextNodes(): T { 23 | childNodes.asList().forEach { 24 | if ((it.nodeType == TEXT_NODE) && it.nodeValue.isBlank()) { 25 | removeChild(it) 26 | } else { 27 | it.removeEmptyTextNodes() 28 | } 29 | } 30 | return this 31 | } 32 | -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/net/kautler/NodeListExtension.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler 18 | 19 | import org.w3c.dom.NodeList 20 | 21 | fun NodeList.asList() = (0 until length).map(::item) 22 | -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/net/kautler/PropertyExtension.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler 18 | 19 | import org.gradle.api.file.FileSystemLocation 20 | import org.gradle.api.file.FileSystemLocationProperty 21 | import org.gradle.api.provider.HasMultipleValues 22 | import org.gradle.api.provider.MapProperty 23 | import org.gradle.api.provider.Property 24 | import org.gradle.api.provider.Provider 25 | import java.io.File 26 | 27 | @Suppress("UnstableApiUsage") 28 | operator fun Property.invoke(value: T) = set(value) 29 | 30 | @Suppress("UnstableApiUsage") 31 | operator fun Property.invoke(provider: Provider) = set(provider) 32 | 33 | @Suppress("UnstableApiUsage") 34 | operator fun HasMultipleValues.invoke(elements: Iterable) = set(elements) 35 | 36 | @Suppress("UnstableApiUsage") 37 | operator fun HasMultipleValues.invoke(provider: Provider>) = set(provider) 38 | 39 | @Suppress("UnstableApiUsage") 40 | operator fun MapProperty.invoke(entries: Map) = set(entries) 41 | 42 | @Suppress("UnstableApiUsage") 43 | operator fun MapProperty.invoke(provider: Provider>) = set(provider) 44 | 45 | @Suppress("UnstableApiUsage") 46 | operator fun FileSystemLocationProperty.invoke(file: File) = set(file) 47 | -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/net/kautler/ReleaseExtensionExtension.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler 18 | 19 | import net.researchgate.release.GitAdapter.GitConfig 20 | import net.researchgate.release.ReleaseExtension 21 | 22 | fun ReleaseExtension.git(configure: GitConfig.() -> Unit) = (getProperty("git") as GitConfig).configure() 23 | -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/net/kautler/ResultExtension.kt: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler 18 | 19 | import com.github.benmanes.gradle.versions.reporter.result.Result 20 | 21 | fun Result.updateCounts() { 22 | val dependencyGroups = listOf(current, outdated, exceeded, unresolved) 23 | dependencyGroups.forEach { 24 | it.count = it.dependencies.size 25 | } 26 | count = dependencyGroups.map { it.count }.sum() 27 | } 28 | -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/net/kautler/antlr.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2020 Bjoern Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler 18 | 19 | plugins { 20 | `java-library` 21 | antlr 22 | idea 23 | } 24 | 25 | java { 26 | val main by sourceSets 27 | registerFeature("parameterParser") { 28 | usingSourceSet(main) 29 | } 30 | } 31 | 32 | // work-around for https://github.com/gradle/gradle/issues/820 33 | configurations { 34 | compile { 35 | setExtendsFrom(extendsFrom.filterNot { it == antlr.get() }) 36 | } 37 | } 38 | 39 | dependencies { 40 | val versions: Map by project 41 | antlr("org.antlr:antlr4:${versions["antlr"]}") 42 | "parameterParserImplementation"("org.antlr:antlr4-runtime:${versions["antlr"]}") 43 | } 44 | 45 | tasks.withType().configureEach { 46 | arguments.apply { 47 | add("-no-listener") 48 | add("-visitor") 49 | add("-Werror") 50 | } 51 | } 52 | 53 | val generateGrammarSource by tasks.existing(AntlrTask::class) 54 | 55 | tasks.matching { it.name == "generate" }.configureEach { 56 | dependsOn(generateGrammarSource) 57 | } 58 | 59 | idea.module { 60 | generatedSourceDirs.add(generateGrammarSource.get().outputDirectory) 61 | } 62 | -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/net/kautler/codenarc.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Bjoern Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler 18 | 19 | plugins { 20 | java 21 | codenarc 22 | } 23 | 24 | val versions: Map by project 25 | 26 | codenarc { 27 | toolVersion = versions.safeGet("codenarc") 28 | // customized copy from http://codenarc.sourceforge.net/StarterRuleSet-AllRulesByCategory.groovy.txt 29 | // update with new rules when version is updated (previous version: 1.4) 30 | config = resources.text.fromFile("config/codenarc/codenarc.groovy") 31 | } 32 | 33 | tasks.withType().configureEach { 34 | val sourceSetName = name.replaceFirst("^codenarc".toRegex(), "").decapitalize() 35 | @Suppress("UnstableApiUsage") 36 | compilationClasspath = sourceSets[sourceSetName].let { 37 | it.runtimeClasspath + it.compileClasspath + project.configurations[it.compileOnlyConfigurationName] 38 | } 39 | 40 | @Suppress("UnstableApiUsage") 41 | reports.xml.isEnabled = true 42 | } 43 | -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/net/kautler/idea.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Bjoern Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler 18 | 19 | plugins { 20 | idea 21 | } 22 | 23 | // prevent split output paths which do not work properly with CDI 24 | idea.module { 25 | outputDir = file("$buildDir/classes/idea") 26 | testOutputDir = file("$buildDir/classes/idea-test") 27 | } 28 | -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/net/kautler/jars.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Bjoern Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler 18 | 19 | plugins { 20 | java 21 | } 22 | 23 | val javadocJar by tasks.registering(Jar::class) { 24 | group = "build" 25 | description = "Assembles a jar archive containing the JavaDoc files." 26 | archiveClassifier("javadoc") 27 | from(tasks.javadoc) 28 | } 29 | 30 | val sourcesJar by tasks.registering(Jar::class) { 31 | group = "build" 32 | description = "Assembles a jar archive containing the Java source files." 33 | archiveClassifier("sources") 34 | val main by sourceSets 35 | from(main.allJava) 36 | } 37 | 38 | artifacts { 39 | archives(javadocJar) 40 | archives(sourcesJar) 41 | } 42 | -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/net/kautler/osgi.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Bjoern Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler 18 | 19 | import aQute.bnd.gradle.BundleTaskConvention 20 | 21 | plugins { 22 | id("biz.aQute.bnd.builder") 23 | } 24 | 25 | tasks.jar { 26 | withConvention(BundleTaskConvention::class) { 27 | val version by archiveVersion 28 | bnd(mapOf( 29 | "Import-Package" to listOf( 30 | listOf( 31 | "org.javacord.*", 32 | "resolution:=optional" 33 | ).joinToString(";"), 34 | listOf( 35 | "net.dv8tion.jda.*", 36 | "resolution:=optional" 37 | ).joinToString(";"), 38 | "*" 39 | ).joinToString(), 40 | "Export-Package" to listOf( 41 | "net.kautler.command.api.*", 42 | "version=$version", 43 | "-noimport:=true" 44 | ).joinToString(";"), 45 | // work-around for https://github.com/bndtools/bnd/issues/2227 46 | "-fixupmessages" to "^Classes found in the wrong directory: \\\\{META-INF/versions/9/module-info\\\\.class=module-info}$" 47 | )) 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /buildSrc/src/main/kotlin/net/kautler/pmd.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Bjoern Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler 18 | 19 | plugins { 20 | pmd 21 | } 22 | 23 | val versions: Map by project 24 | 25 | pmd { 26 | toolVersion = versions.safeGet("pmd") 27 | // necessary due to https://github.com/gradle/gradle/issues/8514 28 | ruleSets.clear() 29 | ruleSetConfig = resources.text.fromFile("config/pmd/pmd.xml") 30 | incrementalAnalysis(true) 31 | } 32 | 33 | tasks.named("pmdMain") { 34 | exclude("net/kautler/command/usage/UsageBaseListener.java") 35 | exclude("net/kautler/command/usage/UsageBaseVisitor.java") 36 | exclude("net/kautler/command/usage/UsageLexer.java") 37 | exclude("net/kautler/command/usage/UsageListener.java") 38 | exclude("net/kautler/command/usage/UsageParser.java") 39 | exclude("net/kautler/command/usage/UsageVisitor.java") 40 | } 41 | -------------------------------------------------------------------------------- /examples/simplePingBotJavacord/.gitattributes: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Björn Kautler 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | /gradlew eol=lf 16 | /gradlew.bat eol=crlf 17 | -------------------------------------------------------------------------------- /examples/simplePingBotJavacord/.gitignore: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Björn Kautler 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | /.gradle/ 16 | /.idea/ 17 | /build/ 18 | -------------------------------------------------------------------------------- /examples/simplePingBotJavacord/build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | plugins { 18 | application 19 | } 20 | 21 | repositories { 22 | mavenCentral() 23 | } 24 | 25 | dependencies { 26 | implementation("net.kautler:command-framework") 27 | 28 | implementation("jakarta.enterprise:jakarta.enterprise.cdi-api:3.0.0") 29 | implementation("jakarta.inject:jakarta.inject-api:2.0.0") 30 | runtimeOnly("org.jboss.weld.se:weld-se-core:4.0.3.Final") { because("CDI implementation") } 31 | runtimeOnly("org.jboss:jandex:2.1.1.Final") { because("faster CDI bean scanning") } 32 | 33 | implementation("org.javacord:javacord:3.4.0") 34 | implementation(platform("org.apache.logging.log4j:log4j-bom:2.17.2")) 35 | implementation("org.apache.logging.log4j:log4j-api") 36 | 37 | runtimeOnly("org.apache.logging.log4j:log4j-core") 38 | runtimeOnly("org.fusesource.jansi:jansi:1.18") { because("ANSI colors on Windows") } 39 | } 40 | 41 | application { 42 | mainClassName = "net.kautler.command.example.ping.PingBot" 43 | } 44 | -------------------------------------------------------------------------------- /examples/simplePingBotJavacord/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Vampire/command-framework/7574ecdef8be3995ce4d814fd286989191a92c69/examples/simplePingBotJavacord/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /examples/simplePingBotJavacord/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /examples/simplePingBotJavacord/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | rootProject.name = "simplePingBotJavacord" 18 | includeBuild("../..") 19 | -------------------------------------------------------------------------------- /examples/simplePingBotJavacord/src/main/java/net/kautler/command/example/ping/JavacordProducer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.example.ping; 18 | 19 | import jakarta.enterprise.context.ApplicationScoped; 20 | import jakarta.enterprise.inject.Disposes; 21 | import jakarta.enterprise.inject.Produces; 22 | import jakarta.inject.Inject; 23 | import jakarta.inject.Named; 24 | import org.apache.logging.log4j.Logger; 25 | import org.javacord.api.DiscordApi; 26 | import org.javacord.api.DiscordApiBuilder; 27 | 28 | @ApplicationScoped 29 | class JavacordProducer { 30 | @Inject 31 | Logger logger; 32 | 33 | @Inject 34 | @Named 35 | String discordToken; 36 | 37 | @Produces 38 | @ApplicationScoped 39 | DiscordApi produceDiscordApi() { 40 | return new DiscordApiBuilder() 41 | .setToken(discordToken) 42 | .login() 43 | .whenComplete((discordApi, throwable) -> { 44 | if (throwable != null) { 45 | logger.error("Exception while logging in to Discord", throwable); 46 | } 47 | }) 48 | .join(); 49 | } 50 | 51 | private void disposeDiscordApi(@Disposes DiscordApi discordApi) { 52 | discordApi.disconnect(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /examples/simplePingBotJavacord/src/main/java/net/kautler/command/example/ping/LoggerProducer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.example.ping; 18 | 19 | import jakarta.enterprise.context.ApplicationScoped; 20 | import jakarta.enterprise.inject.Produces; 21 | import jakarta.enterprise.inject.spi.InjectionPoint; 22 | import org.apache.logging.log4j.LogManager; 23 | import org.apache.logging.log4j.Logger; 24 | 25 | @ApplicationScoped 26 | class LoggerProducer { 27 | @Produces 28 | Logger getLogger(InjectionPoint injectionPoint) { 29 | return LogManager.getLogger(injectionPoint.getMember().getDeclaringClass()); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /examples/simplePingBotJavacord/src/main/java/net/kautler/command/example/ping/PingBot.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.example.ping; 18 | 19 | import jakarta.enterprise.context.ApplicationScoped; 20 | import jakarta.enterprise.inject.Produces; 21 | import jakarta.enterprise.inject.se.SeContainerInitializer; 22 | import jakarta.inject.Named; 23 | 24 | import static java.lang.Boolean.FALSE; 25 | import static java.lang.Boolean.TRUE; 26 | 27 | @ApplicationScoped 28 | public class PingBot { 29 | @Produces 30 | @Named 31 | static String discordToken; 32 | 33 | public static void main(String[] args) { 34 | if (args.length != 1) { 35 | System.err.println("Please supply a Discord Bot token as sole argument"); 36 | System.exit(1); 37 | } 38 | discordToken = args[0]; 39 | SeContainerInitializer.newInstance() 40 | .addProperty("jakarta.enterprise.inject.scan.implicit", TRUE) 41 | .addProperty("org.jboss.weld.construction.relaxed", FALSE) 42 | .initialize(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /examples/simplePingBotJavacord/src/main/java/net/kautler/command/example/ping/PingCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.example.ping; 18 | 19 | import jakarta.enterprise.context.ApplicationScoped; 20 | import jakarta.inject.Inject; 21 | import net.kautler.command.api.Command; 22 | import net.kautler.command.api.CommandContext; 23 | import org.apache.logging.log4j.Logger; 24 | import org.javacord.api.entity.message.Message; 25 | 26 | @ApplicationScoped 27 | class PingCommand implements Command { 28 | @Inject 29 | Logger logger; 30 | 31 | @Override 32 | public void execute(CommandContext commandContext) { 33 | commandContext 34 | .getMessage() 35 | .getChannel() 36 | .sendMessage(commandContext 37 | .getParameterString() 38 | .filter(nonce -> !nonce.isEmpty()) 39 | .map(nonce -> "pong: " + nonce) 40 | .orElse("pong")) 41 | .whenComplete((sentMessage, throwable) -> { 42 | if (throwable != null) { 43 | logger.error("Exception while executing ping command", throwable); 44 | } 45 | }); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /examples/simplePingBotJavacord/src/main/java/net/kautler/command/example/ping/SlashCommandRegisterer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.example.ping; 18 | 19 | import java.util.List; 20 | 21 | import jakarta.enterprise.context.ApplicationScoped; 22 | import jakarta.enterprise.context.Initialized; 23 | import jakarta.enterprise.event.Observes; 24 | import jakarta.inject.Inject; 25 | import org.apache.logging.log4j.Logger; 26 | import org.javacord.api.DiscordApi; 27 | import org.javacord.api.interaction.SlashCommandBuilder; 28 | 29 | @ApplicationScoped 30 | public class SlashCommandRegisterer { 31 | @Inject 32 | Logger logger; 33 | 34 | @Inject 35 | DiscordApi discordApi; 36 | 37 | @Inject 38 | List slashCommandBuilders; 39 | 40 | void registerSlashCommands(@Observes @Initialized(ApplicationScoped.class) Object __) { 41 | discordApi 42 | .bulkOverwriteGlobalApplicationCommands(slashCommandBuilders) 43 | .whenComplete((slashCommands, throwable) -> { 44 | if (throwable != null) { 45 | logger.error("Exception while registering slash commands", throwable); 46 | } 47 | }); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /examples/simplePingBotJavacord/src/main/resources/log4j2.component.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Vampire/command-framework/7574ecdef8be3995ce4d814fd286989191a92c69/examples/simplePingBotJavacord/src/main/resources/log4j2.component.properties -------------------------------------------------------------------------------- /examples/simplePingBotJavacord/src/main/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 22 | <%-35.35t> <%x> <%X> <%50.50c> %m}%n]]> 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /examples/simplePingBotJda/.gitattributes: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Björn Kautler 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | /gradlew eol=lf 16 | /gradlew.bat eol=crlf 17 | -------------------------------------------------------------------------------- /examples/simplePingBotJda/.gitignore: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Björn Kautler 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | /.gradle/ 16 | /.idea/ 17 | /build/ 18 | -------------------------------------------------------------------------------- /examples/simplePingBotJda/build.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | plugins { 18 | application 19 | } 20 | 21 | repositories { 22 | mavenCentral() 23 | maven("https://m2.dv8tion.net/releases") 24 | } 25 | 26 | dependencies { 27 | implementation("net.kautler:command-framework") 28 | 29 | implementation("jakarta.enterprise:jakarta.enterprise.cdi-api:3.0.0") 30 | implementation("jakarta.inject:jakarta.inject-api:2.0.0") 31 | runtimeOnly("org.jboss.weld.se:weld-se-core:4.0.3.Final") { because("CDI implementation") } 32 | runtimeOnly("org.jboss:jandex:2.1.1.Final") { because("faster CDI bean scanning") } 33 | 34 | implementation("net.dv8tion:JDA:4.4.0_352") { 35 | exclude("club.minnced", "opus-java") 36 | exclude("com.google.code.findbugs", "jsr305") 37 | } 38 | implementation(platform("org.apache.logging.log4j:log4j-bom:2.17.2")) 39 | implementation("org.apache.logging.log4j:log4j-api") 40 | 41 | runtimeOnly("org.apache.logging.log4j:log4j-slf4j-impl") 42 | runtimeOnly("org.apache.logging.log4j:log4j-core") 43 | runtimeOnly("org.fusesource.jansi:jansi:1.18") { because("ANSI colors on Windows") } 44 | } 45 | 46 | application { 47 | mainClassName = "net.kautler.command.example.ping.PingBot" 48 | } 49 | -------------------------------------------------------------------------------- /examples/simplePingBotJda/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Vampire/command-framework/7574ecdef8be3995ce4d814fd286989191a92c69/examples/simplePingBotJda/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /examples/simplePingBotJda/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /examples/simplePingBotJda/settings.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | rootProject.name = "simplePingBotJda" 18 | includeBuild("../..") 19 | -------------------------------------------------------------------------------- /examples/simplePingBotJda/src/main/java/net/kautler/command/example/ping/JdaProducer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.example.ping; 18 | 19 | import jakarta.enterprise.context.ApplicationScoped; 20 | import jakarta.enterprise.inject.Disposes; 21 | import jakarta.enterprise.inject.Produces; 22 | import jakarta.inject.Inject; 23 | import jakarta.inject.Named; 24 | import net.dv8tion.jda.api.JDA; 25 | import net.dv8tion.jda.api.JDABuilder; 26 | import org.apache.logging.log4j.Logger; 27 | 28 | import javax.security.auth.login.LoginException; 29 | 30 | @ApplicationScoped 31 | class JdaProducer { 32 | @Inject 33 | Logger logger; 34 | 35 | @Inject 36 | @Named 37 | String discordToken; 38 | 39 | @Produces 40 | @ApplicationScoped 41 | JDA produceJda() { 42 | try { 43 | return JDABuilder 44 | .createLight(discordToken) 45 | .build() 46 | .awaitReady(); 47 | } catch (InterruptedException | LoginException e) { 48 | logger.error("Exception while logging in to Discord", e); 49 | return null; 50 | } 51 | } 52 | 53 | private void disposeJda(@Disposes JDA jda) { 54 | jda.shutdown(); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /examples/simplePingBotJda/src/main/java/net/kautler/command/example/ping/LoggerProducer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.example.ping; 18 | 19 | import jakarta.enterprise.context.ApplicationScoped; 20 | import jakarta.enterprise.inject.Produces; 21 | import jakarta.enterprise.inject.spi.InjectionPoint; 22 | import org.apache.logging.log4j.LogManager; 23 | import org.apache.logging.log4j.Logger; 24 | 25 | @ApplicationScoped 26 | class LoggerProducer { 27 | @Produces 28 | Logger getLogger(InjectionPoint injectionPoint) { 29 | return LogManager.getLogger(injectionPoint.getMember().getDeclaringClass()); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /examples/simplePingBotJda/src/main/java/net/kautler/command/example/ping/PingBot.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.example.ping; 18 | 19 | import jakarta.enterprise.context.ApplicationScoped; 20 | import jakarta.enterprise.inject.Produces; 21 | import jakarta.enterprise.inject.se.SeContainerInitializer; 22 | import jakarta.inject.Named; 23 | 24 | import static java.lang.Boolean.FALSE; 25 | import static java.lang.Boolean.TRUE; 26 | 27 | @ApplicationScoped 28 | public class PingBot { 29 | @Produces 30 | @Named 31 | static String discordToken; 32 | 33 | public static void main(String[] args) { 34 | if (args.length != 1) { 35 | System.err.println("Please supply a Discord Bot token as sole argument"); 36 | System.exit(1); 37 | } 38 | discordToken = args[0]; 39 | SeContainerInitializer.newInstance() 40 | .addProperty("jakarta.enterprise.inject.scan.implicit", TRUE) 41 | .addProperty("org.jboss.weld.construction.relaxed", FALSE) 42 | .initialize(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /examples/simplePingBotJda/src/main/java/net/kautler/command/example/ping/PingCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.example.ping; 18 | 19 | import jakarta.enterprise.context.ApplicationScoped; 20 | import jakarta.inject.Inject; 21 | import net.dv8tion.jda.api.entities.Message; 22 | import net.kautler.command.api.Command; 23 | import net.kautler.command.api.CommandContext; 24 | import org.apache.logging.log4j.Logger; 25 | 26 | @ApplicationScoped 27 | class PingCommand implements Command { 28 | @Inject 29 | Logger logger; 30 | 31 | @Override 32 | public void execute(CommandContext commandContext) { 33 | commandContext 34 | .getMessage() 35 | .getChannel() 36 | .sendMessage(commandContext 37 | .getParameterString() 38 | .filter(nonce -> !nonce.isEmpty()) 39 | .map(nonce -> "pong: " + nonce) 40 | .orElse("pong")) 41 | .queue(null, throwable -> logger.error("Exception while executing ping command", throwable)); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /examples/simplePingBotJda/src/main/resources/log4j2.component.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Vampire/command-framework/7574ecdef8be3995ce4d814fd286989191a92c69/examples/simplePingBotJda/src/main/resources/log4j2.component.properties -------------------------------------------------------------------------------- /examples/simplePingBotJda/src/main/resources/log4j2.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 22 | <%-35.35t> <%x> <%X> <%50.50c> %m}%n]]> 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | -------------------------------------------------------------------------------- /gradle.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Vampire/command-framework/7574ecdef8be3995ce4d814fd286989191a92c69/gradle.properties -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Vampire/command-framework/7574ecdef8be3995ce4d814fd286989191a92c69/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /readme/README.md.sha256: -------------------------------------------------------------------------------- 1 | db92a7ab066a7a306a5a918e0e22795f573360876b9050a924e3d02009de071b -------------------------------------------------------------------------------- /settings.gradle.kts: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | rootProject.name = "command-framework" 18 | 19 | // work-around for https://github.com/bndtools/bnd/issues/3174 20 | // can hopefully removed with 4.3.0 release 21 | pluginManagement { 22 | repositories { 23 | mavenCentral() 24 | @Suppress("UnstableApiUsage") 25 | gradlePluginPortal() 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/integTestCommon/groovy/net/kautler/command/integ/test/ManualTests.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.integ.test 18 | 19 | interface ManualTests { 20 | } 21 | -------------------------------------------------------------------------------- /src/integTestCommon/groovy/net/kautler/command/integ/test/spock/AddBean.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2020 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.integ.test.spock 18 | 19 | import java.lang.annotation.Repeatable 20 | import java.lang.annotation.Retention 21 | import java.lang.annotation.Target 22 | 23 | import static java.lang.annotation.ElementType.METHOD 24 | import static java.lang.annotation.ElementType.TYPE 25 | import static java.lang.annotation.RetentionPolicy.RUNTIME 26 | 27 | @Retention(RUNTIME) 28 | @Target([TYPE, METHOD]) 29 | @Repeatable(AddBeans) 30 | @interface AddBean { 31 | Class value() 32 | } 33 | -------------------------------------------------------------------------------- /src/integTestCommon/groovy/net/kautler/command/integ/test/spock/AddBeans.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2020 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.integ.test.spock 18 | 19 | import java.lang.annotation.Retention 20 | import java.lang.annotation.Target 21 | 22 | import static java.lang.annotation.ElementType.METHOD 23 | import static java.lang.annotation.ElementType.TYPE 24 | import static java.lang.annotation.RetentionPolicy.RUNTIME 25 | 26 | @Retention(RUNTIME) 27 | @Target([TYPE, METHOD]) 28 | @interface AddBeans { 29 | AddBean[] value() 30 | } 31 | -------------------------------------------------------------------------------- /src/integTestCommon/groovy/net/kautler/command/integ/test/spock/AddBeansExtension.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.integ.test.spock 18 | 19 | import jakarta.enterprise.event.Observes 20 | import jakarta.enterprise.inject.Vetoed 21 | import jakarta.enterprise.inject.spi.BeforeBeanDiscovery 22 | import jakarta.enterprise.inject.spi.Extension 23 | 24 | class AddBeansExtension implements Extension { 25 | def beans 26 | 27 | AddBeansExtension(Collection> beans) { 28 | this.beans = beans 29 | } 30 | 31 | void addBeans(@Observes BeforeBeanDiscovery beforeBeanDiscovery) { 32 | beans.each { 33 | beforeBeanDiscovery 34 | .addAnnotatedType(it, "${it.name}_manuallyRegistered") 35 | .remove { it.annotationType() == Vetoed } 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/integTestCommon/groovy/net/kautler/command/integ/test/spock/GlobalRetryExtension.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.integ.test.spock 18 | 19 | import org.spockframework.runtime.extension.AbstractGlobalExtension 20 | import org.spockframework.runtime.extension.builtin.RetryExtension 21 | import org.spockframework.runtime.model.SpecInfo 22 | import spock.lang.Retry 23 | 24 | /** 25 | * A global spock extension that enables retrying on all specifications as if {@link Retry @Retry} is applied 26 | * explicitly on them with default settings. If retrying is not wanted on a specific class or method, 27 | * it can easily be disabled by applying {@code @Retry(count = 0)} explicitly. 28 | * 29 | * @see Retry 30 | */ 31 | class GlobalRetryExtension extends AbstractGlobalExtension { 32 | private final Retry retry = Retried.getAnnotation(Retry) 33 | 34 | private final RetryExtension extension = new RetryExtension() 35 | 36 | @Override 37 | void visitSpec(SpecInfo spec) { 38 | if (!spec.getAnnotation(Retry)) { 39 | extension.visitSpecAnnotation(retry, spec) 40 | } 41 | } 42 | 43 | @Retry 44 | private static final class Retried { 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/integTestCommon/groovy/net/kautler/command/integ/test/spock/VetoBean.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.integ.test.spock 18 | 19 | import java.lang.annotation.Repeatable 20 | import java.lang.annotation.Retention 21 | import java.lang.annotation.Target 22 | 23 | import static java.lang.annotation.ElementType.METHOD 24 | import static java.lang.annotation.ElementType.TYPE 25 | import static java.lang.annotation.RetentionPolicy.RUNTIME 26 | 27 | @Retention(RUNTIME) 28 | @Target([TYPE, METHOD]) 29 | @Repeatable(VetoBeans) 30 | @interface VetoBean { 31 | Class value() 32 | } 33 | -------------------------------------------------------------------------------- /src/integTestCommon/groovy/net/kautler/command/integ/test/spock/VetoBeans.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.integ.test.spock 18 | 19 | import java.lang.annotation.Retention 20 | import java.lang.annotation.Target 21 | 22 | import static java.lang.annotation.ElementType.METHOD 23 | import static java.lang.annotation.ElementType.TYPE 24 | import static java.lang.annotation.RetentionPolicy.RUNTIME 25 | 26 | @Retention(RUNTIME) 27 | @Target([TYPE, METHOD]) 28 | @interface VetoBeans { 29 | VetoBean[] value() 30 | } 31 | -------------------------------------------------------------------------------- /src/integTestCommon/groovy/net/kautler/command/integ/test/spock/VetoBeansExtension.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.integ.test.spock 18 | 19 | import jakarta.enterprise.event.Observes 20 | import jakarta.enterprise.inject.spi.Extension 21 | import jakarta.enterprise.inject.spi.ProcessAnnotatedType 22 | 23 | class VetoBeansExtension implements Extension { 24 | def beans 25 | 26 | VetoBeansExtension(Collection> beans) { 27 | this.beans = beans 28 | } 29 | 30 | void vetoBean(@Observes ProcessAnnotatedType processAnnotatedType) { 31 | if (processAnnotatedType.annotatedType.javaClass in beans) { 32 | processAnnotatedType.veto() 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/integTestCommon/resources/META-INF/services/org.spockframework.runtime.extension.IGlobalExtension: -------------------------------------------------------------------------------- 1 | # Copyright 2019-2020 Björn Kautler 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | net.kautler.command.integ.test.spock.CDIExtension 16 | net.kautler.command.integ.test.spock.GlobalRetryExtension 17 | -------------------------------------------------------------------------------- /src/integTestCommon/resources/log4j2-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 22 | <%-35.35t> <%x> <%X> <%50.50c> %m}{TRACE = magenta}%n]]> 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /src/integTestCommon/resources/log4j2.component.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Vampire/command-framework/7574ecdef8be3995ce4d814fd286989191a92c69/src/integTestCommon/resources/log4j2.component.properties -------------------------------------------------------------------------------- /src/javacordIntegTest/groovy/net/kautler/command/integ/test/VersionIntegTest.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.integ.test 18 | 19 | import jakarta.enterprise.context.ApplicationScoped 20 | import jakarta.enterprise.context.Initialized 21 | import jakarta.enterprise.event.Observes 22 | import jakarta.enterprise.inject.Vetoed 23 | import jakarta.inject.Inject 24 | import net.kautler.command.api.Version 25 | import net.kautler.command.integ.test.spock.AddBean 26 | import spock.lang.Specification 27 | import spock.lang.Subject 28 | 29 | @Subject(Version) 30 | class VersionIntegTest extends Specification { 31 | @AddBean(VersionHolder) 32 | def 'version should be known'() { 33 | expect: 34 | VersionHolder.version.version != '' 35 | } 36 | 37 | @AddBean(VersionHolder) 38 | def 'build timestamp should be known'() { 39 | expect: 40 | VersionHolder.version.buildTimestamp 41 | } 42 | 43 | @AddBean(VersionHolder) 44 | def 'display version should be equal to version if and only if the version is not a snapshot version'() { 45 | expect: 46 | with (VersionHolder.version) { 47 | (displayVersion == version) != (version.endsWith('-SNAPSHOT') || version == '') 48 | } 49 | } 50 | 51 | @Vetoed 52 | @ApplicationScoped 53 | static class VersionHolder { 54 | static Version version 55 | 56 | @Inject 57 | def setVersion(Version version) { 58 | VersionHolder.version = version 59 | } 60 | 61 | def ensureInitializationAtStartup(@Observes @Initialized(ApplicationScoped) Object event) { 62 | // just ensure initialization at startup 63 | } 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /src/javacordIntegTest/resources/META-INF/services/org.spockframework.runtime.extension.IGlobalExtension: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Björn Kautler 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | net.kautler.command.integ.test.javacord.spock.JavacordExtension 16 | -------------------------------------------------------------------------------- /src/jdaIntegTest/groovy/net/kautler/command/integ/test/jda/event/CommandNotFoundEventJdaIntegTest.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.integ.test.jda.event 18 | 19 | import jakarta.enterprise.context.ApplicationScoped 20 | import jakarta.enterprise.event.ObservesAsync 21 | import jakarta.enterprise.inject.Vetoed 22 | import net.dv8tion.jda.api.entities.TextChannel 23 | import net.kautler.command.api.CommandHandler 24 | import net.kautler.command.api.event.jda.CommandNotFoundEventJda 25 | import net.kautler.command.integ.test.spock.AddBean 26 | import spock.lang.Specification 27 | import spock.lang.Subject 28 | import spock.util.concurrent.BlockingVariable 29 | 30 | @Subject([CommandHandler, CommandNotFoundEventJda]) 31 | class CommandNotFoundEventJdaIntegTest extends Specification { 32 | @AddBean(EventReceiver) 33 | def 'command not found event should be fired if command was not found'(TextChannel textChannelAsUser) { 34 | given: 35 | def commandNotFoundEventReceived = new BlockingVariable(System.properties.testResponseTimeout as double) 36 | EventReceiver.commandNotFoundEventReceived = commandNotFoundEventReceived 37 | 38 | when: 39 | textChannelAsUser 40 | .sendMessage('!ping') 41 | .complete() 42 | 43 | then: 44 | commandNotFoundEventReceived.get() 45 | } 46 | 47 | @Vetoed 48 | @ApplicationScoped 49 | static class EventReceiver { 50 | static commandNotFoundEventReceived 51 | 52 | void handleCommandNotFoundEvent(@ObservesAsync CommandNotFoundEventJda commandNotFoundEvent) { 53 | commandNotFoundEventReceived?.set(commandNotFoundEvent) 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/jdaIntegTest/resources/META-INF/services/org.spockframework.runtime.extension.IGlobalExtension: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Björn Kautler 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | net.kautler.command.integ.test.jda.spock.JdaExtension 16 | -------------------------------------------------------------------------------- /src/main/java/net/kautler/command/Internal.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command; 18 | 19 | import java.lang.annotation.Documented; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.Target; 22 | 23 | import jakarta.enterprise.util.AnnotationLiteral; 24 | import jakarta.inject.Qualifier; 25 | 26 | import static java.lang.annotation.ElementType.FIELD; 27 | import static java.lang.annotation.ElementType.METHOD; 28 | import static java.lang.annotation.ElementType.PARAMETER; 29 | import static java.lang.annotation.ElementType.TYPE; 30 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 31 | 32 | /** 33 | * A CDI qualifier that is used for internal beans that should not be injected into client code and injection points 34 | * where no client beans should get injected. 35 | */ 36 | @Retention(RUNTIME) 37 | @Target({ TYPE, FIELD, METHOD, PARAMETER }) 38 | @Documented 39 | @Qualifier 40 | public @interface Internal { 41 | /** 42 | * An annotation literal for programmatic CDI lookup. 43 | */ 44 | class Literal extends AnnotationLiteral implements Internal { 45 | /** 46 | * The annotation literal instance. 47 | */ 48 | public static final Literal INSTANCE = new Literal(); 49 | 50 | /** 51 | * The serial version UID of this class. 52 | */ 53 | private static final long serialVersionUID = 1; 54 | 55 | /** 56 | * Constructs a new internal annotation literal. 57 | */ 58 | private Literal() { 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/net/kautler/command/InvalidAnnotationCombinationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2020 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command; 18 | 19 | import net.kautler.command.api.annotation.RestrictedTo; 20 | import net.kautler.command.api.annotation.RestrictionPolicy; 21 | 22 | /** 23 | * An exception that is thrown if an invalid annotation combination is detected like for example multiple 24 | * {@link RestrictedTo @RestrictedTo} annotations without a {@link RestrictionPolicy @RestrictionPolicy} annotation. 25 | */ 26 | public class InvalidAnnotationCombinationException extends RuntimeException { 27 | /** 28 | * The serial version UID of this class. 29 | */ 30 | private static final long serialVersionUID = 1; 31 | 32 | /** 33 | * Constructs a new invalid annotation combination exception with the given message. 34 | * 35 | * @param message the detail message 36 | */ 37 | public InvalidAnnotationCombinationException(String message) { 38 | super(message); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/net/kautler/command/LoggerProducer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command; 18 | 19 | import jakarta.enterprise.context.ApplicationScoped; 20 | import jakarta.enterprise.inject.Produces; 21 | import jakarta.enterprise.inject.spi.InjectionPoint; 22 | import org.apache.logging.log4j.LogManager; 23 | import org.apache.logging.log4j.Logger; 24 | 25 | /** 26 | * A CDI producer that produces log4j loggers for the declaring class of the injection point. 27 | */ 28 | @ApplicationScoped 29 | class LoggerProducer { 30 | /** 31 | * Returns a newly produced log4j logger for the declaring class of the injection point. 32 | * 33 | * @param injectionPoint the injection point for which to produce a log4j logger 34 | * @return a newly produced log4j logger for the injection point 35 | */ 36 | @Produces 37 | @Internal 38 | Logger getLogger(InjectionPoint injectionPoint) { 39 | return LogManager.getLogger(injectionPoint.getMember().getDeclaringClass()); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/net/kautler/command/api/annotation/Aliases.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.api.annotation; 18 | 19 | import java.lang.annotation.Documented; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.Target; 22 | 23 | import static java.lang.annotation.ElementType.TYPE; 24 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 25 | 26 | /** 27 | * An annotation which serves as container for applying multiple {@link Alias @Alias} annotations. 28 | * This container annotation is used implicitly and should usually not be applied manually. 29 | * Just use multiple {@code @Alias} annotations on the same class instead. 30 | * 31 | * @see Alias @Alias 32 | */ 33 | @Retention(RUNTIME) 34 | @Target(TYPE) 35 | @Documented 36 | public @interface Aliases { 37 | /** 38 | * Returns the aliases for the annotated command. 39 | * 40 | * @return the aliases for the annotated command 41 | */ 42 | Alias[] value(); 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/net/kautler/command/api/annotation/Description.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.api.annotation; 18 | 19 | import net.kautler.command.api.Command; 20 | import net.kautler.command.api.slash.javacord.SlashCommandJavacord; 21 | import org.javacord.api.interaction.SlashCommandBuilder; 22 | 23 | import java.lang.annotation.Documented; 24 | import java.lang.annotation.Retention; 25 | import java.lang.annotation.Target; 26 | 27 | import static java.lang.annotation.ElementType.TYPE; 28 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 29 | 30 | /** 31 | * An annotation with which a description of the command can be configured. 32 | * This description can for example be displayed in an own help command. 33 | * 34 | *

When injecting a {@link SlashCommandBuilder List<SlashCommandBuilder>} anywhere, all commands 35 | * implementing {@link SlashCommandJavacord} have to provide a description. 36 | * 37 | *

Alternatively to using this annotation the {@link Command#getDescription()} method can be overwritten. 38 | * If that method is overwritten and this annotation is used, the method overwrite takes precedence. 39 | * That method is also what should be used to retrieve the configured description. 40 | * 41 | * @see Command#getDescription() 42 | */ 43 | @Retention(RUNTIME) 44 | @Target(TYPE) 45 | @Documented 46 | public @interface Description { 47 | /** 48 | * Returns the description of the annotated command. 49 | * 50 | * @return the description of the annotated command 51 | */ 52 | String value(); 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/net/kautler/command/api/annotation/Restrictions.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.api.annotation; 18 | 19 | import java.lang.annotation.Documented; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.Target; 22 | 23 | import static java.lang.annotation.ElementType.TYPE; 24 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 25 | 26 | /** 27 | * An annotation which serves as container for applying multiple {@link RestrictedTo @RestrictedTo} annotations. 28 | * This container annotation is used implicitly and should usually not be applied manually. 29 | * Just use multiple {@code @RestrictedTo} annotations on the same class instead. 30 | * 31 | * @see RestrictedTo @RestrictedTo 32 | */ 33 | @Retention(RUNTIME) 34 | @Target(TYPE) 35 | @Documented 36 | public @interface Restrictions { 37 | /** 38 | * Returns the restrictions for the annotated command. 39 | * 40 | * @return the restrictions for the annotated command 41 | */ 42 | RestrictedTo[] value(); 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/net/kautler/command/api/annotation/Usage.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2020 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.api.annotation; 18 | 19 | import net.kautler.command.api.Command; 20 | import net.kautler.command.api.parameter.ParameterParser; 21 | 22 | import java.lang.annotation.Documented; 23 | import java.lang.annotation.Retention; 24 | import java.lang.annotation.Target; 25 | 26 | import static java.lang.annotation.ElementType.TYPE; 27 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 28 | 29 | /** 30 | * An annotation with which the usage of the command can be configured. 31 | * This usage can for example be displayed in an own help command. 32 | * 33 | *

When using the {@link ParameterParser}, the usage string has to follow 34 | * a pre-defined format that is described there. 35 | * 36 | *

Alternatively to using this annotation the {@link Command#getUsage()} method can be overwritten. 37 | * If that method is overwritten and this annotation is used, the method overwrite takes precedence. 38 | * That method is also what should be used to retrieve the configured usage. 39 | * 40 | * @see Command#getUsage() 41 | * @see ParameterParser 42 | */ 43 | @Retention(RUNTIME) 44 | @Target(TYPE) 45 | @Documented 46 | public @interface Usage { 47 | /** 48 | * Returns the usage of the annotated command. 49 | * 50 | * @return the usage of the annotated command 51 | */ 52 | String value(); 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/net/kautler/command/api/event/javacord/CommandNotAllowedEventJavacord.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.api.event.javacord; 18 | 19 | import jakarta.enterprise.event.ObservesAsync; 20 | import net.kautler.command.api.CommandContext; 21 | import net.kautler.command.api.annotation.RestrictedTo; 22 | import net.kautler.command.api.event.CommandEvent; 23 | import org.javacord.api.entity.message.Message; 24 | 25 | /** 26 | * An event that is sent asynchronously via the CDI event mechanism if a command was not allowed due to some 27 | * configured {@link RestrictedTo restriction} by the Javacord command handler. It can be handled using 28 | * {@link ObservesAsync @ObservesAsync}. 29 | * 30 | * @see ObservesAsync @ObservesAsync 31 | * @see RestrictedTo @RestrictedTo 32 | */ 33 | public class CommandNotAllowedEventJavacord extends CommandEvent { 34 | /** 35 | * Constructs a new command not allowed event with the given command context as payload. 36 | * 37 | * @param commandContext the command context, usually fully populated 38 | */ 39 | public CommandNotAllowedEventJavacord(CommandContext commandContext) { 40 | super(commandContext); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/net/kautler/command/api/event/javacord/CommandNotAllowedEventJavacordSlash.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.api.event.javacord; 18 | 19 | import jakarta.enterprise.event.ObservesAsync; 20 | import net.kautler.command.api.CommandContext; 21 | import net.kautler.command.api.annotation.RestrictedTo; 22 | import net.kautler.command.api.event.CommandEvent; 23 | import org.javacord.api.interaction.SlashCommandInteraction; 24 | 25 | /** 26 | * An event that is sent asynchronously via the CDI event mechanism if a command was not allowed due to some 27 | * configured {@link RestrictedTo restriction} by the Javacord slash command handler. It can be handled using 28 | * {@link ObservesAsync @ObservesAsync}. 29 | * 30 | * @see ObservesAsync @ObservesAsync 31 | * @see RestrictedTo @RestrictedTo 32 | */ 33 | public class CommandNotAllowedEventJavacordSlash extends CommandEvent { 34 | /** 35 | * Constructs a new command not allowed event with the given command context as payload. 36 | * 37 | * @param commandContext the command context, usually fully populated 38 | */ 39 | public CommandNotAllowedEventJavacordSlash(CommandContext commandContext) { 40 | super(commandContext); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/net/kautler/command/api/event/javacord/CommandNotFoundEventJavacord.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.api.event.javacord; 18 | 19 | import jakarta.enterprise.event.ObservesAsync; 20 | import net.kautler.command.api.CommandContext; 21 | import net.kautler.command.api.event.CommandEvent; 22 | import org.javacord.api.entity.message.Message; 23 | 24 | /** 25 | * An event that is sent asynchronously via the CDI event mechanism if a command was not found for a message. 26 | * This event is only sent for messages that could have been a command like for example 27 | * they started with the correct prefix but the alias did not match any available command. 28 | * It can be handled using {@link ObservesAsync @ObservesAsync}. 29 | * 30 | * @see ObservesAsync @ObservesAsync 31 | */ 32 | public class CommandNotFoundEventJavacord extends CommandEvent { 33 | /** 34 | * Constructs a new command not found event with the given command context as payload. 35 | * 36 | * @param commandContext the command context, usually populated according to current phase 37 | */ 38 | public CommandNotFoundEventJavacord(CommandContext commandContext) { 39 | super(commandContext); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/net/kautler/command/api/event/javacord/CommandNotFoundEventJavacordSlash.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.api.event.javacord; 18 | 19 | import jakarta.enterprise.event.ObservesAsync; 20 | import net.kautler.command.api.CommandContext; 21 | import net.kautler.command.api.event.CommandEvent; 22 | import org.javacord.api.interaction.SlashCommandInteraction; 23 | 24 | /** 25 | * An event that is sent asynchronously via the CDI event mechanism if a command was not found for a slash command. 26 | * This event is only sent for messages that could have been a command like for example 27 | * they started with the correct prefix but the alias did not match any available command. 28 | * It can be handled using {@link ObservesAsync @ObservesAsync}. 29 | * 30 | * @see ObservesAsync @ObservesAsync 31 | */ 32 | public class CommandNotFoundEventJavacordSlash extends CommandEvent { 33 | /** 34 | * Constructs a new command not found event with the given command context as payload. 35 | * 36 | * @param commandContext the command context, usually populated according to current phase 37 | */ 38 | public CommandNotFoundEventJavacordSlash(CommandContext commandContext) { 39 | super(commandContext); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/net/kautler/command/api/event/jda/CommandNotAllowedEventJda.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.api.event.jda; 18 | 19 | import jakarta.enterprise.event.ObservesAsync; 20 | import net.dv8tion.jda.api.entities.Message; 21 | import net.kautler.command.api.CommandContext; 22 | import net.kautler.command.api.annotation.RestrictedTo; 23 | import net.kautler.command.api.event.CommandEvent; 24 | 25 | /** 26 | * An event that is sent asynchronously via the CDI event mechanism if a command was not allowed due to some 27 | * configured {@link RestrictedTo restriction} by the JDA command handler. It can be handled using 28 | * {@link ObservesAsync @ObservesAsync}. 29 | * 30 | * @see ObservesAsync @ObservesAsync 31 | * @see RestrictedTo @RestrictedTo 32 | */ 33 | public class CommandNotAllowedEventJda extends CommandEvent { 34 | /** 35 | * Constructs a new command not allowed event with the given command context as payload. 36 | * 37 | * @param commandContext the command context, usually fully populated 38 | */ 39 | public CommandNotAllowedEventJda(CommandContext commandContext) { 40 | super(commandContext); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/net/kautler/command/api/event/jda/CommandNotFoundEventJda.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.api.event.jda; 18 | 19 | import jakarta.enterprise.event.ObservesAsync; 20 | import net.dv8tion.jda.api.entities.Message; 21 | import net.kautler.command.api.CommandContext; 22 | import net.kautler.command.api.event.CommandEvent; 23 | 24 | /** 25 | * An event that is sent asynchronously via the CDI event mechanism if a command was not found for a message. 26 | * This event is only sent for messages that could have been a command like for example 27 | * they started with the correct prefix but the alias did not match any available command. 28 | * It can be handled using {@link ObservesAsync @ObservesAsync}. 29 | * 30 | * @see ObservesAsync @ObservesAsync 31 | */ 32 | public class CommandNotFoundEventJda extends CommandEvent { 33 | /** 34 | * Constructs a new command not found event with the given command context as payload. 35 | * 36 | * @param commandContext the command context, usually populated according to current phase 37 | */ 38 | public CommandNotFoundEventJda(CommandContext commandContext) { 39 | super(commandContext); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/net/kautler/command/api/parameter/InvalidParameterFormatException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.api.parameter; 18 | 19 | /** 20 | * An invalid parameter format exception that is thrown by {@link ParameterConverter}s 21 | * if the format of the parameter is invalid, for example some text for a number-parsing converter. 22 | * The message should be written in a way so that it can be directly presented to the end user. 23 | */ 24 | public class InvalidParameterFormatException extends ParameterParseException { 25 | /** 26 | * The serial version UID of this class. 27 | */ 28 | private static final long serialVersionUID = 1; 29 | 30 | /** 31 | * Constructs a new invalid parameter format exception with the given message. 32 | * The message should be written in a way so that it can be directly presented to the end user. 33 | * 34 | * @param message the detail message 35 | */ 36 | public InvalidParameterFormatException(String message) { 37 | super(message); 38 | } 39 | 40 | /** 41 | * Constructs a new invalid parameter format exception with the given message and cause. 42 | * The message should be written in a way so that it can be directly presented to the end user. 43 | * 44 | * @param message the detail message 45 | * @param cause the cause 46 | */ 47 | public InvalidParameterFormatException(String message, Throwable cause) { 48 | super(message, cause); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/net/kautler/command/api/parameter/InvalidParameterValueException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.api.parameter; 18 | 19 | /** 20 | * An invalid parameter value exception that is thrown by {@link ParameterConverter}s 21 | * if the value of the parameter is invalid though the format was correct, for example the id of an unknown user. 22 | * The message should be written in a way so that it can be directly presented to the end user. 23 | */ 24 | public class InvalidParameterValueException extends ParameterParseException { 25 | /** 26 | * The serial version UID of this class. 27 | */ 28 | private static final long serialVersionUID = 1; 29 | 30 | /** 31 | * Constructs a new invalid parameter value exception with the given message. 32 | * The message should be written in a way so that it can be directly presented to the end user. 33 | * 34 | * @param message the detail message 35 | */ 36 | public InvalidParameterValueException(String message) { 37 | super(message); 38 | } 39 | 40 | /** 41 | * Constructs a new invalid parameter value exception with the given message and cause. 42 | * The message should be written in a way so that it can be directly presented to the end user. 43 | * 44 | * @param message the detail message 45 | * @param cause the cause 46 | */ 47 | public InvalidParameterValueException(String message, Throwable cause) { 48 | super(message, cause); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/net/kautler/command/api/parameter/ParameterTypes.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.api.parameter; 18 | 19 | import java.lang.annotation.Documented; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.Target; 22 | 23 | import static java.lang.annotation.ElementType.FIELD; 24 | import static java.lang.annotation.ElementType.METHOD; 25 | import static java.lang.annotation.ElementType.PARAMETER; 26 | import static java.lang.annotation.ElementType.TYPE; 27 | import static java.lang.annotation.RetentionPolicy.RUNTIME; 28 | 29 | /** 30 | * An annotation which serves as container for applying multiple {@link ParameterType @ParameterType} annotations. 31 | * This container annotation is used implicitly and should usually not be applied manually. 32 | * Just use multiple {@code @ParameterType} annotations on the same class instead. 33 | * 34 | * @see ParameterType @ParameterType 35 | */ 36 | @Retention(RUNTIME) 37 | @Target({ TYPE, FIELD, METHOD, PARAMETER }) 38 | @Documented 39 | public @interface ParameterTypes { 40 | /** 41 | * Returns the parameter types for the annotated parameter converter. 42 | * 43 | * @return the parameter types for the annotated parameter converter 44 | */ 45 | ParameterType[] value(); 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/net/kautler/command/api/restriction/Everyone.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.api.restriction; 18 | 19 | import jakarta.enterprise.context.ApplicationScoped; 20 | import net.kautler.command.api.CommandContext; 21 | 22 | /** 23 | * A restriction that allows a command for everyone. This always allows a command and is effectively the same as not 24 | * having any restrictions. It is used internally if no other restrictions are applied and can be used to explicitly 25 | * state that a command is allowed for everyone. 26 | */ 27 | @ApplicationScoped 28 | public class Everyone implements Restriction { 29 | @Override 30 | public boolean allowCommand(CommandContext commandContext) { 31 | return true; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/net/kautler/command/api/restriction/Restriction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.api.restriction; 18 | 19 | import net.kautler.command.api.CommandContext; 20 | 21 | /** 22 | * A restriction that checks allowance for usage of a command that was caused by a given command context. 23 | * 24 | * @param the class of the messages for which this restriction can check allowance 25 | */ 26 | public interface Restriction { 27 | /** 28 | * Returns the real class of this restriction. Subclasses usually do not need to overwrite this method as the 29 | * default implementation should be appropriate. This is necessary as CDI implementations that create 30 | * proxies might not provide the real class that is necessary for restriction lookup. 31 | * 32 | * @return the real class of this restriction 33 | */ 34 | default Class getRealClass() { 35 | return this.getClass(); 36 | } 37 | 38 | /** 39 | * Returns whether a command caused by the given command context should be allowed by this restriction or not. 40 | * 41 | * @param commandContext the command context, usually fully populated 42 | * @return whether a command caused by the given command context should be allowed by this restriction or not 43 | */ 44 | boolean allowCommand(CommandContext commandContext); 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/net/kautler/command/api/restriction/javacord/BotOwnerJavacord.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.api.restriction.javacord; 18 | 19 | import jakarta.enterprise.context.ApplicationScoped; 20 | import net.kautler.command.api.CommandContext; 21 | import net.kautler.command.api.restriction.Restriction; 22 | import org.javacord.api.entity.message.Message; 23 | 24 | /** 25 | * A restriction that allows a command for the bot owner and is evaluated by the Javacord command handler. 26 | */ 27 | @ApplicationScoped 28 | public class BotOwnerJavacord implements Restriction { 29 | @Override 30 | public boolean allowCommand(CommandContext commandContext) { 31 | return commandContext.getMessage().getAuthor().isBotOwner(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/net/kautler/command/api/restriction/javacord/NsfwChannelJavacord.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.api.restriction.javacord; 18 | 19 | import jakarta.enterprise.context.ApplicationScoped; 20 | import net.kautler.command.api.CommandContext; 21 | import net.kautler.command.api.restriction.Restriction; 22 | import org.javacord.api.entity.channel.ServerTextChannel; 23 | import org.javacord.api.entity.message.Message; 24 | 25 | import static java.lang.Boolean.FALSE; 26 | 27 | /** 28 | * A restriction that allows a command for NSFW channels and is evaluated by the Javacord command handler. 29 | * If a message is not sent on a server, this restriction always denies. 30 | */ 31 | @ApplicationScoped 32 | public class NsfwChannelJavacord implements Restriction { 33 | @Override 34 | public boolean allowCommand(CommandContext commandContext) { 35 | return commandContext 36 | .getMessage() 37 | .getChannel() 38 | .asServerTextChannel() 39 | .map(ServerTextChannel::isNsfw) 40 | .orElse(FALSE); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/net/kautler/command/api/restriction/javacord/PrivateMessageJavacord.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.api.restriction.javacord; 18 | 19 | import jakarta.enterprise.context.ApplicationScoped; 20 | import net.kautler.command.api.CommandContext; 21 | import net.kautler.command.api.restriction.Restriction; 22 | import org.javacord.api.entity.message.Message; 23 | 24 | /** 25 | * A restriction that allows a command for private messages and is evaluated by the Javacord command handler. 26 | */ 27 | @ApplicationScoped 28 | public class PrivateMessageJavacord implements Restriction { 29 | @Override 30 | public boolean allowCommand(CommandContext commandContext) { 31 | return commandContext.getMessage().isPrivateMessage(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/net/kautler/command/api/restriction/javacord/RegularUserJavacord.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.api.restriction.javacord; 18 | 19 | import jakarta.enterprise.context.ApplicationScoped; 20 | import net.kautler.command.api.CommandContext; 21 | import net.kautler.command.api.restriction.Restriction; 22 | import org.javacord.api.entity.message.Message; 23 | 24 | import static java.lang.Boolean.FALSE; 25 | 26 | /** 27 | * A restriction that allows a command for regular users and is evaluated by the Javacord command handler. 28 | * Regular users means no bots, and no webhooks. 29 | */ 30 | @ApplicationScoped 31 | public class RegularUserJavacord implements Restriction { 32 | @Override 33 | public boolean allowCommand(CommandContext commandContext) { 34 | return commandContext 35 | .getMessage() 36 | .getUserAuthor() 37 | .map(user -> !user.isBot()) 38 | .orElse(FALSE); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/net/kautler/command/api/restriction/javacord/ServerManagerJavacord.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.api.restriction.javacord; 18 | 19 | import jakarta.enterprise.context.ApplicationScoped; 20 | import net.kautler.command.api.CommandContext; 21 | import net.kautler.command.api.restriction.Restriction; 22 | import org.javacord.api.entity.message.Message; 23 | 24 | /** 25 | * A restriction that allows a command for server managers and is evaluated by the Javacord command handler. 26 | * If a message is not sent on a server, this restriction always denies. 27 | */ 28 | @ApplicationScoped 29 | public class ServerManagerJavacord implements Restriction { 30 | @Override 31 | public boolean allowCommand(CommandContext commandContext) { 32 | return commandContext.getMessage().getAuthor().canManageServer(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/net/kautler/command/api/restriction/javacord/ServerOwnerJavacord.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.api.restriction.javacord; 18 | 19 | import jakarta.enterprise.context.ApplicationScoped; 20 | import net.kautler.command.api.CommandContext; 21 | import net.kautler.command.api.restriction.Restriction; 22 | import org.javacord.api.entity.message.Message; 23 | 24 | import static java.lang.Boolean.FALSE; 25 | 26 | /** 27 | * A restriction that allows a command for the server owner and is evaluated by the Javacord command handler. 28 | * If a message is not sent on a server, this restriction always denies. 29 | */ 30 | @ApplicationScoped 31 | public class ServerOwnerJavacord implements Restriction { 32 | @Override 33 | public boolean allowCommand(CommandContext commandContext) { 34 | Message message = commandContext.getMessage(); 35 | return message.getServer() 36 | .flatMap(server -> message.getUserAuthor().map(server::isOwner)) 37 | // if message is not on a server 38 | // or author is no user 39 | .orElse(FALSE); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/net/kautler/command/api/restriction/javacord/slash/BotOwnerJavacordSlash.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.api.restriction.javacord.slash; 18 | 19 | import jakarta.enterprise.context.ApplicationScoped; 20 | import net.kautler.command.api.CommandContext; 21 | import net.kautler.command.api.restriction.Restriction; 22 | import org.javacord.api.interaction.SlashCommandInteraction; 23 | 24 | /** 25 | * A restriction that allows a command for the bot owner and is evaluated by the Javacord slash command handler. 26 | */ 27 | @ApplicationScoped 28 | public class BotOwnerJavacordSlash implements Restriction { 29 | @Override 30 | public boolean allowCommand(CommandContext commandContext) { 31 | return commandContext 32 | .getMessage() 33 | .getUser() 34 | .isBotOwner(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/net/kautler/command/api/restriction/javacord/slash/NsfwChannelJavacordSlash.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.api.restriction.javacord.slash; 18 | 19 | import jakarta.enterprise.context.ApplicationScoped; 20 | import net.kautler.command.api.CommandContext; 21 | import net.kautler.command.api.restriction.Restriction; 22 | import org.javacord.api.entity.channel.ServerTextChannel; 23 | import org.javacord.api.interaction.SlashCommandInteraction; 24 | 25 | import static java.lang.Boolean.FALSE; 26 | 27 | /** 28 | * A restriction that allows a command for NSFW channels and is evaluated by the Javacord slash command handler. 29 | * If a message is not sent on a server, this restriction always denies. 30 | */ 31 | @ApplicationScoped 32 | public class NsfwChannelJavacordSlash implements Restriction { 33 | @Override 34 | public boolean allowCommand(CommandContext commandContext) { 35 | return commandContext 36 | .getMessage() 37 | .getChannel() 38 | .orElseThrow(AssertionError::new) 39 | .asServerTextChannel() 40 | .map(ServerTextChannel::isNsfw) 41 | .orElse(FALSE); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/net/kautler/command/api/restriction/javacord/slash/PrivateMessageJavacordSlash.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.api.restriction.javacord.slash; 18 | 19 | import jakarta.enterprise.context.ApplicationScoped; 20 | import net.kautler.command.api.CommandContext; 21 | import net.kautler.command.api.restriction.Restriction; 22 | import org.javacord.api.interaction.SlashCommandInteraction; 23 | 24 | /** 25 | * A restriction that allows a command for slash commands in private messages and is evaluated 26 | * by the Javacord slash command handler. 27 | */ 28 | @ApplicationScoped 29 | public class PrivateMessageJavacordSlash implements Restriction { 30 | @Override 31 | public boolean allowCommand(CommandContext commandContext) { 32 | return commandContext 33 | .getMessage() 34 | .getChannel() 35 | .orElseThrow(AssertionError::new) 36 | .asPrivateChannel() 37 | .isPresent(); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/net/kautler/command/api/restriction/javacord/slash/ServerManagerJavacordSlash.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.api.restriction.javacord.slash; 18 | 19 | import jakarta.enterprise.context.ApplicationScoped; 20 | import net.kautler.command.api.CommandContext; 21 | import net.kautler.command.api.restriction.Restriction; 22 | import org.javacord.api.interaction.SlashCommandInteraction; 23 | 24 | import static java.lang.Boolean.FALSE; 25 | 26 | /** 27 | * A restriction that allows a command for server managers and is evaluated by the Javacord slash command handler. 28 | * If a message is not sent on a server, this restriction always denies. 29 | */ 30 | @ApplicationScoped 31 | public class ServerManagerJavacordSlash implements Restriction { 32 | @Override 33 | public boolean allowCommand(CommandContext commandContext) { 34 | SlashCommandInteraction slashCommandInteraction = commandContext.getMessage(); 35 | return slashCommandInteraction 36 | .getServer() 37 | .map(server -> server.canManage(slashCommandInteraction.getUser())) 38 | .orElse(FALSE); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/net/kautler/command/api/restriction/javacord/slash/ServerOwnerJavacordSlash.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.api.restriction.javacord.slash; 18 | 19 | import jakarta.enterprise.context.ApplicationScoped; 20 | import net.kautler.command.api.CommandContext; 21 | import net.kautler.command.api.restriction.Restriction; 22 | import org.javacord.api.interaction.SlashCommandInteraction; 23 | 24 | import static java.lang.Boolean.FALSE; 25 | 26 | /** 27 | * A restriction that allows a command for the server owner and is evaluated by the Javacord slash command handler. 28 | * If a message is not sent on a server, this restriction always denies. 29 | */ 30 | @ApplicationScoped 31 | public class ServerOwnerJavacordSlash implements Restriction { 32 | @Override 33 | public boolean allowCommand(CommandContext commandContext) { 34 | SlashCommandInteraction slashCommandInteraction = commandContext.getMessage(); 35 | return slashCommandInteraction 36 | .getServer() 37 | .map(server -> server.isOwner(slashCommandInteraction.getUser())) 38 | .orElse(FALSE); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/net/kautler/command/api/restriction/jda/BotOwnerJda.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.api.restriction.jda; 18 | 19 | import jakarta.enterprise.context.ApplicationScoped; 20 | import net.dv8tion.jda.api.JDA; 21 | import net.dv8tion.jda.api.entities.Message; 22 | import net.kautler.command.api.CommandContext; 23 | import net.kautler.command.api.restriction.Restriction; 24 | 25 | import java.util.Map; 26 | import java.util.concurrent.ConcurrentHashMap; 27 | 28 | /** 29 | * A restriction that allows a command for the bot owner and is evaluated by the JDA command handler. 30 | */ 31 | @ApplicationScoped 32 | public class BotOwnerJda implements Restriction { 33 | /** 34 | * A cache of bot owners by JDA instance as JDA does not cache this information. 35 | */ 36 | private final Map ownerByJda = new ConcurrentHashMap<>(); 37 | 38 | @Override 39 | public boolean allowCommand(CommandContext commandContext) { 40 | Message message = commandContext.getMessage(); 41 | JDA jda = message.getJDA(); 42 | Long owner = ownerByJda.computeIfAbsent( 43 | jda, 44 | key -> key.retrieveApplicationInfo().complete().getOwner().getIdLong()); 45 | return owner.equals(message.getAuthor().getIdLong()); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/net/kautler/command/api/restriction/jda/GuildOwnerJda.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.api.restriction.jda; 18 | 19 | import jakarta.enterprise.context.ApplicationScoped; 20 | import net.dv8tion.jda.api.entities.Member; 21 | import net.dv8tion.jda.api.entities.Message; 22 | import net.kautler.command.api.CommandContext; 23 | import net.kautler.command.api.restriction.Restriction; 24 | 25 | import java.util.Optional; 26 | 27 | import static java.lang.Boolean.FALSE; 28 | 29 | /** 30 | * A restriction that allows a command for the guild owner and is evaluated by the JDA command handler. 31 | * If a message is not sent on a guild, this restriction always denies. 32 | */ 33 | @ApplicationScoped 34 | public class GuildOwnerJda implements Restriction { 35 | @Override 36 | public boolean allowCommand(CommandContext commandContext) { 37 | return Optional.ofNullable(commandContext.getMessage().getMember()) 38 | .map(Member::isOwner) 39 | .orElse(FALSE); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/net/kautler/command/api/restriction/jda/NsfwChannelJda.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.api.restriction.jda; 18 | 19 | import jakarta.enterprise.context.ApplicationScoped; 20 | import net.dv8tion.jda.api.entities.Message; 21 | import net.dv8tion.jda.api.entities.TextChannel; 22 | import net.kautler.command.api.CommandContext; 23 | import net.kautler.command.api.restriction.Restriction; 24 | 25 | import java.util.Optional; 26 | 27 | import static java.lang.Boolean.FALSE; 28 | import static net.dv8tion.jda.api.entities.ChannelType.TEXT; 29 | 30 | /** 31 | * A restriction that allows a command for NSFW channels and is evaluated by the JDA command handler. 32 | * If a message is not sent on a guild, this restriction always denies. 33 | */ 34 | @ApplicationScoped 35 | public class NsfwChannelJda implements Restriction { 36 | @Override 37 | public boolean allowCommand(CommandContext commandContext) { 38 | return Optional.of(commandContext.getMessage()) 39 | .filter(msg -> msg.isFromType(TEXT)) 40 | .map(Message::getTextChannel) 41 | .map(TextChannel::isNSFW) 42 | .orElse(FALSE); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/net/kautler/command/api/restriction/jda/PrivateMessageJda.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.api.restriction.jda; 18 | 19 | import jakarta.enterprise.context.ApplicationScoped; 20 | import net.dv8tion.jda.api.entities.Message; 21 | import net.kautler.command.api.CommandContext; 22 | import net.kautler.command.api.restriction.Restriction; 23 | 24 | import static net.dv8tion.jda.api.entities.ChannelType.PRIVATE; 25 | 26 | /** 27 | * A restriction that allows a command for private messages and is evaluated by the JDA command handler. 28 | */ 29 | @ApplicationScoped 30 | public class PrivateMessageJda implements Restriction { 31 | @Override 32 | public boolean allowCommand(CommandContext commandContext) { 33 | return commandContext.getMessage().isFromType(PRIVATE); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/net/kautler/command/api/restriction/jda/RegularUserJda.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.api.restriction.jda; 18 | 19 | import jakarta.enterprise.context.ApplicationScoped; 20 | import net.dv8tion.jda.api.entities.Message; 21 | import net.kautler.command.api.CommandContext; 22 | import net.kautler.command.api.restriction.Restriction; 23 | 24 | import java.util.Optional; 25 | 26 | import static java.lang.Boolean.FALSE; 27 | 28 | /** 29 | * A restriction that allows a command for regular users and is evaluated by the JDA command handler. 30 | * Regular users means no bots, and no webhooks. 31 | */ 32 | @ApplicationScoped 33 | public class RegularUserJda implements Restriction { 34 | @Override 35 | public boolean allowCommand(CommandContext commandContext) { 36 | return Optional.of(commandContext.getMessage().getAuthor()) 37 | .filter(author -> !author.isSystem()) 38 | .map(author -> !author.isBot()) 39 | .orElse(FALSE); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/net/kautler/command/api/restriction/jda/ServerManagerJda.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.api.restriction.jda; 18 | 19 | import jakarta.enterprise.context.ApplicationScoped; 20 | import net.dv8tion.jda.api.entities.Message; 21 | import net.kautler.command.api.CommandContext; 22 | import net.kautler.command.api.restriction.Restriction; 23 | 24 | import java.util.Optional; 25 | 26 | import static java.lang.Boolean.FALSE; 27 | import static net.dv8tion.jda.api.Permission.MANAGE_SERVER; 28 | 29 | /** 30 | * A restriction that allows a command for server managers and is evaluated by the JDA command handler. 31 | * If a message is not sent on a guild, this restriction always denies. 32 | */ 33 | @ApplicationScoped 34 | public class ServerManagerJda implements Restriction { 35 | @Override 36 | public boolean allowCommand(CommandContext commandContext) { 37 | return Optional.ofNullable(commandContext.getMessage().getMember()) 38 | .map(author -> author.hasPermission(MANAGE_SERVER)) 39 | .orElse(FALSE); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/net/kautler/command/api/slash/javacord/SlashCommandJavacord.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.api.slash.javacord; 18 | 19 | import java.util.List; 20 | 21 | import net.kautler.command.api.Command; 22 | import net.kautler.command.api.annotation.Description; 23 | import org.javacord.api.interaction.SlashCommandBuilder; 24 | import org.javacord.api.interaction.SlashCommandInteraction; 25 | import org.javacord.api.interaction.SlashCommandOption; 26 | 27 | import static java.util.Collections.emptyList; 28 | 29 | /** 30 | * A command that can be triggered by slash commands in Javacord. 31 | * 32 | *

When injecting a {@link SlashCommandBuilder List<SlashCommandBuilder>}, implementations of this interface 33 | * must provide a description through the {@link Description @Description} annotation or an overwritten 34 | * {@link #getDescription()} method and all aliases have to consist of one to three slash separated parts, 35 | * so either {@code "command"}, {@code "command/subcommand"}, or {@code "command/subcommand-group/subcommand"}. 36 | */ 37 | public interface SlashCommandJavacord extends Command { 38 | /** 39 | * Returns the slash command options of this command that should be used when registering the command. 40 | * 41 | *

The default implementation of this method returns an empty list. 42 | * 43 | * @return the slash command options of this command 44 | */ 45 | default List getOptions() { 46 | return emptyList(); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/net/kautler/command/parameter/converter/DecimalConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.parameter.converter; 18 | 19 | import jakarta.enterprise.context.ApplicationScoped; 20 | import net.kautler.command.Internal; 21 | import net.kautler.command.api.CommandContext; 22 | import net.kautler.command.api.parameter.InvalidParameterFormatException; 23 | import net.kautler.command.api.parameter.ParameterConverter; 24 | import net.kautler.command.api.parameter.ParameterType; 25 | 26 | import java.math.BigDecimal; 27 | 28 | import static java.lang.String.format; 29 | 30 | /** 31 | * A parameter converter that reacts to the type {@code decimal} 32 | * and converts the parameter to a {@link BigDecimal}. 33 | */ 34 | @ApplicationScoped 35 | @Internal 36 | @ParameterType("decimal") 37 | class DecimalConverter implements ParameterConverter { 38 | @Override 39 | public BigDecimal convert(String parameter, String type, CommandContext commandContext) { 40 | try { 41 | return new BigDecimal(parameter); 42 | } catch (NumberFormatException nfe) { 43 | throw new InvalidParameterFormatException(format("'%s' is not a valid decimal", parameter), nfe); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/net/kautler/command/parameter/converter/NumberConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.parameter.converter; 18 | 19 | import jakarta.enterprise.context.ApplicationScoped; 20 | import net.kautler.command.Internal; 21 | import net.kautler.command.api.CommandContext; 22 | import net.kautler.command.api.parameter.InvalidParameterFormatException; 23 | import net.kautler.command.api.parameter.ParameterConverter; 24 | import net.kautler.command.api.parameter.ParameterType; 25 | 26 | import java.math.BigInteger; 27 | 28 | import static java.lang.String.format; 29 | 30 | /** 31 | * A parameter converter that reacts to the types {@code number} and {@code integer} 32 | * and converts the parameter to a {@link BigInteger}. 33 | */ 34 | @ApplicationScoped 35 | @Internal 36 | @ParameterType("number") 37 | @ParameterType("integer") 38 | class NumberConverter implements ParameterConverter { 39 | @Override 40 | public BigInteger convert(String parameter, String type, CommandContext commandContext) { 41 | try { 42 | return new BigInteger(parameter); 43 | } catch (NumberFormatException nfe) { 44 | throw new InvalidParameterFormatException(format("'%s' is not a valid number", parameter), nfe); 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/net/kautler/command/parameter/converter/StringConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.parameter.converter; 18 | 19 | import jakarta.enterprise.context.ApplicationScoped; 20 | import net.kautler.command.Internal; 21 | import net.kautler.command.api.CommandContext; 22 | import net.kautler.command.api.parameter.ParameterConverter; 23 | import net.kautler.command.api.parameter.ParameterType; 24 | 25 | /** 26 | * A parameter converter that reacts to the types {@code string} and {@code text} and just returns the parameter as-is. 27 | * This can be helpful to specify a type for every parameter explicitly and it is mandatory if a colon in a parameter 28 | * name is necessary. 29 | */ 30 | @ApplicationScoped 31 | @Internal 32 | @ParameterType("string") 33 | @ParameterType("text") 34 | class StringConverter implements ParameterConverter { 35 | @Override 36 | public String convert(String parameter, String type, CommandContext commandContext) { 37 | return parameter; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/net/kautler/command/parameter/parser/UntypedParameterParser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.parameter.parser; 18 | 19 | import jakarta.enterprise.context.ApplicationScoped; 20 | import net.kautler.command.api.CommandContext; 21 | import net.kautler.command.api.parameter.Parameters; 22 | import net.kautler.command.parameter.ParametersImpl; 23 | 24 | import java.util.ArrayList; 25 | import java.util.Collection; 26 | import java.util.HashMap; 27 | import java.util.Map; 28 | import java.util.Objects; 29 | 30 | /** 31 | * The non-typed parameter parser that just returns {@code String} parameter values for single-valued parameters and 32 | * {@code List} for multi-valued parameters. 33 | */ 34 | @ApplicationScoped 35 | class UntypedParameterParser extends BaseParameterParser { 36 | @Override 37 | public Parameters parse(CommandContext commandContext) { 38 | return parse(commandContext, (parameterMatcher, groupNamesByTokenName) -> { 39 | Collection firstTokenValues = new ArrayList<>(); 40 | Map parameters = new HashMap<>(); 41 | groupNamesByTokenName.forEach((tokenName, groupNames) -> groupNames 42 | .stream() 43 | .map(parameterMatcher::group) 44 | .filter(Objects::nonNull) 45 | .forEach(tokenValue -> addParameterValue(parameters, tokenName, tokenValue, firstTokenValues))); 46 | return new ParametersImpl<>(parameters); 47 | }); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/net/kautler/command/parameter/parser/missingdependency/MissingDependencyParameterParser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.parameter.parser.missingdependency; 18 | 19 | import jakarta.enterprise.context.ApplicationScoped; 20 | import jakarta.enterprise.inject.Default; 21 | import net.kautler.command.api.CommandContext; 22 | import net.kautler.command.api.parameter.ParameterParser; 23 | import net.kautler.command.api.parameter.ParameterParser.Typed; 24 | import net.kautler.command.api.parameter.Parameters; 25 | 26 | /** 27 | * A parameter parser that is present if the ANTLR dependency is missing and throws an 28 | * {@link UnsupportedOperationException} if used. 29 | */ 30 | @ApplicationScoped 31 | @Default 32 | @Typed 33 | class MissingDependencyParameterParser implements ParameterParser { 34 | /** 35 | * Throws an {@link UnsupportedOperationException} as the ANTLR dependency is missing. 36 | */ 37 | public MissingDependencyParameterParser() { 38 | throw new UnsupportedOperationException("ANTLR runtime is missing"); 39 | } 40 | 41 | @Override 42 | public Parameters parse(CommandContext commandContext) { 43 | throw new AssertionError(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/net/kautler/command/usage/UsageErrorListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.usage; 18 | 19 | import org.antlr.v4.runtime.BaseErrorListener; 20 | import org.antlr.v4.runtime.RecognitionException; 21 | import org.antlr.v4.runtime.Recognizer; 22 | 23 | import static java.lang.String.format; 24 | 25 | /** 26 | * An ANTLR error listener that throws an exception when a syntax error happened. 27 | */ 28 | public class UsageErrorListener extends BaseErrorListener { 29 | @Override 30 | public void syntaxError(Recognizer recognizer, Object offendingSymbol, 31 | int line, int charPositionInLine, 32 | String msg, RecognitionException exception) { 33 | throw new IllegalArgumentException( 34 | format("%s [at %d:%d]", msg, line, charPositionInLine)); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/net/kautler/command/util/lazy/LazyReferenceByFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.util.lazy; 18 | 19 | import java.util.function.Function; 20 | 21 | import static java.util.Objects.requireNonNull; 22 | 23 | /** 24 | * A lazy reference that initializes its value on first query in a thread-safe way from the given function. 25 | * {@code null} is not valid as value and means the value was not computed yet. 26 | * 27 | * @param the class of the value object 28 | */ 29 | public class LazyReferenceByFunction extends LazyReference { 30 | /** 31 | * The function for the value that is called on first query to compute the value. 32 | */ 33 | private final Function valueFunction; 34 | 35 | /** 36 | * Constructs a new lazy reference that gets its value from the given function. 37 | * 38 | * @param valueFunction the function for the value that is called on first query to compute the value 39 | */ 40 | public LazyReferenceByFunction(Function valueFunction) { 41 | this.valueFunction = requireNonNull(valueFunction, "value function must not be null"); 42 | } 43 | 44 | /** 45 | * Returns the value of this reference. If the value was not computed yet, it gets 46 | * initialized using the value function given in the constructor with the parameter given to this 47 | * method in a thread-safe way and then returned. 48 | * 49 | * @return the value of this reference 50 | */ 51 | public T get(P parameter) { 52 | return get(() -> valueFunction.apply(parameter)); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/net/kautler/command/util/lazy/LazyReferenceBySupplier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.util.lazy; 18 | 19 | import java.util.function.Supplier; 20 | 21 | import static java.util.Objects.requireNonNull; 22 | 23 | /** 24 | * A lazy reference that initializes its value on first query in a thread-safe way from the given supplier. 25 | * {@code null} is not valid as value and means the value was not computed yet. 26 | * 27 | * @param the class of the value object 28 | */ 29 | public class LazyReferenceBySupplier extends LazyReference { 30 | /** 31 | * The supplier for the value that is called on first query to compute the value. 32 | */ 33 | private final Supplier valueSupplier; 34 | 35 | /** 36 | * Constructs a new lazy reference that gets its value from the given supplier. 37 | * 38 | * @param valueSupplier the supplier for the value that is called on first query to compute the value 39 | */ 40 | public LazyReferenceBySupplier(Supplier valueSupplier) { 41 | this.valueSupplier = requireNonNull(valueSupplier, "value supplier must not be null"); 42 | } 43 | 44 | /** 45 | * Returns the value of this reference. If the value was not computed yet, it gets 46 | * initialized using the value supplier given in the constructor in a thread-safe way and then returned. 47 | * 48 | * @return the value of this reference 49 | */ 50 | public T get() { 51 | return get(valueSupplier); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/resources/net/kautler/command/api/version.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Vampire/command-framework/7574ecdef8be3995ce4d814fd286989191a92c69/src/main/resources/net/kautler/command/api/version.properties -------------------------------------------------------------------------------- /src/pitest/java/net/kautler/test/pitest/SpockTestPlugin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.test.pitest; 18 | 19 | import org.pitest.classinfo.ClassByteArraySource; 20 | import org.pitest.testapi.Configuration; 21 | import org.pitest.testapi.TestGroupConfig; 22 | import org.pitest.testapi.TestPluginFactory; 23 | 24 | import java.util.Collection; 25 | 26 | /** 27 | * A Spock test plugin. 28 | */ 29 | public class SpockTestPlugin implements TestPluginFactory { 30 | @Override 31 | public Configuration createTestFrameworkConfiguration(TestGroupConfig config, 32 | ClassByteArraySource source, 33 | Collection excludedRunners, 34 | Collection includedTestMethods) { 35 | return new SpockConfiguration(config, excludedRunners, includedTestMethods); 36 | } 37 | 38 | @Override 39 | public String name() { 40 | return "spock"; 41 | } 42 | 43 | @Override 44 | public String description() { 45 | return "Spock plugin"; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/pitest/java/net/kautler/test/pitest/SurvivorDetectorFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.test.pitest; 18 | 19 | import org.pitest.mutationtest.ListenerArguments; 20 | import org.pitest.mutationtest.MutationResultListener; 21 | import org.pitest.mutationtest.MutationResultListenerFactory; 22 | 23 | import java.util.Properties; 24 | 25 | /** 26 | * A mutation result listener factory that produces {@link SurvivorDetector}s. 27 | */ 28 | public class SurvivorDetectorFactory implements MutationResultListenerFactory { 29 | @Override 30 | public MutationResultListener getListener(Properties props, ListenerArguments args) { 31 | return new SurvivorDetector(); 32 | } 33 | 34 | @Override 35 | public String name() { 36 | return "SURVIVOR_DETECTOR"; 37 | } 38 | 39 | @Override 40 | public String description() { 41 | return "Detects survivors and fails the run if any are found"; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/pitest/java/net/kautler/test/pitest/UncoveredDetectorFactory.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.test.pitest; 18 | 19 | import org.pitest.mutationtest.ListenerArguments; 20 | import org.pitest.mutationtest.MutationResultListener; 21 | import org.pitest.mutationtest.MutationResultListenerFactory; 22 | 23 | import java.util.Properties; 24 | 25 | /** 26 | * A mutation result listener factory that produces {@link UncoveredDetector}s. 27 | */ 28 | public class UncoveredDetectorFactory implements MutationResultListenerFactory { 29 | @Override 30 | public MutationResultListener getListener(Properties props, ListenerArguments args) { 31 | return new UncoveredDetector(); 32 | } 33 | 34 | @Override 35 | public String name() { 36 | return "UNCOVERED_DETECTOR"; 37 | } 38 | 39 | @Override 40 | public String description() { 41 | return "Detects uncovered mutants and fails the run if any are found"; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/pitest/resources/META-INF/services/org.pitest.mutationtest.MutationResultListenerFactory: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Björn Kautler 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | net.kautler.test.pitest.SurvivorDetectorFactory 16 | net.kautler.test.pitest.UncoveredDetectorFactory 17 | -------------------------------------------------------------------------------- /src/pitest/resources/META-INF/services/org.pitest.mutationtest.build.MutationInterceptorFactory: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Björn Kautler 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | net.kautler.test.pitest.MutationFilterFactory 16 | -------------------------------------------------------------------------------- /src/pitest/resources/META-INF/services/org.pitest.testapi.TestPluginFactory: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Björn Kautler 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | net.kautler.test.pitest.SpockTestPlugin 16 | -------------------------------------------------------------------------------- /src/spock/java/net/kautler/test/spock/EagerExceptionRenderer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.test.spock; 18 | 19 | import org.spockframework.runtime.SpockAssertionError; 20 | import org.spockframework.runtime.extension.AbstractGlobalExtension; 21 | import org.spockframework.runtime.model.SpecInfo; 22 | 23 | /** 24 | * A global Spock extension that eagerly renders exceptions, otherwise toString() might be called 25 | * on a CDI proxy when the container is shut down already and the call cannot be done. 26 | */ 27 | public class EagerExceptionRenderer extends AbstractGlobalExtension { 28 | @SuppressWarnings("ResultOfMethodCallIgnored") 29 | @Override 30 | public void visitSpec(SpecInfo spec) { 31 | spec.getAllFeatures().forEach(featureInfo -> 32 | featureInfo.getFeatureMethod().addInterceptor(invocation -> { 33 | try { 34 | invocation.proceed(); 35 | } catch (SpockAssertionError spockAssertionError) { 36 | spockAssertionError.toString(); 37 | throw spockAssertionError; 38 | } 39 | })); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/spock/java/net/kautler/test/spock/TestAppenderClearer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.test.spock; 18 | 19 | import org.apache.logging.log4j.test.appender.ListAppender; 20 | import org.spockframework.runtime.extension.AbstractGlobalExtension; 21 | import org.spockframework.runtime.model.SpecInfo; 22 | 23 | import static org.apache.logging.log4j.test.appender.ListAppender.getListAppender; 24 | 25 | /** 26 | * A global Spock extension that clears the test appender before each iteration. 27 | */ 28 | public class TestAppenderClearer extends AbstractGlobalExtension { 29 | @Override 30 | public void visitSpec(SpecInfo spec) { 31 | spec.getAllFeatures().forEach(featureInfo -> 32 | featureInfo.addIterationInterceptor(invocation -> { 33 | ListAppender testAppender = getListAppender("Test Appender"); 34 | if (testAppender != null) { 35 | testAppender.clear(); 36 | } 37 | invocation.proceed(); 38 | })); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/spock/resources/META-INF/services/org.codehaus.groovy.transform.ASTTransformation: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Björn Kautler 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | net.kautler.test.spock.AnonymousClassTransform 16 | -------------------------------------------------------------------------------- /src/spock/resources/META-INF/services/org.spockframework.runtime.extension.IGlobalExtension: -------------------------------------------------------------------------------- 1 | # Copyright 2019-2022 Björn Kautler 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | net.kautler.test.spock.EagerExceptionRenderer 16 | net.kautler.test.spock.TestAppenderClearer 17 | -------------------------------------------------------------------------------- /src/test/groovy/net/kautler/command/InvalidAnnotationCombinationExceptionTest.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command 18 | 19 | import spock.lang.Specification 20 | import spock.lang.Subject 21 | 22 | import static java.util.UUID.randomUUID 23 | 24 | @Subject(InvalidAnnotationCombinationException) 25 | class InvalidAnnotationCombinationExceptionTest extends Specification { 26 | def 'constructor should set message'() { 27 | given: 28 | def random = randomUUID() as String 29 | 30 | when: 31 | def testee = new InvalidAnnotationCombinationException(random) 32 | 33 | then: 34 | testee.message == random 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/groovy/net/kautler/command/LoggerProducerTest.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command 18 | 19 | import jakarta.enterprise.context.ApplicationScoped 20 | import jakarta.inject.Inject 21 | import org.apache.logging.log4j.Logger 22 | import org.jboss.weld.junit4.WeldInitiator 23 | import org.junit.Rule 24 | import spock.lang.Specification 25 | import spock.lang.Subject 26 | 27 | @Subject(LoggerProducer) 28 | class LoggerProducerTest extends Specification { 29 | @Rule 30 | WeldInitiator weld = WeldInitiator 31 | .from( 32 | SubLoggerConsumer, 33 | LoggerProducer 34 | ) 35 | .inject(this) 36 | .build() 37 | 38 | @Inject 39 | SubLoggerConsumer subLoggerConsumer 40 | 41 | @Inject 42 | @Internal 43 | Logger logger 44 | 45 | def 'logger should be produced for the class where the logger field is declared'() { 46 | expect: 47 | logger.name == getClass().canonicalName 48 | subLoggerConsumer.logger.name == LoggerConsumer.canonicalName 49 | subLoggerConsumer.subLogger.name == SubLoggerConsumer.canonicalName 50 | } 51 | 52 | static class LoggerConsumer { 53 | @Inject 54 | @Internal 55 | Logger logger 56 | } 57 | 58 | @ApplicationScoped 59 | static class SubLoggerConsumer extends LoggerConsumer { 60 | @Inject 61 | @Internal 62 | Logger subLogger 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/test/groovy/net/kautler/command/api/parameter/InvalidParameterFormatExceptionTest.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.api.parameter 18 | 19 | import spock.lang.Specification 20 | import spock.lang.Subject 21 | 22 | import static java.util.UUID.randomUUID 23 | 24 | @Subject(InvalidParameterFormatException) 25 | class InvalidParameterFormatExceptionTest extends Specification { 26 | def 'constructor should set message'() { 27 | given: 28 | def random = randomUUID() as String 29 | 30 | when: 31 | def testee = new InvalidParameterFormatException(random) 32 | 33 | then: 34 | testee.message == random 35 | } 36 | 37 | def 'constructor should set message and cause'() { 38 | given: 39 | def random = randomUUID() as String 40 | def exception = new Throwable() 41 | 42 | when: 43 | def testee = new InvalidParameterFormatException(random, exception) 44 | 45 | then: 46 | testee.message == random 47 | testee.cause == exception 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/test/groovy/net/kautler/command/api/parameter/InvalidParameterValueExceptionTest.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.api.parameter 18 | 19 | import spock.lang.Specification 20 | import spock.lang.Subject 21 | 22 | import static java.util.UUID.randomUUID 23 | 24 | @Subject(InvalidParameterValueException) 25 | class InvalidParameterValueExceptionTest extends Specification { 26 | def 'constructor should set message'() { 27 | given: 28 | def random = randomUUID() as String 29 | 30 | when: 31 | def testee = new InvalidParameterValueException(random) 32 | 33 | then: 34 | testee.message == random 35 | } 36 | 37 | def 'constructor should set message and cause'() { 38 | given: 39 | def random = randomUUID() as String 40 | def exception = new Throwable() 41 | 42 | when: 43 | def testee = new InvalidParameterValueException(random, exception) 44 | 45 | then: 46 | testee.message == random 47 | testee.cause == exception 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/test/groovy/net/kautler/command/api/restriction/AllOfTest.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.api.restriction 18 | 19 | import net.kautler.command.api.CommandContext 20 | import spock.lang.Specification 21 | import spock.lang.Subject 22 | 23 | class AllOfTest extends Specification { 24 | Restriction restriction1 = Stub() 25 | 26 | Restriction restriction2 = Stub() 27 | 28 | @Subject 29 | AllOf allOf = Spy(constructorArgs: [restriction1, restriction2]) 30 | 31 | def 'all of [restriction1Allowed: #restriction1Allowed, restriction2Allowed: #restriction2Allowed] should #be allowed'() { 32 | given: 33 | restriction1.allowCommand(_) >> restriction1Allowed 34 | restriction2.allowCommand(_) >> restriction2Allowed 35 | 36 | expect: 37 | allOf.allowCommand(Stub(CommandContext)) == allowed 38 | 39 | where: 40 | [restriction1Allowed, restriction2Allowed] << 41 | ([[true, false]] * 2).combinations() 42 | allowed = restriction1Allowed && restriction2Allowed 43 | be = allowed ? 'be' : 'not be' 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/test/groovy/net/kautler/command/api/restriction/AnyOfTest.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.api.restriction 18 | 19 | import net.kautler.command.api.CommandContext 20 | import spock.lang.Specification 21 | import spock.lang.Subject 22 | 23 | class AnyOfTest extends Specification { 24 | Restriction restriction1 = Stub() 25 | 26 | Restriction restriction2 = Stub() 27 | 28 | @Subject 29 | AnyOf anyOf = Spy(constructorArgs: [restriction1, restriction2]) 30 | 31 | def 'any of [restriction1Allowed: #restriction1Allowed, restriction2Allowed: #restriction2Allowed] should #be allowed'() { 32 | given: 33 | restriction1.allowCommand(_) >> restriction1Allowed 34 | restriction2.allowCommand(_) >> restriction2Allowed 35 | 36 | expect: 37 | anyOf.allowCommand(Stub(CommandContext)) == allowed 38 | 39 | where: 40 | [restriction1Allowed, restriction2Allowed] << 41 | ([[true, false]] * 2).combinations() 42 | allowed = restriction1Allowed || restriction2Allowed 43 | be = allowed ? 'be' : 'not be' 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/test/groovy/net/kautler/command/api/restriction/EveryoneTest.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.api.restriction 18 | 19 | import jakarta.inject.Inject 20 | import net.kautler.command.api.CommandContext 21 | import org.jboss.weld.junit4.WeldInitiator 22 | import org.junit.Rule 23 | import spock.lang.Specification 24 | import spock.lang.Subject 25 | 26 | class EveryoneTest extends Specification { 27 | @Rule 28 | WeldInitiator weld = WeldInitiator 29 | .from(Everyone) 30 | .inject(this) 31 | .build() 32 | 33 | @Inject 34 | @Subject 35 | Everyone everyone 36 | 37 | def 'everyone should be allowed'() { 38 | expect: 39 | everyone.allowCommand(Stub(CommandContext)) 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/test/groovy/net/kautler/command/api/restriction/NoneOfTest.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.api.restriction 18 | 19 | import net.kautler.command.api.CommandContext 20 | import spock.lang.Specification 21 | import spock.lang.Subject 22 | 23 | class NoneOfTest extends Specification { 24 | Restriction restriction1 = Stub() 25 | 26 | Restriction restriction2 = Stub() 27 | 28 | @Subject 29 | NoneOf noneOf = Spy(constructorArgs: [restriction1, restriction2]) 30 | 31 | def 'none of [restriction1Allowed: #restriction1Allowed, restriction2Allowed: #restriction2Allowed] should #be allowed'() { 32 | given: 33 | restriction1.allowCommand(_) >> restriction1Allowed 34 | restriction2.allowCommand(_) >> restriction2Allowed 35 | 36 | expect: 37 | noneOf.allowCommand(Stub(CommandContext)) == allowed 38 | 39 | where: 40 | [restriction1Allowed, restriction2Allowed] << 41 | ([[true, false]] * 2).combinations() 42 | allowed = !restriction1Allowed && !restriction2Allowed 43 | be = allowed ? 'be' : 'not be' 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/test/groovy/net/kautler/command/api/restriction/javacord/BotOwnerJavacordTest.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.api.restriction.javacord 18 | 19 | import jakarta.inject.Inject 20 | import net.kautler.command.api.CommandContext 21 | import org.javacord.api.entity.message.Message 22 | import org.javacord.api.entity.message.MessageAuthor 23 | import org.jboss.weld.junit4.WeldInitiator 24 | import org.junit.Rule 25 | import spock.lang.Specification 26 | import spock.lang.Subject 27 | 28 | class BotOwnerJavacordTest extends Specification { 29 | @Rule 30 | WeldInitiator weld = WeldInitiator 31 | .from(BotOwnerJavacord) 32 | .inject(this) 33 | .build() 34 | 35 | @Inject 36 | @Subject 37 | BotOwnerJavacord botOwnerJavacord 38 | 39 | CommandContext commandContext = Stub { 40 | it.message >> Stub(Message) { 41 | it.author >> Stub(MessageAuthor) 42 | } 43 | } 44 | 45 | def 'bot owner "#botOwner" should #be allowed'() { 46 | given: 47 | commandContext.message.author.botOwner >> botOwner 48 | 49 | expect: 50 | botOwnerJavacord.allowCommand(commandContext) == allowed 51 | 52 | where: 53 | botOwner || allowed | be 54 | true || true | 'be' 55 | false || false | 'not be' 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/test/groovy/net/kautler/command/api/restriction/javacord/PrivateMessageJavacordTest.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.api.restriction.javacord 18 | 19 | import jakarta.inject.Inject 20 | import net.kautler.command.api.CommandContext 21 | import org.javacord.api.entity.message.Message 22 | import org.jboss.weld.junit4.WeldInitiator 23 | import org.junit.Rule 24 | import spock.lang.Specification 25 | import spock.lang.Subject 26 | 27 | class PrivateMessageJavacordTest extends Specification { 28 | @Rule 29 | WeldInitiator weld = WeldInitiator 30 | .from(PrivateMessageJavacord) 31 | .inject(this) 32 | .build() 33 | 34 | @Inject 35 | @Subject 36 | PrivateMessageJavacord privateMessageJavacord 37 | 38 | CommandContext commandContext = Stub { 39 | it.message >> Stub(Message) 40 | } 41 | 42 | def 'private message "#privateMessage" should #be allowed'() { 43 | given: 44 | commandContext.message.privateMessage >> privateMessage 45 | 46 | expect: 47 | privateMessageJavacord.allowCommand(commandContext) == allowed 48 | 49 | where: 50 | privateMessage || allowed | be 51 | true || true | 'be' 52 | false || false | 'not be' 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/test/groovy/net/kautler/command/api/restriction/javacord/RegularUserJavacordTest.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.api.restriction.javacord 18 | 19 | import jakarta.inject.Inject 20 | import net.kautler.command.api.CommandContext 21 | import org.javacord.api.entity.message.Message 22 | import org.javacord.api.entity.user.User 23 | import org.jboss.weld.junit4.WeldInitiator 24 | import org.junit.Rule 25 | import spock.lang.Specification 26 | import spock.lang.Subject 27 | 28 | class RegularUserJavacordTest extends Specification { 29 | @Rule 30 | WeldInitiator weld = WeldInitiator 31 | .from(RegularUserJavacord) 32 | .inject(this) 33 | .build() 34 | 35 | @Inject 36 | @Subject 37 | RegularUserJavacord regularUserJavacord 38 | 39 | CommandContext commandContext = Stub { 40 | it.message >> Stub(Message) { 41 | it.userAuthor >> Optional.of(Stub(User)) 42 | } 43 | } 44 | 45 | def 'regular user "#regularUser" should #be allowed'() { 46 | given: 47 | commandContext.message.userAuthor.get().bot >> !regularUser 48 | 49 | expect: 50 | regularUserJavacord.allowCommand(commandContext) == allowed 51 | 52 | where: 53 | regularUser || allowed | be 54 | true || true | 'be' 55 | false || false | 'not be' 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/test/groovy/net/kautler/command/api/restriction/javacord/ServerManagerJavacordTest.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.api.restriction.javacord 18 | 19 | import jakarta.inject.Inject 20 | import net.kautler.command.api.CommandContext 21 | import org.javacord.api.entity.message.Message 22 | import org.javacord.api.entity.message.MessageAuthor 23 | import org.jboss.weld.junit4.WeldInitiator 24 | import org.junit.Rule 25 | import spock.lang.Specification 26 | import spock.lang.Subject 27 | 28 | class ServerManagerJavacordTest extends Specification { 29 | @Rule 30 | WeldInitiator weld = WeldInitiator 31 | .from(ServerManagerJavacord) 32 | .inject(this) 33 | .build() 34 | 35 | @Inject 36 | @Subject 37 | ServerManagerJavacord serverManagerJavacord 38 | 39 | CommandContext commandContext = Stub { 40 | it.message >> Stub(Message) { 41 | it.author >> Stub(MessageAuthor) 42 | } 43 | } 44 | 45 | def 'server manager "#serverManager" should #be allowed'() { 46 | given: 47 | commandContext.message.author.canManageServer() >> serverManager 48 | 49 | expect: 50 | serverManagerJavacord.allowCommand(commandContext) == allowed 51 | 52 | where: 53 | serverManager || allowed | be 54 | true || true | 'be' 55 | false || false | 'not be' 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/test/groovy/net/kautler/command/api/restriction/javacord/slash/BotOwnerJavacordSlashTest.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.api.restriction.javacord.slash 18 | 19 | import jakarta.inject.Inject 20 | import net.kautler.command.api.CommandContext 21 | import org.javacord.api.entity.user.User 22 | import org.javacord.api.interaction.SlashCommandInteraction 23 | import org.jboss.weld.junit4.WeldInitiator 24 | import org.junit.Rule 25 | import spock.lang.Specification 26 | import spock.lang.Subject 27 | 28 | class BotOwnerJavacordSlashTest extends Specification { 29 | @Rule 30 | WeldInitiator weld = WeldInitiator 31 | .from(BotOwnerJavacordSlash) 32 | .inject(this) 33 | .build() 34 | 35 | @Inject 36 | @Subject 37 | BotOwnerJavacordSlash botOwnerJavacord 38 | 39 | CommandContext commandContext = Stub { 40 | it.message >> Stub(SlashCommandInteraction) { 41 | it.user >> Stub(User) 42 | } 43 | } 44 | 45 | def 'bot owner "#botOwner" should #be allowed'() { 46 | given: 47 | commandContext.message.user.botOwner >> botOwner 48 | 49 | expect: 50 | botOwnerJavacord.allowCommand(commandContext) == allowed 51 | 52 | where: 53 | botOwner || allowed | be 54 | true || true | 'be' 55 | false || false | 'not be' 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/test/groovy/net/kautler/command/api/restriction/javacord/slash/PrivateMessageJavacordSlashTest.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.api.restriction.javacord.slash 18 | 19 | import jakarta.inject.Inject 20 | import net.kautler.command.api.CommandContext 21 | import org.javacord.api.entity.channel.TextChannel 22 | import org.javacord.api.interaction.SlashCommandInteraction 23 | import org.jboss.weld.junit4.WeldInitiator 24 | import org.junit.Rule 25 | import spock.lang.Specification 26 | import spock.lang.Subject 27 | 28 | class PrivateMessageJavacordSlashTest extends Specification { 29 | @Rule 30 | WeldInitiator weld = WeldInitiator 31 | .from(PrivateMessageJavacordSlash) 32 | .inject(this) 33 | .build() 34 | 35 | @Inject 36 | @Subject 37 | PrivateMessageJavacordSlash privateMessageJavacord 38 | 39 | CommandContext commandContext = Stub { 40 | it.message >> Stub(SlashCommandInteraction) { 41 | it.channel >> Optional.of(Stub(TextChannel)) 42 | } 43 | } 44 | 45 | def 'private message "#privateMessage" should #be allowed'() { 46 | given: 47 | commandContext.message.channel.get().asPrivateChannel() >> (privateMessage ? commandContext.message.channel : Optional.empty()) 48 | 49 | expect: 50 | privateMessageJavacord.allowCommand(commandContext) == allowed 51 | 52 | where: 53 | privateMessage || allowed | be 54 | true || true | 'be' 55 | false || false | 'not be' 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/test/groovy/net/kautler/command/api/restriction/javacord/slash/ServerManagerJavacordSlashTest.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.api.restriction.javacord.slash 18 | 19 | import jakarta.inject.Inject 20 | import net.kautler.command.api.CommandContext 21 | import org.javacord.api.entity.server.Server 22 | import org.javacord.api.entity.user.User 23 | import org.javacord.api.interaction.SlashCommandInteraction 24 | import org.jboss.weld.junit4.WeldInitiator 25 | import org.junit.Rule 26 | import spock.lang.Specification 27 | import spock.lang.Subject 28 | 29 | class ServerManagerJavacordSlashTest extends Specification { 30 | @Rule 31 | WeldInitiator weld = WeldInitiator 32 | .from(ServerManagerJavacordSlash) 33 | .inject(this) 34 | .build() 35 | 36 | @Inject 37 | @Subject 38 | ServerManagerJavacordSlash serverManagerJavacord 39 | 40 | CommandContext commandContext = Stub { 41 | it.message >> Stub(SlashCommandInteraction) { 42 | it.server >> Optional.of(Stub(Server)) 43 | it.user >> Stub(User) 44 | } 45 | } 46 | 47 | def 'server manager "#serverManager" should #be allowed'() { 48 | given: 49 | commandContext.message.server.get().canManage(commandContext.message.user) >> serverManager 50 | 51 | expect: 52 | serverManagerJavacord.allowCommand(commandContext) == allowed 53 | 54 | where: 55 | serverManager || allowed | be 56 | true || true | 'be' 57 | false || false | 'not be' 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/test/groovy/net/kautler/command/api/restriction/jda/GuildOwnerJdaTest.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.api.restriction.jda 18 | 19 | import jakarta.inject.Inject 20 | import net.dv8tion.jda.api.entities.Member 21 | import net.dv8tion.jda.api.entities.Message 22 | import net.kautler.command.api.CommandContext 23 | import org.jboss.weld.junit4.WeldInitiator 24 | import org.junit.Rule 25 | import spock.lang.Specification 26 | import spock.lang.Subject 27 | 28 | class GuildOwnerJdaTest extends Specification { 29 | @Rule 30 | WeldInitiator weld = WeldInitiator 31 | .from(GuildOwnerJda) 32 | .inject(this) 33 | .build() 34 | 35 | @Inject 36 | @Subject 37 | GuildOwnerJda guildOwnerJda 38 | 39 | CommandContext commandContext = Stub { 40 | it.message >> Stub(Message) { 41 | it.member >> null 42 | } 43 | } 44 | 45 | CommandContext guildCommandContext = Stub { 46 | it.message >> Stub(Message) { 47 | it.member >> Stub(Member) 48 | } 49 | } 50 | 51 | def 'guild owner "#guildOwner" should #be allowed'() { 52 | given: 53 | guildCommandContext.message.member.owner >> guildOwner 54 | 55 | expect: 56 | !guildOwnerJda.allowCommand(commandContext) 57 | guildOwnerJda.allowCommand(guildCommandContext) == allowed 58 | 59 | where: 60 | guildOwner || allowed | be 61 | true || true | 'be' 62 | false || false | 'not be' 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /src/test/groovy/net/kautler/command/api/restriction/jda/PrivateMessageJdaTest.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.api.restriction.jda 18 | 19 | import jakarta.inject.Inject 20 | import net.dv8tion.jda.api.entities.Message 21 | import net.kautler.command.api.CommandContext 22 | import org.jboss.weld.junit4.WeldInitiator 23 | import org.junit.Rule 24 | import spock.lang.Specification 25 | import spock.lang.Subject 26 | 27 | import static net.dv8tion.jda.api.entities.ChannelType.PRIVATE 28 | 29 | class PrivateMessageJdaTest extends Specification { 30 | @Rule 31 | WeldInitiator weld = WeldInitiator 32 | .from(PrivateMessageJda) 33 | .inject(this) 34 | .build() 35 | 36 | @Inject 37 | @Subject 38 | PrivateMessageJda privateMessageJda 39 | 40 | CommandContext commandContext = Stub { 41 | it.message >> Stub(Message) 42 | } 43 | 44 | def 'private message "#privateMessage" should #be allowed'() { 45 | given: 46 | commandContext.message.isFromType(PRIVATE) >> privateMessage 47 | 48 | expect: 49 | privateMessageJda.allowCommand(commandContext) == allowed 50 | 51 | where: 52 | privateMessage || allowed | be 53 | true || true | 'be' 54 | false || false | 'not be' 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/test/groovy/net/kautler/command/api/restriction/jda/RegularUserJdaTest.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.api.restriction.jda 18 | 19 | import jakarta.inject.Inject 20 | import net.dv8tion.jda.api.entities.Message 21 | import net.dv8tion.jda.api.entities.User 22 | import net.kautler.command.api.CommandContext 23 | import org.jboss.weld.junit4.WeldInitiator 24 | import org.junit.Rule 25 | import spock.lang.Specification 26 | import spock.lang.Subject 27 | 28 | class RegularUserJdaTest extends Specification { 29 | @Rule 30 | WeldInitiator weld = WeldInitiator 31 | .from(RegularUserJda) 32 | .inject(this) 33 | .build() 34 | 35 | @Inject 36 | @Subject 37 | RegularUserJda regularUserJda 38 | 39 | CommandContext commandContext = Stub { 40 | it.message >> Stub(Message) { 41 | it.author >> Stub(User) 42 | } 43 | } 44 | 45 | def 'system user author #systemUser and bot user author #botUser should #be allowed'() { 46 | given: 47 | commandContext.message.author.with { 48 | it.system >> systemUser 49 | it.bot >> botUser 50 | } 51 | 52 | expect: 53 | regularUserJda.allowCommand(commandContext) == allowed 54 | 55 | where: 56 | [systemUser, botUser] << ([[true, false]] * 2).combinations() 57 | allowed = !systemUser && !botUser 58 | be = allowed ? 'be' : 'not be' 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /src/test/groovy/net/kautler/command/api/restriction/jda/ServerManagerJdaTest.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.api.restriction.jda 18 | 19 | import jakarta.inject.Inject 20 | import net.dv8tion.jda.api.entities.Member 21 | import net.dv8tion.jda.api.entities.Message 22 | import net.kautler.command.api.CommandContext 23 | import org.jboss.weld.junit4.WeldInitiator 24 | import org.junit.Rule 25 | import spock.lang.Specification 26 | import spock.lang.Subject 27 | 28 | import static net.dv8tion.jda.api.Permission.MANAGE_SERVER 29 | 30 | class ServerManagerJdaTest extends Specification { 31 | @Rule 32 | WeldInitiator weld = WeldInitiator 33 | .from(ServerManagerJda) 34 | .inject(this) 35 | .build() 36 | 37 | @Inject 38 | @Subject 39 | ServerManagerJda serverManagerJda 40 | 41 | CommandContext commandContext = Stub { 42 | it.message >> Stub(Message) { 43 | it.member >> null 44 | } 45 | } 46 | 47 | CommandContext guildCommandContext = Stub { 48 | it.message >> Stub(Message) { 49 | it.member >> Stub(Member) 50 | } 51 | } 52 | 53 | def 'server manager "#serverManager" should #be allowed'() { 54 | given: 55 | guildCommandContext.message.member.hasPermission(MANAGE_SERVER) >> serverManager 56 | 57 | expect: 58 | !serverManagerJda.allowCommand(commandContext) 59 | serverManagerJda.allowCommand(guildCommandContext) == allowed 60 | 61 | where: 62 | serverManager || allowed | be 63 | true || true | 'be' 64 | false || false | 'not be' 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/test/groovy/net/kautler/command/api/slash/javacord/SlashCommandJavacordTest.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.api.slash.javacord 18 | 19 | import net.kautler.command.api.CommandContext 20 | import org.javacord.api.interaction.SlashCommandInteraction 21 | import spock.lang.Specification 22 | import spock.lang.Subject 23 | 24 | @Subject(SlashCommandJavacordTest) 25 | class SlashCommandJavacordTest extends Specification { 26 | def testee = new SlashCommandJavacord() { 27 | @Override 28 | void execute(CommandContext commandContext) { 29 | } 30 | } 31 | 32 | def 'default slash command options should be empty'() { 33 | expect: 34 | testee.options.size() == 0 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/test/groovy/net/kautler/command/parameter/converter/DecimalConverterTest.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.parameter.converter 18 | 19 | import net.kautler.command.api.parameter.InvalidParameterFormatException 20 | import spock.lang.Specification 21 | import spock.lang.Subject 22 | 23 | class DecimalConverterTest extends Specification { 24 | @Subject 25 | def testee = new DecimalConverter() 26 | 27 | def '"#parameter" should be converted to #result'() { 28 | expect: 29 | testee.convert(parameter, null, null) == result 30 | 31 | where: 32 | parameter || result 33 | '1.5' || 1.5 34 | '-1.5' || -1.5 35 | '0' || 0 36 | Long.MAX_VALUE as String || Long.MAX_VALUE 37 | Long.MIN_VALUE as String || Long.MIN_VALUE 38 | "${Long.toUnsignedString(-1)}.5" || (Long.MAX_VALUE as BigDecimal) * 2 + 1.5 39 | ((Long.MAX_VALUE as BigDecimal) * 3.5) as String || (Long.MAX_VALUE as BigDecimal) * 3.5 40 | } 41 | 42 | def 'non-numerical should throw InvalidParameterFormatException'() { 43 | when: 44 | testee.convert('a', null, null) 45 | 46 | then: 47 | InvalidParameterFormatException ipfe = thrown() 48 | ipfe.message == '\'a\' is not a valid decimal' 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/test/groovy/net/kautler/command/parameter/converter/NumberConverterTest.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.parameter.converter 18 | 19 | import net.kautler.command.api.parameter.InvalidParameterFormatException 20 | import spock.lang.Specification 21 | import spock.lang.Subject 22 | 23 | class NumberConverterTest extends Specification { 24 | @Subject 25 | def testee = new NumberConverter() 26 | 27 | def '"#parameter" should be converted to #result'() { 28 | expect: 29 | testee.convert(parameter, null, null) == result 30 | 31 | where: 32 | parameter || result 33 | '1' || 1 34 | '-1' || -1 35 | '0' || 0 36 | Long.MAX_VALUE as String || Long.MAX_VALUE 37 | Long.MIN_VALUE as String || Long.MIN_VALUE 38 | Long.toUnsignedString(-1) || (Long.MAX_VALUE as BigInteger) * 2 + 1 39 | ((Long.MAX_VALUE as BigInteger) * 3) as String || (Long.MAX_VALUE as BigInteger) * 3 40 | } 41 | 42 | def 'non-numerical should throw InvalidParameterFormatException'() { 43 | when: 44 | testee.convert('a', null, null) 45 | 46 | then: 47 | InvalidParameterFormatException ipfe = thrown() 48 | ipfe.message == '\'a\' is not a valid number' 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/test/groovy/net/kautler/command/parameter/converter/StringConverterTest.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.parameter.converter 18 | 19 | import spock.lang.Specification 20 | import spock.lang.Subject 21 | 22 | import static java.util.UUID.randomUUID 23 | 24 | class StringConverterTest extends Specification { 25 | @Subject 26 | def testee = new StringConverter() 27 | 28 | def 'parameter should be converted to itself'() { 29 | given: 30 | def parameter = randomUUID() as String 31 | 32 | expect: 33 | testee.convert(parameter, null, null).is(parameter) 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/test/groovy/net/kautler/command/parameter/parser/missingdependency/MissingDependencyParameterParserTest.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2020-2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.parameter.parser.missingdependency 18 | 19 | import jakarta.enterprise.inject.Instance 20 | import jakarta.inject.Inject 21 | import org.jboss.weld.junit4.WeldInitiator 22 | import org.junit.Rule 23 | import spock.lang.Specification 24 | import spock.lang.Subject 25 | 26 | @Subject(MissingDependencyParameterParser) 27 | class MissingDependencyParameterParserTest extends Specification { 28 | @Rule 29 | WeldInitiator weld = WeldInitiator 30 | .from(MissingDependencyParameterParser) 31 | .inject(this) 32 | .build() 33 | 34 | @Inject 35 | Instance testee 36 | 37 | def 'constructor should throw UnsupportedOperationException'() { 38 | when: 39 | testee.get().toString() 40 | 41 | then: 42 | UnsupportedOperationException uoe = thrown() 43 | uoe.message == 'ANTLR runtime is missing' 44 | } 45 | 46 | def 'parse should throw AssertionError'() { 47 | given: 48 | MissingDependencyParameterParser testee = Spy(useObjenesis: true) 49 | 50 | when: 51 | testee.parse(null) 52 | 53 | then: 54 | thrown(AssertionError) 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/test/groovy/net/kautler/command/usage/UsageErrorListenerTest.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.usage 18 | 19 | import spock.lang.Specification 20 | import spock.lang.Subject 21 | 22 | class UsageErrorListenerTest extends Specification { 23 | @Subject 24 | UsageErrorListener usageErrorListener = new UsageErrorListener() 25 | 26 | def 'exception should be thrown on syntax error'() { 27 | when: 28 | usageErrorListener.syntaxError(null, null, 1, 2, 'Error in Syntax', null) 29 | 30 | then: 31 | IllegalArgumentException iae = thrown() 32 | iae.message == 'Error in Syntax [at 1:2]' 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/test/groovy/net/kautler/command/util/SlashCommandBuilderProducerWithoutCommandsTest.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.command.util 18 | 19 | import jakarta.inject.Inject 20 | import org.javacord.api.interaction.SlashCommandBuilder 21 | import org.jboss.weld.junit4.WeldInitiator 22 | import org.junit.Rule 23 | import spock.lang.Specification 24 | import spock.lang.Subject 25 | 26 | @Subject(SlashCommandBuilderProducer) 27 | class SlashCommandBuilderProducerWithoutCommandsTest extends Specification { 28 | @Rule 29 | WeldInitiator weld = WeldInitiator 30 | .from(SlashCommandBuilderProducer) 31 | .inject(this) 32 | .build() 33 | 34 | @Inject 35 | List slashCommandBuilders 36 | 37 | def 'no commands available should result in empty list'() { 38 | expect: 39 | slashCommandBuilders == [] 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/test/groovy/net/kautler/test/ContextualInstanceCategory.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.test 18 | 19 | import org.jboss.weld.proxy.WeldClientProxy 20 | 21 | class ContextualInstanceCategory { 22 | static T ci(T probableProxy) { 23 | probableProxy instanceof WeldClientProxy ? 24 | probableProxy.metadata.contextualInstance : 25 | probableProxy 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/test/groovy/net/kautler/test/protocol/testproperties/Handler.groovy: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2019 Björn Kautler 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package net.kautler.test.protocol.testproperties 18 | 19 | import static java.nio.charset.StandardCharsets.UTF_8 20 | 21 | class Handler extends URLStreamHandler { 22 | @Override 23 | protected URLConnection openConnection(URL url) throws IOException { 24 | new URLConnection(url) { 25 | @Override 26 | InputStream getInputStream() throws IOException { 27 | if (url.path == 'IOException') { 28 | throw new IOException() 29 | } 30 | def properties = URLDecoder.decode(url.path, UTF_8.name()) 31 | new ByteArrayInputStream(properties.bytes) 32 | } 33 | 34 | @Override 35 | void connect() { 36 | } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/test/resources/log4j2-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 21 | 22 | <%-35.35t> <%x> <%X> <%50.50c> %m}{TRACE = magenta}%n]]> 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /src/test/resources/log4j2.component.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Vampire/command-framework/7574ecdef8be3995ce4d814fd286989191a92c69/src/test/resources/log4j2.component.properties -------------------------------------------------------------------------------- /src/test/resources/weld.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Vampire/command-framework/7574ecdef8be3995ce4d814fd286989191a92c69/src/test/resources/weld.properties --------------------------------------------------------------------------------