Add resource to chat message plugin hooks

This commit is contained in:
James Booth
2016-08-10 21:38:57 +01:00
parent 72542b75dc
commit 009a5c79a3
6 changed files with 110 additions and 110 deletions

View File

@@ -78,44 +78,44 @@ def prof_init(version, status, account_name, fulljid):
prof.register_command("/browser", 0, 1, synopsis, description, args, examples, _cmd_browser) prof.register_command("/browser", 0, 1, synopsis, description, args, examples, _cmd_browser)
def prof_on_chat_win_focus(jid): def prof_on_chat_win_focus(barejid):
prof.completer_clear("/browser") prof.completer_clear("/browser")
if jid in _links: if barejid in _links:
prof.completer_add("/browser", _links[jid]) prof.completer_add("/browser", _links[barejid])
def prof_on_room_win_focus(room): def prof_on_room_win_focus(barejid):
prof.completer_clear("/browser") prof.completer_clear("/browser")
if room in _links: if barejid in _links:
prof.completer_add("/browser", _links[room]) prof.completer_add("/browser", _links[barejid])
def _process_message(jid, current_jid, message): def _process_message(barejid, current_jid, message):
links = re.findall(r'(https?://\S+)', message) links = re.findall(r'(https?://\S+)', message)
if (len(links) > 0): if (len(links) > 0):
if jid not in _links: if barejid not in _links:
_links[jid] = [] _links[barejid] = []
# add to list of links for jid # add to list of links for barejid
for link in links: for link in links:
if link not in _links[jid]: if link not in _links[barejid]:
_links[jid].append(link) _links[barejid].append(link)
# add to autocompleter if message for current window # add to autocompleter if message for current window
if current_jid == jid: if current_jid == barejid:
prof.completer_add("/browser", _links[jid]) prof.completer_add("/browser", _links[barejid])
# set last link for jid # set last link for barejid
_lastlink[jid] = links[len(links)-1] _lastlink[barejid] = links[len(links)-1]
def prof_post_chat_message_display(jid, message): def prof_post_chat_message_display(barejid, resource, message):
current_jid = prof.get_current_recipient() current_jid = prof.get_current_recipient()
_process_message(jid, current_jid, message) _process_message(barejid, current_jid, message)
def prof_post_room_message_display(room, nick, message): def prof_post_room_message_display(barejid, nick, message):
current_jid = prof.get_current_muc() current_jid = prof.get_current_muc()
_process_message(room, current_jid, message) _process_message(barejid, current_jid, message)
def prof_on_room_history_message(room, nick, message, timestamp): def prof_on_room_history_message(barejid, nick, message, timestamp):
current_jid = prof.get_current_muc() current_jid = prof.get_current_muc()
_process_message(room, current_jid, message) _process_message(barejid, current_jid, message)

View File

@@ -10,12 +10,12 @@ bot_session = {}
bot_state = False bot_state = False
def prof_post_chat_message_display(jid, message): def prof_post_chat_message_display(barejid, resource, message):
if bot_state: if bot_state:
if jid not in bot_session: if barejid not in bot_session:
bot_session[jid] = bot.create_session() bot_session[barejid] = bot.create_session()
response = bot_session[jid].think(message) response = bot_session[barejid].think(message)
prof.send_line("/msg " + jid + " " + response) prof.send_line("/msg " + barejid + " " + response)
def _cmd_chatterbot(state): def _cmd_chatterbot(state):

View File

@@ -18,13 +18,13 @@ def _emote(input_str):
return result return result
def prof_pre_chat_message_display(jid, message): def prof_pre_chat_message_display(barejid, resource, message):
return _emote(message) return _emote(message)
def prof_pre_room_message_display(room, nick, message): def prof_pre_room_message_display(barejid, nick, message):
return _emote(message) return _emote(message)
def prof_pre_priv_message_display(room, nick, message): def prof_pre_priv_message_display(barejid, nick, message):
return _emote(message) return _emote(message)

14
say.py
View File

