-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Check if user already exists in contacts list
- Loading branch information
Showing
3 changed files
with
39 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
[tool.poetry] | ||
name = "duck-duck-bot" | ||
version = "1.9.4" | ||
version = "1.9.5" | ||
description = "" | ||
authors = ["Eldos <[email protected]>"] | ||
readme = "README.md" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,25 @@ | ||
__all__ = ('can_create_new_contact', 'compute_new_contact_price') | ||
__all__ = ( | ||
'can_create_new_contact', | ||
'compute_new_contact_price', | ||
'is_user_already_contact', | ||
) | ||
|
||
from collections.abc import Iterable | ||
|
||
from models import Contact | ||
|
||
|
||
def can_create_new_contact(*, contact_price: int, balance: int) -> bool: | ||
return balance >= contact_price | ||
|
||
|
||
def compute_new_contact_price(contacts_count: int) -> int: | ||
return 100 * 2 ** contacts_count | ||
return 100 * (2 + contacts_count) // 2 * (contacts_count + 1) | ||
|
||
|
||
def is_user_already_contact( | ||
*, | ||
user_id: int, | ||
contacts: Iterable[Contact], | ||
) -> bool: | ||
return any(contact.to_user.id == user_id for contact in contacts) |