Skip to content

Commit

Permalink
Fix bad story state (#19)
Browse files Browse the repository at this point in the history
* Added null checl.

* Updated version numbers.

* Force text to have LF for EOL.

* Tweak version number for release.
  • Loading branch information
rabidgremlin authored Jul 15, 2019
1 parent 49a0f03 commit ff223b8
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 144 deletions.
48 changes: 6 additions & 42 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -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
16 changes: 8 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
```

Expand All @@ -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'
}
```

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}

}

0 comments on commit ff223b8

Please sign in to comment.