plugins room_game, quiz, radiocol, tarot: use JID instead of unicode in many methods + class attributes

This commit is contained in:
souliane 2015-03-11 12:36:22 +01:00
commit 5ef7999fa7

View file

@ -58,9 +58,9 @@ class Quiz(object):
log.info(_("Plugin Quiz initialization"))
self.inheritFromRoomGame(host)
RoomGame._init_(self, host, PLUGIN_INFO, (NS_QG, QG_TAG), game_init={'stage': None}, player_init={'score': 0})
host.bridge.addMethod("quizGameLaunch", ".plugin", in_sign='asss', out_sign='', method=self.prepareRoom) # args: players, room_jid, profile
host.bridge.addMethod("quizGameCreate", ".plugin", in_sign='sass', out_sign='', method=self.createGame) # args: room_jid, players, profile
host.bridge.addMethod("quizGameReady", ".plugin", in_sign='sss', out_sign='', method=self.playerReady) # args: player, referee, profile
host.bridge.addMethod("quizGameLaunch", ".plugin", in_sign='asss', out_sign='', method=self._prepareRoom) # args: players, room_jid, profile
host.bridge.addMethod("quizGameCreate", ".plugin", in_sign='sass', out_sign='', method=self._createGame) # args: room_jid, players, profile
host.bridge.addMethod("quizGameReady", ".plugin", in_sign='sss', out_sign='', method=self._playerReady) # args: player, referee, profile
host.bridge.addMethod("quizGameAnswer", ".plugin", in_sign='ssss', out_sign='', method=self.playerAnswer)
host.bridge.addSignal("quizGameStarted", ".plugin", signature='ssass') # args: room_jid, referee, players, profile
host.bridge.addSignal("quizGameNew", ".plugin",
@ -192,7 +192,7 @@ class Quiz(object):
def timerExpired(self, room_jid, profile):
"""Called when nobody answered the question in time"""
game_data = self.games[room_jid.userhost()]
game_data = self.games[room_jid]
game_data['stage'] = 'expired'
mess = self.createGameElt(room_jid)
expired_elt = mess.firstChildElement().addElement('timer_expired')
@ -201,7 +201,7 @@ class Quiz(object):
def pauseTimer(self, room_jid):
"""Stop the timer and save the time left"""
game_data = self.games[room_jid.userhost()]
game_data = self.games[room_jid]
left = max(0, game_data["timer"].getTime() - time())
game_data['timer'].cancel()
game_data['time_left'] = int(left)
@ -210,7 +210,7 @@ class Quiz(object):
def restartTimer(self, room_jid, profile):
"""Restart a timer with the saved time"""
game_data = self.games[room_jid.userhost()]
game_data = self.games[room_jid]
assert game_data['time_left'] is not None
mess = self.createGameElt(room_jid)
restarted_elt = mess.firstChildElement().addElement('timer_restarted')
@ -223,7 +223,7 @@ class Quiz(object):
def askQuestion(self, room_jid, profile):
"""Ask a new question"""
game_data = self.games[room_jid.userhost()]
game_data = self.games[room_jid]
game_data['stage'] = "question"
game_data['question_id'] = "1"
timer = 30
@ -235,7 +235,7 @@ class Quiz(object):
def checkAnswer(self, room_jid, player, answer, profile):
"""Check if the answer given is right"""
game_data = self.games[room_jid.userhost()]
game_data = self.games[room_jid]
players_data = game_data['players_data']
good_answer = game_data['question_id'] == "1" and answer == "42"
players_data[player]['score'] += 1 if good_answer else -1
@ -264,7 +264,7 @@ Attention, tu es prêt ?""")}
from_jid = jid.JID(mess_elt['from'])
room_jid = jid.JID(from_jid.userhost())
game_elt = mess_elt.firstChildElement()
game_data = self.games[room_jid.userhost()]
game_data = self.games[room_jid]
if 'players_data' in game_data:
players_data = game_data['players_data']
@ -278,8 +278,8 @@ Attention, tu es prêt ?""")}
elif elt.name == 'player_ready': # ready to play
player = elt['player']
status = self.games[room_jid.userhost()]['status']
nb_players = len(self.games[room_jid.userhost()]['players'])
status = self.games[room_jid]['status']
nb_players = len(self.games[room_jid]['players'])
status[player] = 'ready'
log.debug(_('Player %(player)s is ready to start [status: %(status)s]') % {'player': player, 'status': status})
if status.values().count('ready') == nb_players: # everybody is ready, we can start the game
@ -294,7 +294,7 @@ Attention, tu es prêt ?""")}
elif elt.name == 'player_answer':
player = elt['player']
pause = game_data['stage'] == 'question' # we pause the game only if we are have a question at the moment
#we first send a buzzer message
# we first send a buzzer message
mess = self.createGameElt(room_jid)
buzzer_elt = mess.firstChildElement().addElement('player_buzzed')
buzzer_elt['player'] = player
@ -302,7 +302,7 @@ Attention, tu es prêt ?""")}
self.host.profiles[profile].xmlstream.send(mess)
if pause:
self.pauseTimer(room_jid)
#and we send the player answer
# and we send the player answer
mess = self.createGameElt(room_jid)
_answer = unicode(elt)
say_elt = mess.firstChildElement().addElement('player_says')