mirror of
https://github.com/ZoiteChat/zoitechat.git
synced 2026-03-10 16:00:18 +00:00
new name after fork
This commit is contained in:
@@ -2,7 +2,7 @@ import inspect
|
||||
import sys
|
||||
from contextlib import contextmanager
|
||||
|
||||
from _hexchat_embedded import ffi, lib
|
||||
from _zoitechat_embedded import ffi, lib
|
||||
|
||||
__all__ = [
|
||||
'EAT_ALL', 'EAT_HEXCHAT', 'EAT_NONE', 'EAT_PLUGIN', 'EAT_XCHAT',
|
||||
@@ -15,7 +15,7 @@ __all__ = [
|
||||
'set_pluginpref', 'strip', 'unhook',
|
||||
]
|
||||
|
||||
__doc__ = 'HexChat Scripting Interface'
|
||||
__doc__ = 'ZoiteChat Scripting Interface'
|
||||
__version__ = (2, 0)
|
||||
__license__ = 'GPL-2.0+'
|
||||
|
||||
@@ -57,7 +57,7 @@ else:
|
||||
|
||||
# ------------ API ------------
|
||||
def prnt(string):
|
||||
lib.hexchat_print(lib.ph, string.encode())
|
||||
lib.zoitechat_print(lib.ph, string.encode())
|
||||
|
||||
|
||||
def emit_print(event_name, *args, **kwargs):
|
||||
@@ -69,33 +69,33 @@ def emit_print(event_name, *args, **kwargs):
|
||||
cargs.append(cstring)
|
||||
|
||||
if time == 0:
|
||||
return lib.hexchat_emit_print(lib.ph, event_name.encode(), *cargs)
|
||||
return lib.zoitechat_emit_print(lib.ph, event_name.encode(), *cargs)
|
||||
|
||||
attrs = lib.hexchat_event_attrs_create(lib.ph)
|
||||
attrs = lib.zoitechat_event_attrs_create(lib.ph)
|
||||
attrs.server_time_utc = time
|
||||
ret = lib.hexchat_emit_print_attrs(lib.ph, attrs, event_name.encode(), *cargs)
|
||||
lib.hexchat_event_attrs_free(lib.ph, attrs)
|
||||
ret = lib.zoitechat_emit_print_attrs(lib.ph, attrs, event_name.encode(), *cargs)
|
||||
lib.zoitechat_event_attrs_free(lib.ph, attrs)
|
||||
return ret
|
||||
|
||||
|
||||
# TODO: this shadows itself. command should be changed to cmd
|
||||
def command(command):
|
||||
lib.hexchat_command(lib.ph, command.encode())
|
||||
lib.zoitechat_command(lib.ph, command.encode())
|
||||
|
||||
|
||||
def nickcmp(string1, string2):
|
||||
return lib.hexchat_nickcmp(lib.ph, string1.encode(), string2.encode())
|
||||
return lib.zoitechat_nickcmp(lib.ph, string1.encode(), string2.encode())
|
||||
|
||||
|
||||
def strip(text, length=-1, flags=3):
|
||||
stripped = lib.hexchat_strip(lib.ph, text.encode(), length, flags)
|
||||
stripped = lib.zoitechat_strip(lib.ph, text.encode(), length, flags)
|
||||
ret = __decode(ffi.string(stripped))
|
||||
lib.hexchat_free(lib.ph, stripped)
|
||||
lib.zoitechat_free(lib.ph, stripped)
|
||||
return ret
|
||||
|
||||
|
||||
def get_info(name):
|
||||
ret = lib.hexchat_get_info(lib.ph, name.encode())
|
||||
ret = lib.zoitechat_get_info(lib.ph, name.encode())
|
||||
if ret == ffi.NULL:
|
||||
return None
|
||||
if name in ('gtkwin_ptr', 'win_ptr'):
|
||||
@@ -109,7 +109,7 @@ def get_info(name):
|
||||
def get_prefs(name):
|
||||
string_out = ffi.new('char**')
|
||||
int_out = ffi.new('int*')
|
||||
_type = lib.hexchat_get_prefs(lib.ph, name.encode(), string_out, int_out)
|
||||
_type = lib.zoitechat_get_prefs(lib.ph, name.encode(), string_out, int_out)
|
||||
if _type == 0:
|
||||
return None
|
||||
|
||||
@@ -136,7 +136,7 @@ __FIELD_CACHE = {}
|
||||
|
||||
|
||||
def __get_fields(name):
|
||||
return __FIELD_CACHE.setdefault(name, __cstrarray_to_list(lib.hexchat_list_fields(lib.ph, name)))
|
||||
return __FIELD_CACHE.setdefault(name, __cstrarray_to_list(lib.zoitechat_list_fields(lib.ph, name)))
|
||||
|
||||
|
||||
__FIELD_PROPERTY_CACHE = {}
|
||||
@@ -177,7 +177,7 @@ def get_list(name):
|
||||
if name not in __get_fields(b'lists'):
|
||||
raise KeyError('list not available')
|
||||
|
||||
list_ = lib.hexchat_list_get(lib.ph, name)
|
||||
list_ = lib.zoitechat_list_get(lib.ph, name)
|
||||
if list_ == ffi.NULL:
|
||||
return None
|
||||
|
||||
@@ -185,7 +185,7 @@ def get_list(name):
|
||||
fields = __get_fields(name)
|
||||
|
||||
def string_getter(field):
|
||||
string = lib.hexchat_list_str(lib.ph, list_, field)
|
||||
string = lib.zoitechat_list_str(lib.ph, list_, field)
|
||||
if string != ffi.NULL:
|
||||
return __decode(ffi.string(string))
|
||||
|
||||
@@ -193,20 +193,20 @@ def get_list(name):
|
||||
|
||||
def ptr_getter(field):
|
||||
if field == b'context':
|
||||
ptr = lib.hexchat_list_str(lib.ph, list_, field)
|
||||
ctx = ffi.cast('hexchat_context*', ptr)
|
||||
ptr = lib.zoitechat_list_str(lib.ph, list_, field)
|
||||
ctx = ffi.cast('zoitechat_context*', ptr)
|
||||
return Context(ctx)
|
||||
|
||||
return None
|
||||
|
||||
getters = {
|
||||
ord('s'): string_getter,
|
||||
ord('i'): lambda field: lib.hexchat_list_int(lib.ph, list_, field),
|
||||
ord('t'): lambda field: lib.hexchat_list_time(lib.ph, list_, field),
|
||||
ord('i'): lambda field: lib.zoitechat_list_int(lib.ph, list_, field),
|
||||
ord('t'): lambda field: lib.zoitechat_list_time(lib.ph, list_, field),
|
||||
ord('p'): ptr_getter,
|
||||
}
|
||||
|
||||
while lib.hexchat_list_next(lib.ph, list_) == 1:
|
||||
while lib.zoitechat_list_next(lib.ph, list_) == 1:
|
||||
item = ListItem(orig_name)
|
||||
for _field in fields:
|
||||
getter = getters.get(get_getter(_field))
|
||||
@@ -216,7 +216,7 @@ def get_list(name):
|
||||
|
||||
ret.append(item)
|
||||
|
||||
lib.hexchat_list_free(lib.ph, list_)
|
||||
lib.zoitechat_list_free(lib.ph, list_)
|
||||
return ret
|
||||
|
||||
|
||||
@@ -224,50 +224,50 @@ def get_list(name):
|
||||
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,
|
||||
handle = lib.zoitechat_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
|
||||
hook.zoitechat_hook = handle
|
||||
return id(hook)
|
||||
|
||||
|
||||
def hook_print(name, callback, userdata=None, priority=PRI_NORM):
|
||||
plugin = __get_current_plugin()
|
||||
hook = plugin.add_hook(callback, userdata)
|
||||
handle = lib.hexchat_hook_print(lib.ph, name.encode(), priority, lib._on_print_hook, hook.handle)
|
||||
hook.hexchat_hook = handle
|
||||
handle = lib.zoitechat_hook_print(lib.ph, name.encode(), priority, lib._on_print_hook, hook.handle)
|
||||
hook.zoitechat_hook = handle
|
||||
return id(hook)
|
||||
|
||||
|
||||
def hook_print_attrs(name, callback, userdata=None, priority=PRI_NORM):
|
||||
plugin = __get_current_plugin()
|
||||
hook = plugin.add_hook(callback, userdata)
|
||||
handle = lib.hexchat_hook_print_attrs(lib.ph, name.encode(), priority, lib._on_print_attrs_hook, hook.handle)
|
||||
hook.hexchat_hook = handle
|
||||
handle = lib.zoitechat_hook_print_attrs(lib.ph, name.encode(), priority, lib._on_print_attrs_hook, hook.handle)
|
||||
hook.zoitechat_hook = handle
|
||||
return id(hook)
|
||||
|
||||
|
||||
def hook_server(name, callback, userdata=None, priority=PRI_NORM):
|
||||
plugin = __get_current_plugin()
|
||||
hook = plugin.add_hook(callback, userdata)
|
||||
handle = lib.hexchat_hook_server(lib.ph, name.encode(), priority, lib._on_server_hook, hook.handle)
|
||||
hook.hexchat_hook = handle
|
||||
handle = lib.zoitechat_hook_server(lib.ph, name.encode(), priority, lib._on_server_hook, hook.handle)
|
||||
hook.zoitechat_hook = handle
|
||||
return id(hook)
|
||||
|
||||
|
||||
def hook_server_attrs(name, callback, userdata=None, priority=PRI_NORM):
|
||||
plugin = __get_current_plugin()
|
||||
hook = plugin.add_hook(callback, userdata)
|
||||
handle = lib.hexchat_hook_server_attrs(lib.ph, name.encode(), priority, lib._on_server_attrs_hook, hook.handle)
|
||||
hook.hexchat_hook = handle
|
||||
handle = lib.zoitechat_hook_server_attrs(lib.ph, name.encode(), priority, lib._on_server_attrs_hook, hook.handle)
|
||||
hook.zoitechat_hook = handle
|
||||
return id(hook)
|
||||
|
||||
|
||||
def hook_timer(timeout, callback, userdata=None):
|
||||
plugin = __get_current_plugin()
|
||||
hook = plugin.add_hook(callback, userdata)
|
||||
handle = lib.hexchat_hook_timer(lib.ph, timeout, lib._on_timer_hook, hook.handle)
|
||||
hook.hexchat_hook = handle
|
||||
handle = lib.zoitechat_hook_timer(lib.ph, timeout, lib._on_timer_hook, hook.handle)
|
||||
hook.zoitechat_hook = handle
|
||||
return id(hook)
|
||||
|
||||
|
||||
@@ -284,10 +284,10 @@ def unhook(handle):
|
||||
|
||||
def set_pluginpref(name, value):
|
||||
if isinstance(value, str):
|
||||
return bool(lib.hexchat_pluginpref_set_str(lib.ph, name.encode(), value.encode()))
|
||||
return bool(lib.zoitechat_pluginpref_set_str(lib.ph, name.encode(), value.encode()))
|
||||
|
||||
if isinstance(value, int):
|
||||
return bool(lib.hexchat_pluginpref_set_int(lib.ph, name.encode(), value))
|
||||
return bool(lib.zoitechat_pluginpref_set_int(lib.ph, name.encode(), value))
|
||||
|
||||
# XXX: This should probably raise but this keeps API
|
||||
return False
|
||||
@@ -296,7 +296,7 @@ def set_pluginpref(name, value):
|
||||
def get_pluginpref(name):
|
||||
name = name.encode()
|
||||
string_out = ffi.new('char[512]')
|
||||
if lib.hexchat_pluginpref_get_str(lib.ph, name, string_out) != 1:
|
||||
if lib.zoitechat_pluginpref_get_str(lib.ph, name, string_out) != 1:
|
||||
return None
|
||||
|
||||
string = ffi.string(string_out)
|
||||
@@ -305,7 +305,7 @@ def get_pluginpref(name):
|
||||
if len(string) > 12: # Can't be a number
|
||||
return __decode(string)
|
||||
|
||||
number = lib.hexchat_pluginpref_get_int(lib.ph, name)
|
||||
number = lib.zoitechat_pluginpref_get_int(lib.ph, name)
|
||||
if number == -1 and string != b'-1':
|
||||
return __decode(string)
|
||||
|
||||
@@ -313,12 +313,12 @@ def get_pluginpref(name):
|
||||
|
||||
|
||||
def del_pluginpref(name):
|
||||
return bool(lib.hexchat_pluginpref_delete(lib.ph, name.encode()))
|
||||
return bool(lib.zoitechat_pluginpref_delete(lib.ph, name.encode()))
|
||||
|
||||
|
||||
def list_pluginpref():
|
||||
prefs_str = ffi.new('char[4096]')
|
||||
if lib.hexchat_pluginpref_list(lib.ph, prefs_str) == 1:
|
||||
if lib.zoitechat_pluginpref_list(lib.ph, prefs_str) == 1:
|
||||
return __decode(ffi.string(prefs_str)).split(',')
|
||||
|
||||
return []
|
||||
@@ -336,18 +336,18 @@ class Context:
|
||||
|
||||
@contextmanager
|
||||
def __change_context(self):
|
||||
old_ctx = lib.hexchat_get_context(lib.ph)
|
||||
old_ctx = lib.zoitechat_get_context(lib.ph)
|
||||
if not self.set():
|
||||
# XXX: Behavior change, previously used wrong context
|
||||
lib.hexchat_print(lib.ph, b'Context object refers to closed context, ignoring call')
|
||||
lib.zoitechat_print(lib.ph, b'Context object refers to closed context, ignoring call')
|
||||
return
|
||||
|
||||
yield
|
||||
lib.hexchat_set_context(lib.ph, old_ctx)
|
||||
lib.zoitechat_set_context(lib.ph, old_ctx)
|
||||
|
||||
def set(self):
|
||||
# XXX: API addition, C plugin silently ignored failure
|
||||
return bool(lib.hexchat_set_context(lib.ph, self._ctx))
|
||||
return bool(lib.zoitechat_set_context(lib.ph, self._ctx))
|
||||
|
||||
def prnt(self, string):
|
||||
with self.__change_context():
|
||||
@@ -372,14 +372,14 @@ class Context:
|
||||
|
||||
|
||||
def get_context():
|
||||
ctx = lib.hexchat_get_context(lib.ph)
|
||||
ctx = lib.zoitechat_get_context(lib.ph)
|
||||
return Context(ctx)
|
||||
|
||||
|
||||
def find_context(server=None, channel=None):
|
||||
server = server.encode() if server is not None else ffi.NULL
|
||||
channel = channel.encode() if channel is not None else ffi.NULL
|
||||
ctx = lib.hexchat_find_context(lib.ph, server, channel)
|
||||
ctx = lib.zoitechat_find_context(lib.ph, server, channel)
|
||||
if ctx == ffi.NULL:
|
||||
return None
|
||||
|
||||
@@ -5,11 +5,11 @@ import cffi
|
||||
|
||||
builder = cffi.FFI()
|
||||
|
||||
# hexchat-plugin.h
|
||||
# zoitechat-plugin.h
|
||||
with open(sys.argv[1]) as f:
|
||||
output = []
|
||||
eat_until_endif = 0
|
||||
# This is very specific to hexchat-plugin.h, it is not a cpp
|
||||
# This is very specific to zoitechat-plugin.h, it is not a cpp
|
||||
for line in f:
|
||||
if line.startswith('#define'):
|
||||
continue
|
||||
@@ -21,7 +21,7 @@ with open(sys.argv[1]) as f:
|
||||
eat_until_endif += 1
|
||||
elif line.startswith('#endif'):
|
||||
eat_until_endif -= 1
|
||||
elif eat_until_endif and '_hexchat_context' not in line:
|
||||
elif eat_until_endif and '_zoitechat_context' not in line:
|
||||
continue
|
||||
else:
|
||||
output.append(line)
|
||||
@@ -36,30 +36,30 @@ extern "Python" int _on_say_command(char **, char **, void *);
|
||||
|
||||
extern "Python" int _on_command_hook(char **, char **, void *);
|
||||
extern "Python" int _on_print_hook(char **, void *);
|
||||
extern "Python" int _on_print_attrs_hook(char **, hexchat_event_attrs *, void *);
|
||||
extern "Python" int _on_print_attrs_hook(char **, zoitechat_event_attrs *, void *);
|
||||
extern "Python" int _on_server_hook(char **, char **, void *);
|
||||
extern "Python" int _on_server_attrs_hook(char **, char **, hexchat_event_attrs *, void *);
|
||||
extern "Python" int _on_server_attrs_hook(char **, char **, zoitechat_event_attrs *, void *);
|
||||
extern "Python" int _on_timer_hook(void *);
|
||||
|
||||
extern "Python" int _on_plugin_init(char **, char **, char **, char *, char *);
|
||||
extern "Python" int _on_plugin_deinit(void);
|
||||
|
||||
static hexchat_plugin *ph;
|
||||
static zoitechat_plugin *ph;
|
||||
''')
|
||||
|
||||
builder.set_source('_hexchat_embedded', '''
|
||||
builder.set_source('_zoitechat_embedded', '''
|
||||
/* Python's header defines these.. */
|
||||
#undef HAVE_MEMRCHR
|
||||
#undef HAVE_STRINGS_H
|
||||
|
||||
#include "config.h"
|
||||
#include "hexchat-plugin.h"
|
||||
#include "zoitechat-plugin.h"
|
||||
|
||||
static hexchat_plugin *ph;
|
||||
static zoitechat_plugin *ph;
|
||||
CFFI_DLLEXPORT int _on_plugin_init(char **, char **, char **, char *, char *);
|
||||
CFFI_DLLEXPORT int _on_plugin_deinit(void);
|
||||
|
||||
int hexchat_plugin_init(hexchat_plugin *plugin_handle,
|
||||
int zoitechat_plugin_init(zoitechat_plugin *plugin_handle,
|
||||
char **name_out, char **description_out,
|
||||
char **version_out, char *arg)
|
||||
{
|
||||
@@ -73,7 +73,7 @@ int hexchat_plugin_init(hexchat_plugin *plugin_handle,
|
||||
return _on_plugin_init(name_out, description_out, version_out, arg, HEXCHATLIBDIR);
|
||||
}
|
||||
|
||||
int hexchat_plugin_deinit(void)
|
||||
int zoitechat_plugin_deinit(void)
|
||||
{
|
||||
int ret = _on_plugin_deinit();
|
||||
ph = NULL;
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
from _hexchat import *
|
||||
@@ -14,17 +14,17 @@ else
|
||||
endif
|
||||
|
||||
python3_source = custom_target('python-bindings',
|
||||
input: ['../../src/common/hexchat-plugin.h', 'python.py'],
|
||||
input: ['../../src/common/zoitechat-plugin.h', 'python.py'],
|
||||
output: 'python.c',
|
||||
command: [find_program('generate_plugin.py'), '@INPUT@', '@OUTPUT@']
|
||||
)
|
||||
|
||||
install_data(['_hexchat.py', 'hexchat.py', 'xchat.py'],
|
||||
install_dir: join_paths(get_option('libdir'), 'hexchat/python')
|
||||
install_data(['_zoitechat.py', 'zoitechat.py', 'xchat.py'],
|
||||
install_dir: join_paths(get_option('libdir'), 'zoitechat/python')
|
||||
)
|
||||
|
||||
shared_module('python', python3_source,
|
||||
dependencies: [hexchat_plugin_dep, python_dep],
|
||||
dependencies: [zoitechat_plugin_dep, python_dep],
|
||||
install: true,
|
||||
install_dir: plugindir,
|
||||
name_prefix: '',
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
EXPORTS
|
||||
hexchat_plugin_init
|
||||
hexchat_plugin_deinit
|
||||
zoitechat_plugin_init
|
||||
zoitechat_plugin_deinit
|
||||
|
||||
@@ -9,7 +9,7 @@ import traceback
|
||||
import weakref
|
||||
from contextlib import contextmanager
|
||||
|
||||
from _hexchat_embedded import ffi, lib
|
||||
from _zoitechat_embedded import ffi, lib
|
||||
|
||||
if sys.version_info < (3, 0):
|
||||
from io import BytesIO as HelpEater
|
||||
@@ -17,17 +17,17 @@ else:
|
||||
from io import StringIO as HelpEater
|
||||
|
||||
if not hasattr(sys, 'argv'):
|
||||
sys.argv = ['<hexchat>']
|
||||
sys.argv = ['<zoitechat>']
|
||||
|
||||
VERSION = b'2.0' # Sync with hexchat.__version__
|
||||
VERSION = b'2.0' # Sync with zoitechat.__version__
|
||||
PLUGIN_NAME = ffi.new('char[]', b'Python')
|
||||
PLUGIN_DESC = ffi.new('char[]', b'Python %d.%d scripting interface' % (sys.version_info[0], sys.version_info[1]))
|
||||
PLUGIN_VERSION = ffi.new('char[]', VERSION)
|
||||
|
||||
# TODO: Constants should be screaming snake case
|
||||
hexchat = None
|
||||
zoitechat = None
|
||||
local_interp = None
|
||||
hexchat_stdout = None
|
||||
zoitechat_stdout = None
|
||||
plugins = set()
|
||||
|
||||
|
||||
@@ -36,8 +36,8 @@ def redirected_stdout():
|
||||
sys.stdout = sys.__stdout__
|
||||
sys.stderr = sys.__stderr__
|
||||
yield
|
||||
sys.stdout = hexchat_stdout
|
||||
sys.stderr = hexchat_stdout
|
||||
sys.stdout = zoitechat_stdout
|
||||
sys.stderr = zoitechat_stdout
|
||||
|
||||
|
||||
if os.getenv('HEXCHAT_LOG_PYTHON'):
|
||||
@@ -59,13 +59,13 @@ class Stdout:
|
||||
idx = string.rfind(b'\n')
|
||||
if idx != -1:
|
||||
self.buffer += string[:idx]
|
||||
lib.hexchat_print(lib.ph, bytes(self.buffer))
|
||||
lib.zoitechat_print(lib.ph, bytes(self.buffer))
|
||||
self.buffer = bytearray(string[idx + 1:])
|
||||
else:
|
||||
self.buffer += string
|
||||
|
||||
def flush(self):
|
||||
lib.hexchat_print(lib.ph, bytes(self.buffer))
|
||||
lib.zoitechat_print(lib.ph, bytes(self.buffer))
|
||||
self.buffer = bytearray()
|
||||
|
||||
def isatty(self):
|
||||
@@ -86,14 +86,14 @@ class Hook:
|
||||
self.plugin = weakref.proxy(plugin)
|
||||
self.callback = callback
|
||||
self.userdata = userdata
|
||||
self.hexchat_hook = None
|
||||
self.zoitechat_hook = None
|
||||
self.handle = ffi.new_handle(weakref.proxy(self))
|
||||
|
||||
def __del__(self):
|
||||
log('Removing hook', id(self))
|
||||
if self.is_unload is False:
|
||||
assert self.hexchat_hook is not None
|
||||
lib.hexchat_unhook(lib.ph, self.hexchat_hook)
|
||||
assert self.zoitechat_hook is not None
|
||||
lib.zoitechat_unhook(lib.ph, self.zoitechat_hook)
|
||||
|
||||
|
||||
if sys.version_info[0] == 2:
|
||||
@@ -159,17 +159,17 @@ class Plugin:
|
||||
self.name = self.globals['__module_name__']
|
||||
|
||||
except KeyError:
|
||||
lib.hexchat_print(lib.ph, b'Failed to load module: __module_name__ must be set')
|
||||
lib.zoitechat_print(lib.ph, b'Failed to load module: __module_name__ must be set')
|
||||
|
||||
return False
|
||||
|
||||
self.version = self.globals.get('__module_version__', '')
|
||||
self.description = self.globals.get('__module_description__', '')
|
||||
self.ph = lib.hexchat_plugingui_add(lib.ph, filename.encode(), self.name.encode(),
|
||||
self.ph = lib.zoitechat_plugingui_add(lib.ph, filename.encode(), self.name.encode(),
|
||||
self.description.encode(), self.version.encode(), ffi.NULL)
|
||||
|
||||
except Exception as e:
|
||||
lib.hexchat_print(lib.ph, 'Failed to load module: {}'.format(e).encode())
|
||||
lib.zoitechat_print(lib.ph, 'Failed to load module: {}'.format(e).encode())
|
||||
traceback.print_exc()
|
||||
return False
|
||||
|
||||
@@ -188,7 +188,7 @@ class Plugin:
|
||||
|
||||
del self.hooks
|
||||
if self.ph is not None:
|
||||
lib.hexchat_plugingui_remove(lib.ph, self.ph)
|
||||
lib.zoitechat_plugingui_remove(lib.ph, self.ph)
|
||||
|
||||
|
||||
if sys.version_info[0] == 2:
|
||||
@@ -292,7 +292,7 @@ def _on_timer_hook(userdata):
|
||||
return 1
|
||||
|
||||
try:
|
||||
# Avoid calling hexchat_unhook twice if unnecessary
|
||||
# Avoid calling zoitechat_unhook twice if unnecessary
|
||||
hook.is_unload = True
|
||||
except ReferenceError:
|
||||
# hook is a weak reference, it might have been destroyed by the callback
|
||||
@@ -310,10 +310,10 @@ def _on_timer_hook(userdata):
|
||||
|
||||
@ffi.def_extern(error=3)
|
||||
def _on_say_command(word, word_eol, userdata):
|
||||
channel = ffi.string(lib.hexchat_get_info(lib.ph, b'channel'))
|
||||
channel = ffi.string(lib.zoitechat_get_info(lib.ph, b'channel'))
|
||||
if channel == b'>>python<<':
|
||||
python = ffi.string(word_eol[1])
|
||||
lib.hexchat_print(lib.ph, b'>>> ' + python)
|
||||
lib.zoitechat_print(lib.ph, b'>>> ' + python)
|
||||
exec_in_interp(__decode(python))
|
||||
return 1
|
||||
|
||||
@@ -323,7 +323,7 @@ def _on_say_command(word, word_eol, userdata):
|
||||
def load_filename(filename):
|
||||
filename = os.path.expanduser(filename)
|
||||
if not os.path.isabs(filename):
|
||||
configdir = __decode(ffi.string(lib.hexchat_get_info(lib.ph, b'configdir')))
|
||||
configdir = __decode(ffi.string(lib.zoitechat_get_info(lib.ph, b'configdir')))
|
||||
|
||||
filename = os.path.join(configdir, 'addons', filename)
|
||||
|
||||
@@ -366,7 +366,7 @@ def change_cwd(path):
|
||||
|
||||
|
||||
def autoload():
|
||||
configdir = __decode(ffi.string(lib.hexchat_get_info(lib.ph, b'configdir')))
|
||||
configdir = __decode(ffi.string(lib.zoitechat_get_info(lib.ph, b'configdir')))
|
||||
addondir = os.path.join(configdir, 'addons')
|
||||
try:
|
||||
with change_cwd(addondir): # Maintaining old behavior
|
||||
@@ -382,7 +382,7 @@ def autoload():
|
||||
|
||||
def list_plugins():
|
||||
if not plugins:
|
||||
lib.hexchat_print(lib.ph, b'No python modules loaded')
|
||||
lib.zoitechat_print(lib.ph, b'No python modules loaded')
|
||||
return
|
||||
|
||||
tbl_headers = [b'Name', b'Version', b'Filename', b'Description']
|
||||
@@ -404,9 +404,9 @@ def list_plugins():
|
||||
]
|
||||
|
||||
for row in tbl:
|
||||
lib.hexchat_print(lib.ph, b' '.join(item.ljust(column_sizes[i])
|
||||
lib.zoitechat_print(lib.ph, b' '.join(item.ljust(column_sizes[i])
|
||||
for i, item in enumerate(row)))
|
||||
lib.hexchat_print(lib.ph, b'')
|
||||
lib.zoitechat_print(lib.ph, b'')
|
||||
|
||||
|
||||
def exec_in_interp(python):
|
||||
@@ -418,16 +418,16 @@ def exec_in_interp(python):
|
||||
if local_interp is None:
|
||||
local_interp = Plugin()
|
||||
local_interp.locals = {}
|
||||
local_interp.globals['hexchat'] = hexchat
|
||||
local_interp.globals['zoitechat'] = zoitechat
|
||||
|
||||
code = compile_line(python)
|
||||
try:
|
||||
ret = eval(code, local_interp.globals, local_interp.locals)
|
||||
if ret is not None:
|
||||
lib.hexchat_print(lib.ph, '{}'.format(ret).encode())
|
||||
lib.zoitechat_print(lib.ph, '{}'.format(ret).encode())
|
||||
|
||||
except Exception as e:
|
||||
traceback.print_exc(file=hexchat_stdout)
|
||||
traceback.print_exc(file=zoitechat_stdout)
|
||||
|
||||
|
||||
@ffi.def_extern()
|
||||
@@ -475,32 +475,32 @@ def _on_py_command(word, word_eol, userdata):
|
||||
elif subcmd == 'unload':
|
||||
name = __decode(ffi.string(word[3]))
|
||||
if not unload_name(name):
|
||||
lib.hexchat_print(lib.ph, b'Can\'t find a python plugin with that name')
|
||||
lib.zoitechat_print(lib.ph, b'Can\'t find a python plugin with that name')
|
||||
|
||||
elif subcmd == 'reload':
|
||||
name = __decode(ffi.string(word[3]))
|
||||
if not reload_name(name):
|
||||
lib.hexchat_print(lib.ph, b'Can\'t find a python plugin with that name')
|
||||
lib.zoitechat_print(lib.ph, b'Can\'t find a python plugin with that name')
|
||||
|
||||
elif subcmd == 'console':
|
||||
lib.hexchat_command(lib.ph, b'QUERY >>python<<')
|
||||
lib.zoitechat_command(lib.ph, b'QUERY >>python<<')
|
||||
|
||||
elif subcmd == 'list':
|
||||
list_plugins()
|
||||
|
||||
elif subcmd == 'about':
|
||||
lib.hexchat_print(lib.ph, b'HexChat Python interface version ' + VERSION)
|
||||
lib.zoitechat_print(lib.ph, b'ZoiteChat Python interface version ' + VERSION)
|
||||
|
||||
else:
|
||||
lib.hexchat_command(lib.ph, b'HELP PY')
|
||||
lib.zoitechat_command(lib.ph, b'HELP PY')
|
||||
|
||||
return 3
|
||||
|
||||
|
||||
@ffi.def_extern()
|
||||
def _on_plugin_init(plugin_name, plugin_desc, plugin_version, arg, libdir):
|
||||
global hexchat
|
||||
global hexchat_stdout
|
||||
global zoitechat
|
||||
global zoitechat_stdout
|
||||
|
||||
signal.signal(signal.SIGINT, signal.SIG_DFL)
|
||||
|
||||
@@ -512,23 +512,23 @@ def _on_plugin_init(plugin_name, plugin_desc, plugin_version, arg, libdir):
|
||||
libdir = __decode(ffi.string(libdir))
|
||||
modpath = os.path.join(libdir, '..', 'python')
|
||||
sys.path.append(os.path.abspath(modpath))
|
||||
hexchat = importlib.import_module('hexchat')
|
||||
zoitechat = importlib.import_module('zoitechat')
|
||||
|
||||
except (UnicodeDecodeError, ImportError) as e:
|
||||
lib.hexchat_print(lib.ph, b'Failed to import module: ' + repr(e).encode())
|
||||
lib.zoitechat_print(lib.ph, b'Failed to import module: ' + repr(e).encode())
|
||||
|
||||
return 0
|
||||
|
||||
hexchat_stdout = Stdout()
|
||||
sys.stdout = hexchat_stdout
|
||||
sys.stderr = hexchat_stdout
|
||||
zoitechat_stdout = Stdout()
|
||||
sys.stdout = zoitechat_stdout
|
||||
sys.stderr = zoitechat_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>
|
||||
lib.zoitechat_hook_command(lib.ph, b'', 0, lib._on_say_command, ffi.NULL, ffi.NULL)
|
||||
lib.zoitechat_hook_command(lib.ph, b'LOAD', 0, lib._on_load_command, ffi.NULL, ffi.NULL)
|
||||
lib.zoitechat_hook_command(lib.ph, b'UNLOAD', 0, lib._on_unload_command, ffi.NULL, ffi.NULL)
|
||||
lib.zoitechat_hook_command(lib.ph, b'RELOAD', 0, lib._on_reload_command, ffi.NULL, ffi.NULL)
|
||||
lib.zoitechat_hook_command(lib.ph, b'PY', 0, lib._on_py_command, b'''Usage: /PY LOAD <filename>
|
||||
UNLOAD <filename|name>
|
||||
RELOAD <filename|name>
|
||||
LIST
|
||||
@@ -536,7 +536,7 @@ def _on_plugin_init(plugin_name, plugin_desc, plugin_version, arg, libdir):
|
||||
CONSOLE
|
||||
ABOUT''', ffi.NULL)
|
||||
|
||||
lib.hexchat_print(lib.ph, b'Python interface loaded')
|
||||
lib.zoitechat_print(lib.ph, b'Python interface loaded')
|
||||
autoload()
|
||||
return 1
|
||||
|
||||
@@ -544,19 +544,19 @@ def _on_plugin_init(plugin_name, plugin_desc, plugin_version, arg, libdir):
|
||||
@ffi.def_extern()
|
||||
def _on_plugin_deinit():
|
||||
global local_interp
|
||||
global hexchat
|
||||
global hexchat_stdout
|
||||
global zoitechat
|
||||
global zoitechat_stdout
|
||||
global plugins
|
||||
|
||||
plugins = set()
|
||||
local_interp = None
|
||||
hexchat = None
|
||||
hexchat_stdout = None
|
||||
zoitechat = None
|
||||
zoitechat_stdout = None
|
||||
sys.stdout = sys.__stdout__
|
||||
sys.stderr = sys.__stderr__
|
||||
pydoc.help = pydoc.Helper()
|
||||
|
||||
for mod in ('_hexchat', 'hexchat', 'xchat', '_hexchat_embedded'):
|
||||
for mod in ('_zoitechat', 'zoitechat', 'xchat', '_zoitechat_embedded'):
|
||||
try:
|
||||
del sys.modules[mod]
|
||||
|
||||
|
||||
@@ -22,15 +22,15 @@
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
|
||||
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
|
||||
<Import Project="..\..\win32\hexchat.props" />
|
||||
<Import Project="..\..\win32\zoitechat.props" />
|
||||
<PropertyGroup>
|
||||
<TargetName>$(Python3Output)</TargetName>
|
||||
<OutDir>$(HexChatRel)plugins\</OutDir>
|
||||
<OutDir>$(ZoiteChatRel)plugins\</OutDir>
|
||||
</PropertyGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
|
||||
<ClCompile>
|
||||
<PreprocessorDefinitions>WIN32;NDEBUG;_WINDOWS;_USRDLL;PYTHON_EXPORTS;$(OwnFlags);%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>$(Glib);$(Python3Path)\include;..\..\src\common;$(HexChatLib);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(Glib);$(Python3Path)\include;..\..\src\common;$(ZoiteChatLib);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<ModuleDefinitionFile>python.def</ModuleDefinitionFile>
|
||||
@@ -38,13 +38,13 @@
|
||||
<AdditionalLibraryDirectories>$(DepsRoot)\lib;$(Python3Path)\libs;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
<PreBuildEvent>
|
||||
<Command>"$(Python3Path)\python.exe" generate_plugin.py ..\..\src\common\hexchat-plugin.h python.py "$(IntDir)python.c"</Command>
|
||||
<Command>"$(Python3Path)\python.exe" generate_plugin.py ..\..\src\common\zoitechat-plugin.h python.py "$(IntDir)python.c"</Command>
|
||||
</PreBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||
<ClCompile>
|
||||
<PreprocessorDefinitions>WIN32;_WIN64;_AMD64_;NDEBUG;_WINDOWS;_USRDLL;PYTHON_EXPORTS;$(OwnFlags);%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<AdditionalIncludeDirectories>$(Glib);$(Python3Path)\include;..\..\src\common;$(HexChatLib);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(Glib);$(Python3Path)\include;..\..\src\common;$(ZoiteChatLib);%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<ModuleDefinitionFile>python.def</ModuleDefinitionFile>
|
||||
@@ -52,16 +52,16 @@
|
||||
<AdditionalLibraryDirectories>$(DepsRoot)\lib;$(Python3Path)\libs;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
</Link>
|
||||
<PreBuildEvent>
|
||||
<Command>"$(Python3Path)\python.exe" generate_plugin.py ..\..\src\common\hexchat-plugin.h python.py "$(IntDir)python.c"</Command>
|
||||
<Command>"$(Python3Path)\python.exe" generate_plugin.py ..\..\src\common\zoitechat-plugin.h python.py "$(IntDir)python.c"</Command>
|
||||
</PreBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<None Include="generate_plugin.py" />
|
||||
<None Include="hexchat.py" />
|
||||
<None Include="zoitechat.py" />
|
||||
<None Include="python.def" />
|
||||
<None Include="python.py" />
|
||||
<None Include="xchat.py" />
|
||||
<None Include="_hexchat.py" />
|
||||
<None Include="_zoitechat.py" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="$(IntDir)python.c" />
|
||||
|
||||
@@ -15,13 +15,13 @@
|
||||
<None Include="python.def">
|
||||
<Filter>Resource Files</Filter>
|
||||
</None>
|
||||
<None Include="_hexchat.py">
|
||||
<None Include="_zoitechat.py">
|
||||
<Filter>Source Files</Filter>
|
||||
</None>
|
||||
<None Include="generate_plugin.py">
|
||||
<Filter>Source Files</Filter>
|
||||
</None>
|
||||
<None Include="hexchat.py">
|
||||
<None Include="zoitechat.py">
|
||||
<Filter>Source Files</Filter>
|
||||
</None>
|
||||
<None Include="python.py">
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
# HexChat Python Module Style Guide
|
||||
# ZoiteChat Python Module Style Guide
|
||||
|
||||
(This is a work in progress).
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
from _hexchat import *
|
||||
from _zoitechat import *
|
||||
|
||||
1
plugins/python/zoitechat.py
Normal file
1
plugins/python/zoitechat.py
Normal file
@@ -0,0 +1 @@
|
||||
from _zoitechat import *
|
||||
Reference in New Issue
Block a user