mirror of
https://github.com/gryf/weechat-highlightxmpp.git
synced 2025-12-19 04:20:16 +01:00
Add some options to surpass the output.
This commit is contained in:
@@ -40,6 +40,7 @@
|
|||||||
#
|
#
|
||||||
# /set plugins.var.python.highlightxmpp.debug off
|
# /set plugins.var.python.highlightxmpp.debug off
|
||||||
#
|
#
|
||||||
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
import weechat
|
import weechat
|
||||||
@@ -63,6 +64,9 @@ def send_xmpp(data, signal, message):
|
|||||||
command = weechat.config_get_plugin('command').split(' ')
|
command = weechat.config_get_plugin('command').split(' ')
|
||||||
debug = weechat.config_get_plugin('debug') == 'on'
|
debug = weechat.config_get_plugin('debug') == 'on'
|
||||||
|
|
||||||
|
if os.path.exists(os.path.expanduser("~/.dont_send_xmpp")):
|
||||||
|
return weechat.WEECHAT_RC_OK
|
||||||
|
|
||||||
if not jid:
|
if not jid:
|
||||||
weechat.prnt('', 'You need to provide destination JID to use this '
|
weechat.prnt('', 'You need to provide destination JID to use this '
|
||||||
'plugin.')
|
'plugin.')
|
||||||
@@ -70,19 +74,26 @@ def send_xmpp(data, signal, message):
|
|||||||
|
|
||||||
command.append(jid)
|
command.append(jid)
|
||||||
|
|
||||||
pipe = subprocess.Popen(command, stdin=subprocess.PIPE,
|
try:
|
||||||
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
pipe = subprocess.Popen(command, stdin=subprocess.PIPE,
|
||||||
|
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
|
except FileNotFoundError as ex:
|
||||||
|
if debug:
|
||||||
|
weechat.prnt('', 'Command %s cannot be find.' % ex.filename)
|
||||||
|
return weechat.WEECHAT_RC_OK
|
||||||
|
|
||||||
try:
|
try:
|
||||||
message = message.encode()
|
message = message.encode()
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
_, stderr = pipe.communicate(input=message)
|
# don't throw your output on the screen.
|
||||||
|
res = pipe.communicate(input=message)
|
||||||
if pipe.returncode != 0 and debug:
|
if pipe.returncode != 0 and debug:
|
||||||
try:
|
try:
|
||||||
stderr = stderr.decode()
|
stderr = res[1].decode()
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
pass
|
stderr = res[1]
|
||||||
weechat.prnt('', 'Error sending message to %s:\n%s' % (jid, stderr))
|
weechat.prnt('', 'Error sending message to %s:\n%s' % (jid, stderr))
|
||||||
return weechat.WEECHAT_RC_OK
|
return weechat.WEECHAT_RC_OK
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user