This repository has been archived by the owner on Apr 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpaimon_gui.py
234 lines (204 loc) · 6.98 KB
/
paimon_gui.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
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# SPDX-License-Identifier: MIT
# Copyright (c) 2021-2024 scmanjarrez. All rights reserved.
# This work is licensed under the terms of the MIT license.
import calendar
import datetime
from typing import List, Tuple
import database as db
import utils as ut
from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Update
from telegram.error import BadRequest
async def _answer(update: Update, msg: str = None) -> None:
if update.callback_query is not None:
try:
await update.callback_query.answer(msg)
except BadRequest:
pass
def button(buttons: List[Tuple[str, str]]):
return [InlineKeyboardButton(bt[0], callback_data=bt[1]) for bt in buttons]
async def main_menu(update: Update) -> None:
await _answer(update)
kb = [
button([("🗒 Daily Notes 🗒", "notes_menu")]),
button([("📖 Traveler's Diary 📖", "diary_month_menu")]),
button([("✨ Abyss ✨", "abyss_seasons_menu")]),
button([("⚙️ Notifications ⚙️", "notifications_menu")]),
]
resp = ut.send
if update.callback_query is not None:
resp = ut.edit
await resp(update, "Menu", reply_markup=InlineKeyboardMarkup(kb))
async def notes_menu(update: Update, context: ut.Context) -> None:
ut.autoupdate_notes(update, context)
msg, notes_data = await ut.notes(ut.uid(update))
await _answer(update)
ut.notifier_resin(update, context, notes_data.resin_time)
ut.notifier_teapot(update, context, notes_data)
ut.notifier_parametric(update, context, notes_data.parametric_time)
ut.notifier_expedition(update, context, notes_data.expeditions_max)
kb = [
button([("🔃 Update 🔃", "notes_menu")]),
button([("« Back to Menu", "main_menu")]),
]
await ut.edit(update, msg, InlineKeyboardMarkup(kb))
async def update_notes(
update: Update, context: ut.Context, data: Tuple[str, ut.Notes] = None
) -> None:
if data is None:
msg, notes_data = await ut.notes(ut.uid(update))
else:
msg, notes_data = data
ut.notifier_resin(update, context, notes_data.resin_time)
ut.notifier_teapot(update, context, notes_data)
ut.notifier_parametric(update, context, notes_data.parametric_time)
ut.notifier_expedition(update, context, notes_data.expeditions_max)
kb = [
button([("🔃 Update 🔃", "notes_menu")]),
button([("« Back to Menu", "main_menu")]),
]
await ut.edit(update, msg, InlineKeyboardMarkup(kb))
async def diary_month_menu(update: Update) -> None:
await _answer(update)
month = datetime.datetime.now().month
kb = [
button(
[
(calendar.month_name[month], f"diary_menu_{month}"),
(calendar.month_name[month - 1], f"diary_menu_{month-1}"),
(calendar.month_name[month - 2], f"diary_menu_{month-2}"),
]
),
button([("« Back to Menu", "main_menu")]),
]
await ut.edit(update, "Traveler's Diary", InlineKeyboardMarkup(kb))
async def diary_menu(update: Update, month: int) -> None:
msg = await ut.diary(ut.uid(update), month)
await _answer(update)
kb = [
button(
[
("« Back to Diary", "diary_month_menu"),
("« Back to Menu", "main_menu"),
]
)
]
await ut.edit(update, msg, InlineKeyboardMarkup(kb))
async def abyss_seasons_menu(update: Update) -> None:
await _answer(update)
kb = [
button(
[
("Current", "abyss_floors_menu"),
("Previous", "abyss_floors_menu_previous"),
]
),
button([("« Back to Menu", "main_menu")]),
]
if update.callback_query is not None:
resp = ut.edit
await resp(update, "Abyss Seasons", reply_markup=InlineKeyboardMarkup(kb))
async def abyss_floors_menu(update: Update, previous: bool) -> None:
await _answer(update)
suffix = ""
season = "current"
if previous:
suffix = "_previous"
season = "previous"
kb = [
button([("All", f"abyss_menu{suffix}_all")]),
button(
[
("9", f"abyss_menu{suffix}_9"),
("10", f"abyss_menu{suffix}_10"),
("11", f"abyss_menu{suffix}_11"),
("12", f"abyss_menu{suffix}_12"),
]
),
button(
[
("« Back to Seasons", "abyss_seasons_menu"),
("« Back to Menu", "main_menu"),
]
),
]
if update.callback_query is not None:
resp = ut.edit
await resp(
update,
f"Abyss Floors ({season})",
reply_markup=InlineKeyboardMarkup(kb),
)
async def abyss_menu(update: Update, previous: bool, floor: str) -> None:
msg = await ut.abyss(ut.uid(update), previous, floor)
await _answer(update)
suffix = ""
if previous:
suffix = "_previous"
kb = [
button([("🔃 Update 🔃", f"abyss_menu{suffix}_{floor}")]),
button(
[
("« Back to Floors", f"abyss_floors_menu{suffix}"),
("« Back to Seasons", "abyss_seasons_menu"),
("« Back to Menu", "main_menu"),
]
),
]
await ut.edit(update, msg, InlineKeyboardMarkup(kb))
def notification_icon(value: int) -> str:
return "🔔" if value == 1 else "🔕"
async def notifications_menu(update: Update) -> None:
await _answer(update)
uid = ut.uid(update)
kb = [
button(
[
(
f"Resin ({db.resin(uid)}): "
f"{notification_icon(db.resin_warn(uid))}",
"notification_toggle_resin",
)
]
),
button(
[
(
f"Teapot Currency ({db.teapot(uid)}): "
f"{notification_icon(db.teapot_warn(uid))}",
"notification_toggle_teapot",
)
]
),
button(
[
(
f"Pt.Transformer: "
f"{notification_icon(db.parametric_warn(uid))}",
"notification_toggle_parametric",
)
]
),
button(
[
(
f"Expeditions: "
f"{notification_icon(db.expedition_warn(uid))}",
"notification_toggle_expedition",
)
]
),
button([("« Back to Menu", "main_menu")]),
]
await ut.edit(update, "Notifications", InlineKeyboardMarkup(kb))
async def notification_toggle(update: Update, toggle: str) -> None:
await _answer(update)
uid = ut.uid(update)
if toggle == "resin":
db.toggle_resin_warn(uid)
elif toggle == "teapot":
db.toggle_teapot_warn(uid)
elif toggle == "parametric":
db.toggle_parametric_warn(uid)
elif toggle == "expedition":
db.toggle_expedition_warn(uid)
await notifications_menu(update)