- Portierung folgender Plugins:

+ Clypit
+ Dailymotion
+ DeviantArt
+ DHL
+ Dropbox
+ Vimeo
+ Vine
- Fixe einige, kleine Bugs
This commit is contained in:
Andreas Bielawski 2016-06-18 15:18:42 +02:00
parent f891672572
commit f3c841fb90
10 changed files with 288 additions and 10 deletions

View File

@ -158,7 +158,7 @@ function banhammer:pre_process(msg, self, config)
return msg
end
function banhammer:action(msg, config)
function banhammer:action(msg, config, matches)
if msg.from.id ~= config.admin then
utilities.send_reply(self, msg, config.errors.sudo)
return

View File

@ -69,7 +69,7 @@ function channels:pre_process(msg, self, config)
return msg
end
function channels:action(msg, config)
function channels:action(msg, config, matches)
if msg.from.id ~= config.admin then
utilities.send_reply(self, msg, config.errors.sudo)
return

33
otouto/plugins/clypit.lua Normal file
View File

@ -0,0 +1,33 @@
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-_-]+)"
}
function clypit:get_clypit_details(shortcode)
local BASE_URL = "http://api.clyp.it"
local url = BASE_URL..'/'..shortcode
local res,code = http.request(url)
if code ~= 200 then return nil end
local data = json.decode(res)
local title = data.Title
local duration = data.Duration
local audio = download_to_file(data.Mp3Url)
return audio, title, duration
end
function clypit:action(msg, config, matches)
utilities.send_typing(self, msg.chat.id, 'upload_audio')
local audio, title, duration = clypit:get_clypit_details(matches[1])
if not audio then return utilities.send_reply(self, msg, config.errors.connection) end
utilities.send_audio(self, msg.chat.id, audio, nil, msg.message_id, duration, nil, title)
end
return clypit

View File

@ -0,0 +1,31 @@
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-_-]+)"
}
local BASE_URL = 'https://api.dailymotion.com'
function dailymotion:send_dailymotion_info (dm_code)
local url = BASE_URL..'/video/'..dm_code
local res,code = https.request(url)
if code ~= 200 then return nil end
local data = json.decode(res)
local title = data.title
local channel = data.channel
local text = '*'..title..'*\nHochgeladen in die Kategorie *'..channel..'*'
return text
end
function dailymotion:action(msg, config, matches)
local text = dailymotion:send_dailymotion_info(matches[1])
if not text then utilities.send_reply(self, msg, config.errors.connection) return end
utilities.send_reply(self, msg, text, true)
end
return dailymotion

View File

@ -0,0 +1,52 @@
local deviantart = {}
local https = require('ssl.https')
local json = require('dkjson')
local utilities = require('otouto.utilities')
deviantart.triggers = {
"http://(.*).deviantart.com/art/(.*)"
}
local BASE_URL = 'https://backend.deviantart.com'
function deviantart:get_da_data (da_code)
local url = BASE_URL..'/oembed?url='..da_code
local res,code = https.request(url)
if code ~= 200 then return nil end
local data = json.decode(res)
return data
end
function deviantart:send_da_data (data)
local title = data.title
local category = data.category
local author_name = data.author_name
local text = title..' von '..author_name..'\n'..category
if data.rating == "adult" then
return title..' von '..author_name..'\n'..category..'\n(NSFW)'
else
local image_url = data.fullsize_url
if image_url == nil then
image_url = data.url
end
local file = download_to_file(image_url)
return text, file
end
end
function deviantart:action(msg, config, matches)
local data = deviantart:get_da_data('http://'..matches[1]..'.deviantart.com/art/'..matches[2])
if not data then utilities.send_reply(self, msg, config.errors.connection) return end
local text, file = deviantart:send_da_data(data)
if file then
utilities.send_photo(self, msg.chat.id, file, text, msg.message_id)
else
utilities.send_reply(self, msg, text)
return
end
end
return deviantart

38
otouto/plugins/dhl.lua Normal file
View File

@ -0,0 +1,38 @@
local dhl = {}
local https = require('ssl.https')
local json = require('dkjson')
local utilities = require('otouto.utilities')
function dhl:init(config)
dhl.triggers = {
"/dhl (%d+)$"
}
dhl.doc = [[*
]]..config.cmd_pat..[[dhl* _<Sendungsnummer>_: Aktueller Status der Sendung]]
end
local BASE_URL = 'https://mobil.dhl.de'
function dhl:sendungsstatus(id)
local url = BASE_URL..'/shipmentdetails.html?shipmentId='..id
local res,code = https.request(url)
if code ~= 200 then return "Fehler beim Abrufen von mobil.dhl.de" end
local status = string.match(res, "<div id%=\"detailShortStatus\">(.-)</div>")
local status = all_trim(status)
local zeit = string.match(res, "<div id%=\"detailStatusDateTime\">(.-)</div>")
local zeit = all_trim(zeit)
if not zeit or zeit == '<br />' then
return status
end
return '*'..status..'*\n_Stand: '..zeit..'_'
end
function dhl:action(msg, config, matches)
local sendungs_id = matches[1]
if string.len(sendungs_id) < 8 then return end
utilities.send_reply(self, msg, dhl:sendungsstatus(sendungs_id), true)
end
return dhl

