所以我使用RiveScript的JavaScript 端口,它使用 ajax,当然我不想再使用 jQuery。只有一行 ajax,我想将其更改为新的 Fetch API。
**FYI: You can see the ajax code in line 1795 of the CDN.**
Run Code Online (Sandbox Code Playgroud)
所以这是原始代码:
return $.ajax({
url: file,
dataType: "text",
success: (function(_this) {
return function(data, textStatus, xhr) {
_this.say("Loading file " + file + " complete.");
_this.parse(file, data, onError);
delete _this._pending[loadCount][file];
if (Object.keys(_this._pending[loadCount]).length === 0) {
if (typeof onSuccess === "function") {
return onSuccess.call(void 0, loadCount);
}
}
};
})(this),
error: (function(_this) {
return function(xhr, textStatus, errorThrown) {
_this.say("Ajax …Run Code Online (Sandbox Code Playgroud) 我的机器人将用户的名称存储在数据库中,并且数据库有时会向会话发送消息"setname username".样本rivescript:
+ setname *
- <set name=<formal>>
+ (what is my name|who am i)
- You're <get name>, right?
+ didntlike
- {topic=nlike}Why?
> topic nlike
+ *
- {topic=random}Thanks for charing.
< topic
+ *
- I don't have a reply for that.
- Try asking that a different way.
Run Code Online (Sandbox Code Playgroud)
问题是,当用户处于*nlike'之类的主题时,我会发送消息来设置名称,然后会话退出主题.
期待的对话:
Me: hello
Bot: I don't have a reply for that.
Me: didntlike
Bot: Why?
Me: setname John
Bot:
Me: I didn't like because you are ugly. …Run Code Online (Sandbox Code Playgroud)