From ff223b817ef2b7bfd37c8da04047405d5caf3757 Mon Sep 17 00:00:00 2001 From: rabidgremlin Date: Mon, 15 Jul 2019 13:59:00 +1200 Subject: [PATCH] Fix bad story state (#19) * Added null checl. * Updated version numbers. * Force text to have LF for EOL. * Tweak version number for release. --- .gitattributes | 48 +---- README.md | 16 +- gradle.properties | 2 +- .../mutters/bot/ink/SessionUtils.java | 191 +++++++++--------- 4 files changed, 113 insertions(+), 144 deletions(-) diff --git a/.gitattributes b/.gitattributes index 606cb97..30aa107 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,43 +1,7 @@ -# Handle line endings automatically for files detected as text -# and leave all files detected as binary untouched. -* text=auto +* text=auto +* text eol=lf -gradlew text eol=lf - -# -# The above will handle all files NOT found below -# -# These files are text and should be normalized (Convert crlf => lf) -*.bash text eol=lf -*.css text diff=css -*.df text -*.htm text diff=html -*.html text diff=html -*.java text diff=java -*.js text -*.json text -*.jsp text -*.jspf text -*.jspx text -*.properties text -*.sh text eol=lf -*.tld text -*.txt text -*.tag text -*.tagx text -*.xml text -*.yml text - -# These files are binary and should be left untouched -# (binary is a macro for -text -diff) -*.class binary -*.dll binary -*.ear binary -*.gif binary -*.ico binary -*.jar binary -*.jpg binary -*.jpeg binary -*.png binary -*.so binary -*.war binary +*.jar binary +*.png binary +*.gif binary +*.ico binary diff --git a/README.md b/README.md index e2098ff..15f961a 100644 --- a/README.md +++ b/README.md @@ -220,10 +220,10 @@ repositories { } dependencies { - compile 'com.rabidgremlin:mutters-ink-bot:5.0.1' - compile 'com.rabidgremlin:mutters-opennlp-intent:5.0.1' - compile 'com.rabidgremlin:mutters-opennlp-ner:5.0.1' - compile 'com.rabidgremlin:mutters-slots:5.0.1' + compile 'com.rabidgremlin:mutters-ink-bot:5.0.2' + compile 'com.rabidgremlin:mutters-opennlp-intent:5.0.2' + compile 'com.rabidgremlin:mutters-opennlp-ner:5.0.2' + compile 'com.rabidgremlin:mutters-slots:5.0.2' } ``` @@ -241,10 +241,10 @@ repositories { } dependencies { - compile 'com.rabidgremlin:mutters-ink-bot:5.0.1-SNAPSHOT' - compile 'com.rabidgremlin:mutters-opennlp-intent:5.0.1-SNAPSHOT' - compile 'com.rabidgremlin:mutters-opennlp-ner:5.0.1-SNAPSHOT' - compile 'com.rabidgremlin:mutters-slots:5.0.1-SNAPSHOT' + compile 'com.rabidgremlin:mutters-ink-bot:5.0.2-SNAPSHOT' + compile 'com.rabidgremlin:mutters-opennlp-intent:5.0.2-SNAPSHOT' + compile 'com.rabidgremlin:mutters-opennlp-ner:5.0.2-SNAPSHOT' + compile 'com.rabidgremlin:mutters-slots:5.0.2-SNAPSHOT' } ``` diff --git a/gradle.properties b/gradle.properties index 257f6cb..79086bb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ -version=5.0.1 +version=5.0.2 # These are place holder values. Real values should be set in user's home gradle.properties # and are only needed when signing and uploading to central maven repo diff --git a/mutters-ink-bot/src/main/java/com/rabidgremlin/mutters/bot/ink/SessionUtils.java b/mutters-ink-bot/src/main/java/com/rabidgremlin/mutters/bot/ink/SessionUtils.java index 1cd2236..5a0d9ce 100644 --- a/mutters-ink-bot/src/main/java/com/rabidgremlin/mutters/bot/ink/SessionUtils.java +++ b/mutters-ink-bot/src/main/java/com/rabidgremlin/mutters/bot/ink/SessionUtils.java @@ -1,93 +1,98 @@ -package com.rabidgremlin.mutters.bot.ink; - -import com.bladecoder.ink.runtime.StoryState; -import com.rabidgremlin.mutters.core.session.Session; - -/** - * Utility class for InkBot's interactions with a Session. - * - * @author rabidgremlin - * - */ -public class SessionUtils - extends com.rabidgremlin.mutters.core.util.SessionUtils -{ - - protected SessionUtils() - { - // utility class - } - - /** - * Stores the failed to understand count for the bot. - * - * @param session The session. - * @param count The count. - */ - public static void setFailedToUnderstandCount(Session session, int count) - { - session.setAttribute(SLOT_PREFIX + "0987654321FAILEDCOUNT1234567890", new Integer(count)); - } - - /** - * Gets the failed to understand count for the bot. - * - * @param session The session. - * @return The count. - */ - public static int getFailedToUnderstandCount(Session session) - { - Integer failedToUnderstandCount = (Integer) session.getAttribute(SLOT_PREFIX + "0987654321FAILEDCOUNT1234567890"); - - if (failedToUnderstandCount == null) - { - return 0; - } - else - { - return failedToUnderstandCount; - } - } - - /** - * Stores the current Ink story state for the user into the session. - * - * @param session The session. - * @param storyState The story state. - */ - public static void saveInkStoryState(Session session, StoryState storyState) - { - try - { - session.setAttribute(SLOT_PREFIX + "0987654321STORYSTATE1234567890", storyState.toJson()); - } - catch (Exception e) - { - throw new RuntimeException("Unexpected error. Failed to save story state", e); - } - } - - /** - * Gets the user's current Ink story state from the session. - * - * @param session The session. - * @param storyState The story state. - */ - public static void loadInkStoryState(Session session, StoryState storyState) - { - try - { - String stateJson = (String) session - .getAttribute(SLOT_PREFIX + "0987654321STORYSTATE1234567890"); - if (stateJson != null) - { - storyState.loadJson(stateJson); - } - } - catch (Exception e) - { - throw new BadInkStoryState("Unexpected error. Failed to load story state", e); - } - } - -} +package com.rabidgremlin.mutters.bot.ink; + +import com.bladecoder.ink.runtime.StoryState; +import com.rabidgremlin.mutters.core.session.Session; + +/** + * Utility class for InkBot's interactions with a Session. + * + * @author rabidgremlin + * + */ +public class SessionUtils + extends com.rabidgremlin.mutters.core.util.SessionUtils +{ + + protected SessionUtils() + { + // utility class + } + + /** + * Stores the failed to understand count for the bot. + * + * @param session The session. + * @param count The count. + */ + public static void setFailedToUnderstandCount(Session session, int count) + { + session.setAttribute(SLOT_PREFIX + "0987654321FAILEDCOUNT1234567890", new Integer(count)); + } + + /** + * Gets the failed to understand count for the bot. + * + * @param session The session. + * @return The count. + */ + public static int getFailedToUnderstandCount(Session session) + { + Integer failedToUnderstandCount = (Integer) session.getAttribute(SLOT_PREFIX + "0987654321FAILEDCOUNT1234567890"); + + if (failedToUnderstandCount == null) + { + return 0; + } + else + { + return failedToUnderstandCount; + } + } + + /** + * Stores the current Ink story state for the user into the session. + * + * @param session The session. + * @param storyState The story state. + */ + public static void saveInkStoryState(Session session, StoryState storyState) + { + if (storyState == null) + { + throw new BadInkStoryState("storyState should not be null"); + } + + try + { + session.setAttribute(SLOT_PREFIX + "0987654321STORYSTATE1234567890", storyState.toJson()); + } + catch (Exception e) + { + throw new RuntimeException("Unexpected error. Failed to save story state", e); + } + } + + /** + * Gets the user's current Ink story state from the session. + * + * @param session The session. + * @param storyState The story state. + */ + public static void loadInkStoryState(Session session, StoryState storyState) + { + try + { + String stateJson = (String) session + .getAttribute(SLOT_PREFIX + "0987654321STORYSTATE1234567890"); + if (stateJson != null) + { + storyState.loadJson(stateJson); + } + } + catch (Exception e) + { + throw new BadInkStoryState("Unexpected error. Failed to load story state", e); + } + } + +}