Compare commits
8 Commits
v0.7.0-rc1
...
v0.7.0-rc2
| Author | SHA1 | Date | |
|---|---|---|---|
| 36e2c6f66f | |||
| 69d56f4632 | |||
| af0f731a8a | |||
| cf8c05e1c5 | |||
| 7d5e307368 | |||
| 701b28c33c | |||
| a239ca439a | |||
| 578af19baa |
@@ -33,6 +33,7 @@ RUN apk add --no-cache --virtual .build-deps \
|
|||||||
python3-dev \
|
python3-dev \
|
||||||
libffi-dev \
|
libffi-dev \
|
||||||
build-base \
|
build-base \
|
||||||
|
git \
|
||||||
&& apk add --no-cache \
|
&& apk add --no-cache \
|
||||||
py3-virtualenv \
|
py3-virtualenv \
|
||||||
py3-pillow \
|
py3-pillow \
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ depends_on = None
|
|||||||
def upgrade():
|
def upgrade():
|
||||||
conn = op.get_bind()
|
conn = op.get_bind()
|
||||||
conn.execute("UPDATE mx_user_profile SET membership=UPPER(membership)")
|
conn.execute("UPDATE mx_user_profile SET membership=UPPER(membership)")
|
||||||
|
conn.execute("UPDATE mx_user_profile SET membership='LEAVE' WHERE membership='LEFT'")
|
||||||
|
|
||||||
|
|
||||||
def downgrade():
|
def downgrade():
|
||||||
|
|||||||
+1
-1
@@ -33,7 +33,7 @@ appservice:
|
|||||||
# the HS database.
|
# the HS database.
|
||||||
public:
|
public:
|
||||||
# Whether or not the public-facing endpoints should be enabled.
|
# Whether or not the public-facing endpoints should be enabled.
|
||||||
enabled: true
|
enabled: false
|
||||||
# The prefix to use in the public-facing endpoints.
|
# The prefix to use in the public-facing endpoints.
|
||||||
prefix: /public
|
prefix: /public
|
||||||
# The base URL where the public-facing endpoints are available. The prefix is not added
|
# The base URL where the public-facing endpoints are available. The prefix is not added
|
||||||
|
|||||||
@@ -1,2 +1,2 @@
|
|||||||
__version__ = "0.7.0rc1"
|
__version__ = "0.7.0rc2"
|
||||||
__author__ = "Tulir Asokan <tulir@maunium.net>"
|
__author__ = "Tulir Asokan <tulir@maunium.net>"
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ from .portal import init as init_portal
|
|||||||
from .puppet import Puppet, init as init_puppet
|
from .puppet import Puppet, init as init_puppet
|
||||||
from .sqlstatestore import SQLStateStore
|
from .sqlstatestore import SQLStateStore
|
||||||
from .user import User, init as init_user
|
from .user import User, init as init_user
|
||||||
from . import __version__
|
from .version import version, linkified_version
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import prometheus_client as prometheus
|
import prometheus_client as prometheus
|
||||||
@@ -47,8 +47,10 @@ class TelegramBridge(Bridge):
|
|||||||
name = "mautrix-telegram"
|
name = "mautrix-telegram"
|
||||||
command = "python -m mautrix-telegram"
|
command = "python -m mautrix-telegram"
|
||||||
description = "A Matrix-Telegram puppeting bridge."
|
description = "A Matrix-Telegram puppeting bridge."
|
||||||
|
repo_url = "https://github.com/tulir/mautrix-telegram"
|
||||||
real_user_content_key = "net.maunium.telegram.puppet"
|
real_user_content_key = "net.maunium.telegram.puppet"
|
||||||
version = __version__
|
version = version
|
||||||
|
markdown_version = linkified_version
|
||||||
config_class = Config
|
config_class = Config
|
||||||
matrix_class = MatrixHandler
|
matrix_class = MatrixHandler
|
||||||
state_store_class = SQLStateStore
|
state_store_class = SQLStateStore
|
||||||
|
|||||||
@@ -112,7 +112,7 @@ def command_handler(_func: Optional[CommandHandlerFunc] = None, *, needs_auth: b
|
|||||||
class CommandProcessor(BaseCommandProcessor):
|
class CommandProcessor(BaseCommandProcessor):
|
||||||
def __init__(self, context: c.Context) -> None:
|
def __init__(self, context: c.Context) -> None:
|
||||||
super().__init__(az=context.az, config=context.config, event_class=CommandEvent,
|
super().__init__(az=context.az, config=context.config, event_class=CommandEvent,
|
||||||
loop=context.loop)
|
loop=context.loop, bridge=context.bridge)
|
||||||
self.tgbot = context.bot
|
self.tgbot = context.bot
|
||||||
self.bridge = context.bridge
|
self.bridge = context.bridge
|
||||||
self.az, self.config, self.loop, self.tgbot = context.core
|
self.az, self.config, self.loop, self.tgbot = context.core
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ from ... import portal as po, util
|
|||||||
from .. import command_handler, CommandEvent, SECTION_PORTAL_MANAGEMENT
|
from .. import command_handler, CommandEvent, SECTION_PORTAL_MANAGEMENT
|
||||||
|
|
||||||
|
|
||||||
@command_handler(help_section=SECTION_PORTAL_MANAGEMENT,
|
@command_handler(needs_auth=False, help_section=SECTION_PORTAL_MANAGEMENT,
|
||||||
help_text="View or change per-portal settings.",
|
help_text="View or change per-portal settings.",
|
||||||
help_args="<`help`|_subcommand_> [...]")
|
help_args="<`help`|_subcommand_> [...]")
|
||||||
async def config(evt: CommandEvent) -> None:
|
async def config(evt: CommandEvent) -> None:
|
||||||
@@ -43,6 +43,10 @@ async def config(evt: CommandEvent) -> None:
|
|||||||
await config_view(evt, portal)
|
await config_view(evt, portal)
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if not await portal.can_user_perform(evt.sender, "config"):
|
||||||
|
await evt.reply("You do not have the permissions to configure this room.")
|
||||||
|
return
|
||||||
|
|
||||||
key = evt.args[1] if len(evt.args) > 1 else None
|
key = evt.args[1] if len(evt.args) > 1 else None
|
||||||
value = yaml.load(" ".join(evt.args[2:])) if len(evt.args) > 2 else None
|
value = yaml.load(" ".join(evt.args[2:])) if len(evt.args) > 2 else None
|
||||||
if cmd == "set":
|
if cmd == "set":
|
||||||
|
|||||||
@@ -19,7 +19,8 @@ import os
|
|||||||
|
|
||||||
from mautrix.types import UserID
|
from mautrix.types import UserID
|
||||||
from mautrix.client import Client
|
from mautrix.client import Client
|
||||||
from mautrix.bridge.config import BaseBridgeConfig, ConfigUpdateHelper
|
from mautrix.bridge.config import (BaseBridgeConfig, ConfigUpdateHelper, ForbiddenKey,
|
||||||
|
ForbiddenDefault)
|
||||||
|
|
||||||
Permissions = NamedTuple("Permissions", relaybot=bool, user=bool, puppeting=bool,
|
Permissions = NamedTuple("Permissions", relaybot=bool, user=bool, puppeting=bool,
|
||||||
matrix_puppeting=bool, admin=bool, level=str)
|
matrix_puppeting=bool, admin=bool, level=str)
|
||||||
@@ -32,6 +33,17 @@ class Config(BaseBridgeConfig):
|
|||||||
except KeyError:
|
except KeyError:
|
||||||
return super().__getitem__(key)
|
return super().__getitem__(key)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def forbidden_defaults(self) -> List[ForbiddenDefault]:
|
||||||
|
return [
|
||||||
|
*super().forbidden_defaults,
|
||||||
|
ForbiddenDefault("appservice.public.external", "https://example.com/public",
|
||||||
|
condition="appservice.public.enabled"),
|
||||||
|
ForbiddenDefault("bridge.permissions", ForbiddenKey("example.com")),
|
||||||
|
ForbiddenDefault("telegram.api_id", 12345),
|
||||||
|
ForbiddenDefault("telegram.api_hash", "tjyd5yge35lbodk1xwzw2jstp90k55qz"),
|
||||||
|
]
|
||||||
|
|
||||||
def do_update(self, helper: ConfigUpdateHelper) -> None:
|
def do_update(self, helper: ConfigUpdateHelper) -> None:
|
||||||
copy, copy_dict, base = helper
|
copy, copy_dict, base = helper
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
import subprocess
|
||||||
|
import os
|
||||||
|
|
||||||
|
from . import __version__
|
||||||
|
|
||||||
|
cmd_env = {
|
||||||
|
"PATH": os.environ["PATH"],
|
||||||
|
"HOME": os.environ["HOME"],
|
||||||
|
"LANG": "C",
|
||||||
|
"LC_ALL": "C",
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def run(cmd):
|
||||||
|
return subprocess.check_output(cmd, stderr=subprocess.DEVNULL, env=cmd_env)
|
||||||
|
|
||||||
|
|
||||||
|
if os.path.exists(".git"):
|
||||||
|
try:
|
||||||
|
git_revision = run(["git", "rev-parse", "HEAD"]).strip().decode("ascii")
|
||||||
|
git_revision_url = f"https://github.com/tulir/mautrix-telegram/commit/{git_revision}"
|
||||||
|
git_revision = git_revision[:8]
|
||||||
|
except (subprocess.SubprocessError, OSError):
|
||||||
|
git_revision = "unknown"
|
||||||
|
git_revision_url = None
|
||||||
|
|
||||||
|
try:
|
||||||
|
git_tag = run(["git", "describe", "--exact-match", "--tags"]).strip().decode("ascii")
|
||||||
|
git_tag_url = f"https://github.com/tulir/mautrix-telegram/releases/tag/{git_tag}"
|
||||||
|
except (subprocess.SubprocessError, OSError):
|
||||||
|
git_tag = None
|
||||||
|
git_tag_url = None
|
||||||
|
else:
|
||||||
|
git_revision = "unknown"
|
||||||
|
git_revision_url = None
|
||||||
|
git_tag = None
|
||||||
|
git_tag_url = None
|
||||||
|
|
||||||
|
if git_tag and __version__ == git_tag[1:].replace("-", ""):
|
||||||
|
version = __version__
|
||||||
|
linkified_version = f"[{version}]({git_tag_url})"
|
||||||
|
else:
|
||||||
|
if not __version__.endswith("+dev"):
|
||||||
|
__version__ += "+dev"
|
||||||
|
version = f"{__version__}.{git_revision}"
|
||||||
|
if git_revision_url:
|
||||||
|
linkified_version = f"{__version__}.[{git_revision}]({git_revision_url})"
|
||||||
|
else:
|
||||||
|
linkified_version = version
|
||||||
@@ -401,9 +401,11 @@ class BasePortal(ABC):
|
|||||||
|
|
||||||
if peer_type:
|
if peer_type:
|
||||||
cls.log.info(f"Creating portal for {peer_type} {tgid} (receiver {tg_receiver})")
|
cls.log.info(f"Creating portal for {peer_type} {tgid} (receiver {tg_receiver})")
|
||||||
if peer_type == "chat":
|
# TODO enable this for non-release builds
|
||||||
import traceback
|
# (or add better wrong peer type error handling)
|
||||||
cls.log.info("Chat portal stack trace:\n" + "".join(traceback.format_stack()))
|
# if peer_type == "chat":
|
||||||
|
# import traceback
|
||||||
|
# cls.log.info("Chat portal stack trace:\n" + "".join(traceback.format_stack()))
|
||||||
portal = cls(tgid, peer_type=peer_type, tg_receiver=tg_receiver)
|
portal = cls(tgid, peer_type=peer_type, tg_receiver=tg_receiver)
|
||||||
portal.db_instance.insert()
|
portal.db_instance.insert()
|
||||||
return portal
|
return portal
|
||||||
|
|||||||
@@ -19,7 +19,8 @@ import logging
|
|||||||
import asyncio
|
import asyncio
|
||||||
|
|
||||||
from telethon.tl.types import (TypeUpdate, UpdateNewMessage, UpdateNewChannelMessage, PeerUser,
|
from telethon.tl.types import (TypeUpdate, UpdateNewMessage, UpdateNewChannelMessage, PeerUser,
|
||||||
UpdateShortChatMessage, UpdateShortMessage, User as TLUser, Chat)
|
UpdateShortChatMessage, UpdateShortMessage, User as TLUser, Chat,
|
||||||
|
ChatForbidden)
|
||||||
from telethon.tl.types.contacts import ContactsNotModified
|
from telethon.tl.types.contacts import ContactsNotModified
|
||||||
from telethon.tl.functions.contacts import GetContactsRequest, SearchRequest
|
from telethon.tl.functions.contacts import GetContactsRequest, SearchRequest
|
||||||
from telethon.tl.functions.account import UpdateStatusRequest
|
from telethon.tl.functions.account import UpdateStatusRequest
|
||||||
@@ -327,7 +328,9 @@ class User(AbstractUser, BaseUser):
|
|||||||
async for dialog in self.client.iter_dialogs(limit=limit, ignore_migrated=True,
|
async for dialog in self.client.iter_dialogs(limit=limit, ignore_migrated=True,
|
||||||
archived=False):
|
archived=False):
|
||||||
entity = dialog.entity
|
entity = dialog.entity
|
||||||
if isinstance(entity, Chat) and (entity.deactivated or entity.left):
|
if isinstance(entity, ChatForbidden):
|
||||||
|
self.log.warning(f"Ignoring forbidden chat {entity} while syncing")
|
||||||
|
elif isinstance(entity, Chat) and (entity.deactivated or entity.left):
|
||||||
self.log.warning(f"Ignoring deactivated or left chat {entity} while syncing")
|
self.log.warning(f"Ignoring deactivated or left chat {entity} while syncing")
|
||||||
continue
|
continue
|
||||||
elif isinstance(entity, TLUser) and not config["bridge.sync_direct_chats"]:
|
elif isinstance(entity, TLUser) and not config["bridge.sync_direct_chats"]:
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
from .get_version import git_tag, git_revision, version, linkified_version
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import setuptools
|
import setuptools
|
||||||
import glob
|
import glob
|
||||||
import mautrix_telegram
|
|
||||||
|
from mautrix_telegram.get_version import git_tag, git_revision, version, linkified_version
|
||||||
|
|
||||||
extras = {
|
extras = {
|
||||||
"speedups": ["cryptg>=0.1,<0.3", "cchardet", "aiodns", "Brotli"],
|
"speedups": ["cryptg>=0.1,<0.3", "cchardet", "aiodns", "Brotli"],
|
||||||
@@ -16,9 +17,18 @@ try:
|
|||||||
except IOError:
|
except IOError:
|
||||||
long_desc = "Failed to read README.md"
|
long_desc = "Failed to read README.md"
|
||||||
|
|
||||||
|
with open("mautrix_telegram/version.py", "w") as version_file:
|
||||||
|
version_file.write(f"""# Generated in setup.py
|
||||||
|
|
||||||
|
git_tag = {git_tag!r}
|
||||||
|
git_revision = {git_revision!r}
|
||||||
|
version = {version!r}
|
||||||
|
linkified_version = {linkified_version!r}
|
||||||
|
""")
|
||||||
|
|
||||||
setuptools.setup(
|
setuptools.setup(
|
||||||
name="mautrix-telegram",
|
name="mautrix-telegram",
|
||||||
version=mautrix_telegram.__version__,
|
version=version,
|
||||||
url="https://github.com/tulir/mautrix-telegram",
|
url="https://github.com/tulir/mautrix-telegram",
|
||||||
|
|
||||||
author="Tulir Asokan",
|
author="Tulir Asokan",
|
||||||
@@ -32,7 +42,7 @@ setuptools.setup(
|
|||||||
|
|
||||||
install_requires=[
|
install_requires=[
|
||||||
"aiohttp>=3.0.1,<4",
|
"aiohttp>=3.0.1,<4",
|
||||||
"mautrix>=0.4.0rc1,<0.5",
|
"mautrix>=0.4.0rc2,<0.5",
|
||||||
"SQLAlchemy>=1.2.3,<2",
|
"SQLAlchemy>=1.2.3,<2",
|
||||||
"alembic>=1.0.0,<2",
|
"alembic>=1.0.0,<2",
|
||||||
"commonmark>=0.8.1,<0.10",
|
"commonmark>=0.8.1,<0.10",
|
||||||
|
|||||||
Reference in New Issue
Block a user