@@ -20,27 +20,27 @@ def say(message):
os.system("echo '" + message + "' | espeak " + args + " 2>/dev/null") os.system("echo '" + message + "' | espeak " + args + " 2>/dev/null")
def prof_post_chat_message_display(jid, message): def prof_post_chat_message_display(barejid, resource, message):
enabled = prof.settings_string_get("say", "enabled", "off") enabled = prof.settings_string_get("say", "enabled", "off")
current_recipient = prof.get_current_recipient() current_recipient = prof.get_current_recipient()
if enabled == "on" or (enabled == "active" and current_recipient == jid): if enabled == "on" or (enabled == "active" and current_recipient == barejid):
say(jid + " says " + message) say(barejid + " says " + message)
return message return message
def prof_post_room_message_display(room, nick, message): def prof_post_room_message_display(barejid, nick, message):
enabled = prof.settings_string_get("say", "enabled", "off") enabled = prof.settings_string_get("say", "enabled", "off")
current_muc = prof.get_current_muc() current_muc = prof.get_current_muc()
if enabled == "on": if enabled == "on":
say(nick + " in " + room + " says " + message) say(nick + " in " + barejid + " says " + message)
elif enabled == "active" and current_muc == room: elif enabled == "active" and current_muc == barejid:
say(nick + " says " + message) say(nick + " says " + message)
return message return message
def prof_post_priv_message_display(room, nick, message): def prof_post_priv_message_display(barejid, nick, message):
# TODO add get current nick hook for private chats # TODO add get current nick hook for private chats
if enabled: if enabled:
say(nick + " says " + message) say(nick + " says " + message)

View File

