Closed protektwar closed 3 years ago
Hi @protektwar, sounds interesting. I didn't mention that messages get duplicated after stop/start or restart though I didn't do it intentionally.
I think it is all about offset
option in Client
. It is getting updated before yielding message to a block specified.
I guess you can try to pass initial offset
on Client
initialization. You could store offset
somehow while handling /quit
command before exiting application.
def saveLastMsgID(id)
File.open(@lastMsgID_filename, "wb") { |file|
file.write(id)
}
end
def loadLastMsgID
File.open(@lastMsgID_filename){ |file|
@lastMsgID = file.gets
}
end
and inside bot.listen
block
bot.listen do |message|
if ( bot.options[:offset].to_s == @lastMsgID.to_s )
break
end
end
It is not what I meant but it is up to you. If the problem is solved please close the issue.
How can I stop this bot and flush/acknowledge the last message received, without having it repeated next time when I start the bot? For instance it receive a "/quit" command and it run an
exit(true)
in my code. Next time when I start my bot it will stop right away as the last message/command is repeating...