Archived
1
0
Fork 0

Merge pull request #12 from braiden-vasco/basic_implementation

Basic implementation
This commit is contained in:
Braiden Vasco 2015-09-13 19:43:57 +00:00
commit 4053ab9a8d

View file

@ -1,3 +1,5 @@
require 'tox'
##
# Lita module.
#
@ -10,6 +12,34 @@ module Lita
# Tox adapter for the Lita chat bot.
#
class Tox < Adapter
def initialize(robot)
@tox = ::Tox.new
log.info("ID: #{@tox.id}")
@tox.on_friend_request do |key|
@tox.friend_add_norequest(key)
end
@tox.on_friend_message do |friend_number, text|
user = User.new(friend_number)
source = Source.new(user: user)
message = Message.new(robot, text, source)
message.command!
robot.receive(message)
end
end
def run
@tox.loop
end
def send_messages(target, messages)
messages.reject(&:empty?).each do |message|
@tox.friend_send_message(target.user.id.to_i, message)
end
end
end
Lita.register_adapter(:tox, Tox)