changeset 952:2899474aefd7

irccd: misc cleanups
author David Demelier <markand@malikania.fr>
date Sun, 17 Jan 2021 19:05:39 +0100
parents d11c2b0001ce
children ab43ba409f9d
files lib/CMakeLists.txt lib/irccd/config.h.in lib/irccd/jsapi-plugin.c
diffstat 3 files changed, 36 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/lib/CMakeLists.txt	Sat Jan 16 23:25:32 2021 +0100
+++ b/lib/CMakeLists.txt	Sun Jan 17 19:05:39 2021 +0100
@@ -100,3 +100,5 @@
 if (IRCCD_WITH_JS)
 	target_link_libraries(libirccd libirccd-duktape)
 endif ()
+
+source_group(TREE ${libirccd_SOURCE_DIR} FILES ${SOURCES})
--- a/lib/irccd/config.h.in	Sat Jan 16 23:25:32 2021 +0100
+++ b/lib/irccd/config.h.in	Sun Jan 17 19:05:39 2021 +0100
@@ -1,3 +1,21 @@
+/*
+ * config.h.h -- irccd configuration
+ *
+ * Copyright (c) 2013-2021 David Demelier <markand@malikania.fr>
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
 #ifndef IRCCD_CONFIG_H
 #define IRCCD_CONFIG_H
 
--- a/lib/irccd/jsapi-plugin.c	Sat Jan 16 23:25:32 2021 +0100
+++ b/lib/irccd/jsapi-plugin.c	Sun Jan 17 19:05:39 2021 +0100
@@ -130,13 +130,25 @@
 	return get(ctx, IRC_JSAPI_PLUGIN_PROP_PATHS);
 }
 
+static struct irc_plugin *
+find(duk_context *ctx)
+{
+	const char *name = duk_require_string(ctx, 0);
+	struct irc_plugin *plg = irc_bot_find_plugin(name);
+
+	if (!plg)
+		duk_error(ctx, DUK_ERR_REFERENCE_ERROR, "plugin %s not found", name);
+
+	return plg;
+}
+
 static duk_ret_t
 Plugin_info(duk_context *ctx)
 {
 	struct irc_plugin *p;
 
 	if (duk_get_top(ctx) >= 1)
-		p = irc_bot_find_plugin(duk_require_string(ctx, 0));
+		p = find(ctx);
 	else
 		p = irc_jsapi_plugin_self(ctx);
 
@@ -180,7 +192,7 @@
 static duk_ret_t
 Plugin_reload(duk_context *ctx)
 {
-	(void)ctx;
+	irc_plugin_reload(find(ctx));
 
 	return 0;
 }
@@ -188,7 +200,8 @@
 static duk_ret_t
 Plugin_unload(duk_context *ctx)
 {
-	(void)ctx;
+	/* Use find so it can raise ReferenceError if not found. */
+	irc_bot_remove_plugin(find(ctx)->name);
 
 	return 0;
 }