Skip to content

Commit

Permalink
Merge pull request #10 from BreadMoirai/plugin/waiter
Browse files Browse the repository at this point in the history
Plugin/waiter
  • Loading branch information
BreadMoirai authored Jan 31, 2018
2 parents 0ede1ea + 092032a commit db373d7
Show file tree
Hide file tree
Showing 38 changed files with 1,602 additions and 110 deletions.
2 changes: 1 addition & 1 deletion BreadBotFramework.iml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="BreadBotFramework" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="com.github.breadmoirai" external.system.module.version="0.9.1" type="JAVA_MODULE" version="4">
<module external.linked.project.id="BreadBotFramework" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$" external.system.id="GRADLE" external.system.module.group="com.github.breadmoirai" external.system.module.version="0.12.0" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ plugins {
final author = 'BreadMoirai'
final artifactId = 'breadbot-framework'
group "com.github.${author.toLowerCase()}"
version '0.11.4'
version '0.12.0'

//project.hasProperty never seems to work properly
final boolean keysArePresent = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package com.github.breadmoirai.breadbot.framework;

import com.github.breadmoirai.breadbot.framework.builder.BreadBotBuilder;
import com.github.breadmoirai.breadbot.framework.event.CommandEvent;

public interface CommandPlugin {

Expand All @@ -30,13 +29,11 @@ default String getName() {
/**
* This method is called when the BreadBotClient has been built.
*
* @param client
* @param client the
*/
default void onBreadReady(BreadBot client) {
}

default void onHelpEvent(CommandEvent event) {
event.reply("This is not the help you are looking for");
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ public BreadBotBuilder addAdminPlugin(Predicate<Member> isAdmin) {
return this;
}

@Override
public BreadBotBuilder addEventWaiterPlugin() {
CommandPluginBuilder.super.addEventWaiterPlugin();
return this;
}

@Override
public CommandHandleBuilder createCommand(Class<?> commandClass) {
Checks.notNull(commandClass, "commandClass");
Expand Down Expand Up @@ -366,9 +372,9 @@ public BreadBotBuilder clearParameterModifiers(Class<?> parameterType) {
}

@Override
public <T> BreadBotBuilder addCommandModifier(Class<T> propertyType, BiConsumer<T, CommandHandleBuilder> configurator) {
public <T> BreadBotBuilder bindCommandModifier(Class<T> propertyType, BiConsumer<T, CommandHandleBuilder> configurator) {
Checks.notNull(configurator, "configurator");
commandProperties.addCommandModifier(propertyType, configurator);
commandProperties.bindCommandModifier(propertyType, configurator);
for (CommandHandleBuilder commandBuilder : commandBuilders) {
applyCommandModifierRecursive(propertyType, configurator, commandBuilder);
}
Expand All @@ -386,9 +392,9 @@ private <T> void applyCommandModifierRecursive(Class<T> propertyType, BiConsumer
}

@Override
public <T> BreadBotBuilder addParameterModifier(Class<T> propertyType, BiConsumer<T, CommandParameterBuilder> configurator) {
public <T> BreadBotBuilder bindParameterModifier(Class<T> propertyType, BiConsumer<T, CommandParameterBuilder> configurator) {
Checks.notNull(configurator, "configurator");
commandProperties.addParameterModifier(propertyType, configurator);
commandProperties.bindParameterModifier(propertyType, configurator);
for (CommandHandleBuilder c : commandBuilders) {
applyParameterModifierRecursive(propertyType, configurator, c);
}
Expand Down Expand Up @@ -438,26 +444,26 @@ public <T> void applyParameterModifier(Class<T> propertyType, CommandParameterBu
}

@Override
public <T> BreadBotBuilder associatePreprocessorFactory(String identifier, Class<T> propertyType, Function<T, CommandPreprocessorFunction> factory) {
commandProperties.associatePreprocessorFactory(identifier, propertyType, factory);
public <T> BreadBotBuilder bindPreprocessorFactory(String identifier, Class<T> propertyType, Function<T, CommandPreprocessorFunction> factory) {
commandProperties.bindPreprocessorFactory(identifier, propertyType, factory);
return this;
}

@Override
public <T> BreadBotBuilder associatePreprocessorPredicateFactory(String identifier, Class<T> propertyType, Function<T, CommandPreprocessorPredicate> factory) {
commandProperties.associatePreprocessorPredicateFactory(identifier, propertyType, factory);
public <T> BreadBotBuilder bindPreprocessorPredicateFactory(String identifier, Class<T> propertyType, Function<T, CommandPreprocessorPredicate> factory) {
commandProperties.bindPreprocessorPredicateFactory(identifier, propertyType, factory);
return this;
}

@Override
public BreadBotBuilder associatePreprocessor(String identifier, Class<?> propertyType, CommandPreprocessorFunction function) {
commandProperties.associatePreprocessor(identifier, propertyType, function);
public BreadBotBuilder bindPreprocessor(String identifier, Class<?> propertyType, CommandPreprocessorFunction function) {
commandProperties.bindPreprocessor(identifier, propertyType, function);
return this;
}

@Override
public BreadBotBuilder associatePreprocessorPredicate(String identifier, Class<?> propertyType, CommandPreprocessorPredicate predicate) {
commandProperties.associatePreprocessorPredicate(identifier, propertyType, predicate);
public BreadBotBuilder bindPreprocessorPredicate(String identifier, Class<?> propertyType, CommandPreprocessorPredicate predicate) {
commandProperties.bindPreprocessorPredicate(identifier, propertyType, predicate);
return this;
}

Expand All @@ -484,8 +490,8 @@ public Comparator<CommandPreprocessor> getPriorityComparator() {
}

@Override
public <T> BreadBotBuilder putTypeParser(Class<T> type, TypeParser<T> parser) {
argumentTypes.putTypeParser(type, parser);
public <T> BreadBotBuilder bindTypeParser(Class<T> type, TypeParser<T> parser) {
argumentTypes.bindTypeParser(type, parser);
return this;
}

Expand All @@ -501,8 +507,8 @@ public BreadBotBuilder clearTypeModifiers(Class<?> parameterType) {
}

@Override
public BreadBotBuilder addTypeModifier(Class<?> parameterType, Consumer<CommandParameterBuilder> modifier) {
argumentTypes.addTypeModifier(parameterType, modifier);
public BreadBotBuilder bindTypeModifier(Class<?> parameterType, Consumer<CommandParameterBuilder> modifier) {
argumentTypes.bindTypeModifier(parameterType, modifier);
for (CommandHandleBuilderInternal commandBuilder : commandBuilders) {
applyTypeModifierRecursive(commandBuilder, parameterType, modifier);
}
Expand All @@ -526,8 +532,8 @@ public void applyTypeModifiers(CommandParameterBuilder parameterBuilder) {
}

@Override
public <T> BreadBotBuilder registerResultHandler(Class<T> resultType, CommandResultHandler<T> handler) {
resultManager.registerResultHandler(resultType, handler);
public <T> BreadBotBuilder bindResultHandler(Class<T> resultType, CommandResultHandler<T> handler) {
resultManager.bindResultHandler(resultType, handler);
return this;
}

Expand Down Expand Up @@ -596,6 +602,8 @@ public BreadBot build() {
commandEventFactory = new CommandEventFactoryImpl(getPlugin(PrefixPlugin.class));
final List<CommandHandleImpl> build = commandBuilders.stream().map(o -> o.build(null)).collect(Collectors.toList());
commands.addAll(build);
return new BreadBotClientImpl(plugins, commands, resultManager, argumentTypes, commandEventFactory, preProcessPredicate, shouldEvaluateCommandOnMessageUpdate);
final BreadBotClientImpl breadBotClient = new BreadBotClientImpl(plugins, commands, resultManager, argumentTypes, commandEventFactory, preProcessPredicate, shouldEvaluateCommandOnMessageUpdate);
breadBotClient.propogateReadyEvent();
return breadBotClient;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public interface CommandParameterManagerBuilder extends CommandParameterManager
* @param <T> the type
* @return this
*/
<T> CommandParameterManagerBuilder putTypeParser(Class<T> type, TypeParser<T> parser);
<T> CommandParameterManagerBuilder bindTypeParser(Class<T> type, TypeParser<T> parser);


CommandParameterManagerBuilder clearTypeModifiers(Class<?> parameterType);
Expand All @@ -43,5 +43,5 @@ public interface CommandParameterManagerBuilder extends CommandParameterManager
* @param modifier a Consumer that takes the ParameterBuilder as its argument
* @return this
*/
CommandParameterManagerBuilder addTypeModifier(Class<?> parameterType, Consumer<CommandParameterBuilder> modifier);
CommandParameterManagerBuilder bindTypeModifier(Class<?> parameterType, Consumer<CommandParameterBuilder> modifier);
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.github.breadmoirai.breadbot.plugins.owner.StaticOwnerPlugin;
import com.github.breadmoirai.breadbot.plugins.prefix.PrefixPlugin;
import com.github.breadmoirai.breadbot.plugins.prefix.UnmodifiablePrefixPlugin;
import com.github.breadmoirai.breadbot.plugins.waiter.EventWaiterPlugin;
import net.dv8tion.jda.core.entities.Member;
import net.dv8tion.jda.core.utils.Checks;

Expand Down Expand Up @@ -130,5 +131,9 @@ default CommandPluginBuilder addOwnerPlugin(long... owners) {
return this;
}

default CommandPluginBuilder addEventWaiterPlugin() {
return addPlugin(new EventWaiterPlugin());
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public interface CommandPropertiesManager {
* The second argument is the {@link CommandHandleBuilder CommandHandleBuilder} the property is attached to.
* @param <T> the propertyType
*/
<T> CommandPropertiesManager addCommandModifier(Class<T> propertyType, BiConsumer<T, CommandHandleBuilder> configurator);
<T> CommandPropertiesManager bindCommandModifier(Class<T> propertyType, BiConsumer<T, CommandHandleBuilder> configurator);

/**
* Removes any existing behavior attached to this parameter.
Expand All @@ -70,7 +70,7 @@ public interface CommandPropertiesManager {
* The second argument is the {@link CommandHandleBuilder CommandHandleBuilder} the property is attached to.
* @param <T> the propertyType
*/
<T> CommandPropertiesManager addParameterModifier(Class<T> propertyType, BiConsumer<T, CommandParameterBuilder> configurator);
<T> CommandPropertiesManager bindParameterModifier(Class<T> propertyType, BiConsumer<T, CommandParameterBuilder> configurator);

/**
* Applies modifiers to a CommandHandleBuilder based on whether the handle contains a property.
Expand All @@ -86,7 +86,7 @@ public interface CommandPropertiesManager {
* @param <T> the property type.
* @return a BiConsumer if present, otherwise {@code null}.
* @see #clearCommandModifiers(Class)
* @see #addCommandModifier(Class, BiConsumer)
* @see #bindCommandModifier(Class, BiConsumer)
* @see #applyCommandModifier(Class, CommandHandleBuilder)
*/
<T> BiConsumer<T, CommandHandleBuilder> getCommandModifier(Class<T> propertyType);
Expand All @@ -100,7 +100,7 @@ public interface CommandPropertiesManager {
* @param builder the CommandHandleBuilder to be modified
* @param <T> the property type
* @see #clearCommandModifiers(Class) (Class)
* @see #addCommandModifier(Class, BiConsumer)
* @see #bindCommandModifier(Class, BiConsumer)
* @see #getCommandModifier(Class)
*/
<T> void applyCommandModifier(Class<T> propertyType, CommandHandleBuilder builder);
Expand All @@ -119,7 +119,7 @@ public interface CommandPropertiesManager {
* @param <T> the property type.
* @return a BiConsumer if present, otherwise {@code null}.
* @see #clearParameterModifiers(Class)
* @see #addParameterModifier(Class, BiConsumer)
* @see #bindParameterModifier(Class, BiConsumer)
* @see #applyParameterModifier(Class, CommandParameterBuilder)
*/
<T> BiConsumer<T, CommandParameterBuilder> getParameterModifier(Class<T> propertyType);
Expand All @@ -132,7 +132,7 @@ public interface CommandPropertiesManager {
* @param builder the CommandHandleBuilder to be modified
* @param <T> the property type
* @see #clearParameterModifiers(Class) (Class, BiConsumer)
* @see #addParameterModifier(Class, BiConsumer)
* @see #bindParameterModifier(Class, BiConsumer)
* @see #getParameterModifier(Class)
*/
<T> void applyParameterModifier(Class<T> propertyType, CommandParameterBuilder builder);
Expand All @@ -144,8 +144,8 @@ public interface CommandPropertiesManager {
* @param propertyType the property class
* @param function a {@link CommandPreprocessorFunction#process CommandPreprocessorFunction}
*/
default CommandPropertiesManager associatePreprocessor(String identifier, Class<?> propertyType, CommandPreprocessorFunction function) {
addCommandModifier(propertyType, (t, commandHandleBuilder) -> commandHandleBuilder.addPreprocessor(new CommandPreprocessor(identifier, function)));
default CommandPropertiesManager bindPreprocessor(String identifier, Class<?> propertyType, CommandPreprocessorFunction function) {
bindCommandModifier(propertyType, (t, commandHandleBuilder) -> commandHandleBuilder.addPreprocessor(new CommandPreprocessor(identifier, function)));
return this;
}

Expand All @@ -157,8 +157,8 @@ default CommandPropertiesManager associatePreprocessor(String identifier, Class<
* @param factory a function that generates a preprocessor based upon the value of the property
* @param <T> the property type
*/
default <T> CommandPropertiesManager associatePreprocessorFactory(String identifier, Class<T> propertyType, Function<T, CommandPreprocessorFunction> factory) {
addCommandModifier(propertyType, (t, commandHandleBuilder) -> commandHandleBuilder.addPreprocessor(new CommandPreprocessor(identifier, factory.apply(t))));
default <T> CommandPropertiesManager bindPreprocessorFactory(String identifier, Class<T> propertyType, Function<T, CommandPreprocessorFunction> factory) {
bindCommandModifier(propertyType, (t, commandHandleBuilder) -> commandHandleBuilder.addPreprocessor(new CommandPreprocessor(identifier, factory.apply(t))));
return this;
}

Expand All @@ -169,8 +169,8 @@ default <T> CommandPropertiesManager associatePreprocessorFactory(String identif
* @param propertyType the property class
* @param predicate a {@link java.util.function.Predicate Predicate}{@literal <}{@link CommandEvent CommandEvent}{@literal >} that returns {@code true} when the command should continue to execute, {@code false} otherwise
*/
default CommandPropertiesManager associatePreprocessorPredicate(String identifier, Class<?> propertyType, CommandPreprocessorPredicate predicate) {
addCommandModifier(propertyType, (t, commandHandleBuilder) -> commandHandleBuilder.addPreprocessor(new CommandPreprocessor(identifier, predicate)));
default CommandPropertiesManager bindPreprocessorPredicate(String identifier, Class<?> propertyType, CommandPreprocessorPredicate predicate) {
bindCommandModifier(propertyType, (t, commandHandleBuilder) -> commandHandleBuilder.addPreprocessor(new CommandPreprocessor(identifier, predicate)));
return this;
}

Expand All @@ -182,8 +182,8 @@ default CommandPropertiesManager associatePreprocessorPredicate(String identifie
* @param factory a function that generates a preprocessor predicate based upon the value of the property
* @param <T> the property type
*/
default <T> CommandPropertiesManager associatePreprocessorPredicateFactory(String identifier, Class<T> propertyType, Function<T, CommandPreprocessorPredicate> factory) {
addCommandModifier(propertyType, (t, commandHandleBuilder) -> commandHandleBuilder.addPreprocessor(new CommandPreprocessor(identifier, factory.apply(t))));
default <T> CommandPropertiesManager bindPreprocessorPredicateFactory(String identifier, Class<T> propertyType, Function<T, CommandPreprocessorPredicate> factory) {
bindCommandModifier(propertyType, (t, commandHandleBuilder) -> commandHandleBuilder.addPreprocessor(new CommandPreprocessor(identifier, factory.apply(t))));
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

public interface CommandResultManagerBuilder {

<T> CommandResultManagerBuilder registerResultHandler(Class<T> resultType, CommandResultHandler<T> handler);
<T> CommandResultManagerBuilder bindResultHandler(Class<T> resultType, CommandResultHandler<T> handler);

<T> CommandResultHandler<? super T> getResultHandler(Class<T> resultType);
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2017-2018 Ton Ly (BreadMoirai)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.github.breadmoirai.breadbot.framework.command;

import com.github.breadmoirai.breadbot.framework.event.CommandEvent;
Expand Down Expand Up @@ -39,6 +55,7 @@ public String getDescription() {
@Override
public boolean handle(CommandEventInternal event, Iterator<String> keyItr) {
onCommand(event);
event.getManager().complete();
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public CommandPropertiesManager clearCommandModifiers(Class<?> propertyType) {
}

@Override
public <T> CommandPropertiesManager addCommandModifier(Class<T> propertyType, BiConsumer<T, CommandHandleBuilder> configurator) {
public <T> CommandPropertiesManager bindCommandModifier(Class<T> propertyType, BiConsumer<T, CommandHandleBuilder> configurator) {
commandPropertyMap.merge(propertyType, configurator, (c1, c2) -> {
@SuppressWarnings("unchecked") final BiConsumer<T, CommandHandleBuilder> cc1 = (BiConsumer<T, CommandHandleBuilder>) c1;
@SuppressWarnings("unchecked") final BiConsumer<T, CommandHandleBuilder> cc2 = (BiConsumer<T, CommandHandleBuilder>) c2;
Expand All @@ -88,7 +88,7 @@ public CommandPropertiesManager clearParameterModifiers(Class<?> parameterType)
}

@Override
public <T> CommandPropertiesManager addParameterModifier(Class<T> propertyType, BiConsumer<T, CommandParameterBuilder> configurator) {
public <T> CommandPropertiesManager bindParameterModifier(Class<T> propertyType, BiConsumer<T, CommandParameterBuilder> configurator) {
parameterPropertyMap.merge(propertyType, configurator, (c1, c2) -> {
@SuppressWarnings("unchecked") final BiConsumer<T, CommandParameterBuilder> cc1 = (BiConsumer<T, CommandParameterBuilder>) c1;
@SuppressWarnings("unchecked") final BiConsumer<T, CommandParameterBuilder> cc2 = (BiConsumer<T, CommandParameterBuilder>) c2;
Expand Down Expand Up @@ -147,7 +147,7 @@ public <T> void applyParameterModifier(Class<T> propertyType, CommandParameterBu
}

private <T> void associatePreprocessor(Class<T> propertyType, Function<T, CommandPreprocessor> factory) {
addCommandModifier(propertyType, (t, commandHandleBuilder) -> commandHandleBuilder.addPreprocessor(factory.apply(t)));
bindCommandModifier(propertyType, (t, commandHandleBuilder) -> commandHandleBuilder.addPreprocessor(factory.apply(t)));
}

@Override
Expand Down
Loading

0 comments on commit db373d7

Please sign in to comment.