diff --git a/.gitignore b/.gitignore index e72bf0f..6f5a830 100755 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,3 @@ config.lua loc/weeb.lua -console.lua *.json -plugins/owm.lua -plugins/liberblock.lua -plugins/dgmp.lua diff --git a/config.lua.default b/config.lua.default index e59246e..ca1965b 100755 --- a/config.lua.default +++ b/config.lua.default @@ -22,6 +22,7 @@ return { 'wikipedia.lua', 'imdb.lua', 'urbandictionary.lua', + 'spotify.lua', 'kickass.lua', 'hackernews.lua', 'cats.lua', diff --git a/console.lua b/console.lua new file mode 100755 index 0000000..6596216 --- /dev/null +++ b/console.lua @@ -0,0 +1,34 @@ +JSON = require('dkjson') +URL = require('socket.url') +HTTP = require('socket.http') +HTTPS= require('ssl.https') + +require('utilities') +config = require('config') +require('bindings') + +data = load_data('moderation.json') + +print('Fetching bot data...') +bot = get_me().result +if not bot then + error('Failure fetching bot information.') +end +for k,v in pairs(bot) do + print('',k,v) +end + +print('Loading plugins...') +plugins = {} +for i,v in ipairs(config.plugins) do + local p = dofile('plugins/'..v) + table.insert(plugins, p) +end + +clear = function() + for i = 1, 100 do + print('\n') + end +end + +print('You are now in the otouto console!') diff --git a/plugins/about.lua b/plugins/about.lua index 4af18c8..a074d72 100755 --- a/plugins/about.lua +++ b/plugins/about.lua @@ -19,7 +19,10 @@ function PLUGIN.action(msg) Based on otouto v]] .. VERSION .. [[ by @topkecleon. otouto v2 is licensed under the GPLv2. topkecleon.github.io/otouto - ]] -- Please do not remove this message. + + Join the update/news channel! + telegram.me/otouto + ]] -- Please do not remove this message. ^.^ send_message(msg.chat.id, message, true) diff --git a/plugins/dgmp.lua b/plugins/dgmp.lua index 99d83c4..8275278 100755 --- a/plugins/dgmp.lua +++ b/plugins/dgmp.lua @@ -1,3 +1,5 @@ + -- This is an experimental plugin for indexing a list of compliant groups, their descriptions, how to join them, etc. It is not complete nor fully implemented. The current test bot is @dgmpbot. + local triggers = { '^/index', '^/listgroups' diff --git a/plugins/kickass.lua b/plugins/kickass.lua index c0a1452..7e1b41c 100755 --- a/plugins/kickass.lua +++ b/plugins/kickass.lua @@ -21,7 +21,7 @@ local action = function(msg) return send_msg(msg, doc) end - local jstr, res = HTTP.request(url..URL.escape(input)) + local jstr, res = HTTPS.request(url..URL.escape(input)) if res ~= 200 then return send_msg(msg, config.locale.errors.connection) end diff --git a/plugins/owm.lua b/plugins/owm.lua new file mode 100755 index 0000000..19f9688 --- /dev/null +++ b/plugins/owm.lua @@ -0,0 +1,40 @@ +local PLUGIN = {} + +PLUGIN.doc = [[ + /weather + Returns the current temperature and weather conditions for a specified location. + Non-city locations are accepted; "/weather Buckingham Palace" will return the weather for Westminster. +]] + +PLUGIN.triggers = { + '^/weather' +} + +function PLUGIN.action(msg) + + local input = get_input(msg.text) + if not input then + return send_msg(msg, PLUGIN.doc) + end + + coords = get_coords(input) + if not coords then + return send_msg(msg, config.locale.errors.results) + end + + local url = 'http://api.openweathermap.org/data/2.5/weather?lat=' .. coords.lat .. '&lon=' .. coords.lon + local jstr, res = HTTP.request(url) + if res ~= 200 then + return send_msg(msg, config.locale.errors.connection) + end + local jdat = JSON.decode(jstr) + + local celsius = jdat.main.temp - 273.15 + local fahrenheit = tonumber(string.format("%.2f", celsius * (9/5) + 32)) + local message = celsius .. '°C | ' .. fahrenheit .. '°F, ' .. jdat.weather[1].description .. '.' + + send_msg(msg, message) + +end + +return PLUGIN diff --git a/plugins/spotify.lua b/plugins/spotify.lua new file mode 100755 index 0000000..b09359b --- /dev/null +++ b/plugins/spotify.lua @@ -0,0 +1,52 @@ +-- Spotify Plugin for bot based on otouto +-- ByTiagoDanin - Telegram.me/tiagodanin +local PLUGIN = {} + +PLUGIN.doc = [[ + /spotify + Track Spotify music. +]] + +PLUGIN.triggers = { + '^/spoti$', + '^/spotify' +} + +function PLUGIN.action(msg) + + local input = get_input(msg.text) + if not input then + return send_msg(msg, PLUGIN.doc) + end + --URL API + local BASE_URL = "https://api.spotify.com/v1/search" + local URLP = "?q=".. (URL.escape(input) or "").."&type=track&limit=5" -- Limit 5 + -- Decode json + local decj, tim = HTTPS.request(BASE_URL..URLP) + if tim ~=200 then return nil end + -- Table + local spotify = JSON.decode(decj) + local tables = {} + for pri,result in ipairs(spotify.tracks.items) do + table.insert(tables, { + spotify.tracks.total, + result.name .. ' - ' .. result.artists[1].name, + result.external_urls.spotify + }) + end + -- Print Tables + local gets = "" + for pri,cont in ipairs(tables) do + gets=gets.."▶️ "..cont[2].."\n"..cont[3].."\n" + end + -- ERRO 404 + local text_end = gets -- Text END + if gets == "" then + text_end = "Not found music" + end + -- Send MSG + send_msg(msg, text_end) + +end + +return PLUGIN