12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- from uuid import uuid4
- from telethon.utils import get_display_name
- def parse_command(text):
- text = text.strip()
- if not text.startswith('/'):
- raise ValueError
- text = text.split(' ')
- if len(text) < 1:
- raise ValueError
- command = text[0][1:].lower()
- if '@' in command:
- command = command.split('@')
- command = command[0]
- args = text[1:]
- argc = len(args)
- args_string = ' '.join(args)
- return (command, argc, args, args_string)
- def get_link_to_user(user):
- full_name = get_display_name(user)
- if not full_name:
- full_name = user.username
-
- if not full_name:
- full_name = '?'
- if user.username:
- return f'[{full_name}](@{user.username})'
- return full_name
- def is_valid_name(name):
- return name.isidentifier()
- def make_temporary_filename(ext):
- uid = uuid4().hex
- return f'tmp_{uid}.{ext}'
|