diff --git a/otouto/bot.lua b/otouto/bot.lua index 3180048..a4af63f 100644 --- a/otouto/bot.lua +++ b/otouto/bot.lua @@ -1,17 +1,11 @@ local bot = {} --- Requires are moved to init to allow for reloads. -local bindings -- Load Telegram bindings. -local utilities -- Load miscellaneous and cross-plugin functions. -local redis = (loadfile "./otouto/redis.lua")() +bindings = require('otouto.bindings') +utilities = require('otouto.utilities') bot.version = '2.2.3.2' function bot:init(config) -- The function run when the bot is started or reloaded. - - bindings = require('otouto.bindings') - utilities = require('otouto.utilities') - redis = (loadfile "./otouto/redis.lua")() cred_data = load_cred() assert( diff --git a/otouto/plugins/9gag.lua b/otouto/plugins/9gag.lua index 766e8bf..7ea4e27 100644 --- a/otouto/plugins/9gag.lua +++ b/otouto/plugins/9gag.lua @@ -1,11 +1,5 @@ local ninegag = {} -local HTTP = require('socket.http') -local URL = require('socket.url') -local JSON = require('dkjson') -local utilities = require('otouto.utilities') -local bindings = require('otouto.bindings') - ninegag.command = '9gag' function ninegag:init(config) @@ -20,9 +14,9 @@ end local url = "http://api-9gag.herokuapp.com/" function ninegag:get_9GAG() - local b,c = HTTP.request(url) + local b,c = http.request(url) if c ~= 200 then return nil end - local gag = JSON.decode(b) + local gag = json.decode(b) -- random max json table size local i = math.random(#gag) @@ -33,9 +27,9 @@ function ninegag:get_9GAG() end function ninegag:inline_callback(inline_query, config) - local res, code = HTTP.request(url) + local res, code = http.request(url) if code ~= 200 then return end - local gag = JSON.decode(res) + local gag = json.decode(res) local results = '[' for n in pairs(gag) do diff --git a/otouto/plugins/about.lua b/otouto/plugins/about.lua index cc9f974..930c184 100644 --- a/otouto/plugins/about.lua +++ b/otouto/plugins/about.lua @@ -1,7 +1,6 @@ local about = {} local bot = require('otouto.bot') -local utilities = require('otouto.utilities') about.command = 'about' about.doc = '`Sendet Informationen über den Bot.`' diff --git a/otouto/plugins/adfly.lua b/otouto/plugins/adfly.lua index db260ee..cbe23e3 100644 --- a/otouto/plugins/adfly.lua +++ b/otouto/plugins/adfly.lua @@ -1,9 +1,5 @@ local adfly = {} -local utilities = require('otouto.utilities') -local HTTPS = require('ssl.https') -local redis = (loadfile "./otouto/redis.lua")() - function adfly:init(config) adfly.triggers = { 'adf.ly/([A-Za-z0-9-_-]+)' @@ -15,7 +11,7 @@ end function adfly:expand_adfly_link(adfly_code) local BASE_URL = 'https://andibi.tk/dl/adfly.php' local url = BASE_URL..'/?url=http://adf.ly/'..adfly_code - local res,code = HTTPS.request(url) + local res,code = https.request(url) if code ~= 200 then return nil end if res == 'Fehler: Keine Adf.ly-URL gefunden!' then return 'NOTFOUND' end cache_data('adfly', adfly_code, res, 31536000, 'key') diff --git a/otouto/plugins/afk.lua b/otouto/plugins/afk.lua index a0c5c63..bab7d6e 100644 --- a/otouto/plugins/afk.lua +++ b/otouto/plugins/afk.lua @@ -3,9 +3,6 @@ local afk = {} -local utilities = require('otouto.utilities') -local redis = (loadfile "./otouto/redis.lua")() - function afk:init(config) afk.triggers = { "^/([A|a][F|f][K|k])$", diff --git a/otouto/plugins/app_store.lua b/otouto/plugins/app_store.lua index 0ba1bf4..1508586 100644 --- a/otouto/plugins/app_store.lua +++ b/otouto/plugins/app_store.lua @@ -1,10 +1,5 @@ local app_store = {} -local https = require('ssl.https') -local json = require('dkjson') -local utilities = require('otouto.utilities') -local redis = (loadfile "./otouto/redis.lua")() - app_store.triggers = { "itunes.apple.com/(.*)/app/(.*)/id(%d+)", "^/itunes (%d+)$", diff --git a/otouto/plugins/bImages.lua b/otouto/plugins/bImages.lua index 5642528..f6c3aa4 100644 --- a/otouto/plugins/bImages.lua +++ b/otouto/plugins/bImages.lua @@ -1,13 +1,5 @@ local bImages = {} -local HTTPS = require('ssl.https') -HTTPS.timeout = 10 -local URL = require('socket.url') -local JSON = require('dkjson') -local redis = (loadfile "./otouto/redis.lua")() -local utilities = require('otouto.utilities') -local bindings = require('otouto.bindings') - function bImages:init(config) if not cred_data.bing_search_key then print('Missing config value: bing_search_key.') @@ -36,9 +28,9 @@ function bImages:getImages(query) ["Ocp-Apim-Subscription-Key"] = apikey } } - local ok, response_code, response_headers = HTTPS.request(request_constructor) + local ok, response_code, response_headers = https.request(request_constructor) if not ok then return end - local images = JSON.decode(table.concat(response_body)).value + local images = json.decode(table.concat(response_body)).value if not images[1] then return end diff --git a/otouto/plugins/banhammer.lua b/otouto/plugins/banhammer.lua index 9eb2627..f0669de 100644 --- a/otouto/plugins/banhammer.lua +++ b/otouto/plugins/banhammer.lua @@ -1,9 +1,5 @@ local banhammer = {} -local bindings = require('otouto.bindings') -local utilities = require('otouto.utilities') -local redis = (loadfile "./otouto/redis.lua")() - banhammer.command = 'banhammer ' function banhammer:init(config) diff --git a/otouto/plugins/bitly.lua b/otouto/plugins/bitly.lua index 5b45ec7..fbbd227 100644 --- a/otouto/plugins/bitly.lua +++ b/otouto/plugins/bitly.lua @@ -1,10 +1,5 @@ local bitly = {} -local https = require('ssl.https') -local json = require('dkjson') -local utilities = require('otouto.utilities') -local redis = (loadfile "./otouto/redis.lua")() - function bitly:init(config) if not cred_data.bitly_access_token then print('Missing config value: bitly_access_token.') diff --git a/otouto/plugins/bitly_create.lua b/otouto/plugins/bitly_create.lua index 4c94f9f..afa5481 100644 --- a/otouto/plugins/bitly_create.lua +++ b/otouto/plugins/bitly_create.lua @@ -1,14 +1,5 @@ local bitly_create = {} -local http = require('socket.http') -local https = require('ssl.https') -local URL = require('socket.url') -local json = require('dkjson') -local utilities = require('otouto.utilities') -local bindings = require('otouto.bindings') -local OAuth = require "OAuth" -local redis = (loadfile "./otouto/redis.lua")() - function bitly_create:init(config) if not cred_data.bitly_client_id then print('Missing config value: bitly_client_id.') diff --git a/otouto/plugins/br.lua b/otouto/plugins/br.lua index d96b934..d7e50f3 100644 --- a/otouto/plugins/br.lua +++ b/otouto/plugins/br.lua @@ -1,11 +1,5 @@ local br = {} -local https = require('ssl.https') -local URL = require('socket.url') -local json = require('dkjson') -local utilities = require('otouto.utilities') -local bindings = require('otouto.bindings') - br.triggers = { "br.de/nachrichten/(.*).html$" } diff --git a/otouto/plugins/btc.lua b/otouto/plugins/btc.lua index 41548d2..0ae96fe 100644 --- a/otouto/plugins/btc.lua +++ b/otouto/plugins/btc.lua @@ -1,11 +1,5 @@ local btc = {} -local https = require('ssl.https') -local URL = require('socket.url') -local json = require('dkjson') -local utilities = require('otouto.utilities') -local bindings = require('otouto.bindings') - function btc:init(config) btc.triggers = { "^/btc$" diff --git a/otouto/plugins/calc.lua b/otouto/plugins/calc.lua index 169acce..c94d2ac 100644 --- a/otouto/plugins/calc.lua +++ b/otouto/plugins/calc.lua @@ -1,9 +1,5 @@ local calc = {} -local URL = require('socket.url') -local http = require('socket.http') -local utilities = require('otouto.utilities') - calc.command = 'calc ' function calc:init(config) diff --git a/otouto/plugins/cats.lua b/otouto/plugins/cats.lua index cb3be6b..56db05e 100644 --- a/otouto/plugins/cats.lua +++ b/otouto/plugins/cats.lua @@ -1,9 +1,5 @@ local cats = {} -local https = require('ssl.https') -local json = require('dkjson') -local utilities = require('otouto.utilities') - cats.command = 'cat [gif]' function cats:init(config) diff --git a/otouto/plugins/channel.lua b/otouto/plugins/channel.lua index 9838083..2ed752e 100644 --- a/otouto/plugins/channel.lua +++ b/otouto/plugins/channel.lua @@ -1,8 +1,5 @@ local channel = {} -local bindings = require('otouto.bindings') -local utilities = require('otouto.utilities') - channel.command = 'ch \\n ' channel.doc = [[* /ch*_ _|_[Inline-Keyboard]_ diff --git a/otouto/plugins/channels.lua b/otouto/plugins/channels.lua index bc06571..25a5632 100644 --- a/otouto/plugins/channels.lua +++ b/otouto/plugins/channels.lua @@ -1,9 +1,5 @@ local channels = {} -local bindings = require('otouto.bindings') -local utilities = require('otouto.utilities') -local redis = (loadfile "./otouto/redis.lua")() - channels.command = 'channel ' function channels:init(config) diff --git a/otouto/plugins/cleverbot.lua b/otouto/plugins/cleverbot.lua index 5557b4c..4f298a6 100644 --- a/otouto/plugins/cleverbot.lua +++ b/otouto/plugins/cleverbot.lua @@ -1,10 +1,5 @@ local cleverbot = {} -local https = require('ssl.https') -local URL = require('socket.url') -local utilities = require('otouto.utilities') -local json = require('dkjson') - function cleverbot:init(config) cleverbot.triggers = { "^/cbot (.*)$" diff --git a/otouto/plugins/clypit.lua b/otouto/plugins/clypit.lua index f4d3693..8a41aec 100644 --- a/otouto/plugins/clypit.lua +++ b/otouto/plugins/clypit.lua @@ -1,10 +1,5 @@ local clypit = {} -local http = require('socket.http') -local json = require('dkjson') -local utilities = require('otouto.utilities') -local bindings = require('otouto.bindings') - clypit.triggers = { "clyp.it/([A-Za-z0-9-_-]+)" } diff --git a/otouto/plugins/control.lua b/otouto/plugins/control.lua index d093437..52fa9c3 100644 --- a/otouto/plugins/control.lua +++ b/otouto/plugins/control.lua @@ -1,8 +1,6 @@ local control = {} local bot = require('otouto.bot') -local utilities = require('otouto.utilities') - local cmd_pat -- Prevents the command from being uncallable. function control:init(config) diff --git a/otouto/plugins/creds.lua b/otouto/plugins/creds.lua index ff32f46..1c95ddf 100644 --- a/otouto/plugins/creds.lua +++ b/otouto/plugins/creds.lua @@ -1,8 +1,5 @@ local creds_manager = {} -local utilities = require('otouto.utilities') -local redis = (loadfile "./otouto/redis.lua")() - function creds_manager:init(config) creds_manager.triggers = { "^(/creds)$", diff --git a/otouto/plugins/currency.lua b/otouto/plugins/currency.lua index 82be81f..bf12a3d 100644 --- a/otouto/plugins/currency.lua +++ b/otouto/plugins/currency.lua @@ -1,8 +1,5 @@ local currency = {} -local HTTPS = require('ssl.https') -local utilities = require('otouto.utilities') - currency.command = 'cash [Menge] ' function currency:init(config) @@ -42,7 +39,7 @@ function currency:action(msg, config) end local url = BASE_URL..'?from='..from..'&to='..to..'&a='..amount - local str, res = HTTPS.request(url) + local str, res = https.request(url) if res ~= 200 then utilities.send_reply(self, msg, config.errors.connection) return diff --git a/otouto/plugins/dailymotion.lua b/otouto/plugins/dailymotion.lua index 65775dc..33f5fc3 100644 --- a/otouto/plugins/dailymotion.lua +++ b/otouto/plugins/dailymotion.lua @@ -1,9 +1,5 @@ local dailymotion = {} -local https = require('ssl.https') -local json = require('dkjson') -local utilities = require('otouto.utilities') - dailymotion.triggers = { "dailymotion.com/video/([A-Za-z0-9-_-]+)" } diff --git a/otouto/plugins/deviantart.lua b/otouto/plugins/deviantart.lua index 7449cfb..9497877 100644 --- a/otouto/plugins/deviantart.lua +++ b/otouto/plugins/deviantart.lua @@ -1,9 +1,5 @@ local deviantart = {} -local https = require('ssl.https') -local json = require('dkjson') -local utilities = require('otouto.utilities') - deviantart.triggers = { "http://(.*).deviantart.com/art/(.*)" } diff --git a/otouto/plugins/dhl.lua b/otouto/plugins/dhl.lua index 54173ad..1ecd6fe 100644 --- a/otouto/plugins/dhl.lua +++ b/otouto/plugins/dhl.lua @@ -1,9 +1,5 @@ local dhl = {} -local https = require('ssl.https') -local json = require('dkjson') -local utilities = require('otouto.utilities') - function dhl:init(config) dhl.triggers = { "/dhl (%d+)$" diff --git a/otouto/plugins/dropbox.lua b/otouto/plugins/dropbox.lua index bff0897..365768e 100644 --- a/otouto/plugins/dropbox.lua +++ b/otouto/plugins/dropbox.lua @@ -2,10 +2,6 @@ local dropbox = {} -local https = require('ssl.https') -local json = require('dkjson') -local utilities = require('otouto.utilities') - dropbox.triggers = { "dropbox.com/s/([a-z0-9]+)/(.*)" } diff --git a/otouto/plugins/echo.lua b/otouto/plugins/echo.lua index 7018ac8..3d9b154 100644 --- a/otouto/plugins/echo.lua +++ b/otouto/plugins/echo.lua @@ -1,7 +1,5 @@ local echo = {} -local utilities = require('otouto.utilities') - echo.command = 'echo ' function echo:init(config) @@ -35,6 +33,8 @@ function echo:action(msg) local output if msg.chat.type == 'supergroup' then output = '*Echo:*\n"' .. utilities.md_escape(input) .. '"' + utilities.send_message(self, msg.chat.id, output, true, nil, true) + return end utilities.send_message(self, msg.chat.id, input, true, nil, true) end diff --git a/otouto/plugins/entergroup.lua b/otouto/plugins/entergroup.lua index 1762767..7423d82 100644 --- a/otouto/plugins/entergroup.lua +++ b/otouto/plugins/entergroup.lua @@ -1,8 +1,5 @@ local entergroup = {} -local utilities = require('otouto.utilities') -local bindings = require('otouto.bindings') - entergroup.triggers = { '/nil' } diff --git a/otouto/plugins/expand.lua b/otouto/plugins/expand.lua index 8f6d422..c6cecd5 100644 --- a/otouto/plugins/expand.lua +++ b/otouto/plugins/expand.lua @@ -1,8 +1,5 @@ local expand = {} -local http = require('socket.http') -local utilities = require('otouto.utilities') - function expand:init(config) expand.triggers = { "^/expand (https?://[%w-_%.%?%.:/%+=&]+)$" diff --git a/otouto/plugins/facebook.lua b/otouto/plugins/facebook.lua index a5a6698..8f9f341 100644 --- a/otouto/plugins/facebook.lua +++ b/otouto/plugins/facebook.lua @@ -1,13 +1,5 @@ local facebook = {} -local http = require('socket.http') -local https = require('ssl.https') -local URL = require('socket.url') -local json = require('dkjson') -local utilities = require('otouto.utilities') -local bindings = require('otouto.bindings') -local redis = (loadfile "./otouto/redis.lua")() - function facebook:init(config) if not cred_data.fb_access_token then print('Missing config value: fb_access_token.') diff --git a/otouto/plugins/fefe.lua b/otouto/plugins/fefe.lua index 81f7639..4c6a3d3 100644 --- a/otouto/plugins/fefe.lua +++ b/otouto/plugins/fefe.lua @@ -1,9 +1,5 @@ local fefe = {} -local https = require('ssl.https') -local json = require('dkjson') -local utilities = require('otouto.utilities') - fefe.triggers = { "blog.fefe.de/%?ts=%w%w%w%w%w%w%w%w" } diff --git a/otouto/plugins/flickr.lua b/otouto/plugins/flickr.lua index 8a66428..a026712 100644 --- a/otouto/plugins/flickr.lua +++ b/otouto/plugins/flickr.lua @@ -1,10 +1,5 @@ local flickr = {} -local https = require('ssl.https') -local json = require('dkjson') -local utilities = require('otouto.utilities') -local bindings = require('otouto.bindings') - function flickr:init(config) if not cred_data.flickr_apikey then print('Missing config value: flickr_apikey.') diff --git a/otouto/plugins/flickr_search.lua b/otouto/plugins/flickr_search.lua index 4d4b9a3..3ce44ba 100644 --- a/otouto/plugins/flickr_search.lua +++ b/otouto/plugins/flickr_search.lua @@ -1,10 +1,5 @@ local flickr_search = {} -local https = require('ssl.https') -local json = require('dkjson') -local utilities = require('otouto.utilities') -local bindings = require('otouto.bindings') - function flickr_search:init(config) if not cred_data.flickr_apikey then print('Missing config value: flickr_apikey.') diff --git a/otouto/plugins/forecast.lua b/otouto/plugins/forecast.lua index 8108ba4..99cc965 100644 --- a/otouto/plugins/forecast.lua +++ b/otouto/plugins/forecast.lua @@ -1,12 +1,5 @@ local forecast = {} -local HTTPS = require('ssl.https') -local URL = require('socket.url') -local JSON = require('dkjson') -local utilities = require('otouto.utilities') -local bindings = require('otouto.bindings') -local redis = (loadfile "./otouto/redis.lua")() - function forecast:init(config) if not cred_data.forecastio_apikey then print('Missing config value: forecastio_apikey.') @@ -46,9 +39,9 @@ function get_city_name(lat, lng) local city = redis:hget('telegram:cache:weather:pretty_names', lat..','..lng) if city then return city end local url = 'https://maps.googleapis.com/maps/api/geocode/json?latlng='..lat..','..lng..'&result_type=political&language=de&key='..google_apikey - local res, code = HTTPS.request(url) + local res, code = https.request(url) if code ~= 200 then return 'Unbekannte Stadt' end - local data = JSON.decode(res).results[1] + local data = json.decode(res).results[1] local city = data.formatted_address print('Setting '..lat..','..lng..' in redis hash telegram:cache:weather:pretty_names to "'..city..'"') redis:hset('telegram:cache:weather:pretty_names', lat..','..lng, city) @@ -107,9 +100,9 @@ function forecast:get_forecast(lat, lng) method = "GET", sink = ltn12.sink.table(response_body) } - local ok, response_code, response_headers, response_status_line = HTTPS.request(request_constructor) + local ok, response_code, response_headers, response_status_line = https.request(request_constructor) if not ok then return nil end - local data = JSON.decode(table.concat(response_body)) + local data = json.decode(table.concat(response_body)) local ttl = string.sub(response_headers["cache-control"], 9) @@ -153,9 +146,9 @@ function forecast:get_forecast_hourly(lat, lng) method = "GET", sink = ltn12.sink.table(response_body) } - local ok, response_code, response_headers, response_status_line = HTTPS.request(request_constructor) + local ok, response_code, response_headers, response_status_line = https.request(request_constructor) if not ok then return nil end - local data = JSON.decode(table.concat(response_body)) + local data = json.decode(table.concat(response_body)) local ttl = string.sub(response_headers["cache-control"], 9) diff --git a/otouto/plugins/gImages.lua b/otouto/plugins/gImages.lua index 59a12b3..9eaa939 100644 --- a/otouto/plugins/gImages.lua +++ b/otouto/plugins/gImages.lua @@ -3,14 +3,6 @@ local gImages = {} -local HTTPS = require('ssl.https') -HTTPS.timeout = 10 -local URL = require('socket.url') -local JSON = require('dkjson') -local redis = (loadfile "./otouto/redis.lua")() -local utilities = require('otouto.utilities') -local bindings = require('otouto.bindings') - function gImages:init(config) if not cred_data.google_apikey then print('Missing config value: google_apikey.') @@ -115,8 +107,8 @@ function gImages:get_image(input) local cseid = cred_data.google_cse_id local BASE_URL = 'https://www.googleapis.com/customsearch/v1' local url = BASE_URL..'/?searchType=image&alt=json&num=10&key='..apikey..'&cx='..cseid..'&safe=high'..'&q=' .. input .. '&fields=items(link,mime,image(contextLink))' - local jstr, res = HTTPS.request(url) - local jdat = JSON.decode(jstr).items + local jstr, res = https.request(url) + local jdat = json.decode(jstr).items if not jdat then return 'NORESULTS' diff --git a/otouto/plugins/gMaps.lua b/otouto/plugins/gMaps.lua index 1bc4207..123c0c4 100644 --- a/otouto/plugins/gMaps.lua +++ b/otouto/plugins/gMaps.lua @@ -1,8 +1,5 @@ local gMaps = {} -local URL = require('socket.url') -local utilities = require('otouto.utilities') - gMaps.command = 'loc ' function gMaps:init(config) diff --git a/otouto/plugins/gSearch.lua b/otouto/plugins/gSearch.lua index 45f9611..b9e53d9 100644 --- a/otouto/plugins/gSearch.lua +++ b/otouto/plugins/gSearch.lua @@ -1,10 +1,5 @@ local gSearch = {} -local HTTPS = require('ssl.https') -local URL = require('socket.url') -local JSON = require('dkjson') -local utilities = require('otouto.utilities') - gSearch.command = 'google ' function gSearch:init(config) @@ -23,7 +18,7 @@ function gSearch:googlethat(query, config) local api = BASE_URL.."/?key="..apikey.."&cx="..cseid.."&gl=de&num="..number.."&safe=medium&fields=searchInformation%28formattedSearchTime,formattedTotalResults%29,items%28title,link,displayLink%29&" local parameters = "q=".. (URL.escape(query) or "") -- Do the request - local res, code = HTTPS.request(api..parameters) + local res, code = https.request(api..parameters) if code == 403 then return '403' end diff --git a/otouto/plugins/games.lua b/otouto/plugins/games.lua index 61841bd..e5e0222 100644 --- a/otouto/plugins/games.lua +++ b/otouto/plugins/games.lua @@ -1,10 +1,6 @@ local games = {} -local http = require('socket.http') -local URL = require('socket.url') local xml = require("xml") -local utilities = require('otouto.utilities') -local bindings = require('otouto.bindings') games.command = 'game ' diff --git a/otouto/plugins/gdrive.lua b/otouto/plugins/gdrive.lua index 5e1b3b0..41a4055 100644 --- a/otouto/plugins/gdrive.lua +++ b/otouto/plugins/gdrive.lua @@ -1,11 +1,5 @@ local gdrive = {} -local utilities = require('otouto.utilities') -local https = require('ssl.https') -local ltn12 = require('ltn12') -local json = require('dkjson') -local bindings = require('otouto.bindings') - function gdrive:init(config) if not cred_data.google_apikey then print('Missing config value: google_apikey.') diff --git a/otouto/plugins/get.lua b/otouto/plugins/get.lua index 9d008a7..1a89ef5 100644 --- a/otouto/plugins/get.lua +++ b/otouto/plugins/get.lua @@ -1,8 +1,5 @@ local get = {} -local utilities = require('otouto.utilities') -local redis = (loadfile "./otouto/redis.lua")() - get.command = 'get ' function get:init(config) diff --git a/otouto/plugins/getfile.lua b/otouto/plugins/getfile.lua index 378d96b..cf29dfb 100644 --- a/otouto/plugins/getfile.lua +++ b/otouto/plugins/getfile.lua @@ -4,12 +4,6 @@ local media_download = {} -local utilities = require('otouto.utilities') -local bindings = require('otouto.bindings') -local ltn12 = require('ltn12') -local HTTPS = require('ssl.https') -local redis = (loadfile "./otouto/redis.lua")() - media_download.triggers = { '/nil' } @@ -22,7 +16,7 @@ function media_download:download_to_file_permanently(url, file_name) redirect = false } local response = nil - response = {HTTPS.request(options)} + response = {https.request(options)} local code = response[2] local headers = response[3] diff --git a/otouto/plugins/gfycat.lua b/otouto/plugins/gfycat.lua index 0793355..18781bf 100644 --- a/otouto/plugins/gfycat.lua +++ b/otouto/plugins/gfycat.lua @@ -2,10 +2,6 @@ local gfycat = {} -local https = require('ssl.https') -local json = require('dkjson') -local utilities = require('otouto.utilities') - gfycat.triggers = { "gfycat.com/([A-Za-z0-9-_-]+)" } diff --git a/otouto/plugins/giphy.lua b/otouto/plugins/giphy.lua index 1918794..3177cf3 100644 --- a/otouto/plugins/giphy.lua +++ b/otouto/plugins/giphy.lua @@ -1,10 +1,5 @@ local giphy = {} -local http = require('socket.http') -local URL = require('socket.url') -local JSON = require('dkjson') -local utilities = require('otouto.utilities') - function giphy:init(config) giphy.triggers = { "/nil" @@ -26,7 +21,7 @@ function giphy:get_gifs(query) end local res, code = http.request(url) if code ~= 200 then return nil end - return JSON.decode(res).data + return json.decode(res).data end function giphy:inline_callback(inline_query, config, matches) diff --git a/otouto/plugins/github.lua b/otouto/plugins/github.lua index bcee3a1..62adc4d 100644 --- a/otouto/plugins/github.lua +++ b/otouto/plugins/github.lua @@ -1,13 +1,5 @@ local github = {} -local http = require('socket.http') -local https = require('ssl.https') -local URL = require('socket.url') -local json = require('dkjson') -local utilities = require('otouto.utilities') -local bindings = require('otouto.bindings') -local redis = (loadfile "./otouto/redis.lua")() - function github:init(config) github.triggers = { "github.com/([A-Za-z0-9-_-.-._.]+)/([A-Za-z0-9-_-.-._.]+)/commit/([a-z0-9-]+)", diff --git a/otouto/plugins/golem.lua b/otouto/plugins/golem.lua index c5a3e8d..2937c62 100644 --- a/otouto/plugins/golem.lua +++ b/otouto/plugins/golem.lua @@ -1,10 +1,5 @@ local golem = {} -local http = require('socket.http') -local json = require('dkjson') -local utilities = require('otouto.utilities') -local bindings = require('otouto.bindings') - function golem:init(config) if not cred_data.golem_apikey then print('Missing config value: golem_apikey.') diff --git a/otouto/plugins/googl.lua b/otouto/plugins/googl.lua index aebc333..35eb08e 100644 --- a/otouto/plugins/googl.lua +++ b/otouto/plugins/googl.lua @@ -1,9 +1,5 @@ local googl = {} -local https = require('ssl.https') -local json = require('dkjson') -local utilities = require('otouto.utilities') - function googl:init(config) if not cred_data.google_apikey then print('Missing config value: google_apikey.') diff --git a/otouto/plugins/gps.lua b/otouto/plugins/gps.lua index cb958a1..a8e6e2e 100644 --- a/otouto/plugins/gps.lua +++ b/otouto/plugins/gps.lua @@ -1,8 +1,5 @@ local gps = {} -local utilities = require('otouto.utilities') -local bindings = require('otouto.bindings') - gps.command = 'gps ,' function gps:init(config) diff --git a/otouto/plugins/greetings.lua b/otouto/plugins/greetings.lua index a2252c4..c64d244 100644 --- a/otouto/plugins/greetings.lua +++ b/otouto/plugins/greetings.lua @@ -4,8 +4,6 @@ local greetings = {} -local utilities = require('otouto.utilities') - function greetings:init(config) config.greetings = config.greetings or { ['Hello, #NAME.'] = { diff --git a/otouto/plugins/hackernews.lua b/otouto/plugins/hackernews.lua index 4da99c0..59c9f51 100644 --- a/otouto/plugins/hackernews.lua +++ b/otouto/plugins/hackernews.lua @@ -1,10 +1,5 @@ local hackernews = {} -local https = require('ssl.https') -local json = require('dkjson') -local URL = require('socket.url') -local utilities = require('otouto.utilities') - hackernews.triggers = { "news.ycombinator.com/item%?id=(%d+)" } diff --git a/otouto/plugins/heise.lua b/otouto/plugins/heise.lua index e9d04d3..9157c1e 100644 --- a/otouto/plugins/heise.lua +++ b/otouto/plugins/heise.lua @@ -1,11 +1,5 @@ local heise = {} -local https = require('ssl.https') -local URL = require('socket.url') -local json = require('dkjson') -local utilities = require('otouto.utilities') -local bindings = require('otouto.bindings') - heise.triggers = { "heise.de/newsticker/meldung/(.*).html$" } diff --git a/otouto/plugins/hello.lua b/otouto/plugins/hello.lua index bdc10b0..2d3483e 100644 --- a/otouto/plugins/hello.lua +++ b/otouto/plugins/hello.lua @@ -1,7 +1,5 @@ local hello = {} -local utilities = require('otouto.utilities') - hello.triggers = { "^[Ss][Aa][Gg] [Hh][Aa][Ll][Ll][Oo] [Zz][Uu] (.*)$" } diff --git a/otouto/plugins/help.lua b/otouto/plugins/help.lua index 7392407..efa8536 100644 --- a/otouto/plugins/help.lua +++ b/otouto/plugins/help.lua @@ -3,8 +3,6 @@ local help = {} -local utilities = require('otouto.utilities') - local help_text function help:init(config) diff --git a/otouto/plugins/id.lua b/otouto/plugins/id.lua index 92bdbcf..ffb2a62 100644 --- a/otouto/plugins/id.lua +++ b/otouto/plugins/id.lua @@ -1,9 +1,5 @@ local id = {} -local redis = (loadfile "./otouto/redis.lua")() -local bindings = require('otouto.bindings') -local utilities = require('otouto.utilities') - id.command = 'id' function id:init(config) diff --git a/otouto/plugins/ifttt.lua b/otouto/plugins/ifttt.lua index 984ea82..537394a 100644 --- a/otouto/plugins/ifttt.lua +++ b/otouto/plugins/ifttt.lua @@ -1,11 +1,5 @@ local ifttt = {} -local https = require('ssl.https') -local URL = require('socket.url') -local redis = (loadfile "./otouto/redis.lua")() -local utilities = require('otouto.utilities') -local bindings = require('otouto.bindings') - function ifttt:init(config) ifttt.triggers = { "^/ifttt (!set) (.*)$", diff --git a/otouto/plugins/images.lua b/otouto/plugins/images.lua index fd7289e..70a83b8 100644 --- a/otouto/plugins/images.lua +++ b/otouto/plugins/images.lua @@ -1,6 +1,5 @@ local images = {} -local utilities = require('otouto.utilities') images.triggers = { "(https?://[%w-_%%%.%?%.:,/%+=~&%[%]]+%.[Pp][Nn][Gg])$", "(https?://[%w-_%%%.%?%.:,/%+=~&%[%]]+%.[Jj][Pp][Ee]?[Gg])$" diff --git a/otouto/plugins/imdb.lua b/otouto/plugins/imdb.lua index b82d803..4fc7f81 100644 --- a/otouto/plugins/imdb.lua +++ b/otouto/plugins/imdb.lua @@ -1,11 +1,5 @@ local imdb = {} -local HTTP = require('socket.http') -local URL = require('socket.url') -local JSON = require('dkjson') -local utilities = require('otouto.utilities') -local bindings = require('otouto.bindings') - imdb.command = 'imdb ' function imdb:init(config) @@ -29,13 +23,13 @@ function imdb:action(msg, config) local url = 'http://www.omdbapi.com/?t=' .. URL.escape(input) - local jstr, res = HTTP.request(url) + local jstr, res = http.request(url) if res ~= 200 then utilities.send_reply(self, msg, config.errors.connection) return end - local jdat = JSON.decode(jstr) + local jdat = json.decode(jstr) if jdat.Response ~= 'True' then utilities.send_reply(self, msg, config.errors.results) diff --git a/otouto/plugins/imgblacklist.lua b/otouto/plugins/imgblacklist.lua index b13a64b..e6cdc99 100644 --- a/otouto/plugins/imgblacklist.lua +++ b/otouto/plugins/imgblacklist.lua @@ -1,8 +1,5 @@ local imgblacklist = {} -local utilities = require('otouto.utilities') -local redis = (loadfile "./otouto/redis.lua")() - imgblacklist.command = 'imgblacklist' function imgblacklist:init(config) diff --git a/otouto/plugins/imgur.lua b/otouto/plugins/imgur.lua index d584c9d..0802dbc 100644 --- a/otouto/plugins/imgur.lua +++ b/otouto/plugins/imgur.lua @@ -1,9 +1,5 @@ local imgur = {} -local https = require('ssl.https') -local json = require('dkjson') -local utilities = require('otouto.utilities') - function imgur:init(config) if not cred_data.imgur_client_id then print('Missing config value: imgur_client_id.') diff --git a/otouto/plugins/instagram.lua b/otouto/plugins/instagram.lua index 97d905b..96c2cf6 100644 --- a/otouto/plugins/instagram.lua +++ b/otouto/plugins/instagram.lua @@ -1,10 +1,5 @@ local instagram = {} -local https = require('ssl.https') -local json = require('dkjson') -local URL = require('socket.url') -local utilities = require('otouto.utilities') - function instagram:init(config) if not cred_data.instagram_access_token then print('Missing config value: instagram_access_token.') diff --git a/otouto/plugins/ip_info.lua b/otouto/plugins/ip_info.lua index 4d50e47..92d4d46 100644 --- a/otouto/plugins/ip_info.lua +++ b/otouto/plugins/ip_info.lua @@ -1,10 +1,5 @@ local ip_info = {} -local http = require('socket.http') -local json = require('dkjson') -local URL = require('socket.url') -local utilities = require('otouto.utilities') - function ip_info:init(config) ip_info.triggers = { "^/ip (.*)$", diff --git a/otouto/plugins/isup.lua b/otouto/plugins/isup.lua index ea37df0..e43e745 100644 --- a/otouto/plugins/isup.lua +++ b/otouto/plugins/isup.lua @@ -1,10 +1,6 @@ local isup = {} -local http = require('socket.http') -local https = require('ssl.https') local socket = require('socket') -local URL = require('socket.url') -local utilities = require('otouto.utilities') function isup:init(config) isup.triggers = { diff --git a/otouto/plugins/leave_group.lua b/otouto/plugins/leave_group.lua index 86dcb3d..c494962 100644 --- a/otouto/plugins/leave_group.lua +++ b/otouto/plugins/leave_group.lua @@ -1,8 +1,5 @@ local leave_group = {} -local utilities = require('otouto.utilities') -local bindings = require('otouto.bindings') - leave_group.triggers = { '/nil' } diff --git a/otouto/plugins/location_manager.lua b/otouto/plugins/location_manager.lua index aece496..923060b 100644 --- a/otouto/plugins/location_manager.lua +++ b/otouto/plugins/location_manager.lua @@ -1,8 +1,5 @@ local loc_manager = {} -local utilities = require('otouto.utilities') -local redis = (loadfile "./otouto/redis.lua")() - function loc_manager:init(config) loc_manager.triggers = { "^/location (set) (.*)$", diff --git a/otouto/plugins/luarun.lua b/otouto/plugins/luarun.lua index 1e9e095..1ce45a5 100644 --- a/otouto/plugins/luarun.lua +++ b/otouto/plugins/luarun.lua @@ -1,9 +1,5 @@ local luarun = {} -local utilities = require('otouto.utilities') -local URL = require('socket.url') -local JSON = require('dkjson') - function luarun:init(config) luarun.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('lua', true):t('return', true).table end @@ -28,17 +24,17 @@ function luarun:action(msg, config) local bot = require('otouto.bot') local bindings = require('otouto.bindings') local utilities = require('otouto.utilities') - local JSON = require('dkjson') + local json = require('dkjson') local URL = require('socket.url') - local HTTP = require('socket.http') - local HTTPS = require('ssl.https') + local http = require('socket.http') + local https = require('ssl.https') return function (self, msg, config) ]] .. input .. [[ end ]] )()(self, msg, config) if output == nil then output = 'Done!' else if type(output) == 'table' then - local s = JSON.encode(output, {indent=true}) + local s = json.encode(output, {indent=true}) if URL.escape(s):len() < 4000 then output = s end diff --git a/otouto/plugins/lyrics.lua b/otouto/plugins/lyrics.lua index 59bc49b..6e8e263 100644 --- a/otouto/plugins/lyrics.lua +++ b/otouto/plugins/lyrics.lua @@ -1,9 +1,5 @@ local lyrics = {} -local http = require('socket.http') -local json = require('dkjson') -local utilities = require('otouto.utilities') - function lyrics:init(config) if not cred_data.lyricsnmusic_apikey then print('Missing config value: lyricsnmusic_apikey.') diff --git a/otouto/plugins/magische_miesmuschel.lua b/otouto/plugins/magische_miesmuschel.lua index a7be099..851443f 100644 --- a/otouto/plugins/magische_miesmuschel.lua +++ b/otouto/plugins/magische_miesmuschel.lua @@ -1,7 +1,5 @@ local muschel = {} -local utilities = require('otouto.utilities') - muschel.triggers = { "^[Mm][Aa][Gg][Ii][Ss][Cc][Hh][Ee] [Mm][Ii][Ee][Ss][Mm][Uu][Ss][Cc][Hh][Ee][Ll], (.*)$" } diff --git a/otouto/plugins/media.lua b/otouto/plugins/media.lua index e755f96..940ad81 100644 --- a/otouto/plugins/media.lua +++ b/otouto/plugins/media.lua @@ -1,11 +1,5 @@ local media = {} -local HTTP = require('socket.http') -local HTTPS = require('ssl.https') -local redis = (loadfile "./otouto/redis.lua")() -local utilities = require('otouto.utilities') -local mimetype = (loadfile "./otouto/mimetype.lua")() - media.triggers = { "(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(gif))$", "^(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(mp4))$", diff --git a/otouto/plugins/minecraft_server.lua b/otouto/plugins/minecraft_server.lua index b5b8bec..d235bea 100644 --- a/otouto/plugins/minecraft_server.lua +++ b/otouto/plugins/minecraft_server.lua @@ -1,11 +1,5 @@ local mc_server = {} -local http = require('socket.http') -local ltn12 = require('ltn12') -local URL = require('socket.url') -local json = require('dkjson') -local utilities = require('otouto.utilities') - function mc_server:init(config) mc_server.triggers = { "^/mine (.*)$" diff --git a/otouto/plugins/minecraft_skin.lua b/otouto/plugins/minecraft_skin.lua index d2898f6..f310bed 100644 --- a/otouto/plugins/minecraft_skin.lua +++ b/otouto/plugins/minecraft_skin.lua @@ -1,7 +1,5 @@ local mc_skin = {} -local utilities = require('otouto.utilities') - function mc_skin:init(config) mc_skin.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('skin', true).table mc_skin.doc = [[* diff --git a/otouto/plugins/myanimelist.lua b/otouto/plugins/myanimelist.lua index d6dc3c6..ea08e9a 100644 --- a/otouto/plugins/myanimelist.lua +++ b/otouto/plugins/myanimelist.lua @@ -1,10 +1,6 @@ local mal = {} -local http = require('socket.http') -local URL = require('socket.url') local xml = require("xml") -local utilities = require('otouto.utilities') -local bindings = require('otouto.bindings') mal.command = 'anime , /manga ' diff --git a/otouto/plugins/notify.lua b/otouto/plugins/notify.lua index db0483e..7530420 100644 --- a/otouto/plugins/notify.lua +++ b/otouto/plugins/notify.lua @@ -3,9 +3,6 @@ local notify = {} -local redis = (loadfile "./otouto/redis.lua")() -local utilities = require('otouto.utilities') - function notify:init(config) notify.triggers = { "^/notify (del)$", diff --git a/otouto/plugins/pagespeed_insights.lua b/otouto/plugins/pagespeed_insights.lua index 7eb5593..a7daaa2 100644 --- a/otouto/plugins/pagespeed_insights.lua +++ b/otouto/plugins/pagespeed_insights.lua @@ -1,9 +1,5 @@ local pagespeed_insights = {} -local https = require('ssl.https') -local json = require('dkjson') -local utilities = require('otouto.utilities') - function pagespeed_insights:init(config) if not cred_data.google_apikey then print('Missing config value: google_apikey.') diff --git a/otouto/plugins/pasteee.lua b/otouto/plugins/pasteee.lua index 3d7d45e..9a9870f 100644 --- a/otouto/plugins/pasteee.lua +++ b/otouto/plugins/pasteee.lua @@ -1,8 +1,5 @@ local pasteee = {} -local bot = require('otouto.bot') -local utilities = require('otouto.utilities') - function pasteee:init(config) if not cred_data.pasteee_key then print('Missing config value: pasteee_key.') diff --git a/otouto/plugins/patterns.lua b/otouto/plugins/patterns.lua index ff0f766..ddcf4ee 100644 --- a/otouto/plugins/patterns.lua +++ b/otouto/plugins/patterns.lua @@ -1,7 +1,5 @@ local patterns = {} -local utilities = require('otouto.utilities') - patterns.triggers = { '^/?s/.-/.-$' } diff --git a/otouto/plugins/pixabay.lua b/otouto/plugins/pixabay.lua index 6d0fb54..eb72fe7 100644 --- a/otouto/plugins/pixabay.lua +++ b/otouto/plugins/pixabay.lua @@ -1,10 +1,5 @@ local pixabay = {} -local https = require('ssl.https') -local json = require('dkjson') -local utilities = require('otouto.utilities') -local redis = (loadfile "./otouto/redis.lua")() - function pixabay:init(config) if not cred_data.pixabay_apikey then print('Missing config value: pixabay_apikey.') diff --git a/otouto/plugins/play_store.lua b/otouto/plugins/play_store.lua index 7a30feb..47ff240 100644 --- a/otouto/plugins/play_store.lua +++ b/otouto/plugins/play_store.lua @@ -1,9 +1,5 @@ local play_store = {} -local https = require('ssl.https') -local json = require('dkjson') -local utilities = require('otouto.utilities') - function play_store:init(config) if not cred_data.x_mashape_key then print('Missing config value: x_mashape_key.') diff --git a/otouto/plugins/plugins.lua b/otouto/plugins/plugins.lua index 7fe9647..019f176 100644 --- a/otouto/plugins/plugins.lua +++ b/otouto/plugins/plugins.lua @@ -1,9 +1,6 @@ local plugin_manager = {} local bot = require('otouto.bot') -local bindings = require('otouto.bindings') -local utilities = require('otouto.utilities') -local redis = (loadfile "./otouto/redis.lua")() function plugin_manager:init(config) plugin_manager.triggers = { diff --git a/otouto/plugins/pocket.lua b/otouto/plugins/pocket.lua index f75a21f..18228e7 100644 --- a/otouto/plugins/pocket.lua +++ b/otouto/plugins/pocket.lua @@ -1,11 +1,5 @@ local pocket = {} -local https = require('ssl.https') -local URL = require('socket.url') -local redis = (loadfile "./otouto/redis.lua")() -local utilities = require('otouto.utilities') -local bindings = require('otouto.bindings') - function pocket:init(config) if not cred_data.pocket_consumer_key then print('Missing config value: pocket_consumer_key.') diff --git a/otouto/plugins/pokedex.lua b/otouto/plugins/pokedex.lua index a38de1a..1aab7b9 100644 --- a/otouto/plugins/pokedex.lua +++ b/otouto/plugins/pokedex.lua @@ -1,10 +1,5 @@ local pokedex = {} -local HTTP = require('socket.http') -local JSON = require('dkjson') -local bindings = require('otouto.bindings') -local utilities = require('otouto.utilities') - pokedex.command = 'pokedex ' function pokedex:init(config) @@ -33,22 +28,22 @@ function pokedex:action(msg, config) local url = 'http://pokeapi.co' local dex_url = url .. '/api/v1/pokemon/' .. input - local dex_jstr, res = HTTP.request(dex_url) + local dex_jstr, res = http.request(dex_url) if res ~= 200 then utilities.send_reply(self, msg, config.errors.connection) return end - local dex_jdat = JSON.decode(dex_jstr) + local dex_jdat = json.decode(dex_jstr) local desc_url = url .. dex_jdat.descriptions[math.random(#dex_jdat.descriptions)].resource_uri - local desc_jstr, _ = HTTP.request(desc_url) + local desc_jstr, _ = http.request(desc_url) if res ~= 200 then utilities.send_reply(self, msg, config.errors.connection) return end - local desc_jdat = JSON.decode(desc_jstr) + local desc_jdat = json.decode(desc_jstr) local poke_type for _,v in ipairs(dex_jdat.types) do diff --git a/otouto/plugins/preview.lua b/otouto/plugins/preview.lua index 7b535d6..a09bbc9 100644 --- a/otouto/plugins/preview.lua +++ b/otouto/plugins/preview.lua @@ -1,8 +1,5 @@ local preview = {} -local HTTP = require('socket.http') -local utilities = require('otouto.utilities') - preview.command = 'preview ' function preview:init(config) @@ -27,7 +24,7 @@ function preview:action(msg) input = 'http://' .. input end - local res = HTTP.request(input) + local res = http.request(input) if not res then utilities.send_reply(self, msg, 'Please provide a valid link.') return diff --git a/otouto/plugins/qr.lua b/otouto/plugins/qr.lua index 09b8702..2c607d4 100644 --- a/otouto/plugins/qr.lua +++ b/otouto/plugins/qr.lua @@ -1,9 +1,5 @@ local qr = {} -local http = require('socket.http') -local URL = require('socket.url') -local utilities = require('otouto.utilities') - function qr:init(config) qr.triggers = { '^/qr "(%w+)" "(%w+)" (.+)$', diff --git a/otouto/plugins/quotes.lua b/otouto/plugins/quotes.lua index 527d617..2df5d28 100644 --- a/otouto/plugins/quotes.lua +++ b/otouto/plugins/quotes.lua @@ -1,8 +1,5 @@ local quotes = {} -local bot = require('otouto.bot') -local utilities = require('otouto.utilities') -local redis = (loadfile "./otouto/redis.lua")() require("./otouto/plugins/pasteee") function quotes:init(config) diff --git a/otouto/plugins/random.lua b/otouto/plugins/random.lua index 99e6fab..428c62e 100644 --- a/otouto/plugins/random.lua +++ b/otouto/plugins/random.lua @@ -1,7 +1,5 @@ local fun = {} -local utilities = require('otouto.utilities') - function fun:init(config) fun.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('random', true).table fun.doc = [[* diff --git a/otouto/plugins/reddit.lua b/otouto/plugins/reddit.lua index 29c8193..cc46488 100644 --- a/otouto/plugins/reddit.lua +++ b/otouto/plugins/reddit.lua @@ -1,10 +1,5 @@ local reddit = {} -local https = require('ssl.https') -local URL = require('socket.url') -local JSON = require('dkjson') -local utilities = require('otouto.utilities') - reddit.command = 'reddit [r/subreddit | Suchbegriff]' function reddit:init(config) @@ -68,7 +63,7 @@ function reddit:action(msg, config) if res ~= 200 then utilities.send_reply(self, msg, config.errors.results) else - local jdat = JSON.decode(jstr) + local jdat = json.decode(jstr) if #jdat.data.children == 0 then utilities.send_reply(self, msg, config.errors.results) else diff --git a/otouto/plugins/reddit_post.lua b/otouto/plugins/reddit_post.lua index 86bd4c5..cc2d16d 100644 --- a/otouto/plugins/reddit_post.lua +++ b/otouto/plugins/reddit_post.lua @@ -1,10 +1,5 @@ local reddit_post = {} -local https = require('ssl.https') -local URL = require('socket.url') -local json = require('dkjson') -local utilities = require('otouto.utilities') - reddit_post.triggers = { "reddit.com/r/([A-Za-z0-9-/-_-.]+)/comments/([A-Za-z0-9-/-_-.]+)" } diff --git a/otouto/plugins/remind.lua b/otouto/plugins/remind.lua index 013d255..e691d83 100644 --- a/otouto/plugins/remind.lua +++ b/otouto/plugins/remind.lua @@ -1,7 +1,5 @@ local remind = {} -local utilities = require('otouto.utilities') - remind.command = 'remind ' function remind:init(config) diff --git a/otouto/plugins/respond.lua b/otouto/plugins/respond.lua index a8921d3..8368d7d 100644 --- a/otouto/plugins/respond.lua +++ b/otouto/plugins/respond.lua @@ -1,9 +1,5 @@ local respond = {} -local https = require('ssl.https') -local utilities = require('otouto.utilities') -local bindings = require('otouto.bindings') - function respond:init(config) respond.triggers = { "([Ff][Gg][Tt].? [Ss][Ww][Ii][Ff][Tt])", diff --git a/otouto/plugins/roll.lua b/otouto/plugins/roll.lua index f445ed3..d65bec6 100644 --- a/otouto/plugins/roll.lua +++ b/otouto/plugins/roll.lua @@ -1,7 +1,5 @@ local roll = {} -local utilities = require('otouto.utilities') - roll.command = 'roll' function roll:init(config) diff --git a/otouto/plugins/rss.lua b/otouto/plugins/rss.lua index 90d63ec..32f0baf 100644 --- a/otouto/plugins/rss.lua +++ b/otouto/plugins/rss.lua @@ -1,11 +1,5 @@ local rss = {} -local http = require('socket.http') -local https = require('ssl.https') -local url = require('socket.url') -local bindings = require('otouto.bindings') -local utilities = require('otouto.utilities') -local redis = (loadfile "./otouto/redis.lua")() local feedparser = require("feedparser") rss.command = 'rss ' diff --git a/otouto/plugins/set.lua b/otouto/plugins/set.lua index be57785..e133e92 100644 --- a/otouto/plugins/set.lua +++ b/otouto/plugins/set.lua @@ -1,8 +1,5 @@ local set = {} -local utilities = require('otouto.utilities') -local redis = (loadfile "./otouto/redis.lua")() - set.command = 'set ' function set:init(config) diff --git a/otouto/plugins/shell.lua b/otouto/plugins/shell.lua index ef3600c..4399c26 100644 --- a/otouto/plugins/shell.lua +++ b/otouto/plugins/shell.lua @@ -1,7 +1,5 @@ local shell = {} -local utilities = require('otouto.utilities') - function shell:init(config) shell.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('sh', true).table end diff --git a/otouto/plugins/site_header.lua b/otouto/plugins/site_header.lua index 4f58a33..6d07844 100644 --- a/otouto/plugins/site_header.lua +++ b/otouto/plugins/site_header.lua @@ -1,7 +1,5 @@ local site_header = {} -local utilities = require('otouto.utilities') - function site_header:init(config) site_header.triggers = { "^/(head) ([%w-_%.%?%.:,/%+=&#!]+)$", diff --git a/otouto/plugins/soundcloud.lua b/otouto/plugins/soundcloud.lua index f50c9d7..475681e 100644 --- a/otouto/plugins/soundcloud.lua +++ b/otouto/plugins/soundcloud.lua @@ -1,9 +1,5 @@ local soundcloud = {} -local http = require('socket.http') -local json = require('dkjson') -local utilities = require('otouto.utilities') - soundcloud.triggers = { "soundcloud.com/([A-Za-z0-9-/-_-.]+)" } diff --git a/otouto/plugins/speedtest.lua b/otouto/plugins/speedtest.lua index 9c46853..dfa0682 100644 --- a/otouto/plugins/speedtest.lua +++ b/otouto/plugins/speedtest.lua @@ -1,7 +1,5 @@ local speedtest = {} -local utilities = require('otouto.utilities') - speedtest.triggers = { "speedtest.net/my%-result/(%d+)", "speedtest.net/my%-result/i/(%d+)" diff --git a/otouto/plugins/spotify.lua b/otouto/plugins/spotify.lua index 3464a97..744c527 100644 --- a/otouto/plugins/spotify.lua +++ b/otouto/plugins/spotify.lua @@ -1,9 +1,5 @@ local spotify = {} -local https = require('ssl.https') -local json = require('dkjson') -local utilities = require('otouto.utilities') - spotify.triggers = { "open.spotify.com/track/([A-Za-z0-9-]+)", "play.spotify.com/track/([A-Za-z0-9-]+)" diff --git a/otouto/plugins/stats.lua b/otouto/plugins/stats.lua index 4fbef53..0e920be 100644 --- a/otouto/plugins/stats.lua +++ b/otouto/plugins/stats.lua @@ -1,8 +1,5 @@ local stats = {} -local utilities = require('otouto.utilities') -local redis = (loadfile "./otouto/redis.lua")() - function stats:init(config) stats.triggers = { "^/([Ss]tats)$", diff --git a/otouto/plugins/steam.lua b/otouto/plugins/steam.lua index 1db3888..145b1ea 100644 --- a/otouto/plugins/steam.lua +++ b/otouto/plugins/steam.lua @@ -1,10 +1,5 @@ local steam = {} -local utilities = require('otouto.utilities') -local http = require('socket.http') -local json = require('dkjson') -local bindings = require('otouto.bindings') - steam.triggers = { "store.steampowered.com/app/([0-9]+)", "steamcommunity.com/app/([0-9]+)" diff --git a/otouto/plugins/streamable.lua b/otouto/plugins/streamable.lua index 84c30b6..518a2f2 100644 --- a/otouto/plugins/streamable.lua +++ b/otouto/plugins/streamable.lua @@ -1,9 +1,5 @@ local streamable = {} -local https = require('ssl.https') -local json = require('dkjson') -local utilities = require('otouto.utilities') - streamable.triggers = { "streamable.com/([A-Za-z0-9-_-]+)", } diff --git a/otouto/plugins/surrogate.lua b/otouto/plugins/surrogate.lua index 642c64f..2b52d94 100644 --- a/otouto/plugins/surrogate.lua +++ b/otouto/plugins/surrogate.lua @@ -1,7 +1,5 @@ local surrogate = {} -local utilities = require('otouto.utilities') - surrogate.triggers = { "^/s (%-%d+) +(.+)$", "^/s (%d+) +(.+)$" diff --git a/otouto/plugins/tagesschau.lua b/otouto/plugins/tagesschau.lua index 3806d08..24a5494 100644 --- a/otouto/plugins/tagesschau.lua +++ b/otouto/plugins/tagesschau.lua @@ -1,11 +1,5 @@ local tagesschau = {} -local https = require('ssl.https') -local URL = require('socket.url') -local json = require('dkjson') -local utilities = require('otouto.utilities') -local bindings = require('otouto.bindings') - tagesschau.triggers = { "tagesschau.de/([A-Za-z0-9-_-_-/]+).html" } diff --git a/otouto/plugins/tagesschau_eil.lua b/otouto/plugins/tagesschau_eil.lua index 59328e8..c1b7363 100644 --- a/otouto/plugins/tagesschau_eil.lua +++ b/otouto/plugins/tagesschau_eil.lua @@ -1,12 +1,5 @@ local tagesschau_eil = {} -local http = require('socket.http') -local https = require('ssl.https') -local url = require('socket.url') -local json = require('dkjson') -local utilities = require('otouto.utilities') -local redis = (loadfile "./otouto/redis.lua")() - tagesschau_eil.command = 'eil ' function tagesschau_eil:init(config) diff --git a/otouto/plugins/tex.lua b/otouto/plugins/tex.lua index 0f0a87a..d8f7e81 100644 --- a/otouto/plugins/tex.lua +++ b/otouto/plugins/tex.lua @@ -1,8 +1,5 @@ local tex = {} -local URL = require('socket.url') -local utilities = require('otouto.utilities') - tex.command = 'tex ' function tex:init(config) diff --git a/otouto/plugins/thetvdb.lua b/otouto/plugins/thetvdb.lua index 78d77dc..5ee3812 100644 --- a/otouto/plugins/thetvdb.lua +++ b/otouto/plugins/thetvdb.lua @@ -1,9 +1,6 @@ local tv = {} -local http = require('socket.http') -local URL = require('socket.url') local xml = require("xml") -local utilities = require('otouto.utilities') tv.command = 'tv ' diff --git a/otouto/plugins/time.lua b/otouto/plugins/time.lua index 38d9ce1..779e2cf 100644 --- a/otouto/plugins/time.lua +++ b/otouto/plugins/time.lua @@ -1,9 +1,5 @@ local time = {} -local HTTPS = require('ssl.https') -local JSON = require('dkjson') -local utilities = require('otouto.utilities') - time.command = 'time ' function time:init(config) @@ -67,13 +63,13 @@ function time:action(msg, config) local utc = os.time(os.date("!*t", now)) local url = 'https://maps.googleapis.com/maps/api/timezone/json?location=' .. coords.lat ..','.. coords.lon .. '×tamp='..utc..'&language=de' - local jstr, res = HTTPS.request(url) + local jstr, res = https.request(url) if res ~= 200 then utilities.send_reply(self, msg, config.errors.connection) return end - local jdat = JSON.decode(jstr) + local jdat = json.decode(jstr) local timezoneid = '*'..string.gsub(jdat.timeZoneId, '_', ' ' )..'*' local timestamp = now + jdat.rawOffset + jdat.dstOffset local utcoff = (jdat.rawOffset + jdat.dstOffset) / 3600 diff --git a/otouto/plugins/translate.lua b/otouto/plugins/translate.lua index f9e8427..5caf71b 100644 --- a/otouto/plugins/translate.lua +++ b/otouto/plugins/translate.lua @@ -1,9 +1,4 @@ local translate = {} - -local https = require('ssl.https') -local URL = require('socket.url') -local json = require('dkjson') -local utilities = require('otouto.utilities') local mime = require("mime") require("./otouto/plugins/pasteee") diff --git a/otouto/plugins/tweet.lua b/otouto/plugins/tweet.lua index ad0c88e..19c831c 100644 --- a/otouto/plugins/tweet.lua +++ b/otouto/plugins/tweet.lua @@ -1,12 +1,5 @@ local tweet = {} -local utilities = require('otouto.utilities') -local HTTPS = require('ssl.https') -local JSON = require('dkjson') -local redis = (loadfile "./otouto/redis.lua")() -local OAuth = (require "OAuth") -local bindings = require('otouto.bindings') - function tweet:init(config) if not cred_data.tw_consumer_key then print('Missing config value: tw_consumer_key.') @@ -145,7 +138,7 @@ function tweet:getTweet(self, msg, base, all) return "Konnte nicht verbinden, evtl. existiert der User nicht?" end - local response = JSON.decode(response_body) + local response = json.decode(response_body) if #response == 0 then return "Konnte keinen Tweet bekommen, sorry" end diff --git a/otouto/plugins/twitch.lua b/otouto/plugins/twitch.lua index c28511e..edd0aa8 100644 --- a/otouto/plugins/twitch.lua +++ b/otouto/plugins/twitch.lua @@ -1,9 +1,5 @@ local twitch = {} -local https = require('ssl.https') -local json = require('dkjson') -local utilities = require('otouto.utilities') - twitch.triggers = { "twitch.tv/([A-Za-z0-9-_-]+)" } diff --git a/otouto/plugins/twitter.lua b/otouto/plugins/twitter.lua index b3a622c..b96b9a8 100644 --- a/otouto/plugins/twitter.lua +++ b/otouto/plugins/twitter.lua @@ -1,12 +1,5 @@ local twitter = {} -local utilities = require('otouto.utilities') -local HTTPS = require('ssl.https') -local JSON = require('dkjson') -local redis = (loadfile "./otouto/redis.lua")() -local OAuth = (require "OAuth") -local bindings = require('otouto.bindings') - function twitter:init(config) if not cred_data.tw_consumer_key then print('Missing config value: tw_consumer_key.') @@ -57,7 +50,7 @@ function twitter:action(msg, config, matches) local twitter_url = "https://api.twitter.com/1.1/statuses/show/" .. id.. ".json" local response_code, response_headers, response_status_line, response_body = client:PerformRequest("GET", twitter_url) - local response = JSON.decode(response_body) + local response = json.decode(response_body) local full_name = response.user.name local user_name = response.user.screen_name diff --git a/otouto/plugins/twitter_send.lua b/otouto/plugins/twitter_send.lua index 4b8bdbb..35b40ff 100644 --- a/otouto/plugins/twitter_send.lua +++ b/otouto/plugins/twitter_send.lua @@ -1,14 +1,5 @@ local twitter_send = {} -local http = require('socket.http') -local https = require('ssl.https') -local URL = require('socket.url') -local json = require('dkjson') -local utilities = require('otouto.utilities') -local bindings = require('otouto.bindings') -local OAuth = require "OAuth" -local redis = (loadfile "./otouto/redis.lua")() - function twitter_send:init(config) if not cred_data.tw_consumer_key then print('Missing config value: tw_consumer_key.') diff --git a/otouto/plugins/twitter_user.lua b/otouto/plugins/twitter_user.lua index dbf87e0..7dd64c5 100644 --- a/otouto/plugins/twitter_user.lua +++ b/otouto/plugins/twitter_user.lua @@ -1,12 +1,5 @@ local twitter_user = {} -local utilities = require('otouto.utilities') -local http = require('socket.http') -local https = require('ssl.https') -local json = require('dkjson') -local OAuth = (require "OAuth") -local bindings = require('otouto.bindings') - function twitter_user:init(config) if not cred_data.tw_consumer_key then print('Missing config value: tw_consumer_key.') diff --git a/otouto/plugins/urbandictionary.lua b/otouto/plugins/urbandictionary.lua index 916a8a1..4c2bdee 100644 --- a/otouto/plugins/urbandictionary.lua +++ b/otouto/plugins/urbandictionary.lua @@ -1,10 +1,5 @@ local urbandictionary = {} -local HTTP = require('socket.http') -local URL = require('socket.url') -local JSON = require('dkjson') -local utilities = require('otouto.utilities') - urbandictionary.command = 'urbandictionary ' function urbandictionary:init(config) @@ -31,13 +26,13 @@ function urbandictionary:action(msg, config) local url = 'http://api.urbandictionary.com/v0/define?term=' .. URL.escape(input) - local jstr, res = HTTP.request(url) + local jstr, res = http.request(url) if res ~= 200 then utilities.send_reply(self, msg, config.errors.connection) return end - local jdat = JSON.decode(jstr) + local jdat = json.decode(jstr) if jdat.result_type == "no_results" then utilities.send_reply(self, msg, config.errors.results) return diff --git a/otouto/plugins/venue.lua b/otouto/plugins/venue.lua index 0d2f104..ce75c59 100644 --- a/otouto/plugins/venue.lua +++ b/otouto/plugins/venue.lua @@ -1,9 +1,5 @@ local venue = {} -local https = require('ssl.https') -local json = require('dkjson') -local utilities = require('otouto.utilities') - venue.triggers = { '/nil' } diff --git a/otouto/plugins/vimeo.lua b/otouto/plugins/vimeo.lua index 21b7ee8..c5668ad 100644 --- a/otouto/plugins/vimeo.lua +++ b/otouto/plugins/vimeo.lua @@ -1,9 +1,5 @@ local vimeo = {} -local https = require('ssl.https') -local json = require('dkjson') -local utilities = require('otouto.utilities') - vimeo.triggers = { "vimeo.com/(%d+)" } diff --git a/otouto/plugins/vine.lua b/otouto/plugins/vine.lua index 15e087b..baa8bba 100644 --- a/otouto/plugins/vine.lua +++ b/otouto/plugins/vine.lua @@ -1,9 +1,5 @@ local vine = {} -local https = require('ssl.https') -local json = require('dkjson') -local utilities = require('otouto.utilities') - vine.triggers = { "vine.co/v/([A-Za-z0-9-_-]+)" } diff --git a/otouto/plugins/weather.lua b/otouto/plugins/weather.lua index a0f42f5..828a08e 100644 --- a/otouto/plugins/weather.lua +++ b/otouto/plugins/weather.lua @@ -1,12 +1,5 @@ local weather = {} -local HTTPS = require('ssl.https') -local URL = require('socket.url') -local JSON = require('dkjson') -local utilities = require('otouto.utilities') -local bindings = require('otouto.bindings') -local redis = (loadfile "./otouto/redis.lua")() - function weather:init(config) if not cred_data.forecastio_apikey then print('Missing config value: forecastio_apikey.') @@ -40,9 +33,9 @@ function get_city_name(lat, lng) local city = redis:hget('telegram:cache:weather:pretty_names', lat..','..lng) if city then return city end local url = 'https://maps.googleapis.com/maps/api/geocode/json?latlng='..lat..','..lng..'&result_type=political&language=de&key='..google_apikey - local res, code = HTTPS.request(url) + local res, code = https.request(url) if code ~= 200 then return 'Unbekannte Stadt' end - local data = JSON.decode(res).results[1] + local data = json.decode(res).results[1] local city = data.formatted_address print('Setting '..lat..','..lng..' in redis hash telegram:cache:weather:pretty_names to "'..city..'"') redis:hset('telegram:cache:weather:pretty_names', lat..','..lng, city) @@ -62,9 +55,9 @@ function weather:get_weather(lat, lng) method = "GET", sink = ltn12.sink.table(response_body) } - local ok, response_code, response_headers, response_status_line = HTTPS.request(request_constructor) + local ok, response_code, response_headers, response_status_line = https.request(request_constructor) if not ok then return nil end - local data = JSON.decode(table.concat(response_body)) + local data = json.decode(table.concat(response_body)) local ttl = string.sub(response_headers["cache-control"], 9) diff --git a/otouto/plugins/webshot.lua b/otouto/plugins/webshot.lua index 9bf373d..8e2e07b 100644 --- a/otouto/plugins/webshot.lua +++ b/otouto/plugins/webshot.lua @@ -1,12 +1,5 @@ local webshot = {} -local helpers = require('OAuth.helpers') -local utilities = require('otouto.utilities') -local https = require('ssl.https') -local ltn12 = require('ltn12') -local json = require('dkjson') -local bindings = require('otouto.bindings') - local base = 'https://screenshotmachine.com/' local url = base .. 'processor.php' diff --git a/otouto/plugins/wiimmfi.lua b/otouto/plugins/wiimmfi.lua index 0ff956c..0e5c054 100644 --- a/otouto/plugins/wiimmfi.lua +++ b/otouto/plugins/wiimmfi.lua @@ -1,9 +1,5 @@ local wiimmfi = {} -local http = require('socket.http') -local utilities = require('otouto.utilities') -local bindings = require('otouto.bindings') - function wiimmfi:init(config) wiimmfi.triggers = { "^/(mkw)$", diff --git a/otouto/plugins/wikia.lua b/otouto/plugins/wikia.lua index 839fde0..71cf3d4 100644 --- a/otouto/plugins/wikia.lua +++ b/otouto/plugins/wikia.lua @@ -1,10 +1,5 @@ local wikia = {} -local http = require('socket.http') -local json = require('dkjson') -local utilities = require('otouto.utilities') -local bindings = require('otouto.bindings') - wikia.triggers = { "https?://(.+).wikia.com/wiki/(.+)" } diff --git a/otouto/plugins/wikipedia.lua b/otouto/plugins/wikipedia.lua index 19a133d..44131ac 100644 --- a/otouto/plugins/wikipedia.lua +++ b/otouto/plugins/wikipedia.lua @@ -1,11 +1,5 @@ local wikipedia = {} -local https = require('ssl.https') -local URL = require('socket.url') -local JSON = require('dkjson') -local socket = require('socket') -local utilities = require('otouto.utilities') - wikipedia.command = 'wiki ' function wikipedia:init(config) @@ -101,7 +95,7 @@ function wikipedia:loadPage(text, lang, intro, plain, is_search) local content = table.concat(sink) if content ~= "" then - local ok, result = pcall(JSON.decode, content) + local ok, result = pcall(json.decode, content) if ok and result then return result else @@ -174,7 +168,7 @@ function wikipedia:inline_callback(inline_query, config, matches) local url = 'https://'..lang..'.wikipedia.org/w/api.php?action=query&list=search&srsearch='..URL.escape(query)..'&format=json&prop=extracts&srprop=snippet' local res, code = https.request(url) if code ~= 200 then return end - local data = JSON.decode(res).query + local data = json.decode(res).query if data.searchinfo.totalhits == 0 then return end diff --git a/otouto/plugins/xkcd.lua b/otouto/plugins/xkcd.lua index 9445109..e3dc69c 100644 --- a/otouto/plugins/xkcd.lua +++ b/otouto/plugins/xkcd.lua @@ -1,9 +1,5 @@ local xkcd = {} -local http = require('socket.http') -local json = require('dkjson') -local utilities = require('otouto.utilities') - xkcd.command = 'xkcd [i]' function xkcd:init(config) diff --git a/otouto/plugins/yourls.lua b/otouto/plugins/yourls.lua index 7e01365..f3fb225 100644 --- a/otouto/plugins/yourls.lua +++ b/otouto/plugins/yourls.lua @@ -1,9 +1,5 @@ local yourls = {} -local http = require('socket.http') -local https = require('ssl.https') -local utilities = require('otouto.utilities') - function yourls:init(config) if not cred_data.yourls_site_url then print('Missing config value: yourls_site_url.') diff --git a/otouto/plugins/youtube.lua b/otouto/plugins/youtube.lua index 655b9d0..6ca9428 100644 --- a/otouto/plugins/youtube.lua +++ b/otouto/plugins/youtube.lua @@ -1,11 +1,5 @@ local youtube = {} -local utilities = require('otouto.utilities') -local https = require('ssl.https') -local URL = require('socket.url') -local JSON = require('dkjson') -local bindings = require('otouto.bindings') - function youtube:init(config) if not cred_data.google_apikey then print('Missing config value: google_apikey.') @@ -46,7 +40,7 @@ function get_yt_data (yt_code) local url = BASE_URL..'/videos?part=snippet,statistics,contentDetails&key='..apikey..'&id='..yt_code..'&fields=items(snippet(publishedAt,channelTitle,localized(title,description),thumbnails),statistics(viewCount,likeCount,dislikeCount,commentCount),contentDetails(duration,regionRestriction(blocked)))' local res,code = https.request(url) if code ~= 200 then return "HTTP-FEHLER" end - local data = JSON.decode(res).items[1] + local data = json.decode(res).items[1] return data end @@ -162,7 +156,7 @@ function youtube:inline_callback(inline_query, config, matches) local res,code = https.request(url) if code ~= 200 then return end - local data = JSON.decode(res) + local data = json.decode(res) if not data.items[1] then return end local video_ids = "" @@ -179,7 +173,7 @@ function youtube:inline_callback(inline_query, config, matches) local res,code = https.request(url) if code ~= 200 then return end - local video_results = JSON.decode(res) + local video_results = json.decode(res) if not video_results.items[1] then return end local results = '[' diff --git a/otouto/plugins/youtube_channel.lua b/otouto/plugins/youtube_channel.lua index e45d11c..e7ba65d 100644 --- a/otouto/plugins/youtube_channel.lua +++ b/otouto/plugins/youtube_channel.lua @@ -1,9 +1,5 @@ local youtube_channel = {} -local utilities = require('otouto.utilities') -local https = require('ssl.https') -local JSON = require('dkjson') - function youtube_channel:init(config) if not cred_data.google_apikey then print('Missing config value: google_apikey.') @@ -30,12 +26,12 @@ function youtube_channel:get_yt_channel_data(channel_name) local url = BASE_URL..'/channels?part=snippet,statistics&key='..apikey..'&forUsername='..channel_name..'&fields=items%28snippet%28publishedAt,localized%28title,description%29%29,statistics%28viewCount,subscriberCount,videoCount%29%29' local res,code = https.request(url) if code ~= 200 then return "HTTP-FEHLER" end - local data = JSON.decode(res).items[1] + local data = json.decode(res).items[1] if data == nil then local url = BASE_URL..'/channels?part=snippet,statistics&key='..apikey..'&id='..channel_name..'&fields=items%28snippet%28publishedAt,localized%28title,description%29%29,statistics%28viewCount,subscriberCount,videoCount%29%29' local res,code = https.request(url) if code ~= 200 then return "HTTP-FEHLER" end - return JSON.decode(res).items[1] + return json.decode(res).items[1] end return data end diff --git a/otouto/plugins/youtube_dl.lua b/otouto/plugins/youtube_dl.lua index af8d798..b11b3d5 100644 --- a/otouto/plugins/youtube_dl.lua +++ b/otouto/plugins/youtube_dl.lua @@ -1,7 +1,5 @@ local youtube_dl = {} -local utilities = require('otouto.utilities') - function youtube_dl:init(config) youtube_dl.triggers = { "^/(mp4) (https?://[%w-_%.%?%.:/%+=&]+)$", diff --git a/otouto/plugins/youtube_playlist.lua b/otouto/plugins/youtube_playlist.lua index 2722dcd..19c96f5 100644 --- a/otouto/plugins/youtube_playlist.lua +++ b/otouto/plugins/youtube_playlist.lua @@ -1,9 +1,5 @@ local youtube_playlist = {} -local utilities = require('otouto.utilities') -local https = require('ssl.https') -local JSON = require('dkjson') - function youtube_playlist:init(config) if not cred_data.google_apikey then print('Missing config value: google_apikey.') @@ -29,7 +25,7 @@ function youtube_playlist:get_pl_data (pl_code) local url = BASE_URL..'/playlists?part=snippet,contentDetails&key='..apikey..'&id='..pl_code..'&fields=items(snippet(publishedAt,channelTitle,localized(title,description)),contentDetails(itemCount))' local res,code = https.request(url) if code ~= 200 then return "HTTP-FEHLER" end - local data = JSON.decode(res).items[1] + local data = json.decode(res).items[1] return data end diff --git a/otouto/plugins/youtube_search.lua b/otouto/plugins/youtube_search.lua index f94a392..94a73b8 100644 --- a/otouto/plugins/youtube_search.lua +++ b/otouto/plugins/youtube_search.lua @@ -1,11 +1,6 @@ -require("./otouto/plugins/youtube") - local yt_search = {} -local utilities = require('otouto.utilities') -local https = require('ssl.https') -local URL = require('socket.url') -local JSON = require('dkjson') +require("./otouto/plugins/youtube") yt_search.command = 'yt ' @@ -40,7 +35,7 @@ end function httpsRequest(url) local res,code = https.request(url) if code ~= 200 then return nil end - return JSON.decode(res) + return json.decode(res) end function yt_search:action(msg) diff --git a/otouto/utilities.lua b/otouto/utilities.lua index 83da24b..0307c00 100644 --- a/otouto/utilities.lua +++ b/otouto/utilities.lua @@ -3,20 +3,20 @@ local utilities = {} -local HTTP = require('socket.http') -local ltn12 = require('ltn12') -local HTTPS = require('ssl.https') -local URL = require('socket.url') -local JSON = require('dkjson') -local http = require('socket.http') -local serpent = require("serpent") -local bindings = require('otouto.bindings') -local redis = (loadfile "./otouto/redis.lua")() -local mimetype = (loadfile "./otouto/mimetype.lua")() -local OAuth = require "OAuth" -local helpers = require "OAuth.helpers" +ltn12 = require('ltn12') +http = require('socket.http') +https = require('ssl.https') +URL = require('socket.url') +json = require('dkjson') +serpent = require("serpent") +bindings = require('otouto.bindings') +redis = (loadfile "./otouto/redis.lua")() +mimetype = (loadfile "./otouto/mimetype.lua")() +OAuth = require "OAuth" +helpers = require "OAuth.helpers" -HTTP.timeout = 10 +http.timeout = 5 +https.timeout = 5 -- For the sake of ease to new contributors and familiarity to old contributors, -- we'll provide a couple of aliases to real bindings here. @@ -301,10 +301,10 @@ function download_to_file(url, file_name) file_name = '/tmp/' .. file_name end local body = {} - local doer = HTTP + local doer = http local do_redir = true if url:match('^https') then - doer = HTTPS + doer = https do_redir = false end local _, res = doer.request{ @@ -332,13 +332,13 @@ function utilities.load_data(filename) end local s = f:read('*all') f:close() - local data = JSON.decode(s) + local data = json.decode(s) return data end -- Saves a table to a JSON file. function utilities.save_data(filename, data) - local s = JSON.encode(data) + local s = json.encode(data) local f = io.open(filename, 'w') f:write(s) f:close() @@ -349,12 +349,12 @@ function utilities.get_coords(input, config) local url = 'https://maps.googleapis.com/maps/api/geocode/json?address=' .. URL.escape(input) - local jstr, res = HTTPS.request(url) + local jstr, res = https.request(url) if res ~= 200 then return config.errors.connection end - local jdat = JSON.decode(jstr) + local jdat = json.decode(jstr) if jdat.status == 'ZERO_RESULTS' then return config.errors.results end @@ -522,10 +522,10 @@ function utilities.triggers(username, cmd_pat, trigger_table) end function utilities.with_http_timeout(timeout, fun) - local original = HTTP.TIMEOUT - HTTP.TIMEOUT = timeout + local original = http.TIMEOUT + http.TIMEOUT = timeout fun() - HTTP.TIMEOUT = original + http.TIMEOUT = original end function utilities.enrich_user(user) @@ -662,14 +662,14 @@ function post_petition(url, arguments, headers) if post_prot == "http" then ok, response_code, response_headers, response_status_line = http.request(request_constructor) else - ok, response_code, response_headers, response_status_line = HTTPS.request(request_constructor) + ok, response_code, response_headers, response_status_line = https.request(request_constructor) end if not ok then return nil end - response_body = JSON.decode(table.concat(response_body)) + response_body = json.decode(table.concat(response_body)) return response_body, response_headers end @@ -782,7 +782,7 @@ function get_http_header(url) local doer = HTTP local do_redir = true if url:match('^https') then - doer = HTTPS + doer = https do_redir = false end local _, code, header = doer.request {