Skip to content

Commit

Permalink
added spotify plugin (thanks to @TiagoDanin)
Browse files Browse the repository at this point in the history
fixed kickass plugin (required HTTPS)
included console.lua (for those who may use it)
included link to otouto update channel in about.lua
  • Loading branch information
topkecleon committed Sep 23, 2015
1 parent ab16426 commit c7ba76e
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 6 deletions.
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
config.lua
loc/weeb.lua
console.lua
*.json
plugins/owm.lua
plugins/liberblock.lua
plugins/dgmp.lua
1 change: 1 addition & 0 deletions config.lua.default
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ return {
'wikipedia.lua',
'imdb.lua',
'urbandictionary.lua',
'spotify.lua',
'kickass.lua',
'hackernews.lua',
'cats.lua',
Expand Down
34 changes: 34 additions & 0 deletions console.lua
Original file line number Diff line number Diff line change
@@ -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!')
5 changes: 4 additions & 1 deletion plugins/about.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 2 additions & 0 deletions plugins/dgmp.lua
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
2 changes: 1 addition & 1 deletion plugins/kickass.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
40 changes: 40 additions & 0 deletions plugins/owm.lua
Original file line number Diff line number Diff line change
@@ -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 changes: 52 additions & 0 deletions plugins/spotify.lua
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit c7ba76e

Please sign in to comment.