@@ -565,72 +565,72 @@ def prof_on_disconnect(account_name, fulljid):
prof.win_show(plugin_win, "fired -> prof_on_disconnect: " + account_name + ", " + fulljid) prof.win_show(plugin_win, "fired -> prof_on_disconnect: " + account_name + ", " + fulljid)
def prof_pre_chat_message_display(jid, message): def prof_pre_chat_message_display(barejid, resource, message):
prof.win_create(plugin_win, _handle_win_input) prof.win_create(plugin_win, _handle_win_input)
prof.win_show(plugin_win, "fired -> prof_pre_chat_message_display: " + jid + ", " + message) prof.win_show(plugin_win, "fired -> prof_pre_chat_message_display: " + barejid + "/" + resource + ", " + message)
def prof_post_chat_message_display(jid, message): def prof_post_chat_message_display(barejid, resource, message):
prof.win_create(plugin_win, _handle_win_input) prof.win_create(plugin_win, _handle_win_input)
prof.win_show(plugin_win, "fired -> prof_post_chat_message_display: " + jid + ", " + message) prof.win_show(plugin_win, "fired -> prof_post_chat_message_display: " + barejid + "/" + resource + ", " + message)
def prof_pre_chat_message_send(jid, message): def prof_pre_chat_message_send(barejid, message):
prof.win_create(plugin_win, _handle_win_input) prof.win_create(plugin_win, _handle_win_input)
prof.win_show(plugin_win, "fired -> prof_pre_chat_message_send: " + jid + ", " + message) prof.win_show(plugin_win, "fired -> prof_pre_chat_message_send: " + barejid + ", " + message)
def prof_post_chat_message_send(jid, message): def prof_post_chat_message_send(barejid, message):
prof.win_create(plugin_win, _handle_win_input) prof.win_create(plugin_win, _handle_win_input)
prof.win_show(plugin_win, "fired -> prof_post_chat_message_send: " + jid + ", " + message) prof.win_show(plugin_win, "fired -> prof_post_chat_message_send: " + barejid + ", " + message)
def prof_pre_room_message_display(room, nick, message): def prof_pre_room_message_display(barejid, nick, message):
prof.win_create(plugin_win, _handle_win_input) prof.win_create(plugin_win, _handle_win_input)
prof.win_show(plugin_win, "fired -> prof_pre_room_message_display: " + room + ", " + nick + ", " + message) prof.win_show(plugin_win, "fired -> prof_pre_room_message_display: " + barejid + ", " + nick + ", " + message)
def prof_post_room_message_display(room, nick, message): def prof_post_room_message_display(barejid, nick, message):
prof.win_create(plugin_win, _handle_win_input) prof.win_create(plugin_win, _handle_win_input)
prof.win_show(plugin_win, "fired -> prof_post_room_message_display: " + room + ", " + nick + ", " + message) prof.win_show(plugin_win, "fired -> prof_post_room_message_display: " + barejid + ", " + nick + ", " + message)
def prof_pre_room_message_send(room, message): def prof_pre_room_message_send(barejid, message):
prof.win_create(plugin_win, _handle_win_input) prof.win_create(plugin_win, _handle_win_input)
prof.win_show(plugin_win, "fired -> prof_pre_room_message_send: " + room + ", " + message) prof.win_show(plugin_win, "fired -> prof_pre_room_message_send: " + barejid + ", " + message)
def prof_post_room_message_send(room, message): def prof_post_room_message_send(barejid, message):
prof.win_create(plugin_win, _handle_win_input) prof.win_create(plugin_win, _handle_win_input)
prof.win_show(plugin_win, "fired -> prof_post_room_message_send: " + room + ", " + message) prof.win_show(plugin_win, "fired -> prof_post_room_message_send: " + barejid + ", " + message)
def prof_on_room_history_message(room, nick, message, timestamp): def prof_on_room_history_message(barejid, nick, message, timestamp):
prof.win_create(plugin_win, _handle_win_input) prof.win_create(plugin_win, _handle_win_input)
if timestamp: if timestamp:
prof.win_show(plugin_win, "fired -> prof_on_room_history_message: " + room + ", " + nick + ", " + message + ", " + timestamp) prof.win_show(plugin_win, "fired -> prof_on_room_history_message: " + barejid + ", " + nick + ", " + message + ", " + timestamp)
else: else:
prof.win_show(plugin_win, "fired -> prof_on_room_history_message: " + room + ", " + nick + ", " + message) prof.win_show(plugin_win, "fired -> prof_on_room_history_message: " + barejid + ", " + nick + ", " + message)
def prof_pre_priv_message_display(room, nick, message): def prof_pre_priv_message_display(barejid, nick, message):
prof.win_create(plugin_win, _handle_win_input) prof.win_create(plugin_win, _handle_win_input)
prof.win_show(plugin_win, "fired -> prof_pre_priv_message_display: " + room + ", " + nick + ", " + message) prof.win_show(plugin_win, "fired -> prof_pre_priv_message_display: " + barejid + ", " + nick + ", " + message)
def prof_post_priv_message_display(room, nick, message): def prof_post_priv_message_display(barejid, nick, message):
prof.win_create(plugin_win, _handle_win_input) prof.win_create(plugin_win, _handle_win_input)
prof.win_show(plugin_win, "fired -> prof_post_priv_message_display: " + room + ", " + nick + ", " + message) prof.win_show(plugin_win, "fired -> prof_post_priv_message_display: " + barejid + ", " + nick + ", " + message)
def prof_pre_priv_message_send(room, nick, message): def prof_pre_priv_message_send(barejid, nick, message):
prof.win_create(plugin_win, _handle_win_input) prof.win_create(plugin_win, _handle_win_input)
prof.win_show(plugin_win, "fired -> prof_pre_priv_message_send: " + room + ", " + nick + ", " + message) prof.win_show(plugin_win, "fired -> prof_pre_priv_message_send: " + barejid + ", " + nick + ", " + message)
def prof_post_priv_message_send(room, nick, message): def prof_post_priv_message_send(barejid, nick, message):
prof.win_create(plugin_win, _handle_win_input) prof.win_create(plugin_win, _handle_win_input)
prof.win_show(plugin_win, "fired -> prof_post_priv_message_send: " + room + ", " + nick + ", " + message) prof.win_show(plugin_win, "fired -> prof_post_priv_message_send: " + barejid + ", " + nick + ", " + message)
def prof_on_message_stanza_send(stanza): def prof_on_message_stanza_send(stanza):
@@ -687,6 +687,6 @@ def prof_on_chat_win_focus(barejid):
prof.win_show(plugin_win, "fired -> prof_on_chat_win_focus: " + barejid) prof.win_show(plugin_win, "fired -> prof_on_chat_win_focus: " + barejid)
def prof_on_room_win_focus(roomjid): def prof_on_room_win_focus(barejid):
prof.win_create(plugin_win, _handle_win_input) prof.win_create(plugin_win, _handle_win_input)
prof.win_show(plugin_win, "fired -> prof_on_room_win_focus: " + roomjid) prof.win_show(plugin_win, "fired -> prof_on_room_win_focus: " + barejid)

