Add some options to surpass the output.

This commit is contained in:
2023-11-07 19:28:01 +01:00
parent 0e78873a71
commit a8c3eeda14

View File

@@ -40,6 +40,7 @@
#
# /set plugins.var.python.highlightxmpp.debug off
#
import os
import subprocess
import weechat
@@ -63,6 +64,9 @@ def send_xmpp(data, signal, message):
command = weechat.config_get_plugin('command').split(' ')
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:
weechat.prnt('', 'You need to provide destination JID to use this '
'plugin.')
@@ -70,19 +74,26 @@ def send_xmpp(data, signal, message):
command.append(jid)
pipe = subprocess.Popen(command, stdin=subprocess.PIPE,
stdout=subprocess.PIPE, stderr=subprocess.PIPE)
try:
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:
message = message.encode()
except UnicodeDecodeError:
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:
try:
stderr = stderr.decode()
stderr = res[1].decode()
except UnicodeDecodeError:
pass
stderr = res[1]
weechat.prnt('', 'Error sending message to %s:\n%s' % (jid, stderr))
return weechat.WEECHAT_RC_OK