123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- from uuid import uuid4
- from collections import namedtuple
- from telethon.utils import get_display_name
- Command = namedtuple(
- 'Command',
- 'name argc args args_string'
- )
- 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(
- name=command,
- argc=argc,
- args=args,
- args_string=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}'
|