[документация]defsplit_text(text:str,max_length:int=4096)->list[str]:"""Split long text into parts for sending. VK API limits messages to 4096 characters. Splits by lines and words without breaking words. """iflen(text)<=max_length:return[text]parts=[]current=""forlineintext.split("\n"):iflen(current)+len(line)+1<=max_length:current=f"{current}\n{line}"ifcurrentelselineelse:ifcurrent:parts.append(current)iflen(line)>max_length:words=line.split(" ")current=""forwordinwords:iflen(current)+len(word)+1<=max_length:current=f"{current}{word}"ifcurrentelsewordelse:ifcurrent:parts.append(current)iflen(word)>max_length:parts.extend(word[i:i+max_length]foriinrange(0,len(word),max_length))current=""else:current=wordelse:current=lineifcurrent:parts.append(current)returnparts
[документация]defcreate_link(text:str,url:str)->str:"""Build a VK-formatted link: ``[url|text]``."""returnf"[{url}|{text}]"
[документация]defformat_time(timestamp:int)->str:"""Format a Unix timestamp to a human-readable string."""returndatetime.fromtimestamp(timestamp,tz=UTC).strftime("%d.%m.%Y %H:%M")