View File

@@ -744,163 +744,163 @@ prof_on_disconnect(const char * const account_name, const char * const fulljid)
} }
char* char*
prof_pre_chat_message_display(const char * const jid, const char *message) prof_pre_chat_message_display(const char * const barejid, const char *const resource, const char *message)
{ {
prof_win_create(plugin_win, handle_win_input); prof_win_create(plugin_win, handle_win_input);
char *str = "fired -> prof_pre_chat_message_display: "; char *str = "fired -> prof_pre_chat_message_display: ";
char buf[strlen(str) + strlen(jid) + 2 + strlen(message) + 1]; char buf[strlen(str) + strlen(barejid) + 1 + strlen(resource) + 2 + strlen(message) + 1];
sprintf(buf, "%s%s, %s", str, jid, message); sprintf(buf, "%s%s/%s, %s", str, barejid, resource, message);
prof_win_show(plugin_win, buf); prof_win_show(plugin_win, buf);
return NULL; return NULL;
} }
void void
prof_post_chat_message_display(const char * const jid, const char *message) prof_post_chat_message_display(const char * const barejid, const char *const resource, const char *message)
{ {
prof_win_create(plugin_win, handle_win_input); prof_win_create(plugin_win, handle_win_input);
char *str = "fired -> prof_post_chat_message_display: "; char *str = "fired -> prof_post_chat_message_display: ";
char buf[strlen(str) + strlen(jid) + 2 + strlen(message) + 1]; char buf[strlen(str) + strlen(barejid) + 1 + strlen(resource) + 2 + strlen(message) + 1];
sprintf(buf, "%s%s, %s", str, jid, message); sprintf(buf, "%s%s/%s, %s", str, barejid, resource, message);
prof_win_show(plugin_win, buf); prof_win_show(plugin_win, buf);
} }
char* char*
prof_pre_chat_message_send(const char * const jid, const char *message) prof_pre_chat_message_send(const char * const barejid, const char *message)
{ {
prof_win_create(plugin_win, handle_win_input); prof_win_create(plugin_win, handle_win_input);
char *str = "fired -> prof_pre_chat_message_send: "; char *str = "fired -> prof_pre_chat_message_send: ";
char buf[strlen(str) + strlen(jid) + 2 + strlen(message) + 1]; char buf[strlen(str) + strlen(barejid) + 2 + strlen(message) + 1];
sprintf(buf, "%s%s, %s", str, jid, message); sprintf(buf, "%s%s, %s", str, barejid, message);
prof_win_show(plugin_win, buf); prof_win_show(plugin_win, buf);
return NULL; return NULL;
} }
void void
prof_post_chat_message_send(const char * const jid, const char *message) prof_post_chat_message_send(const char * const barejid, const char *message)
{ {
prof_win_create(plugin_win, handle_win_input); prof_win_create(plugin_win, handle_win_input);
char *str = "fired -> prof_post_chat_message_send: "; char *str = "fired -> prof_post_chat_message_send: ";
char buf[strlen(str) + strlen(jid) + 2 + strlen(message) + 1]; char buf[strlen(str) + strlen(barejid) + 2 + strlen(message) + 1];
sprintf(buf, "%s%s, %s", str, jid, message); sprintf(buf, "%s%s, %s", str, barejid, message);
prof_win_show(plugin_win, buf); prof_win_show(plugin_win, buf);
} }
char* char*
prof_pre_room_message_display(const char * const room, const char * const nick, const char *message) prof_pre_room_message_display(const char * const barejid, const char * const nick, const char *message)
{ {
prof_win_create(plugin_win, handle_win_input); prof_win_create(plugin_win, handle_win_input);
char *str = "fired -> prof_pre_room_message_display: "; char *str = "fired -> prof_pre_room_message_display: ";
char buf[strlen(str) + strlen(room) + 2 + strlen(nick) + 2 + strlen(message) + 1]; char buf[strlen(str) + strlen(barejid) + 2 + strlen(nick) + 2 + strlen(message) + 1];
sprintf(buf, "%s%s, %s, %s", str, room, nick, message); sprintf(buf, "%s%s, %s, %s", str, barejid, nick, message);
prof_win_show(plugin_win, buf); prof_win_show(plugin_win, buf);
return NULL; return NULL;
} }
void void
prof_post_room_message_display(const char * const room, const char * const nick, const char *message) prof_post_room_message_display(const char * const barejid, const char * const nick, const char *message)
{ {
prof_win_create(plugin_win, handle_win_input); prof_win_create(plugin_win, handle_win_input);
char *str = "fired -> prof_post_room_message_display: "; char *str = "fired -> prof_post_room_message_display: ";
char buf[strlen(str) + strlen(room) + 2 + strlen(nick) + 2 + strlen(message) + 1]; char buf[strlen(str) + strlen(barejid) + 2 + strlen(nick) + 2 + strlen(message) + 1];
sprintf(buf, "%s%s, %s, %s", str, room, nick, message); sprintf(buf, "%s%s, %s, %s", str, barejid, nick, message);
prof_win_show(plugin_win, buf); prof_win_show(plugin_win, buf);
} }
char * char *
prof_pre_room_message_send(const char * const room, const char *message) prof_pre_room_message_send(const char * const barejid, const char *message)
{ {
prof_win_create(plugin_win, handle_win_input); prof_win_create(plugin_win, handle_win_input);
char *str = "fired -> prof_pre_room_message_send: "; char *str = "fired -> prof_pre_room_message_send: ";
char buf[strlen(str) + strlen(room) + 2 + strlen(message) + 1]; char buf[strlen(str) + strlen(barejid) + 2 + strlen(message) + 1];
sprintf(buf, "%s%s, %s", str, room, message); sprintf(buf, "%s%s, %s", str, barejid, message);
prof_win_show(plugin_win, buf); prof_win_show(plugin_win, buf);
return NULL; return NULL;
} }
void void
prof_post_room_message_send(const char * const room, const char *message) prof_post_room_message_send(const char * const barejid, const char *message)
{ {
prof_win_create(plugin_win, handle_win_input); prof_win_create(plugin_win, handle_win_input);
char *str = "fired -> prof_post_room_message_send: "; char *str = "fired -> prof_post_room_message_send: ";
char buf[strlen(str) + strlen(room) + 2 + strlen(message) + 1]; char buf[strlen(str) + strlen(barejid) + 2 + strlen(message) + 1];
sprintf(buf, "%s%s, %s", str, room, message); sprintf(buf, "%s%s, %s", str, barejid, message);
prof_win_show(plugin_win, buf); prof_win_show(plugin_win, buf);
} }
void void
prof_on_room_history_message(const char * const room, const char *const nick, const char *const message, const char *const timestamp) prof_on_room_history_message(const char * const barejid, const char *const nick, const char *const message, const char *const timestamp)
{ {
prof_win_create(plugin_win, handle_win_input); prof_win_create(plugin_win, handle_win_input);
char *str = "fired -> prof_on_room_history_message: "; char *str = "fired -> prof_on_room_history_message: ";
if (timestamp == NULL) { if (timestamp == NULL) {
char buf[strlen(str) + strlen(room) + 2 + strlen(nick) + 2 + strlen(message) + 1]; char buf[strlen(str) + strlen(barejid) + 2 + strlen(nick) + 2 + strlen(message) + 1];
sprintf(buf, "%s%s, %s, %s", str, room, nick, message); sprintf(buf, "%s%s, %s, %s", str, barejid, nick, message);
prof_win_show(plugin_win, buf); prof_win_show(plugin_win, buf);
} else { } else {
char buf[strlen(str) + strlen(room) + 2 + strlen(nick) + 2 + strlen(message) + 2 + strlen(timestamp) + 1]; char buf[strlen(str) + strlen(barejid) + 2 + strlen(nick) + 2 + strlen(message) + 2 + strlen(timestamp) + 1];
sprintf(buf, "%s%s, %s, %s, %s", str, room, nick, message, timestamp); sprintf(buf, "%s%s, %s, %s, %s", str, barejid, nick, message, timestamp);
prof_win_show(plugin_win, buf); prof_win_show(plugin_win, buf);
} }
} }
char * char *
prof_pre_priv_message_display(const char * const room, const char * const nick, const char *message) prof_pre_priv_message_display(const char * const barejid, const char * const nick, const char *message)
{ {
prof_win_create(plugin_win, handle_win_input); prof_win_create(plugin_win, handle_win_input);
char *str = "fired -> prof_pre_priv_message_display: "; char *str = "fired -> prof_pre_priv_message_display: ";
char buf[strlen(str) + strlen(room) + 2 + strlen(nick) + 2 + strlen(message) + 1]; char buf[strlen(str) + strlen(barejid) + 2 + strlen(nick) + 2 + strlen(message) + 1];
sprintf(buf, "%s%s, %s, %s", str, room, nick, message); sprintf(buf, "%s%s, %s, %s", str, barejid, nick, message);
prof_win_show(plugin_win, buf); prof_win_show(plugin_win, buf);
return NULL; return NULL;
} }
void void
prof_post_priv_message_display(const char * const room, const char * const nick, const char *message) prof_post_priv_message_display(const char * const barejid, const char * const nick, const char *message)
{ {
prof_win_create(plugin_win, handle_win_input); prof_win_create(plugin_win, handle_win_input);
char *str = "fired -> prof_post_priv_message_display: "; char *str = "fired -> prof_post_priv_message_display: ";
char buf[strlen(str) + strlen(room) + 2 + strlen(nick) + 2 + strlen(message) + 1]; char buf[strlen(str) + strlen(barejid) + 2 + strlen(nick) + 2 + strlen(message) + 1];
sprintf(buf, "%s%s, %s, %s", str, room, nick, message); sprintf(buf, "%s%s, %s, %s", str, barejid, nick, message);
prof_win_show(plugin_win, buf); prof_win_show(plugin_win, buf);
} }
char * char *
prof_pre_priv_message_send(const char * const room, const char * const nick, const char *message) prof_pre_priv_message_send(const char * const barejid, const char * const nick, const char *message)
{ {
prof_win_create(plugin_win, handle_win_input); prof_win_create(plugin_win, handle_win_input);
char *str = "fired -> prof_pre_priv_message_send: "; char *str = "fired -> prof_pre_priv_message_send: ";
char buf[strlen(str) + strlen(room) + 2 + strlen(nick) + 2 + strlen(message) + 1]; char buf[strlen(str) + strlen(barejid) + 2 + strlen(nick) + 2 + strlen(message) + 1];
sprintf(buf, "%s%s, %s, %s", str, room, nick, message); sprintf(buf, "%s%s, %s, %s", str, barejid, nick, message);
prof_win_show(plugin_win, buf); prof_win_show(plugin_win, buf);
return NULL; return NULL;
} }
void void
prof_post_priv_message_send(const char * const room, const char * const nick, const char *message) prof_post_priv_message_send(const char * const barejid, const char * const nick, const char *message)
{ {
prof_win_create(plugin_win, handle_win_input); prof_win_create(plugin_win, handle_win_input);
char *str = "fired -> prof_post_priv_message_send: "; char *str = "fired -> prof_post_priv_message_send: ";
char buf[strlen(str) + strlen(room) + 2 + strlen(nick) + 2 + strlen(message) + 1]; char buf[strlen(str) + strlen(barejid) + 2 + strlen(nick) + 2 + strlen(message) + 1];
sprintf(buf, "%s%s, %s, %s", str, room, nick, message); sprintf(buf, "%s%s, %s, %s", str, barejid, nick, message);
prof_win_show(plugin_win, buf); prof_win_show(plugin_win, buf);
} }
@@ -1027,11 +1027,11 @@ prof_on_chat_win_focus(const char *const barejid)
} }
void void
prof_on_room_win_focus(const char *const roomjid) prof_on_room_win_focus(const char *const barejid)
{ {
prof_win_create(plugin_win, handle_win_input); prof_win_create(plugin_win, handle_win_input);
char *str = "fired -> prof_on_room_win_focus: "; char *str = "fired -> prof_on_room_win_focus: ";
char buf[strlen(str) + strlen(roomjid) + 1]; char buf[strlen(str) + strlen(barejid) + 1];
sprintf(buf, "%s%s", str, roomjid); sprintf(buf, "%s%s", str, barejid);
prof_win_show(plugin_win, buf); prof_win_show(plugin_win, buf);
} }