View File

@ -0,0 +1,39 @@
-- Doesn't use the API for now, maybe we can integrate some cool features?
local dropbox = {}
local https = require('ssl.https')
local json = require('dkjson')
local utilities = require('otouto.utilities')
dropbox.triggers = {
"dropbox.com/s/([a-z0-9]+)/(.*)"
}
function dropbox:action(msg, config, matches)
local folder = matches[1]
local file = string.gsub(matches[2], "?dl=0", "")
local link = 'https://dl.dropboxusercontent.com/s/'..folder..'/'..file
local v,code = https.request(link)
if code == 200 then
if string.ends(link, ".png") or string.ends(link, ".jpeg") or string.ends(link, ".jpg") then
utilities.send_typing(self, msg.chat.id, 'upload_photo')
local file = download_to_file(link)
utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id)
return
elseif string.ends(link, ".webp") or string.ends(link, ".gif") then
utilities.send_typing(self, msg.chat.id, 'upload_photo')
local file = download_to_file(link)
utilities.send_document(self, msg.chat.id, file, nil, msg.message_id)
return
else
utilities.send_reply(self, msg, link)
end
return
else
return
end
end
return dropbox

View File

@ -1,5 +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")()
@ -68,14 +69,15 @@ function plugin_manager:list_plugins()
end
function plugin_manager:reload_plugins(self, config, plugin_name, status)
self.plugins = {}
load_plugins()
for _,v in ipairs(enabled_plugins) do
local p = require('otouto.plugins.'..v)
print('loading plugin',v)
table.insert(self.plugins, p)
if p.init then p.init(self, config) end
end
for pac, _ in pairs(package.loaded) do
if pac:match('^otouto%.plugins%.') then
package.loaded[pac] = nil
end
end
package.loaded['otouto.bindings'] = nil
package.loaded['otouto.utilities'] = nil
package.loaded['config'] = nil
bot.init(self, config)
if plugin_name then
return 'Plugin '..plugin_name..' wurde '..status
else

38
otouto/plugins/vimeo.lua Normal file
View File

@ -0,0 +1,38 @@
local vimeo = {}
local https = require('ssl.https')
local json = require('dkjson')
local utilities = require('otouto.utilities')
vimeo.triggers = {
"vimeo.com/(%d+)"
}
local BASE_URL = 'https://vimeo.com/api/v2'
function vimeo:send_vimeo_data (vimeo_code)
local url = BASE_URL..'/video/'..vimeo_code..'.json'
local res,code = https.request(url)
if code ~= 200 then return "HTTP FEHLER" end
local data = json.decode(res)
local title = '*'..data[1].title..'*'
local uploader = data[1].user_name
local totalseconds = data[1].duration
local duration = makeHumanTime(totalseconds)
if not data[1].stats_number_of_plays then
return title..'\n_(Hochgeladen von: '..uploader..', '..duration..')_'
else
local viewCount = ', '..comma_value(data[1].stats_number_of_plays)..' mal angsehen)' or ""
return title..'\n_(Hochgeladen von: '..uploader..', '..duration..viewCount..'_'
end
end
function vimeo:action(msg, config, matches)
local text = vimeo:send_vimeo_data(matches[1])
if not text then utilities.send_reply(self, msg, config.errors.connection) return end
utilities.send_reply(self, msg, text, true)
end
return vimeo

45
otouto/plugins/vine.lua Normal file
View File

@ -0,0 +1,45 @@
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-_-]+)"
}
local BASE_URL = 'https://vine.co'
function vine:get_vine_data(vine_code)
local res, code = https.request(BASE_URL..'/v/'..vine_code..'/embed/simple')
if code ~= 200 then return nil end
local json_data = string.match(res, '<script type%="application/json" id%="configuration">(.-)</script>')
local data = json.decode(json_data).post
return data
end
function vine:send_vine_data(data)
local title = data.description
local author_name = data.user.username
local creation_date = data.createdPretty
local loops = data.loops.count
local video_url = data.videoUrls[1].videoUrl
local profile_name = string.gsub(data.user.profileUrl, '/', '')
local text = '"'..title..'", hochgeladen von '..author_name..' ('..profile_name..') im '..creation_date..', '..loops..'x angesehen'
if data.explicitContent == 1 then
text = text..' (🔞 NSFW 🔞)'
end
local file = download_to_file(video_url, data.shortId..'.mp4')
return text, file
end
function vine:action(msg, config, matches)
local data = vine:get_vine_data(matches[1])
if not data then utilities.send_reply(self, msg, config.errors.connection) return end
utilities.send_typing(self, msg.chat.id, 'upload_video')
local text, file = vine:send_vine_data(data)
utilities.send_video(self, msg.chat.id, file, text, msg.message_id)
end
return vine