feat: add cat identity rename flow

This commit is contained in:
nyan404 committed 2026-10-13 00:30:36 +03:00
1 parent a15c22b4a2
commit 546fa37fce
10 files changed
+203 -14

No files matched your search

+35
View File
@@ -156,6 +156,41 @@ class IdentityDirectory:
self._index(identity)
return identity
def rename_existing(self, *, character_id: int, new_name: str) -> tuple[Identity, Identity]:
"""Переименовывает только уже существующую связку и её профили."""
current = self.resolve(character_id=character_id)
if current is None:
raise KeyError(f"Связка для ID {character_id} не найдена")
updated = Identity(name=new_name, character_id=character_id)
if self.database_url.startswith(("postgres://", "postgresql://")):
with self._psycopg.connect(self.database_url) as connection:
connection.execute(
"UPDATE identities SET name = %s WHERE character_id = %s",
(updated.name, updated.character_id),
)
connection.execute(
"UPDATE profiles SET name = %s WHERE character_id = %s",
(updated.name, updated.character_id),
)
elif self.db_path:
with sqlite3.connect(self.db_path) as connection:
connection.execute(
"UPDATE identities SET name = ? WHERE character_id = ?",
(updated.name, updated.character_id),
)
connection.execute(
"UPDATE profiles SET name = ? WHERE character_id = ?",
(updated.name, updated.character_id),
)
old_key = current.name.casefold()
if self._by_name.get(old_key) == current:
self._by_name.pop(old_key, None)
self._index(updated)
for actor_id, profile in tuple(self._profiles.items()):
if profile.character_id == character_id:
self._profiles[actor_id] = updated
return current, updated
def remember_profile(self, *, actor_id: int, name: str, character_id: int) -> Identity:
"""
Сохраняет профиль пользователя (кто — кто).