@@ -14,7 +14,6 @@
|
|||||||
# You should have received a copy of the GNU Affero General Public License
|
# You should have received a copy of the GNU Affero General Public License
|
||||||
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
from typing import List, Optional, Tuple, cast
|
from typing import List, Optional, Tuple, cast
|
||||||
import logging
|
|
||||||
import codecs
|
import codecs
|
||||||
import base64
|
import base64
|
||||||
import re
|
import re
|
||||||
@@ -119,21 +118,21 @@ async def pm(evt: CommandEvent) -> EventID:
|
|||||||
f"{pu.Puppet.get_displayname(user, False)}")
|
f"{pu.Puppet.get_displayname(user, False)}")
|
||||||
|
|
||||||
|
|
||||||
async def _join(evt: CommandEvent, arg: str) -> Tuple[Optional[TypeUpdates], Optional[EventID]]:
|
async def _join(evt: CommandEvent, identifier: str, link_type: str
|
||||||
if arg.startswith("joinchat/"):
|
) -> Tuple[Optional[TypeUpdates], Optional[EventID]]:
|
||||||
invite_hash = arg[len("joinchat/"):]
|
if link_type == "joinchat":
|
||||||
try:
|
try:
|
||||||
await evt.sender.client(CheckChatInviteRequest(invite_hash))
|
await evt.sender.client(CheckChatInviteRequest(identifier))
|
||||||
except InviteHashInvalidError:
|
except InviteHashInvalidError:
|
||||||
return None, await evt.reply("Invalid invite link.")
|
return None, await evt.reply("Invalid invite link.")
|
||||||
except InviteHashExpiredError:
|
except InviteHashExpiredError:
|
||||||
return None, await evt.reply("Invite link expired.")
|
return None, await evt.reply("Invite link expired.")
|
||||||
try:
|
try:
|
||||||
return (await evt.sender.client(ImportChatInviteRequest(invite_hash))), None
|
return (await evt.sender.client(ImportChatInviteRequest(identifier))), None
|
||||||
except UserAlreadyParticipantError:
|
except UserAlreadyParticipantError:
|
||||||
return None, await evt.reply("You are already in that chat.")
|
return None, await evt.reply("You are already in that chat.")
|
||||||
else:
|
else:
|
||||||
channel = await evt.sender.client.get_entity(arg)
|
channel = await evt.sender.client.get_entity(identifier)
|
||||||
if not channel:
|
if not channel:
|
||||||
return None, await evt.reply("Channel/supergroup not found.")
|
return None, await evt.reply("Channel/supergroup not found.")
|
||||||
return await evt.sender.client(JoinChannelRequest(channel)), None
|
return await evt.sender.client(JoinChannelRequest(channel)), None
|
||||||
@@ -146,12 +145,18 @@ async def join(evt: CommandEvent) -> Optional[EventID]:
|
|||||||
if len(evt.args) == 0:
|
if len(evt.args) == 0:
|
||||||
return await evt.reply("**Usage:** `$cmdprefix+sp join <invite link>`")
|
return await evt.reply("**Usage:** `$cmdprefix+sp join <invite link>`")
|
||||||
|
|
||||||
regex = re.compile(r"(?:https?://)?t(?:elegram)?\.(?:dog|me)(?:joinchat/)?/(.+)")
|
regex = re.compile(r"(?:https?://)?t(?:elegram)?\.(?:dog|me)"
|
||||||
|
r"(?:/(?P<type>joinchat|s))?/(?P<id>[^/]+)/?", flags=re.IGNORECASE)
|
||||||
arg = regex.match(evt.args[0])
|
arg = regex.match(evt.args[0])
|
||||||
if not arg:
|
if not arg:
|
||||||
return await evt.reply("That doesn't look like a Telegram invite link.")
|
return await evt.reply("That doesn't look like a Telegram invite link.")
|
||||||
|
|
||||||
updates, _ = await _join(evt, arg.group(1))
|
data = arg.groupdict()
|
||||||
|
identifier = data["id"]
|
||||||
|
link_type = data["type"]
|
||||||
|
if link_type:
|
||||||
|
link_type = link_type.lower()
|
||||||
|
updates, _ = await _join(evt, identifier, link_type)
|
||||||
if not updates:
|
if not updates:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
@@ -165,9 +170,8 @@ async def join(evt: CommandEvent) -> Optional[EventID]:
|
|||||||
try:
|
try:
|
||||||
await portal.create_matrix_room(evt.sender, chat, [evt.sender.mxid])
|
await portal.create_matrix_room(evt.sender, chat, [evt.sender.mxid])
|
||||||
except ChatIdInvalidError as e:
|
except ChatIdInvalidError as e:
|
||||||
logging.getLogger("mau.commands").trace("ChatIdInvalidError while creating portal "
|
evt.log.trace("ChatIdInvalidError while creating portal from !tg join command: %s",
|
||||||
"from !tg join command: %s",
|
updates.stringify())
|
||||||
updates.stringify())
|
|
||||||
raise e
|
raise e
|
||||||
return await evt.reply(f"Created room for {portal.title}")
|
return await evt.reply(f"Created room for {portal.title}")
|
||||||
return None
|
return None
|
||||||
|
|||||||
Reference in New Issue
Block a user