comparison src/plugins/plugin_misc_quiz.py @ 536:a31abb97310d

core, plugins: fixed bad namespace in stanza creation
author Goffi <goffi@goffi.org>
date Thu, 01 Nov 2012 22:41:39 +0100
parents 2a072735e459
children f65f5a324bd5
comparison
equal deleted inserted replaced
535:790be337cc41 536:a31abb97310d
119 'param_2': '%(doc_profile)s'}) 119 'param_2': '%(doc_profile)s'})
120 host.trigger.add("MUC user joined", self.userJoinedTrigger) 120 host.trigger.add("MUC user joined", self.userJoinedTrigger)
121 121
122 def createGameElt(self, to_jid, type="normal"): 122 def createGameElt(self, to_jid, type="normal"):
123 type = "normal" if to_jid.resource else "groupchat" 123 type = "normal" if to_jid.resource else "groupchat"
124 elt = domish.Element(('jabber:client','message')) 124 elt = domish.Element((None,'message'))
125 elt["to"] = to_jid.full() 125 elt["to"] = to_jid.full()
126 elt["type"] = type 126 elt["type"] = type
127 elt.addElement((NS_QG, QG_TAG)) 127 elt.addElement((NS_QG, QG_TAG))
128 return elt 128 return elt
129 129
130 def __game_data_to_xml(self, game_data): 130 def __game_data_to_xml(self, game_data):
131 """Convert a game data dict to domish element""" 131 """Convert a game data dict to domish element"""
132 game_data_elt = domish.Element(('','game_data')) 132 game_data_elt = domish.Element((None,'game_data'))
133 for data in game_data: 133 for data in game_data:
134 data_elt = domish.Element(('',data)) 134 data_elt = domish.Element((None,data))
135 data_elt.addContent(game_data[data]) 135 data_elt.addContent(game_data[data])
136 game_data_elt.addChild(data_elt) 136 game_data_elt.addChild(data_elt)
137 return game_data_elt 137 return game_data_elt
138 138
139 def __xml_to_game_data(self, game_data_elt): 139 def __xml_to_game_data(self, game_data_elt):
160 players_data = game_data['players_data'] 160 players_data = game_data['players_data']
161 score = {} 161 score = {}
162 for player in game_data['players']: 162 for player in game_data['players']:
163 score[player] = players_data[player]['score'] 163 score[player] = players_data[player]['score']
164 164
165 answer_result_elt = domish.Element(('','answer_result')) 165 answer_result_elt = domish.Element((None,'answer_result'))
166 answer_result_elt['player'] = player_answering 166 answer_result_elt['player'] = player_answering
167 answer_result_elt['good_answer'] = str(good_answer) 167 answer_result_elt['good_answer'] = str(good_answer)
168 168
169 for player in score: 169 for player in score:
170 score_elt = domish.Element(('',"score")) 170 score_elt = domish.Element((None,"score"))
171 score_elt['player'] = player 171 score_elt['player'] = player
172 score_elt['score'] = str(score[player]) 172 score_elt['score'] = str(score[player])
173 answer_result_elt.addChild(score_elt) 173 answer_result_elt.addChild(score_elt)
174 174
175 return answer_result_elt 175 return answer_result_elt
176 176
177 def __create_started_elt(self, players): 177 def __create_started_elt(self, players):
178 """Create a game_started domish element""" 178 """Create a game_started domish element"""
179 started_elt = domish.Element(('','started')) 179 started_elt = domish.Element((None,'started'))
180 idx = 0 180 idx = 0
181 for player in players: 181 for player in players:
182 player_elt = domish.Element(('','player')) 182 player_elt = domish.Element((None,'player'))
183 player_elt.addContent(player) 183 player_elt.addContent(player)
184 player_elt['index'] = str(idx) 184 player_elt['index'] = str(idx)
185 idx+=1 185 idx+=1
186 started_elt.addChild(player_elt) 186 started_elt.addChild(player_elt)
187 return started_elt 187 return started_elt
188 188
189 def __ask_question(self, question_id, question, timer): 189 def __ask_question(self, question_id, question, timer):
190 """Create a element for asking a question""" 190 """Create a element for asking a question"""
191 question_elt = domish.Element(('','question')) 191 question_elt = domish.Element((None,'question'))
192 question_elt['id'] = question_id 192 question_elt['id'] = question_id
193 question_elt['timer'] = str(timer) 193 question_elt['timer'] = str(timer)
194 question_elt.addContent(question) 194 question_elt.addContent(question)
195 return question_elt 195 return question_elt
196 196