removed /harvest command
Marco Andronaco andronacomarco@gmail.com
Fri, 23 Sep 2022 22:07:23 +0200
2 files changed,
14 insertions(+),
21 deletions(-)
M
Gardening.py
→
Gardening.py
@@ -146,7 +146,7 @@ res2 = min(plant.last_update - plant.last_water, water_duration)
plant.points += max(0, res1 - res2) # max() not necessary but just in case - print("generation bonus: ", plant.generation_bonus, ". increase: ", res1 - res2, "max: ", water_duration) + #print("generation bonus: ", plant.generation_bonus, ". increase: ", res1 - res2, "max: ", water_duration) plant.last_update = now stages = tuple(ti / plant.generation_bonus for ti in plant.life_stages) # bonus is applied to stage thresholds@@ -159,7 +159,7 @@ if (n <= delta and (closest is None or (delta - n) < (delta - closest))):
closest = n count += 1 - print("plant is in stage", count, "because it passed", closest, "seconds of life") + #print("plant is in stage", count, "because it passed", closest, "seconds of life") return count def get_plant_water(plant: Plant):
M
main.py
→
main.py
@@ -24,12 +24,20 @@ return plant
def start(update: Update, context: CallbackContext): plant = get_plant(update, context) + new = False - if plant is not None: - return reply(update, context, "Hai già una pianta. Usa /water se vuoi innaffiarla.") + if plant is None: + context.bot_data[update.effective_user.id] = { "plant" : Plant(update.effective_user.id) } + new = True + + if plant.dead or plant.stage == 5: + plant.start_over() + new = True - context.bot_data[update.effective_user.id] = { "plant" : Plant(update.effective_user.id) } - return reply(update, context, "Hai piantato un seme! Adesso usa /water per innaffiarlo.") + if new: + return reply(update, context, "Hai piantato un nuovo seme! Adesso usa /water per innaffiarlo.") + + return reply(update, context, "La tua pianta non è ancora pronta per andarsene!") def water(update: Update, context: CallbackContext): plant = get_plant(update, context)@@ -51,21 +59,7 @@ return reply(update, context, "Non hai nessuna pianta da mostrare! Usa /start per piantarne una.")
return reply(update, context, get_plant_info(plant)) -def harvest(update: Update, context: CallbackContext): - plant = get_plant(update, context) - - if plant is None: - return reply(update, context, "Non hai nessuna pianta! Usa /start per piantarne una.") - if plant.dead: - plant.start_over() - return reply(update, context, "Hai piantato un nuovo seme. Usa /water per innaffiarlo, magari stavolta un po' più spesso.") - - if plant.stage != 5: - return reply(update, context, "La tua pianta non è ancora pronta per andarsene!") - - plant.start_over() - return reply(update, context, "Complimenti, hai piantato un nuovo seme! Usa /water per innaffiarlo.") ''' def keyboard_handler(update: Update, context: CallbackContext): query = update.callback_query@@ -106,7 +100,6 @@ # commands
dispatcher.add_handler(CommandHandler('start', start)) dispatcher.add_handler(CommandHandler('water', water)) dispatcher.add_handler(CommandHandler('show', show)) - dispatcher.add_handler(CommandHandler('harvest', harvest)) ''' # slot