Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #54: Allowed cooler messages for timer, clarified help text #55

Merged
merged 1 commit into from
Apr 4, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 9 additions & 4 deletions src/main/java/com/gmail/inverseconduit/timer/TimerCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import static com.gmail.inverseconduit.AppContext.INSTANCE;

import java.util.Arrays;
import java.util.stream.Collectors;

import com.gmail.inverseconduit.chat.ChatInterface;
import com.gmail.inverseconduit.commands.CommandHandle;
import com.gmail.inverseconduit.datatype.ChatMessage;
Expand All @@ -15,14 +18,14 @@ public static CommandHandle timerCommand(ChatInterface chatInterface) {
CommandHandle handle =
new CommandHandle.Builder("timer", message -> TimerCommands.processChatMessage(message, chatInterface))
.setHelpText(
"Schedule Timers for your personal use. Syntax: timer delay(in minutes) (optional message). You can also abort timers by calling timer abort timernumber")
"Schedule Timers for your personal use. Syntax: timer (delay in minutes) (optional message). You can also abort timers by calling timer abort timernumber")
.setInfoText("Schedule Timers for your personal use.").build();
return handle;
}

private static String processChatMessage(ChatMessage message, ChatInterface chatInterface) {
String[] arguments = message.getMessage().split(" ");
if (2 > arguments.length || 3 < arguments.length) { return "Command does not match the syntax: timer delay(in minutes) (optional message). You can also abort timers by calling timer abort timernumber"; }
if (2 > arguments.length) { return "Command does not match the syntax: timer (delay in minutes) (optional message). You can also abort timers by calling timer abort timernumber"; }

if (arguments[1].equalsIgnoreCase("abort") && 3 == arguments.length) { return handleCancelRequest(arguments); }
int requestedDelay;
Expand All @@ -33,9 +36,11 @@ private static String processChatMessage(ChatMessage message, ChatInterface chat
}

final int timernumber;
if (3 == arguments.length) { // includes a custom message
if (3 <= arguments.length) { // includes a custom message
timernumber = INSTANCE.get(TimerKeeper.class).addTimer(() -> {
chatInterface.sendMessage(SeChatDescriptor.buildSeChatDescriptorFrom(message), String.format("@%s %s", message.getUsername(), arguments[2]));
final String userMessage = Arrays.stream(arguments, 2, arguments.length).collect(Collectors.joining(" "));

chatInterface.sendMessage(SeChatDescriptor.buildSeChatDescriptorFrom(message), String.format("@%s %s", message.getUsername(), userMessage));
}, requestedDelay);
}
else {
Expand Down