-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add vagrant file to the examples Add examples Add lombok logs Add jakson Add java 20 Move torrent client to the separate service Make output more readable Change CommandsCollection Move Void actions to the separate classes Refactoring Add start and pause all command Change CommandsCollection Move Void actions to the separate classes Refactoring Fix percentage for file list
- Loading branch information
Showing
48 changed files
with
691 additions
and
498 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
bot/src/main/java/com/halushko/kinocat/bot/handlers/telegram/TextHandler.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 0 additions & 71 deletions
71
core/src/main/java/com/halushko/kinocat/core/cli/Command.java
This file was deleted.
Oops, something went wrong.
37 changes: 0 additions & 37 deletions
37
core/src/main/java/com/halushko/kinocat/core/cli/Script.java
This file was deleted.
Oops, something went wrong.
29 changes: 29 additions & 0 deletions
29
core/src/main/java/com/halushko/kinocat/core/commands/Command.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.halushko.kinocat.core.commands; | ||
|
||
import com.halushko.kinocat.core.rabbit.SmartJson; | ||
import lombok.Getter; | ||
|
||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
|
||
@Getter | ||
public class Command { | ||
private final String command; | ||
private final String queue; | ||
private final SmartJson arguments; | ||
|
||
Command(){ | ||
command = ""; | ||
queue = Constants.Queues.Telegram.TELEGRAM_OUTPUT_TEXT; | ||
arguments = new SmartJson(SmartJson.KEYS.TEXT, "Такої команди не знайдено"); | ||
} | ||
|
||
Command(String command, String queue, SmartJson arguments) { | ||
this.command = command == null ? "" : command; | ||
this.queue = queue == null ? "" : queue; | ||
this.arguments = arguments == null ? new SmartJson("") : arguments; | ||
} | ||
Command(String command, String queue, Map<String, String> arguments) { | ||
this(command, queue, arguments == null ? new SmartJson("") : new SmartJson(new LinkedHashMap<>(arguments))); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
core/src/main/java/com/halushko/kinocat/core/commands/CommandChecker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.halushko.kinocat.core.commands; | ||
|
||
import com.halushko.kinocat.core.rabbit.SmartJson; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
@Slf4j | ||
class CommandChecker { | ||
private final String fullText; | ||
private Command command = new Command(); | ||
|
||
private CommandChecker(String str) { | ||
this.fullText = str; | ||
} | ||
|
||
static Command getCommand(String inputText, Collection<Command> commandsToCheck) { | ||
CommandChecker checker = new CommandChecker(inputText); | ||
commandsToCheck.forEach(checker::validate); | ||
return checker.command; | ||
} | ||
|
||
private void validate(Command candidate) { | ||
if (candidate == null) return; | ||
String fullCommand = fullText.split(" ")[0]; | ||
if (!fullCommand.endsWith("_")) { | ||
if (candidate.getCommand().equals(fullCommand)) { | ||
setCommand(candidate); | ||
} | ||
} | ||
if (fullText.startsWith(candidate.getCommand()) && this.command.getCommand().length() < candidate.getCommand().length()) { | ||
setCommand(candidate); | ||
} | ||
} | ||
|
||
private void setCommand(Command candidate) { | ||
log.debug("[setCommandText] Command={}, fullText={}, Queue={}, Arguments={}", candidate.getCommand(), fullText, candidate.getQueue(), candidate.getArguments()); | ||
String delimiter = candidate.getCommand().endsWith("_") ? "_" : "\\s+"; | ||
Map<String, Object> arguments = new HashMap<>() {{ | ||
put(SmartJson.KEYS.COMMAND_ARGUMENTS.name(), | ||
fullText.replace(candidate.getCommand(), "") | ||
.trim() | ||
.split(delimiter) | ||
); | ||
}}; | ||
command = new Command(candidate.getCommand(), candidate.getQueue(), new SmartJson(arguments)); | ||
} | ||
} |
35 changes: 20 additions & 15 deletions
35
...o/kinocat/core/cli/ScriptsCollection.java → ...cat/core/commands/CommandsCollection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.