0

I wrote this auto-reply bot with ruby, it is supposed to autoreply with cleverbot messages when im away:

require "cleverbot"
require "cinch"

    $client = Cleverbot::Client.new


def get_answer(text)
    reply = $client.write text
    return reply
end

bot = Cinch::Bot.new do
  configure do |c|
        c.nick = "mybotsnickname"
        c.server = "my.irc.testserver"
        c.channels = ["#mychannel"]
    end

  on :message do |m|
    m.reply m.user
    m.reply get_answer(m.message)
  end
end

bot.start

It works fine but the session id changes every message. What do i have to change to keep it? best case scenario is every user writing me gets a different session id at cleverbot so they have individual conversations.

I'm pretty new to ruby.

I used: https://github.com/benmanns/cleverbot and https://github.com/cinchrb/cinch

pinpox
  • 179
  • 2
  • 10

1 Answers1

0

Comparing this to the structure of my cinch bot, I'd try the following:

1) Make get_answer a helper block and place it inside the bot = Cinch::Bot.new block:

helpers do
  def get_answer(text)
      reply = $client.write text
      return reply
  end
end

2) Replace

on :message do |m|

with

on :message do |m, text|

3) Replace

m.reply get_answer(m.message)

with

m.reply get_answer(text)

I suspect this should work. But I'm a relatively new to Ruby as well.