Archived
1
0
Fork 0

Save Tox state

This commit is contained in:
Braiden Vasco 2015-09-13 23:21:16 +00:00
parent ddd903a96f
commit 2f08914397

View file

@ -12,10 +12,20 @@ module Lita
# Tox adapter for the Lita chat bot.
#
class Tox < Adapter
config :savedata_filename, type: String
def initialize(robot)
super
@tox = ::Tox.new
options = ::Tox::Options.new
if config.savedata_filename && File.exist?(config.savedata_filename)
savedata_file = open(config.savedata_filename)
options.data = savedata_file.read
savedata_file.close
end
@tox = ::Tox.new(options)
log.info("ID: #{@tox.id}")
@ -37,6 +47,16 @@ module Lita
@tox.loop
end
def shut_down
if config.savedata_filename
savedata_file = open(config.savedata_filename, 'w')
savedata_file.write(@tox.savedata)
savedata_file.close
end
@tox.kill
end
def send_messages(target, messages)
messages.reject(&:empty?).each do |message|
@tox.friend_send_message(target.user.id.to_i, message)