~homeworkprod/byceps

ref: 87b31ba68669551f699c7d12cf18401663b2d043 byceps/byceps/announce/text_assembly/tourney.py -rw-r--r-- 4.1 KiB
87b31ba6 — Jochen Kupperschmidt Fix type errors 1 year, 3 months ago
                                                                                
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
"""
byceps.announce.text_assembly.tourney
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Announce tourney events.

:Copyright: 2006-2021 Jochen Kupperschmidt
:License: Revised BSD (see `LICENSE` file for details)
"""

from typing import Optional

from ...events.tourney import (
    TourneyStarted,
    TourneyPaused,
    TourneyCanceled,
    TourneyFinished,
    TourneyMatchReady,
    TourneyMatchReset,
    TourneyMatchScoreSubmitted,
    TourneyMatchScoreConfirmed,
    TourneyMatchScoreRandomized,
    TourneyParticipantReady,
    TourneyParticipantEliminated,
    TourneyParticipantWarned,
    TourneyParticipantDisqualified,
)


# -------------------------------------------------------------------- #
# tourney


def assemble_text_for_tourney_started(event: TourneyStarted) -> str:
    return f'Das Turnier {event.tourney_title} wurde gestartet.'


def assemble_text_for_tourney_paused(event: TourneyPaused) -> str:
    return f'Das Turnier {event.tourney_title} wurde unterbrochen.'


def assemble_text_for_tourney_canceled(event: TourneyCanceled) -> str:
    return f'Das Turnier {event.tourney_title} wurde abgesagt.'


def assemble_text_for_tourney_finished(event: TourneyFinished) -> str:
    return f'Das Turnier {event.tourney_title} wurde beendet.'


# -------------------------------------------------------------------- #
# match


def assemble_text_for_match_ready(event: TourneyMatchReady) -> str:
    return (
        f'Das Match {get_match_label(event)} im Turnier {event.tourney_title} '
        f'kann gespielt werden.'
    )


def assemble_text_for_match_reset(event: TourneyMatchReset) -> str:
    return (
        f'Das Match {get_match_label(event)} im Turnier {event.tourney_title} '
        f'wurde zurückgesetzt.'
    )


def assemble_text_for_match_score_submitted(
    event: TourneyMatchScoreSubmitted,
) -> str:
    return (
        f'Für das Match {get_match_label(event)} '
        f'im Turnier {event.tourney_title} '
        f'wurde ein Ergebnis eingetragen.'
    )


def assemble_text_for_match_score_confirmed(
    event: TourneyMatchScoreConfirmed,
) -> str:
    return (
        f'Für das Match {get_match_label(event)} '
        f'im Turnier {event.tourney_title} '
        f'wurde das eingetragene Ergebnis bestätigt.'
    )


def assemble_text_for_match_score_randomized(
    event: TourneyMatchScoreRandomized,
) -> str:
    return (
        f'Für das Match {get_match_label(event)} '
        f'im Turnier {event.tourney_title} '
        f'wurde ein zufälliges Ergebnis eingetragen.'
    )


# -------------------------------------------------------------------- #
# participant


def assemble_text_for_participant_ready(event: TourneyParticipantReady) -> str:
    return (
        f'"{event.participant_name}" im Turnier {event.tourney_title} '
        'ist spielbereit.'
    )


def assemble_text_for_participant_eliminated(
    event: TourneyParticipantEliminated,
) -> str:
    return (
        f'"{event.participant_name}" scheidet aus dem Turnier '
        f'{event.tourney_title} aus.'
    )


def assemble_text_for_participant_warned(
    event: TourneyParticipantWarned,
) -> str:
    return (
        f'"{event.participant_name}" im Turnier {event.tourney_title} '
        f'hat eine gelbe Karte \x038,8 \x03 erhalten.'
    )


def assemble_text_for_participant_disqualified(
    event: TourneyParticipantDisqualified,
) -> str:
    return (
        f'"{event.participant_name}" im Turnier {event.tourney_title} '
        f'wurde disqualifiziert \x034,4 \x03.'
    )


# -------------------------------------------------------------------- #
# helpers


def get_match_label(match_event) -> str:
    participant1_label = get_participant_label(
        match_event.participant1_id, match_event.participant1_name
    )
    participant2_label = get_participant_label(
        match_event.participant2_id, match_event.participant2_name
    )

    return f'"{participant1_label}" vs. "{participant2_label}"'


def get_participant_label(
    participant_id: Optional[str], participant_name: Optional[str]
) -> str:
    if participant_id is None:
        return 'freilos'

    return participant_name