Skip to content

Commit

Permalink
Moved Response to correct package. Commands now have no return value.
Browse files Browse the repository at this point in the history
  • Loading branch information
BreadMoirai committed Aug 3, 2017
1 parent ec5c718 commit 8dc918f
Show file tree
Hide file tree
Showing 16 changed files with 45 additions and 55 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ plugins {
apply plugin: 'com.github.breadmoirai.github-release'

group 'com.github.breadmoirai'
version '0.4.3'
version '0.4.4'

sourceCompatibility = 1.8
targetCompatibility = 1.8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,13 @@
package com.github.breadmoirai.bot.framework.core;

import com.github.breadmoirai.bot.framework.core.command.ICommand;
import com.github.breadmoirai.bot.framework.core.impl.Response;

import java.util.Optional;
import java.util.stream.Stream;

public interface CommandEngine {

Optional<Response> execute(CommandEvent event);
void execute(CommandEvent event);

Class<? extends ICommand> getCommandClass(String key);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
*/
package com.github.breadmoirai.bot.framework.core;

import com.github.breadmoirai.bot.framework.core.impl.Response;
import com.github.breadmoirai.bot.framework.core.response.menu.PromptBuilder;
import com.github.breadmoirai.bot.framework.core.response.menu.ReactionMenuBuilder;
import com.github.breadmoirai.bot.framework.core.response.simple.EmbedResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.github.breadmoirai.bot.framework.core.impl;
package com.github.breadmoirai.bot.framework.core;

import com.github.breadmoirai.bot.framework.core.CommandEvent;
import com.github.breadmoirai.bot.framework.core.SamuraiClient;
import com.github.breadmoirai.bot.framework.core.response.simple.EditResponse;
import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.entities.MessageChannel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@
*/
package com.github.breadmoirai.bot.framework.core;

import com.github.breadmoirai.bot.framework.core.impl.Response;
import net.dv8tion.jda.core.JDA;
import net.dv8tion.jda.core.entities.TextChannel;
import net.dv8tion.jda.core.entities.User;

import java.util.Objects;
import java.util.Optional;

public interface SamuraiClient {
Expand All @@ -33,11 +34,31 @@ public interface SamuraiClient {

CommandEngine getCommandEngine();

void send(Response response);
JDA getJDA();

void send(long channeId, Response response);
default void send(Response response) {
send(response.getChannelId(), response);
}

void send(TextChannel channel, Response response);

void send(User user, Response response);
default void send(long channeId, Response response) {
TextChannel textChannel = getJDA().getTextChannelById(channeId);
if (textChannel == null) return;
send(textChannel, response);
}


default void send(TextChannel textChannel, Response response) {
Objects.requireNonNull(textChannel, "TextChannel");
Objects.requireNonNull(response, "Response");
response.base(0, textChannel.getIdLong(), textChannel.getGuild().getIdLong(), 0, this);
response.send(textChannel);
}

default void send(User user, Response response) {
Objects.requireNonNull(user, "User");
Objects.requireNonNull(user, "Response");
response.setClient(this);
user.openPrivateChannel().queue(response::send);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.github.breadmoirai.bot.framework.core.CommandEngine;
import com.github.breadmoirai.bot.framework.core.CommandEvent;
import com.github.breadmoirai.bot.framework.core.IModule;
import com.github.breadmoirai.bot.framework.core.Response;
import com.github.breadmoirai.bot.framework.core.command.ICommand;
import net.dv8tion.jda.core.utils.SimpleLog;

Expand Down Expand Up @@ -72,7 +73,7 @@ private List<Class<?>> getInterfaceHeirarchy(Class<?> from, Class<?> toSuper) {


@Override
public Optional<Response> execute(CommandEvent event) {
public void execute(CommandEvent event) {
ICommand command;
final String key = event.getKey().toLowerCase();
command = getCommand(key);
Expand All @@ -83,7 +84,6 @@ public Optional<Response> execute(CommandEvent event) {
command.run();
}
}
return Optional.empty();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ public SamuraiClientImpl(List<IModule> modules, IEventManager eventManager, ICom
this.commandEngine = engineBuilder.build();
}

@Override
public JDA getJDA() {
return jda;
}

@Override
public boolean hasModule(String moduleName) {
Expand Down Expand Up @@ -99,35 +103,6 @@ public CommandEngine getCommandEngine() {
return commandEngine;
}

@Override
public void send(Response response) {
send(response.getChannelId(), response);
}

@Override
public void send(long channeId, Response response) {
TextChannel textChannel = jda.getTextChannelById(channeId);
if (textChannel == null) return;
send(textChannel, response);
}

@Override
public void send(TextChannel textChannel, Response response) {
Objects.requireNonNull(textChannel, "TextChannel");
Objects.requireNonNull(response, "Response");
response.base(0, textChannel.getIdLong(), textChannel.getGuild().getIdLong(), 0, this);
response.send(textChannel);
}

@Override
public void send(User user, Response response) {
Objects.requireNonNull(user, "User");
Objects.requireNonNull(user, "Response");
response.setClient(this);
user.openPrivateChannel().queue(response::send);
}


private class SamuraiEventListener extends ListenerAdapter {

private final Predicate<Message> preProcessPredicate;
Expand Down Expand Up @@ -158,9 +133,7 @@ private void onGuildMessageEvent(GenericGuildMessageEvent event, Message message
if (preProcessPredicate.test(message)) {
final CommandEvent commandEvent = eventFactory.createEvent(event, message, SamuraiClientImpl.this);
if (commandEvent != null) {
final Optional<Response> response = commandEngine.execute(commandEvent);
response.ifPresent(r -> r.setClient(SamuraiClientImpl.this));
response.ifPresent(SamuraiClientImpl.this::send);
commandEngine.execute(commandEvent);
eventManager.handle(commandEvent);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package com.github.breadmoirai.bot.framework.core.response;

import com.github.breadmoirai.bot.framework.core.impl.Response;
import com.github.breadmoirai.bot.framework.core.Response;
import com.github.breadmoirai.bot.framework.core.response.menu.ResponseMenu;
import com.github.breadmoirai.bot.framework.core.response.simple.StringResponse;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package com.github.breadmoirai.bot.framework.core.response.list;

import com.github.breadmoirai.bot.framework.core.impl.Response;
import com.github.breadmoirai.bot.framework.core.Response;
import com.github.breadmoirai.bot.framework.core.response.CloseableResponse;
import net.dv8tion.jda.core.entities.Message;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import com.github.breadmoirai.bot.framework.core.response.CloseableResponse;
import com.github.breadmoirai.bot.framework.core.response.simple.EditResponse;
import net.dv8tion.jda.core.entities.Message;
import com.github.breadmoirai.bot.framework.core.impl.Response;
import com.github.breadmoirai.bot.framework.core.Response;
import com.github.breadmoirai.bot.framework.waiter.EventWaiter;

public class ResponseMenu extends Response implements CloseableResponse {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.github.breadmoirai.bot.framework.core.response.simple;

import com.github.breadmoirai.bot.framework.core.impl.Response;
import com.github.breadmoirai.bot.framework.core.Response;

public abstract class BasicResponse extends Response {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package com.github.breadmoirai.bot.framework.core.response.simple;

import com.github.breadmoirai.bot.framework.core.impl.Response;
import com.github.breadmoirai.bot.framework.core.Response;
import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.entities.MessageChannel;

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

package com.github.breadmoirai.bot.framework.core.response.simple;

import com.github.breadmoirai.bot.framework.core.impl.Response;
import com.github.breadmoirai.bot.framework.core.Response;
import net.dv8tion.jda.core.MessageBuilder;
import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.entities.MessageEmbed;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.github.breadmoirai.bot.framework.core.response.simple;

import com.github.breadmoirai.bot.framework.core.impl.Response;
import com.github.breadmoirai.bot.framework.core.Response;
import net.dv8tion.jda.core.entities.Message;

import java.util.function.Consumer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
package com.github.breadmoirai.bot.framework.core.response.simple;

import com.github.breadmoirai.bot.framework.core.impl.Response;
import com.github.breadmoirai.bot.framework.core.Response;
import com.github.breadmoirai.bot.framework.core.response.menu.reactions.IMenuReaction;
import com.github.breadmoirai.bot.framework.core.response.menu.reactions.MenuEmoji;
import com.github.breadmoirai.bot.framework.core.response.menu.reactions.MenuEmote;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

package com.github.breadmoirai.bot.framework.core.response.simple;

import com.github.breadmoirai.bot.framework.core.impl.Response;
import com.github.breadmoirai.bot.framework.core.Response;
import net.dv8tion.jda.core.MessageBuilder;
import net.dv8tion.jda.core.entities.Message;
import net.dv8tion.jda.core.entities.MessageChannel;
Expand Down

0 comments on commit 8dc918f

Please sign in to comment.