11from telegram .ext import CommandHandler
22from pycamp_bot .models import Pycampista
3+ import random
34
45
56async def become_wizard (update , context ):
@@ -24,19 +25,23 @@ async def become_wizard(update, context):
2425
2526async def summon_wizard (update , context ):
2627 username = update .message .from_user .username
27- try :
28- wizard = Pycampista .get (Pycampista .wizard is True )
28+ wizard_list = list (Pycampista .select ().where (Pycampista .wizard == True ))
29+ if len (wizard_list ) == 0 :
30+ await context .bot .send_message (
31+ chat_id = update .message .chat_id ,
32+ text = "No hay ningunx magx todavia"
33+ )
34+ else :
35+ wizard = random .choice (wizard_list )
2936 await context .bot .send_message (
3037 chat_id = wizard .chat_id ,
3138 text = "PING PING PING MAGX! @{} te necesesita!" .format (username )
3239 )
33- except Pycampista .DoesNotExist :
3440 await context .bot .send_message (
35- chat_id = update .chat_id ,
36- text = "Hubo un accidente, el mago esta en otro plano. " .format (username )
41+ chat_id = update .message . chat_id ,
42+ text = "Tu magx asignadx es: @{} " .format (wizard . username )
3743 )
3844
39-
4045def set_handlers (application ):
4146 application .add_handler (
4247 CommandHandler ('evocar_magx' , summon_wizard ))
0 commit comments