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

Alpha #39

Merged
merged 34 commits into from
Nov 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
2150b5d
Beta 5 add vagrantfile (#31)
halushko Oct 8, 2023
9bc4b54
Beta 6 add log (#33)
halushko Oct 9, 2023
6e17834
Beta 7 add jakson (#34)
halushko Oct 11, 2023
08a24cd
Beta 8 move torrent from cli to web api (#35)
halushko Oct 23, 2023
191971f
Merge remote-tracking branch 'origin/master' into alpha
Oct 23, 2023
901ada0
Merge remote-tracking branch 'origin/alpha' into alpha
Oct 23, 2023
35f534a
Beta 9 beautiful output (#37)
halushko Oct 23, 2023
fcba10e
Add start and pause all command
Oct 25, 2023
3850787
Add start and pause all command
Oct 25, 2023
be81a3d
Add start and pause all command
Oct 25, 2023
d7eef24
Add start and pause all command
Oct 25, 2023
3173c5f
Add start and pause all command
Oct 26, 2023
123d982
Add start and pause all command
Oct 31, 2023
a8d64c1
Add start and pause all command
Oct 31, 2023
a0d4b01
Add start and pause all command
Oct 31, 2023
3d4bbcb
Add start and pause all command
Oct 31, 2023
354806f
Add start and pause all command
Nov 1, 2023
84d66b4
Add start and pause all command
Nov 1, 2023
151a43d
Add start and pause all command
Nov 1, 2023
ae690ec
Add start and pause all command
Nov 1, 2023
4166318
Add start and pause all command
Nov 1, 2023
57cfa4e
Add start and pause all command
Nov 1, 2023
f5cb114
Add start and pause all command
Nov 1, 2023
ab8c87e
Add start and pause all command
Nov 1, 2023
0832eec
Add start and pause all command
Nov 1, 2023
b159792
Add start and pause all command
Nov 1, 2023
408145c
Add start and pause all command
Nov 1, 2023
a01a5a6
Add start and pause all command
Nov 5, 2023
437317f
Add start and pause all command
Nov 5, 2023
10552a9
Add start and pause all command
Nov 5, 2023
b6b84cd
Add start and pause all command
Nov 5, 2023
1d5a6f8
Beta 10 pause start all (#38)
halushko Nov 5, 2023
0079308
Merge branch 'master' into alpha
Nov 5, 2023
8099490
Merge branch 'beta-10_pause_start_all' into alpha
Nov 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion bot/src/main/java/com/halushko/kinocat/bot/KoTorrentBot.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.halushko.kinocat.bot.handlers.telegram.MyPingHandler;
import com.halushko.kinocat.bot.handlers.telegram.TextHandler;
import com.halushko.kinocat.bot.handlers.telegram.TorrentFileHandler;
import com.halushko.kinocat.core.handlers.input.InputMessageHandler;
import com.halushko.kinocat.core.handlers.telegram.UserMessageHandler;
import lombok.extern.slf4j.Slf4j;
import org.telegram.telegrambots.bots.TelegramLongPollingBot;
Expand Down Expand Up @@ -88,7 +89,7 @@ public static void sendText(long chatId, String str) {
log.debug("[BOT.sendText] Send text chatId:{}, text:{}", chatId, str);
BOT.execute(new SendMessage() {{
setChatId(chatId);
setText(str);
setText(str.replace(InputMessageHandler.OUTPUT_SEPARATOR, "\n"));
}}
);
} catch (TelegramApiException ex) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.halushko.kinocat.bot.handlers.input;

import com.halushko.kinocat.core.cli.Constants;
import com.halushko.kinocat.core.commands.Constants;
import com.halushko.kinocat.core.handlers.input.InputMessageHandler;
import com.halushko.kinocat.core.rabbit.SmartJson;
import lombok.extern.slf4j.Slf4j;
Expand All @@ -10,11 +10,12 @@
@Slf4j
public class SendTextMessageToUser extends InputMessageHandler {
@Override
protected void getDeliverCallbackPrivate(SmartJson message) {
protected String getDeliverCallbackPrivate(SmartJson message) {
long chatId = message.getUserId();
String text = message.getText();
log.debug("[SendTextMessageToUser] Send text chatId:{}, text:{}", chatId, text);
sendText(chatId, text);
return text;
}
@Override
protected String getQueue() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.halushko.kinocat.bot.handlers.telegram;

import com.halushko.kinocat.core.cli.Constants;
import com.halushko.kinocat.core.commands.Constants;
import com.halushko.kinocat.core.handlers.telegram.UserMessageHandler;
import com.halushko.kinocat.core.rabbit.RabbitUtils;
import com.halushko.kinocat.core.rabbit.SmartJson;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.halushko.kinocat.bot.handlers.telegram;

import com.halushko.kinocat.bot.KoTorrentBot;
import com.halushko.kinocat.core.cli.Constants;
import com.halushko.kinocat.core.commands.Constants;
import com.halushko.kinocat.core.handlers.telegram.UserMessageHandler;
import com.halushko.kinocat.core.rabbit.SmartJson;
import com.halushko.kinocat.core.rabbit.RabbitUtils;
Expand Down Expand Up @@ -34,11 +34,11 @@ protected void readMessagePrivate(Update update) {
try {
SmartJson rm = new SmartJson(chatId).
addValue(FILE_PATH, KoTorrentBot.BOT.execute(uploadedFile).getFilePath()).
addValue("FILE_ID", update.getMessage().getDocument().getFileId()).
addValue(FILE_ID, update.getMessage().getDocument().getFileId()).
addValue(TEXT, message).
addValue("CAPTION", caption).
addValue("SIZE", String.valueOf(fileSize)).
addValue("MIME_TYPE", mimeType);
addValue(CAPTION, caption).
addValue(SIZE, String.valueOf(fileSize)).
addValue(MIME_TYPE, mimeType);

RabbitUtils.postMessage(rm, Constants.Queues.Telegram.TELEGRAM_INPUT_FILE);
} catch (TelegramApiException e) {
Expand Down
71 changes: 0 additions & 71 deletions core/src/main/java/com/halushko/kinocat/core/cli/Command.java

This file was deleted.

37 changes: 0 additions & 37 deletions core/src/main/java/com/halushko/kinocat/core/cli/Script.java

This file was deleted.

29 changes: 29 additions & 0 deletions core/src/main/java/com/halushko/kinocat/core/commands/Command.java
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)));
}
}
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));
}
}
Original file line number Diff line number Diff line change
@@ -1,37 +1,42 @@
package com.halushko.kinocat.core.cli;
package com.halushko.kinocat.core.commands;

import lombok.extern.slf4j.Slf4j;
import lombok.val;

import java.util.*;

@Slf4j
public class ScriptsCollection {
private Map<String, Script> allCommands;
private final List<Script> values = new ArrayList<>();
public class CommandsCollection {
private Map<String, Command> allCommands;
private final List<Command> values = new ArrayList<>();

public void addValue(String command, String script, String queue, String... args) {
values.add(new Script(command, script, queue, args));
@SuppressWarnings("unused")
public void addValue(String command, String queue) {
values.add(new Command(command, queue, new LinkedHashMap<>()));
}
@SuppressWarnings("unused")
public void addValue(String command, String queue, Map<String, String> params) {
values.add(new Command(command, queue, params));
}

@SuppressWarnings("unused")
public Command getCommand(String text) {
log.debug("Try to get command from text [{}]", text);
if (text == null) return new Command("");

Command tmp = new Command(text);
getCommandList().forEach(tmp::tryToSetScript);
log.debug("Command is command=%s, script={}, queue={}", tmp.getFinalCommand(), tmp.getScript(), tmp.getQueue());
return tmp;
log.debug("[getCommand] Try to get command from text [{}]", text);
if (text == null || text.isEmpty()) return new Command();
val result = CommandChecker.getCommand(text, getCommandList());
log.debug("[getCommand] Command is command={}, queue={}", result.getCommand(), result.getQueue());
return result;
}

private Collection<Script> getCommandList() {
private Collection<Command> getCommandList() {
init();
return allCommands.values();
}

private void init() {
if (allCommands == null) {
allCommands = new LinkedHashMap<>();
Map<String, Script> allCommandsTemp = new LinkedHashMap<>();
Map<String, Command> allCommandsTemp = new LinkedHashMap<>();
values.sort(Comparator.comparingInt(s -> s.getCommand().length()));
values.forEach(s -> allCommandsTemp.put(s.getCommand(), s));
allCommandsTemp.forEach((key, value) -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.halushko.kinocat.core.cli;
package com.halushko.kinocat.core.commands;

@SuppressWarnings("unused")
public interface Constants {
Expand All @@ -10,11 +10,17 @@ interface Telegram {
}

interface Torrent {
String EXECUTE_VOID_TORRENT_COMMAND = "EXECUTE_TORRENT_COMMAND_QUEUE";
String EXECUTE_TORRENT_COMMAND_LIST = "EXECUTE_TORRENT_COMMAND_LIST";
String EXECUTE_TORRENT_COMMAND_LIST_FILES = "EXECUTE_TORRENT_COMMAND_LIST_FILES";
String EXECUTE_TORRENT_COMMAND_INFO = "EXECUTE_TORRENT_COMMAND_INFO";
String EXECUTE_TORRENT_COMMAND_COMMANDS = "EXECUTE_TORRENT_COMMAND_FILE_COMMANDS";
String TORRENTS_LIST = "EXECUTE_TORRENT_COMMAND_LIST";
String FILES_LIST = "EXECUTE_TORRENT_COMMAND_LIST_FILES";
String TORRENT_INFO = "EXECUTE_TORRENT_COMMAND_INFO";
String TORRENT_COMMANDS = "EXECUTE_TORRENT_COMMAND_SHOW_COMMANDS";
String RESUME_TORRENT = "EXECUTE_TORRENT_COMMAND_RESUME_TORRENT";
String PAUSE_TORRENT = "EXECUTE_TORRENT_COMMAND_PAUSE_TORRENT";
String RESUME_ALL = "EXECUTE_TORRENT_COMMAND_RESUME_ALL_TORRENTS";
String PAUSE_ALL = "EXECUTE_TORRENT_COMMAND_PAUSE_ALL_TORRENTS";
String DELETE = "EXECUTE_TORRENT_COMMAND_DELETE";
String DELETE_ONLY_TORRENT = "EXECUTE_TORRENT_COMMAND_DELETE_ONLY_TORRENT";
String DELETE_WITH_FILES = "EXECUTE_TORRENT_COMMAND_DELETE_WITH_FILES";

}

Expand All @@ -26,20 +32,22 @@ interface MediaServer {
interface Commands {
interface Torrent {
String LIST_TORRENTS = "/list";
String START_TORRENT_FILE = "/start_torrent";
String LIST_TORRENT_COMMANDS = "/more_";
String RESUME = "/resume_";
String PAUSE = "/pause_";
String RESUME_ALL = "/resume_all";
String PAUSE_ALL = "/pause_all";
String TORRENT_INFO = "/full_info_";
String REMOVE_WITH_FILES = "/approve_with_files_";
String REMOVE_JUST_TORRENT = "/approve_just_torrent_";
String LIST_FILES = "/files_";
String REMOVE_COMMAND = "/remove_";

}

interface Text {
String SEND_TEXT_TO_USER = "#$SEND_TEXT_TO_USER$#";
String SEPARATOR = "#$SEPARATOR$#";
String REMOVE_COMMAND = "/remove_";
String REMOVE_WARN_TEXT_FUNC = "askRemoveTorrent";
}
}
Expand Down
Loading
Loading