Release 0.7

[FIX] now trying to revive stream if any exception occured
[FIX] fixed >quotes without messages ID
[UPD] using unicode symbols to compact msg prefix
[UPD] logging slightly modified
[UPD] added garbage collection after each incoming message
This commit is contained in:
annelin 2019-04-16 06:45:56 +03:00
parent 56db8c356e
commit 2987d8f3a5
3 changed files with 17 additions and 6 deletions

View file

@ -4,7 +4,7 @@ telegram:
api_hash: '344583e45741c457fe1862106095a5eb' api_hash: '344583e45741c457fe1862106095a5eb'
verbosity: 2 verbosity: 2
useragent: 'Zhabogram XMPP Gateway' useragent: 'Zhabogram XMPP Gateway'
version: '0.4' version: '0.7'
use_test_dc: false use_test_dc: false
loglevel: 0 loglevel: 0
content_path: '/var/www/tg_media' content_path: '/var/www/tg_media'

View file

@ -95,6 +95,8 @@ class TelegramClient
@logger.debug 'Got NewMessage update' @logger.debug 'Got NewMessage update'
@logger.debug update.message.to_json @logger.debug update.message.to_json
@logger.info 'New message from Telegram chat %s' % update.message.chat_id
return if update.message.is_outgoing and update.message.sending_state.instance_of? TD::Types::MessageSendingState::Pending # ignore self outgoing messages return if update.message.is_outgoing and update.message.sending_state.instance_of? TD::Types::MessageSendingState::Pending # ignore self outgoing messages
# media? # # media? #
@ -158,6 +160,7 @@ class TelegramClient
@cache[:unread_msg][update.message.chat_id] = update.message.id @cache[:unread_msg][update.message.chat_id] = update.message.id
@xmpp.incoming_message(update.message.chat_id.to_s, text) @xmpp.incoming_message(update.message.chat_id.to_s, text)
GC.start
end end
# new chat update -- when tg client discovers new chat # # new chat update -- when tg client discovers new chat #
@ -180,7 +183,7 @@ class TelegramClient
@logger.debug update.to_json @logger.debug update.to_json
# formatting # formatting
text = "| %s edit | %s" % [update.message_id.to_s, update.new_content.text.text.to_s] text = "✎ %s | %s" % [update.message_id.to_s, update.new_content.text.text.to_s]
@xmpp.incoming_message(update.chat_id.to_s, text) @xmpp.incoming_message(update.chat_id.to_s, text)
end end
@ -189,7 +192,7 @@ class TelegramClient
@logger.debug 'Got MessageDeleted update' @logger.debug 'Got MessageDeleted update'
@logger.debug update.to_json @logger.debug update.to_json
return if not update.is_permanent return if not update.is_permanent
text = "| %s del |" % update.message_ids.join(',') text = "✗ %s |" % update.message_ids.join(',')
@xmpp.incoming_message(update.chat_id.to_s, text) @xmpp.incoming_message(update.chat_id.to_s, text)
end end
@ -220,7 +223,7 @@ class TelegramClient
# processing authorization # # processing authorization #
def process_auth(typ, auth_data) def process_auth(typ, auth_data)
@logger.debug 'check_authorization with %s..' % typ @logger.info "Authorizing with :%s.." % typ
@client.check_authentication_code(auth_data) if typ == '/code' @client.check_authentication_code(auth_data) if typ == '/code'
@client.check_authentication_password(auth_data) if typ == '/password' @client.check_authentication_password(auth_data) if typ == '/password'
end end
@ -321,7 +324,7 @@ class TelegramClient
# processing outgoing message from queue # # processing outgoing message from queue #
def process_outgoing_msg(chat_id, text) def process_outgoing_msg(chat_id, text)
@logger.debug 'Sending message to user/chat <%s> within Telegram network..' % chat_id.to_s @logger.info 'Sending message to Telegram chat %s...' % chat_id
# processing /commands # # processing /commands #
return self.process_command(chat_id, text) if text[0] == '/' return self.process_command(chat_id, text) if text[0] == '/'
@ -329,7 +332,8 @@ class TelegramClient
# handling replies # # handling replies #
if text[0] == '>' then if text[0] == '>' then
splitted = text.split("\n") splitted = text.split("\n")
reply_to = splitted[0].scan(/\d/).join('') || 0 reply_to = splitted[0].scan(/\d/).join('').to_i
reply_to = 0 if reply_to < 10000 # o_O
text = splitted.drop(1).join("\n") if reply_to != 0 text = splitted.drop(1).join("\n") if reply_to != 0
else else
reply_to = 0 reply_to = 0

View file

@ -61,6 +61,7 @@ class XMPPComponent
@@transport.add_message_callback do |msg| msg.first_element_text('body') ? self.message_handler(msg) : nil end @@transport.add_message_callback do |msg| msg.first_element_text('body') ? self.message_handler(msg) : nil end
@@transport.add_presence_callback do |presence| self.presence_handler(presence) end @@transport.add_presence_callback do |presence| self.presence_handler(presence) end
@@transport.add_iq_callback do |iq| self.iq_handler(iq) end @@transport.add_iq_callback do |iq| self.iq_handler(iq) end
@@transport.on_exception do |exception, stream, state| self.survive(exception, stream, state) end
@logger.info "Connection established" @logger.info "Connection established"
self.load_db() self.load_db()
@logger.info 'Found %s sessions in database.' % @sessions.count @logger.info 'Found %s sessions in database.' % @sessions.count
@ -81,6 +82,12 @@ class XMPPComponent
end end
end end
def survive(exception, stream, state)
@logger.error "Stream error on :%s (%s)" % [state.to_s, exception.to_s]
@logger.info "Trying to revive session..."
self.connect()
end
############################# #############################
#### Callback handlers ##### #### Callback handlers #####
############################# #############################