Repository navigation
Expand file tree
/
Copy pathoptionTemplates.py
More file actions
338 lines (257 loc) · 9.29 KB
/
Copy pathoptionTemplates.py
File metadata and controls
338 lines (257 loc) · 9.29 KB
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
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
import copy
from typing import Any
from bungio.models import DamageType
from naff import OptionTypes, SlashCommandChoice, slash_option
import ElevatorBot.core.destiny.stat as stats
from ElevatorBot.misc.formatting import capitalize_string
from ElevatorBot.static.destinyDates import expansion_dates, season_and_expansion_dates
from ElevatorBot.static.timezones import timezones_dict
from Shared.enums.destiny import DestinyWeaponTypeEnum, UsableDestinyActivityModeTypeEnum
def get_timezone_choices() -> list[SlashCommandChoice]:
return [
SlashCommandChoice(
name=timezone_name,
value=timezone_value,
)
for timezone_name, timezone_value in timezones_dict.items()
]
# ===================================================================================
# Decorators
def default_user_option(
description: str = "The user you want to look up",
required: bool = False,
) -> Any:
"""
Decorator that replaces @slash_option()
Call with `@default_user_option()`
"""
def wrapper(func):
return slash_option(name="user", description=description, opt_type=OptionTypes.USER, required=required)(func)
return wrapper
def lfg_event_id() -> Any:
"""
Decorator that replaces @slash_option()
Call with `@lfg_event_id()`
"""
def wrapper(func):
return slash_option(
name="lfg_id", description="The lfg event ID", opt_type=OptionTypes.INTEGER, required=True, min_value=0
)(func)
return wrapper
def default_class_option(description: str = "Restrict the class. Default: All classes") -> Any:
"""
Decorator that replaces @slash_option()
Call with `@default_class_option()`
"""
def wrapper(func):
return slash_option(
name="destiny_class",
description=description,
opt_type=OptionTypes.STRING,
required=False,
choices=[
SlashCommandChoice(name="Warlock", value="Warlock"),
SlashCommandChoice(name="Hunter", value="Hunter"),
SlashCommandChoice(name="Titan", value="Titan"),
],
)(func)
return wrapper
def default_mode_option(description: str = "Restrict the game mode. Default: All modes", required: bool = False) -> Any:
"""
Decorator that replaces @slash_option()
Call with `@default_mode_option()`
"""
def wrapper(func):
return slash_option(
name="mode",
description=description,
opt_type=OptionTypes.STRING,
required=required,
choices=[
SlashCommandChoice(
name=capitalize_string(activity_type.name),
value=str(activity_type.value),
)
for activity_type in UsableDestinyActivityModeTypeEnum
],
)(func)
return wrapper
def default_stat_option(pvp: bool = False) -> Any:
"""
Decorator that replaces @slash_option()
Call with `@default_stat_option()`
"""
def wrapper(func):
if pvp:
options = copy.deepcopy(stats.stat_translation)
options.pop("Activities Cleared")
options.pop("Public Events Completed")
options.pop("Heroic Public Events Completed")
else:
options = stats.stat_translation
return slash_option(
name="name",
description="The name of the leaderboard you want to see",
opt_type=OptionTypes.STRING,
required=True,
choices=[SlashCommandChoice(name=name, value=name) for name in options],
)(func)
return wrapper
def default_time_option(
name: str, description: str = "Format: `HH:MM DD/MM` - Restrict the time", required: bool = False
) -> Any:
"""
Decorator that replaces @slash_option()
Call with `@default_time_option()`
"""
def wrapper(func):
return slash_option(
name=name,
description=description,
opt_type=OptionTypes.STRING,
required=required,
)(func)
return wrapper
def default_expansion_option(
description: str = "Restrict the expansion. Default: All expansions", required: bool = False
) -> Any:
"""
Decorator that replaces @slash_option()
Call with `@default_expansion_option()`
The value is formatted:
"name: str|start_time_timestamp: int|end_time_timestamp: int"
"""
def wrapper(func):
return slash_option(
name="expansion",
description=description,
opt_type=OptionTypes.STRING,
required=required,
choices=[
SlashCommandChoice(
name=expansion.name,
value=(
f"{expansion.name}|{int(expansion.start.timestamp())}|{int(expansion_dates[(expansion_dates.index(expansion) + 1)].start.timestamp())}"
if expansion_dates.index(expansion) + 1 < len(expansion_dates)
else f"{expansion.name}|{int(expansion.start.timestamp())}|9999999999"
),
)
for expansion in expansion_dates
],
)(func)
return wrapper
def default_season_option(
description: str = "Restrict the season. Default: All seasons", required: bool = False
) -> Any:
"""
Decorator that replaces @slash_option()
Call with `@default_season_option()`
The value is formatted:
"name|start_time_timestamp|end_time_timestamp"
"""
def wrapper(func):
return slash_option(
name="season",
description=description,
opt_type=OptionTypes.STRING,
required=required,
choices=[
SlashCommandChoice(
name=season.name,
value=(
f"{season.name}|{int(season.start.timestamp())}|{int(season_and_expansion_dates[(season_and_expansion_dates.index(season) + 1)].start.timestamp())}"
if season_and_expansion_dates.index(season) + 1 < len(season_and_expansion_dates)
else f"{season.name}|{int(season.start.timestamp())}|9999999999"
),
)
for season in season_and_expansion_dates
],
)(func)
return wrapper
def default_weapon_type_option(
description: str = "Restrict the weapon type. Default: All types", required: bool = False
) -> Any:
"""
Decorator that replaces @slash_option()
Call with `@default_weapon_type_option()`
"""
def wrapper(func):
return slash_option(
name="weapon_type",
description=description,
opt_type=OptionTypes.INTEGER,
required=required,
choices=[
SlashCommandChoice(
name=capitalize_string(weapon_type.name),
value=weapon_type.value,
)
for weapon_type in DestinyWeaponTypeEnum
],
)(func)
return wrapper
def default_damage_type_option(
description: str = "Restrict the damage type. Default: All types", required: bool = False
) -> Any:
"""
Decorator that replaces @slash_option()
Call with `@default_damage_type_option()`
"""
def wrapper(func):
return slash_option(
name="damage_type",
description=description,
opt_type=OptionTypes.INTEGER,
required=required,
choices=[
SlashCommandChoice(
name=capitalize_string(damage_type.name),
value=damage_type.value,
)
for damage_type in DamageType
],
)(func)
return wrapper
def autocomplete_activity_option(
description: str = "Restrict the activity. Overwrites `mode`. Default: All activities", required: bool = False
) -> Any:
"""
Decorator that replaces @slash_option()
Call with `@autocomplete_activity_option()`
And register the autocomplete callback in setup()
"""
def wrapper(func):
name = "activity"
option = slash_option(
name=name, description=description, opt_type=OptionTypes.STRING, required=required, autocomplete=True
)(func)
return option
return wrapper
def autocomplete_weapon_option(description: str, required: bool = False) -> Any:
"""
Decorator that replaces @slash_option()
Call with `@autocomplete_weapon_option()`
And register the autocomplete callback in setup()
"""
def wrapper(func):
name = "weapon"
option = slash_option(
name=name, description=description, opt_type=OptionTypes.STRING, required=required, autocomplete=True
)(func)
return option
return wrapper
def autocomplete_lore_option(
description: str = "The name of item / card having the lore", required: bool = True
) -> Any:
"""
Decorator that replaces @slash_option()
Call with `@autocomplete_lore_option()`
And register the autocomplete callback in setup()
"""
def wrapper(func):
name = "name"
option = slash_option(
name=name, description=description, opt_type=OptionTypes.STRING, required=required, autocomplete=True
)(func)
return option
return wrapper