1
0

bot reframe, based on local_settings TOKEN, and periodic run

This commit is contained in:
andrea
2025-07-24 21:28:42 +02:00
parent c5a6f4ea36
commit f193464006
3 changed files with 16 additions and 10 deletions

19
bot.py
View File

@@ -1,19 +1,20 @@
import asyncio import asyncio
import datetime import datetime
from telegram import Update import pytz
from telegram.ext import Application, CommandHandler, MessageHandler, filters, ContextTypes from telegram.ext import Application, CommandHandler, MessageHandler, filters
import bot_syms as _botsyms import bot_syms as _botsyms
import main as _brsim import main as _brsim
async def loop_game(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: async def loop_game(context):
chat_id = update.effective_chat.id chat_id = context.job.chat_id
if 'arena' in context.application.bot_data: if 'arena' in context.application.bot_data:
print(f'{chat_id}: Guarino ha trovato l\'arena')
pass pass
else: else:
print('Arena non trovata') print('Arena non trovata')
await update.message.reply_text('Che e\' successo? un Guarino ha rubato l\'arena, avvia una nuova partita con /start') 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: async def bot_start(update, context):
await update.message.reply_text(_botsyms.START_MSG) await update.message.reply_text(_botsyms.START_MSG)
chat_id = update.effective_chat.id chat_id = update.effective_chat.id
@@ -29,19 +30,21 @@ async def bot_start(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None:
await update.message.reply_text(f'Queste le armi che avranno a disposizione nell\'arena:\n{weapons}') await update.message.reply_text(f'Queste le armi che avranno a disposizione nell\'arena:\n{weapons}')
context.application.bot_data['arena'] = Arena context.application.bot_data['arena'] = Arena
#context.job_queue.run_repeating(loop_game, interval=10, first=0, chat_id= chat_id)
timezone = pytz.timezone('Europe/Rome')
context.job_queue.run_daily( context.job_queue.run_daily(
loop_game, loop_game,
time=datetime.time(hour=0, minute=0, second=5, tzinfo=datetime.timezone.utc), time=datetime.time(hour=13, minute=0, second=0, tzinfo= timezone),
chat_id=chat_id, chat_id=chat_id,
name=str(chat_id) name=str(chat_id)
) )
print(f'Job giornaliero creato per la chat {chat_id}') print(f'Job giornaliero creato per la chat {chat_id}')
async def echo(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: async def echo(update, context):
testo_ricevuto = update.message.text testo_ricevuto = update.message.text
await update.message.reply_text(_botsyms.WIP_MSG) await update.message.reply_text(_botsyms.WIP_MSG)
async def add_player(update: Update, context: ContextTypes.DEFAULT_TYPE) -> None: async def add_player(update, context):
name= " ".join(context.args) name= " ".join(context.args)
print(f'sto aggiungendo il giocatore {name} all\'arena') print(f'sto aggiungendo il giocatore {name} all\'arena')
_brsim.BrSimArena _brsim.BrSimArena

View File

@@ -1,4 +1,6 @@
TOKEN = "7670066927:AAG8jI5n9NcyxPksYky7LPYqA08BThs07c4" from local_settings import TOKEN as _token
TOKEN= _token
START_MSG= """Benvenuto nel crudele mondo di Battle Royal Simulator, START_MSG= """Benvenuto nel crudele mondo di Battle Royal Simulator,
La tua avventura e quella dei tuoi compagni inizia qui. La tua avventura e quella dei tuoi compagni inizia qui.

View File

@@ -1 +1,2 @@
python-telegram-bot==22.3 python-telegram-bot==22.3
pytz==2025.2