Update README and clean up new methods
This commit is contained in:
@@ -1,5 +1,5 @@
|
|||||||
# mautrix-telegram
|
# mautrix-telegram
|
||||||
**This is the python rewrite. If you want more features (and more bugs), check the JavaScript version on the master branch.**
|
**This is the python rewrite. The JavaScript version on the master branch has different features and more bugs**
|
||||||
|
|
||||||
A Matrix-Telegram puppeting bridge.
|
A Matrix-Telegram puppeting bridge.
|
||||||
|
|
||||||
@@ -88,8 +88,8 @@ does not do this automatically.
|
|||||||
* [x] Audio messages
|
* [x] Audio messages
|
||||||
* [x] Video messages
|
* [x] Video messages
|
||||||
* [x] Documents
|
* [x] Documents
|
||||||
* [ ] Message deletions
|
* [ ] Message deletions (no way to tell difference between user-specific deletion and global deletion)
|
||||||
* [ ] Message edits
|
* [ ] Message edits (not supported in Matrix)
|
||||||
* [x] Avatars
|
* [x] Avatars
|
||||||
* [x] Presence
|
* [x] Presence
|
||||||
* [x] Typing notifications
|
* [x] Typing notifications
|
||||||
@@ -114,3 +114,10 @@ does not do this automatically.
|
|||||||
* Misc
|
* Misc
|
||||||
* [ ] Use optional bot to relay messages for unauthenticated Matrix users
|
* [ ] Use optional bot to relay messages for unauthenticated Matrix users
|
||||||
* [ ] Command to upgrade chat to supergroup from Matrix
|
* [ ] Command to upgrade chat to supergroup from Matrix
|
||||||
|
* Commands
|
||||||
|
* [x] Logging in and out
|
||||||
|
* [ ] Registering
|
||||||
|
* [ ] Searching for users
|
||||||
|
* [ ] Starting a private chat with users
|
||||||
|
* [ ] Creating a Telegram chat for an existing Matrix room
|
||||||
|
* [ ] Upgrading the chat of a portal room into a supergroup
|
||||||
|
|||||||
@@ -33,6 +33,8 @@ class CommandHandler:
|
|||||||
self._is_management = False
|
self._is_management = False
|
||||||
self._is_portal = False
|
self._is_portal = False
|
||||||
|
|
||||||
|
# region Utility functions for handling commands
|
||||||
|
|
||||||
def handle(self, room, sender, command, args, is_management, is_portal):
|
def handle(self, room, sender, command, args, is_management, is_portal):
|
||||||
with self.handler(sender, room, command, args, is_management, is_portal) as handle_command:
|
with self.handler(sender, room, command, args, is_management, is_portal) as handle_command:
|
||||||
handle_command(self, sender, args)
|
handle_command(self, sender, args)
|
||||||
@@ -70,6 +72,20 @@ class CommandHandler:
|
|||||||
html = message
|
html = message
|
||||||
self.az.intent.send_notice(self._room_id, message, html=html)
|
self.az.intent.send_notice(self._room_id, message, html=html)
|
||||||
|
|
||||||
|
# endregion
|
||||||
|
# region Command handlers
|
||||||
|
|
||||||
|
@command_handler
|
||||||
|
def ping(self, sender, args):
|
||||||
|
if not sender.logged_in:
|
||||||
|
return self.reply("You're not logged in.")
|
||||||
|
me = sender.client.get_me()
|
||||||
|
if me:
|
||||||
|
return self.reply(f"You're logged in as @{me.username}")
|
||||||
|
else:
|
||||||
|
return self.reply("You're not logged in.")
|
||||||
|
|
||||||
|
# region Authentication commands
|
||||||
@command_handler
|
@command_handler
|
||||||
def register(self, sender, args):
|
def register(self, sender, args):
|
||||||
self.reply("Not yet implemented.")
|
self.reply("Not yet implemented.")
|
||||||
@@ -160,15 +176,8 @@ class CommandHandler:
|
|||||||
return self.reply("Logged out successfully.")
|
return self.reply("Logged out successfully.")
|
||||||
return self.reply("Failed to log out.")
|
return self.reply("Failed to log out.")
|
||||||
|
|
||||||
@command_handler
|
# endregion
|
||||||
def ping(self, sender, args):
|
# region Telegram interaction commands
|
||||||
if not sender.logged_in:
|
|
||||||
return self.reply("You're not logged in.")
|
|
||||||
me = sender.client.get_me()
|
|
||||||
if me:
|
|
||||||
return self.reply(f"You're logged in as @{me.username}")
|
|
||||||
else:
|
|
||||||
return self.reply("You're not logged in.")
|
|
||||||
|
|
||||||
@command_handler
|
@command_handler
|
||||||
def search(self, sender, args):
|
def search(self, sender, args):
|
||||||
@@ -186,6 +195,8 @@ class CommandHandler:
|
|||||||
def upgrade(self, sender, args):
|
def upgrade(self, sender, args):
|
||||||
self.reply("Not yet implemented.")
|
self.reply("Not yet implemented.")
|
||||||
|
|
||||||
|
# endregion
|
||||||
|
# region Command-related commands
|
||||||
@command_handler
|
@command_handler
|
||||||
def cancel(self, sender, args):
|
def cancel(self, sender, args):
|
||||||
if sender.command_status:
|
if sender.command_status:
|
||||||
@@ -230,3 +241,6 @@ _**Telegram actions**: commands for using the bridge to interact with Telegram._
|
|||||||
**upgrade** - Upgrade a normal Telegram group to a supergroup.
|
**upgrade** - Upgrade a normal Telegram group to a supergroup.
|
||||||
"""
|
"""
|
||||||
return self.reply(management_status + help)
|
return self.reply(management_status + help)
|
||||||
|
|
||||||
|
# endregion
|
||||||
|
# endregion
|
||||||
|
|||||||
@@ -300,7 +300,6 @@ class Portal:
|
|||||||
"formatted_body": formatted_body,
|
"formatted_body": formatted_body,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
def handle_telegram_message(self, source, sender, evt):
|
def handle_telegram_message(self, source, sender, evt):
|
||||||
if not self.mxid:
|
if not self.mxid:
|
||||||
self.create_room(source, invites=[source.mxid])
|
self.create_room(source, invites=[source.mxid])
|
||||||
|
|||||||
@@ -126,24 +126,17 @@ class User:
|
|||||||
|
|
||||||
return self.client._get_response_message(request, result)
|
return self.client._get_response_message(request, result)
|
||||||
|
|
||||||
def send_file(self, entity, file, mime_type=None, caption=None,
|
def send_file(self, entity, file, mime_type=None, caption=None, attributes=[], file_name=None,
|
||||||
attributes=None, file_name=None, reply_to=None):
|
reply_to=None):
|
||||||
entity = self.client.get_input_entity(entity)
|
entity = self.client.get_input_entity(entity)
|
||||||
reply_to = self.client._get_reply_to(reply_to)
|
reply_to = self.client._get_reply_to(reply_to)
|
||||||
|
|
||||||
file_handle = self.client.upload_file(file, file_name=file_name, use_cache=False)
|
file_handle = self.client.upload_file(file, file_name=file_name, use_cache=False)
|
||||||
print(entity, mime_type, caption)
|
|
||||||
for a in attributes:
|
|
||||||
print(a)
|
|
||||||
print(file_handle)
|
|
||||||
|
|
||||||
if mime_type.startswith("image/"):
|
if mime_type.startswith("image/"):
|
||||||
media = InputMediaUploadedPhoto(file_handle, caption or "")
|
media = InputMediaUploadedPhoto(file_handle, caption or "")
|
||||||
else:
|
else:
|
||||||
attr_dict = {}
|
attr_dict = {type(attr): attr for attr in attributes}
|
||||||
if attributes:
|
|
||||||
for a in attributes:
|
|
||||||
attr_dict[type(a)] = a
|
|
||||||
|
|
||||||
media = InputMediaUploadedDocument(
|
media = InputMediaUploadedDocument(
|
||||||
file=file_handle,
|
file=file_handle,
|
||||||
@@ -173,11 +166,9 @@ class User:
|
|||||||
dialogs = self.client.get_dialogs(limit=30)
|
dialogs = self.client.get_dialogs(limit=30)
|
||||||
for dialog in dialogs:
|
for dialog in dialogs:
|
||||||
entity = dialog.entity
|
entity = dialog.entity
|
||||||
if isinstance(entity, User):
|
if isinstance(entity, User) \
|
||||||
continue
|
or (isinstance(entity, Chat) and entity.deactivated) \
|
||||||
elif isinstance(entity, Chat) and entity.deactivated:
|
or isinstance(entity, ChannelForbidden):
|
||||||
continue
|
|
||||||
elif isinstance(entity, ChannelForbidden):
|
|
||||||
continue
|
continue
|
||||||
portal = po.Portal.get_by_entity(entity)
|
portal = po.Portal.get_by_entity(entity)
|
||||||
portal.create_room(self, entity, invites=[self.mxid])
|
portal.create_room(self, entity, invites=[self.mxid])
|
||||||
|
|||||||
Reference in New Issue
Block a user