2025-07-26 11:00:20 +02:00
|
|
|
from telegram.ext import Application
|
|
|
|
|
from telegram.ext import CommandHandler
|
|
|
|
|
from telegram.ext import MessageHandler
|
|
|
|
|
from telegram.ext import filters
|
|
|
|
|
from telegram import ReplyKeyboardMarkup
|
|
|
|
|
from telegram import ReplyKeyboardRemove
|
2025-07-26 14:44:16 +02:00
|
|
|
|
2025-07-26 20:58:35 +02:00
|
|
|
from utils import logs as _log
|
|
|
|
|
|
2025-07-26 18:07:14 +02:00
|
|
|
from entities import arena as _arena
|
2025-07-26 19:44:45 +02:00
|
|
|
from bot_libs import upstart as _bot_upstart
|
2025-07-26 10:13:20 +02:00
|
|
|
from bot_libs import syms as _botsyms
|
2025-07-26 20:58:35 +02:00
|
|
|
from bot_libs import commands_handling as _bot_commands
|
2025-07-23 21:17:09 +02:00
|
|
|
|
2025-07-26 11:00:20 +02:00
|
|
|
|
2025-07-24 21:28:42 +02:00
|
|
|
async def bot_start(update, context):
|
2025-07-23 23:14:35 +02:00
|
|
|
await update.message.reply_text(_botsyms.START_MSG)
|
2025-07-23 21:17:09 +02:00
|
|
|
|
2025-07-26 11:00:20 +02:00
|
|
|
keyboard = [
|
|
|
|
|
['Init/Restart'],
|
2025-07-26 15:20:03 +02:00
|
|
|
['Add Player', 'Add random Players', 'Add random color Players'],
|
2025-07-26 17:56:54 +02:00
|
|
|
['Get Players', 'Get Alive Players', 'Get Death Players', 'Get Ranking Players',],
|
2025-07-26 11:00:20 +02:00
|
|
|
['Simulate Day', 'Run Periodically']
|
|
|
|
|
]
|
|
|
|
|
reply_markup= ReplyKeyboardMarkup(keyboard, one_time_keyboard=False, resize_keyboard=True)
|
|
|
|
|
|
2025-07-23 23:43:26 +02:00
|
|
|
chat_id = update.effective_chat.id
|
2025-07-26 21:25:38 +02:00
|
|
|
_log.log_debug(f'bot_start: {chat_id} - I\'m building the world\'s game...')
|
2025-07-26 18:07:14 +02:00
|
|
|
Arena= _arena.BrSimArena()
|
2025-07-23 23:43:26 +02:00
|
|
|
|
2025-07-26 11:00:20 +02:00
|
|
|
await update.message.reply_text('Ho creato il mondo di gioco', reply_markup=reply_markup)
|
2025-07-23 21:17:09 +02:00
|
|
|
context.application.bot_data['arena'] = Arena
|
|
|
|
|
|
2025-07-26 11:00:20 +02:00
|
|
|
async def bot_commands(update, context):
|
|
|
|
|
text= update.message.text
|
|
|
|
|
chat_id = update.effective_chat.id
|
|
|
|
|
|
2025-07-26 21:25:38 +02:00
|
|
|
_log.log_info(f'bot_command: {chat_id} - text received: {text}')
|
2025-07-26 20:58:35 +02:00
|
|
|
|
2025-07-26 11:00:20 +02:00
|
|
|
if text == 'Init/Restart':
|
|
|
|
|
return await bot_start(update, context)
|
|
|
|
|
|
|
|
|
|
if text == 'Add Player':
|
2025-07-26 20:58:35 +02:00
|
|
|
return await _bot_commands.bot_command_add_player(context, update, chat_id)
|
2025-07-26 11:00:20 +02:00
|
|
|
if text == 'Get Players':
|
2025-07-26 20:58:35 +02:00
|
|
|
return await _bot_commands.bot_command_get_players(context, update, chat_id)
|
2025-07-26 11:00:20 +02:00
|
|
|
if text == 'Get Alive Players':
|
2025-07-26 20:58:35 +02:00
|
|
|
return await _bot_commands.bot_command_get_alive_players(context, update, chat_id)
|
2025-07-26 11:00:20 +02:00
|
|
|
if text == 'Get Death Players':
|
2025-07-26 20:58:35 +02:00
|
|
|
return await _bot_commands.bot_command_get_death_players(context, update, chat_id)
|
2025-07-26 17:56:54 +02:00
|
|
|
if text == 'Get Ranking Players':
|
2025-07-26 20:58:35 +02:00
|
|
|
return await _bot_commands.bot_command_get_ranking_players(context, update, chat_id)
|
2025-07-26 11:00:20 +02:00
|
|
|
if text == 'Simulate Day':
|
2025-07-26 20:58:35 +02:00
|
|
|
return await _bot_commands.bot_command_simulate_day(context, update, chat_id)
|
2025-07-26 11:00:20 +02:00
|
|
|
if text == 'Run Periodically':
|
2025-07-26 20:58:35 +02:00
|
|
|
return await _bot_commands.bot_command_simulate_day_cron(context, update, chat_id)
|
2025-07-26 11:00:20 +02:00
|
|
|
|
2025-07-26 15:20:03 +02:00
|
|
|
waiting_for_name= context.application.bot_data.get('ask_name')
|
|
|
|
|
if waiting_for_name or text in ['Add random Players', 'Add random color Players']:
|
2025-07-26 20:58:35 +02:00
|
|
|
return await _bot_commands.get_name_from_input(context, update, chat_id, text)
|
2025-07-26 15:20:03 +02:00
|
|
|
|
2025-07-26 11:15:44 +02:00
|
|
|
waiting_for_seconds= context.application.bot_data.get('ask_seconds')
|
|
|
|
|
if waiting_for_seconds:
|
2025-07-26 20:58:35 +02:00
|
|
|
return await _bot_commands.get_seconds_from_input(context, update, chat_id, text)
|
2025-07-26 12:38:06 +02:00
|
|
|
|
2025-07-26 19:44:45 +02:00
|
|
|
if text == 'upstart': return await _bot_upstart.update_bot(update, context)
|
2025-07-26 20:34:15 +02:00
|
|
|
|
2025-07-26 21:25:38 +02:00
|
|
|
_log.log_debug(f'bot_command: {chat_id} - sent this text: {text}')
|
2025-07-26 11:00:20 +02:00
|
|
|
await update.message.reply_text(_botsyms.WIP_MSG)
|
|
|
|
|
|
2025-07-23 21:17:09 +02:00
|
|
|
def main():
|
2025-07-23 23:14:35 +02:00
|
|
|
application = Application.builder().token(_botsyms.TOKEN).build()
|
2025-07-23 21:17:09 +02:00
|
|
|
|
|
|
|
|
application.add_handler(CommandHandler('start', bot_start))
|
2025-07-26 11:00:20 +02:00
|
|
|
application.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, bot_commands))
|
2025-07-23 21:17:09 +02:00
|
|
|
|
2025-07-26 21:25:38 +02:00
|
|
|
_log.log_info('main: Bot is running...')
|
2025-07-23 21:17:09 +02:00
|
|
|
application.run_polling()
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
main()
|