diff --git a/bot.py b/bot.py new file mode 100644 index 0000000..1e32fa5 --- /dev/null +++ b/bot.py @@ -0,0 +1,68 @@ +import asyncio +import datetime +from telegram import Update +from telegram.ext import Application, CommandHandler, MessageHandler, filters, ContextTypes +import main as _brsim + +TOKEN = "7670066927:AAG8jI5n9NcyxPksYky7LPYqA08BThs07c4" + +async def bot_start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: + txt="""Benvenuto nel crudele mondo di Battle Royal Simulator, +La tua avventura e quella dei tuoi compagni inizia qui. +Questo Bot simula Hunger Games, +Tu e i tuoi compagni, sarete catapultati in questo mondo, +ma solo 1 di voi riuscira' a salvarsi. +Uccidi o sarai tu ad essere ucciso +""" + await update.message.reply_text(txt) + + 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?') + +async def send_message(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?') + +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') + +def main(): + # Crea l'applicazione e passagli il token del tuo bot. + application = Application.builder().token(TOKEN).build() + + # 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() diff --git a/main.py b/main.py index 75e10e0..dd65c9a 100644 --- a/main.py +++ b/main.py @@ -15,6 +15,20 @@ class BrSimArena(): def next_day(self): self.day+= 1 + def get_alive_players(self): + res= [] + for p in self.players: + if not p.is_alive(): continue + res.append(p) + return res + + def get_death_players(self): + res= [] + for p in self.players: + if p.is_alive(): continue + res.append(p) + return res + def do_random_event(self): #XXX random player does random action according to his inventory health, wounds, available weapons on the world, etc... pass @@ -26,17 +40,17 @@ class BrSimArena(): def init_arena(): - players= [{'name': 'Crystal'}, {'name': 'Cyan'}] - weapons= [{_wsyms.KNIFE: 1}] + players= [{'name': 'Crystal'}, {'name': 'Andrea'}] + weapons= [{_wsyms.KNIFE['name']: 1}] return BrSimArena(players, weapons) -Arena= init_arena() -def run_event(): +def run_event(Arena): pass -def main(): +def local_debug(): + Arena= init_arena() print(Arena.players) print(Arena.weapons) - run_event() + run_event(Arena)