Add command to get invite link. Fixes #32

This commit is contained in:
Tulir Asokan
2018-01-29 22:40:32 +02:00
parent 6c9b31b0e9
commit 4593e1c857
3 changed files with 46 additions and 9 deletions
+18 -2
View File
@@ -15,9 +15,10 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from telethon.tl.functions.messages import (GetFullChatRequest, EditChatAdminRequest,
CreateChatRequest, AddChatUserRequest)
CreateChatRequest, AddChatUserRequest,
ExportChatInviteRequest)
from telethon.tl.functions.channels import (GetParticipantsRequest, CreateChannelRequest,
InviteToChannelRequest)
InviteToChannelRequest, ExportInviteRequest)
from telethon.errors.rpc_error_list import ChatAdminRequiredError, LocationInvalidError
from telethon.tl.types import *
from PIL import Image
@@ -236,6 +237,21 @@ class Portal:
elif self.peer_type == "user":
return [entity], []
def get_invite_link(self, user):
if self.peer_type == "user":
raise ValueError("You can't invite users to private chats.")
elif self.peer_type == "chat":
link = user.client(ExportChatInviteRequest(chat_id=self.tgid))
elif self.peer_type == "channel":
link = user.client(ExportInviteRequest(channel=user.client.get_input_entity(self.peer)))
else:
raise ValueError(f"Invalid peer type '{self.peer_type}' for invite link.")
if isinstance(link, ChatInviteEmpty):
raise ValueError("Failed to get invite link.")
return link.link
# endregion
# region Matrix event handling