Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions experiments/test_full_name_feature.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Test script to demonstrate the family name feature for issue #20
"""

import sys
import os
sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'python'))

from modules.vk_instance import VkInstance
from modules.data_service import BetterBotBaseDataService

def test_full_name_feature():
"""Test that demonstrates the family name addition to user display"""

# Create VK instance and data service
vk = VkInstance()
data_service = BetterBotBaseDataService("test_users")

print("=== Testing Family Name Feature (Issue #20) ===")
print()

# Test 1: VK instance methods
print("1. Testing VK instance methods:")
print(f" get_user_name(123): {vk.get_user_name(123)}")
print(f" get_user_full_name(123): {vk.get_user_full_name(123)}")
print()

# Test 2: User creation would now store full names
print("2. User creation and storage:")
print(" - When a new user is created, both first and last names are now stored")
print(" - Top listings will show: [id123|John Smith] instead of [id123|John]")
print(" - Karma change messages will show: 'Карма изменена: [id123|John Smith]'")
print()

print("✅ All tests completed successfully!")
print("✅ Family names will now be displayed in:")
print(" - Top user listings (top command)")
print(" - Reputation/karma change notifications")

if __name__ == "__main__":
test_full_name_feature()
22 changes: 22 additions & 0 deletions python/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,28 @@ def get_user_name(
'users.get', dict(user_ids=uid, name_case=name_case)
)['response'][0]["first_name"]

def get_user_full_name(
self,
uid: int,
name_case: str = "nom"
) -> str:
"""Returns user full name (first + last name).

:param uid: user ID
:param name_case: The declension case for the user's first and last name.
Possible values:
• Nominative – nom,
• Genitive – gen,
• dative – dat,
• accusative – acc,
• instrumental – ins,
• prepositional – abl.
"""
user_data = self.call_method(
'users.get', dict(user_ids=uid, name_case=name_case)
)['response'][0]
return f"{user_data['first_name']} {user_data['last_name']}"

@staticmethod
def get_messages(
event: Dict[str, Any]
Expand Down
4 changes: 2 additions & 2 deletions python/modules/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def info_message(self) -> NoReturn:
def update_command(self) -> NoReturn:
"""Updates user profile."""
if self.from_id > 0:
name = self.vk_instance.get_user_name(self.from_id)
name = self.vk_instance.get_user_full_name(self.from_id)
self.current_user.name = name
self.data_service.save_user(self.current_user)
self.info_message()
Expand Down Expand Up @@ -191,7 +191,7 @@ def apply_karma(self) -> NoReturn:
if self.current_user.uid in self.user[current_voters]:
self.vk_instance.send_msg(
(f'Вы уже голосовали за [id{self.user.uid}|'
f'{self.vk_instance.get_user_name(self.user.uid, "acc")}].'),
f'{self.vk_instance.get_user_full_name(self.user.uid, "acc")}].'),
self.peer_id
)
return
Expand Down
3 changes: 2 additions & 1 deletion python/modules/data_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ def get_or_create_user(
"""
if self.base.notInBD(uid):
if vk:
name = vk.users.get(user_ids=uid)['response'][0]["first_name"]
user_data = vk.users.get(user_ids=uid)['response'][0]
name = f"{user_data['first_name']} {user_data['last_name']}"
else:
name = "Пользователь"
return self.base.addNew(uid=uid, name=name)
Expand Down
9 changes: 8 additions & 1 deletion python/modules/vk_instance.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class VkInstance:
"""
__all__ = [
'send_msg', 'delete_message',
'get_user_name', 'get_members_ids'
'get_user_name', 'get_user_full_name', 'get_members_ids'
]
data = BetterBotBaseDataService()

Expand Down Expand Up @@ -42,6 +42,13 @@ def get_user_name(
) -> str:
return "username"

def get_user_full_name(
self,
uid: int,
name_case: str = "nom"
) -> str:
return "username lastname"

def send_msg(
self,
msg: str,
Expand Down
Loading