all repos — groupgardenbot @ 056f4f5f06e566ab73cc13313ff23211fc3949f1

An extension of the game "botany", originally designed for unix-based systems, to the Telegram Bot API.

removed /harvest command
Marco Andronaco andronacomarco@gmail.com
Fri, 23 Sep 2022 22:07:23 +0200
commit

056f4f5f06e566ab73cc13313ff23211fc3949f1

parent

8434ee64d0634a3230ff2c7ae8cc3f4eb9d50f47

2 files changed, 14 insertions(+), 21 deletions(-)

jump to
M Gardening.pyGardening.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.pymain.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