mirror of
https://github.com/mautrix/telegram.git
synced 2026-05-17 07:25:46 +03:00
Add command to forget portal room. Fixes #30
This commit is contained in:
@@ -129,4 +129,4 @@ The bridge does not do this automatically.
|
||||
* [x] Creating a Telegram chat for an existing Matrix room (`create`)
|
||||
* [ ] Upgrading the chat of a portal room into a supergroup (`upgrade`)
|
||||
* [x] Getting the Telegram invite link to a Matrix room (`invitelink`)
|
||||
* [ ] Clean up and forget a portal room (`deleteportal`)
|
||||
* [x] Clean up and forget a portal room (`deleteportal`)
|
||||
|
||||
@@ -67,6 +67,10 @@ bridge:
|
||||
- "internal-hs.example.com"
|
||||
- "@user:public.example.com"
|
||||
|
||||
# Admins can do things like delete portal rooms.
|
||||
admins:
|
||||
- "@admin:internal-hs.example.com"
|
||||
|
||||
# Telegram config
|
||||
telegram:
|
||||
# Get your own API keys at https://my.telegram.org/apps
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
from contextlib import contextmanager
|
||||
import markdown
|
||||
from matrix_client.errors import MatrixRequestError
|
||||
from telethon.errors import *
|
||||
from telethon.tl.types import *
|
||||
from telethon.tl.functions.contacts import SearchRequest
|
||||
@@ -255,6 +256,26 @@ class CommandHandler:
|
||||
except ChatAdminRequiredError:
|
||||
return self.reply("You don't have the permission to create an invite link.")
|
||||
|
||||
@command_handler
|
||||
def delete_portal(self, sender, args):
|
||||
if not sender.logged_in:
|
||||
return self.reply("This command requires you to be logged in.")
|
||||
elif not sender.is_admin:
|
||||
return self.reply("This is command requires administrator privileges.")
|
||||
|
||||
portal = po.Portal.get_by_mxid(self._room_id)
|
||||
if not portal:
|
||||
return self.reply("This is not a portal room.")
|
||||
|
||||
for user in portal.main_intent.get_room_members(portal.mxid):
|
||||
if user != portal.main_intent.mxid:
|
||||
try:
|
||||
portal.main_intent.kick(portal.mxid, user, "Portal deleted.")
|
||||
except MatrixRequestError:
|
||||
pass
|
||||
portal.main_intent.leave_room(portal.mxid)
|
||||
portal.delete()
|
||||
|
||||
def _strip_prefix(self, value, prefixes):
|
||||
for prefix in prefixes:
|
||||
if value.startswith(prefix):
|
||||
@@ -393,7 +414,9 @@ _**Telegram actions**: commands for using the bridge to interact with Telegram._
|
||||
**join** <_link_> - Join a chat with an invite link.
|
||||
**create** [_type_] - Create a Telegram chat of the given type for the current Matrix room.
|
||||
The type is either `group`, `supergroup` or `channel` (defaults to `group`).
|
||||
**upgrade** - Upgrade a normal Telegram group to a supergroup.
|
||||
**upgrade** - Upgrade a normal Telegram group to a supergroup.
|
||||
**invitelink** - Get a Telegram invite link to the current chat.
|
||||
**deleteportal** - Forget the current portal room.
|
||||
"""
|
||||
return self.reply(management_status + help)
|
||||
|
||||
|
||||
@@ -40,7 +40,12 @@ class User:
|
||||
self.command_status = None
|
||||
self.connected = False
|
||||
self.client = None
|
||||
whitelist = config.get("bridge", {}).get("whitelist", None) or [self.mxid]
|
||||
|
||||
bridge_config = config.get("bridge", {})
|
||||
|
||||
self.is_admin = self.mxid in bridge_config.get("admins", [])
|
||||
|
||||
whitelist = bridge_config.get("whitelist", None) or [self.mxid]
|
||||
self.whitelisted = not whitelist or self.mxid in whitelist
|
||||
if not self.whitelisted:
|
||||
homeserver = self.mxid[self.mxid.index(":") + 1:]
|
||||
@@ -185,7 +190,7 @@ class User:
|
||||
for dialog in dialogs:
|
||||
entity = dialog.entity
|
||||
if (isinstance(entity, (TLUser, ChatForbidden, ChannelForbidden)) or (
|
||||
isinstance(entity, Chat) and entity.deactivated)):
|
||||
isinstance(entity, Chat) and (entity.deactivated or entity.left))):
|
||||
continue
|
||||
portal = po.Portal.get_by_entity(entity)
|
||||
portal.create_matrix_room(self, entity, invites=[self.mxid])
|
||||
|
||||
Reference in New Issue
Block a user