This repository was archived by the owner on Mar 5, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathtrainer.py
More file actions
339 lines (291 loc) · 10.8 KB
/
trainer.py
File metadata and controls
339 lines (291 loc) · 10.8 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
339
from classes import DataDAO
TRAINER_JSON_FILE = "trainers.json"
class TrainerDAO(DataDAO):
"""
Accesses, modifies and returns the PokeBot JSON data
"""
BRONZE = "bronze"
SILVER = "silver"
GOLD = "gold"
EGG_COUNT = "egg_count"
EGG_MANAPHY_COUNT = "egg_manaphy_count"
PINVENTORY = "pinventory"
LAST_CATCH_TIME = "last_catch_time"
LAST_DAILY_REDEEMED_TIME = "last_daily_redeemed_time"
LOOTBOX = "lootbox"
DAILY_TOKENS = "daily_tokens"
LEGENDARY_PKMN_COUNT = "legendary_pkmn_count"
SHINY_PKMN_COUNT = "shiny_pkmn_count"
TOTAL_PKMN_COUNT = "total_pkmn_count"
ULTRA_BEASTS_COUNT = "ultra_beasts_count"
def __init__(self, filename=TRAINER_JSON_FILE):
if (self.__initialized):
return
self.__initialized = True
super().__init__(filename)
def __new__(cls):
if not hasattr(cls, 'instance'):
cls.instance = super(TrainerDAO, cls).__new__(cls)
cls.__initialized = False
return cls.instance
return cls.instance
def is_existing_trainer(self, user_id: str) -> bool:
"""
Checks if trainer exists and returns True if so,
otherwise False
"""
return bool(self.data.get(user_id, False))
def get_pokemon_inventory(self, user_id: str) -> dict:
"""
Gets the inventory of pokemon from the trainer
"""
return self.data[user_id][self.PINVENTORY]
def get_pokemon_quantity(self, user_id: str, pkmn_name: str) -> int:
"""
Gets the number of a specific pokemon from the inventory
"""
if pkmn_name not in self.data[user_id][self.PINVENTORY]:
return 0
return self.data[user_id][self.PINVENTORY][pkmn_name]
def increment_pokemon_quantity(self, user_id: str, pkmn_name: str) -> None:
"""
Increments the quantity of a specific trainer's pokemon
within their inventory
"""
pinventory = self.get_pokemon_inventory(user_id)
if pkmn_name not in pinventory:
self.set_pokemon_quantity(user_id, pkmn_name, 1)
else:
self.data[user_id][self.PINVENTORY][pkmn_name] += 1
def set_pokemon_quantity(self, user_id: str, pkmn_name: str, quantity: int) -> None:
"""
Sets the quantity of a specific trainer's pokemon
within their inventory
"""
if quantity <= 0:
del self.data[user_id][self.PINVENTORY][pkmn_name]
else:
self.data[user_id][self.PINVENTORY][pkmn_name] = quantity
def get_last_catch_time(self, user_id: str) -> float:
"""
Gets the last catch time of the trainer
"""
if not self.is_existing_trainer(user_id):
return 0
return self.data[user_id][self.LAST_CATCH_TIME]
def get_last_daily_redeemed_time(self, user_id: str) -> float:
"""
Gets the last daily redeemed time of the trainer
"""
if user_id not in self.data:
return 0
return self.data[user_id][self.LAST_DAILY_REDEEMED_TIME]
def get_lootbox_inventory(self, user_id: str) -> dict:
"""
Gets the inventory of lootboxes that the trainer has
"""
return self.data[user_id][self.LOOTBOX]
def increment_lootbox_quantity(self, user_id: str, lootbox) -> None:
"""
Increments the quantity of the lootbox specified in the trainer's
inventory
"""
self.data[user_id][self.LOOTBOX][lootbox] += 1
def get_bronze_lootbox_quantity(self, user_id: str) -> dict:
"""
Gets the quantity of bronze lootboxes that the trainer has
"""
return self.data[user_id][self.LOOTBOX][self.BRONZE]
def get_silver_lootbox_quantity(self, user_id: str) -> dict:
"""
Gets the quantity of silver lootboxes that the trainer has
"""
return self.data[user_id][self.LOOTBOX][self.SILVER]
def get_gold_lootbox_quantity(self, user_id: str) -> dict:
"""
Gets the quantity of gold lootboxes that the trainer has
"""
return self.data[user_id][self.LOOTBOX][self.GOLD]
def get_daily_tokens(self, user_id: str) -> int:
"""
Gets the list of daily tokens that the trainer has
"""
if user_id not in self.data:
return 0
return self.data[user_id][self.DAILY_TOKENS]
def set_last_catch_time(self, user_id: str, time: float) -> None:
"""
Sets the trainer's last daily redeemed time
"""
self.data[user_id][self.LAST_CATCH_TIME] = time
def set_last_daily_redeemed_time(self, user_id: str, time: float) -> None:
"""
Sets the trainer's last daily redeemed time
"""
self.data[user_id][self.LAST_DAILY_REDEEMED_TIME] = time
def set_lootbox_inventory(self, user_id: str, lootbox_tier_name: str, quantity: int) -> None:
"""
Sets the quantity of a specific lootbox tier within
the trainer's inventory
"""
self.data[user_id][self.LOOTBOX][lootbox_tier_name] = quantity
def set_daily_tokens(self, user_id: str, quantity: int) -> None:
"""
Sets the trainer's daily token amount
"""
self.data[user_id][self.DAILY_TOKENS] = quantity
def generate_new_trainer(self, user_id: str) -> None:
"""
Generates a new trainer in the database
"""
self.data[user_id] = {}
self.data[user_id][self.PINVENTORY] = {}
self.data[user_id][self.LOOTBOX] = {
"bronze": 0,
"silver": 0,
"gold": 0,
}
self.data[user_id][self.LAST_CATCH_TIME] = 0
self.data[user_id][self.LAST_DAILY_REDEEMED_TIME] = 0
self.data[user_id][self.DAILY_TOKENS] = 0
self.data[user_id][self.LEGENDARY_PKMN_COUNT] = 0
self.data[user_id][self.SHINY_PKMN_COUNT] = 0
self.data[user_id][self.TOTAL_PKMN_COUNT] = 0
self.data[user_id][self.ULTRA_BEASTS_COUNT] = 0
self.data[user_id][self.EGG_COUNT] = 0
self.data[user_id][self.EGG_MANAPHY_COUNT] = 0
def get_total_pokemon_caught(self) -> int:
"""
Gets the total amount of pokemon caught across
all trainers
"""
total_pokemon_caught = 0
for trainer in self.data:
total_pokemon_caught += self.data[trainer][self.TOTAL_PKMN_COUNT]
return total_pokemon_caught
def get_legendary_pkmn_count(self, user_id: str) -> int:
"""
Gets the legendary pokemon count
"""
return self.data[user_id][self.LEGENDARY_PKMN_COUNT]
def increment_legendary_pkmn_count(self, user_id: str) -> None:
"""
Increments the trainer's count for legendary pokemon
"""
self.data[user_id][self.LEGENDARY_PKMN_COUNT] += 1
def decrease_legendary_pkmn_count(
self,
user_id: str,
quantity: int
) -> None:
"""
Decreases the legendary pokemon count by a specified amount
"""
self.data[user_id][self.LEGENDARY_PKMN_COUNT] -= quantity
def get_shiny_pkmn_count(self, user_id: str) -> int:
"""
Gets the shiny pokemon count
"""
return self.data[user_id][self.SHINY_PKMN_COUNT]
def increment_shiny_pkmn_count(self, user_id: str) -> None:
"""
Increments the trainer's count for shiny pokemon
"""
self.data[user_id][self.SHINY_PKMN_COUNT] += 1
def decrease_shiny_pkmn_count(
self,
user_id: str,
quantity: int
) -> None:
"""
Decreases the shiny pokemon count by a specified amount
"""
self.data[user_id][self.SHINY_PKMN_COUNT] -= quantity
def get_total_pkmn_count(self, user_id: str) -> int:
"""
Gets the total pokemon count
"""
return self.data[user_id][self.TOTAL_PKMN_COUNT]
def increment_total_pkmn_count(self, user_id: str) -> None:
"""
Increments the trainer's count for total pokemon
"""
self.data[user_id][self.TOTAL_PKMN_COUNT] += 1
def decrease_total_pkmn_count(
self,
user_id: str,
quantity: int
) -> None:
"""
Decreases the total pokemon count by a specified amount
"""
self.data[user_id][self.TOTAL_PKMN_COUNT] -= quantity
def get_ultra_beasts_count(self, user_id: str) -> int:
"""
Gets the ultra beasts count
"""
return self.data[user_id][self.ULTRA_BEASTS_COUNT]
def increment_ultra_beasts_count(self, user_id: str) -> None:
"""
Increments the trainer's count for ultra beasts
"""
self.data[user_id][self.ULTRA_BEASTS_COUNT] += 1
def decrease_ultra_beasts_count(
self,
user_id: str,
quantity: int
) -> None:
"""
Decreases the ultra beast count by a specified amount
"""
self.data[user_id][self.ULTRA_BEASTS_COUNT] -= quantity
def get_egg_count(self, user_id: str) -> int:
"""
Gets the amount of eggs that exist with the user
"""
return self.data[user_id][self.EGG_COUNT]
def get_egg_manaphy_count(self, user_id: str) -> int:
"""
Gets the amount of manaphy eggs that exist with the user
"""
return self.data[user_id][self.EGG_MANAPHY_COUNT]
def increment_egg_count(self, user_id: str) -> None:
"""
Increment trainer's egg count
"""
self.data[user_id][self.EGG_COUNT] += 1
def decrement_egg_count(self, user_id: str) -> None:
"""
Decrement trainer's egg count
"""
self.data[user_id][self.EGG_COUNT] -= 1
def increment_egg_manaphy_count(self, user_id: str) -> None:
"""
Increment trainer's manaphy egg count
"""
self.data[user_id][self.EGG_MANAPHY_COUNT] += 1
def decrement_egg_manaphy_count(self, user_id: str) -> None:
"""
Decrement trainer's manaphy egg count
"""
self.data[user_id][self.EGG_MANAPHY_COUNT] -= 1
def decrement_bronze_lootbox_quantity(self, user_id: str):
"""
Decreases the bronze lootbox quantity of a user by 1
"""
self.data[user_id][self.LOOTBOX][self.BRONZE] -= 1
def decrement_silver_lootbox_quantity(self, user_id: str):
"""
Decreases the silver lootbox quantity of a user by 1
"""
self.data[user_id][self.LOOTBOX][self.SILVER] -= 1
def decrement_gold_lootbox_quantity(self, user_id: str):
"""
Decreases the gold lootbox quantity of a user by 1
"""
self.data[user_id][self.LOOTBOX][self.GOLD] -= 1
def increment_daily_tokens(self, user_id: str):
"""
Increments the daily token count of a trainer
"""
self.data[user_id][self.DAILY_TOKENS] += 1