Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,16 @@ Command-execute is a plugin for Pidgin and Finch which lets you execute a comman
It can also act on new chat messages.

A conversation update is triggered everytime a message is received which you did not see yet. For example that applies for messages which occur in a window which is in the background of Finch.

You can pass the name of the sender and the received message by using $sender and $msg in the command. Before that you have to activate this feature in the configuration menu. This feature is untested and probably not secure. I wouldn't recommend using it at the moment.
## How?
Just put the `command-execute.so` file into your Pidgin/Finch plugin directory.
Normally this is `~/.purple/plugins/` or `/usr/lib/pidgin/`.

If this does not work for you, you maybe have to compile the plugin yourself:

gcc command-execute.c -O2 -Wall -fpic `pkg-config --cflags glib-2.0` -I/path/to/your/libpurple/headers -shared -o command-execute.so
## Why?
I wrote this plugin because non of the existing command execution plugins worked for Pidgin _and_ Finch.

## TODO

- Provide .so files for every platform.
43 changes: 28 additions & 15 deletions command-execute.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
* along with this program; if not, see <http://www.gnu.org/licenses/>.
*/


#define PURPLE_PLUGINS

#include <glib.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>

#include "notify.h"
Expand All @@ -33,23 +35,30 @@
#ifndef _PIDGIN_CONVERSATION_H_
typedef enum
{
PIDGIN_UNSEEN_NONE,
PIDGIN_UNSEEN_EVENT,
PIDGIN_UNSEEN_NO_LOG,
PIDGIN_UNSEEN_TEXT,
PIDGIN_UNSEEN_NICK
PIDGIN_UNSEEN_NONE,
PIDGIN_UNSEEN_EVENT,
PIDGIN_UNSEEN_NO_LOG,
PIDGIN_UNSEEN_TEXT,
PIDGIN_UNSEEN_NICK
} PidginUnseenState;
#endif

void execute(const char *cmd) {
void execute(const char *cmd, char *sender, char *message) {
if(strcmp(cmd,"") != 0) {
/* Execute command */
if(g_spawn_command_line_async(cmd, NULL) == TRUE) {
pid_t pid = fork();
if (pid == -1) {
// error, failed to fork()
} else if (pid > 0) {
purple_debug_info(PLUGIN_ID, "Command executed\n");
purple_debug_info(PLUGIN_ID, cmd);
} else {
// we are the child
execl(cmd,cmd,sender,message,(char *) NULL);
purple_debug_warning(PLUGIN_ID, "There was a problem executing the command\n");
_exit(EXIT_FAILURE); // exec never returns
}
} else {
// There is no command
purple_debug_warning(PLUGIN_ID, "No command found\n");
}
}
Expand All @@ -66,25 +75,25 @@ static void cmdexe_conversation_updated(PurpleConversation *conv, PurpleConvUpda

/* Check if the conversation_updated signal has been emitted by a new message or something else */
if(has_unseen_state || has_unseen_count) {
const char *cmd = purple_prefs_get_string("/plugins/core/tymm-command-execute/command");
execute(cmd);
//const char *cmd = purple_prefs_get_string("/plugins/core/tymm-command-execute/command");
//execute(cmd, sender, message);
}
}
}

static void cmdexe_received_im_msg(PurpleConversation *conv, PurpleConvUpdateType type) {
static void cmdexe_received_im_msg(PurpleAccount *account, char *sender, char *message, PurpleConversation *conv, PurpleMessageFlags flags) {
/* Check if the user wants to execute the command on _every_ received IM */
if(purple_prefs_get_bool("/plugins/core/tymm-command-execute/execute_always")) {
const char *cmd = purple_prefs_get_string("/plugins/core/tymm-command-execute/command");
execute(cmd);
execute(cmd, sender, message);
}
}

static void cmdexe_received_chat_msg() {
static void cmdexe_received_chat_msg(PurpleAccount *account, char *sender, char *message, PurpleConversation *conv, PurpleMessageFlags flags) {
/* Check if the user wants to execute the command _everytime_ the user receives a chat message */
if(purple_prefs_get_bool("/plugins/core/tymm-command-execute/execute_chat")) {
const char *cmd = purple_prefs_get_string("/plugins/core/tymm-command-execute/command");
execute(cmd);
execute(cmd, sender, message);
}
}

Expand Down Expand Up @@ -131,6 +140,9 @@ static PurplePluginPrefFrame *plugin_config_frame(PurplePlugin *plugin) {
ppref = purple_plugin_pref_new_with_name_and_label("/plugins/core/tymm-command-execute/execute_chat", "Execute command on new chat messages");
purple_plugin_pref_frame_add(frame, ppref);

ppref = purple_plugin_pref_new_with_name_and_label("/plugins/core/tymm-command-execute/arguments", "Enable arguments (%s sender, %m message)");
purple_plugin_pref_frame_add(frame, ppref);

return frame;
}

Expand All @@ -155,7 +167,7 @@ static PurplePluginInfo info = {
PURPLE_PRIORITY_DEFAULT,
PLUGIN_ID,
"Command execute",
"1.0",
"1.1",
"Command execution for pidgin and finch",
"Takes a command which will be executed either on every new IM or on every conversation update. It can also act on new chat messages.",
"tymm <tymmm1@gmail.com>",
Expand All @@ -178,6 +190,7 @@ static void init_plugin(PurplePlugin *plugin) {
purple_prefs_add_string("/plugins/core/tymm-command-execute/command", "");
purple_prefs_add_bool("/plugins/core/tymm-command-execute/execute_always", FALSE);
purple_prefs_add_bool("/plugins/core/tymm-command-execute/execute_chat", FALSE);
purple_prefs_add_bool("/plugins/core/tymm-command-execute/arguments", FALSE);
}

PURPLE_INIT_PLUGIN(command-execute, init_plugin, info)
Binary file modified command-execute64.so
Binary file not shown.