4 #include <libpurple/debug.h>
5 #include <libpurple/version.h>
6 #include <libpurple/conversation.h>
7 #include <libpurple/debug.h>
8 #include <libpurple/log.h>
9 #include <libpurple/plugin.h>
10 #include <libpurple/pluginpref.h>
11 #include <libpurple/prefs.h>
12 #include <libpurple/signals.h>
13 #include <libpurple/util.h>
14 #include <libpurple/notify.h>
19 #define RESPONSE_LINE_LENGTH 4096
20 #define HOOK_SCRIPT "answerscripts.exe"
23 char *hook_script
= NULL
;
24 char response
[RESPONSE_LINE_LENGTH
+1];
28 received_im_msg_cb(PurpleAccount
* account
, char *who
, char *buffer
,
29 PurpleConversation
* conv
, PurpleMessageFlags flags
,
31 /* A workaround to avoid skipping of the first message as a result on NULL-conv: */
32 if (conv
== NULL
) conv
= purple_conversation_new(PURPLE_CONV_TYPE_IM
, account
, who
);
34 buff
= purple_markup_strip_html(buffer
);
35 //printf("\nHarvie received: %s: %s\n", who, buff); //debug
36 //purple_conv_im_send(purple_conversation_get_im_data(conv), ":-*"); //debug
38 setenv("PURPLE_FROM", who
, 1);
39 setenv("PURPLE_MSG", buff
, 1);
41 FILE* pipe
= popen(hook_script
, "r"); //TODO: process scripts and send response asynchronously
42 while (pipe
&& fgets(response
, RESPONSE_LINE_LENGTH
, pipe
)) {
43 for(i
=0;response
[i
];i
++) if(response
[i
]=='\n') response
[i
]=0;
44 purple_conv_im_send(purple_conversation_get_im_data(conv
), response
);
50 static gboolean
plugin_load(PurplePlugin
* plugin
) {
51 asprintf(&hook_script
,"%s/%s",purple_user_dir(),HOOK_SCRIPT
);
53 void *conv_handle
= purple_conversations_get_handle();
55 purple_signal_connect(conv_handle
, "received-im-msg",
56 plugin
, PURPLE_CALLBACK(received_im_msg_cb
),
61 static gboolean
plugin_unload(PurplePlugin
* plugin
) {
66 static PurplePluginInfo info
= {
70 PURPLE_PLUGIN_STANDARD
,
74 PURPLE_PRIORITY_DEFAULT
,
79 "Framework for hooking scripts to received messages for various libpurple clients",
80 "This plugin will call ~/.purple/" HOOK_SCRIPT
" (or wherever purple_user_dir() points) "
81 "script (or any executable) for each single message called."
82 "Envinronment values PURPLE_MSG and PURPLE_FROM will be set to carry "
83 "informations about message text and sender so script can respond to that message. "
84 "Any text printed to STDOUT by the script will be sent back as answer to message. "
85 "Please see example scripts for more informations...",
86 "Harvie <harvie@email.cz>",
87 "http://github.com/harvie",
102 static void init_plugin(PurplePlugin
* plugin
) {
106 PURPLE_INIT_PLUGIN(autoanswer
, init_plugin
, info
)
This page took 0.348871 seconds and 4 git commands to generate.