[SVN] initial commit after SVN rebirth;

[SVN] bump to version 2.0
[UPD] now transport working with telethon 0.15.5 and sleekxmpp 1.3.2
[FIX] fixed everlasting authorization requests. if you got deauth message — ignore it, FROM subscription is enough.
[ADD] implemented roster exchange via XEP-0144
[ADD] we will send authorization request when unknown contact sent us a message
[ADD] correct presence handling for transport and users
[ADD] fixed presence spam (by default, we updating presence once for 60 seconds -- look at `status_update_interval` in mtproto.py)
[ADD] we will automatically connect to all actual sessions after transport start
This commit is contained in:
annelin
2018-06-19 05:09:38 +00:00
commit bca6860159
11 changed files with 1320 additions and 0 deletions

73
start.py Normal file
View File

@@ -0,0 +1,73 @@
import xmpp_tg
import logging
import logging.handlers
import os
import sys
import signal
from config import CONFIG
import telethon
import sleekxmpp
xmpp_logger = logging.getLogger('sleekxmpp')
class StreamToLogger:
"""
Прикидывается файловым объектом. Нужен для перехвата стандартных потоков ввода-вывода.
"""
def __init__(self, logger, level=logging.INFO, old_out=None):
self.logger = logger
self.level = level
self.old_out = old_out
self.linebuf = []
self._buffer = ''
self._prev = None
def write(self, buf):
if self._prev == buf == '\n': # Надо на буфер переделывать
self._prev = buf
buf = ''
else:
self._prev = buf
if buf != '\n':
self.logger.log(self.level, buf)
if self.old_out:
self.old_out.write(buf)
def flush(self):
pass
# Настраиваем логгирование
logging.basicConfig(
level=logging.DEBUG if CONFIG['debug'] else logging.INFO,
format='%(asctime)s :: %(levelname)s:%(name)s :: %(message)s',
datefmt='%m/%d/%Y %I:%M:%S %p',
handlers=[logging.handlers.RotatingFileHandler(filename='gate.log'), logging.StreamHandler(sys.stdout)]
)
# Создаем логгеры и перехватчики для STDOUT/STDERR
logger_stdout = logging.getLogger('__stdout')
sys.stdout = StreamToLogger(logger_stdout, logging.INFO)
logger_stderr = logging.getLogger('__stderr')
sys.stderr = StreamToLogger(logger_stderr, logging.ERROR)
logging.getLogger().log(logging.INFO, '~'*81)
logging.getLogger().log(logging.INFO, ' RESTART '*9)
logging.getLogger().log(logging.INFO, '~'*81)
print('----------------------------------------------------------------------')
print('--- Telegram (MTProto) <---> XMPP Gateway ---')
print('----------------------------------------------------------------------')
print()
print('Starting...')
print('Gate build: rev{}'.format(xmpp_tg.__version__))
print('Process pid: {}'.format(os.getpid()))
print('Using Telethon v{} and SleekXMPP v{}'.format(telethon.TelegramClient.__version__, sleekxmpp.__version__))
print()
gate = xmpp_tg.XMPPTelegram(CONFIG)
signal.signal(signal.SIGINT, gate.handle_interrupt)
gate.connect()
gate.process()