javascript - 机器人不能在 IRC 上工作,用 Node.js 编写
问题描述
我一直在尝试为 IRC 服务器创建一个机器人。IRC 服务器是:“open.ircnet.net”,频道是“#Mal1t1a”。该机器人的代码是用 Node.js 编写的。我在 youtube 上观看了有关如何编写机器人代码的教程,我观看的视频可以在此链接中找到:https ://www.youtube.com/watch?v=OuYIlea4j7g&t=333s 。制作该视频的人制作了一个用于抽搐的机器人,因此需要一个 oauth。由于我已连接到不需要任何密码登录的 IRC 服务器,因此我注释了这些行,其中包含有关密码的代码。我与我的一个朋友在服务器上连接,在我提到的频道上,我们能够交谈,所以服务器正在工作。在这里,您有机器人的代码:
var irc = require("irc");
var config = {
channels: ["#Mal1t1a"],
server: "open.ircnet.net",
botName: "tren",
//oauth: "oauth:YOURUNIQUEOAUTHTOKEN",
autoRejoin: false,
autoConnect: true,
floodProtection: true,
floodProtectionDelay: 3000
};
var bot = new irc.Client(config.server, config.botName, {
channels: config.channels,
//password: config.oauth
});
function OnMessage(from, channel, text, message)
{
console.log(from, channel, text);
if (text == "!greeting")
{
bot.send("PRIVMSG", channel, "Hello " + from + "! You have triggered my command!");
}
}
bot.addListener("message", OnMessage);
bot.addListener("action", OnMessage);
function OnJoin(channel, nick, msgobj)
{
if (nick.toLowerCase() == config.botName.toLowerCase())
{
console.log("Bot has joined channel", channel);
}
}
bot.addListener("join", OnJoin);
function OnError(message)
{
console.log("IRC Error:", message);
}
bot.addListener("error", OnError);
我在聊天中写了无数次“!问候”,但机器人没有回答。它可以做什么?
解决方案
推荐阅读
- python - 如何修复“_io.TextIOWrapper”对象没有属性“readline”
- python - 如何在Django中获取所有与记录相关的父母和孩子?
- qt - 带有标头的 QNetworkRequest
- sql - 如何正确插入 M..N 表?
- angular - 角度 6 中的 Jwt 令牌过期
- excel - 新工作簿中的现有行下未添加新行
- aws-sdk - 使用 amazon textract 服务的端点详细信息
- android - 使用 AsyncTask 加载 XML 时出错
- oracle - 在 pandas read_sql_query() 中加入表 - 多索引问题
- python - 如何从父目录导入变量?