mirror of
https://github.com/RYGhub/royal-mifia.git
synced 2024-11-26 15:44:19 +00:00
Rewritten /join and /debugjoin functions
This commit is contained in:
parent
9d3d2f2754
commit
185b1ff752
1 changed files with 43 additions and 32 deletions
61
main.py
61
main.py
|
@ -940,6 +940,13 @@ class Game:
|
||||||
for player in self.playersinrole['Mifioso']:
|
for player in self.playersinrole['Mifioso']:
|
||||||
player.message(bot, text)
|
player.message(bot, text)
|
||||||
|
|
||||||
|
def joinplayer(self, bot, player):
|
||||||
|
self.players.append(player)
|
||||||
|
self.message(bot, s.player_joined.format(name=p.tusername))
|
||||||
|
# Se è il primo giocatore ad unirsi, diventa admin
|
||||||
|
if len(self.players) == 0:
|
||||||
|
self.admin = player
|
||||||
|
|
||||||
|
|
||||||
# Partite in corso
|
# Partite in corso
|
||||||
inprogress = list()
|
inprogress = list()
|
||||||
|
@ -983,46 +990,50 @@ def newgame(bot, update):
|
||||||
def join(bot, update):
|
def join(bot, update):
|
||||||
"""Unisciti a una partita."""
|
"""Unisciti a una partita."""
|
||||||
game = findgamebyid(update.message.chat['id'])
|
game = findgamebyid(update.message.chat['id'])
|
||||||
if game is not None:
|
# Nessuna partita in corso
|
||||||
if game.phase == 'Join':
|
if game is None:
|
||||||
|
bot.sendMessage(update.message.chat['id'], s.error_no_games_found, parse_mode=ParseMode.MARKDOWN)
|
||||||
|
return
|
||||||
|
# Fase di join finita
|
||||||
|
if game.phase != 'Join':
|
||||||
|
game.message(bot, s.error_join_phase_ended)
|
||||||
|
return
|
||||||
p = game.findplayerbyid(update.message.from_user['id'])
|
p = game.findplayerbyid(update.message.from_user['id'])
|
||||||
if p is None:
|
# Giocatore già in partita
|
||||||
try:
|
if p is not None:
|
||||||
p = Player(update.message.from_user['id'], update.message.from_user['username'])
|
game.message(bot, s.error_player_already_joined)
|
||||||
except KeyError:
|
return
|
||||||
|
# Giocatore senza username
|
||||||
|
if 'username' not in update.message.from_user:
|
||||||
game.message(bot, s.error_no_username)
|
game.message(bot, s.error_no_username)
|
||||||
else:
|
return
|
||||||
|
p = Player(update.message.from_user['id'], update.message.from_user['username'])
|
||||||
try:
|
try:
|
||||||
p.message(bot, s.you_joined.format(game=game.name))
|
p.message(bot, s.you_joined.format(game=game.name))
|
||||||
except Unauthorized:
|
except Unauthorized:
|
||||||
|
# Bot bloccato dall'utente
|
||||||
game.message(bot, s.error_chat_unavailable)
|
game.message(bot, s.error_chat_unavailable)
|
||||||
else:
|
return
|
||||||
game.message(bot, s.player_joined.format(name=p.tusername))
|
# Aggiungi il giocatore alla partita
|
||||||
if len(game.players) == 0:
|
game.joinplayer(bot, p)
|
||||||
game.admin = p
|
# Salva
|
||||||
game.players.append(p)
|
game.save(bot)
|
||||||
else:
|
|
||||||
game.message(bot, s.error_player_already_joined)
|
|
||||||
else:
|
|
||||||
game.message(bot, s.error_join_phase_ended)
|
|
||||||
else:
|
|
||||||
bot.sendMessage(update.message.chat['id'], s.error_no_games_found, parse_mode=ParseMode.MARKDOWN)
|
|
||||||
|
|
||||||
|
|
||||||
def debugjoin(bot, update):
|
def debugjoin(bot, update):
|
||||||
"""Aggiungi un bot alla partita."""
|
"""Aggiungi un bot alla partita."""
|
||||||
if __debug__:
|
if __debug__:
|
||||||
game = findgamebyid(update.message.chat['id'])
|
game = findgamebyid(update.message.chat['id'])
|
||||||
if game is not None:
|
if game is None:
|
||||||
if game.phase == 'Join':
|
bot.sendMessage(update.message.chat['id'], s.error_no_games_found, parse_mode=ParseMode.MARKDOWN)
|
||||||
|
return
|
||||||
|
if game.phase != 'Join':
|
||||||
|
game.message(bot, s.error_join_phase_ended)
|
||||||
|
return
|
||||||
arg = update.message.text.split(" ")
|
arg = update.message.text.split(" ")
|
||||||
p = Player(random.randrange(0, 10000), arg[1], True)
|
p = Player(random.randrange(0, 10000), arg[1], True) # ewwwwww
|
||||||
game.message(bot, s.player_joined.format(name=p.tusername))
|
game.message(bot, s.player_joined.format(name=p.tusername))
|
||||||
game.players.append(p)
|
game.players.append(p)
|
||||||
else:
|
|
||||||
game.message(bot, s.error_join_phase_ended)
|
|
||||||
else:
|
|
||||||
bot.sendMessage(update.message.chat['id'], s.error_no_games_found, parse_mode=ParseMode.MARKDOWN)
|
|
||||||
|
|
||||||
|
|
||||||
def status(bot, update):
|
def status(bot, update):
|
||||||
|
|
Loading…
Reference in a new issue