[!] temporary disabled timezone detection to prevent crash after incorrect data in tz requet

[!] trying to fix fetching files without filenames/extensions..
This commit is contained in:
annelin 2019-07-14 10:23:48 +03:00
parent 7a2f85e0fe
commit 193dff330f
2 changed files with 34 additions and 25 deletions

View file

@ -18,8 +18,8 @@ class TelegramClient
config.client.use_test_dc = params['use_test_dc'] || false
config.client.system_version = '42' # I think I have permission to hardcode The Ultimate Question of Life, the Universe, and Everything?..
config.client.use_file_database = true # wow
config.client.use_message_database = true # such library
config.client.use_chat_info_database = true # much options
config.client.use_message_database = false # such library
config.client.use_chat_info_database = false # much options
config.client.enable_storage_optimizer = false # ...
end
TD::Api.set_log_verbosity_level(params['verbosity'] || 1)
@ -124,18 +124,19 @@ class TelegramClient
# file handling
file = case content
when TD::Types::MessageContent::Sticker then [content.sticker.sticker, content.sticker.emoji + '.webp']
when TD::Types::MessageContent::VoiceNote then [content.voice_note.voice, 'voice message (%i seconds).oga' % content.voice_note.duration]
when TD::Types::MessageContent::VideoNote then [content.video_note.video, 'video message (%i seconds).mp4' % content.video_note.duration]
when TD::Types::MessageContent::Animation then [content.animation.animation, content.animation.file_name + '.mp4' ]
when TD::Types::MessageContent::Photo then [content.photo.sizes[-1].photo, content.photo.id + '.jpg']
when TD::Types::MessageContent::Audio then [content.audio.audio, content.audio.file_name]
when TD::Types::MessageContent::Video then [content.video.video, content.video.file_name]
when TD::Types::MessageContent::Document then [content.document.document, content.document.file_name]
when TD::Types::MessageContent::Sticker then [content.sticker.sticker, 'sticker.webp']
when TD::Types::MessageContent::VoiceNote then [content.voice_note.voice, 'voicenote (%i s.).oga' % content.voice_note.duration]
when TD::Types::MessageContent::VideoNote then [content.video_note.video, 'videonote (%i s.).mp4' % content.video_note.duration]
when TD::Types::MessageContent::Animation then [content.animation.animation, 'animation.mp4' ]
when TD::Types::MessageContent::Photo then [content.photo.sizes[-1].photo, 'photo' + content.photo.id + '.jpg']
when TD::Types::MessageContent::Audio then [content.audio.audio, 'audio' + content.audio.file_name]
when TD::Types::MessageContent::Video then [content.video.video, 'video' + content.video.file_name]
when TD::Types::MessageContent::Document then [content.document.document, 'doc' + content.document.file_name]
end
# text handling
text = case content
when TD::Types::MessageContent::Sticker then content.sticker.emoji
when TD::Types::MessageContent::BasicGroupChatCreate, TD::Types::MessageContent::SupergroupChatCreate then "has created chat"
when TD::Types::MessageContent::ChatJoinByLink then "joined chat via invite link"
when TD::Types::MessageContent::ChatAddMembers then "invited %s" % self.format_contact(message.content.member_user_ids.first)
@ -147,6 +148,7 @@ class TelegramClient
when TD::Types::MessageContent::Text then content.text.text
when TD::Types::MessageContent::VoiceNote then content.caption.text
when TD::Types::MessageContent::VideoNote then ''
when TD::Types::MessageContent::Animation then ''
else "unknown message type %s" % update.message.content.class
end

View file

@ -139,18 +139,18 @@ class XMPPComponent
end
# request timezone information #
def request_tz(jid)
@logger.debug "Request timezone from JID %s" % jid.to_s
iq = Jabber::Iq.new
iq.type = :get
iq.to = jid
iq.from = @component.jid
iq.id = 'time_req_1'
iq.add_element("time", {"xmlns" => "urn:xmpp:time"})
@logger.debug iq.to_s
@component.send(iq)
end
#def request_tz(jid)
#@logger.debug "Request timezone from JID %s" % jid.to_s
#iq = Jabber::Iq.new
#iq.type = :get
#iq.to = jid
#iq.from = @component.jid
#iq.id = 'time_req_1'
#iq.add_element("time", {"xmlns" => "urn:xmpp:time"})
#@logger.debug iq.to_s
#@component.send(iq)
#end
#############################
#### Callback handlers #####
#############################
@ -161,7 +161,10 @@ class XMPPComponent
@logger.info 'Received message from <%s> to <%s>' % [msg.from.to_s, msg.to.to_s]
@logger.debug msg.to_s
if msg.to == @component.jid then self.process_command(msg.from, msg.first_element_text('body') ); return; end # treat message as internal command if received as transport jid
if @sessions.key? msg.from.bare.to_s then self.request_tz(msg.from) if not @sessions[msg.from.bare.to_s].tz_set?; @sessions[msg.from.bare.to_s].process_outgoing_msg(msg.to.to_s.split('@')[0].to_i, msg.first_element_text('body')); return; end #if @sessions.key? msg.from.bare.to_s and @sessions[msg.from.bare.to_s].online? # queue message for processing session is active for jid from
if @sessions.key? msg.from.bare.to_s then
# self.request_tz(msg.from) if not @sessions[msg.from.bare.to_s].tz_set?
return @sessions[msg.from.bare.to_s].process_outgoing_msg(msg.to.to_s.split('@')[0].to_i, msg.first_element_text('body'))
end
end
# new presence to XMPP component #
@ -170,7 +173,11 @@ class XMPPComponent
@logger.debug(prsnc.to_s)
if prsnc.type == :subscribe then reply = prsnc.answer(false); reply.type = :subscribed; @component.send(reply); end # send "subscribed" reply to "subscribe" presence
if prsnc.to == @component.jid and @sessions.key? prsnc.from.bare.to_s and prsnc.type == :unavailable then @sessions[prsnc.from.bare.to_s].disconnect(); self.presence(prsnc.from, nil, :subscribe) ; return; end # go offline when received offline presence from jabber user
if prsnc.to == @component.jid and @sessions.key? prsnc.from.bare.to_s then self.request_tz(prsnc.from); @sessions[prsnc.from.bare.to_s].connect() || @sessions[prsnc.from.bare.to_s].sync_status(); return; end # connect if we have session
if prsnc.to == @component.jid and @sessions.key? prsnc.from.bare.to_s then
# self.request_tz(prsnc.from);
@sessions[prsnc.from.bare.to_s].connect() || @sessions[prsnc.from.bare.to_s].sync_status()
return
end
end
# new iq (vcard/tz) request to XMPP component #
@ -220,7 +227,7 @@ class XMPPComponent
when '/login' # create new session
@sessions[from.bare.to_s] = TelegramClient.new(self, from.bare.to_s, body.split[1]) if not (@sessions.key? from.bare.to_s and @sessions[from.bare.to_s].online?)
@sessions[from.bare.to_s].connect()
self.request_tz(from)
# self.request_tz(from)
self.save_db()
when '/code', '/password' # pass auth data to telegram
@sessions[from.bare.to_s].process_auth(body.split[0], body.split[1]) if @sessions.key? from.bare.to_s