如何根据浏览器内容创建基本的聊天机器人/自动应答器? (Applescript,或其他建议?)
我是一名(非常)初学者程序员,我想知道编写一个非常简单的聊天室机器人是否可行,该机器人很大程度上取决于所使用的聊天室类型。
场景是我的一个朋友设置了一个基本的聊天室(https://blueimp.net/ajax/)仅供几个好友使用,但我想创建一个仅存在于客户端机器(我的)。因此,它会不断检查浏览器(无需重新加载页面)是否有特定字符串,然后在检测到该字符串时做出响应。举个例子,也许他们会输入!机器人歌曲,它会返回歌曲推荐。
我认为 Applescript 可能是做到这一点的简单方法。有人可以帮助我开始吗?就像我说的,我是初学者,所以请记住这一点。尝试将此作为一种学习经历,我通过尝试针对特定场景提出解决方案而不是通过书籍或教程来学习得最好。
本质上,流程类似于:
- 每 2 秒检查一次网页中的字符串(它是基于 Ajax 的,无需刷新...只需检查浏览器窗口本身)
- 如果字符串找到 em>,在第一个文本字段中回复 response + Enter
我知道这不是制作聊天机器人的最有效方法,我只是想用这个场景来帮助我了解应用程序如何在本地相互交互。 :)
I am a (very) beginner programmer and I am wondering if it would be feasible to write a very simple chat room bot which is fairly dependent of what kind of chat room is being used.
The scenario is that a friend of mine has a basic chat room set up (https://blueimp.net/ajax/) just for a few buddies to use, but I want to make a "bot" account that exists only on the client machine (mine). So, it would continually check the browser (without reloading the page) for a particular string and then respond if it detects it. Just as an example, maybe they would type !bot song and it would return with a song recommendation.
I was thinking Applescript could be an easy way to do this. Can anyone possibly help get me started? Like I said, I'm a beginner so please keep that in mind. Trying to use this as a learning experience, and I learn best by trying to come up with a solution to a particular scenario rather than by books or tutorials.
Essentially, the flow would be something like:
- Check webpage for string every 2 seconds (it's Ajax-based, no need to refresh... just check the browser window itself)
- If string is found, reply in the first text field with response + enter
I know this isn't the most efficient way to make a chat bot, I'm just trying to use this scenario to help me understand how applications interact with each other locally. :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我希望我没有通过向您提供此代码来破坏 StackOverflow 的一些不成文规则,但您可以尝试此 AppleScript 代码并查看它是如何工作的(假设整个浏览器窗口只是聊天框,请根据需要更改它)
:由于某种原因这不起作用和/或您有任何疑问,请询问。 :)
I hope I'm not breaking some unwritten rule of StackOverflow by giving you this code, but you could try out this AppleScript code and see how it works (assuming the whole browser window is just the chat box, change this as needed):
If this doesn't work for some reason and/or you have any questions, just ask. :)