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:
parent
56db8c356e
commit
2987d8f3a5
|
@ -4,7 +4,7 @@ telegram:
|
|||
api_hash: '344583e45741c457fe1862106095a5eb'
|
||||
verbosity: 2
|
||||
useragent: 'Zhabogram XMPP Gateway'
|
||||
version: '0.4'
|
||||
version: '0.7'
|
||||
use_test_dc: false
|
||||
loglevel: 0
|
||||
content_path: '/var/www/tg_media'
|
||||
|
|
|
@ -95,6 +95,8 @@ class TelegramClient
|
|||
@logger.debug 'Got NewMessage update'
|
||||
@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
|
||||
|
||||
# media? #
|
||||
|
@ -158,6 +160,7 @@ class TelegramClient
|
|||
@cache[:unread_msg][update.message.chat_id] = update.message.id
|
||||
@xmpp.incoming_message(update.message.chat_id.to_s, text)
|
||||
|
||||
GC.start
|
||||
end
|
||||
|
||||
# new chat update -- when tg client discovers new chat #
|
||||
|
@ -180,7 +183,7 @@ class TelegramClient
|
|||
@logger.debug update.to_json
|
||||
|
||||
# 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)
|
||||
end
|
||||
|
||||
|
@ -189,7 +192,7 @@ class TelegramClient
|
|||
@logger.debug 'Got MessageDeleted update'
|
||||
@logger.debug update.to_json
|
||||
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)
|
||||
end
|
||||
|
||||
|
@ -220,7 +223,7 @@ class TelegramClient
|
|||
|
||||
# processing authorization #
|
||||
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_password(auth_data) if typ == '/password'
|
||||
end
|
||||
|
@ -321,7 +324,7 @@ class TelegramClient
|
|||
|
||||
# processing outgoing message from queue #
|
||||
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 #
|
||||
return self.process_command(chat_id, text) if text[0] == '/'
|
||||
|
@ -329,7 +332,8 @@ class TelegramClient
|
|||
# handling replies #
|
||||
if text[0] == '>' then
|
||||
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
|
||||
else
|
||||
reply_to = 0
|
||||
|
|
|
@ -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_presence_callback do |presence| self.presence_handler(presence) 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"
|
||||
self.load_db()
|
||||
@logger.info 'Found %s sessions in database.' % @sessions.count
|
||||
|
@ -81,6 +82,12 @@ class XMPPComponent
|
|||
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 #####
|
||||
#############################
|
||||
|
|
Reference in a new issue