88from pycamp_bot .commands .auth import admin_needed
99from pycamp_bot .commands .manage_pycamp import get_active_pycamp
1010from pycamp_bot .logger import logger
11- from pycamp_bot .utils import escape_markdown
11+ from pycamp_bot .utils import escape_markdown , active_pycamp_needed
1212
1313
1414LUNCH_TIME_START_HOUR = 13
@@ -80,7 +80,7 @@ def define_wizards_schedule(pycamp):
8080
8181 """
8282 all_wizards = pycamp .get_wizards ()
83- if all_wizards . count ( ) == 0 :
83+ if len ( all_wizards ) == 0 :
8484 return {}
8585
8686 wizard_per_slot = {}
@@ -103,28 +103,21 @@ def define_wizards_schedule(pycamp):
103103 return wizard_per_slot
104104
105105
106- async def become_wizard (update , context ):
107- current_wizards = Pycampista .select ().where (Pycampista .wizard is True )
108-
109- for w in current_wizards :
110- w .current = False
111- w .save ()
112-
106+ @active_pycamp_needed
107+ async def become_wizard (update , context , pycamp = None ):
113108 username = update .message .from_user .username
114109 chat_id = update .message .chat_id
115110
116- user = Pycampista .get_or_create (username = username , chat_id = chat_id )[0 ]
117- user .wizard = True
118- user .save ()
111+ pycamp .add_wizard (username , chat_id )
119112
120113 await context .bot .send_message (
121114 chat_id = update .message .chat_id ,
122115 text = "¡Felicidades! Has sido registrado como magx."
123116 )
124117
125118
126- async def list_wizards ( update , context ):
127- _ , pycamp = get_active_pycamp ()
119+ @ active_pycamp_needed
120+ async def list_wizards ( update , context , pycamp = None ):
128121 msg = ""
129122 for i , wizard in enumerate (pycamp .get_wizards ()):
130123 msg += "{}) @{}\n " .format (i + 1 , wizard .username )
@@ -137,8 +130,8 @@ async def list_wizards(update, context):
137130 logger .exception ("Coulnd't deliver the Wizards list to {}" .format (update .message .from_user .username ))
138131
139132
140- async def summon_wizard ( update , context ):
141- _ , pycamp = get_active_pycamp ()
133+ @ active_pycamp_needed
134+ async def summon_wizard ( update , context , pycamp = None ):
142135 wizard = pycamp .get_current_wizard ()
143136 if wizard is None :
144137 await context .bot .send_message (
@@ -220,9 +213,8 @@ def persist_wizards_schedule_in_db(pycamp):
220213
221214
222215@admin_needed
223- async def schedule_wizards (update , context ):
224- _ , pycamp = get_active_pycamp ()
225-
216+ @active_pycamp_needed
217+ async def schedule_wizards (update , context , pycamp = None ):
226218 n = pycamp .clear_wizards_schedule ()
227219 logger .info ("Deleted wizards schedule ({} records)" .format (n ))
228220
@@ -281,7 +273,8 @@ def aux_resolve_show_all(message):
281273 return show_all
282274
283275
284- async def show_wizards_schedule (update , context ):
276+ @active_pycamp_needed
277+ async def show_wizards_schedule (update , context , pycamp = None ):
285278 try :
286279 show_all = aux_resolve_show_all (update .message )
287280 except ValueError :
@@ -290,8 +283,6 @@ async def show_wizards_schedule(update, context):
290283 text = "El comando solo acepta un parámetro (opcional): 'completa'. ¿Probás de nuevo?" ,
291284 )
292285 return
293-
294- _ , pycamp = get_active_pycamp ()
295286
296287 agenda = WizardAtPycamp .select ().where (WizardAtPycamp .pycamp == pycamp )
297288 if not show_all :
0 commit comments