diff --git a/src/main/groovy/eu/m724/chatapi/example/ExampleSource.groovy b/src/main/groovy/eu/m724/chatapi/example/ExampleSource.groovy index 680357e..33c2ccf 100644 --- a/src/main/groovy/eu/m724/chatapi/example/ExampleSource.groovy +++ b/src/main/groovy/eu/m724/chatapi/example/ExampleSource.groovy @@ -75,9 +75,12 @@ class ExampleSource implements ChatSource { } String rollResponse(Chat chat) { + def special = -1 def prompt = chat.messages.getLast().text() int messagesCount = (int) Math.ceil(chat.messages.size() / 2) def counter = lastCounter + def response = "" + if (prompt.toLowerCase().startsWith("my name is")) { options.setValue("name", prompt.substring(11)) @@ -87,12 +90,28 @@ class ExampleSource implements ChatSource { counter = 11 } - while (counter == lastCounter) { - counter = random.nextInt(13) + def parseable = prompt.toLowerCase().strip().replaceAll("[^a-zA-Z0-9\\s]", ""); + switch (parseable) { + case "who am i": + case "whats my name": + special = 0 + break } - lastCounter = counter - def response = "" + if (special != -1) { + counter = -1 + switch (special) { + case 0: + response = "Your name is " + options.getStringValue("name") + ". How can I help you, " + options.getStringValue("name") + "?" + break + } + // TODO make it unique and better + } else { + while (counter == lastCounter) { + counter = random.nextInt(13) + } + lastCounter = counter + } def words = prompt.split(" ") def randomWord = words[random.nextInt(words.length)] @@ -144,8 +163,8 @@ class ExampleSource implements ChatSource { i2 = random.nextInt(messagesCount) } response = "I'm still angry after you said \"%s\" to me. You could have apologized, but you chose to say \"%s\", so I can't assist you.".formatted(chat.messages.get(i * 2).text(), chat.messages.get(i2 * 2).text()) - break } + break case 13: response = "And?" break