Archived
1
0
Fork 0
This repository has been archived on 2023-03-27. You can view files and clone it, but cannot push or open issues or pull requests.
lita-tox/lib/lita/adapters/tox.rb

48 lines
918 B
Ruby
Raw Normal View History

2015-09-13 15:40:46 -04:00
require 'tox'
2015-07-25 04:32:00 -04:00
##
# Lita module.
#
module Lita
2015-07-25 04:32:00 -04:00
##
# Lita adapters module.
#
module Adapters
2015-07-25 04:32:00 -04:00
##
# Tox adapter for the Lita chat bot.
#
class Tox < Adapter
2015-09-13 15:40:46 -04:00
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)
end
end