Skip to content

Commit

Permalink
Prepare v1.16.0 for release
Browse files Browse the repository at this point in the history
  • Loading branch information
kirsle committed Sep 6, 2016
1 parent 8e3d97b commit a2cc32e
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 53 deletions.
8 changes: 8 additions & 0 deletions Changes.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# Changes

* 1.16.0 2016-09-06
- Add TypeScript declaration files (PR #162).
- Add a `--watch` option to `shell.js` to automatically reload the bot's
brain when the source files change (PR #160).
- Fix the `json-server` example not giving errors correctly (passing invalid
data into the RiveScript library and potentially raising an exception
from within there; bug #165).

* 1.15.0 2016-08-07
- Add a new contructor option, `forceCase`, which will force-lowercase your
triggers during parse time, enabling authors to use uppercase letters in
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,8 @@ of JavaScript code. See `/help` for more.
Both shell scripts accept command line parameters:

* `--debug`: enables verbose debug logging.
* `--watch`: watch the reply folder for changes and automatically reload the
bot when files are modified.
* `--utf8`: enables UTF-8 mode.

When using RiveScript.js as a library, the synopsis is as follows:
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "rivescript",
"version": "1.15.0",
"version": "1.16.0",
"description": "RiveScript is a scripting language for chatterbots, making it easy to write trigger/response pairs for building up a bot's intelligence.",
"keywords": [
"bot",
Expand Down
121 changes: 70 additions & 51 deletions shell.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
################################################################################

readline = require "readline"
fs = require "fs"
RiveScript = require "./src/rivescript"
CoffeeObjectHandler = require "./lib/lang/coffee"

Expand All @@ -18,16 +19,16 @@ CoffeeObjectHandler = require "./lib/lang/coffee"
opts =
debug: false
utf8: false
watch: false
brain: undefined

process.argv.forEach((val, index, array) ->
if index < 2
return

process.argv.slice(2).forEach((val, index, array) ->
if val is "--debug"
opts.debug = true
else if val is "--utf8"
opts.utf8 = true
else if val is "--watch"
opts.watch = true
else if val.indexOf("-") is 0
console.error "Unknown option: #{val}"
else if opts.brain is undefined
Expand All @@ -37,63 +38,81 @@ process.argv.forEach((val, index, array) ->
)

if opts.brain is undefined
console.log "Usage: coffee shell.coffee [--debug --utf8] </path/to/brain>"
console.log "Usage: coffee shell.coffee [--debug --utf8 --watch] </path/to/brain>"
process.exit 1

################################################################################
# Initialize the RiveScript bot and print the welcome banner.
################################################################################

bot = new RiveScript({
debug: opts.debug
utf8: opts.utf8
})
bot.setHandler("coffee", new CoffeeObjectHandler())
bot.loadDirectory opts.brain, (batch_num) ->
bot.sortReplies()

console.log """
. .
.:...:: RiveScript Interpreter (CoffeeScript)
.:: ::. Library Version: v#{bot.version()}
..:;;. ' .;;:..
. ''' . Type '/quit' to quit.
:;,:,;: Type '/help' for more options.
: :
Using the RiveScript bot found in: #{opts.brain}
Type a message to the bot and press Return to send it.
"""

##############################################################################
# Drop into the interactive command shell.
##############################################################################
rl = readline.createInterface
input: process.stdin
output: process.stdout

rl = readline.createInterface
input: process.stdin
output: process.stdout

rl.setPrompt "You> "
rl.prompt()
rl.on "line", (cmd) ->
if cmd is "/help"
help()
else if cmd.indexOf("/eval ") is 0
eval(cmd.replace("/eval ", ""))
else if cmd.indexOf("/log ") is 0
console.log(eval(cmd.replace("/log ", "")))
else if cmd is "/quit"
process.exit 0
else
reply = bot.reply "localuser", cmd
console.log "Bot> #{reply}"
bot = null

loadingDone = (batchNumber) ->
bot.sortReplies()
bot.ready = true

loadingError = (error, batchNumber) ->
console.error "Loading error: #{error}"

loadBot = ->
bot = new RiveScript({
debug: opts.debug
utf8: opts.utf8
})
bot.ready = false
bot.setHandler("coffee", new CoffeeObjectHandler())
bot.loadDirectory(opts.brain, loadingDone, loadingError)

loadBot()

if opts.watch?
fs.watch opts.brain, {recursive: false}, ->
console.log ""
console.log "[INFO] Brain changed, reloading bot."
rl.prompt()
.on "close", () ->
loadBot()

##############################################################################
# Drop into the interactive command shell.
##############################################################################

console.log """
. .
.:...:: RiveScript Interpreter (CoffeeScript)
.:: ::. Library Version: v#{bot.version()}
..:;;. ' .;;:..
. ''' . Type '/quit' to quit.
:;,:,;: Type '/help' for more options.
: :
Using the RiveScript bot found in: #{opts.brain}
Type a message to the bot and press Return to send it.
"""

rl.setPrompt "You> "
rl.prompt()
rl.on "line", (cmd) ->
if cmd is "/help"
help()
else if cmd.indexOf("/eval ") is 0
eval(cmd.replace("/eval ", ""))
else if cmd.indexOf("/log ") is 0
console.log(eval(cmd.replace("/log ", "")))
else if cmd is "/quit"
process.exit 0
, (err, loadBatch) ->
console.error "Loading error: #{err}"
else
reply = if (bot and bot.ready) then bot.reply("localuser", cmd) else "ERR: Bot not ready yet"
console.log "Bot> #{reply}"

rl.prompt()
.on "close", () ->
console.log ""
process.exit 0

help = () ->
console.log """Supported commands:
Expand Down
2 changes: 1 addition & 1 deletion src/rivescript.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"use strict"

# Constants
VERSION = "1.15.0"
VERSION = "1.16.0"

# Helper modules
Parser = require "./parser"
Expand Down

0 comments on commit a2cc32e

Please sign in to comment.