added spotify plugin (thanks to @TiagoDanin)

fixed kickass plugin (required HTTPS)
included console.lua (for those who may use it)
included link to otouto update channel in about.lua
This commit is contained in:
topkecleon 2015-09-22 22:27:36 -04:00
parent ab16426898
commit c7ba76e72b
8 changed files with 134 additions and 6 deletions

4
.gitignore vendored
View File

@ -1,7 +1,3 @@
config.lua
loc/weeb.lua
console.lua
*.json
plugins/owm.lua
plugins/liberblock.lua
plugins/dgmp.lua

View File

@ -22,6 +22,7 @@ return {
'wikipedia.lua',
'imdb.lua',
'urbandictionary.lua',
'spotify.lua',
'kickass.lua',
'hackernews.lua',
'cats.lua',

34
console.lua Executable file
View File

@ -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!')

View File

@ -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)

View File

@ -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'

View File

@ -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

40
plugins/owm.lua Executable file
View File

@ -0,0 +1,40 @@
local PLUGIN = {}
PLUGIN.doc = [[
/weather <location>
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

52
plugins/spotify.lua Executable file
View File

@ -0,0 +1,52 @@
-- Spotify Plugin for bot based on otouto
-- ByTiagoDanin - Telegram.me/tiagodanin
local PLUGIN = {}
PLUGIN.doc = [[
/spotify <music>
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