2025-07-23 21:17:09 +02:00
import asyncio
import datetime
from telegram import Update
from telegram . ext import Application , CommandHandler , MessageHandler , filters , ContextTypes
2025-07-23 23:14:35 +02:00
import bot_syms as _botsyms
2025-07-23 21:17:09 +02:00
import main as _brsim
2025-07-23 23:14:35 +02:00
async def loop_game ( update : Update , context : ContextTypes . DEFAULT_TYPE ) - > None :
chat_id = update . effective_chat . id
if ' arena ' in context . application . bot_data :
pass
else :
print ( ' Arena non trovata ' )
await update . message . reply_text ( ' Che e \' successo? un Guarino ha rubato l \' arena, avvia una nuova partita con /start ' )
2025-07-23 21:17:09 +02:00
async def bot_start ( update : Update , context : ContextTypes . DEFAULT_TYPE ) - > None :
2025-07-23 23:14:35 +02:00
await update . message . reply_text ( _botsyms . START_MSG )
2025-07-23 21:17:09 +02:00
print ( ' Sto costruendo il mondo di gioco... ' )
Arena = _brsim . init_arena ( )
players = Arena . players
weapons = Arena . weapons
print ( f ' Ecco il mondo di gioco, questi sono i giocatori: { players } ' )
print ( f ' Ecco le armi disponibili nel mondo: { weapons } ' )
await update . message . reply_text ( ' Ho creato il mondo di gioco ' )
await update . message . reply_text ( f ' Ecco la lista degli sfortunati avventurieri: { players } ' )
await update . message . reply_text ( f ' Queste le armi che avranno a disposizione nell \' arena: { weapons } ' )
context . application . bot_data [ ' arena ' ] = Arena
chat_id = update . effective_chat . id
context . job_queue . run_daily (
loop_game ,
time = datetime . time ( hour = 0 , minute = 0 , second = 5 , tzinfo = datetime . timezone . utc ) ,
chat_id = chat_id ,
name = str ( chat_id ) # Usiamo il chat_id come nome univoco per il job
)
print ( f ' Job giornaliero creato per la chat { chat_id } ' )
async def echo ( update : Update , context : ContextTypes . DEFAULT_TYPE ) - > None :
testo_ricevuto = update . message . text
await update . message . reply_text ( f ' Ehi, mio padre mi sta ancora finendo di creare, abbi pazienza, che fretta hai di entrare in questo mondo per morire? ' )
def main ( ) :
# Crea l'applicazione e passagli il token del tuo bot.
2025-07-23 23:14:35 +02:00
application = Application . builder ( ) . token ( _botsyms . TOKEN ) . build ( )
2025-07-23 21:17:09 +02:00
# Gestisce il comando /start
application . add_handler ( CommandHandler ( ' start ' , bot_start ) )
# Gestisce tutti gli altri messaggi di testo
application . add_handler ( MessageHandler ( filters . TEXT & ~ filters . COMMAND , echo ) )
print ( ' Bot in esecuzione... ' )
application . run_polling ( )
if __name__ == ' __main__ ' :
main ( )