Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5d9b94fa5f | |||
| 6ef31599e9 | |||
| e961e0bcc6 | |||
| dc85754b1e | |||
| 04e2c03dae | |||
| 42d54dac5b | |||
| 767a51f994 | |||
| 313b5e5d07 |
+8
-8
@@ -7,12 +7,14 @@ COPY . /opt/mautrixtelegram
|
||||
RUN apk add --no-cache \
|
||||
python3-dev \
|
||||
py3-virtualenv \
|
||||
py3-pillow \
|
||||
py3-aiohttp \
|
||||
py3-lxml \
|
||||
py3-magic \
|
||||
py3-numpy \
|
||||
py3-asn1crypto \
|
||||
py3-sqlalchemy \
|
||||
build-base \
|
||||
zlib-dev \
|
||||
jpeg-dev \
|
||||
libxslt-dev \
|
||||
libxml2-dev \
|
||||
libmagic \
|
||||
ffmpeg \
|
||||
bash \
|
||||
ca-certificates \
|
||||
@@ -21,9 +23,7 @@ RUN apk add --no-cache \
|
||||
&& cd /opt/mautrixtelegram \
|
||||
&& cp -r docker/root/* / \
|
||||
&& rm docker -rf \
|
||||
&& virtualenv -p /usr/bin/python3 .venv \
|
||||
&& source .venv/bin/activate \
|
||||
&& pip install -r requirements.txt -r optional-requirements.txt
|
||||
&& pip3 install -r requirements.txt -r optional-requirements.txt
|
||||
|
||||
VOLUME /data
|
||||
|
||||
|
||||
@@ -35,9 +35,6 @@ script_location = alembic
|
||||
# are written from script.py.mako
|
||||
# output_encoding = utf-8
|
||||
|
||||
sqlalchemy.url = sqlite:///mautrix-telegram.db
|
||||
|
||||
|
||||
# Logging configuration
|
||||
[loggers]
|
||||
keys = root,sqlalchemy,alembic
|
||||
|
||||
+7
-1
@@ -1,4 +1,3 @@
|
||||
from __future__ import with_statement
|
||||
from alembic import context
|
||||
from sqlalchemy import engine_from_config, pool
|
||||
from logging.config import fileConfig
|
||||
@@ -8,12 +7,19 @@ from os.path import abspath, dirname
|
||||
sys.path.insert(0, dirname(dirname(abspath(__file__))))
|
||||
|
||||
from mautrix_telegram.base import Base
|
||||
from mautrix_telegram.config import Config
|
||||
import mautrix_telegram.db
|
||||
|
||||
# this is the Alembic Config object, which provides
|
||||
# access to the values within the .ini file in use.
|
||||
config = context.config
|
||||
|
||||
mxtg_config_path = context.get_x_argument(as_dictionary=True).get("config", "config.yaml")
|
||||
mxtg_config = Config(mxtg_config_path, None, None)
|
||||
mxtg_config.load()
|
||||
config.set_main_option("sqlalchemy.url",
|
||||
mxtg_config.get("appservice.database", "sqlite:///mautrix-telegram.db"))
|
||||
|
||||
# Interpret the config file for Python logging.
|
||||
# This line sets up loggers basically.
|
||||
fileConfig(config.config_file_name)
|
||||
|
||||
@@ -19,31 +19,31 @@ depends_on = None
|
||||
|
||||
def upgrade():
|
||||
Session = op.create_table('telethon_sessions',
|
||||
sa.Column('session_id', sa.VARCHAR(), nullable=False),
|
||||
sa.Column('dc_id', sa.INTEGER(), nullable=False),
|
||||
sa.Column('server_address', sa.VARCHAR(), nullable=True),
|
||||
sa.Column('port', sa.INTEGER(), nullable=True),
|
||||
sa.Column('auth_key', sa.BLOB(), nullable=True),
|
||||
sa.Column('session_id', sa.String, nullable=False),
|
||||
sa.Column('dc_id', sa.Integer, nullable=False),
|
||||
sa.Column('server_address', sa.String, nullable=True),
|
||||
sa.Column('port', sa.Integer, nullable=True),
|
||||
sa.Column('auth_key', sa.LargeBinary, nullable=True),
|
||||
sa.PrimaryKeyConstraint('session_id', 'dc_id'))
|
||||
SentFile = op.create_table('telethon_sent_files',
|
||||
sa.Column('session_id', sa.VARCHAR(), nullable=False),
|
||||
sa.Column('md5_digest', sa.BLOB(), nullable=False),
|
||||
sa.Column('file_size', sa.INTEGER(), nullable=False),
|
||||
sa.Column('type', sa.INTEGER(), nullable=False),
|
||||
sa.Column('id', sa.INTEGER(), nullable=True),
|
||||
sa.Column('hash', sa.INTEGER(), nullable=True),
|
||||
sa.Column('session_id', sa.String, nullable=False),
|
||||
sa.Column('md5_digest', sa.LargeBinary, nullable=False),
|
||||
sa.Column('file_size', sa.Integer, nullable=False),
|
||||
sa.Column('type', sa.Integer, nullable=False),
|
||||
sa.Column('id', sa.BigInteger, nullable=True),
|
||||
sa.Column('hash', sa.BigInteger, nullable=True),
|
||||
sa.PrimaryKeyConstraint('session_id', 'md5_digest', 'file_size',
|
||||
'type'))
|
||||
Entity = op.create_table('telethon_entities',
|
||||
sa.Column('session_id', sa.VARCHAR(), nullable=False),
|
||||
sa.Column('id', sa.INTEGER(), nullable=False),
|
||||
sa.Column('hash', sa.INTEGER(), nullable=False),
|
||||
sa.Column('username', sa.VARCHAR(), nullable=True),
|
||||
sa.Column('phone', sa.INTEGER(), nullable=True),
|
||||
sa.Column('name', sa.VARCHAR(), nullable=True),
|
||||
sa.Column('session_id', sa.String, nullable=False),
|
||||
sa.Column('id', sa.Integer, nullable=False),
|
||||
sa.Column('hash', sa.Integer, nullable=False),
|
||||
sa.Column('username', sa.String, nullable=True),
|
||||
sa.Column('phone', sa.Integer, nullable=True),
|
||||
sa.Column('name', sa.String, nullable=True),
|
||||
sa.PrimaryKeyConstraint('session_id', 'id'))
|
||||
Version = op.create_table('telethon_version',
|
||||
sa.Column('version', sa.INTEGER(), nullable=False),
|
||||
sa.Column('version', sa.Integer, nullable=False),
|
||||
sa.PrimaryKeyConstraint('version'))
|
||||
conn = op.get_bind()
|
||||
sessions = [os.path.basename(f) for f in os.listdir(".") if f.endswith(".session")]
|
||||
|
||||
@@ -18,7 +18,7 @@ depends_on = None
|
||||
def upgrade():
|
||||
op.add_column('telegram_file',
|
||||
sa.Column('timestamp', sa.BigInteger(), nullable=False, default=0,
|
||||
server_default="true"))
|
||||
server_default="0"))
|
||||
|
||||
|
||||
def downgrade():
|
||||
|
||||
@@ -29,7 +29,7 @@ def upgrade():
|
||||
sa.UniqueConstraint('mxid'))
|
||||
op.create_table('user',
|
||||
sa.Column('mxid', sa.String),
|
||||
sa.Column('tgid', sa.Integer, nullable=True),
|
||||
sa.Column('tgid', sa.Integer, nullable=True, unique=True),
|
||||
sa.Column('tg_username', sa.String, nullable=True),
|
||||
sa.Column('saved_contacts', sa.Integer, nullable=False, default=0),
|
||||
sa.PrimaryKeyConstraint('mxid'))
|
||||
|
||||
@@ -8,14 +8,13 @@ function fixperms {
|
||||
|
||||
# Go into env
|
||||
cd /opt/mautrixtelegram
|
||||
source .venv/bin/activate
|
||||
export FFMPEG_BINARY=/usr/bin/ffmpeg
|
||||
|
||||
# Replace database path in alembic.ini
|
||||
sed -i "s#sqlite:///mautrix-telegram.db#sqlite:////data/mautrix-telegram.db#" alembic.ini
|
||||
# Replace database path in config.
|
||||
sed -i "s#sqlite:///mautrix-telegram.db#sqlite:////data/mautrix-telegram.db#" /data/config.yaml
|
||||
|
||||
# Check that database is in the right state
|
||||
alembic upgrade head
|
||||
alembic -x config=/data/config.yaml upgrade head
|
||||
|
||||
if [[ ! -f /data/config.yaml ]]; then
|
||||
cp example-config.yaml /data/config.yaml
|
||||
@@ -28,7 +27,7 @@ if [[ ! -f /data/config.yaml ]]; then
|
||||
fi
|
||||
|
||||
if [[ ! -f /data/registration.yaml ]]; then
|
||||
python -m mautrix_telegram -g -c /data/config.yaml -r /data/registration.yaml
|
||||
python3 -m mautrix_telegram -g -c /data/config.yaml -r /data/registration.yaml
|
||||
echo "Didn't find a registration file."
|
||||
echo "Generated ode for you."
|
||||
echo "Copy that over to synapses app service directory."
|
||||
@@ -36,7 +35,5 @@ if [[ ! -f /data/registration.yaml ]]; then
|
||||
exit
|
||||
fi
|
||||
|
||||
export FFMPEG_BINARY=/usr/bin/ffmpeg
|
||||
|
||||
fixperms
|
||||
exec su-exec ${UID}:${GID} python -m mautrix_telegram -c /data/config.yaml
|
||||
exec su-exec ${UID}:${GID} python3 -m mautrix_telegram -c /data/config.yaml
|
||||
|
||||
@@ -1,2 +1,2 @@
|
||||
__version__ = "0.2.0rc2"
|
||||
__version__ = "0.2.0rc4"
|
||||
__author__ = "Tulir Asokan <tulir@maunium.net>"
|
||||
|
||||
@@ -26,7 +26,7 @@ from alchemysession import AlchemySessionContainer
|
||||
from mautrix_appservice import AppService
|
||||
|
||||
from .base import Base
|
||||
from .config import Config, DictWithRecursion
|
||||
from .config import Config
|
||||
from .matrix import MatrixHandler
|
||||
|
||||
from .db import init as init_db
|
||||
|
||||
@@ -166,7 +166,7 @@ class Bot(AbstractUser):
|
||||
if not self.mxid_regex.match(mxid):
|
||||
return await reply("That doesn't look like a Matrix ID.")
|
||||
user = await u.User.get_by_mxid(mxid).ensure_started()
|
||||
if not user.whitelisted:
|
||||
if not user.relaybot_whitelisted:
|
||||
return await reply("That user is not whitelisted to use the bridge.")
|
||||
elif user.logged_in:
|
||||
displayname = f"@{user.username}" if user.username else user.displayname
|
||||
|
||||
@@ -102,7 +102,7 @@ def _get_portal_murder_function(action, room_id, function, command, completed_me
|
||||
}
|
||||
|
||||
|
||||
@command_handler()
|
||||
@command_handler(needs_auth=False)
|
||||
async def delete_portal(evt: CommandEvent):
|
||||
portal, ok = await _get_portal_and_check_permission(evt, "delete_portal")
|
||||
if not ok:
|
||||
@@ -117,7 +117,7 @@ async def delete_portal(evt: CommandEvent):
|
||||
"by typing `$cmdprefix+sp confirm-delete`")
|
||||
|
||||
|
||||
@command_handler()
|
||||
@command_handler(needs_auth=False)
|
||||
async def unbridge(evt: CommandEvent):
|
||||
portal, ok = await _get_portal_and_check_permission(evt, "unbridge_room")
|
||||
if not ok:
|
||||
@@ -131,7 +131,7 @@ async def unbridge(evt: CommandEvent):
|
||||
"by typing `$cmdprefix+sp confirm-unbridge`")
|
||||
|
||||
|
||||
@command_handler()
|
||||
@command_handler(needs_auth=False)
|
||||
async def bridge(evt: CommandEvent):
|
||||
if len(evt.args) == 0:
|
||||
return await evt.reply("**Usage:** "
|
||||
@@ -247,14 +247,25 @@ async def confirm_bridge(evt: CommandEvent):
|
||||
return await evt.reply("Please use `$cmdprefix+sp continue` to confirm the bridging or "
|
||||
"`$cmdprefix+sp cancel` to cancel.")
|
||||
|
||||
user = evt.sender if evt.sender.logged_in else evt.tgbot
|
||||
try:
|
||||
entity = await user.client.get_entity(portal.peer)
|
||||
except Exception:
|
||||
evt.log.exception("Failed to get_entity(%s) for manual bridging.", portal.peer)
|
||||
if evt.sender.logged_in:
|
||||
return await evt.reply("Failed to get info of telegram chat. "
|
||||
"You are logged in, are you in that chat?")
|
||||
else:
|
||||
return await evt.reply("Failed to get info of telegram chat. "
|
||||
"You're not logged in, is the relay bot in the chat?")
|
||||
direct = False
|
||||
|
||||
portal.mxid = bridge_to_mxid
|
||||
portal.title, portal.about, levels = await _get_initial_state(evt)
|
||||
portal.photo_id = ""
|
||||
portal.save()
|
||||
|
||||
entity = await evt.sender.client.get_entity(portal.peer)
|
||||
direct = False
|
||||
asyncio.ensure_future(portal.update_matrix_room(evt.sender, entity, direct, levels=levels),
|
||||
asyncio.ensure_future(portal.update_matrix_room(user, entity, direct, levels=levels),
|
||||
loop=evt.loop)
|
||||
|
||||
return await evt.reply("Bridging complete. Portal synchronization should begin momentarily.")
|
||||
|
||||
@@ -70,7 +70,7 @@ class User(Base):
|
||||
__tablename__ = "user"
|
||||
|
||||
mxid = Column(String, primary_key=True)
|
||||
tgid = Column(Integer, nullable=True)
|
||||
tgid = Column(Integer, nullable=True, unique=True)
|
||||
tg_username = Column(String, nullable=True)
|
||||
saved_contacts = Column(Integer, default=0)
|
||||
contacts = relationship("Contact", uselist=True,
|
||||
|
||||
Reference in New Issue
Block a user