[PATCH] Implement autosendcmd (/channel add -botcmd) for silc irssi client (and silc protocol irssi plugin .so)

Skywing <[email protected]> Thu, 26 Jun 2008 20:27:22 -0500
Newsgroups gmane.network.silc.devel
Message-ID <982D8D05B6407A49AD506E6C3AC8E7D66147930B15@caralain.haven.nynaeve.net>
This implements the "autosendcmd" directive in a channel config section for the irssi silc client.

Note that it doesn't currently support the "bots" mask and always sends the command out to the channel.  Also, the autosendcmd will run on resume detached sessions as well as initial channel join (for my purposes, this is the desired behavior).

Diff vs the 1.1.4 client tree.

- S

_______________________________________________________________________
Info:    https://lists.silcnet.org/mailman/listinfo/silc-announce
Archive: https://lists.silcnet.org/pipermail/silc-announce
FAQ:     http://silcnet.org/support/faq/
autosendcmd_channel.patch (application/octet-stream, 2.7 KB)
--- silc-client-orig/apps/irssi/src/silc/core/silc-channels.c	2008-03-14 07:06:09.000000000 -0500
+++ silc-client-1.1.4/apps/irssi/src/silc/core/silc-channels.c	2008-06-26 20:02:16.000000000 -0500
@@ -31,6 +31,7 @@
 #include "rawlog.h"
 #include "misc.h"
 #include "settings.h"
+#include "special-vars.h"
 
 #include "channels-setup.h"
 
@@ -161,6 +162,25 @@
     silc_command_exec(server, "QUIT", msg);
 }
 
+static void sig_silc_channel_joined(SILC_CHANNEL_REC *channel)
+{
+  CHANNEL_SETUP_REC *rec;
+
+  if (!IS_SILC_CHANNEL(channel))
+    return;
+  if (channel->server && channel->server->disconnected)
+    return;
+  if (channel->session_rejoin)
+    return;
+  
+  rec = channel_setup_find(channel->name, channel->server->connrec->chatnet); 
+
+  if (rec == NULL || rec->autosendcmd == NULL || !*rec->autosendcmd)
+    return;
+
+  eval_special_string(rec->autosendcmd, "", (SERVER_REC*)channel->server, (CHANNEL_REC*)channel);
+}
+
 /* Find Irssi channel entry by SILC channel entry */
 
 SILC_CHANNEL_REC *silc_channel_find_entry(SILC_SERVER_REC *server,
@@ -698,7 +718,7 @@
 					    argv[4], argv_lens[4]);
       } else if (type == 2) {
 	/* Set private channel key */
-	if (!(channel_entry->mode & SILC_CHANNEL_MODE_PRIVKEY)) {
+	if (!(channel_entry) || !(channel_entry->mode & SILC_CHANNEL_MODE_PRIVKEY)) {
 	  printformat_module("fe-common/silc", server, NULL, MSGLEVEL_CRAP,
 			     SILCTXT_CH_PRIVATE_KEY_NOMODE,
 			     channel_entry->channel_name);
@@ -1261,6 +1281,7 @@
   signal_add("server connected", (SIGNAL_FUNC) sig_connected);
   signal_add("server quit", (SIGNAL_FUNC) sig_server_quit);
   signal_add("mime", (SIGNAL_FUNC) sig_mime);
+  signal_add("channel joined", (SIGNAL_FUNC) sig_silc_channel_joined);
 
   command_bind_silc("part", MODULE_NAME, (SIGNAL_FUNC) command_part);
   command_bind_silc("me", MODULE_NAME, (SIGNAL_FUNC) command_me);
@@ -1283,6 +1304,7 @@
   signal_remove("server connected", (SIGNAL_FUNC) sig_connected);
   signal_remove("server quit", (SIGNAL_FUNC) sig_server_quit);
   signal_remove("mime", (SIGNAL_FUNC) sig_mime);
+  signal_remove("channel joined", (SIGNAL_FUNC) sig_silc_channel_joined);
 
   command_unbind("part", (SIGNAL_FUNC) command_part);
   command_unbind("me", (SIGNAL_FUNC) command_me);
--- silc-client-orig/apps/irssi/src/silc/core/client_ops.c	2008-03-14 07:06:09.000000000 -0500
+++ silc-client-1.1.4/apps/irssi/src/silc/core/client_ops.c	2008-06-26 20:04:09.000000000 -0500
@@ -1807,8 +1807,8 @@
       if (!ownnick)
 	break;
       nicklist_set_own(CHANNEL(chanrec), ownnick);
-      signal_emit("channel joined", 1, chanrec);
       chanrec->entry = channel_entry;
+      signal_emit("channel joined", 1, chanrec);
 
       if (chanrec->topic)
 	printformat_module("fe-common/silc", server,