├── README.md ├── command-execute.c ├── command-execute.dll └── command-execute64.so /README.md: -------------------------------------------------------------------------------- 1 | # Readme 2 | ## What? 3 | Command-execute is a plugin for Pidgin and Finch which lets you execute a command on either every new IM received or on every conversation update. 4 | It can also act on new chat messages. 5 | 6 | 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. 7 | ## How? 8 | Just put the `command-execute.so` file into your Pidgin/Finch plugin directory. 9 | Normally this is `~/.purple/plugins/` or `/usr/lib/pidgin/`. 10 | 11 | If this does not work for you, you maybe have to compile the plugin yourself: 12 | 13 | gcc command-execute.c -O2 -Wall -fpic `pkg-config --cflags glib-2.0` -I/path/to/your/libpurple/headers -shared -o command-execute.so 14 | 15 | ## TODO 16 | 17 | - Provide .so files for every platform. 18 | 19 | - Provide a feature which makes passing arguments like $msg for message or $sender for the id of the sender possible. This is already implemented in the develop branch. I wouldn't recommend using it though since I hadn't time yet to test it and make sure the feature doesn't raise security vulnerabilities. 20 | -------------------------------------------------------------------------------- /command-execute.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Command-execute 3 | * Copyright (C) 2010 tymm 4 | * 5 | * This program is free software; you can redistribute it and/or 6 | * modify it under the terms of the GNU General Public License 7 | * as published by the Free Software Foundation; either version 3 8 | * of the License, or (at your option) any later version. 9 | * 10 | * This program is distributed in the hope that it will be useful, 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | * GNU General Public License for more details. 14 | * 15 | * You should have received a copy of the GNU General Public License 16 | * along with this program; if not, see . 17 | */ 18 | 19 | #define PURPLE_PLUGINS 20 | 21 | #include 22 | #include 23 | #include 24 | 25 | #include "notify.h" 26 | #include "plugin.h" 27 | #include "version.h" 28 | #include "debug.h" 29 | #include "prefs.h" 30 | 31 | #define PLUGIN_ID "core-tymm-command-execute" 32 | 33 | #ifndef _PIDGIN_CONVERSATION_H_ 34 | typedef enum 35 | { 36 | PIDGIN_UNSEEN_NONE, 37 | PIDGIN_UNSEEN_EVENT, 38 | PIDGIN_UNSEEN_NO_LOG, 39 | PIDGIN_UNSEEN_TEXT, 40 | PIDGIN_UNSEEN_NICK 41 | } PidginUnseenState; 42 | #endif 43 | 44 | void execute(const char *cmd) { 45 | if(strcmp(cmd,"") != 0) { 46 | /* Execute command */ 47 | if(g_spawn_command_line_async(cmd, NULL) == TRUE) { 48 | purple_debug_info(PLUGIN_ID, "Command executed\n"); 49 | } else { 50 | purple_debug_warning(PLUGIN_ID, "There was a problem executing the command\n"); 51 | } 52 | } else { 53 | purple_debug_warning(PLUGIN_ID, "No command found\n"); 54 | } 55 | } 56 | 57 | 58 | static void cmdexe_conversation_updated(PurpleConversation *conv, PurpleConvUpdateType type) { 59 | /* Check if the user wants to execute the command only when a conversation is updated */ 60 | if(!purple_prefs_get_bool("/plugins/core/tymm-command-execute/execute_always")) { 61 | gboolean has_unseen_state=FALSE, has_unseen_count; 62 | if( type != PURPLE_CONV_UPDATE_UNSEEN) return; 63 | 64 | //has_unseen_state = (GPOINTER_TO_INT(purple_conversation_get_data(conv, "unseen-state")) >= PIDGIN_UNSEEN_TEXT); 65 | has_unseen_count = (GPOINTER_TO_INT(purple_conversation_get_data(conv, "unseen-count")) > 0); 66 | 67 | /* Check if the conversation_updated signal has been emitted by a new message or something else */ 68 | if(has_unseen_state || has_unseen_count) { 69 | const char *cmd = purple_prefs_get_string("/plugins/core/tymm-command-execute/command"); 70 | execute(cmd); 71 | } 72 | } 73 | } 74 | 75 | static void cmdexe_received_im_msg(PurpleConversation *conv, PurpleConvUpdateType type) { 76 | /* Check if the user wants to execute the command on _every_ received IM */ 77 | if(purple_prefs_get_bool("/plugins/core/tymm-command-execute/execute_always")) { 78 | const char *cmd = purple_prefs_get_string("/plugins/core/tymm-command-execute/command"); 79 | execute(cmd); 80 | } 81 | } 82 | 83 | static void cmdexe_received_chat_msg() { 84 | /* Check if the user wants to execute the command _everytime_ the user receives a chat message */ 85 | if(purple_prefs_get_bool("/plugins/core/tymm-command-execute/execute_chat")) { 86 | const char *cmd = purple_prefs_get_string("/plugins/core/tymm-command-execute/command"); 87 | execute(cmd); 88 | } 89 | } 90 | 91 | static gboolean plugin_load(PurplePlugin *plugin) { 92 | /* Connect the conversation-updated signal to the callback function cmdexe_conversation_updated. 93 | * The conversation-updated signal is emitted when a conversation is updated. 94 | * I discovered that the conversation-updated signal is also triggered if the focus of a chat window is being triggered */ 95 | purple_signal_connect(purple_conversations_get_handle(), "conversation-updated", plugin, PURPLE_CALLBACK(cmdexe_conversation_updated), NULL); 96 | 97 | /* Connect the received-im-msg signal to the callback function cmdexe_received_im_msg. 98 | * This signal is emitted everytime an IM message is received */ 99 | purple_signal_connect(purple_conversations_get_handle(), "received-im-msg", plugin, PURPLE_CALLBACK(cmdexe_received_im_msg), NULL); 100 | 101 | /* Connect the received-chat-msg signal to the callback function cmdexe_received_chat_msg. 102 | * This signal is emitted everytime a Chat message is received */ 103 | purple_signal_connect(purple_conversations_get_handle(), "received-chat-msg", plugin, PURPLE_CALLBACK(cmdexe_received_chat_msg), NULL); 104 | return TRUE; 105 | } 106 | 107 | static gboolean plugin_unload(PurplePlugin *plugin) { 108 | /* Disconnect the signal if the plugin is getting unloaded */ 109 | purple_signal_disconnect(purple_conversations_get_handle(), "conversation-updated", plugin, PURPLE_CALLBACK(cmdexe_conversation_updated)); 110 | purple_signal_disconnect(purple_conversations_get_handle(), "received-im-msg", plugin, PURPLE_CALLBACK(cmdexe_received_im_msg)); 111 | purple_signal_disconnect(purple_conversations_get_handle(), "received-chat-msg", plugin, PURPLE_CALLBACK(cmdexe_received_chat_msg)); 112 | return TRUE; 113 | } 114 | 115 | /* UI */ 116 | static PurplePluginPrefFrame *plugin_config_frame(PurplePlugin *plugin) { 117 | PurplePluginPrefFrame *frame; 118 | PurplePluginPref *ppref; 119 | 120 | frame = purple_plugin_pref_frame_new(); 121 | 122 | ppref = purple_plugin_pref_new_with_label("Insert Command:"); 123 | purple_plugin_pref_frame_add(frame, ppref); 124 | 125 | ppref = purple_plugin_pref_new_with_name_and_label("/plugins/core/tymm-command-execute/command", "Command"); 126 | purple_plugin_pref_frame_add(frame, ppref); 127 | 128 | ppref = purple_plugin_pref_new_with_name_and_label("/plugins/core/tymm-command-execute/execute_always", "Execute command on every new IM (not only on updated conversations)"); 129 | purple_plugin_pref_frame_add(frame, ppref); 130 | 131 | ppref = purple_plugin_pref_new_with_name_and_label("/plugins/core/tymm-command-execute/execute_chat", "Execute command on new chat messages"); 132 | purple_plugin_pref_frame_add(frame, ppref); 133 | 134 | return frame; 135 | } 136 | 137 | static PurplePluginUiInfo prefs_info = { 138 | plugin_config_frame, 139 | 0, 140 | NULL, 141 | NULL, 142 | NULL, 143 | NULL, 144 | NULL 145 | }; 146 | 147 | static PurplePluginInfo info = { 148 | PURPLE_PLUGIN_MAGIC, 149 | PURPLE_MAJOR_VERSION, 150 | PURPLE_MINOR_VERSION, 151 | PURPLE_PLUGIN_STANDARD, 152 | NULL, 153 | 0, 154 | NULL, 155 | PURPLE_PRIORITY_DEFAULT, 156 | PLUGIN_ID, 157 | "Command execute", 158 | "1.0", 159 | "Command execution for pidgin and finch", 160 | "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.", 161 | "tymm ", 162 | "https://github.com/tymm/command-execute/", 163 | plugin_load, 164 | plugin_unload, 165 | NULL, // plugin_destroy 166 | NULL, 167 | NULL, 168 | &prefs_info, 169 | NULL, // plugin_actions function here 170 | NULL, 171 | NULL, 172 | NULL, 173 | NULL 174 | }; 175 | 176 | static void init_plugin(PurplePlugin *plugin) { 177 | purple_prefs_add_none("/plugins/core/tymm-command-execute"); 178 | purple_prefs_add_string("/plugins/core/tymm-command-execute/command", ""); 179 | purple_prefs_add_bool("/plugins/core/tymm-command-execute/execute_always", FALSE); 180 | purple_prefs_add_bool("/plugins/core/tymm-command-execute/execute_chat", FALSE); 181 | } 182 | 183 | PURPLE_INIT_PLUGIN(command-execute, init_plugin, info) 184 | -------------------------------------------------------------------------------- /command-execute.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tymm/command-execute/781bf595d1cac71c8efb59760b14430fa3a50fe8/command-execute.dll -------------------------------------------------------------------------------- /command-execute64.so: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/tymm/command-execute/781bf595d1cac71c8efb59760b14430fa3a50fe8/command-execute64.so --------------------------------------------------------------------------------