comparison src/plugins/plugin_misc_text_commands.py @ 993:301b342c697a

core: use of the new core.log module: /!\ this is a massive refactoring and was largely automated, it probably did bring some bugs /!\
author Goffi <goffi@goffi.org>
date Sat, 19 Apr 2014 19:19:19 +0200
parents 059b56cbd247
children 291eb8216f6e
comparison
equal deleted inserted replaced
992:f51a1895275c 993:301b342c697a
21 from sat.core.constants import Const as C 21 from sat.core.constants import Const as C
22 from sat.core.sat_main import MessageSentAndStored 22 from sat.core.sat_main import MessageSentAndStored
23 from twisted.words.protocols.jabber import jid 23 from twisted.words.protocols.jabber import jid
24 from twisted.internet import defer 24 from twisted.internet import defer
25 from twisted.python.failure import Failure 25 from twisted.python.failure import Failure
26 from logging import debug, info, warning, error 26 from sat.core.log import getLogger
27 log = getLogger(__name__)
27 28
28 PLUGIN_INFO = { 29 PLUGIN_INFO = {
29 "name": "Text commands", 30 "name": "Text commands",
30 "import_name": C.TEXT_CMDS, 31 "import_name": C.TEXT_CMDS,
31 "type": "Misc", 32 "type": "Misc",
41 #FIXME: doc strings for commands have to be translatable 42 #FIXME: doc strings for commands have to be translatable
42 # plugins need a dynamic translation system (translation 43 # plugins need a dynamic translation system (translation
43 # should be downloadable independently) 44 # should be downloadable independently)
44 45
45 def __init__(self, host): 46 def __init__(self, host):
46 info(_("Text commands initialization")) 47 log.info(_("Text commands initialization"))
47 self.host = host 48 self.host = host
48 host.trigger.add("sendMessage", self.sendMessageTrigger) 49 host.trigger.add("sendMessage", self.sendMessageTrigger)
49 self._commands = {} 50 self._commands = {}
50 self._whois = [] 51 self._whois = []
51 self.registerTextCommands(self) 52 self.registerTextCommands(self)
57 """ 58 """
58 for attr in dir(instance): 59 for attr in dir(instance):
59 if attr.startswith('cmd_'): 60 if attr.startswith('cmd_'):
60 cmd = getattr(instance, attr) 61 cmd = getattr(instance, attr)
61 if not callable(cmd): 62 if not callable(cmd):
62 warning(_("Skipping not callable [%s] attribute") % attr) 63 log.warning(_("Skipping not callable [%s] attribute") % attr)
63 continue 64 continue
64 cmd_name = attr[4:] 65 cmd_name = attr[4:]
65 if not cmd_name: 66 if not cmd_name:
66 warning(_("Skipping cmd_ method")) 67 log.warning(_("Skipping cmd_ method"))
67 if cmd_name in self._commands: 68 if cmd_name in self._commands:
68 suff=2 69 suff=2
69 while (cmd_name + str(suff)) in self._commands: 70 while (cmd_name + str(suff)) in self._commands:
70 suff+=1 71 suff+=1
71 new_name = cmd_name + str(suff) 72 new_name = cmd_name + str(suff)
72 warning(_("Conflict for command [%(old_name)s], renaming it to [%(new_name)s]") % {'old_name': cmd_name, 'new_name': new_name}) 73 log.warning(_("Conflict for command [%(old_name)s], renaming it to [%(new_name)s]") % {'old_name': cmd_name, 'new_name': new_name})
73 cmd_name = new_name 74 cmd_name = new_name
74 self._commands[cmd_name] = cmd 75 self._commands[cmd_name] = cmd
75 info(_("Registered text command [%s]") % cmd_name) 76 log.info(_("Registered text command [%s]") % cmd_name)
76 77
77 def addWhoIsCb(self, callback, priority=0): 78 def addWhoIsCb(self, callback, priority=0):
78 """Add a callback which give information to the /whois command 79 """Add a callback which give information to the /whois command
79 @param callback: a callback which will be called with the following arguments 80 @param callback: a callback which will be called with the following arguments
80 - whois_msg: list of information strings to display, callback need to append its own strings to it 81 - whois_msg: list of information strings to display, callback need to append its own strings to it
158 159
159 self.host.bridge.newMessage(unicode(mess_data["to"]), message, mess_data['type'], unicode(_from), {}, profile=profile) 160 self.host.bridge.newMessage(unicode(mess_data["to"]), message, mess_data['type'], unicode(_from), {}, profile=profile)
160 161
161 def cmd_whois(self, mess_data, profile): 162 def cmd_whois(self, mess_data, profile):
162 """show informations on entity""" 163 """show informations on entity"""
163 debug("Catched whois command") 164 log.debug("Catched whois command")
164 165
165 entity = mess_data["unparsed"].strip() 166 entity = mess_data["unparsed"].strip()
166 167
167 if mess_data['type'] == "groupchat": 168 if mess_data['type'] == "groupchat":
168 room = mess_data["to"].userhostJID() 169 room = mess_data["to"].userhostJID()
169 try: 170 try:
170 if self.host.plugins["XEP-0045"].isNickInRoom(room, entity, profile): 171 if self.host.plugins["XEP-0045"].isNickInRoom(room, entity, profile):
171 entity = u"%s/%s" % (room, entity) 172 entity = u"%s/%s" % (room, entity)
172 except KeyError: 173 except KeyError:
173 warning("plugin XEP-0045 is not present") 174 log.warning("plugin XEP-0045 is not present")
174 175
175 if not entity: 176 if not entity:
176 target_jid = mess_data["to"] 177 target_jid = mess_data["to"]
177 else: 178 else:
178 try: 179 try: