From 0032a8389420394e1f4e11a3e4a97547befed487 Mon Sep 17 00:00:00 2001 From: annelin Date: Sat, 13 Apr 2019 18:39:20 +0300 Subject: [PATCH] Release 0.4.1 [FIX] fixed joining groups/adding contacts [FIX] fixed kick/ban/unban commands [FIX] fixed status of supergroups --- inc/telegramclient.rb | 15 +++++++-------- inc/xmppcomponent.rb | 6 ++++-- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/inc/telegramclient.rb b/inc/telegramclient.rb index 7d42c4f..46513af 100644 --- a/inc/telegramclient.rb +++ b/inc/telegramclient.rb @@ -232,18 +232,17 @@ class TelegramClient case splitted[0] when '/add' # open new private chat by its id chat = (resolved) ? resolved.id : splitted[1].to_i - @client.create_private_chat(chat).wait - self.process_chat_info(chat) + self.process_chat_info(chat) if chat != 0 when '/join' # join group/supergroup by invite link or by id - chat = splitted[1] - chat.start_with? "http" ? @client.join_chat_by_invite_link(chat).wait : @client.join_chat(chat.to_i).wait + chat = (resolved) ? resolved.id : splitted[1] + chat.to_s[0..3] == "http" ? @client.join_chat_by_invite_link(chat).wait : @client.join_chat(chat.to_i).wait when '/invite' # invite user to chat - @client.add_chat_member(chat_id, response.id).wait if resolved + @client.add_chat_member(chat_id, resolved.id).wait if resolved when '/kick' # removes user from chat - @client.set_chat_member_status(chat_id, response.id, TD::Types::ChatMemberStatus::Left.new()).wait if resolved + @client.set_chat_member_status(chat_id, resolved.id, TD::Types::ChatMemberStatus::Left.new()).wait if resolved when '/ban' # removes user from chat. argument = hours to ban. until_date = (splitted[1]) ? Time.now.getutc.to_i + splitted[1].to_i * 3600 : 0 - @client.set_chat_member_status(chat_id, response.id, TD::Types::ChatMemberStatus::Banned.new(banned_until_date: until_date)).wait if resolved + @client.set_chat_member_status(chat_id, resolved.id, TD::Types::ChatMemberStatus::Banned.new(banned_until_date: until_date)).wait if resolved when '/block' # add user to blacklist @client.block_user(chat_id) when '/unblock' # add user to blacklist @@ -324,7 +323,7 @@ class TelegramClient @cache[:chats][chat_id] = chat # cache chat @client.download_file(chat.photo.small.id) if chat.photo # download userpic @xmpp.presence(chat_id.to_s, :subscribe, nil, nil, @cache[:chats][chat_id].title.to_s) # send subscription request - @xmpp.presence(chat_id.to_s, nil, :chat, nil, @cache[:chats][chat_id].title.to_s) if chat.type.instance_of? TD::Types::ChatType::BasicGroup orchat.type.instance_of? TD::Types::ChatType::Supergroup # send :chat status if its group/supergroup + @xmpp.presence(chat_id.to_s, nil, :chat, nil, @cache[:chats][chat_id].title.to_s) if chat.type.instance_of? TD::Types::ChatType::BasicGroup or chat.type.instance_of? TD::Types::ChatType::Supergroup # send :chat status if its group/supergroup self.process_user_info(chat.type.user_id) if chat.type.instance_of? TD::Types::ChatType::Private # process user if its a private chat }.wait end diff --git a/inc/xmppcomponent.rb b/inc/xmppcomponent.rb index c5776ce..838ab9d 100644 --- a/inc/xmppcomponent.rb +++ b/inc/xmppcomponent.rb @@ -1,5 +1,6 @@ require 'sqlite3' require 'xmpp4r' +require 'digest' ############################# ### Some constants ######### @@ -102,14 +103,15 @@ class XMPPComponent def iq_handler(iq) @logger.debug "New iq received" @logger.debug(iq.to_s) - reply = iq.answer if iq.vcard and @sessions.key? iq.from.bare.to_s then vcard = @sessions[iq.from.bare.to_s].make_vcard(iq.to.to_s) + reply = iq.answer reply.type = :result reply.elements["vCard"] = vcard - @@transport.send(reply) + @@transport.send(reply) else + reply = iq.answer reply.type = :error end @@transport.send(reply)