From 84b7062aed959054a8ea302c21779d6098d5edaf Mon Sep 17 00:00:00 2001 From: Yago Date: Fri, 27 Feb 2015 21:23:23 +0100 Subject: [PATCH 01/22] Update giphy.lua --- plugins/giphy.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/plugins/giphy.lua b/plugins/giphy.lua index b10e72f..3ab0e1c 100644 --- a/plugins/giphy.lua +++ b/plugins/giphy.lua @@ -16,6 +16,7 @@ end function search(text) local res, code = http.request(BASE_URL.."/gifs/search?q="..text.."&api_key="..API_KEY) + if code ~= 200 then return nil end local images = json:decode(res).data if #images == 0 then return nil end -- No images local i = math.random(0,#images) @@ -56,4 +57,4 @@ return { run = run } -end \ No newline at end of file +end From 5c38c4842f636c5a32dd75a425207a22bdef898e Mon Sep 17 00:00:00 2001 From: Yago Date: Fri, 27 Feb 2015 21:31:14 +0100 Subject: [PATCH 02/22] Update giphy.lua --- plugins/giphy.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/plugins/giphy.lua b/plugins/giphy.lua index 3ab0e1c..295b424 100644 --- a/plugins/giphy.lua +++ b/plugins/giphy.lua @@ -15,7 +15,10 @@ function get_random_top() end function search(text) - local res, code = http.request(BASE_URL.."/gifs/search?q="..text.."&api_key="..API_KEY) + text = URL.escape(text) + local url = BASE_URL.."/gifs/search?q="..text.."&api_key="..API_KEY + print(url) + local res, code = http.request(url) if code ~= 200 then return nil end local images = json:decode(res).data if #images == 0 then return nil end -- No images From 73f3a21904235398e8050e2ddbaf9a12a77c24e7 Mon Sep 17 00:00:00 2001 From: Yago Date: Fri, 27 Feb 2015 21:36:50 +0100 Subject: [PATCH 03/22] Update utils.lua --- bot/utils.lua | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bot/utils.lua b/bot/utils.lua index f5ef26c..efd8ccb 100644 --- a/bot/utils.lua +++ b/bot/utils.lua @@ -67,8 +67,9 @@ function download_to_file(url, file_name) } local one, c, h = http.request(options) - - local file_name = get_http_file_name(url, h) + + file_name = file_name or get_http_file_name(url, h) + local file_path = "/tmp/"..file_name print("Saved to: "..file_path) @@ -311,4 +312,4 @@ function send_document_from_url(receiver, url, cb_function, cb_extra) local file_path = download_to_file(url, false) print("File path: "..file_path) _send_document(receiver, file_path, cb_function, cb_extra) -end \ No newline at end of file +end From 2e6c0f823d98090aef3740f2017cc2247a4796df Mon Sep 17 00:00:00 2001 From: Yago Date: Fri, 27 Feb 2015 22:20:05 +0100 Subject: [PATCH 04/22] get_http_file_name if not content_type --- bot/utils.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bot/utils.lua b/bot/utils.lua index efd8ccb..1ddb1c4 100644 --- a/bot/utils.lua +++ b/bot/utils.lua @@ -46,7 +46,10 @@ function get_http_file_name(url, headers) content_type = content_type or headers["Content-type"] content_type = content_type or h["Content-Type"] - local extension = mimetype.get_mime_extension(content_type) + local extension = nil + if content_type then + extension = mimetype.get_mime_extension(content_type) + end if extension then file_name = file_name.."."..extension end From 13a787e57779843dc86fb1e5fb3501b898df3328 Mon Sep 17 00:00:00 2001 From: yago Date: Sat, 28 Feb 2015 12:30:58 +0100 Subject: [PATCH 05/22] giphy sends original if downsized doesn't exists --- plugins/giphy.lua | 38 +++++++++++++++++++++++++------------- 1 file changed, 25 insertions(+), 13 deletions(-) diff --git a/plugins/giphy.lua b/plugins/giphy.lua index 295b424..6d684fd 100644 --- a/plugins/giphy.lua +++ b/plugins/giphy.lua @@ -6,28 +6,40 @@ do local BASE_URL = 'http://api.giphy.com/v1' local API_KEY = 'dc6zaTOxFJmzC' -- public beta key -function get_random_top() - local res, code = http.request(BASE_URL.."/gifs/trending?api_key="..API_KEY) - if code ~= 200 then return nil end - local images = json:decode(res).data +function get_image(response) + local images = json:decode(response).data + if #images == 0 then return nil end -- No images local i = math.random(0,#images) - return images[i].images.downsized.url + local image = images[i] -- A random one + + if image.images.downsized then + return image.images.downsized.url + end + + if image.images.original then + return image.original.url + end + + return nil +end + +function get_random_top() + local url = BASE_URL.."/gifs/trending?api_key="..API_KEY + local response, code = http.request(url) + if code ~= 200 then return nil end + return get_image(response) end function search(text) text = URL.escape(text) local url = BASE_URL.."/gifs/search?q="..text.."&api_key="..API_KEY - print(url) - local res, code = http.request(url) + local response, code = http.request(url) if code ~= 200 then return nil end - local images = json:decode(res).data - if #images == 0 then return nil end -- No images - local i = math.random(0,#images) - return images[i].images.downsized.url + return get_image(response) end function run(msg, matches) - local gif_url = '' + local gif_url = nil -- If no search data, a random trending GIF will be sended if matches[1] == "!gif" or matches[1] == "!giphy" then @@ -60,4 +72,4 @@ return { run = run } -end +end \ No newline at end of file From 6a8be349561a8ff0fb4d1ae76d4f39bd191f7365 Mon Sep 17 00:00:00 2001 From: yago Date: Sat, 28 Feb 2015 14:09:25 +0100 Subject: [PATCH 06/22] HTTPS support for download_to_file :lock: and string:starts(text) function --- bot/utils.lua | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/bot/utils.lua b/bot/utils.lua index 1ddb1c4..91575f0 100644 --- a/bot/utils.lua +++ b/bot/utils.lua @@ -69,10 +69,22 @@ function download_to_file(url, file_name) redirect = true } - local one, c, h = http.request(options) - - file_name = file_name or get_http_file_name(url, h) - + -- nil, code, headers, status + local response = nil + + if url:starts('https') then + options.redirect = false + response = {https.request(options)} + else + response = {http.request(options)} + end + + local code = response[2] + local headers = response[3] + local status = response[4] + + file_name = file_name or get_http_file_name(url, headers) + local file_path = "/tmp/"..file_name print("Saved to: "..file_path) @@ -204,9 +216,15 @@ function string:isblank() return self:isempty() end --- Returns true if String starts with Start +-- DEPRECATED!!!!! function string.starts(String, Start) - return Start == string.sub(String,1,string.len(Start)) + print "string.starts(String, Start) is DEPRECATED use string:starts(text) instead" + return Start == string.sub(String,1,string.len(Start)) +end + +-- Returns true if String starts with Start +function string:starts(text) + return text == string.sub(self,1,string.len(text)) end -- Send image to user and delete it when finished. From dab0c97bb623e48c11666801ba3f73aafadb619f Mon Sep 17 00:00:00 2001 From: yago Date: Sat, 28 Feb 2015 14:22:53 +0100 Subject: [PATCH 07/22] Controll HTTP errors downloading images --- bot/utils.lua | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/bot/utils.lua b/bot/utils.lua index 91575f0..81f36e1 100644 --- a/bot/utils.lua +++ b/bot/utils.lua @@ -83,6 +83,8 @@ function download_to_file(url, file_name) local headers = response[3] local status = response[4] + if code ~= 200 then return nil end + file_name = file_name or get_http_file_name(url, headers) local file_path = "/tmp/"..file_name @@ -242,9 +244,18 @@ end -- Download the image and send to receiver, it will be deleted. -- cb_function and cb_extra are optionals callback function send_photo_from_url(receiver, url, cb_function, cb_extra) + -- If callback not provided + cb_function = cb_function or ok_cb + cb_extra = cb_extra or false + local file_path = download_to_file(url, false) - print("File path: "..file_path) - _send_photo(receiver, file_path, cb_function, cb_extra) + if not file_path then -- Error + local text = 'Error downloading the image' + send_msg(receiver, text, cb_function, cb_extra) + else + print("File path: "..file_path) + _send_photo(receiver, file_path, cb_function, cb_extra) + end end -- Same as send_photo_from_url but as callback function @@ -253,8 +264,13 @@ function send_photo_from_url_callback(cb_extra, success, result) local url = cb_extra.url local file_path = download_to_file(url, false) - print("File path: "..file_path) - _send_photo(receiver, file_path, cb_function, cb_extra) + if not file_path then -- Error + local text = 'Error downloading the image' + send_msg(receiver, text, ok_cb, false) + else + print("File path: "..file_path) + _send_photo(receiver, file_path, ok_cb, false) + end end -- Send multimple images asynchronous. From 9eb136b734210c84b90b1faf83c10b8f4677391c Mon Sep 17 00:00:00 2001 From: yago Date: Sat, 28 Feb 2015 14:53:39 +0100 Subject: [PATCH 08/22] string.trim(s) is deprecated. Removed some spaces tabulations --- bot/utils.lua | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/bot/utils.lua b/bot/utils.lua index 81f36e1..49a1305 100644 --- a/bot/utils.lua +++ b/bot/utils.lua @@ -33,11 +33,17 @@ function string:split(sep) return fields end --- Removes spaces +-- DEPRECATED function string.trim(s) + print("string.trim(s) is DEPRECATED use string:trim() instead") return s:gsub("^%s*(.-)%s*$", "%1") end +-- Removes spaces +function string:trim() + return self:gsub("^%s*(.-)%s*$", "%1") +end + function get_http_file_name(url, headers) -- Everything after the last / local file_name = url:match("([^/]+)$") @@ -153,24 +159,25 @@ function run_command(str) return result end +-- User has priviledges function is_sudo(msg) - local var = false - -- Check users id in config - for v,user in pairs(_config.sudo_users) do - if user == msg.from.id then - var = true - end - end - return var + local var = false + -- Check users id in config + for v,user in pairs(_config.sudo_users) do + if user == msg.from.id then + var = true + end + end + return var end -- Returns the name of the sender function get_name(msg) - local name = msg.from.first_name - if name == nil then - name = msg.from.id - end - return name + local name = msg.from.first_name + if name == nil then + name = msg.from.id + end + return name end -- Returns at table of lua files inside plugins @@ -220,7 +227,7 @@ end -- DEPRECATED!!!!! function string.starts(String, Start) - print "string.starts(String, Start) is DEPRECATED use string:starts(text) instead" + print("string.starts(String, Start) is DEPRECATED use string:starts(text) instead") return Start == string.sub(String,1,string.len(Start)) end From bdf18bfc096fbddaa32b546c77c5223b201f2f2b Mon Sep 17 00:00:00 2001 From: Yago Date: Mon, 2 Mar 2015 20:12:41 +0100 Subject: [PATCH 09/22] LICENSE name and year --- LICENSE | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/LICENSE b/LICENSE index 22fbe5d..27b4e5e 100644 --- a/LICENSE +++ b/LICENSE @@ -291,7 +291,7 @@ convey the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found. {description} - Copyright (C) {year} {fullname} + Copyright (C) 2015 Yago PĂ©rez This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -336,4 +336,4 @@ This General Public License does not permit incorporating your program into proprietary programs. If your program is a subroutine library, you may consider it more useful to permit linking proprietary applications with the library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. \ No newline at end of file +Public License instead of this License. From adf8120c70846ca047ad1e3dd5dc70e4b0f771b3 Mon Sep 17 00:00:00 2001 From: Yago Date: Wed, 4 Mar 2015 23:14:39 +0100 Subject: [PATCH 10/22] Fix DOT extension. --- plugins/media.lua | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/plugins/media.lua b/plugins/media.lua index 64c8175..6b86618 100644 --- a/plugins/media.lua +++ b/plugins/media.lua @@ -8,16 +8,16 @@ return { description = "When user sends media URL (ends with gif, mp4, pdf, etc.) download and send it to origin.", usage = "", patterns = { - "(https?://[%w-_%.%?%.:/%+=&]+.gif)$", - "(https?://[%w-_%.%?%.:/%+=&]+.mp4)$", - "(https?://[%w-_%.%?%.:/%+=&]+.pdf)$", - "(https?://[%w-_%.%?%.:/%+=&]+.ogg)$", - "(https?://[%w-_%.%?%.:/%+=&]+.zip)$", - "(https?://[%w-_%.%?%.:/%+=&]+.mp3)$", - "(https?://[%w-_%.%?%.:/%+=&]+.rar)$", - "(https?://[%w-_%.%?%.:/%+=&]+.wmv)$", - "(https?://[%w-_%.%?%.:/%+=&]+.doc)$", - "(https?://[%w-_%.%?%.:/%+=&]+.avi)$" + "(https?://[%w-_%.%?%.:/%+=&]+%.gif)$", + "(https?://[%w-_%.%?%.:/%+=&]+%.mp4)$", + "(https?://[%w-_%.%?%.:/%+=&]+%.pdf)$", + "(https?://[%w-_%.%?%.:/%+=&]+%.ogg)$", + "(https?://[%w-_%.%?%.:/%+=&]+%.zip)$", + "(https?://[%w-_%.%?%.:/%+=&]+%.mp3)$", + "(https?://[%w-_%.%?%.:/%+=&]+%.rar)$", + "(https?://[%w-_%.%?%.:/%+=&]+%.wmv)$", + "(https?://[%w-_%.%?%.:/%+=&]+%.doc)$", + "(https?://[%w-_%.%?%.:/%+=&]+%.avi)$" }, run = run -} \ No newline at end of file +} From 230fbc0177cabf02bdfef497c7fc02f89c535879 Mon Sep 17 00:00:00 2001 From: Yago Date: Wed, 4 Mar 2015 23:22:00 +0100 Subject: [PATCH 11/22] Fix DOT extension. --- plugins/images.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/plugins/images.lua b/plugins/images.lua index bf342f6..1b89ee2 100644 --- a/plugins/images.lua +++ b/plugins/images.lua @@ -10,11 +10,11 @@ return { description = "When user sends image URL (ends with png, jpg, jpeg) download and send it to origin.", usage = "", patterns = { - "(https?://[%w-_%.%?%.:/%+=&]+.png)$", - "(https?://[%w-_%.%?%.:/%+=&]+.jpg)$", - "(https?://[%w-_%.%?%.:/%+=&]+.jpeg)$", + "(https?://[%w-_%.%?%.:/%+=&]+%.png)$", + "(https?://[%w-_%.%?%.:/%+=&]+%.jpg)$", + "(https?://[%w-_%.%?%.:/%+=&]+%.jpeg)$", }, run = run } -end \ No newline at end of file +end From 565ac4db4041e7ad1cb8b68dd1dfa83dba250882 Mon Sep 17 00:00:00 2001 From: yago Date: Wed, 4 Mar 2015 23:45:11 +0100 Subject: [PATCH 12/22] v0.9.4 --- bot/bot.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/bot.lua b/bot/bot.lua index cd69354..d6f1b1b 100644 --- a/bot/bot.lua +++ b/bot/bot.lua @@ -5,7 +5,7 @@ json = (loadfile "./libs/JSON.lua")() serpent = (loadfile "./libs/serpent.lua")() require("./bot/utils") -VERSION = '0.9.3' +VERSION = '0.9.4' function on_msg_receive (msg) vardump(msg) From 7224cec8341ee78df5399d89f86ac7a32a27fb0a Mon Sep 17 00:00:00 2001 From: yago Date: Wed, 4 Mar 2015 23:51:36 +0100 Subject: [PATCH 13/22] Fixed some tabulation --- plugins/google.lua | 20 ++++++++++---------- plugins/hello.lua | 16 +++++++++------- plugins/help.lua | 20 ++++++++++---------- plugins/img_google.lua | 8 ++++---- plugins/media.lua | 37 ++++++++++++++++++++----------------- 5 files changed, 53 insertions(+), 48 deletions(-) diff --git a/plugins/google.lua b/plugins/google.lua index 61f6b2e..5e3434b 100644 --- a/plugins/google.lua +++ b/plugins/google.lua @@ -22,17 +22,17 @@ function stringlinks(results) end function run(msg, matches) - vardump(matches) - local results = googlethat(matches[1]) - return stringlinks(results) + vardump(matches) + local results = googlethat(matches[1]) + return stringlinks(results) end return { - description = "Searches Google and send results", - usage = "!google [terms]: Searches Google and send results", - patterns = { - "^!google (.*)$", - "^%.[g|G]oogle (.*)$" - }, - run = run + description = "Searches Google and send results", + usage = "!google [terms]: Searches Google and send results", + patterns = { + "^!google (.*)$", + "^%.[g|G]oogle (.*)$" + }, + run = run } diff --git a/plugins/hello.lua b/plugins/hello.lua index f9b13ba..706b3d1 100644 --- a/plugins/hello.lua +++ b/plugins/hello.lua @@ -1,15 +1,17 @@ +do function run(msg, matches) return "Hello, " .. matches[1] end return { - description = "Says hello to someone", - usage = "say hello to [name]", - patterns = { - "^say hello to (.*)$", - "^Say hello to (.*)$" - }, - run = run + description = "Says hello to someone", + usage = "say hello to [name]", + patterns = { + "^say hello to (.*)$", + "^Say hello to (.*)$" + }, + run = run } +end \ No newline at end of file diff --git a/plugins/help.lua b/plugins/help.lua index c671ff1..186a2af 100644 --- a/plugins/help.lua +++ b/plugins/help.lua @@ -61,14 +61,14 @@ function run(msg, matches) end return { - description = "Help plugin. Get info from other plugins. ", - usage = { - "!help: Show all the help", - "!help md: Generate a GitHub Markdown table" - }, - patterns = { - "^!help$", - "^!help md$" - }, - run = run + description = "Help plugin. Get info from other plugins. ", + usage = { + "!help: Show all the help", + "!help md: Generate a GitHub Markdown table" + }, + patterns = { + "^!help$", + "^!help md$" + }, + run = run } \ No newline at end of file diff --git a/plugins/img_google.lua b/plugins/img_google.lua index 5335082..3e7c552 100644 --- a/plugins/img_google.lua +++ b/plugins/img_google.lua @@ -26,10 +26,10 @@ function run(msg, matches) end return { - description = "Search image with Google API and sends it.", - usage = "!img [term]: Random search an image with Google API.", - patterns = {"^!img (.*)$"}, - run = run + description = "Search image with Google API and sends it.", + usage = "!img [term]: Random search an image with Google API.", + patterns = {"^!img (.*)$"}, + run = run } end \ No newline at end of file diff --git a/plugins/media.lua b/plugins/media.lua index 6b86618..ce2c3fb 100644 --- a/plugins/media.lua +++ b/plugins/media.lua @@ -1,23 +1,26 @@ +do function run(msg, matches) - file = download_to_file(matches[1]) - send_document(get_receiver(msg), file, ok_cb, false) + file = download_to_file(matches[1]) + send_document(get_receiver(msg), file, ok_cb, false) end return { - description = "When user sends media URL (ends with gif, mp4, pdf, etc.) download and send it to origin.", - usage = "", - patterns = { - "(https?://[%w-_%.%?%.:/%+=&]+%.gif)$", - "(https?://[%w-_%.%?%.:/%+=&]+%.mp4)$", - "(https?://[%w-_%.%?%.:/%+=&]+%.pdf)$", - "(https?://[%w-_%.%?%.:/%+=&]+%.ogg)$", - "(https?://[%w-_%.%?%.:/%+=&]+%.zip)$", - "(https?://[%w-_%.%?%.:/%+=&]+%.mp3)$", - "(https?://[%w-_%.%?%.:/%+=&]+%.rar)$", - "(https?://[%w-_%.%?%.:/%+=&]+%.wmv)$", - "(https?://[%w-_%.%?%.:/%+=&]+%.doc)$", - "(https?://[%w-_%.%?%.:/%+=&]+%.avi)$" - }, - run = run + description = "When user sends media URL (ends with gif, mp4, pdf, etc.) download and send it to origin.", + usage = "", + patterns = { + "(https?://[%w-_%.%?%.:/%+=&]+%.gif)$", + "(https?://[%w-_%.%?%.:/%+=&]+%.mp4)$", + "(https?://[%w-_%.%?%.:/%+=&]+%.pdf)$", + "(https?://[%w-_%.%?%.:/%+=&]+%.ogg)$", + "(https?://[%w-_%.%?%.:/%+=&]+%.zip)$", + "(https?://[%w-_%.%?%.:/%+=&]+%.mp3)$", + "(https?://[%w-_%.%?%.:/%+=&]+%.rar)$", + "(https?://[%w-_%.%?%.:/%+=&]+%.wmv)$", + "(https?://[%w-_%.%?%.:/%+=&]+%.doc)$", + "(https?://[%w-_%.%?%.:/%+=&]+%.avi)$" + }, + run = run } + +end \ No newline at end of file From cfff96677ac8bf887fa03fc6ff0b2bde10c62418 Mon Sep 17 00:00:00 2001 From: Yuri Date: Fri, 6 Mar 2015 04:30:44 +0300 Subject: [PATCH 14/22] Added boobs plugin --- plugins/boobs.lua | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 plugins/boobs.lua diff --git a/plugins/boobs.lua b/plugins/boobs.lua new file mode 100644 index 0000000..5d39c34 --- /dev/null +++ b/plugins/boobs.lua @@ -0,0 +1,39 @@ + +function getBoobs() + + local rand = math.random(1, 8315) + local res,status = http.request("http://api.oboobs.ru/boobs/get/"..rand) + + if status ~= 200 then return nil end + + local data = json:decode(res) + + -- The OpenBoobs API sometimes returns an empty array + if not data[1] then + print 'Cannot get that boobs, trying another ones...' + return getBoobs() + end + + return 'http://media.oboobs.ru/' .. data[1].preview +end + +function run(msg, matches) + + local boobs = getBoobs() + + if boobs ~= nil then + file = download_to_file(boobs) + send_photo(get_receiver(msg), file, ok_cb, false) + else + return 'Error getting boobs for you, please try again later.' + end +end + +return { + description = "Gets a random boobs pic", + usage = "!boobs", + patterns = { + "^!boobs$" + }, + run = run +} \ No newline at end of file From 9c2582f6277c89d3e002d655ca904319e1997c10 Mon Sep 17 00:00:00 2001 From: yago Date: Sun, 8 Mar 2015 22:02:19 +0100 Subject: [PATCH 15/22] !butts command :peach: and indentation in boobs.lua --- plugins/boobs.lua | 81 ++++++++++++++++++++++++++++++++--------------- 1 file changed, 55 insertions(+), 26 deletions(-) diff --git a/plugins/boobs.lua b/plugins/boobs.lua index 5d39c34..d08f1ab 100644 --- a/plugins/boobs.lua +++ b/plugins/boobs.lua @@ -1,39 +1,68 @@ +do -function getBoobs() - - local rand = math.random(1, 8315) - local res,status = http.request("http://api.oboobs.ru/boobs/get/"..rand) +function getRandomButts(attempt) + attempt = attempt or 0; + attempt = attempt + 1 - if status ~= 200 then return nil end + local res,status = http.request("http://api.obutts.ru/noise/1") - local data = json:decode(res) + if status ~= 200 then return nil end + local data = json:decode(res)[1] - -- The OpenBoobs API sometimes returns an empty array - if not data[1] then - print 'Cannot get that boobs, trying another ones...' - return getBoobs() - end + -- The OpenBoobs API sometimes returns an empty array + if not data and attempt < 10 then + print('Cannot get that boobs, trying another ones...') + return getRandomBoobs(attempt) + end - return 'http://media.oboobs.ru/' .. data[1].preview + return 'http://media.obutts.ru/' .. data.preview +end + +function getRandomBoobs(attempt) + attempt = attempt or 0; + attempt = attempt + 1 + + local res,status = http.request("http://api.oboobs.ru/noise/1") + + if status ~= 200 then return nil end + local data = json:decode(res)[1] + + -- The OpenBoobs API sometimes returns an empty array + if not data and attempt < 10 then + print('Cannot get that boobs, trying another ones...') + return getRandomBoobs(attempt) + end + + return 'http://media.oboobs.ru/' .. data.preview end function run(msg, matches) + local url = nil + + if matches[1] == "^!boobs" then + url = getRandomBoobs() + end - local boobs = getBoobs() + if matches[1] == "!buts" then + url = getRandomButts() + end - if boobs ~= nil then - file = download_to_file(boobs) - send_photo(get_receiver(msg), file, ok_cb, false) - else - return 'Error getting boobs for you, please try again later.' - end + if url ~= nil then + local receiver = get_receiver(msg) + send_photo_from_url(receiver, url) + else + return 'Error getting boobs for you, please try again later.' + end end return { - description = "Gets a random boobs pic", - usage = "!boobs", - patterns = { - "^!boobs$" - }, - run = run -} \ No newline at end of file + description = "Gets a random boobs pic", + usage = "!boobs", + patterns = { + "^!boobs", + "^!buts" + }, + run = run +} + +end \ No newline at end of file From 8bb1a19cfca0626be5f244628e0be4af0bb0a003 Mon Sep 17 00:00:00 2001 From: yago Date: Sun, 8 Mar 2015 22:11:00 +0100 Subject: [PATCH 16/22] Butts bugfix --- plugins/boobs.lua | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/plugins/boobs.lua b/plugins/boobs.lua index d08f1ab..7d4b6a5 100644 --- a/plugins/boobs.lua +++ b/plugins/boobs.lua @@ -1,7 +1,7 @@ do function getRandomButts(attempt) - attempt = attempt or 0; + attempt = attempt or 0 attempt = attempt + 1 local res,status = http.request("http://api.obutts.ru/noise/1") @@ -11,15 +11,15 @@ function getRandomButts(attempt) -- The OpenBoobs API sometimes returns an empty array if not data and attempt < 10 then - print('Cannot get that boobs, trying another ones...') - return getRandomBoobs(attempt) + print('Cannot get that butts, trying another ones...') + return getRandomButts(attempt) end return 'http://media.obutts.ru/' .. data.preview end function getRandomBoobs(attempt) - attempt = attempt or 0; + attempt = attempt or 0 attempt = attempt + 1 local res,status = http.request("http://api.oboobs.ru/noise/1") @@ -39,11 +39,11 @@ end function run(msg, matches) local url = nil - if matches[1] == "^!boobs" then + if matches[1] == "!boobs" then url = getRandomBoobs() end - if matches[1] == "!buts" then + if matches[1] == "!butts" then url = getRandomButts() end @@ -51,7 +51,7 @@ function run(msg, matches) local receiver = get_receiver(msg) send_photo_from_url(receiver, url) else - return 'Error getting boobs for you, please try again later.' + return 'Error getting boobs/butts for you, please try again later.' end end @@ -59,8 +59,8 @@ return { description = "Gets a random boobs pic", usage = "!boobs", patterns = { - "^!boobs", - "^!buts" + "^!boobs$", + "^!butts$" }, run = run } From 8f9d1a1e598ca913ed111fd8c541d807d58e71e7 Mon Sep 17 00:00:00 2001 From: Lee Watson Date: Tue, 10 Mar 2015 00:34:17 +0000 Subject: [PATCH 17/22] tigle -> title --- plugins/xkcd.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/xkcd.lua b/plugins/xkcd.lua index d00037b..0354b62 100644 --- a/plugins/xkcd.lua +++ b/plugins/xkcd.lua @@ -44,7 +44,7 @@ end return { description = "Send comic images from xkcd", - usage = {"!xkcd (id): Send an xkcd image and tigle. If not id, send a random one"}, + usage = {"!xkcd (id): Send an xkcd image and title. If not id, send a random one"}, patterns = { "^!xkcd$", "^!xkcd (%d+)", From e30fb76ac50d87c8b6cbfe686860433a47f99b28 Mon Sep 17 00:00:00 2001 From: Yago Date: Tue, 10 Mar 2015 18:21:37 +0100 Subject: [PATCH 18/22] Update boobs.lua usage --- plugins/boobs.lua | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/plugins/boobs.lua b/plugins/boobs.lua index 7d4b6a5..ba4edab 100644 --- a/plugins/boobs.lua +++ b/plugins/boobs.lua @@ -56,8 +56,11 @@ function run(msg, matches) end return { - description = "Gets a random boobs pic", - usage = "!boobs", + description = "Gets a random boobs or butts pic", + usage = { + "!boobs", + "!butts" + }, patterns = { "^!boobs$", "^!butts$" @@ -65,4 +68,4 @@ return { run = run } -end \ No newline at end of file +end From 9d52c6103c7b7173441b5fad41395774e5be23cf Mon Sep 17 00:00:00 2001 From: yago Date: Tue, 10 Mar 2015 20:35:19 +0100 Subject: [PATCH 19/22] Support for encr_chat --- bot/bot.lua | 4 ++-- bot/utils.lua | 3 +++ 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/bot/bot.lua b/bot/bot.lua index d6f1b1b..3d4c929 100644 --- a/bot/bot.lua +++ b/bot/bot.lua @@ -39,7 +39,7 @@ function msg_valid(msg) print("Not valid, msg from us") return false end - if msg.date < now then + if msg.date < (now - 60) then print("Not valid, old msg") return false end @@ -87,7 +87,7 @@ function do_action(msg) -- print("Trying", text, "against", pattern) matches = { string.match(text, pattern) } if matches[1] then - mark_read(get_receiver(msg), ok_cb, false) + mark_read(receiver, ok_cb, false) print(" matches", pattern) if desc.run ~= nil then -- If plugin is for privileged user diff --git a/bot/utils.lua b/bot/utils.lua index 49a1305..cf0d940 100644 --- a/bot/utils.lua +++ b/bot/utils.lua @@ -8,6 +8,9 @@ function get_receiver(msg) if msg.to.type == 'chat' then return 'chat#id'..msg.to.id end + if msg.to.type == 'encr_chat' then + return msg.to.print_name + end end function is_chat_msg( msg ) From 2890acc04ea74c9126cac2607d96b470bc4a9186 Mon Sep 17 00:00:00 2001 From: yago Date: Tue, 10 Mar 2015 20:40:08 +0100 Subject: [PATCH 20/22] require libraries on bot/utils.lua --- bot/bot.lua | 5 ----- bot/utils.lua | 9 +++++++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/bot/bot.lua b/bot/bot.lua index 3d4c929..91c8028 100644 --- a/bot/bot.lua +++ b/bot/bot.lua @@ -1,8 +1,3 @@ -http = require("socket.http") -https = require("ssl.https") -URL = require("socket.url") -json = (loadfile "./libs/JSON.lua")() -serpent = (loadfile "./libs/serpent.lua")() require("./bot/utils") VERSION = '0.9.4' diff --git a/bot/utils.lua b/bot/utils.lua index cf0d940..9b149a3 100644 --- a/bot/utils.lua +++ b/bot/utils.lua @@ -1,5 +1,10 @@ -local mimetype = (loadfile "./libs/mimetype.lua")() -local ltn12 = require "ltn12" +http = require "socket.http" +https = require "ssl.https" +ltn12 = require "ltn12" +URL = require "socket.url" +json = (loadfile "./libs/JSON.lua")() +serpent = (loadfile "./libs/serpent.lua")() +mimetype = (loadfile "./libs/mimetype.lua")() function get_receiver(msg) if msg.to.type == 'user' then From b07e3a5de1c3edb36023c16f2794d7eca78a58eb Mon Sep 17 00:00:00 2001 From: yago Date: Tue, 10 Mar 2015 20:40:42 +0100 Subject: [PATCH 21/22] Version v0.9.5 --- bot/bot.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bot/bot.lua b/bot/bot.lua index 91c8028..409fea5 100644 --- a/bot/bot.lua +++ b/bot/bot.lua @@ -1,6 +1,6 @@ require("./bot/utils") -VERSION = '0.9.4' +VERSION = '0.9.5' function on_msg_receive (msg) vardump(msg) From ee5506ae2460e092ad741d74d29c7ac4ec939301 Mon Sep 17 00:00:00 2001 From: Yago Date: Tue, 10 Mar 2015 21:06:15 +0100 Subject: [PATCH 22/22] now - 60 no more --- bot/bot.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bot/bot.lua b/bot/bot.lua index 409fea5..2396afa 100644 --- a/bot/bot.lua +++ b/bot/bot.lua @@ -34,7 +34,7 @@ function msg_valid(msg) print("Not valid, msg from us") return false end - if msg.date < (now - 60) then + if msg.date < now then print("Not valid, old msg") return false end @@ -219,4 +219,4 @@ end -- Start and load values our_id = 0 now = os.time() -math.randomseed(now) \ No newline at end of file +math.randomseed(now)