slackpost: Properly strip out reply markers

Remove all lines beginning with ">", and the line immediately before
them.

Signed-off-by: Anna Schumaker <Anna@OcarinaProject.net>
This commit is contained in:
Anna Schumaker 2015-05-27 11:10:47 -04:00
parent d07bf33f44
commit 29815fc28b
2 changed files with 10 additions and 4 deletions

View File

@ -3,9 +3,7 @@
#
from . import api
from . import auth
from urllib import request
def postMessage(channel, text):
post = request.quote(text)
api.call("chat.postMessage", token = auth.token(), channel = channel,
text = post, as_user = True, parse = "full")
text = text, as_user = True, parse = "full")

View File

@ -25,5 +25,13 @@ for c in slack.channels.list():
if channel == None:
sys.exit(1)
text = headers.get_payload().split("\n")[0]
lines = headers.get_payload().strip().split("\n")
# Strip out quoted text
if lines[-1][0] == ">":
while lines[-1][0] == ">":
lines.pop(-1)
lines.pop(-1)
text = ' '.join(lines).strip()
channel.post(text)