forked from Cryz/battle_royale_sim
move telegram bot files
This commit is contained in:
61
bot.py
61
bot.py
@@ -1,61 +0,0 @@
|
||||
import asyncio
|
||||
import datetime
|
||||
from telegram import Update
|
||||
from telegram.ext import Application, CommandHandler, MessageHandler, filters, ContextTypes
|
||||
import bot_syms as _botsyms
|
||||
import main as _brsim
|
||||
|
||||
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')
|
||||
|
||||
async def bot_start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||
await update.message.reply_text(_botsyms.START_MSG)
|
||||
|
||||
chat_id = update.effective_chat.id
|
||||
print(f'{chat_id}: 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:\n{players}')
|
||||
await update.message.reply_text(f'Queste le armi che avranno a disposizione nell\'arena:\n{weapons}')
|
||||
context.application.bot_data['arena'] = Arena
|
||||
|
||||
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(_botsyms.WIP_MSG)
|
||||
|
||||
async def add_player(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
|
||||
|
||||
def main():
|
||||
# Crea l'applicazione e passagli il token del tuo bot.
|
||||
application = Application.builder().token(_botsyms.TOKEN).build()
|
||||
|
||||
# Gestisce il comando /start
|
||||
application.add_handler(CommandHandler('start', bot_start))
|
||||
# Gestisce il comando /addplayer
|
||||
application.add_handler(CommandHandler('addplayer', add_player))
|
||||
# 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()
|
||||
Reference in New Issue
Block a user