Merge remote-tracking branch 'olivierlemoal/master'
This commit is contained in:
37
browser.py
37
browser.py
@@ -5,18 +5,20 @@ import re
|
|||||||
|
|
||||||
_lastlink = {}
|
_lastlink = {}
|
||||||
|
|
||||||
|
|
||||||
def _cmd_browser(url):
|
def _cmd_browser(url):
|
||||||
global _lastlink
|
global _lastlink
|
||||||
link = None
|
link = None
|
||||||
|
|
||||||
# use arg if supplied
|
# use arg if supplied
|
||||||
if (url != None):
|
if (url is not None):
|
||||||
link = url
|
link = url
|
||||||
else:
|
else:
|
||||||
jid = prof.get_current_recipient()
|
jid = prof.get_current_recipient()
|
||||||
|
room = prof.get_current_muc()
|
||||||
|
|
||||||
# check if in chat window
|
# check if in chat window
|
||||||
if (jid != None):
|
if (jid is not None):
|
||||||
|
|
||||||
# check for link from recipient
|
# check for link from recipient
|
||||||
if jid in _lastlink.keys():
|
if jid in _lastlink.keys():
|
||||||
@@ -24,15 +26,23 @@ def _cmd_browser(url):
|
|||||||
else:
|
else:
|
||||||
prof.cons_show("No links found from " + jid)
|
prof.cons_show("No links found from " + jid)
|
||||||
|
|
||||||
# not in chat window
|
# check if in muc window
|
||||||
|
elif (room is not None):
|
||||||
|
if room in _lastlink.keys():
|
||||||
|
link = _lastlink[room]
|
||||||
|
else:
|
||||||
|
prof.cons_show("No links found from " + room)
|
||||||
|
|
||||||
|
# not in chat/muc window
|
||||||
else:
|
else:
|
||||||
prof.cons_show("You must supply a URL to the /browser command")
|
prof.cons_show("You must supply a URL to the /browser command")
|
||||||
|
|
||||||
# open the browser if link found
|
# open the browser if link found
|
||||||
if (link != None):
|
if (link is not None):
|
||||||
prof.cons_show("Opening " + link + " in browser")
|
prof.cons_show("Opening " + link + " in browser")
|
||||||
_open_browser(link)
|
_open_browser(link)
|
||||||
|
|
||||||
|
|
||||||
def _open_browser(url):
|
def _open_browser(url):
|
||||||
savout = os.dup(1)
|
savout = os.dup(1)
|
||||||
saverr = os.dup(2)
|
saverr = os.dup(2)
|
||||||
@@ -45,16 +55,25 @@ def _open_browser(url):
|
|||||||
os.dup2(savout, 1)
|
os.dup2(savout, 1)
|
||||||
os.dup2(saverr, 2)
|
os.dup2(saverr, 2)
|
||||||
|
|
||||||
|
|
||||||
def prof_init(version, status):
|
def prof_init(version, status):
|
||||||
prof.register_command("/browser", 0, 1,
|
prof.register_command("/browser", 0, 1,
|
||||||
"/browser [url]",
|
"/browser [url]",
|
||||||
"View a URL in the browser.",
|
"View a URL in the browser.",
|
||||||
"View a URL in the browser, if no argument is supplied, " +
|
"View a URL in the browser, if no argument is supplied, " +
|
||||||
"the last received URL will be used.",
|
"the last received URL will be used.",
|
||||||
_cmd_browser)
|
_cmd_browser)
|
||||||
|
|
||||||
|
|
||||||
def prof_post_chat_message_display(jid, message):
|
def prof_post_chat_message_display(jid, message):
|
||||||
global _lastlink
|
global _lastlink
|
||||||
links = re.findall(r'(https?://\S+)', message)
|
links = re.findall(r'(https?://\S+)', message)
|
||||||
if (len(links) > 0):
|
if (len(links) > 0):
|
||||||
_lastlink[jid] = links[len(links)-1]
|
_lastlink[jid] = links[len(links)-1]
|
||||||
|
|
||||||
|
|
||||||
|
def prof_post_room_message_display(room, nick, message):
|
||||||
|
global _lastlink
|
||||||
|
links = re.findall(r'(https?://\S+)', message)
|
||||||
|
if (len(links) > 0):
|
||||||
|
_lastlink[room] = links[len(links)-1]
|
||||||
|
|||||||
Reference in New Issue
Block a user