简体   繁体   English

我应该使用什么模式在Node / JavaScript中制作一个监听机器人?

[英]What pattern should I use for making a listen bot in Node/JavaScript?

I'm currently using Node to make my first bot, but I'm a little bit confused as to how I can make this into reality. 我目前正在使用Node制作我的第一台机器人,但我对如何将其变为现实感到有些困惑。 The question is, what is the best pattern and name of the pattern I should use for this kind of stuff? 问题是, 我应该为这种东西使用的模式的最佳模式和名称是什么?

Basically, a person can listen to a subject and the speaker. 基本上,一个人可以听主题和发言者。

var test = person("ask_name","hallo person you are special");
console.log(test); // should return thanks!

var test = person("ask_name","hallo person you are dumb as the bird");
console.log(test); // should return i hate you!

function person(ability, body) {

  console.log(ability,body);
  var ability_name = "ability_" + ability;
  console.log(ability_name,typeof ability_name); // ignore all of this, trying something
  if (typeof ability_name) {};

  // ability list array
  var ability = [];

  // Search for ability
  // not done

  var say_bad = function() {
    this.listen_subject = 'ask_name';
    this.listen_body = 'you are dumb';
    return "i hate you!"
  }

  var say_good = function() {
    this.listen_subject = 'ask_name';
    this.listen_body = 'you are special';

    return "thanks!"
  }
}

Sorry, for not completing the code but this is the furthest I can go. 对不起,因为没有完成代码,但这是我能走得最远的。

If you're talking about the conversation logic, chain of responsibility seems like the way to go. 如果你在谈论对话逻辑,责任链似乎是要走的路。 That being said, that's only suitable for implementing a response tree. 话虽这么说,这只适用于实现响应树。 You may have different needs. 您可能有不同的需求。

The way that could work is: All nodes in the logic tree would have this method; 可行的方法是:逻辑树中的所有节点都有这种方法;

bool consider(utterence, history);

This method would return true if the node, or one of its subnodes has handled the situation. 如果节点或其子节点之一已处理该情况,则此方法将返回true。

I would implement a couple of topic detectors and a generic "I can't come up with a good answer", as well as a bunch of specialized responders. 我会实现一些主题检测器和一个通用的“我无法想出一个好的答案”,以及一堆专业的响应者。

The logic would be something like: 逻辑将类似于:

(weatherDetector considers utterence, history) (determines that topic is weather) (passes on to chain of objects that handle weather conversations) (weatherDetector考虑历史,历史)(确定主题是天气)(传递给处理天气对话的对象链)

or 要么

(weatherDetector considers utterence, history) (determines that topic is NOT weather) (passes on to next in chain of topic detectors) (genericFunnyResponder considers utterence, history) (picks a random quirky answer) (weatherDetector考虑历史,历史)(确定主题不是天气)(传递到主题探测器链中的下一个)(genericFunnyResponder考虑话语,历史)(选择一个随机的古怪答案)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我应该为这些任务使用什么模式? - What pattern should I use for such tasks? 我应该使用什么工作流程进行JavaScript编辑? - What workflow should I use for JavaScript editing? 我应该在这个练习中使用 JavaScript 中的哪个函数? - What function in JavaScript should I use for this exercise? 我应该使用什么正则表达式来验证数字模式? - What regex should i use to validate a number pattern? Javascript粒子:我应该使用工厂模式还是对象/原型模式? - Javascript particles: should I use a factory or an object/prototype pattern? 我应该使用什么生命周期方法来监听 state 的变化并在反应 class 组件中相应地更新其他 state - What lifecycle method should i use to listen for changes in state and update other state accordingly in react class component 我应该使用什么编码来在 node.js 中“gzuncompress()”? - What's the encoding should I use to “gzuncompress()” in node.js? 我应该为这样的javascript按钮使用什么标签? - What tag should i use for a javascript button like this? 我应该使用全局变量吗?如果不是,那又是什么? (JavaScript)的 - Should I use a global variable and if not, what instead? (Javascript) 我应该使用什么方法来计算 JavaScript 中子类的实例? - What method should I use to count instances of subclasses in JavaScript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM