# -*- coding: utf-8 -*- # # Copyright (C) 2011 Sebastien Helleu # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 3 of the License, or # (at your option) any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # # # Display time used to execute a WeeChat command. # # History: # # 2011-11-17, Sebastien Helleu : # start dev # SCRIPT_NAME = 'time' SCRIPT_AUTHOR = 'Sebastien Helleu ' SCRIPT_VERSION = '0.1-dev' SCRIPT_LICENSE = 'GPL3' SCRIPT_DESC = 'Display time used to execute a WeeChat command' SCRIPT_COMMAND = 'ctime' import_weechat_ok = True import_other_ok = True try: import weechat except ImportError: import_weechat_ok = False try: from datetime import datetime except ImportError as e: print('Missing package(s) for %s: %s' % (SCRIPT_NAME, e)) import_other_ok = False def cmdtime_cmd_cb(data, buffer, args): if args: if not weechat.string_is_command_char(args): args = '/' + args d1 = datetime.now() weechat.command(buffer, args) diff = datetime.now() - d1 weechat.prnt('', 'time = %s' % diff) return weechat.WEECHAT_RC_OK if __name__ == '__main__' and import_other_ok: if import_weechat_ok: if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT_DESC, '', ''): weechat.hook_command(SCRIPT_COMMAND, SCRIPT_DESC, ' []', 'command: any WeeChat command\n' ' args: arguments for command\n' 'Example:\n' ' /' + SCRIPT_COMMAND + ' filter toggle', '%(weechat_commands)|%(plugins_commands)', 'cmdtime_cmd_cb', '')