forked from Cryz/battle_royale_sim
split player commands from main bot
This commit is contained in:
37
bot.py
37
bot.py
@@ -5,6 +5,7 @@ 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
|
||||||
import debug as _dbg
|
import debug as _dbg
|
||||||
|
from bot_libs import player_handling as _bot_player
|
||||||
|
|
||||||
async def loop_game(context):
|
async def loop_game(context):
|
||||||
chat_id = context.job.chat_id
|
chat_id = context.job.chat_id
|
||||||
@@ -27,8 +28,6 @@ async def bot_start(update, context):
|
|||||||
Arena= _brsim.init_arena()
|
Arena= _brsim.init_arena()
|
||||||
|
|
||||||
await update.message.reply_text('Ho creato il mondo di gioco')
|
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.application.bot_data['arena'] = Arena
|
||||||
|
|
||||||
async def echo(update, context):
|
async def echo(update, context):
|
||||||
@@ -58,38 +57,18 @@ async def start_game(update, context):
|
|||||||
#)
|
#)
|
||||||
print(f'Job giornaliero creato per la chat {chat_id}')
|
print(f'Job giornaliero creato per la chat {chat_id}')
|
||||||
|
|
||||||
async def add_player(update, context):
|
|
||||||
name= " ".join(context.args)
|
|
||||||
print(f'sto aggiungendo il giocatore {name} all\'arena')
|
|
||||||
Arena= context.application.bot_data['arena']
|
|
||||||
Arena.add_player(name)
|
|
||||||
print(f'Giocatori: {Arena.get_players()}')
|
|
||||||
await update.message.reply_text(f'Ecco i giocatori presenti nel mondo do gioco: \n{Arena.get_players()}')
|
|
||||||
|
|
||||||
async def get_players(update, context):
|
|
||||||
Arena= context.application.bot_data['arena']
|
|
||||||
print(f'Giocatori: {Arena.get_players()}')
|
|
||||||
await update.message.reply_text(f'Ecco i giocatori presenti nel mondo do gioco: \n{Arena.get_players()}')
|
|
||||||
|
|
||||||
async def get_alive_players(update, context):
|
|
||||||
Arena= context.application.bot_data['arena']
|
|
||||||
print(f'Giocatori: {Arena.get_players()}')
|
|
||||||
await update.message.reply_text(f'Ecco i giocatori ancora vivi: \n{Arena.get_alive_players()}')
|
|
||||||
|
|
||||||
async def get_death_players(update, context):
|
|
||||||
Arena= context.application.bot_data['arena']
|
|
||||||
print(f'Giocatori: {Arena.get_players()}')
|
|
||||||
await update.message.reply_text(f'Ecco i giocatori morti x.x: \n{Arena.get_death_players()}')
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
application = Application.builder().token(_botsyms.TOKEN).build()
|
application = Application.builder().token(_botsyms.TOKEN).build()
|
||||||
|
|
||||||
application.add_handler(CommandHandler('start', bot_start))
|
application.add_handler(CommandHandler('start', bot_start))
|
||||||
application.add_handler(CommandHandler('start_game', start_game))
|
application.add_handler(CommandHandler('start_game', start_game))
|
||||||
application.add_handler(CommandHandler('add_player', add_player))
|
|
||||||
application.add_handler(CommandHandler('get_players', get_players))
|
# player handler
|
||||||
application.add_handler(CommandHandler('get_alive_players', get_alive_players))
|
application.add_handler(CommandHandler('add_player', _bot_player.add_player))
|
||||||
application.add_handler(CommandHandler('get_death_players', get_death_players))
|
application.add_handler(CommandHandler('get_players', _bot_player.get_players))
|
||||||
|
application.add_handler(CommandHandler('get_alive_players', _bot_player.get_alive_players))
|
||||||
|
application.add_handler(CommandHandler('get_death_players', _bot_player.get_death_players))
|
||||||
|
|
||||||
application.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, echo))
|
application.add_handler(MessageHandler(filters.TEXT & ~filters.COMMAND, echo))
|
||||||
|
|
||||||
print('Bot in esecuzione...')
|
print('Bot in esecuzione...')
|
||||||
|
|||||||
22
bot_libs/player_handling.py
Normal file
22
bot_libs/player_handling.py
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
|
||||||
|
async def add_player(update, context):
|
||||||
|
name= " ".join(context.args)
|
||||||
|
print(f'add_player: {name}')
|
||||||
|
Arena= context.application.bot_data['arena']
|
||||||
|
Arena.add_player(name)
|
||||||
|
await update.message.reply_text(f'Ecco i giocatori presenti nel mondo do gioco: \n{Arena.get_players()}')
|
||||||
|
|
||||||
|
async def get_players(update, context):
|
||||||
|
Arena= context.application.bot_data['arena']
|
||||||
|
print(f'get_players: {Arena.get_players()}')
|
||||||
|
await update.message.reply_text(f'Ecco i giocatori presenti nel mondo do gioco: \n{Arena.get_players()}')
|
||||||
|
|
||||||
|
async def get_alive_players(update, context):
|
||||||
|
Arena= context.application.bot_data['arena']
|
||||||
|
print(f'get_alive_players: {Arena.get_alive_players()}')
|
||||||
|
await update.message.reply_text(f'Ecco i giocatori ancora vivi: \n{Arena.get_alive_players()}')
|
||||||
|
|
||||||
|
async def get_death_players(update, context):
|
||||||
|
Arena= context.application.bot_data['arena']
|
||||||
|
print(f'get_death_players: {Arena.get_death_players()}')
|
||||||
|
await update.message.reply_text(f'Ecco i giocatori morti x.x: \n{Arena.get_death_players()}')
|
||||||
Reference in New Issue
Block a user