From b304f4fb49c8b01ef27d1af3ac09b8fa8ada30a6 Mon Sep 17 00:00:00 2001 From: yago Date: Sun, 12 Apr 2015 20:14:21 +0200 Subject: [PATCH] download_media plugin --- plugins/download_media.lua | 44 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 plugins/download_media.lua diff --git a/plugins/download_media.lua b/plugins/download_media.lua new file mode 100644 index 0000000..75e983e --- /dev/null +++ b/plugins/download_media.lua @@ -0,0 +1,44 @@ +local function callback(extra, success, result) + if success then + print('File downloaded to:', result) + else + print('Error downloading: '..extra) + end +end + +local function run(msg, matches) + if msg.media then + if msg.media.type == 'document' then + load_document(msg.id, callback, msg.id) + end + if msg.media.type == 'photo' then + load_photo(msg.id, callback, msg.id) + end + if msg.media.type == 'video' then + load_video(msg.id, callback, msg.id) + end + if msg.media.type == 'audio' then + load_audio(msg.id, callback, msg.id) + end + end +end + +local function pre_process(msg) + if not msg.text and msg.media then + msg.text = '['..msg.media.type..']' + end + return msg +end + +return { + description = "When bot receives a media msg, download the media.", + usage = "", + run = run, + patterns = { + '%[(document)%]', + '%[(photo)%]', + '%[(video)%]', + '%[(audio)%]' + }, + pre_process = pre_process +} \ No newline at end of file