Skip to content

Commit d16331b

Browse files
authored
Merge pull request #54 from PyAr/alex-branch
Fix summon wizard
2 parents b70085b + e4ee517 commit d16331b

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

src/pycamp_bot/commands/wizard.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from telegram.ext import CommandHandler
22
from pycamp_bot.models import Pycampista
3+
import random
34

45

56
async def become_wizard(update, context):
@@ -24,19 +25,23 @@ async def become_wizard(update, context):
2425

2526
async 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-
4045
def set_handlers(application):
4146
application.add_handler(
4247
CommandHandler('evocar_magx', summon_wizard))

0 commit comments

Comments
 (0)