@@ -45,25 +45,23 @@ def is_tgmember_sect(first_name: str):
4545 return "tgmember.com" in first_name .lower ()
4646
4747
48- def is_bot (user : User ):
48+ def is_bot (user : User ) -> bool :
4949 """
5050 Returns True if a new user is a bot. So far only the length of the
5151 username is checked. In the future, we can add more conditions and use a
5252 score/weight of the probability of being a bot.
5353
5454 :param user: The new User
55- :typus user: User
55+ :type user: User
5656 :return: True if the new user is considered a bot (according to our rules)
5757 :rtype: bool
5858 """
5959 # Add all the checks that you consider necessary
60- return any (
61- (
62- not is_valid_name (user ),
63- too_much_chinese_chars (user .first_name ),
64- is_tgmember_sect (user .first_name ),
65- )
66- )
60+ return any ([
61+ not is_valid_name (user ),
62+ too_much_chinese_chars (user .first_name ),
63+ is_tgmember_sect (user .first_name ),
64+ ])
6765
6866
6967@functools .lru_cache ()
@@ -210,22 +208,21 @@ def setup_bot():
210208
211209 root_path = Path (sys .prefix )
212210 bin_path = Path (sys .executable ).parent
213- bot_executable = bin_path / 'bot '
211+ bot_executable = bin_path / 'pydeckard '
214212 env_path = root_path / '.env'
215213 system_name = platform .system ()
216214
217215 print (f'\n --- Asistente de configuración para PyDeckard (SO: { system_name } ) ---\n \n ' )
218216
219- parameters = [('TELEGRAM_BOT_TOKEN' , 'Introduzca el Token del Bot' , None , str ),
220- ('VERBOSITY' , 'Nivel de verbosidad' , (0.0 , 1.0 ), float ),
221- ('LOG_LEVEL' , 'Nivel de registro de logs' , ['DEBUG' , 'INFO' , 'WARNING' , 'ERROR' ], str ),
222- ('POLL_INTERVAL' , 'Intervalo de polling para la API de Telegram' , (1 , 10 ), int ),
223- ('BOT_GREETING' , 'Saludo del bot' , None , str ),
224- ('MAX_HUMAN_USERNAME_LENGTH' , 'Longitud máxima del username' , None , int ),
225- ('MAX_CHINESE_CHARS_PERCENT' , 'Máximo porcentaje de caracteres chinos en username' , (0.0 ,
226- 1.0 ), float ),
227- ('WELCOME_DELAY' , 'Tiempo de retardo para la bienvenida (seg)' , None , int ),
228- ]
217+ parameters = [
218+ ('TELEGRAM_BOT_TOKEN' , 'Introduzca el Token del Bot' , None , str ),
219+ ('LOG_LEVEL' , 'Nivel de registro de logs' , ['DEBUG' , 'INFO' , 'WARNING' , 'ERROR' ], str ),
220+ ('POLL_INTERVAL' , 'Intervalo de polling para la API de Telegram' , (1 , 10 ), int ),
221+ ('BOT_GREETING' , 'Saludo del bot' , None , str ),
222+ ('MAX_HUMAN_USERNAME_LENGTH' , 'Longitud máxima del username' , None , int ),
223+ ('MAX_CHINESE_CHARS_PERCENT' , 'Máximo porcentaje de caracteres chinos en username' , (0.0 , 1.0 ), float ),
224+ ('WELCOME_DELAY' , 'Tiempo de retardo para la bienvenida (seg)' , None , int ),
225+ ]
229226
230227 try :
231228 items_env = {key : validate_input (* args ) for key , * args in parameters }
@@ -248,41 +245,47 @@ def setup_bot():
248245 service_path = root_path / 'pydeckard.service'
249246
250247 service_content = f"""[Unit]
251- Description=PyDeckard
252- After=network.target
253-
254- [Service]
255- Type=simple
256- User={ user_name }
257- Group={ group_name }
258- WorkingDirectory={ root_path }
259- ExecStart={ bot_executable }
260- Environment=PYTHONUNBUFFERED=1
261- Restart=always
262-
263- [Install]
264- WantedBy=multi-user.target
265- Alias=PyDeckard.service
266- """
267-
248+ Description=PyDeckard
249+ After=network.target
250+
251+ [Service]
252+ Type=simple
253+ User={ user_name }
254+ Group={ group_name }
255+ WorkingDirectory={ root_path }
256+ ExecStart={ bot_executable }
257+ Environment=PYTHONUNBUFFERED=1
258+ Restart=always
259+
260+ [Install]
261+ WantedBy=multi-user.target
262+ Alias=PyDeckard.service
263+ """
268264 with open (service_path , 'w' ) as f :
269265 f .write (service_content )
270266
271267 print (f'\n Archivo pydeckard.service creado en { root_path } ' )
268+ print (f'\n Para configurar, activar e iniciar el service en systemd ejecute los siguientes comandos:' )
269+
272270 print (f'\n sudo cp { service_path } /etc/systemd/system/' )
273271 print ('sudo systemctl daemon-reload' )
274272 print ('sudo systemctl enable --now pydeckard' )
275-
276273 sys .exit (0 )
277274
278275 elif system_name == 'Darwin' :
279- print ('Entorno macOS detectado, configuración realizada, pregúntele a Apple® como arrancarlo.' )
276+ print (
277+ 'Entorno macOS detectado, configuración realizada, pregúntele'
278+ ' a Apple® como arrancarlo.'
279+ )
280280 sys .exit (1 )
281281
282282 elif system_name == 'Windows' :
283- print ('Entorno Windows detectado, configuración realizada, pregúntele a Microsoft® como arrancarlo.' )
283+ print (
284+ 'Entorno Windows detectado , configuración realizada , pregúntele
285+ ' a Microsoft® como arrancarlo.'
286+ )
284287 sys .exit (1 )
285288
286289 elif system_name == 'Java' :
287290 print ('Entorno Jython detectado. Usted mismo.' )
288- sys .exit (1 )
291+ sys .exit (1 )
0 commit comments