1
Fork 0
mirror of https://github.com/RYGhub/royal-mifia.git synced 2024-11-25 15:14:18 +00:00

Impedita creazione di due partite nello stesso gruppo

This commit is contained in:
Steffo 2016-04-25 19:39:57 +02:00
parent d70c3e3f7c
commit 82b9d6ad9c

View file

@ -2,6 +2,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from telegram.ext import Updater, CommandHandler from telegram.ext import Updater, CommandHandler
import filemanager import filemanager
import random
import logging import logging
logger = logging.getLogger() logger = logging.getLogger()
@ -140,7 +141,6 @@ class Game:
return None return None
def assignroles(self, bot, mifia=0, investigatore=0): def assignroles(self, bot, mifia=0, investigatore=0):
import random
random.seed() random.seed()
playersleft = self.players.copy() playersleft = self.players.copy()
random.shuffle(playersleft) random.shuffle(playersleft)
@ -187,7 +187,6 @@ class Game:
mostvoted = player mostvoted = player
elif mostvoted is not None and player.votes == mostvoted.votes: elif mostvoted is not None and player.votes == mostvoted.votes:
# Non sono sicuro che questo algoritmo sia effettivamente il più equo. Ma vabbè, non succederà mai # Non sono sicuro che questo algoritmo sia effettivamente il più equo. Ma vabbè, non succederà mai
import random
mostvoted = random.choice([player, mostvoted]) mostvoted = random.choice([player, mostvoted])
return mostvoted return mostvoted
@ -242,9 +241,13 @@ def ping(bot, update):
def newgame(bot, update): def newgame(bot, update):
if update.message.chat['type'] != 'private': if update.message.chat['type'] != 'private':
g = findgamebyid(update.message.chat['id'])
if g is None:
g = Game(update.message.chat['id'], update.message.from_user['id']) g = Game(update.message.chat['id'], update.message.from_user['id'])
inprogress.append(g) inprogress.append(g)
bot.sendMessage(update.message.chat['id'], "Partita creata: " + repr(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.")
else: else:
bot.sendMessage(update.message.chat['id'], "Non puoi creare una partita in questo tipo di chat!") bot.sendMessage(update.message.chat['id'], "Non puoi creare una partita in questo tipo di chat!")
@ -356,6 +359,7 @@ def power(bot, update):
else: else:
bot.sendMessage(update.message.chat['id'], "Per usare /power, scrivimi in chat privata a @mifiabot!") bot.sendMessage(update.message.chat['id'], "Per usare /power, scrivimi in chat privata a @mifiabot!")
updater.dispatcher.addHandler(CommandHandler('ping', ping)) updater.dispatcher.addHandler(CommandHandler('ping', ping))
updater.dispatcher.addHandler(CommandHandler('newgame', newgame)) updater.dispatcher.addHandler(CommandHandler('newgame', newgame))
updater.dispatcher.addHandler(CommandHandler('join', join)) updater.dispatcher.addHandler(CommandHandler('join', join))