comparison libervia.py @ 36:1d406077b49b

Tarot Game: first draft
author Goffi <goffi@goffi.org>
date Tue, 17 May 2011 01:33:12 +0200
parents d43d6e4b9dc8
children b306aa090438
comparison
equal deleted inserted replaced
35:d43d6e4b9dc8 36:1d406077b49b
64 64
65 class BridgeCall(LiberviaJsonProxy): 65 class BridgeCall(LiberviaJsonProxy):
66 def __init__(self): 66 def __init__(self):
67 LiberviaJsonProxy.__init__(self, "/json_api", 67 LiberviaJsonProxy.__init__(self, "/json_api",
68 ["getContacts", "sendMessage", "sendMblog", "getMblogNodes", "getProfileJid", "getHistory", 68 ["getContacts", "sendMessage", "sendMblog", "getMblogNodes", "getProfileJid", "getHistory",
69 "getPresenceStatus", "getRoomJoined", "launchTarotGame"]) 69 "getPresenceStatus", "getRoomJoined", "launchTarotGame", "getTarotCardsPaths"])
70 70
71 class BridgeSignals(LiberviaJsonProxy): 71 class BridgeSignals(LiberviaJsonProxy):
72 def __init__(self): 72 def __init__(self):
73 LiberviaJsonProxy.__init__(self, "/json_signal_api", 73 LiberviaJsonProxy.__init__(self, "/json_signal_api",
74 ["getSignals"]) 74 ["getSignals"])
165 self._roomJoinedCb(*args) 165 self._roomJoinedCb(*args)
166 elif name == 'roomUserJoined': 166 elif name == 'roomUserJoined':
167 self._roomUserJoinedCb(*args) 167 self._roomUserJoinedCb(*args)
168 elif name == 'roomUserLeft': 168 elif name == 'roomUserLeft':
169 self._roomUserLeftCb(*args) 169 self._roomUserLeftCb(*args)
170 elif name == 'tarotGameStarted':
171 self._tarotGameStartedCb(*args)
170 172
171 def _getProfileJidCB(self, jid): 173 def _getProfileJidCB(self, jid):
172 self.whoami = JID(jid) 174 self.whoami = JID(jid)
173 #we can now ask our status 175 #we can now ask our status
174 self.bridge.call('getPresenceStatus', self._getPresenceStatusCB) 176 self.bridge.call('getPresenceStatus', self._getPresenceStatusCB)
187 if data.has_key('groups'): 189 if data.has_key('groups'):
188 _groups = set(data['groups'].split() if data['groups'] else []) 190 _groups = set(data['groups'].split() if data['groups'] else [])
189 else: 191 else:
190 _groups=None 192 _groups=None
191 for panel in self.mpanels: 193 for panel in self.mpanels:
192 if isinstance(panel,MicroblogPanel) and (panel.isJidAccepted(sender) or _groups == None or _groups.intersection(panel.accepted_groups)): 194 if isinstance(panel,MicroblogPanel) and (panel.isJidAccepted(sender) or _groups == None or _groups.intersection(panel.accepted_groups)): #TODO: check this
193 content = data['content'] 195 content = data['content']
194 author = data.get('author') 196 author = data.get('author')
195 timestamp = float(data.get('timestamp',0)) #XXX: int doesn't work here 197 timestamp = float(data.get('timestamp',0)) #XXX: int doesn't work here
196 panel.addEntry(content, author, timestamp) 198 panel.addEntry(content, author, timestamp)
197 199
229 231
230 def _roomUserLeftCb(self, room_id, room_service, user_nick, user_data): 232 def _roomUserLeftCb(self, room_id, room_service, user_nick, user_data):
231 for panel in self.mpanels + self.other_panels: 233 for panel in self.mpanels + self.other_panels:
232 if isinstance(panel,ChatPanel) and panel.type == 'group' and panel.target.bare == "%s@%s" % (room_id, room_service): 234 if isinstance(panel,ChatPanel) and panel.type == 'group' and panel.target.bare == "%s@%s" % (room_id, room_service):
233 panel.userLeft(user_nick, user_data) 235 panel.userLeft(user_nick, user_data)
234 236
237 def _tarotGameStartedCb(self, room_jid, referee, players):
238 print ("Tarot Game Started \o/")
239 for panel in self.mpanels + self.other_panels:
240 if isinstance(panel,ChatPanel) and panel.type == 'group' and panel.target.bare == room_jid:
241 panel.startGame("Tarot", referee, players)
242
235 def _getPresenceStatusCB(self, presence_data): 243 def _getPresenceStatusCB(self, presence_data):
236 for entity in presence_data: 244 for entity in presence_data:
237 for resource in presence_data[entity]: 245 for resource in presence_data[entity]:
238 args = presence_data[entity][resource] 246 args = presence_data[entity][resource]
239 self._presenceUpdateCb("%s/%s" % (entity, resource), *args) 247 self._presenceUpdateCb("%s/%s" % (entity, resource), *args)