mirror of
https://github.com/profanity-im/profanity.git
synced 2024-12-04 14:46:46 -05:00
Added on_message hook
Browser plugin now uses last received hyperlink when no arg supplied
This commit is contained in:
parent
9f76a5e610
commit
d8eb320b85
@ -1,14 +1,37 @@
|
||||
import prof
|
||||
import os
|
||||
import webbrowser
|
||||
import re
|
||||
|
||||
lastlink = None
|
||||
|
||||
# hooks
|
||||
def prof_init(version, status):
|
||||
prof.register_command("/browser", 1, 1, "/browser url", "View a URL in the browser.", "View a URL in the browser", cmd_browser)
|
||||
prof.register_command("/browser", 0, 1, "/browser url", "View a URL in the browser.", "View a URL in the browser", cmd_browser)
|
||||
|
||||
def prof_on_message(jid, message):
|
||||
global lastlink
|
||||
links = re.findall(r'(https?://\S+)', message)
|
||||
if (len(links) > 0):
|
||||
lastlink = links[len(links)-1]
|
||||
|
||||
# commands
|
||||
def cmd_browser(url):
|
||||
global lastlink
|
||||
|
||||
link = None
|
||||
if (url != None):
|
||||
link = url
|
||||
elif (lastlink != None):
|
||||
link = lastlink
|
||||
|
||||
if (link != None):
|
||||
prof.cons_show("Opening " + link + " in browser.")
|
||||
open_browser(link)
|
||||
else:
|
||||
prof.cons_show("No link supplied.")
|
||||
|
||||
def open_browser(url):
|
||||
savout = os.dup(1)
|
||||
saverr = os.dup(2)
|
||||
os.close(1)
|
||||
|
@ -67,7 +67,13 @@ plugins_command_run(const char * const input)
|
||||
int num_args = g_strv_length(args);
|
||||
PyObject *p_args = NULL;
|
||||
if (num_args == 0) {
|
||||
PyObject_CallObject(command->p_callback, p_args);
|
||||
if (command->max_args == 1) {
|
||||
p_args = Py_BuildValue("(O)", Py_BuildValue(""));
|
||||
PyObject_CallObject(command->p_callback, p_args);
|
||||
Py_XDECREF(p_args);
|
||||
} else {
|
||||
PyObject_CallObject(command->p_callback, p_args);
|
||||
}
|
||||
} else if (num_args == 1) {
|
||||
p_args = Py_BuildValue("(s)", args[0]);
|
||||
PyObject_CallObject(command->p_callback, p_args);
|
||||
|
@ -104,6 +104,14 @@ plugins_on_connect(void)
|
||||
_run_plugins("prof_on_connect", NULL);
|
||||
}
|
||||
|
||||
void
|
||||
plugins_on_message(const char * const jid, const char * const message)
|
||||
{
|
||||
PyObject *p_args = Py_BuildValue("ss", jid, message);
|
||||
_run_plugins("prof_on_message", p_args);
|
||||
Py_XDECREF(p_args);
|
||||
}
|
||||
|
||||
static GSList *
|
||||
_get_module_names(void)
|
||||
{
|
||||
|
@ -26,6 +26,7 @@
|
||||
void plugins_init(void);
|
||||
void plugins_on_start(void);
|
||||
void plugins_on_connect(void);
|
||||
void plugins_on_message(const char * const jid, const char * const message);
|
||||
void plugins_shutdown(void);
|
||||
gboolean plugins_command_run(const char * const cmd);
|
||||
void plugins_run_timed(void);
|
||||
|
@ -119,6 +119,8 @@ prof_handle_incoming_message(char *from, char *message, gboolean priv)
|
||||
ui_incoming_msg(from, message, NULL, priv);
|
||||
ui_current_page_off();
|
||||
|
||||
plugins_on_message(from, message);
|
||||
|
||||
if (prefs_get_boolean(PREF_CHLOG) && !priv) {
|
||||
Jid *from_jid = jid_create(from);
|
||||
const char *jid = jabber_get_fulljid();
|
||||
@ -136,6 +138,8 @@ prof_handle_delayed_message(char *from, char *message, GTimeVal tv_stamp,
|
||||
ui_incoming_msg(from, message, &tv_stamp, priv);
|
||||
ui_current_page_off();
|
||||
|
||||
plugins_on_message(from, message);
|
||||
|
||||
if (prefs_get_boolean(PREF_CHLOG) && !priv) {
|
||||
Jid *from_jid = jid_create(from);
|
||||
const char *jid = jabber_get_fulljid();
|
||||
|
Loading…
Reference in New Issue
Block a user