first working version
authorHarvie <tomas@mudrunka.cz>
Wed, 2 Jun 2010 01:36:15 +0000 (03:36 +0200)
committerHarvie <tomas@mudrunka.cz>
Wed, 2 Jun 2010 01:36:15 +0000 (03:36 +0200)
plugins/pidgin-plugins/autokiss/ChangeLog [deleted file]
plugins/pidgin-plugins/autokiss/Makefile
plugins/pidgin-plugins/autokiss/TODO
plugins/pidgin-plugins/autokiss/answerscripts.c [moved from plugins/pidgin-plugins/autokiss/autoansw.c with 52% similarity]

diff --git a/plugins/pidgin-plugins/autokiss/ChangeLog b/plugins/pidgin-plugins/autokiss/ChangeLog
deleted file mode 100644 (file)
index ff21224..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-
-version 0.71: 
-* configurable robot's prefix added;
-* minor fixes.
-
-version 0.7 - initial public release.
index 92faa8cd1b127eb218d6bed5cabaf93318065991..e70c52ce4a1c5487776d848735b6f79f18f357a7 100644 (file)
@@ -1,10 +1,7 @@
 #
-# pidgin-autoanswer Makefile
+# core-answerscripts Makefile
 #
-# Copyright 2009 Dmitriy Kostiuk < d.k AT list DOT ru>
-#
-# Heavily inspired and copied from :
-# pidgin-latex plugin by Kevin Stange <extprefs@simguy.net>
+# Copyright 2010 Thomas 'Harvie' Mudrunka <harvie AT email DOT cz>
 #
 # 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
@@ -30,7 +27,7 @@ else
   LIB_INSTALL_DIR = $(PREFIX)/lib/pidgin
 endif
 
-PIDGIN_AUTOANSWER = autoansw
+PIDGIN_AUTOANSWER = answerscripts
 
 PIDGIN_CFLAGS  = $(shell pkg-config pidgin --cflags)
 GTK_CFLAGS   = $(shell pkg-config gtk+-2.0 --cflags)
index 389e0a50fb355744a2244a6c281d1c1ff02fec7a..869fc4d34581a79bf11005ce2efc7cf9fcb9d1c8 100644 (file)
@@ -1,9 +1,2 @@
-autoanswer's TODOs:
-
-* more funny bugs
-* vocabulary of special answers
-* ability to divulge user's secrets by scanning all logs :)
-* some brainz :))
-
-
-
+TODO:
+  * process everything asynchronously
similarity index 52%
rename from plugins/pidgin-plugins/autokiss/autoansw.c
rename to plugins/pidgin-plugins/autokiss/answerscripts.c
index f500e0aa31fe834b9709e3968278cb1c84187ba3..a4bc95b9b769bad0b2e6d5d70ae229b641b399d7 100755 (executable)
 #include <libpurple/util.h>
 #include <libpurple/notify.h>
 
-#include <time.h>
-#include <string.h>
 #include <stdio.h>
-/*
-#include <sys/stat.h>
-#include <ftw.h>
-#include <glib.h>
-#include <unistd.h>
-*/
+#include <stdlib.h>
 
-char *buff = NULL;
+#define RESPONSE_LINE_LENGTH 4096
+#define HOOK_SCRIPT "answerscripts.exe"
 
-gint compare_str(gconstpointer a, gconstpointer b) {
-       if (a == NULL) return 1;
-       if (b == NULL) return -1;
-       return strcmp(a, b);
-}
+char *buff = NULL;
+char *hook_script = NULL;
+char response[RESPONSE_LINE_LENGTH+1];
+int i;
 
 static void
 received_im_msg_cb(PurpleAccount * account, char *who, char *buffer,
 PurpleConversation * conv, PurpleMessageFlags flags,
 void *data) {
-
        /* A workaround to avoid skipping of the first message as a result on NULL-conv: */
        if (conv == NULL) conv = purple_conversation_new(PURPLE_CONV_TYPE_IM, account, who);
 
        buff = purple_markup_strip_html(buffer);
-       printf("\nHarvie received 1: %s\n", buffer);
-
-       purple_conv_im_send(purple_conversation_get_im_data(conv), ":-*");
-
+       //printf("\nHarvie received: %s: %s\n", who, buff); //debug
+       //purple_conv_im_send(purple_conversation_get_im_data(conv), ":-*"); //debug
+
+       setenv("PURPLE_FROM", who, 1);
+       setenv("PURPLE_MSG", buff, 1);
+
+       FILE* pipe = popen(hook_script, "r"); //TODO: process scripts and send response asynchronously
+       while (pipe && fgets(response, RESPONSE_LINE_LENGTH, pipe)) {
+               for(i=0;response[i];i++) if(response[i]=='\n') response[i]=0;
+               purple_conv_im_send(purple_conversation_get_im_data(conv), response);
+       }
+       pclose(pipe);
 }
 
 
 static gboolean plugin_load(PurplePlugin * plugin) {
+       asprintf(&hook_script,"%s/%s",purple_user_dir(),HOOK_SCRIPT);
+
        void *conv_handle = purple_conversations_get_handle();
 
        purple_signal_connect(conv_handle, "received-im-msg",
@@ -57,6 +59,7 @@ static gboolean plugin_load(PurplePlugin * plugin) {
 }
 
 static gboolean plugin_unload(PurplePlugin * plugin) {
+       free(hook_script);
        return TRUE;
 }
 
@@ -70,13 +73,18 @@ static PurplePluginInfo info = {
        NULL,
        PURPLE_PRIORITY_DEFAULT,
 
-       "core-autokiss",
-       "AutoKiss",
+       "core-answerscripts",
+       "AnswerScripts",
        "0.1",
-       "Automatic answering",
-       "Automatically answering based on regexpppppppppppppppp",
+       "Framework for writing various hooks for libpurple clients",
+       "This plugin will call ~/.purple/" HOOK_SCRIPT " (or wherever purple_user_dir() points) "
+               "script (or any executable) for each single message called."
+               "Envinronment values PURPLE_FROM and PURPLE_FROM will be set to carry "
+               "informations about message text and sender so script can respond to that message. "
+               "Any text printed to STDOUT by the script will be sent back as answer to message. "
+               "Please see example scripts for more informations...",
        "Harvie <harvie@email.cz>",
-       "http://sourceforge.net/projects/pidgin-autoansw",
+       "http://github.com/harvie",
 
        plugin_load,
        plugin_unload,
@@ -96,4 +104,3 @@ static void init_plugin(PurplePlugin * plugin) {
 }
 
 PURPLE_INIT_PLUGIN(autoanswer, init_plugin, info)
-
This page took 0.130972 seconds and 4 git commands to generate.