标签: rivescript

如何在 JavaScript 中将 Ajax 转换为 Fetch API?

所以我使用RiveScriptJavaScript 端口,它使用 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)

javascript ajax jquery fetch-api rivescript

6
推荐指数
1
解决办法
8775
查看次数

如何在Rivescript-Python中预处理特殊触发器?

我的机器人将用户的名称存储在数据库中,并且数据库有时会向会话发送消息"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)

rivescript

6
推荐指数
1
解决办法
264
查看次数

标签 统计

rivescript ×2

ajax ×1

fetch-api ×1

javascript ×1

jquery ×1