-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessages_logic_validator.py
95 lines (78 loc) · 3.71 KB
/
messages_logic_validator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# ruff: noqa: F403, F405, E402, E501, F401
from typing import TYPE_CHECKING
from rich import print
from rich.console import Console
from env import *
from notification_classes import *
from ccdexplorer_fundamentals.user_v2 import (
AccountForUser,
UserV2,
)
from .messages_definitions_validator import MessageValidator as MessageValidator
from .utils import Utils as Utils
if TYPE_CHECKING:
from bot import Bot
console = Console()
class ProcessValidator(MessageValidator, Utils):
def process_event_type_validator(
self, user: UserV2, notification_event: NotificationEvent
):
message_response = None
notification_services_to_send = None
event_type = EventTypeValidator(
**notification_event.event_type.model_dump()[
list(notification_event.event_type.model_fields_set)[0]
]
)
# We will use the first impacted address for determining whether a user
# should be notified.
account_index = (
notification_event.impacted_addresses[0].address.account.index
if notification_event.impacted_addresses[0].address.account
else None
)
if user.accounts.get(str(account_index)):
user_account: AccountForUser = user.accounts[str(account_index)]
if not user_account.validator_notification_preferences:
return None, None
if event_type.baker_configured or event_type.validator_configured:
notification_services_to_send = self.set_notification_service(
user_account.validator_notification_preferences.validator_configured
)
if any(notification_services_to_send.values()):
message_response = self.define_baker_configured_message(
event_type, notification_event, user
)
if event_type.delegation_configured:
notification_services_to_send = self.set_notification_service(
user_account.validator_notification_preferences.delegation_configured
)
if any(notification_services_to_send.values()):
message_response = self.define_delegation_configured_message(
event_type, notification_event, user
)
if event_type.payday_pool_reward:
notification_services_to_send = self.set_notification_service(
user_account.validator_notification_preferences.payday_pool_reward
)
if any(notification_services_to_send.values()):
message_response = self.define_payday_pool_reward_message(
notification_event, user
)
if event_type.block_validated:
notification_services_to_send = self.set_notification_service(
user_account.validator_notification_preferences.block_validated
)
if any(notification_services_to_send.values()):
message_response = self.define_block_baked_by_baker_message(
notification_event, user
)
if event_type.validator_running_behind:
notification_services_to_send = self.set_notification_service(
user_account.validator_notification_preferences.validator_running_behind
)
if any(notification_services_to_send.values()):
message_response = self.define_validator_running_behind_message(
notification_event, user
)
return message_response, notification_services_to_send