简体   繁体   English

使用Node.js的提醒机器人

[英]Reminder bot with Node.js

I am creating reminder bot. 我正在创建提醒机器人。 User inputs date eg 01.01.19, I'm using new Date() to get milisecs to event, then I call setTimeout() function and wait until it happens. 用户输入日期,例如01.01.19,我使用新的Date()获取事件的毫秒数,然后调用setTimeout()函数并等待它发生。 So the problem is about setTimeout() Is it OK to call it for a long period of time and many times? 所以问题是关于setTimeout()可以长时间调用它吗? If user will call it for eg 10000 times, will it break my bot and so on? 如果用户将其调用例如10000次,它将破坏我的机器人,等等吗? Is it optimal case or you can advice something else 这是最佳案例还是您可以建议别的东西

Well since you have a database, just do the following: 好吧,既然您有一个数据库,只需执行以下操作:

  1. When the user clicks the button, add a new reminder in the database 当用户单击按钮时,在数据库中添加新的提醒
  2. Have an interval timer that constantly iterates through all items in the database and checks if they have passed their time yet 有一个间隔计时器,可以不断地遍历数据库中的所有项目,并检查它们是否已经过去了
  3. Show those ones that need to be reminded. 显示那些需要提醒的内容。

Should be pretty simple to do - just use setInterval , a loop, and a little bit of working with Date in JavaScript. 应该做起来非常简单-只需使用setInterval ,一个循环以及在JavaScript中使用Date的一些方法即可。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM