aichaos / rivescript-go

A RiveScript interpreter for Go. RiveScript is a scripting language for chatterbots.
https://www.rivescript.com/
MIT License
60 stars 16 forks source link

Strips out . in message #38

Closed rmasci closed 4 years ago

rmasci commented 5 years ago

OK So I have a rive script that looks like this:

Rivescript: + echo domain * - What is \<star1>

Go code (simplified):
var bot *rivescript.RiveScript
chatbot = rivescript.New(rivescript.WithUTF8())
err := chatbot.LoadDirectory("/path/to/rivescript/files")
errhandle(err)
bot.SortReplies()
// chatStr = echo domain www.google.com
reply, err := chatbot.Reply(userID, chatStr)
// reply = "What is wwwgooglecom"

What is happening is that rivescript appears to be stripping off the . in urls. Not sure why...

rmasci commented 5 years ago

The rivescript directive looks like this:

+ echo domain * - What is \<star1>

So I tried this with the rivescript command:

MyServer1:/opt/chatbot/rivescript$ /usr/local/bin/rivescript /opt/chatbot/rivescript

      .   .
     .:...::      RiveScript Interpreter (Go)
    .::   ::.     Library Version: v0.3.0 (build -unknown-)
 ..:;;. ' .;;:..
    .  '''  .     Type '/quit' to quit.
     :;,:,;:      Type '/help' for more options.
     :     :
Using the RiveScript bot found in: /opt/chatbot/rivescript
Type a message to the bot and press Return to send it.
You> echo domain www.google.com
RiveScript> What is wwwgooglecom
You>

It stripped off the '.' from www.google.com just like it did in my code -- is there a way around this?

meowgorithm commented 5 years ago

Periods (and some other characters) are stripped by default. From the the docs:

// Make a new bot with UTF-8 mode enabled.
bot := rivescript.New(rivescript.WithUTF8())

// Override the punctuation characters that get stripped
// from the user's message.
bot.SetUnicodePunctuation(`[.,!?;:]`);

So to allow periods through you’d need to add that final line and edit it as such:

bot.SetUnicodePunctuation(`[,!?;:]`);

But yeah, I'd recommend reading the whole section in the the docs to get a better idea of what's going on: https://godoc.org/github.com/aichaos/rivescript-go#hdr-UTF_8_Support