示例#1
0
def _on_plugin_init(plugin_name, plugin_desc, plugin_version, arg, libdir):
    global hexchat
    global hexchat_stdout

    signal.signal(signal.SIGINT, signal.SIG_DFL)

    plugin_name[0] = PLUGIN_NAME
    plugin_desc[0] = PLUGIN_DESC
    plugin_version[0] = PLUGIN_VERSION

    try:
        libdir = __decode(ffi.string(libdir))
        modpath = os.path.join(libdir, '..', 'python')
        sys.path.append(os.path.abspath(modpath))
        hexchat = importlib.import_module('hexchat')

    except (UnicodeDecodeError, ImportError) as e:
        lib.hexchat_print(lib.ph,
                          b'Failed to import module: ' + repr(e).encode())

        return 0

    hexchat_stdout = Stdout()
    sys.stdout = hexchat_stdout
    sys.stderr = hexchat_stdout
    pydoc.help = pydoc.Helper(HelpEater(), HelpEater())

    lib.hexchat_hook_command(lib.ph, b'', 0, lib._on_say_command, ffi.NULL,
                             ffi.NULL)
    lib.hexchat_hook_command(lib.ph, b'LOAD', 0, lib._on_load_command,
                             ffi.NULL, ffi.NULL)
    lib.hexchat_hook_command(lib.ph, b'UNLOAD', 0, lib._on_unload_command,
                             ffi.NULL, ffi.NULL)
    lib.hexchat_hook_command(lib.ph, b'RELOAD', 0, lib._on_reload_command,
                             ffi.NULL, ffi.NULL)
    lib.hexchat_hook_command(
        lib.ph, b'PY', 0, lib._on_py_command, b'''Usage: /PY LOAD   <filename>
           UNLOAD <filename|name>
           RELOAD <filename|name>
           LIST
           EXEC <command>
           CONSOLE
           ABOUT''', ffi.NULL)

    lib.hexchat_print(lib.ph, b'Python interface loaded')
    autoload()
    return 1
示例#2
0
def hook_command(command, callback, userdata=None, priority=PRI_NORM, help=None):
    plugin = __get_current_plugin()
    hook = plugin.add_hook(callback, userdata)
    handle = lib.hexchat_hook_command(lib.ph, command.encode(), priority, lib._on_command_hook,
                                      help.encode() if help is not None else ffi.NULL, hook.handle)

    hook.hexchat_hook = handle
    return id(hook)
示例#3
0
def hook_command(command, callback, userdata=None, priority=PRI_NORM, help=None):
    plugin = __get_current_plugin()
    hook = plugin.add_hook(callback, userdata)
    handle = lib.hexchat_hook_command(lib.ph, command.encode(), priority, lib._on_command_hook,
                                      help.encode() if help is not None else ffi.NULL, hook.handle)

    hook.hexchat_hook = handle
    return id(hook)
示例#4
0
文件: python.py 项目: hexchat/hexchat
def _on_plugin_init(plugin_name, plugin_desc, plugin_version, arg, libdir):
    global hexchat
    global hexchat_stdout

    signal.signal(signal.SIGINT, signal.SIG_DFL)

    plugin_name[0] = PLUGIN_NAME
    plugin_desc[0] = PLUGIN_DESC
    plugin_version[0] = PLUGIN_VERSION

    try:
        libdir = __decode(ffi.string(libdir))
        modpath = os.path.join(libdir, '..', 'python')
        sys.path.append(os.path.abspath(modpath))
        hexchat = importlib.import_module('hexchat')

    except (UnicodeDecodeError, ImportError) as e:
        lib.hexchat_print(lib.ph, b'Failed to import module: ' + repr(e).encode())

        return 0

    hexchat_stdout = Stdout()
    sys.stdout = hexchat_stdout
    sys.stderr = hexchat_stdout
    pydoc.help = pydoc.Helper(HelpEater(), HelpEater())

    lib.hexchat_hook_command(lib.ph, b'', 0, lib._on_say_command, ffi.NULL, ffi.NULL)
    lib.hexchat_hook_command(lib.ph, b'LOAD', 0, lib._on_load_command, ffi.NULL, ffi.NULL)
    lib.hexchat_hook_command(lib.ph, b'UNLOAD', 0, lib._on_unload_command, ffi.NULL, ffi.NULL)
    lib.hexchat_hook_command(lib.ph, b'RELOAD', 0, lib._on_reload_command, ffi.NULL, ffi.NULL)
    lib.hexchat_hook_command(lib.ph, b'PY', 0, lib._on_py_command, b'''Usage: /PY LOAD   <filename>
           UNLOAD <filename|name>
           RELOAD <filename|name>
           LIST
           EXEC <command>
           CONSOLE
           ABOUT''', ffi.NULL)

    lib.hexchat_print(lib.ph, b'Python interface loaded')
    autoload()
    return 1