2016-05-25 09:52:53 +00:00
#!/usr/bin/env python3.5
2016-04-25 18:13:16 +02:00
# -*- coding: utf-8 -*-
2016-04-25 18:21:38 +02:00
from telegram . ext import Updater , CommandHandler
2016-04-21 18:57:23 +02:00
import filemanager
2016-04-25 19:39:57 +02:00
import random
2016-04-21 18:57:23 +02:00
2016-04-21 22:14:35 +02:00
import logging
logger = logging . getLogger ( )
2016-05-22 17:13:26 +02:00
logger . setLevel ( logging . WARN )
logging . basicConfig ( level = logging . WARN ,
format = ' %(asctime)s - %(name)s - %(levelname)s - %(message)s ' )
2016-04-21 22:14:35 +02:00
2016-04-21 18:57:23 +02:00
token = filemanager . readfile ( ' telegramapi.txt ' )
updater = Updater ( token )
2016-04-21 19:52:01 +02:00
# Ruoli possibili per i giocatori
# Base di un ruolo
class Role :
2016-05-25 06:57:03 +00:00
""" Classe base di un ruolo. Da qui si sviluppano tutti gli altri ruoli. """
2016-05-22 17:13:26 +02:00
def __init__ ( self ) :
2016-05-25 09:52:53 +00:00
self . icon = " - " # Icona del ruolo, da visualizzare di fianco al nome
2016-05-22 17:13:26 +02:00
self . team = ' None ' # Squadra: 'None', 'Good', 'Evil'
2016-05-25 09:52:53 +00:00
self . name = " UNDEFINED " # Nome del ruolo, viene visualizzato dall'investigatore e durante l'assegnazione dei ruoli
2016-04-21 19:52:01 +02:00
2016-04-23 17:07:09 +02:00
def power ( self , bot , game , player , arg ) :
2016-05-25 09:52:53 +00:00
""" Il potere del ruolo. Si attiva quando il bot riceve un /power in chat privata. """
2016-04-21 19:52:01 +02:00
pass
2016-04-23 17:07:09 +02:00
def onendday ( self , bot , game ) :
2016-05-25 09:52:53 +00:00
""" Metodo chiamato alla fine di ogni giorno, per attivare o ripristinare allo stato iniziale il potere. """
2016-04-21 19:52:01 +02:00
pass
class Royal ( Role ) :
2016-05-25 09:52:53 +00:00
""" Un membro della Royal Games. Il ruolo principale, non ha alcun potere se non quello di votare. """
2016-05-22 17:13:26 +02:00
def __init__ ( self ) :
super ( ) . __init__ ( )
self . icon = " \U0001F610 "
self . team = ' Good '
self . name = " Royal "
2016-04-21 19:52:01 +02:00
class Mifioso ( Role ) :
2016-05-25 09:52:53 +00:00
""" Il nemico globale. Può impostare come bersaglio una persona al giorno, per poi ucciderla alla fine.
2016-05-22 17:13:26 +02:00
def __init__ ( self ) :
super ( ) . __init__ ( )
self . icon = " \U0001F47F "
self . team = ' Evil '
self . target = None
self . name = " Mifioso "
2016-04-21 19:52:01 +02:00
2016-04-23 17:07:09 +02:00
def power ( self , bot , game , player , arg ) :
2016-05-25 09:52:53 +00:00
# Imposta una persona come bersaglio da uccidere.
2016-04-23 17:07:09 +02:00
self . target = game . findplayerbyusername ( arg )
2016-05-03 11:29:29 +00:00
if self . target is not None :
player . message ( bot , " Hai selezionato come bersaglio {0} . " . format ( self . target . tusername ) )
2016-04-21 19:52:01 +02:00
2016-04-23 17:07:09 +02:00
def onendday ( self , bot , game ) :
2016-05-25 09:52:53 +00:00
# Uccidi il bersaglio se non è protetto da un Angelo.
2016-04-23 17:07:09 +02:00
if self . target is not None :
2016-05-25 06:57:03 +00:00
if self . target . protectedby is None :
2016-05-03 11:29:29 +00:00
self . target . kill ( )
game . message ( bot , " {0} è stato ucciso dalla Mifia. \n "
" Era un {1} {2} . "
. format ( self . target . tusername , self . target . role . icon , self . target . role . name ) )
else :
game . message ( bot , " {0} è stato protetto dalla Mifia da {1} {2} ! \n "
2016-05-25 06:57:03 +00:00
. format ( self . target . tusername , self . target . protectedby . role . icon ,
self . target . protectedby . tusername ) )
2016-05-03 11:29:29 +00:00
self . target = None
2016-04-21 19:52:01 +02:00
class Investigatore ( Role ) :
2016-05-25 09:52:53 +00:00
""" L ' investigatore può indagare sul vero ruolo di una persona una volta al giorno. """
2016-05-22 17:13:26 +02:00
def __init__ ( self ) :
super ( ) . __init__ ( )
self . icon = " \U0001F575 "
self . team = ' Good '
self . poweruses = 1
self . name = " Investigatore "
2016-04-21 19:52:01 +02:00
2016-04-23 17:07:09 +02:00
def power ( self , bot , game , player , arg ) :
2016-05-25 09:52:53 +00:00
# Indaga sul vero ruolo di una persona, se sono ancora disponibili usi del potere.
2016-04-23 17:12:52 +02:00
if self . poweruses > 0 :
target = game . findplayerbyusername ( arg )
if target is not None :
self . poweruses - = 1
player . message ( bot , " {0} è un {1} {2} . \n "
" Puoi usare il tuo potere ancora {3} volte oggi. "
. format ( target . tusername , target . role . icon , target . role . name , self . poweruses ) )
else :
player . message ( bot , " Il nome utente specificato non esiste. " )
else :
player . message ( bot , " Non puoi più usare il tuo potere oggi. " )
2016-04-21 23:04:53 +02:00
2016-04-23 17:07:09 +02:00
def onendday ( self , bot , game ) :
2016-04-21 23:04:53 +02:00
# Ripristina il potere
self . poweruses = 1
2016-05-03 11:29:29 +00:00
class Angelo ( Role ) :
2016-05-25 09:52:53 +00:00
""" L ' angelo può proteggere una persona al giorno dalla Mifia. Se ha successo nella protezione, il suo ruolo sarà rivelato a tutti. """
2016-05-22 17:13:26 +02:00
def __init__ ( self ) :
super ( ) . __init__ ( )
self . icon = " \U0001F607 "
self . team = ' Good ' # Squadra: 'None', 'Good', 'Evil'
self . name = " Angelo "
2016-05-25 09:52:53 +00:00
self . protecting = None # La persona che questo angelo sta proteggendo
2016-05-03 11:29:29 +00:00
def power ( self , bot , game , player , arg ) :
2016-05-25 09:52:53 +00:00
# Imposta qualcuno come protetto
2016-05-03 11:29:29 +00:00
selected = game . findplayerbyusername ( arg )
if player is not selected and selected is not None :
2016-05-25 06:57:03 +00:00
selected . protectedby = player
2016-05-03 22:31:10 +02:00
self . protecting = selected
2016-05-03 11:29:29 +00:00
player . message ( bot , " Hai selezionato come protetto {0} . " . format ( self . protecting . tusername ) )
def onendday ( self , bot , game ) :
# Resetta la protezione
2016-05-25 06:45:46 +00:00
if self . protecting is not None :
2016-05-25 06:57:03 +00:00
self . protecting . protectedby = None
2016-05-03 11:29:29 +00:00
self . protecting = None
2016-05-03 21:49:39 +02:00
2016-04-21 20:20:26 +02:00
class Player :
2016-05-25 09:52:53 +00:00
""" Classe di un giocatore. Contiene tutti i dati riguardanti un giocatore all ' interno di una partita, come il ruolo, e i dati riguardanti telegram, come ID e username. """
2016-04-21 20:20:26 +02:00
def message ( self , bot , text ) :
2016-05-25 09:52:53 +00:00
""" Manda un messaggio privato al giocatore. """
2016-04-25 18:30:49 +02:00
bot . sendMessage ( self . tid , text )
2016-04-21 20:20:26 +02:00
2016-04-22 21:14:14 +02:00
def kill ( self ) :
2016-05-25 09:52:53 +00:00
""" Uccidi il giocatore. """
# Perchè questo esiste?
2016-04-22 21:14:14 +02:00
self . alive = False
2016-04-21 20:20:26 +02:00
def __init__ ( self , tid , tusername ) :
2016-05-25 09:52:53 +00:00
self . tid = tid # ID di Telegram
self . tusername = tusername # Username di Telegram
2016-05-22 17:13:26 +02:00
self . role = Role ( ) # Di base, ogni giocatore è un ruolo indefinito
self . alive = True
self . votingfor = None # Diventa un player se ha votato
2016-05-25 09:52:53 +00:00
self . votes = 0 # Voti che sta ricevendo questo giocatore. Aggiornato da updatevotes()
2016-05-25 06:57:03 +00:00
self . protectedby = None # Protettore. Oggetto player che protegge questo giocatore dalla mifia.
2016-04-21 20:20:26 +02:00
2016-05-25 09:52:53 +00:00
2016-04-21 20:20:26 +02:00
class Game :
2016-05-25 09:52:53 +00:00
""" Classe di una partita, contenente parametri riguardanti stato della partita e informazioni sul gruppo di Telegram. """
2016-04-21 20:20:26 +02:00
def __init__ ( self , groupid , adminid ) :
2016-05-25 09:52:53 +00:00
self . groupid = groupid # ID del gruppo in cui si sta svolgendo una partita
self . adminid = adminid # ID telegram dell'utente che ha creato la partita con /newgame
self . players = list ( ) # Lista dei giocatori in partita
2016-05-22 17:13:26 +02:00
self . tokill = list ( ) # Giocatori che verranno uccisi all'endday
self . phase = ' Join ' # Fase di gioco: 'Join', 'Voting', 'Ended'
2016-04-21 20:20:26 +02:00
def message ( self , bot , text ) :
2016-05-25 09:52:53 +00:00
""" Manda un messaggio nel gruppo. """
2016-04-25 18:30:49 +02:00
bot . sendMessage ( self . groupid , text )
2016-04-21 20:20:26 +02:00
def adminmessage ( self , bot , text ) :
2016-05-25 09:52:53 +00:00
""" Manda un messaggio privato al creatore della partita. """
2016-04-25 18:30:49 +02:00
bot . sendMessage ( self . adminid , text )
2016-04-21 20:20:26 +02:00
def mifiamessage ( self , bot , text ) :
2016-05-25 09:52:53 +00:00
""" Manda un messaggio privato a tutti i Mifiosi nella partita. """
2016-04-21 20:20:26 +02:00
# Trova tutti i mifiosi nell'elenco dei giocatori
for player in self . players :
if isinstance ( player . role , Mifioso ) :
player . message ( bot , text )
# Inoltra il messaggio all'admin
self . adminmessage ( bot , text )
2016-04-22 19:21:50 +02:00
def findplayerbyid ( self , tid ) - > Player :
2016-05-25 09:52:53 +00:00
""" Trova il giocatore con un certo id. """
2016-04-22 19:21:50 +02:00
for player in self . players :
if player . tid == tid :
return player
else :
return None
def findplayerbyusername ( self , tusername ) - > Player :
2016-05-25 09:52:53 +00:00
""" Trova il giocatore con un certo username. """
2016-04-22 19:21:50 +02:00
for player in self . players :
2016-04-23 17:07:09 +02:00
if player . tusername . lower ( ) == tusername . lower ( ) :
2016-04-22 19:21:50 +02:00
return player
else :
return None
2016-05-03 11:32:30 +00:00
def assignroles ( self , bot , mifia = 0 , investigatore = 0 , angelo = 0 ) :
2016-05-25 09:52:53 +00:00
""" Assegna ruoli casuali a tutti i giocatori. """
2016-04-22 19:55:24 +02:00
random . seed ( )
playersleft = self . players . copy ( )
random . shuffle ( playersleft )
2016-04-23 18:26:32 +02:00
# Seleziona mifiosi
2016-04-22 19:55:24 +02:00
while mifia > 0 :
try :
selected = playersleft . pop ( )
except IndexError :
raise IndexError ( " Non ci sono abbastanza giocatori! " )
else :
selected . role = Mifioso ( )
mifia - = 1
2016-04-23 18:26:32 +02:00
# Seleziona detective
2016-04-22 19:55:24 +02:00
while investigatore > 0 :
try :
selected = playersleft . pop ( )
except IndexError :
raise IndexError ( " Non ci sono abbastanza giocatori! " )
else :
selected . role = Investigatore ( )
investigatore - = 1
2016-05-25 09:52:53 +00:00
# Seleziona angeli
2016-05-03 21:49:17 +02:00
while angelo > 0 :
2016-05-03 11:32:30 +00:00
try :
selected = playersleft . pop ( )
except IndexError :
raise IndexError ( " Non ci sono abbastanza giocatori! " )
else :
selected . role = Angelo ( )
angelo - = 1
2016-04-22 19:55:24 +02:00
# Assegna il ruolo di Royal a tutti gli altri
for player in playersleft :
player . role = Royal ( )
2016-04-23 18:26:32 +02:00
# Manda i ruoli assegnati a tutti
for player in self . players :
player . message ( bot , " Ti è stato assegnato il ruolo di {0} {1} . " . format ( player . role . icon , player . role . name ) )
2016-04-22 19:55:24 +02:00
2016-04-22 21:14:14 +02:00
def updatevotes ( self ) :
2016-05-25 09:52:53 +00:00
""" Aggiorna il conteggio dei voti di tutti i giocatori. """
2016-04-22 21:14:14 +02:00
for player in self . players :
player . votes = 0
for player in self . players :
2016-04-23 17:37:43 +02:00
if player . votingfor is not None :
player . votingfor . votes + = 1
2016-04-22 21:14:14 +02:00
def mostvotedplayer ( self ) - > Player :
2016-05-25 09:52:53 +00:00
""" Trova il giocatore più votato. """
2016-04-22 21:14:14 +02:00
mostvoted = None
self . updatevotes ( )
for player in self . players :
2016-04-23 17:37:43 +02:00
# Temo di aver fatto un disastro. Ma finchè va...
if mostvoted is None and player . votes == 0 :
pass
elif ( mostvoted is None and player . votes > = 1 ) or ( player . votes > mostvoted . votes ) :
2016-04-22 21:14:14 +02:00
mostvoted = player
2016-04-23 17:37:43 +02:00
elif mostvoted is not None and player . votes == mostvoted . votes :
2016-05-25 06:57:03 +00:00
# Questo algoritmo non è equo per un pareggio a tre. Riscriverlo se c'è qualche problema
2016-04-22 21:14:14 +02:00
mostvoted = random . choice ( [ player , mostvoted ] )
return mostvoted
def endday ( self , bot ) :
2016-05-25 09:52:53 +00:00
""" Finisci la giornata, esegui gli endday di tutti i giocatori e uccidi il più votato del giorno. """
2016-05-03 10:43:00 +00:00
# Fai gli endday in un certo ordine.
# Si potrebbe fare più velocemente, credo.
# Ma non sto a ottimizzare senza poter eseguire il programma, quindi vado sul sicuro.
# Mifiosi
2016-04-22 21:14:14 +02:00
for player in self . players :
2016-05-03 10:43:00 +00:00
if isinstance ( player . role , Mifioso ) :
2016-05-22 17:13:26 +02:00
player . role . onendday ( bot , self )
2016-05-03 10:43:00 +00:00
# Investigatori
for player in self . players :
if isinstance ( player . role , Investigatore ) :
2016-05-22 17:13:26 +02:00
player . role . onendday ( bot , self )
2016-05-03 11:29:29 +00:00
# Angeli
for player in self . players :
if isinstance ( player . role , Angelo ) :
2016-05-22 17:13:26 +02:00
player . role . onendday ( bot , self )
2016-04-22 21:14:14 +02:00
lynched = self . mostvotedplayer ( )
if lynched is not None :
2016-04-22 21:20:08 +02:00
self . message ( bot , " {0} era il più votato ed è stato ucciso dai Royal. \n "
2016-04-22 21:14:14 +02:00
" Era un {1} {2} . " . format ( lynched . tusername , lynched . role . icon , lynched . role . name ) )
lynched . kill ( )
2016-04-23 17:37:43 +02:00
else :
self . message ( bot , " La Royal Games non è giunta a una decisione in questo giorno e non ha ucciso nessuno. " )
for player in self . players :
player . votingfor = None
2016-04-23 18:26:32 +02:00
# Condizioni di vittoria
royal = 0
mifiosi = 0
for player in self . players :
2016-05-25 06:57:03 +00:00
if player . alive and player . role . team == ' Evil ' :
2016-04-23 18:26:32 +02:00
mifiosi + = 1
2016-05-03 21:49:17 +02:00
elif player . alive and player . role . team == ' Good ' :
2016-04-23 18:26:32 +02:00
royal + = 1
if mifiosi > = royal :
self . message ( bot , " I Mifiosi rimasti sono più dei Royal. \n "
" La Mifia vince! " )
self . endgame ( )
elif mifiosi == 0 :
self . message ( bot , " Tutti i Mifiosi sono stati eliminati. \n "
" La Royal Games vince! " )
self . endgame ( )
def endgame ( self ) :
inprogress . remove ( self )
2016-04-22 21:14:14 +02:00
2016-04-21 22:14:35 +02:00
# Partite in corso
inprogress = list ( )
2016-04-21 20:20:26 +02:00
2016-04-21 23:04:53 +02:00
def findgamebyid ( gid ) - > Game :
2016-05-25 09:52:53 +00:00
""" Trova una partita con un certo id. """
2016-04-21 23:04:53 +02:00
for game in inprogress :
if game . groupid == gid :
return game
2016-04-21 19:52:01 +02:00
# Comandi a cui risponde il bot
2016-04-21 18:57:23 +02:00
def ping ( bot , update ) :
2016-05-25 09:52:53 +00:00
""" Ping! """
2016-04-25 18:30:49 +02:00
bot . sendMessage ( update . message . chat [ ' id ' ] , " Pong! " )
2016-04-21 18:57:23 +02:00
2016-04-21 22:14:35 +02:00
def newgame ( bot , update ) :
2016-05-25 09:52:53 +00:00
""" Crea una nuova partita. """
2016-04-21 22:14:35 +02:00
if update . message . chat [ ' type ' ] != ' private ' :
2016-04-25 19:39:57 +02:00
g = findgamebyid ( update . message . chat [ ' id ' ] )
if g is None :
g = Game ( update . message . chat [ ' id ' ] , update . message . from_user [ ' id ' ] )
inprogress . append ( g )
bot . sendMessage ( update . message . chat [ ' id ' ] , " Partita creata: " + repr ( g ) )
else :
bot . sendMessage ( update . message . chat [ ' id ' ] , " In questo gruppo è già in corso una partita. " )
2016-04-21 22:14:35 +02:00
else :
2016-04-25 18:30:49 +02:00
bot . sendMessage ( update . message . chat [ ' id ' ] , " Non puoi creare una partita in questo tipo di chat! " )
2016-04-21 23:04:53 +02:00
def join ( bot , update ) :
2016-05-25 09:52:53 +00:00
""" Unisciti a una partita. """
2016-04-21 23:04:53 +02:00
game = findgamebyid ( update . message . chat [ ' id ' ] )
if game is not None :
if game . phase == ' Join ' :
2016-04-22 20:39:16 +02:00
p = game . findplayerbyid ( update . message . from_user [ ' id ' ] )
if p is None :
p = Player ( update . message . from_user [ ' id ' ] , update . message . from_user [ ' username ' ] )
game . players . append ( p )
2016-05-22 17:13:26 +02:00
bot . sendMessage ( update . message . chat [ ' id ' ] , " Unito alla partita: " + str ( p . tid ) )
2016-04-22 20:39:16 +02:00
else :
2016-04-25 18:30:49 +02:00
bot . sendMessage ( update . message . chat [ ' id ' ] , " Ti sei già unito alla partita: " + repr ( p ) )
2016-04-22 19:21:50 +02:00
2016-04-23 17:37:43 +02:00
def debug ( bot , update ) :
2016-05-25 09:52:53 +00:00
""" Visualizza tutti i ruoli e gli id. """
2016-04-23 17:37:43 +02:00
game = findgamebyid ( update . message . chat [ ' id ' ] )
if game is None :
2016-04-25 18:30:49 +02:00
bot . sendMessage ( update . message . chat [ ' id ' ] , " In questo gruppo non ci sono partite in corso. " )
2016-04-23 17:37:43 +02:00
else :
if game . adminid == update . message . from_user [ ' id ' ] :
text = " Gruppo: {0} \n " \
" Creatore: {1} \n " \
2016-04-23 18:26:32 +02:00
" Fase: {2} \n " \
2016-04-23 17:37:43 +02:00
" Giocatori partecipanti: \n " . format ( game . groupid , game . adminid , game . phase )
game . updatevotes ( )
# Aggiungi l'elenco dei giocatori
for player in game . players :
if not player . alive :
text + = " \U0001F480 {0} \n " . format ( player . tusername )
elif player . votingfor is not None :
text + = " {0} {1} ( {2} ) vota per {3} \n " \
. format ( player . role . icon , player . tusername , player . votes , player . votingfor . tusername )
else :
text + = " {0} {1} ( {2} ) \n " . format ( player . role . icon , player . tusername , player . votes )
2016-04-25 18:30:49 +02:00
bot . sendMessage ( update . message . from_user [ ' id ' ] , text )
2016-04-23 17:37:43 +02:00
2016-04-22 19:21:50 +02:00
def status ( bot , update ) :
2016-05-25 09:52:53 +00:00
""" Visualizza lo stato della partita. """
2016-04-22 19:21:50 +02:00
game = findgamebyid ( update . message . chat [ ' id ' ] )
if game is None :
2016-04-25 18:30:49 +02:00
bot . sendMessage ( update . message . chat [ ' id ' ] , " In questo gruppo non ci sono partite in corso. " )
2016-04-22 19:21:50 +02:00
else :
text = " Gruppo: {0} \n " \
" Creatore: {1} \n " \
2016-04-23 18:26:32 +02:00
" Fase: {2} \n " \
2016-04-22 19:21:50 +02:00
" Giocatori partecipanti: \n " . format ( game . groupid , game . adminid , game . phase )
2016-04-23 17:37:43 +02:00
game . updatevotes ( )
2016-04-22 19:21:50 +02:00
# Aggiungi l'elenco dei giocatori
for player in game . players :
2016-04-23 17:07:09 +02:00
if not player . alive :
2016-04-23 17:37:43 +02:00
text + = " \U0001F480 {0} \n " . format ( player . tusername )
2016-04-23 17:07:09 +02:00
elif player . votingfor is not None :
2016-04-23 18:26:32 +02:00
text + = " \U0001F610 {0} ( {1} ) vota per {2} \n " \
. format ( player . tusername , player . votes , player . votingfor . tusername )
2016-04-22 19:21:50 +02:00
else :
2016-04-23 18:26:32 +02:00
text + = " \U0001F610 {0} ( {1} ) \n " . format ( player . tusername , player . votes )
2016-04-25 18:30:49 +02:00
bot . sendMessage ( update . message . chat [ ' id ' ] , text )
2016-04-22 19:21:50 +02:00
def endjoin ( bot , update ) :
2016-05-25 09:52:53 +00:00
""" Termina la fase di join e inizia quella di votazione. """
2016-04-22 19:21:50 +02:00
game = findgamebyid ( update . message . chat [ ' id ' ] )
2016-04-22 20:43:23 +02:00
if game is not None and game . phase is ' Join ' and update . message . from_user [ ' id ' ] == game . adminid :
2016-04-22 19:21:50 +02:00
game . phase = ' Voting '
2016-05-22 17:13:26 +02:00
game . message ( bot , " La fase di join è terminata. " )
try :
game . assignroles ( bot , mifia = 1 , investigatore = 0 , angelo = 1 )
except IndexError :
game . message ( bot , " Non ci sono abbastanza giocatori per avviare la partita. \n "
" La partita è annullata. " )
game . endgame ( )
else :
bot . sendMessage ( update . message . chat [ ' id ' ] , " I ruoli sono stati assegnati. \n "
" Controlla la chat con @mifiabot. " )
2016-04-22 19:21:50 +02:00
def vote ( bot , update ) :
2016-05-25 09:52:53 +00:00
""" Vota per uccidere una persona. """
2016-04-22 19:21:50 +02:00
game = findgamebyid ( update . message . chat [ ' id ' ] )
if game is not None and game . phase is ' Voting ' :
player = game . findplayerbyid ( update . message . from_user [ ' id ' ] )
2016-04-23 17:07:09 +02:00
if player is not None and player . alive :
2016-04-22 19:21:50 +02:00
target = game . findplayerbyusername ( update . message . text . split ( ' ' ) [ 1 ] )
if target is not None :
player . votingfor = target
2016-04-25 18:30:49 +02:00
bot . sendMessage ( update . message . chat [ ' id ' ] , " Hai votato per uccidere {0} . " . format ( target . tusername ) )
2016-04-22 19:21:50 +02:00
else :
2016-04-25 18:30:49 +02:00
bot . sendMessage ( update . message . chat [ ' id ' ] , " Il nome utente specificato non esiste. " )
2016-04-22 19:21:50 +02:00
else :
2016-04-25 18:30:49 +02:00
bot . sendMessage ( update . message . chat [ ' id ' ] , " Non puoi votare. Non sei nella partita o sei morto. " )
2016-04-22 19:21:50 +02:00
else :
2016-04-25 18:30:49 +02:00
bot . sendMessage ( update . message . chat [ ' id ' ] , " Nessuna partita in corso trovata. " )
2016-04-21 23:04:53 +02:00
2016-04-21 22:14:35 +02:00
2016-04-22 21:14:14 +02:00
def endday ( bot , update ) :
2016-05-25 09:52:53 +00:00
""" Termina la giornata attuale. """
2016-04-22 21:14:14 +02:00
game = findgamebyid ( update . message . chat [ ' id ' ] )
if game is not None and game . phase is ' Voting ' and update . message . from_user [ ' id ' ] == game . adminid :
game . endday ( bot )
2016-04-23 17:07:09 +02:00
def power ( bot , update ) :
2016-05-25 09:52:53 +00:00
""" Attiva il potere del tuo ruolo. """
2016-04-23 17:07:09 +02:00
if update . message . chat [ ' type ' ] == ' private ' :
# Ho un'idea su come farlo meglio. Forse.
cmd = update . message . text . split ( ' ' , 2 )
game = findgamebyid ( int ( cmd [ 1 ] ) )
if game is not None :
player = game . findplayerbyid ( update . message . from_user [ ' id ' ] )
if player . alive :
player . role . power ( bot , game , player , cmd [ 2 ] )
else :
2016-04-25 18:30:49 +02:00
bot . sendMessage ( update . message . chat [ ' id ' ] , " Sei morto e non puoi usare poteri. " )
2016-04-23 17:07:09 +02:00
else :
2016-04-25 18:30:49 +02:00
bot . sendMessage ( update . message . chat [ ' id ' ] , " Partita non trovata. " )
2016-04-23 17:07:09 +02:00
else :
2016-04-25 18:30:49 +02:00
bot . sendMessage ( update . message . chat [ ' id ' ] , " Per usare /power, scrivimi in chat privata a @mifiabot! " )
2016-04-23 17:07:09 +02:00
2016-04-25 19:39:57 +02:00
2016-04-25 19:44:40 +02:00
def debuggameslist ( bot , update ) :
2016-05-25 09:52:53 +00:00
""" Visualizza l ' elenco delle partite in corso. """
2016-04-25 19:44:40 +02:00
bot . sendMessage ( repr ( inprogress ) )
2016-04-25 18:21:38 +02:00
updater . dispatcher . addHandler ( CommandHandler ( ' ping ' , ping ) )
updater . dispatcher . addHandler ( CommandHandler ( ' newgame ' , newgame ) )
updater . dispatcher . addHandler ( CommandHandler ( ' join ' , join ) )
updater . dispatcher . addHandler ( CommandHandler ( ' debug ' , debug ) )
updater . dispatcher . addHandler ( CommandHandler ( ' endjoin ' , endjoin ) )
updater . dispatcher . addHandler ( CommandHandler ( ' vote ' , vote ) )
2016-05-03 21:55:54 +02:00
updater . dispatcher . addHandler ( CommandHandler ( ' v ' , vote ) )
2016-04-25 18:21:38 +02:00
updater . dispatcher . addHandler ( CommandHandler ( ' endday ' , endday ) )
updater . dispatcher . addHandler ( CommandHandler ( ' power ' , power ) )
updater . dispatcher . addHandler ( CommandHandler ( ' status ' , status ) )
2016-05-03 21:55:54 +02:00
updater . dispatcher . addHandler ( CommandHandler ( ' s ' , status ) )
2016-04-25 19:44:40 +02:00
updater . dispatcher . addHandler ( CommandHandler ( ' debuggameslist ' , debuggameslist ) )
2016-04-21 22:14:35 +02:00
updater . start_polling ( )
2016-04-22 19:21:50 +02:00
updater . idle ( )