comparison src/plugins/plugin_xep_0045.py @ 926:d609581bf74a

plugin text commands: refactoring, text now only contain main commands, and other plugin can add commands themselve: - registerTextCommands can be called by a plugin in its __init__ method, it looks for methods starting with "cmd_" and register them as new commands - addWhoIsCb: add a callback to /whois command, the callback can complete whois informations - plugins parrot, XEP-0045 and XEP-0092 now manage their own commands
author Goffi <goffi@goffi.org>
date Mon, 24 Mar 2014 10:57:15 +0100
parents 1a759096ccbd
children 73873e9b56f7
comparison
equal deleted inserted replaced
925:5c78cefd233f 926:d609581bf74a
41 "name": "XEP 0045 Plugin", 41 "name": "XEP 0045 Plugin",
42 "import_name": "XEP-0045", 42 "import_name": "XEP-0045",
43 "type": "XEP", 43 "type": "XEP",
44 "protocols": ["XEP-0045"], 44 "protocols": ["XEP-0045"],
45 "dependencies": [], 45 "dependencies": [],
46 "recommendations": [C.TEXT_CMDS],
46 "main": "XEP_0045", 47 "main": "XEP_0045",
47 "handler": "yes", 48 "handler": "yes",
48 "description": _("""Implementation of Multi-User Chat""") 49 "description": _("""Implementation of Multi-User Chat""")
49 } 50 }
50 51
72 host.bridge.addSignal("roomUserJoined", ".plugin", signature='ssa{ss}s') # args: room_jid, user_nick, user_data, profile 73 host.bridge.addSignal("roomUserJoined", ".plugin", signature='ssa{ss}s') # args: room_jid, user_nick, user_data, profile
73 host.bridge.addSignal("roomUserLeft", ".plugin", signature='ssa{ss}s') # args: room_jid, user_nick, user_data, profile 74 host.bridge.addSignal("roomUserLeft", ".plugin", signature='ssa{ss}s') # args: room_jid, user_nick, user_data, profile
74 host.bridge.addSignal("roomUserChangedNick", ".plugin", signature='ssss') # args: room_jid, old_nick, new_nick, profile 75 host.bridge.addSignal("roomUserChangedNick", ".plugin", signature='ssss') # args: room_jid, old_nick, new_nick, profile
75 host.bridge.addSignal("roomNewSubject", ".plugin", signature='sss') # args: room_jid, subject, profile 76 host.bridge.addSignal("roomNewSubject", ".plugin", signature='sss') # args: room_jid, subject, profile
76 self.__submit_conf_id = host.registerCallback(self._submitConfiguration, with_data=True) 77 self.__submit_conf_id = host.registerCallback(self._submitConfiguration, with_data=True)
78 try:
79 self.host.plugins[C.TEXT_CMDS].registerTextCommands(self)
80 except KeyError:
81 info(_("Text commands not available"))
77 82
78 def __check_profile(self, profile): 83 def __check_profile(self, profile):
79 """check if profile is used and connected 84 """check if profile is used and connected
80 if profile known but disconnected, remove it from known profiles 85 if profile known but disconnected, remove it from known profiles
81 @param profile: profile to check 86 @param profile: profile to check
345 return self.leave(jid.JID(room_jid_s), profile_key) 350 return self.leave(jid.JID(room_jid_s), profile_key)
346 351
347 def getHandler(self, profile): 352 def getHandler(self, profile):
348 self.clients[profile] = SatMUCClient(self) 353 self.clients[profile] = SatMUCClient(self)
349 return self.clients[profile] 354 return self.clients[profile]
355
356 # Text commands #
357
358 def cmd_nick(self, mess_data, profile):
359 """change nickname"""
360 debug("Catched nick command")
361
362 if mess_data['type'] != "groupchat":
363 #/nick command does nothing if we are not on a group chat
364 info("Ignoring /nick command on a non groupchat message")
365
366 return True
367
368 nick = mess_data["unparsed"].strip()
369 room = mess_data["to"]
370
371 self.nick(room, nick, profile)
372
373 return False
374
375 def cmd_join(self, mess_data, profile):
376 """join a new room (on the same service if full jid is not specified)"""
377 debug("Catched join command")
378
379 if mess_data['type'] != "groupchat":
380 #/leave command does nothing if we are not on a group chat
381 info("Ignoring /join command on a non groupchat message")
382 return True
383
384 if mess_data["unparsed"].strip():
385 room = self.host.plugins[C.TEXT_CMDS].getRoomJID(mess_data["unparsed"].strip(), mess_data["to"].host)
386 nick = (self.getRoomNick(mess_data["to"].userhost(), profile) or
387 self.host.getClient(profile).jid.user)
388 self.join(room, nick, {}, profile)
389
390 return False
391
392 def cmd_leave(self, mess_data, profile):
393 """quit a room"""
394 debug("Catched leave command")
395
396 if mess_data['type'] != "groupchat":
397 #/leave command does nothing if we are not on a group chat
398 info("Ignoring /leave command on a non groupchat message")
399 return True
400
401 if mess_data["unparsed"].strip():
402 room = self.host.plugins[C.TEXT_CMDS].getRoomJID(mess_data["unparsed"].strip(), mess_data["to"].host)
403 else:
404 room = mess_data["to"]
405
406 self.leave(room, profile)
407
408 return False
409
410 def cmd_part(self, mess_data, profile):
411 """just a synonym of /leave"""
412 return self.cmd_leave(mess_data, profile)
413
414 def cmd_title(self, mess_data, profile):
415 """change room's subject"""
416 debug("Catched title command")
417
418 if mess_data['type'] != "groupchat":
419 #/leave command does nothing if we are not on a group chat
420 info("Ignoring /title command on a non groupchat message")
421 return True
422
423 subject = mess_data["unparsed"].strip()
424
425 if subject:
426 room = mess_data["to"]
427 self.subject(room, subject, profile)
428
429 return False
430
431 def cmd_topic(self, mess_data, profile):
432 """just a synonym of /title"""
433 return self.cmd_title(mess_data, profile)
350 434
351 435
352 class SatMUCClient (muc.MUCClient): 436 class SatMUCClient (muc.MUCClient):
353 #implements(iwokkel.IDisco) 437 #implements(iwokkel.IDisco)
354 438