From: Harvie Date: Wed, 2 Jun 2010 01:36:15 +0000 (+0200) Subject: first working version X-Git-Url: http://git.harvie.cz/?a=commitdiff_plain;h=0a076ca80e0c3c127bcc286633f8cd40bf52c038;p=mirrors%2FPrograms.git first working version --- diff --git a/plugins/pidgin-plugins/autokiss/ChangeLog b/plugins/pidgin-plugins/autokiss/ChangeLog deleted file mode 100644 index ff21224..0000000 --- a/plugins/pidgin-plugins/autokiss/ChangeLog +++ /dev/null @@ -1,6 +0,0 @@ - -version 0.71: -* configurable robot's prefix added; -* minor fixes. - -version 0.7 - initial public release. diff --git a/plugins/pidgin-plugins/autokiss/Makefile b/plugins/pidgin-plugins/autokiss/Makefile index 92faa8c..e70c52c 100644 --- a/plugins/pidgin-plugins/autokiss/Makefile +++ b/plugins/pidgin-plugins/autokiss/Makefile @@ -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 +# Copyright 2010 Thomas 'Harvie' Mudrunka # # 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) diff --git a/plugins/pidgin-plugins/autokiss/TODO b/plugins/pidgin-plugins/autokiss/TODO index 389e0a5..869fc4d 100644 --- a/plugins/pidgin-plugins/autokiss/TODO +++ b/plugins/pidgin-plugins/autokiss/TODO @@ -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 diff --git a/plugins/pidgin-plugins/autokiss/autoansw.c b/plugins/pidgin-plugins/autokiss/answerscripts.c similarity index 52% rename from plugins/pidgin-plugins/autokiss/autoansw.c rename to plugins/pidgin-plugins/autokiss/answerscripts.c index f500e0a..a4bc95b 100755 --- a/plugins/pidgin-plugins/autokiss/autoansw.c +++ b/plugins/pidgin-plugins/autokiss/answerscripts.c @@ -13,41 +13,43 @@ #include #include -#include -#include #include -/* -#include -#include -#include -#include -*/ +#include -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 ", - "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) -