From 67941b4cc8dfa18de3e2f00517e9079cbde622d3 Mon Sep 17 00:00:00 2001 From: Braiden Vasco Date: Mon, 14 Sep 2015 08:10:18 +0000 Subject: [PATCH] Implement groupchats in the adapter for Lita --- lib/lita/adapters/tox.rb | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/lita/adapters/tox.rb b/lib/lita/adapters/tox.rb index 1b3f998..deffaeb 100644 --- a/lib/lita/adapters/tox.rb +++ b/lib/lita/adapters/tox.rb @@ -41,6 +41,20 @@ module Lita message.command! robot.receive(message) end + + @tox.on_group_invite do |friend_number, data| + @tox.join_groupchat(friend_number, data) + end + + @tox.on_group_message do |group_number, peer_number, text| + unless @tox.group_peernumber_is_ours(group_number, peer_number) + user = User.new(-1 - peer_number) # TODO + source = Source.new(user: user, room: group_number) + message = Message.new(robot, text, source) + + robot.receive(message) + end + end end def run @@ -59,7 +73,11 @@ module Lita def send_messages(target, messages) messages.reject(&:empty?).each do |message| - @tox.friend_send_message(target.user.id.to_i, message) + if target.user.id.to_i >= 0 + @tox.friend_send_message(target.user.id.to_i, message) + else + @tox.group_message_send(target.room.to_i, message) + end end end end