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
2 changes: 2 additions & 0 deletions python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
| ⭐ | -= [ЯЗЫК] | Убрать язык программирования из своего профиля. |
| ⭐ | += [ССЫЛКА] | Добавить ссылку на профиль github в свой профиль. |
| ⭐ | -= [ССЫЛКА] | Убрать ссылку на профиль github из своего профиля. |
| ⭐ | copy languages | Скопировать языки программирования из профиля другого пользователя (требует перешлите сообщение пользователя). |
| ⭐ | what is [] | Искать в википедии |

Так же возможно использование альтернативных названий команд.
Expand All @@ -44,6 +45,7 @@
| karma | карма|
| info | инфо |
| update | обновить |
| copy languages | копировать языки |
| what is | что такое |

![image](https://user-images.githubusercontent.com/1431904/146941784-670f052c-7b4e-4367-89c5-00466dfc92c9.png)
Expand Down
3 changes: 2 additions & 1 deletion python/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ def __init__(
(patterns.WHAT_IS, self.commands.what_is),
(patterns.WHAT_MEAN, self.commands.what_is),
(patterns.APPLY_KARMA, self.commands.apply_karma),
(patterns.GITHUB_COPILOT, self.commands.github_copilot)
(patterns.GITHUB_COPILOT, self.commands.github_copilot),
(patterns.COPY_LANGUAGES, self.commands.copy_languages)
)

def message_new(
Expand Down
41 changes: 41 additions & 0 deletions python/modules/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,47 @@ def github_copilot(self) -> NoReturn:
f'Пожалуйста, подождите {round(config.GITHUB_COPILOT_TIMEOUT - (now - self.now))} секунд', self.peer_id
)

def copy_languages(self) -> NoReturn:
"""Copy programming languages from another user's profile"""
if not self.user or self.user.uid == self.from_id:
self.vk_instance.send_msg(
'Перешлите сообщение пользователя, чьи языки программирования вы хотите скопировать.',
self.peer_id
)
return

source_languages = self.data_service.get_user_sorted_programming_languages(self.user)
if not source_languages:
self.vk_instance.send_msg(
f'У [id{self.user.uid}|{self.vk_instance.get_user_name(self.user.uid)}] не указано языков программирования.',
self.peer_id
)
return

# Copy languages to current user
current_languages = self.current_user.programming_languages
new_languages = list(set(current_languages + source_languages))
self.current_user.programming_languages = new_languages
self.data_service.save_user(self.current_user)

# Send confirmation message
copied_count = len(source_languages)
total_count = len(new_languages)
already_had = len(current_languages)
new_added = total_count - already_had

if new_added == 0:
self.vk_instance.send_msg(
f'Все языки программирования от [id{self.user.uid}|{self.vk_instance.get_user_name(self.user.uid)}] у вас уже есть.',
self.peer_id
)
else:
self.vk_instance.send_msg(
f'Скопировано {new_added} новых языков программирования от [id{self.user.uid}|{self.vk_instance.get_user_name(self.user.uid)}]. '
f'У вас теперь {total_count} языков программирования.',
self.peer_id
)

def match_command(
self,
pattern: Pattern
Expand Down
3 changes: 3 additions & 0 deletions python/patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,6 @@
GITHUB_COPILOT = recompile(
r'\A\s*(code|код)\s+(?P<lang>(' + COPILOT_LANGUAGES +
r'))(?P<text>[\S\s]+)\Z', IGNORECASE)

COPY_LANGUAGES = recompile(
r'\A\s*(copy|копировать)\s+(languages|языки)\s*\Z', IGNORECASE)
Loading