1

我刚开始使用这个 cinch gem 并使用这个框架来开发一个机器人。

面临一个问题。当有人加入频道时,我想通过机器人向频道发送消息

有人可以帮我解决这个问题。

代码 :

listen_to :join, method: :on_join
    def on_join(m)
      post_message(options(m,
          opcode: 'join',
          nick:   m.user.nick,
          line:   "#{m.user.nick} use this link to get more info"))

你能检查一下,让我知道这有什么遗漏吗?

4

1 回答 1

1

我不确定您的 post_message 命令是什么,但如果它是您在 Cinch 中找到的,请不要使用它。相反,使用内置命令来响应消息

 def on_join(m)
   # Don't greet the bot.
   unless m.user == @bot
   # Reply to the user who joined, the true prepends the line with the user's name
   m.reply "Use this link to get more info - http://whatever", true
 end

接着:

 15:30 -!- Irssi: #bottest: Total of 2 nicks [0 ops, 0 halfops, 0 voices, 2 normal]
 15:30 -!- Channel #bottest created Mon Feb 24 15:30:17 2014
 15:30 < bot> user: Use this link to get more info - http://whatever
于 2014-02-24T23:29:01.757 回答