diff --git a/src/main/java/marusia/controllers/SkillsController.java b/src/main/java/marusia/controllers/SkillsController.java index da6220c..d52e0c1 100644 --- a/src/main/java/marusia/controllers/SkillsController.java +++ b/src/main/java/marusia/controllers/SkillsController.java @@ -2,6 +2,8 @@ package marusia.controllers; import marusia.entities.MarusiaRequest; import marusia.enums.AudioType; +import marusia.repositories.AudioRepo; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.PostMapping; @@ -9,6 +11,10 @@ import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; + //https://github.com/nonstandardmail/marusia-skill-echo-python/blob/master/handler.py //https://skill-debugger.marusia.mail.ru/ //https://dev.vk.com/marusia/api @@ -16,16 +22,39 @@ import org.springframework.web.bind.annotation.RestController; @RequestMapping("/api/skills") @RestController public class SkillsController { + AudioRepo audioRepo; + + @Autowired + public SkillsController(AudioRepo audioRepo) { + this.audioRepo = audioRepo; + } + @PostMapping public ResponseEntity handler(@RequestBody MarusiaRequest request_json){ System.out.println(request_json); - System.out.println(request_json.get("command")); switch (request_json.getCommand()) { case ("кайф"): return new ResponseEntity<>(request_json.createTextResponse("всем привет"), HttpStatus.OK); case ("за ваше здоровье"): - return new ResponseEntity<>(request_json.createAudioResponse(AudioType.vk, "27919760_456239588"), HttpStatus.OK); + return new ResponseEntity(request_json.createTTSResponse( + audioRepo.getSpeaker("и за мое очко") + ), HttpStatus.OK); + case ("привет"): + return new ResponseEntity(request_json.createTTSResponse( + audioRepo.getSpeaker("всем привет") + ), HttpStatus.OK); + case ("рандомный кайф"): + return new ResponseEntity(request_json.createTTSResponse( + audioRepo.getRandomSpeaker(List.of("кайф 1","кайф 2","КАЙФ")) + ), HttpStatus.OK); default: + String[] phrares = request_json.getCommand().split(" "); + if (phrares[0].equals("фраза")) { + String final_phrare = Arrays.stream(phrares).skip(1).collect(Collectors.joining(" ")); + return new ResponseEntity(request_json.createTTSResponse( + audioRepo.getSpeaker(final_phrare) + ), HttpStatus.OK); + } return new ResponseEntity<>(request_json.createTextResponse("мммммм"), HttpStatus.OK); } } diff --git a/src/main/java/marusia/entities/MarusiaRequest.java b/src/main/java/marusia/entities/MarusiaRequest.java index 14b608d..04e161a 100644 --- a/src/main/java/marusia/entities/MarusiaRequest.java +++ b/src/main/java/marusia/entities/MarusiaRequest.java @@ -22,6 +22,17 @@ public class MarusiaRequest extends BaseRequest { return createTextResponse(text, text); } + public Map createTTSResponse(String tts) { + return Map.of( + "response", Map.of( + "tts", tts, + "end_session", false + ), + "session", getSessionInfo(), + "version", getVersion() + ); + } + public Map createAudioResponse(AudioType audioType, String source) { return Map.of( "session", getSessionInfo(), diff --git a/src/main/java/marusia/repositories/AudioRepo.java b/src/main/java/marusia/repositories/AudioRepo.java new file mode 100644 index 0000000..f0aaac5 --- /dev/null +++ b/src/main/java/marusia/repositories/AudioRepo.java @@ -0,0 +1,50 @@ +package marusia.repositories; + +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + +import java.util.HashMap; +import java.util.List; +import java.util.Random; + +@Service +public class AudioRepo { + private HashMap storage = new HashMap<>(); + + @Autowired + public AudioRepo() { + //plekhanovo voice line + storage.put("и за мое очко", "2000512007_456239246"); + storage.put("блять", "2000512007_456239249"); + storage.put("всем привет", "2000512007_456239250"); + storage.put("за ваше здоровье", "2000512007_456239251"); + storage.put("ии за мое очко", "2000512007_456239252"); + storage.put("сейчас пьем без твоего очка", "2000512007_456239253"); + storage.put("сыграл тост", "2000512007_456239254"); + storage.put("тихаа", "2000512007_456239255"); + storage.put("ты хочешь разъебанное очко", "2000512007_456239256"); + storage.put("чтоб твое очко не болелло", "2000512007_456239257"); + //dacha voice line + storage.put("андеграуд", "2000512007_456239258"); + storage.put("бро", "2000512007_456239259"); + storage.put("детка я твой андерграунд", "2000512007_456239260"); + storage.put("кайф 1", "2000512007_456239261"); + storage.put("кайф 2", "2000512007_456239262"); + storage.put("КАЙФ", "2000512007_456239263"); + storage.put("когда просыпаешься по утра", "2000512007_456239264"); + storage.put("мейби бейби", "2000512007_456239265"); + storage.put("поебать", "2000512007_456239266"); + storage.put("таки да", "2000512007_456239267"); + storage.put("хуета", "2000512007_456239268"); + } + + public String getSpeaker(String phrare) { + return storage.containsKey(phrare) ? "".formatted(storage.get(phrare)) : ""; + } + + public String getRandomSpeaker(List phrares) { + return getSpeaker( + phrares.get(new Random().nextInt(phrares.size())) + ); + } +}