1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Added connect.py plugin, refactored init and start events, added send_line

This commit is contained in:
James Booth 2013-08-06 00:28:40 +01:00
parent de3d46becc
commit ab45239033
8 changed files with 52 additions and 27 deletions

9
plugins/connect.py Normal file
View File

@ -0,0 +1,9 @@
import prof
user = "jabber.org"
def prof_on_start():
global user
prof.cons_show("")
prof.cons_show("Enter password for " + user)
prof.send_line("/connect " + user)

View File

@ -3,17 +3,20 @@ import urllib2
import json
import time
score_url = "http://api.scorescard.com/?type=score&teamone=Australia&teamtwo=England"
#score_url = "http://api.scorescard.com/?type=score&teamone=Australia&teamtwo=England"
score_url = None
summary = None
# hooks
def prof_init(version, status):
prof.register_timed(get_scores, 60)
if score_url:
prof.register_timed(get_scores, 60)
def prof_on_start():
get_scores()
if score_url:
get_scores()
def get_scores():
global score_url

View File

@ -25,6 +25,7 @@
#include <glib.h>
#include "plugins/callbacks.h"
#include "profanity.h"
#include "ui/notifier.h"
#include "ui/ui.h"
@ -45,6 +46,7 @@ api_cons_show(PyObject *self, PyObject *args)
}
cons_show("%s", message);
ui_current_page_off();
ui_refresh();
return Py_BuildValue("");
}
@ -118,11 +120,25 @@ api_notify(PyObject *self, PyObject *args)
return Py_BuildValue("");
}
static PyObject*
api_send_line(PyObject *self, PyObject *args)
{
char *line = NULL;
if (!PyArg_ParseTuple(args, "s", &line)) {
return NULL;
}
prof_process_input(line);
return Py_BuildValue("");
}
static PyMethodDef apiMethods[] = {
{ "cons_alert", api_cons_alert, METH_NOARGS, "Highlight the console window in the status bar." },
{ "cons_show", api_cons_show, METH_VARARGS, "Print a line to the console." },
{ "register_command", api_register_command, METH_VARARGS, "Register a command." },
{ "register_timed", api_register_timed, METH_VARARGS, "Register a timed function." },
{ "send_line", api_send_line, METH_VARARGS, "Send a line of input." },
{ "notify", api_notify, METH_VARARGS, "Send desktop notification." },
{ NULL, NULL, 0, NULL }
};

View File

@ -28,8 +28,6 @@
#include "ui/ui.h"
static GSList* _get_module_names(void);
static void _init(void);
static void _on_start(void);
static void _run_plugins(const char * const function, PyObject *p_args);
static GSList* plugins;
@ -79,14 +77,21 @@ plugins_init(void)
module_name = g_slist_next(module_name);
}
_init();
_check_error();
_on_start();
PyObject *p_args = Py_BuildValue("ss", PACKAGE_VERSION, PACKAGE_STATUS);
_run_plugins("prof_init", p_args);
Py_XDECREF(p_args);
_check_error();
}
return;
}
void
plugins_on_start(void)
{
_run_plugins("prof_on_start", NULL);
_check_error();
}
void
plugins_shutdown(void)
{
@ -123,20 +128,6 @@ _get_module_names(void)
}
}
static void
_init(void)
{
PyObject *p_args = Py_BuildValue("ss", PACKAGE_VERSION, PACKAGE_STATUS);
_run_plugins("prof_init", p_args);
Py_XDECREF(p_args);
}
static void
_on_start(void)
{
_run_plugins("prof_on_start", NULL);
}
static void
_run_plugins(const char * const function, PyObject *p_args)
{

View File

@ -24,6 +24,7 @@
#define PLUGINS_H
void plugins_init(void);
void plugins_on_start(void);
void plugins_on_connect(void);
void plugins_shutdown(void);
gboolean plugins_command_run(const char * const cmd);

View File

@ -46,7 +46,6 @@
#include "ui/ui.h"
#include "xmpp/xmpp.h"
static gboolean _process_input(char *inp);
static void _handle_idle_time(void);
static void _init(const int disable_tls, char *log_level);
static void _shutdown(void);
@ -67,6 +66,9 @@ prof_run(const int disable_tls, char *log_level)
char inp[INP_WIN_MAX];
int size = 0;
ui_refresh();
plugins_on_start();
while(cmd_result == TRUE) {
wint_t ch = ERR;
size = 0;
@ -98,7 +100,7 @@ prof_run(const int disable_tls, char *log_level)
}
inp[size++] = '\0';
cmd_result = _process_input(inp);
cmd_result = prof_process_input(inp);
}
g_timer_destroy(timer);
@ -262,7 +264,6 @@ prof_handle_login_account_success(char *account_name)
status_bar_refresh();
accounts_free_account(account);
plugins_on_connect();
}
void
@ -510,8 +511,8 @@ prof_handle_disco_info(const char *from, GSList *identities, GSList *features)
* Take a line of input and process it, return TRUE if profanity is to
* continue, FALSE otherwise
*/
static gboolean
_process_input(char *inp)
gboolean
prof_process_input(char *inp)
{
log_debug("Input recieved: %s", inp);
gboolean result = FALSE;

View File

@ -86,5 +86,6 @@ void prof_handle_already_in_group(const char * const contact, const char * const
void prof_handle_not_in_group(const char * const contact, const char * const group);
void prof_handle_group_add(const char * const contact, const char * const group);
void prof_handle_group_remove(const char * const contact, const char * const group);
gboolean prof_process_input(char *inp);
#endif

View File

@ -28,6 +28,7 @@
#include <strophe.h>
#include "log.h"
#include "plugins/plugins.h"
#include "profanity.h"
#include "tools/autocomplete.h"
#include "xmpp/connection.h"
@ -637,6 +638,8 @@ _roster_handle_result(xmpp_conn_t * const conn, xmpp_stanza_t * const stanza,
contact_presence_t conn_presence =
accounts_get_login_presence(jabber_get_account_name());
presence_update(conn_presence, NULL, 0);
plugins_on_connect();
}
return 1;