[O] Send as file
This commit is contained in:
+11
-1
@@ -1,3 +1,4 @@
|
|||||||
|
import datetime
|
||||||
import difflib
|
import difflib
|
||||||
import json
|
import json
|
||||||
import re
|
import re
|
||||||
@@ -66,11 +67,20 @@ def createTaskCallback(user: str, taskName: str, request):
|
|||||||
|
|
||||||
# Compare diff
|
# Compare diff
|
||||||
else:
|
else:
|
||||||
|
# Generate diff
|
||||||
diffRaw = difflib.unified_diff(cache[user][taskName].splitlines(1), text.splitlines(1), fromfile='before', tofile='after')
|
diffRaw = difflib.unified_diff(cache[user][taskName].splitlines(1), text.splitlines(1), fromfile='before', tofile='after')
|
||||||
diff = ''.join(diffRaw)
|
diff = ''.join(diffRaw)
|
||||||
cache[user][taskName] = text
|
cache[user][taskName] = text
|
||||||
|
|
||||||
if diff != '':
|
if diff != '':
|
||||||
context.bot.send_photo(chat_id=int(user), photo=BytesIO(render(diff)), caption='*%s Changed!*' % taskName, parse_mode='markdown')
|
# Render diff
|
||||||
|
doc = BytesIO(render(diff))
|
||||||
|
time = datetime.datetime.now().strftime('%b %d %Y %H-%M-%S')
|
||||||
|
fileName = 'diff %s %s.png' % (taskName, time)
|
||||||
|
caption = '*%s Changed!*' % taskName
|
||||||
|
|
||||||
|
# Send as file
|
||||||
|
context.bot.send_document(int(user), doc, fileName, caption, parse_mode='markdown')
|
||||||
return task
|
return task
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user