Merge Upstream

This commit is contained in:
Akamaru 2016-11-29 18:28:21 +01:00
commit e49315d035
33 changed files with 1523 additions and 2096 deletions

View File

@ -429,7 +429,7 @@ function create_plugin_set()
'echo', 'echo',
'banhammer', 'banhammer',
'plugins', 'plugins',
'settings', 'respond',
'help' 'help'
} }
print ('Aktiviere Plugins und speicher in telegram:enabled_plugins') print ('Aktiviere Plugins und speicher in telegram:enabled_plugins')

View File

@ -1,62 +1,62 @@
local ninegag = {} local ninegag = {}
ninegag.command = '9gag' ninegag.command = '9gag'
function ninegag:init(config) function ninegag:init(config)
ninegag.triggers = { ninegag.triggers = {
"^/9[Gg][Aa][Gg]$", "^/9[Gg][Aa][Gg]$",
"^/9[Ff][Aa][Gg]$" "^/9[Ff][Aa][Gg]$"
} }
ninegag.inline_triggers = { ninegag.inline_triggers = {
"^9[Gg][Aa][Gg]" "^9[Gg][Aa][Gg]"
} }
ninegag.doc = [[* ninegag.doc = [[*
]]..config.cmd_pat..[[9gag*: Gibt ein zufälliges Bild von den momentan populärsten 9GAG-Posts aus]] ]]..config.cmd_pat..[[9gag*: Gibt ein zufälliges Bild von den momentan populärsten 9GAG-Posts aus]]
end end
local url = "http://api-9gag.herokuapp.com/" local url = "http://api-9gag.herokuapp.com/"
function ninegag:get_9GAG() function ninegag:get_9GAG()
local b,c = http.request(url) local b,c = http.request(url)
if c ~= 200 then return nil end if c ~= 200 then return nil end
local gag = json.decode(b) local gag = json.decode(b)
-- random max json table size -- random max json table size
local i = math.random(#gag) local i = math.random(#gag)
local link_image = gag[i].src local link_image = gag[i].src
local title = gag[i].title local title = gag[i].title
local post_url = gag[i].url local post_url = gag[i].url
return link_image, title, post_url return link_image, title, post_url
end end
function ninegag:inline_callback(inline_query, config) function ninegag:inline_callback(inline_query, config)
local res, code = http.request(url) local res, code = http.request(url)
if code ~= 200 then abort_inline_query(inline_query) return end if code ~= 200 then abort_inline_query(inline_query) return end
local gag = json.decode(res) local gag = json.decode(res)
local results = '[' local results = '['
local id = 50 local id = 50
for n in pairs(gag) do for n in pairs(gag) do
local title = gag[n].title:gsub('"', '\\"') local title = gag[n].title:gsub('"', '\\"')
results = results..'{"type":"photo","id":"'..id..'","photo_url":"'..gag[n].src..'","thumb_url":"'..gag[n].src..'","caption":"'..title..'","reply_markup":{"inline_keyboard":[[{"text":"9GAG aufrufen","url":"'..gag[n].url..'"}]]}}' results = results..'{"type":"photo","id":"'..id..'","photo_url":"'..gag[n].src..'","thumb_url":"'..gag[n].src..'","caption":"'..title..'","reply_markup":{"inline_keyboard":[[{"text":"9GAG aufrufen","url":"'..gag[n].url..'"}]]}}'
id = id+1 id = id+1
if n < #gag then if n < #gag then
results = results..',' results = results..','
end end
end end
local results = results..']' local results = results..']'
utilities.answer_inline_query(inline_query, results, 300) utilities.answer_inline_query(inline_query, results, 300)
end end
function ninegag:action(msg, config) function ninegag:action(msg, config)
utilities.send_typing(msg.chat.id, 'upload_photo') utilities.send_typing(msg.chat.id, 'upload_photo')
local url, title, post_url = ninegag:get_9GAG() local url, title, post_url = ninegag:get_9GAG()
if not url then if not url then
utilities.send_reply(msg, config.errors.connection) utilities.send_reply(msg, config.errors.connection)
return return
end end
utilities.send_photo(msg.chat.id, url, title, msg.message_id, '{"inline_keyboard":[[{"text":"Post aufrufen","url":"'..post_url..'"}]]}') utilities.send_photo(msg.chat.id, url, title, msg.message_id, '{"inline_keyboard":[[{"text":"Post aufrufen","url":"'..post_url..'"}]]}')
end end
return ninegag return ninegag

View File

@ -1,124 +1,124 @@
-- original plugin by Akamaru [https://ponywave.de] -- original plugin by Akamaru [https://ponywave.de]
-- I added Redis and automatic online switching back in 2015 -- I added Redis and automatic online switching back in 2015
local afk = {} local afk = {}
function afk:init(config) function afk:init(config)
afk.triggers = { afk.triggers = {
"^/([Aa][Ff][Kk])$", "^/([Aa][Ff][Kk])$",
"^/([Aa][Ff][Kk]) (.*)$" "^/([Aa][Ff][Kk]) (.*)$"
} }
afk.doc = [[* afk.doc = [[*
]]..config.cmd_pat..[[afk* _[Text]_: Setzt Status auf AFK mit optionalem Text]] ]]..config.cmd_pat..[[afk* _[Text]_: Setzt Status auf AFK mit optionalem Text]]
end end
afk.command = 'afk [Text]' afk.command = 'afk [Text]'
function afk:is_offline(hash) function afk:is_offline(hash)
local afk = redis:hget(hash, 'afk') local afk = redis:hget(hash, 'afk')
if afk == "true" then if afk == "true" then
return true return true
else else
return false return false
end end
end end
function afk:get_afk_text(hash) function afk:get_afk_text(hash)
local afk_text = redis:hget(hash, 'afk_text') local afk_text = redis:hget(hash, 'afk_text')
if afk_text ~= nil and afk_text ~= "" and afk_text ~= "false" then if afk_text ~= nil and afk_text ~= "" and afk_text ~= "false" then
return afk_text return afk_text
else else
return false return false
end end
end end
function afk:switch_afk(user_name, user_id, chat_id, timestamp, text) function afk:switch_afk(user_name, user_id, chat_id, timestamp, text)
local hash = 'afk:'..chat_id..':'..user_id local hash = 'afk:'..chat_id..':'..user_id
if afk:is_offline(hash) then if afk:is_offline(hash) then
local afk_text = afk:get_afk_text(hash) local afk_text = afk:get_afk_text(hash)
if afk_text then if afk_text then
return 'Du bist bereits AFK! ('..afk_text..')' return 'Du bist bereits AFK! ('..afk_text..')'
else else
return 'Du bist bereits AFK!' return 'Du bist bereits AFK!'
end end
end end
print('Setting redis hash afk in '..hash..' to true') print('Setting redis hash afk in '..hash..' to true')
redis:hset(hash, 'afk', true) redis:hset(hash, 'afk', true)
print('Setting redis hash timestamp in '..hash..' to '..timestamp) print('Setting redis hash timestamp in '..hash..' to '..timestamp)
redis:hset(hash, 'time', timestamp) redis:hset(hash, 'time', timestamp)
if text then if text then
print('Setting redis hash afk_text in '..hash..' to '..text) print('Setting redis hash afk_text in '..hash..' to '..text)
redis:hset(hash, 'afk_text', text) redis:hset(hash, 'afk_text', text)
return user_name..' ist AFK! ('..text..')' return user_name..' ist AFK! ('..text..')'
else else
return user_name..' ist AFK!' return user_name..' ist AFK!'
end end
end end
function afk:pre_process(msg) function afk:pre_process(msg)
if msg.chat.type == "private" then if msg.chat.type == "private" then
-- Ignore -- Ignore
return msg return msg
end end
local user_name = get_name(msg) local user_name = get_name(msg)
local user_id = msg.from.id local user_id = msg.from.id
local chat_id = msg.chat.id local chat_id = msg.chat.id
local hash = 'afk:'..chat_id..':'..user_id local hash = 'afk:'..chat_id..':'..user_id
local uhash = 'user:'..user_id local uhash = 'user:'..user_id
if afk:is_offline(hash) then if afk:is_offline(hash) then
local afk_text = afk:get_afk_text(hash) local afk_text = afk:get_afk_text(hash)
-- calculate afk time -- calculate afk time
local timestamp = redis:hget(hash, 'time') local timestamp = redis:hget(hash, 'time')
local current_timestamp = msg.date local current_timestamp = msg.date
local afk_time = current_timestamp - timestamp local afk_time = current_timestamp - timestamp
local duration = makeHumanTime(afk_time) local duration = makeHumanTime(afk_time)
redis:hset(hash, 'afk', false) redis:hset(hash, 'afk', false)
local show_afk_keyboard = redis:hget(uhash, 'afk_keyboard') local show_afk_keyboard = redis:hget(uhash, 'afk_keyboard')
if afk_text then if afk_text then
redis:hset(hash, 'afk_text', false) redis:hset(hash, 'afk_text', false)
if show_afk_keyboard == 'true' then if show_afk_keyboard == 'true' then
utilities.send_reply(msg, user_name..' ist wieder da! (war: <b>'..afk_text..'</b> für '..duration..')', 'HTML', '{"hide_keyboard":true,"selective":true}') utilities.send_reply(msg, user_name..' ist wieder da! (war: <b>'..afk_text..'</b> für '..duration..')', 'HTML', '{"hide_keyboard":true,"selective":true}')
else else
utilities.send_message(chat_id, user_name..' ist wieder da! (war: <b>'..afk_text..'</b> für '..duration..')', true, nil, 'HTML') utilities.send_message(chat_id, user_name..' ist wieder da! (war: <b>'..afk_text..'</b> für '..duration..')', true, nil, 'HTML')
end end
else else
if show_afk_keyboard == 'true' then if show_afk_keyboard == 'true' then
utilities.send_reply(msg, user_name..' ist wieder da! (war '..duration..' weg)', nil, '{"hide_keyboard":true,"selective":true}') utilities.send_reply(msg, user_name..' ist wieder da! (war '..duration..' weg)', nil, '{"hide_keyboard":true,"selective":true}')
else else
utilities.send_message(chat_id, user_name..' ist wieder da! (war '..duration..' weg)') utilities.send_message(chat_id, user_name..' ist wieder da! (war '..duration..' weg)')
end end
end end
end end
return msg return msg
end end
function afk:action(msg, config, matches) function afk:action(msg, config, matches)
if msg.chat.type == "private" then if msg.chat.type == "private" then
utilities.send_reply(msg, "Mir ist's egal, ob du AFK bist.") utilities.send_reply(msg, "Mir ist's egal, ob du AFK bist.")
return return
end end
local user_id = msg.from.id local user_id = msg.from.id
local chat_id = msg.chat.id local chat_id = msg.chat.id
local user_name = get_name(msg) local user_name = get_name(msg)
local timestamp = msg.date local timestamp = msg.date
local uhash = 'user:'..msg.from.id local uhash = 'user:'..msg.from.id
local show_afk_keyboard = redis:hget(uhash, 'afk_keyboard') local show_afk_keyboard = redis:hget(uhash, 'afk_keyboard')
if show_afk_keyboard == 'true' then if show_afk_keyboard == 'true' then
keyboard = '{"keyboard":[[{"text":"Wieder da."}]], "one_time_keyboard":true, "selective":true, "resize_keyboard":true}' keyboard = '{"keyboard":[[{"text":"Wieder da."}]], "one_time_keyboard":true, "selective":true, "resize_keyboard":true}'
else else
keyboard = nil keyboard = nil
end end
utilities.send_reply(msg, afk:switch_afk(user_name, user_id, chat_id, timestamp, matches[2]), false, keyboard) utilities.send_reply(msg, afk:switch_afk(user_name, user_id, chat_id, timestamp, matches[2]), false, keyboard)
end end
return afk return afk

View File

@ -1,137 +0,0 @@
local bitly_create = {}
function bitly_create:init(config)
if not cred_data.bitly_client_id then
print('Fehlender Key: bitly_client_id.')
print('bitly_create.lua wird nicht aktiviert.')
return
elseif not cred_data.bitly_client_secret then
print('Fehlender Key: bitly_client_secret.')
print('bitly_create.lua wird nicht aktiviert.')
return
elseif not cred_data.bitly_redirect_uri then
print('Fehlender Key: bitly_redirect_uri.')
print('bitly_create.lua wird nicht aktiviert.')
return
end
bitly_create.triggers = {
"^/[Ss][Hh][Oo][Rr][Tt](auth)(.+)$",
"^/[Ss][Hh][Oo][Rr][Tt] (auth)$",
"^/[Ss][Hh][Oo][Rr][Tt] (unauth)$",
"^/[Ss][Hh][Oo][Rr][Tt] (me)$",
"^/[Ss][Hh][Oo][Rr][Tt] (j.mp) (https?://[%w-_%.%?%.:/%+=&]+)$",
"^/[Ss][Hh][Oo][Rr][Tt] (bit.ly) (https?://[%w-_%.%?%.:/%+=&]+)$",
"^/[Ss][Hh][Oo][Rr][Tt] (bitly.com) (https?://[%w-_%.%?%.:/%+=&]+)$",
"^/[Ss][Hh][Oo][Rr][Tt] (https?://[%w-_%.%?%.:/%+=&]+)$"
}
bitly_create.doc = [[*
]]..config.cmd_pat..[[short* _<Link>_: Kürzt einen Link mit der Standard Bitly-Adresse
*]]..config.cmd_pat..[[short* _<j.mp|bit.ly|bitly.com>_ _[Link]_: Kürzt einen Link mit der ausgewählten Kurz-URL
*]]..config.cmd_pat..[[short* _auth_: Loggt deinen Account ein und nutzt ihn für deine Links (empfohlen!)
*]]..config.cmd_pat..[[short* _me_: Gibt den eingeloggten Account aus
*]]..config.cmd_pat..[[short* _unauth_: Loggt deinen Account aus
]]
end
bitly_create.command = 'short <URL>'
local BASE_URL = 'https://api-ssl.bitly.com'
local client_id = cred_data.bitly_client_id
local client_secret = cred_data.bitly_client_secret
local redirect_uri = cred_data.bitly_redirect_uri
function bitly_create:get_bitly_access_token(hash, code)
local req = post_petition(BASE_URL..'/oauth/access_token', 'client_id='..client_id..'&client_secret='..client_secret..'&code='..code..'&redirect_uri='..redirect_uri)
if not req.access_token then return '*Fehler beim Einloggen!*' end
local access_token = req.access_token
local login_name = req.login
redis:hset(hash, 'bitly', access_token)
return 'Erfolgreich als `'..login_name..'` eingeloggt!'
end
function bitly_create:get_bitly_user_info(bitly_access_token)
local url = BASE_URL..'/v3/user/info?access_token='..bitly_access_token..'&format=json'
local res,code = https.request(url)
if code == 401 then return 'Login fehlgeschlagen!' end
if code ~= 200 then return 'HTTP-Fehler!' end
local data = json.decode(res).data
if data.full_name then
name = '*'..data.full_name..'* (`'..data.login..'`)'
else
name = '`'..data.login..'`'
end
local text = 'Eingeloggt als '..name
return text
end
function bitly_create:create_bitlink (long_url, domain, bitly_access_atoken)
local url = BASE_URL..'/v3/shorten?access_token='..bitly_access_token..'&domain='..domain..'&longUrl='..long_url..'&format=txt'
local text,code = https.request(url)
if code ~= 200 then return 'FEHLER: '..text end
return text
end
function bitly_create:action(msg, config, matches)
local hash = 'user:'..msg.from.id
bitly_access_token = redis:hget(hash, 'bitly')
if matches[1] == 'auth' and matches[2] then
utilities.send_reply(msg, bitly_create:get_bitly_access_token(hash, matches[2]), true)
local message_id = redis:hget(hash, 'bitly_login_msg')
utilities.edit_message(msg.chat.id, message_id, '*Anmeldung abgeschlossen!*', true, true)
redis:hdel(hash, 'bitly_login_msg')
return
end
if matches[1] == 'auth' then
local result = utilities.send_reply(msg, '*Bitte logge dich ein und folge den Anweisungen.*', true, '{"inline_keyboard":[[{"text":"Bei Bitly anmelden","url":"https://bitly.com/oauth/authorize?client_id='..client_id..'&redirect_uri='..redirect_uri..'&state='..self.info.username..'"}]]}')
redis:hset(hash, 'bitly_login_msg', result.result.message_id)
return
end
if matches[1] == 'unauth' and bitly_access_token then
redis:hdel(hash, 'bitly')
utilities.send_reply(msg, '*Erfolgreich ausgeloggt!* Du kannst den Zugriff [in deinen Kontoeinstellungen](https://bitly.com/a/settings/connected) endgültig entziehen.', true)
return
elseif matches[1] == 'unauth' and not bitly_access_token then
utilities.send_reply(msg, 'Wie willst du dich ausloggen, wenn du gar nicht eingeloggt bist?', true)
return
end
if matches[1] == 'me' and bitly_access_token then
local text = bitly_create:get_bitly_user_info(bitly_access_token)
if text then
utilities.send_reply(msg, text, true)
return
else
return
end
elseif matches[1] == 'me' and not bitly_access_token then
utilities.send_reply(msg, 'Du bist nicht eingeloggt! Logge dich ein mit\n/short auth', true)
return
end
if not bitly_access_token then
print('Not signed in, will use global bitly access_token')
bitly_access_token = cred_data.bitly_access_token
end
if matches[2] == nil then
long_url = URL.encode(matches[1])
domain = 'bit.ly'
else
long_url = URL.encode(matches[2])
domain = matches[1]
end
utilities.send_reply(msg, bitly_create:create_bitlink(long_url, domain, bitly_access_token))
return
end
return bitly_create

View File

@ -1,34 +0,0 @@
local btc = {}
function btc:init(config)
btc.triggers = {
"^/[Bb][Tt][Cc]$"
}
btc.doc = [[*
]]..config.cmd_pat..[[btc*: Zeigt aktuellen Bitcoin-Kurs an]]
end
btc.command = 'btc'
-- See https://bitcoinaverage.com/api
function btc:getBTCX()
local base_url = 'https://api.bitcoinaverage.com/ticker/global/'
-- Do request on bitcoinaverage, the final / is critical!
local res,code = https.request(base_url.."EUR/")
if code ~= 200 then return nil end
local data = json.decode(res)
local ask = string.gsub(data.ask, "%.", ",")
local bid = string.gsub(data.bid, "%.", ",")
-- Easy, it's right there
text = 'BTC/EUR\n'..'*Kaufen:* '..ask..'\n'..'*Verkaufen:* '..bid
return text
end
function btc:action(msg, config, matches)
utilities.send_reply(msg, btc:getBTCX(cur), true)
end
return btc

View File

@ -1,112 +1,112 @@
local cats = {} local cats = {}
cats.command = 'kitty [gif]' cats.command = 'kitty [gif]'
function cats:init(config) function cats:init(config)
if not cred_data.cat_apikey then if not cred_data.cat_apikey then
print('Fehlender Key: cat_apikey.') print('Fehlender Key: cat_apikey.')
print('cats.lua wird aktiviert, aber mit einem Key gibt es mehr Features.') print('cats.lua wird aktiviert, aber mit einem Key gibt es mehr Features.')
end end
cats.triggers = { cats.triggers = {
"^/[Kk][Ii][Tt][Tt][Yy]$", "^/[Kk][Ii][Tt][Tt][Yy]$",
"^/[Kk][Ii][Tt][Tt][Yy] (gif)$" "^/[Kk][Ii][Tt][Tt][Yy] (gif)$"
} }
cats.inline_triggers = { cats.inline_triggers = {
"^[Kk][Ii][Tt][Tt][Yy] (gif)$", "^[Kk][Ii][Tt][Tt][Yy] (gif)$",
"^[Kk][Ii][Tt][Tt][Yy]$" "^[Kk][Ii][Tt][Tt][Yy]$"
} }
cats.doc = [[* cats.doc = [[*
]]..config.cmd_pat..[[kitty*: Postet eine zufällige Katze ]]..config.cmd_pat..[[kitty*: Postet eine zufällige Katze
*]]..config.cmd_pat..[[kitty* _gif_: Postet eine zufällige, animierte Katze]] *]]..config.cmd_pat..[[kitty* _gif_: Postet eine zufällige, animierte Katze]]
end end
local apikey = cred_data.cat_apikey or "" -- apply for one here: http://thecatapi.com/api-key-registration.html local apikey = cred_data.cat_apikey or "" -- apply for one here: http://thecatapi.com/api-key-registration.html
local BASE_URL = 'http://thecatapi.com/api/images/get' local BASE_URL = 'http://thecatapi.com/api/images/get'
function cats:inline_callback(inline_query, config, matches) function cats:inline_callback(inline_query, config, matches)
if matches[1] == 'gif' then if matches[1] == 'gif' then
img_type = 'gif' img_type = 'gif'
id = 100 id = 100
else else
img_type = 'jpg' img_type = 'jpg'
id = 200 id = 200
end end
local url = 'https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%3D%27http%3A%2F%2Fthecatapi.com%2Fapi%2Fimages%2Fget%3Fformat%3Dxml%26results_per_page%3D50%26type%3D'..img_type..'%26apikey%3D'..apikey..'%27&format=json' -- no way I'm using XML, plz die local url = 'https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20xml%20where%20url%3D%27http%3A%2F%2Fthecatapi.com%2Fapi%2Fimages%2Fget%3Fformat%3Dxml%26results_per_page%3D50%26type%3D'..img_type..'%26apikey%3D'..apikey..'%27&format=json' -- no way I'm using XML, plz die
local res, code = https.request(url) local res, code = https.request(url)
if code ~= 200 then return end if code ~= 200 then return end
local data = json.decode(res).query.results.response.data.images.image local data = json.decode(res).query.results.response.data.images.image
if not data then return end if not data then return end
if not data[1] then return end if not data[1] then return end
local results = '[' local results = '['
for n in pairs(data) do for n in pairs(data) do
if img_type == 'gif' then if img_type == 'gif' then
results = results..'{"type":"gif","id":"'..id..'","gif_url":"'..data[n].url..'","thumb_url":"'..data[n].url..'"}' results = results..'{"type":"gif","id":"'..id..'","gif_url":"'..data[n].url..'","thumb_url":"'..data[n].url..'"}'
id = id+1 id = id+1
else else
results = results..'{"type":"photo","id":"'..id..'","photo_url":"'..data[n].url..'","thumb_url":"'..data[n].url..'"}' results = results..'{"type":"photo","id":"'..id..'","photo_url":"'..data[n].url..'","thumb_url":"'..data[n].url..'"}'
id = id+1 id = id+1
end end
if n < #data then if n < #data then
results = results..',' results = results..','
end end
end end
local results = results..']' local results = results..']'
utilities.answer_inline_query(inline_query, results, 30) utilities.answer_inline_query(inline_query, results, 30)
end end
function cats:get_cat(gif) function cats:get_cat(gif)
if gif then if gif then
local url = BASE_URL..'?type=gif&apikey='..apikey local url = BASE_URL..'?type=gif&apikey='..apikey
file = download_to_file(url, 'miau.gif') file = download_to_file(url, 'miau.gif')
else else
local url = BASE_URL..'?type=jpg,png&apikey='..apikey local url = BASE_URL..'?type=jpg,png&apikey='..apikey
file = download_to_file(url, 'miau.png') file = download_to_file(url, 'miau.png')
end end
return file return file
end end
function cats:callback(callback, msg, self, config, input) function cats:callback(callback, msg, self, config, input)
utilities.answer_callback_query(callback, 'Miau!') utilities.answer_callback_query(callback, 'Miau!')
utilities.send_typing(msg.chat.id, 'upload_photo') utilities.send_typing(msg.chat.id, 'upload_photo')
if string.isempty(input) then if string.isempty(input) then
local file = cats:get_cat() local file = cats:get_cat()
if not file then if not file then
utilities.answer_callback_query(callback, 'Beim Herunterladen ist ein Fehler aufgetreten :(', true) utilities.answer_callback_query(callback, 'Beim Herunterladen ist ein Fehler aufgetreten :(', true)
return return
end end
utilities.send_photo(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Nochmal!","callback_data":"cats:"}]]}') utilities.send_photo(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Nochmal!","callback_data":"cats:"}]]}')
else else
local file = cats:get_cat(true) local file = cats:get_cat(true)
if not file then if not file then
utilities.answer_callback_query(callback, 'Beim Herunterladen ist ein Fehler aufgetreten :(', true) utilities.answer_callback_query(callback, 'Beim Herunterladen ist ein Fehler aufgetreten :(', true)
return return
end end
utilities.send_document(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Nochmal!","callback_data":"cats:gif"}]]}') utilities.send_document(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Nochmal!","callback_data":"cats:gif"}]]}')
end end
end end
function cats:action(msg, config, matches) function cats:action(msg, config, matches)
utilities.send_typing(msg.chat.id, 'upload_photo') utilities.send_typing(msg.chat.id, 'upload_photo')
if matches[1] == 'gif' then if matches[1] == 'gif' then
local file = cats:get_cat(true) local file = cats:get_cat(true)
if not file then if not file then
utilities.send_reply(msg, config.errors.connection) utilities.send_reply(msg, config.errors.connection)
return return
end end
utilities.send_document(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Nochmal!","callback_data":"cats:gif"}]]}') utilities.send_document(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Nochmal!","callback_data":"cats:gif"}]]}')
else else
local file = cats:get_cat() local file = cats:get_cat()
if not file then if not file then
utilities.send_reply(msg, config.errors.connection) utilities.send_reply(msg, config.errors.connection)
return return
end end
utilities.send_photo(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Nochmal!","callback_data":"cats:"}]]}') utilities.send_photo(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Nochmal!","callback_data":"cats:"}]]}')
end end
end end
return cats return cats

View File

@ -1,28 +0,0 @@
local clypit = {}
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(msg.chat.id, 'upload_audio')
local audio, title, duration = clypit:get_clypit_details(matches[1])
if not audio then return utilities.send_reply(msg, config.errors.connection) end
utilities.send_audio(msg.chat.id, audio, nil, msg.message_id, duration, nil, title)
end
return clypit

View File

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

View File

@ -1,34 +0,0 @@
local dhl = {}
function dhl:init(config)
dhl.triggers = {
'/[Dd][Hh][Ll] (%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 = utilities.trim(status)
local zeit = string.match(res, "<div id%=\"detailStatusDateTime\">(.-)</div>")
local zeit = utilities.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(msg, dhl:sendungsstatus(sendungs_id), true)
end
return dhl

View File

@ -1,73 +1,73 @@
local flickr_search = {} local flickr_search = {}
function flickr_search:init(config) function flickr_search:init(config)
if not cred_data.flickr_apikey then if not cred_data.flickr_apikey then
print('Fehlender Key: flickr_apikey.') print('Fehlender Key: flickr_apikey.')
print('flickr_search.lua wird nicht aktiviert.') print('flickr_search.lua wird nicht aktiviert.')
return return
end end
flickr_search.triggers = { flickr_search.triggers = {
'^/[Ff][Ll][Ii][Cc][Kk][Rr] (.*)' '^/[Ff][Ll][Ii][Cc][Kk][Rr] (.*)'
} }
end end
flickr_search.command = 'flickr <Suchbegriff>' flickr_search.command = 'flickr <Suchbegriff>'
local apikey = cred_data.flickr_apikey local apikey = cred_data.flickr_apikey
local BASE_URL = 'https://api.flickr.com/services/rest' local BASE_URL = 'https://api.flickr.com/services/rest'
function flickr_search:get_flickr(term) function flickr_search:get_flickr(term)
local url = BASE_URL..'/?method=flickr.photos.search&api_key='..apikey..'&format=json&nojsoncallback=1&privacy_filter=1&safe_search=3&media=photos&sort=relevance&is_common=true&per_page=20&extras=url_l,url_o&text='..term local url = BASE_URL..'/?method=flickr.photos.search&api_key='..apikey..'&format=json&nojsoncallback=1&privacy_filter=1&safe_search=3&media=photos&sort=relevance&is_common=true&per_page=20&extras=url_l,url_o&text='..term
local b,c = https.request(url) local b,c = https.request(url)
if c ~= 200 then return nil end if c ~= 200 then return nil end
local photo = json.decode(b).photos.photo local photo = json.decode(b).photos.photo
if not photo[1] then return nil end if not photo[1] then return nil end
-- truly randomize -- truly randomize
math.randomseed(os.time()) math.randomseed(os.time())
-- random max json table size -- random max json table size
local i = math.random(#photo) local i = math.random(#photo)
local link_image = photo[i].url_l or photo[i].url_o local link_image = photo[i].url_l or photo[i].url_o
local orig_image = photo[i].url_o or link_image local orig_image = photo[i].url_o or link_image
local title = photo[i].title local title = photo[i].title
if title:len() > 200 then if title:len() > 200 then
title = title:sub(1, 197) .. '...' title = title:sub(1, 197) .. '...'
end end
return link_image, title, orig_image return link_image, title, orig_image
end end
function flickr_search:callback(callback, msg, self, config, input) function flickr_search:callback(callback, msg, self, config, input)
utilities.send_typing(msg.chat.id, 'upload_photo') utilities.send_typing(msg.chat.id, 'upload_photo')
local input = URL.unescape(input) local input = URL.unescape(input)
utilities.answer_callback_query(callback, 'Suche nochmal nach "'..input..'"') utilities.answer_callback_query(callback, 'Suche nochmal nach "'..input..'"')
local url, title, orig = flickr_search:get_flickr(input) local url, title, orig = flickr_search:get_flickr(input)
if not url then utilities.answer_callback_query(callback, 'Konnte nicht mit Flickr verbinden :(', true) return end if not url then utilities.answer_callback_query(callback, 'Konnte nicht mit Flickr verbinden :(', true) return end
if string.ends(url, ".gif") then if string.ends(url, ".gif") then
utilities.send_document(msg.chat.id, url, title, msg.message_id, '{"inline_keyboard":[[{"text":"Im Browser öffnen","url":"'..orig..'"},{"text":"Nochmal suchen","callback_data":"flickr_search:'..URL.escape(input)..'"}]]}') utilities.send_document(msg.chat.id, url, title, msg.message_id, '{"inline_keyboard":[[{"text":"Im Browser öffnen","url":"'..orig..'"},{"text":"Nochmal suchen","callback_data":"flickr_search:'..URL.escape(input)..'"}]]}')
return return
else else
utilities.send_photo(msg.chat.id, url, title, msg.message_id, '{"inline_keyboard":[[{"text":"Bild öffnen","url":"'..orig..'"}, {"text":"Nochmal suchen","callback_data":"flickr_search:'..URL.escape(input)..'"}]]}') utilities.send_photo(msg.chat.id, url, title, msg.message_id, '{"inline_keyboard":[[{"text":"Bild öffnen","url":"'..orig..'"}, {"text":"Nochmal suchen","callback_data":"flickr_search:'..URL.escape(input)..'"}]]}')
return return
end end
end end
function flickr_search:action(msg, config, matches) function flickr_search:action(msg, config, matches)
utilities.send_typing(msg.chat.id, 'upload_photo') utilities.send_typing(msg.chat.id, 'upload_photo')
local url, title, orig = flickr_search:get_flickr(matches[1]) local url, title, orig = flickr_search:get_flickr(matches[1])
if not url then utilities.send_reply(msg, config.errors.results) return end if not url then utilities.send_reply(msg, config.errors.results) return end
if string.ends(url, ".gif") then if string.ends(url, ".gif") then
utilities.send_document(msg.chat.id, url, title, msg.message_id, '{"inline_keyboard":[[{"text":"Im Browser öffnen","url":"'..orig..'"},{"text":"Nochmal suchen","callback_data":"flickr_search:'..URL.escape(matches[1])..'"}]]}') utilities.send_document(msg.chat.id, url, title, msg.message_id, '{"inline_keyboard":[[{"text":"Im Browser öffnen","url":"'..orig..'"},{"text":"Nochmal suchen","callback_data":"flickr_search:'..URL.escape(matches[1])..'"}]]}')
return return
else else
utilities.send_photo(msg.chat.id, url, title, msg.message_id, '{"inline_keyboard":[[{"text":"Bild öffnen","url":"'..orig..'"}, {"text":"Nochmal suchen","callback_data":"flickr_search:'..URL.escape(matches[1])..'"}]]}') utilities.send_photo(msg.chat.id, url, title, msg.message_id, '{"inline_keyboard":[[{"text":"Bild öffnen","url":"'..orig..'"}, {"text":"Nochmal suchen","callback_data":"flickr_search:'..URL.escape(matches[1])..'"}]]}')
return return
end end
end end
return flickr_search return flickr_search

View File

@ -1,144 +1,144 @@
local games = {} local games = {}
local xml = require("xml") local xml = require("xml")
games.command = 'game <Spiel>' games.command = 'game <Spiel>'
function games:init(config) function games:init(config)
games.triggers = { games.triggers = {
"^/[Gg][Aa][Mm][Ee] (.+)$" "^/[Gg][Aa][Mm][Ee] (.+)$"
} }
games.doc = [[* games.doc = [[*
]]..config.cmd_pat..[[game*_ <Spiel>_: Sendet Infos zum Spiel]] ]]..config.cmd_pat..[[game*_ <Spiel>_: Sendet Infos zum Spiel]]
end end
local BASE_URL = 'http://thegamesdb.net/api' local BASE_URL = 'http://thegamesdb.net/api'
local makeOurDate = function(dateString) local makeOurDate = function(dateString)
local pattern = "(%d+)%/(%d+)%/(%d+)" local pattern = "(%d+)%/(%d+)%/(%d+)"
local month, day, year = dateString:match(pattern) local month, day, year = dateString:match(pattern)
return day..'.'..month..'.'..year return day..'.'..month..'.'..year
end end
function games:get_game_id(game) function games:get_game_id(game)
local url = BASE_URL..'/GetGamesList.php?name='..game local url = BASE_URL..'/GetGamesList.php?name='..game
local res,code = http.request(url) local res,code = http.request(url)
if code ~= 200 then return "HTTP-FEHLER" end if code ~= 200 then return "HTTP-FEHLER" end
local result = xml.load(res) local result = xml.load(res)
if xml.find(result, 'id') then if xml.find(result, 'id') then
local game = xml.find(result, 'id')[1] local game = xml.find(result, 'id')[1]
return game return game
else else
return nil return nil
end end
end end
function games:send_game_photo(result, self, msg) function games:send_game_photo(result, self, msg)
local BASE_URL = xml.find(result, 'baseImgUrl')[1] local BASE_URL = xml.find(result, 'baseImgUrl')[1]
local images = {} local images = {}
if xml.find(result, 'boxart', 'side', 'front') then if xml.find(result, 'boxart', 'side', 'front') then
local boxart = xml.find(result, 'boxart', 'side', 'front')[1] local boxart = xml.find(result, 'boxart', 'side', 'front')[1]
local boxart_url = BASE_URL..boxart local boxart_url = BASE_URL..boxart
table.insert(images, boxart_url) table.insert(images, boxart_url)
end end
local i = 0 local i = 0
for k, v in pairs(images) do for k, v in pairs(images) do
i = i+1 i = i+1
utilities.send_photo(msg.chat.id, v, nil, msg.message_id) utilities.send_photo(msg.chat.id, v, nil, msg.message_id)
end end
end end
function games:send_game_data(game_id, self, msg) function games:send_game_data(game_id, self, msg)
local url = BASE_URL..'/GetGame.php?id='..game_id local url = BASE_URL..'/GetGame.php?id='..game_id
local res,code = http.request(url) local res,code = http.request(url)
if code ~= 200 then return nil end if code ~= 200 then return nil end
local result = xml.load(res) local result = xml.load(res)
local title = xml.find(result, 'GameTitle')[1] local title = xml.find(result, 'GameTitle')[1]
local platform = xml.find(result, 'Platform')[1] local platform = xml.find(result, 'Platform')[1]
if xml.find(result, 'ReleaseDate') then if xml.find(result, 'ReleaseDate') then
date = ', erschienen am '..makeOurDate(xml.find(result, 'ReleaseDate')[1]) date = ', erschienen am '..makeOurDate(xml.find(result, 'ReleaseDate')[1])
else else
date = '' date = ''
end end
if xml.find(result, 'Overview') then if xml.find(result, 'Overview') then
desc = '\n_'..string.sub(xml.find(result, 'Overview')[1], 1, 200) .. '..._' desc = '\n_'..string.sub(xml.find(result, 'Overview')[1], 1, 200) .. '..._'
else else
desc = '' desc = ''
end end
if xml.find(result, 'Genres') then if xml.find(result, 'Genres') then
local genres = xml.find(result, 'Genres') local genres = xml.find(result, 'Genres')
local genre_count = #genres-1 local genre_count = #genres-1
if genre_count == 1 then if genre_count == 1 then
genre = '\nGenre: '..genres[1][1] genre = '\nGenre: '..genres[1][1]
else else
local genre_loop = '\nGenres: ' local genre_loop = '\nGenres: '
for v in pairs(genres) do for v in pairs(genres) do
if v == 'xml' then break; end if v == 'xml' then break; end
if v < genre_count then if v < genre_count then
genre_loop = genre_loop..genres[v][1]..', ' genre_loop = genre_loop..genres[v][1]..', '
else else
genre_loop = genre_loop..genres[v][1] genre_loop = genre_loop..genres[v][1]
end end
end end
genre = genre_loop genre = genre_loop
end end
else else
genre = '' genre = ''
end end
if xml.find(result, 'Players') then if xml.find(result, 'Players') then
players = '\nSpieler: '..xml.find(result, 'Players')[1] players = '\nSpieler: '..xml.find(result, 'Players')[1]
else else
players = '' players = ''
end end
if xml.find(result, 'Youtube') then if xml.find(result, 'Youtube') then
video = '\n[Video auf YouTube ansehen]('..xml.find(result, 'Youtube')[1]..')' video = '\n[Video auf YouTube ansehen]('..xml.find(result, 'Youtube')[1]..')'
else else
video = '' video = ''
end end
if xml.find(result, 'Publisher') then if xml.find(result, 'Publisher') then
publisher = '\nPublisher: '..xml.find(result, 'Publisher')[1] publisher = '\nPublisher: '..xml.find(result, 'Publisher')[1]
else else
publisher = '' publisher = ''
end end
local text = '*'..title..'* für *'..platform..'*'..date..desc..genre..players..video..publisher local text = '*'..title..'* für *'..platform..'*'..date..desc..genre..players..video..publisher
utilities.send_reply(msg, text, true) utilities.send_reply(msg, text, true)
if xml.find(result, 'boxart') then if xml.find(result, 'boxart') then
utilities.send_typing(msg.chat.id, 'upload_photo') utilities.send_typing(msg.chat.id, 'upload_photo')
games:send_game_photo(result, self, msg) games:send_game_photo(result, self, msg)
end end
return return
end end
function games:action(msg, config) function games:action(msg, config)
local game = utilities.input(msg.text) local game = utilities.input(msg.text)
if not game then if not game then
if msg.reply_to_message and msg.reply_to_message.text then if msg.reply_to_message and msg.reply_to_message.text then
game = msg.reply_to_message.text game = msg.reply_to_message.text
else else
utilities.send_message(msg.chat.id, fun.doc, true, msg.message_id, true) utilities.send_message(msg.chat.id, fun.doc, true, msg.message_id, true)
return return
end end
end end
local game_id = games:get_game_id(game) local game_id = games:get_game_id(game)
if not game_id then if not game_id then
utilities.send_reply(msg, 'Spiel nicht gefunden!') utilities.send_reply(msg, 'Spiel nicht gefunden!')
return return
else else
games:send_game_data(game_id, self, msg) games:send_game_data(game_id, self, msg)
end end
end end
return games return games

View File

@ -1,56 +1,56 @@
local get = {} local get = {}
get.command = 'get <Variable>' get.command = 'get <Variable>'
function get:init(config) function get:init(config)
get.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('[Gg][Ee][Tt]', true).table get.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('[Gg][Ee][Tt]', true).table
get.doc = [[* get.doc = [[*
]]..config.cmd_pat..[[get*: Gibt alle Variablen aus ]]..config.cmd_pat..[[get*: Gibt alle Variablen aus
*]]..config.cmd_pat..[[get* _<Variable>_: Gibt _Variable_ aus *]]..config.cmd_pat..[[get* _<Variable>_: Gibt _Variable_ aus
Nutze `/set <Variable> <Wert>` zum Setzen von Variablen]] Nutze `/set <Variable> <Wert>` zum Setzen von Variablen]]
end end
function get:get_value(msg, var_name) function get:get_value(msg, var_name)
local hash = get_redis_hash(msg, 'variables') local hash = get_redis_hash(msg, 'variables')
if hash then if hash then
local value = redis:hget(hash, var_name) local value = redis:hget(hash, var_name)
if not value then if not value then
return'Nicht gefunden; benutze /get, um alle Variablen aufzulisten.' return'Nicht gefunden; benutze /get, um alle Variablen aufzulisten.'
else else
return var_name..' = '..value return var_name..' = '..value
end end
end end
end end
function get:list_variables(msg) function get:list_variables(msg)
local hash = get_redis_hash(msg, 'variables') local hash = get_redis_hash(msg, 'variables')
print(hash) print(hash)
if hash then if hash then
print('Hole Variable von Redis Hash '..hash) print('Hole Variable von Redis Hash '..hash)
local names = redis:hkeys(hash) local names = redis:hkeys(hash)
local text = '' local text = ''
for i=1, #names do for i=1, #names do
variables = get:get_value(msg, names[i]) variables = get:get_value(msg, names[i])
text = text..variables.."\n" text = text..variables.."\n"
end end
if text == '' or text == nil then if text == '' or text == nil then
return 'Keine Variablen vorhanden!' return 'Keine Variablen vorhanden!'
else else
return text return text
end end
end end
end end
function get:action(msg) function get:action(msg)
local input = utilities.input(msg.text) local input = utilities.input(msg.text)
if input then if input then
output = get:get_value(msg, input:match('(.+)')) output = get:get_value(msg, input:match('(.+)'))
else else
output = get:list_variables(msg) output = get:list_variables(msg)
end end
utilities.send_message(msg.chat.id, output, true, nil, true) utilities.send_message(msg.chat.id, output, true, nil, true)
end end
return get return get

View File

@ -1,52 +1,52 @@
local giphy = {} local giphy = {}
function giphy:init(config) function giphy:init(config)
giphy.triggers = { giphy.triggers = {
"/nil" "/nil"
} }
giphy.inline_triggers = { giphy.inline_triggers = {
"^(gif) (.+)", "^(gif) (.+)",
"^(gif)$" "^(gif)$"
} }
end end
local BASE_URL = 'http://api.giphy.com/v1/gifs' local BASE_URL = 'http://api.giphy.com/v1/gifs'
local apikey = 'dc6zaTOxFJmzC' -- public beta key local apikey = 'dc6zaTOxFJmzC' -- public beta key
function giphy:get_gifs(query) function giphy:get_gifs(query)
if not query then if not query then
url = BASE_URL..'/trending?api_key='..apikey url = BASE_URL..'/trending?api_key='..apikey
else else
url = BASE_URL..'/search?q='..URL.escape(query)..'&api_key='..apikey url = BASE_URL..'/search?q='..URL.escape(query)..'&api_key='..apikey
end end
local res, code = http.request(url) local res, code = http.request(url)
if code ~= 200 then return nil end if code ~= 200 then return nil end
return json.decode(res).data return json.decode(res).data
end end
function giphy:inline_callback(inline_query, config, matches) function giphy:inline_callback(inline_query, config, matches)
if not matches[2] then if not matches[2] then
data = giphy:get_gifs() data = giphy:get_gifs()
else else
data = giphy:get_gifs(matches[2]) data = giphy:get_gifs(matches[2])
end end
if not data then abort_inline_query(inline_query) return end if not data then abort_inline_query(inline_query) return end
if not data[1] then abort_inline_query(inline_query) return end if not data[1] then abort_inline_query(inline_query) return end
local results = '[' local results = '['
local id = 450 local id = 450
for n in pairs(data) do for n in pairs(data) do
results = results..'{"type":"mpeg4_gif","id":"'..id..'","mpeg4_url":"'..data[n].images.original.mp4..'","thumb_url":"'..data[n].images.fixed_height.url..'","mpeg4_width":'..data[n].images.original.width..',"mp4_height":'..data[n].images.original.height..'}' results = results..'{"type":"mpeg4_gif","id":"'..id..'","mpeg4_url":"'..data[n].images.original.mp4..'","thumb_url":"'..data[n].images.fixed_height.url..'","mpeg4_width":'..data[n].images.original.width..',"mp4_height":'..data[n].images.original.height..'}'
id = id+1 id = id+1
if n < #data then if n < #data then
results = results..',' results = results..','
end end
end end
local results = results..']' local results = results..']'
utilities.answer_inline_query(inline_query, results, 3600) utilities.answer_inline_query(inline_query, results, 3600)
end end
function giphy:action() function giphy:action()
end end
return giphy return giphy

View File

@ -1,55 +1,55 @@
local imgur = {} local imgur = {}
function imgur:init(config) function imgur:init(config)
if not cred_data.imgur_client_id then if not cred_data.imgur_client_id then
print('Fehlender Key: imgur_client_id.') print('Fehlender Key: imgur_client_id.')
print('imgur.lua wird nicht aktiviert.') print('imgur.lua wird nicht aktiviert.')
return return
end end
imgur.triggers = { imgur.triggers = {
"imgur.com/([A-Za-z0-9]+)" "imgur.com/([A-Za-z0-9]+)"
} }
end end
local client_id = cred_data.imgur_client_id local client_id = cred_data.imgur_client_id
local BASE_URL = 'https://api.imgur.com/3' local BASE_URL = 'https://api.imgur.com/3'
function imgur:get_imgur_data(imgur_code) function imgur:get_imgur_data(imgur_code)
local response_body = {} local response_body = {}
local request_constructor = { local request_constructor = {
url = BASE_URL..'/image/'..imgur_code, url = BASE_URL..'/image/'..imgur_code,
method = "GET", method = "GET",
sink = ltn12.sink.table(response_body), sink = ltn12.sink.table(response_body),
headers = { headers = {
Authorization = 'Client-ID '..client_id Authorization = 'Client-ID '..client_id
} }
} }
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 if not ok then
return nil return nil
end end
local response_body = json.decode(table.concat(response_body)) local response_body = json.decode(table.concat(response_body))
if response_body.status ~= 200 then return nil end if response_body.status ~= 200 then return nil end
return response_body.data.link return response_body.data.link
end end
function imgur:action(msg) function imgur:action(msg)
local imgur_code = matches[1] local imgur_code = matches[1]
if imgur_code == "login" then return nil end if imgur_code == "login" then return nil end
utilities.send_typing(msg.chat.id, 'upload_photo') utilities.send_typing(msg.chat.id, 'upload_photo')
local link = imgur:get_imgur_data(imgur_code) local link = imgur:get_imgur_data(imgur_code)
if link then if link then
local file = download_to_file(link) local file = download_to_file(link)
if string.ends(link, ".gif") then if string.ends(link, ".gif") then
utilities.send_document(msg.chat.id, file, nil, msg.message_id) utilities.send_document(msg.chat.id, file, nil, msg.message_id)
else else
utilities.send_photo(msg.chat.id, file, nil, msg.message_id) utilities.send_photo(msg.chat.id, file, nil, msg.message_id)
end end
end end
end end
return imgur return imgur

View File

@ -1,79 +0,0 @@
local isup = {}
function isup:init(config)
isup.triggers = {
"^/[Ii][Ss][Uu][Pp] (.*)$",
"^/[Pp][Ii][Nn][Gg] (.*)$"
}
isup.doc = [[*
]]..config.cmd_pat..[[isup* _<URL>_: Prüft, ob die URL up ist]]
end
function isup:is_up_socket(ip, port)
print('Verbinde zu ', ip, port)
local c = socket.try(socket.tcp())
c:settimeout(3)
local conn = c:connect(ip, port)
if not conn then
return false
else
c:close()
return true
end
end
function isup:is_up_http(url)
-- Parse URL from input, default to http
local parsed_url = URL.parse(url, { scheme = 'http', authority = '' })
-- Fix URLs without subdomain not parsed properly
if not parsed_url.host and parsed_url.path then
parsed_url.host = parsed_url.path
parsed_url.path = ""
end
-- Re-build URL
local url = URL.build(parsed_url)
local protocols = {
["https"] = https,
["http"] = http
}
local options = {
url = url,
redirect = false,
method = "GET"
}
local response = { protocols[parsed_url.scheme].request(options) }
local code = tonumber(response[2])
if code == nil or code >= 400 then
return false
end
return true
end
function isup:isup(url)
local pattern = '^(%d%d?%d?%.%d%d?%d?%.%d%d?%d?%.%d%d?%d?):?(%d?%d?%d?%d?%d?)$'
local ip,port = string.match(url, pattern)
local result = nil
-- /isup 8.8.8.8:53
if ip then
port = port or '80'
result = isup:is_up_socket(ip, port)
else
result = isup:is_up_http(url)
end
return result
end
function isup:action(msg, config)
if isup:isup(matches[1]) then
utilities.send_reply(msg, matches[1]..' ist UP! ✅')
return
else
utilities.send_reply(msg, matches[1]..' ist DOWN! ❌')
return
end
end
return isup

View File

@ -1,47 +1,47 @@
local lyrics = {} local lyrics = {}
function lyrics:init(config) function lyrics:init(config)
if not cred_data.lyricsnmusic_apikey then if not cred_data.lyricsnmusic_apikey then
print('Fehlender Key: lyricsnmusic_apikey.') print('Fehlender Key: lyricsnmusic_apikey.')
print('lyrics.lua wird nicht aktiviert.') print('lyrics.lua wird nicht aktiviert.')
return return
end end
lyrics.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('[Ll][Yy][Rr][Ii][Cc][Ss]', true).table lyrics.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('[Ll][Yy][Rr][Ii][Cc][Ss]', true).table
lyrics.doc = [[* lyrics.doc = [[*
]]..config.cmd_pat..[[lyrics* _<Lied>_: Postet Liedertext]] ]]..config.cmd_pat..[[lyrics* _<Lied>_: Postet Liedertext]]
end end
lyrics.command = 'lyrics <Lied>' lyrics.command = 'lyrics <Lied>'
function lyrics:getLyrics(text) function lyrics:getLyrics(text)
local apikey = cred_data.lyricsnmusic_apikey local apikey = cred_data.lyricsnmusic_apikey
local q = URL.encode(text) local q = URL.encode(text)
local b = http.request("http://api.lyricsnmusic.com/songs?api_key="..apikey.."&q=" .. q) local b = http.request("http://api.lyricsnmusic.com/songs?api_key="..apikey.."&q=" .. q)
response = json.decode(b) response = json.decode(b)
local reply = "" local reply = ""
if #response > 0 then if #response > 0 then
-- grab first match -- grab first match
local result = response[1] local result = response[1]
reply = result.title .. " - " .. result.artist.name .. "\n" .. result.snippet .. "\n[Ganzen Liedertext ansehen](" .. result.url .. ")" reply = result.title .. " - " .. result.artist.name .. "\n" .. result.snippet .. "\n[Ganzen Liedertext ansehen](" .. result.url .. ")"
else else
reply = nil reply = nil
end end
return reply return reply
end end
function lyrics:action(msg, config, matches) function lyrics:action(msg, config, matches)
local input = utilities.input(msg.text) local input = utilities.input(msg.text)
if not input then if not input then
if msg.reply_to_message and msg.reply_to_message.text then if msg.reply_to_message and msg.reply_to_message.text then
input = msg.reply_to_message.text input = msg.reply_to_message.text
else else
utilities.send_message(msg.chat.id, lyrics.doc, true, msg.message_id, true) utilities.send_message(msg.chat.id, lyrics.doc, true, msg.message_id, true)
return return
end end
end end
utilities.send_reply(msg, lyrics:getLyrics(input), true) utilities.send_reply(msg, lyrics:getLyrics(input), true)
end end
return lyrics return lyrics

View File

@ -1,236 +1,236 @@
local mal = {} local mal = {}
local xml = require("xml") local xml = require("xml")
mal.command = 'anime <Anime>, /manga <Manga>' mal.command = 'anime <Anime>, /manga <Manga>'
function mal:init(config) function mal:init(config)
if not cred_data.mal_username then if not cred_data.mal_username then
print('Fehlender Key: mal_username.') print('Fehlender Key: mal_username.')
print('myanimelist.lua wird nicht aktiviert.') print('myanimelist.lua wird nicht aktiviert.')
return return
elseif not cred_data.mal_pw then elseif not cred_data.mal_pw then
print('Fehlender Key: mal_pw.') print('Fehlender Key: mal_pw.')
print('myanimelist.lua wird nicht aktiviert.') print('myanimelist.lua wird nicht aktiviert.')
return return
end end
mal.triggers = { mal.triggers = {
"^/(anime) (.+)$", "^/(anime) (.+)$",
"^/(mal) (.+)$", "^/(mal) (.+)$",
"^/(manga) (.+)$" "^/(manga) (.+)$"
} }
mal.doc = [[* mal.doc = [[*
]]..config.cmd_pat..[[anime*_ <Anime>_: Sendet Infos zum Anime ]]..config.cmd_pat..[[anime*_ <Anime>_: Sendet Infos zum Anime
*]]..config.cmd_pat..[[manga*_ <Manga>_: Sendet Infos zum Manga *]]..config.cmd_pat..[[manga*_ <Manga>_: Sendet Infos zum Manga
]] ]]
end end
local user = cred_data.mal_username local user = cred_data.mal_username
local password = cred_data.mal_pw local password = cred_data.mal_pw
local BASE_URL = 'https://'..user..':'..password..'@myanimelist.net/api' local BASE_URL = 'https://'..user..':'..password..'@myanimelist.net/api'
function mal:delete_tags(str) function mal:delete_tags(str)
str = string.gsub( str, '<br />', '') str = string.gsub( str, '<br />', '')
str = string.gsub( str, '%[i%]', '') str = string.gsub( str, '%[i%]', '')
str = string.gsub( str, '%[/i%]', '') str = string.gsub( str, '%[/i%]', '')
str = string.gsub( str, '&mdash;', '') str = string.gsub( str, '&mdash;', '')
return str return str
end end
local makeOurDate = function(dateString) local makeOurDate = function(dateString)
local pattern = "(%d+)%-(%d+)%-(%d+)" local pattern = "(%d+)%-(%d+)%-(%d+)"
local year, month, day = dateString:match(pattern) local year, month, day = dateString:match(pattern)
if month == "00" then if month == "00" then
return year return year
elseif day == "00" then elseif day == "00" then
return month..'.'..year return month..'.'..year
else else
return day..'.'..month..'.'..year return day..'.'..month..'.'..year
end end
end end
function mal:get_mal_info(query, typ) function mal:get_mal_info(query, typ)
if typ == 'anime' then if typ == 'anime' then
url = BASE_URL..'/anime/search.xml?q='..query url = BASE_URL..'/anime/search.xml?q='..query
elseif typ == 'manga' then elseif typ == 'manga' then
url = BASE_URL..'/manga/search.xml?q='..query url = BASE_URL..'/manga/search.xml?q='..query
end end
local res,code = https.request(url) local res,code = https.request(url)
if code ~= 200 then return "HTTP-Fehler" end if code ~= 200 then return "HTTP-Fehler" end
local result = xml.load(res) local result = xml.load(res)
return result return result
end end
function mal:send_anime_data(result, receiver) function mal:send_anime_data(result, receiver)
local title = '*'..xml.find(result, 'title')[1]..'*' local title = '*'..xml.find(result, 'title')[1]..'*'
local id = xml.find(result, 'id')[1] local id = xml.find(result, 'id')[1]
local mal_url = 'https://myanimelist.net/anime/'..id local mal_url = 'https://myanimelist.net/anime/'..id
if xml.find(result, 'type')[1] then if xml.find(result, 'type')[1] then
typ = ' ('..xml.find(result, 'type')[1]..')' typ = ' ('..xml.find(result, 'type')[1]..')'
else else
typ = '' typ = ''
end end
if xml.find(result, 'english')[1] then if xml.find(result, 'english')[1] then
eng = '\nEnglisch: *'..xml.find(result, 'english')[1]..'*' eng = '\nEnglisch: *'..xml.find(result, 'english')[1]..'*'
else else
eng = '' eng = ''
end end
if xml.find(result, 'synonyms')[1] then if xml.find(result, 'synonyms')[1] then
syno = '\nAlternativ: *'..xml.find(result, 'synonyms')[1]..'*' syno = '\nAlternativ: *'..xml.find(result, 'synonyms')[1]..'*'
else else
syno = '' syno = ''
end end
if xml.find(result, 'episodes')[1] then if xml.find(result, 'episodes')[1] then
episodes = '\nEpisoden: '..xml.find(result, 'episodes')[1] episodes = '\nEpisoden: '..xml.find(result, 'episodes')[1]
else else
episodes = '' episodes = ''
end end
if xml.find(result, 'status')[1] then if xml.find(result, 'status')[1] then
status = ' ('..xml.find(result, 'status')[1]..')' status = ' ('..xml.find(result, 'status')[1]..')'
else else
status = '' status = ''
end end
if xml.find(result, 'score')[1] ~= "0.00" then if xml.find(result, 'score')[1] ~= "0.00" then
score = '\nScore: '..string.gsub(xml.find(result, 'score')[1], "%.", ",") score = '\nScore: '..string.gsub(xml.find(result, 'score')[1], "%.", ",")
else else
score = '' score = ''
end end
if xml.find(result, 'start_date')[1] ~= "0000-00-00" then if xml.find(result, 'start_date')[1] ~= "0000-00-00" then
startdate = '\nAusstrahlung: '..makeOurDate(xml.find(result, 'start_date')[1]) startdate = '\nAusstrahlung: '..makeOurDate(xml.find(result, 'start_date')[1])
else else
startdate = '' startdate = ''
end end
if xml.find(result, 'end_date')[1] ~= "0000-00-00" then if xml.find(result, 'end_date')[1] ~= "0000-00-00" then
enddate = ' - '..makeOurDate(xml.find(result, 'end_date')[1]) enddate = ' - '..makeOurDate(xml.find(result, 'end_date')[1])
else else
enddate = '' enddate = ''
end end
if xml.find(result, 'synopsis')[1] then if xml.find(result, 'synopsis')[1] then
desc = '\n_'..unescape(mal:delete_tags(string.sub(xml.find(result, 'synopsis')[1], 1, 250)))..'..._' desc = '\n_'..unescape(mal:delete_tags(string.sub(xml.find(result, 'synopsis')[1], 1, 250)))..'..._'
else else
desc = '' desc = ''
end end
local text = title..typ..eng..syno..episodes..status..score..startdate..enddate..'\n'..desc..'\n[Auf MyAnimeList ansehen]('..mal_url..')' local text = title..typ..eng..syno..episodes..status..score..startdate..enddate..'\n'..desc..'\n[Auf MyAnimeList ansehen]('..mal_url..')'
if xml.find(result, 'image') then if xml.find(result, 'image') then
local image_url = xml.find(result, 'image')[1] local image_url = xml.find(result, 'image')[1]
return text, image_url return text, image_url
else else
return text return text
end end
end end
function mal:send_manga_data(result) function mal:send_manga_data(result)
local title = xml.find(result, 'title')[1] local title = xml.find(result, 'title')[1]
local id = xml.find(result, 'id')[1] local id = xml.find(result, 'id')[1]
local mal_url = 'https://myanimelist.net/manga/'..id local mal_url = 'https://myanimelist.net/manga/'..id
if xml.find(result, 'type')[1] then if xml.find(result, 'type')[1] then
typ = ' ('..xml.find(result, 'type')[1]..')' typ = ' ('..xml.find(result, 'type')[1]..')'
else else
typ = '' typ = ''
end end
if xml.find(result, 'synonyms')[1] then if xml.find(result, 'synonyms')[1] then
alt_name = '\noder: '..unescape(mal:delete_tags(xml.find(result, 'synonyms')[1])) alt_name = '\noder: '..unescape(mal:delete_tags(xml.find(result, 'synonyms')[1]))
else else
alt_name = '' alt_name = ''
end end
if xml.find(result, 'chapters')[1] then if xml.find(result, 'chapters')[1] then
chapters = '\nKapitel: '..xml.find(result, 'chapters')[1] chapters = '\nKapitel: '..xml.find(result, 'chapters')[1]
else else
chapters = '' chapters = ''
end end
if xml.find(result, 'status')[1] then if xml.find(result, 'status')[1] then
status = ' ('..xml.find(result, 'status')[1]..')' status = ' ('..xml.find(result, 'status')[1]..')'
else else
status = '' status = ''
end end
if xml.find(result, 'volumes')[1] then if xml.find(result, 'volumes')[1] then
volumes = '\nBände '..xml.find(result, 'volumes')[1] volumes = '\nBände '..xml.find(result, 'volumes')[1]
else else
volumes = '' volumes = ''
end end
if xml.find(result, 'score')[1] ~= "0.00" then if xml.find(result, 'score')[1] ~= "0.00" then
score = '\nScore: '..xml.find(result, 'score')[1] score = '\nScore: '..xml.find(result, 'score')[1]
else else
score = '' score = ''
end end
if xml.find(result, 'start_date')[1] ~= "0000-00-00" then if xml.find(result, 'start_date')[1] ~= "0000-00-00" then
startdate = '\nVeröffentlichungszeitraum: '..makeOurDate(xml.find(result, 'start_date')[1]) startdate = '\nVeröffentlichungszeitraum: '..makeOurDate(xml.find(result, 'start_date')[1])
else else
startdate = '' startdate = ''
end end
if xml.find(result, 'end_date')[1] ~= "0000-00-00" then if xml.find(result, 'end_date')[1] ~= "0000-00-00" then
enddate = ' - '..makeOurDate(xml.find(result, 'end_date')[1]) enddate = ' - '..makeOurDate(xml.find(result, 'end_date')[1])
else else
enddate = '' enddate = ''
end end
if xml.find(result, 'synopsis')[1] then if xml.find(result, 'synopsis')[1] then
desc = '\n'..unescape(mal:delete_tags(string.sub(xml.find(result, 'synopsis')[1], 1, 200))) .. '...' desc = '\n'..unescape(mal:delete_tags(string.sub(xml.find(result, 'synopsis')[1], 1, 200))) .. '...'
else else
desc = '' desc = ''
end end
local text = '*'..title..'*'..alt_name..typ..chapters..status..volumes..score..startdate..enddate..'_'..desc..'_\n[Auf MyAnimeList ansehen]('..mal_url..')' local text = '*'..title..'*'..alt_name..typ..chapters..status..volumes..score..startdate..enddate..'_'..desc..'_\n[Auf MyAnimeList ansehen]('..mal_url..')'
if xml.find(result, 'image') then if xml.find(result, 'image') then
local image_url = xml.find(result, 'image')[1] local image_url = xml.find(result, 'image')[1]
return text, image_url return text, image_url
else else
return text return text
end end
end end
function mal:action(msg, config, matches) function mal:action(msg, config, matches)
local query = URL.escape(matches[2]) local query = URL.escape(matches[2])
if matches[1] == 'anime' or matches[1] == 'mal' then if matches[1] == 'anime' or matches[1] == 'mal' then
local anime_info = mal:get_mal_info(query, 'anime') local anime_info = mal:get_mal_info(query, 'anime')
if anime_info == "HTTP-Fehler" then if anime_info == "HTTP-Fehler" then
utilities.send_reply(msg, 'Anime nicht gefunden!') utilities.send_reply(msg, 'Anime nicht gefunden!')
return return
else else
local text, image_url = mal:send_anime_data(anime_info) local text, image_url = mal:send_anime_data(anime_info)
if image_url then if image_url then
utilities.send_typing(msg.chat.id, 'upload_photo') utilities.send_typing(msg.chat.id, 'upload_photo')
utilities.send_photo(msg.chat.id, image_url, nil, msg.message_id) utilities.send_photo(msg.chat.id, image_url, nil, msg.message_id)
end end
utilities.send_reply(msg, text, true) utilities.send_reply(msg, text, true)
return return
end end
elseif matches[1] == 'manga' then elseif matches[1] == 'manga' then
local manga_info = mal:get_mal_info(query, 'manga') local manga_info = mal:get_mal_info(query, 'manga')
if manga_info == "HTTP-Fehler" then if manga_info == "HTTP-Fehler" then
utilities.send_reply(msg, 'Manga nicht gefunden!') utilities.send_reply(msg, 'Manga nicht gefunden!')
return return
else else
local text, image_url = mal:send_manga_data(manga_info) local text, image_url = mal:send_manga_data(manga_info)
if image_url then if image_url then
utilities.send_typing(msg.chat.id, 'upload_photo') utilities.send_typing(msg.chat.id, 'upload_photo')
utilities.send_photo(msg.chat.id, image_url, nil, msg.message_id) utilities.send_photo(msg.chat.id, image_url, nil, msg.message_id)
end end
utilities.send_reply(msg, text, true) utilities.send_reply(msg, text, true)
return return
end end
end end
end end
return mal return mal

View File

@ -39,12 +39,13 @@ function notify:pre_process(msg)
if redis:sismember('chat:'..chat_id..':users', id) then if redis:sismember('chat:'..chat_id..':users', id) then
-- ignore message, if user is mentioning him/herself -- ignore message, if user is mentioning him/herself
if id ~= tostring(msg.from.id) then if id ~= tostring(msg.from.id) then
local send_date = run_command('date -d @'..msg.date..' +"%d.%m.%Y um %H:%M:%S Uhr"') local send_date = run_command('date -d @'..msg.date..' +"<i>%d.%m.%Y</i> | 🕒 <i>%H:%M:%S Uhr</i>"')
local send_date = string.gsub(send_date, "\n", "") local send_date = string.gsub(send_date, "\n", "")
local from = string.gsub(msg.from.name, "%_", " ") local from = string.gsub(msg.from.name, "%_", " ")
local chat_name = string.gsub(msg.chat.title, "%_", " ") local chat_name = string.gsub(msg.chat.title, "%_", " ")
local text = from..' am '..send_date..' in "'..chat_name..'":\n\n'..msg.text local text = '🔔 <b>'..utilities.html_escape(from)..'</b> hat dich erwähnt:'
utilities.send_message(id, text, true) local text = text..'\n👥 <b>'..utilities.html_escape(chat_name)..'</b> | 📅 '..send_date..'\n\n'..utilities.html_escape(msg.text)
utilities.send_message(id, text, true, false, 'HTML')
end end
end end
end end

View File

@ -1,35 +0,0 @@
local pagespeed_insights = {}
function pagespeed_insights:init(config)
if not cred_data.google_apikey then
print('Fehlender Key: google_apikey.')
print('pagespeed_insights.lua wird nicht aktiviert.')
return
end
pagespeed_insights.triggers = {
"^/[Ss][Pp][Ee][Ee][Dd] (https?://[%w-_%.%?%.:/%+=&]+)"
}
pagespeed_insights.doc = [[*
]]..config.cmd_pat..[[speed* _<Seiten-URL>_: Testet Geschwindigkeit der Seite mit PageSpeed Insights]]
end
local BASE_URL = 'https://www.googleapis.com/pagespeedonline/v2'
function pagespeed_insights:get_pagespeed(test_url)
local apikey = cred_data.google_apikey
local url = BASE_URL..'/runPagespeed?url='..test_url..'&key='..apikey..'&fields=id,ruleGroups(SPEED(score))'
local res,code = https.request(url)
if code ~= 200 then return "HTTP-FEHLER" end
local data = json.decode(res)
return data.id..' hat einen PageSpeed-Score von *'..data.ruleGroups.SPEED.score..' Punkten.*'
end
function pagespeed_insights:action(msg, config, matches)
utilities.send_typing(msg.chat.id, 'typing')
local text = pagespeed_insights:get_pagespeed(matches[1])
if not text then utilities.send_reply(msg, config.errors.connection) return end
utilities.send_reply(msg, text, true)
end
return pagespeed_insights

View File

@ -1,58 +1,58 @@
local play_store = {} local play_store = {}
function play_store:init(config) function play_store:init(config)
if not cred_data.x_mashape_key then if not cred_data.x_mashape_key then
print('Fehlender Key: x_mashape_key.') print('Fehlender Key: x_mashape_key.')
print('play_store.lua wird nicht aktiviert.') print('play_store.lua wird nicht aktiviert.')
return return
end end
play_store.triggers = { play_store.triggers = {
"play.google.com/store/apps/details%?id=(.*)" "play.google.com/store/apps/details%?id=(.*)"
} }
end end
local BASE_URL = 'https://apps.p.mashape.com/google/application' local BASE_URL = 'https://apps.p.mashape.com/google/application'
function play_store:get_playstore_data (appid) function play_store:get_playstore_data (appid)
local apikey = cred_data.x_mashape_key local apikey = cred_data.x_mashape_key
local url = BASE_URL..'/'..appid..'?mashape-key='..apikey local url = BASE_URL..'/'..appid..'?mashape-key='..apikey
local res,code = https.request(url) local res,code = https.request(url)
if code ~= 200 then return nil end if code ~= 200 then return nil end
local data = json.decode(res).data local data = json.decode(res).data
return data return data
end end
function play_store:send_playstore_data(data) function play_store:send_playstore_data(data)
local title = data.title local title = data.title
local developer = data.developer.id local developer = data.developer.id
local category = data.category.name local category = data.category.name
local rating = data.rating.average local rating = data.rating.average
local installs = data.performance.installs local installs = data.performance.installs
local description = unescape(data.description) local description = unescape(data.description)
if data.version == "Varies with device" then if data.version == "Varies with device" then
appversion = "variiert je nach Gerät" appversion = "variiert je nach Gerät"
else else
appversion = data.version appversion = data.version
end end
if data.price == 0 then if data.price == 0 then
price = "Gratis" price = "Gratis"
else else
price = data.price price = data.price
end end
local text = '*'..title..'* von *'..developer..'* aus der Kategorie _'..category..'_, durschnittlich bewertet mit '..rating..' Sternen.\n_'..description..'_\n'..installs..' Installationen, Version '..appversion local text = '*'..title..'* von *'..developer..'* aus der Kategorie _'..category..'_, durschnittlich bewertet mit '..rating..' Sternen.\n_'..description..'_\n'..installs..' Installationen, Version '..appversion
return text return text
end end
function play_store:action(msg, config, matches) function play_store:action(msg, config, matches)
local appid = matches[1] local appid = matches[1]
local data = play_store:get_playstore_data(appid) local data = play_store:get_playstore_data(appid)
if data == nil then if data == nil then
return return
else else
utilities.send_reply(msg, play_store:send_playstore_data(data), true) utilities.send_reply(msg, play_store:send_playstore_data(data), true)
return return
end end
end end
return play_store return play_store

View File

@ -1,144 +0,0 @@
local pocket = {}
function pocket:init(config)
if not cred_data.pocket_consumer_key then
print('Fehlender Key: pocket_consumer_key.')
print('pocket.lua wird nicht aktiviert.')
return
end
pocket.triggers = {
"^/pocket(set)(.+)$",
"^/pocket (add) (https?://.*)$",
"^/pocket (archive) (%d+)$",
"^/pocket (readd) (%d+)$",
"^/pocket (unfavorite) (%d+)$",
"^/pocket (favorite) (%d+)$",
"^/pocket (delete) (%d+)$",
"^/pocket (unauth)$",
"^/pocket$"
}
pocket.doc = [[*
]]..config.cmd_pat..[[pocket*: Postet Liste deiner Links
*]]..config.cmd_pat..[[pocket* add _(url)_: Fügt diese URL deiner Liste hinzu
*]]..config.cmd_pat..[[pocket* archive _[id]_: Archiviere diesen Eintrag
*]]..config.cmd_pat..[[pocket* readd _[id]_: De-archiviere diesen Eintrag
*]]..config.cmd_pat..[[pocket* favorite _[id]_: Favorisiere diesen Eintrag
*]]..config.cmd_pat..[[pocket* unfavorite _[id]_: Entfavorisiere diesen Eintrag
*]]..config.cmd_pat..[[pocket* delete _[id]_: Lösche diesen Eintrag
*]]..config.cmd_pat..[[pocket* unauth: Löscht deinen Account aus dem Bot]]
end
pocket.command = 'pocket <siehe `/hilfe pocket`>'
local BASE_URL = 'https://getpocket.com/v3'
local consumer_key = cred_data.pocket_consumer_key
local headers = {
["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF8",
["X-Accept"] = "application/json"
}
function pocket:set_pocket_access_token(hash, access_token)
if string.len(access_token) ~= 30 then return '*Inkorrekter Access-Token*' end
print('Setting pocket in redis hash '..hash..' to users access_token')
redis:hset(hash, 'pocket', access_token)
return '*Authentifizierung abgeschlossen!*\nDas Plugin kann jetzt verwendet werden.'
end
function pocket:list_pocket_items(access_token)
local items = post_petition(BASE_URL..'/get', 'consumer_key='..consumer_key..'&access_token='..access_token..'&state=unread&sort=newest&detailType=simple', headers)
if items.status == 2 then return 'Keine Elemente eingespeichert.' end
if items.status ~= 1 then return 'Ein Fehler beim Holen der Elemente ist aufgetreten.' end
local text = ''
for element in pairs(items.list) do
title = items.list[element].given_title
if not title or title == "" then title = items.list[element].resolved_title end
text = text..'#'..items.list[element].item_id..': '..title..'\n'..items.list[element].resolved_url..'\n\n'
end
return text
end
function pocket:add_pocket_item(access_token, url)
local result = post_petition(BASE_URL..'/add', 'consumer_key='..consumer_key..'&access_token='..access_token..'&url='..url, headers)
if result.status ~= 1 then return 'Ein Fehler beim Hinzufügen der URL ist aufgetreten :(' end
local given_url = result.item.given_url
if result.item.title == "" or not result.item.title then
title = 'Seite'
else
title = '"'..result.item.title..'"'
end
local code = result.item.response_code
local text = title..' ('..given_url..') hinzugefügt!'
if not code then return text end
if code ~= "200" and code ~= "0" then text = text..'\nAber die Seite liefert Fehler '..code..' zurück.' end
return text
end
function pocket:modify_pocket_item(access_token, action, id)
local result = post_petition(BASE_URL..'/send', 'consumer_key='..consumer_key..'&access_token='..access_token..'&actions=[{"action":"'..action..'","item_id":'..id..'}]', headers)
if result.status ~= 1 then return 'Ein Fehler ist aufgetreten :(' end
if action == 'readd' then
if result.action_results[1] == false then
return 'Dieser Eintrag existiert nicht!'
end
local url = result.action_results[1].normal_url
return url..' wieder de-archiviert'
end
if result.action_results[1] == true then
return 'Aktion ausgeführt.'
else
return 'Ein Fehler ist aufgetreten.'
end
end
function pocket:action(msg, config, matches)
local hash = 'user:'..msg.from.id
local access_token = redis:hget(hash, 'pocket')
if matches[1] == 'set' then
local access_token = matches[2]
utilities.send_reply(msg, pocket:set_pocket_access_token(hash, access_token), true)
local message_id = redis:hget(hash, 'pocket_login_msg')
utilities.edit_message(msg.chat.id, message_id, '*Anmeldung abgeschlossen!*', true, true)
redis:hdel(hash, 'pocket_login_msg')
return
end
if not access_token then
local result = utilities.send_reply(msg, '*Bitte authentifiziere dich zuerst, indem du dich anmeldest.*', true, '{"inline_keyboard":[[{"text":"Bei Pocket anmelden","url":"https://brawlbot.tk/apis/callback/pocket/connect.php"}]]}')
redis:hset(hash, 'pocket_login_msg', result.result.message_id)
return
end
if matches[1] == 'unauth' then
redis:hdel(hash, 'pocket')
utilities.send_reply(msg, 'Erfolgreich ausgeloggt! Du kannst den Zugriff [in deinen Einstellungen](https://getpocket.com/connected_applications) endgültig entziehen.', true)
return
end
if matches[1] == 'add' then
utilities.send_reply(msg, pocket:add_pocket_item(access_token, matches[2]))
return
end
if matches[1] == 'archive' or matches[1] == 'delete' or matches[1] == 'readd' or matches[1] == 'favorite' or matches[1] == 'unfavorite' then
utilities.send_reply(msg, pocket:modify_pocket_item(access_token, matches[1], matches[2]))
return
end
if msg.chat.type == 'chat' or msg.chat.type == 'supergroup' then
utilities.send_reply(msg, 'Ausgeben deiner privaten Pocket-Liste in einem öffentlichen Chat wird feige verweigert. Bitte schreibe mich privat an!', true)
return
else
utilities.send_reply(msg, pocket:list_pocket_items(access_token))
return
end
end
return pocket

View File

@ -1,77 +1,77 @@
local reddit = {} local reddit = {}
reddit.command = 'reddit [r/subreddit | Suchbegriff]' reddit.command = 'reddit [r/subreddit | Suchbegriff]'
function reddit:init(config) function reddit:init(config)
reddit.triggers = utilities.triggers(self.info.username, config.cmd_pat, {'^/r/'}):t('reddit', true):t('r', true):t('r/', true).table reddit.triggers = utilities.triggers(self.info.username, config.cmd_pat, {'^/r/'}):t('reddit', true):t('r', true):t('r/', true).table
reddit.doc = [[* reddit.doc = [[*
]]..config.cmd_pat..[[r* _[r/subreddit | Suchbegriff]_: Gibt Top-Posts oder Ergebnisse eines Subreddits aus. Wenn kein Argument gegeben ist, wird /r/all genommen.]] ]]..config.cmd_pat..[[r* _[r/subreddit | Suchbegriff]_: Gibt Top-Posts oder Ergebnisse eines Subreddits aus. Wenn kein Argument gegeben ist, wird /r/all genommen.]]
end end
local format_results = function(posts) local format_results = function(posts)
local output = '' local output = ''
for _,v in ipairs(posts) do for _,v in ipairs(posts) do
local post = v.data local post = v.data
local title = post.title:gsub('%[', '('):gsub('%]', ')'):gsub('&amp;', '&') local title = post.title:gsub('%[', '('):gsub('%]', ')'):gsub('&amp;', '&')
if title:len() > 256 then if title:len() > 256 then
title = title:sub(1, 253) title = title:sub(1, 253)
title = utilities.trim(title) .. '...' title = utilities.trim(title) .. '...'
end end
local short_url = 'https://redd.it/' .. post.id local short_url = 'https://redd.it/' .. post.id
local s = '[' .. unescape(title) .. '](' .. short_url .. ')' local s = '[' .. unescape(title) .. '](' .. short_url .. ')'
if post.domain and not post.is_self and not post.over_18 then if post.domain and not post.is_self and not post.over_18 then
s = '`[`[' .. post.domain .. '](' .. post.url:gsub('%)', '\\)') .. ')`]` ' .. s s = '`[`[' .. post.domain .. '](' .. post.url:gsub('%)', '\\)') .. ')`]` ' .. s
end end
output = output .. '' .. s .. '\n' output = output .. '' .. s .. '\n'
end end
return output return output
end end
reddit.subreddit_url = 'https://www.reddit.com/%s/.json?limit=' reddit.subreddit_url = 'https://www.reddit.com/%s/.json?limit='
reddit.search_url = 'https://www.reddit.com/search.json?q=%s&limit=' reddit.search_url = 'https://www.reddit.com/search.json?q=%s&limit='
reddit.rall_url = 'https://www.reddit.com/.json?limit=' reddit.rall_url = 'https://www.reddit.com/.json?limit='
function reddit:action(msg, config) function reddit:action(msg, config)
-- Eight results in PM, four results elsewhere. -- Eight results in PM, four results elsewhere.
local limit = 4 local limit = 4
if msg.chat.type == 'private' then if msg.chat.type == 'private' then
limit = 8 limit = 8
end end
local text = msg.text_lower local text = msg.text_lower
if text:match('^/r/.') then if text:match('^/r/.') then
-- Normalize input so this hack works easily. -- Normalize input so this hack works easily.
text = msg.text_lower:gsub('^/r/', config.cmd_pat..'r r/') text = msg.text_lower:gsub('^/r/', config.cmd_pat..'r r/')
end end
local input = utilities.input(text) local input = utilities.input(text)
local source, url local source, url
if input then if input then
if input:match('^r/.') then if input:match('^r/.') then
input = utilities.get_word(input, 1) input = utilities.get_word(input, 1)
url = reddit.subreddit_url:format(input) .. limit url = reddit.subreddit_url:format(input) .. limit
source = '*/' .. utilities.md_escape(input) .. '*\n' source = '*/' .. utilities.md_escape(input) .. '*\n'
else else
input = utilities.input(msg.text) input = utilities.input(msg.text)
source = '*Ergebnisse für* _' .. utilities.md_escape(input) .. '_ *:*\n' source = '*Ergebnisse für* _' .. utilities.md_escape(input) .. '_ *:*\n'
input = URL.escape(input) input = URL.escape(input)
url = reddit.search_url:format(input) .. limit url = reddit.search_url:format(input) .. limit
end end
else else
url = reddit.rall_url .. limit url = reddit.rall_url .. limit
source = '*/r/all*\n' source = '*/r/all*\n'
end end
local jstr, res = https.request(url) local jstr, res = https.request(url)
if res ~= 200 then if res ~= 200 then
utilities.send_reply(msg, config.errors.results) utilities.send_reply(msg, config.errors.results)
else else
local jdat = json.decode(jstr) local jdat = json.decode(jstr)
if #jdat.data.children == 0 then if #jdat.data.children == 0 then
utilities.send_reply(msg, config.errors.results) utilities.send_reply(msg, config.errors.results)
else else
local output = format_results(jdat.data.children) local output = format_results(jdat.data.children)
output = source .. output output = source .. output
utilities.send_message(msg.chat.id, output, true, nil, true) utilities.send_message(msg.chat.id, output, true, nil, true)
end end
end end
end end
return reddit return reddit

View File

@ -1,29 +0,0 @@
local roll = {}
roll.command = 'roll'
function roll:init(config)
roll.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('roll', true).table
roll.doc = [[*
]]..config.cmd_pat..[[roll*: Werfe einen Würfel]]
end
local canroll = {
"1",
"2",
"3",
"4",
"5",
"6"
}
function roll:roll_dice()
local randomroll = math.random(6)
return canroll[randomroll]
end
function roll:action(msg)
utilities.send_reply(msg, 'Du hast eine *'..roll:roll_dice()..'* gewürfelt.', true)
end
return roll

View File

@ -1,52 +1,52 @@
local set = {} local set = {}
set.command = 'set <Variable> <Wert>' set.command = 'set <Variable> <Wert>'
function set:init(config) function set:init(config)
set.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('set', true).table set.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('set', true).table
set.doc = [[* set.doc = [[*
]]..config.cmd_pat..[[set* _<Variable>_ _<Wert>_: Speichert eine Variable mit einem Wert ]]..config.cmd_pat..[[set* _<Variable>_ _<Wert>_: Speichert eine Variable mit einem Wert
*]]..config.cmd_pat..[[set* _<Variable>_ _nil_: Löscht Variable *]]..config.cmd_pat..[[set* _<Variable>_ _nil_: Löscht Variable
Nutze `/get <Variable>` zum Abrufen]] Nutze `/get <Variable>` zum Abrufen]]
end end
function set:save_value(msg, name, value) function set:save_value(msg, name, value)
local hash = get_redis_hash(msg, 'variables') local hash = get_redis_hash(msg, 'variables')
if hash then if hash then
print('Saving variable to redis hash '..hash) print('Saving variable to redis hash '..hash)
redis:hset(hash, name, value) redis:hset(hash, name, value)
return "Gespeichert: "..name.." = "..value return "Gespeichert: "..name.." = "..value
end end
end end
function set:delete_value(msg, name) function set:delete_value(msg, name)
local hash = get_redis_hash(msg, 'variables') local hash = get_redis_hash(msg, 'variables')
if redis:hexists(hash, name) == true then if redis:hexists(hash, name) == true then
print('Deleting variable from redis hash '..hash) print('Deleting variable from redis hash '..hash)
redis:hdel(hash, name) redis:hdel(hash, name)
return 'Variable "'..name..'" erfolgreich gelöscht!' return 'Variable "'..name..'" erfolgreich gelöscht!'
else else
return 'Du kannst keine Variable löschen, die nicht existiert .-.' return 'Du kannst keine Variable löschen, die nicht existiert .-.'
end end
end end
function set:action(msg) function set:action(msg)
local input = utilities.input(msg.text) local input = utilities.input(msg.text)
if not input or not input:match('([^%s]+) (.+)') then if not input or not input:match('([^%s]+) (.+)') then
utilities.send_message(msg.chat.id, set.doc, true, msg.message_id, true) utilities.send_message(msg.chat.id, set.doc, true, msg.message_id, true)
return return
end end
local name = input:match('([^%s]+) ') local name = input:match('([^%s]+) ')
local value = input:match(' (.+)') local value = input:match(' (.+)')
if value == "nil" then if value == "nil" then
output = set:delete_value(msg, name) output = set:delete_value(msg, name)
else else
output = set:save_value(msg, name, value) output = set:save_value(msg, name, value)
end end
utilities.send_message(msg.chat.id, output, true, nil, true) utilities.send_message(msg.chat.id, output, true, nil, true)
end end
return set return set

View File

@ -1,54 +1,54 @@
local settings = {} local settings = {}
settings.triggers = { settings.triggers = {
"^(⚙ [Ee]instellungen)$", "^(⚙ [Ee]instellungen)$",
"^(/settings)$", "^(/settings)$",
"^(💤 [Aa][Ff][Kk]%-[Kk]eyboard einschalten)", "^(💤 [Aa][Ff][Kk]%-[Kk]eyboard einschalten)",
"^(💤 [Aa][Ff][Kk]%-[Kk]eyboard ausschalten)", "^(💤 [Aa][Ff][Kk]%-[Kk]eyboard ausschalten)",
"^(❌ [Ee]instellungen verstecken)" "^(❌ [Ee]instellungen verstecken)"
} }
--[[ --[[
[ [
[ "Top Left", "Top Right" ], [ "Top Left", "Top Right" ],
[ "Bottom Left", "Bottom Right" ] [ "Bottom Left", "Bottom Right" ]
] ]
]] ]]
function settings:keyboard(user_id) function settings:keyboard(user_id)
if redis:hget('user:'..user_id, 'afk_keyboard') == 'true' then if redis:hget('user:'..user_id, 'afk_keyboard') == 'true' then
afk_button = '{"text":"💤 AFK-Keyboard ausschalten"}' afk_button = '{"text":"💤 AFK-Keyboard ausschalten"}'
else else
afk_button = '{"text":"💤 AFK-Keyboard einschalten"}' afk_button = '{"text":"💤 AFK-Keyboard einschalten"}'
end end
local hide_settings_button = '{"text":"❌ Einstellungen verstecken"}' local hide_settings_button = '{"text":"❌ Einstellungen verstecken"}'
local settings_keyboard = '[['..afk_button..','..hide_settings_button..']]' local settings_keyboard = '[['..afk_button..','..hide_settings_button..']]'
return settings_keyboard return settings_keyboard
end end
function settings:action(msg, config, matches) function settings:action(msg, config, matches)
if msg.chat.type ~= "private" then if msg.chat.type ~= "private" then
return return
end end
local hash = 'user:'..msg.from.id local hash = 'user:'..msg.from.id
if matches[1] == '⚙ Einstellungen' or matches[1] == '/settings' then if matches[1] == '⚙ Einstellungen' or matches[1] == '/settings' then
utilities.send_reply(msg, 'Was möchtest du einstellen?', false, '{"keyboard":'..settings:keyboard(msg.from.id)..', "one_time_keyboard":true, "selective":true, "resize_keyboard":true}') utilities.send_reply(msg, 'Was möchtest du einstellen?', false, '{"keyboard":'..settings:keyboard(msg.from.id)..', "one_time_keyboard":true, "selective":true, "resize_keyboard":true}')
return return
elseif matches[1] == '💤 AFK-Keyboard einschalten' then elseif matches[1] == '💤 AFK-Keyboard einschalten' then
redis:hset(hash, 'afk_keyboard', 'true') redis:hset(hash, 'afk_keyboard', 'true')
utilities.send_reply(msg, 'Das AFK-Keyboard wurde erfolgreich *eingeschaltet*.', true, '{"keyboard":'..settings:keyboard(msg.from.id)..', "one_time_keyboard":true, "selective":true, "resize_keyboard":true}') utilities.send_reply(msg, 'Das AFK-Keyboard wurde erfolgreich *eingeschaltet*.', true, '{"keyboard":'..settings:keyboard(msg.from.id)..', "one_time_keyboard":true, "selective":true, "resize_keyboard":true}')
return return
elseif matches[1] == '💤 AFK-Keyboard ausschalten' then elseif matches[1] == '💤 AFK-Keyboard ausschalten' then
redis:hset(hash, 'afk_keyboard', 'false') redis:hset(hash, 'afk_keyboard', 'false')
utilities.send_reply(msg, 'Das AFK-Keyboard wurde erfolgreich *ausgeschaltet*.', true, '{"keyboard":'..settings:keyboard(msg.from.id)..', "one_time_keyboard":true, "selective":true, "resize_keyboard":true}') utilities.send_reply(msg, 'Das AFK-Keyboard wurde erfolgreich *ausgeschaltet*.', true, '{"keyboard":'..settings:keyboard(msg.from.id)..', "one_time_keyboard":true, "selective":true, "resize_keyboard":true}')
return return
elseif matches[1] == '❌ Einstellungen verstecken' then elseif matches[1] == '❌ Einstellungen verstecken' then
utilities.send_reply(msg, 'Um die Einstellungen wieder einzublenden, führe /settings aus.', true, '{"hide_keyboard":true}') utilities.send_reply(msg, 'Um die Einstellungen wieder einzublenden, führe /settings aus.', true, '{"hide_keyboard":true}')
return return
end end
end end
return settings return settings

View File

@ -1,37 +1,37 @@
local soundcloud = {} local soundcloud = {}
soundcloud.triggers = { soundcloud.triggers = {
"soundcloud.com/([A-Za-z0-9-/-_-.]+)" "soundcloud.com/([A-Za-z0-9-/-_-.]+)"
} }
local BASE_URL = 'http://api.soundcloud.com/resolve.json' local BASE_URL = 'http://api.soundcloud.com/resolve.json'
local client_id = cred_data.soundcloud_client_id local client_id = cred_data.soundcloud_client_id
function soundcloud:send_soundcloud_info(sc_url) function soundcloud:send_soundcloud_info(sc_url)
local url = BASE_URL..'?url=http://soundcloud.com/'..sc_url..'&client_id='..client_id local url = BASE_URL..'?url=http://soundcloud.com/'..sc_url..'&client_id='..client_id
local res,code = http.request(url) local res,code = http.request(url)
if code ~= 200 then return nil end if code ~= 200 then return nil end
local data = json.decode(res) local data = json.decode(res)
local title = data.title local title = data.title
local description = data.description local description = data.description
local user = data.user.username local user = data.user.username
local user = 'Unbekannt' local user = 'Unbekannt'
local genre = data.genre local genre = data.genre
local playback_count = data.playback_count local playback_count = data.playback_count
local milliseconds = data.duration local milliseconds = data.duration
local totalseconds = math.floor(milliseconds / 1000) local totalseconds = math.floor(milliseconds / 1000)
local duration = makeHumanTime(totalseconds) local duration = makeHumanTime(totalseconds)
local text = '*'..title..'* von _'..user..'_\n_(Tag: '..genre..', '..duration..'; '..playback_count..' mal angehört)_\n'..description local text = '*'..title..'* von _'..user..'_\n_(Tag: '..genre..', '..duration..'; '..playback_count..' mal angehört)_\n'..description
return text return text
end end
function soundcloud:action(msg, config, matches) function soundcloud:action(msg, config, matches)
local text = soundcloud:send_soundcloud_info(matches[1]) local text = soundcloud:send_soundcloud_info(matches[1])
if not text then utilities.send_reply(msg, config.errors.connection) return end if not text then utilities.send_reply(msg, config.errors.connection) return end
utilities.send_reply(msg, text, true) utilities.send_reply(msg, text, true)
end end
return soundcloud return soundcloud

View File

@ -1,49 +1,49 @@
local streamable = {} local streamable = {}
streamable.triggers = { streamable.triggers = {
"streamable.com/([A-Za-z0-9-_-]+)", "streamable.com/([A-Za-z0-9-_-]+)",
} }
function streamable:send_streamable_video(shortcode, msg) function streamable:send_streamable_video(shortcode, msg)
local BASE_URL = "https://api.streamable.com" local BASE_URL = "https://api.streamable.com"
local url = BASE_URL..'/videos/'..shortcode local url = BASE_URL..'/videos/'..shortcode
local res,code = https.request(url) local res,code = https.request(url)
if code ~= 200 then return 'HTTP-Fehler' end if code ~= 200 then return 'HTTP-Fehler' end
local data = json.decode(res) local data = json.decode(res)
if data.status ~= 2 then utilities.send_reply(msg, "Video ist (noch) nicht verfügbar.") return end if data.status ~= 2 then utilities.send_reply(msg, "Video ist (noch) nicht verfügbar.") return end
if data.files.webm then if data.files.webm then
if data.title == "" then title = shortcode..'.webm' else title = data.title..'.webm' end if data.title == "" then title = shortcode..'.webm' else title = data.title..'.webm' end
url = 'https:'..data.files.webm.url url = 'https:'..data.files.webm.url
width = data.files.webm.width width = data.files.webm.width
height = data.files.webm.height height = data.files.webm.height
if data.files.webm.size > 50000000 then if data.files.webm.size > 50000000 then
local size = math.floor(data.files.webm.size / 1000000) local size = math.floor(data.files.webm.size / 1000000)
utilities.send_reply(msg, '*Video ist größer als 50 MB* ('..size..' MB)!\n[Direktlink]('..url..')', true) utilities.send_reply(msg, '*Video ist größer als 50 MB* ('..size..' MB)!\n[Direktlink]('..url..')', true)
return return
end end
elseif data.files.mp4 then elseif data.files.mp4 then
if data.title == "" then title = shortcode..'.mp4' else title = data.title..'.mp4' end if data.title == "" then title = shortcode..'.mp4' else title = data.title..'.mp4' end
url = 'https:'..data.files.mp4.url url = 'https:'..data.files.mp4.url
width = data.files.mp4.width width = data.files.mp4.width
height = data.files.mp4.height height = data.files.mp4.height
if data.files.mp4.size > 50000000 then if data.files.mp4.size > 50000000 then
local size = math.floor(data.files.mp4.size / 1000000) local size = math.floor(data.files.mp4.size / 1000000)
utilities.send_reply(msg, '*Video ist größer als 50 MB* ('..size..' MB)!\n[Direktlink]('..url..')', true) utilities.send_reply(msg, '*Video ist größer als 50 MB* ('..size..' MB)!\n[Direktlink]('..url..')', true)
return return
end end
end end
utilities.send_typing(msg.chat.id, 'upload_video') utilities.send_typing(msg.chat.id, 'upload_video')
local file = download_to_file(url, title) local file = download_to_file(url, title)
utilities.send_video(msg.chat.id, file, nil, msg.message_id, nil, width, height) utilities.send_video(msg.chat.id, file, nil, msg.message_id, nil, width, height)
return return
end end
function streamable:action(msg, config, matches) function streamable:action(msg, config, matches)
local shortcode = matches[1] local shortcode = matches[1]
streamable:send_streamable_video(shortcode, msg) streamable:send_streamable_video(shortcode, msg)
return return
end end
return streamable return streamable

View File

@ -1,92 +1,92 @@
local tv = {} local tv = {}
local xml = require("xml") local xml = require("xml")
tv.command = 'tv <TV-Serie>' tv.command = 'tv <TV-Serie>'
function tv:init(config) function tv:init(config)
tv.triggers = { tv.triggers = {
"^/tv (.+)$" "^/tv (.+)$"
} }
tv.doc = [[* tv.doc = [[*
]]..config.cmd_pat..[[tv*_ <TV-Serie>_: Sendet Infos zur TV-Serie]] ]]..config.cmd_pat..[[tv*_ <TV-Serie>_: Sendet Infos zur TV-Serie]]
end end
local BASE_URL = 'http://thetvdb.com/api' local BASE_URL = 'http://thetvdb.com/api'
local makeOurDate = function(dateString) local makeOurDate = function(dateString)
local pattern = "(%d+)%-(%d+)%-(%d+)" local pattern = "(%d+)%-(%d+)%-(%d+)"
local year, month, day = dateString:match(pattern) local year, month, day = dateString:match(pattern)
return day..'.'..month..'.'..year return day..'.'..month..'.'..year
end end
function tv:get_tv_info(series) function tv:get_tv_info(series)
local url = BASE_URL..'/GetSeries.php?seriesname='..series..'&language=de' local url = BASE_URL..'/GetSeries.php?seriesname='..series..'&language=de'
local res,code = http.request(url) local res,code = http.request(url)
if code ~= 200 then return "HTTP-ERROR" end if code ~= 200 then return "HTTP-ERROR" end
local result = xml.load(res) local result = xml.load(res)
if not xml.find(result, 'seriesid') then return "NOTFOUND" end if not xml.find(result, 'seriesid') then return "NOTFOUND" end
return result return result
end end
function tv:send_tv_data(result, msg) function tv:send_tv_data(result, msg)
local title = xml.find(result, 'SeriesName')[1] local title = xml.find(result, 'SeriesName')[1]
local id = xml.find(result, 'seriesid')[1] local id = xml.find(result, 'seriesid')[1]
if xml.find(result, 'AliasNames') and xml.find(result, 'AliasNames')[1] ~= title then if xml.find(result, 'AliasNames') and xml.find(result, 'AliasNames')[1] ~= title then
alias = '\noder: '..xml.find(result, 'AliasNames')[1] alias = '\noder: '..xml.find(result, 'AliasNames')[1]
else else
alias = '' alias = ''
end end
if xml.find(result, 'Overview') then if xml.find(result, 'Overview') then
desc = '\n_'..string.sub(xml.find(result, 'Overview')[1], 1, 250) .. '..._' desc = '\n_'..string.sub(xml.find(result, 'Overview')[1], 1, 250) .. '..._'
else else
desc = '' desc = ''
end end
if xml.find(result, 'FirstAired') then if xml.find(result, 'FirstAired') then
aired = '\n*Erstausstrahlung:* '..makeOurDate(xml.find(result, 'FirstAired')[1]) aired = '\n*Erstausstrahlung:* '..makeOurDate(xml.find(result, 'FirstAired')[1])
else else
aired = '' aired = ''
end end
if xml.find(result, 'Network') then if xml.find(result, 'Network') then
publisher = '\n*Publisher:* '..xml.find(result, 'Network')[1] publisher = '\n*Publisher:* '..xml.find(result, 'Network')[1]
else else
publisher = '' publisher = ''
end end
if xml.find(result, 'IMDB_ID') then if xml.find(result, 'IMDB_ID') then
imdb = '\n[IMDB-Seite](http://www.imdb.com/title/'..xml.find(result, 'IMDB_ID')[1]..')' imdb = '\n[IMDB-Seite](http://www.imdb.com/title/'..xml.find(result, 'IMDB_ID')[1]..')'
else else
imdb = '' imdb = ''
end end
local text = '*'..title..'*'..alias..aired..publisher..imdb..desc..'\n[TVDB-Seite besuchen](http://thetvdb.com/?id='..id..'&tab=series)' local text = '*'..title..'*'..alias..aired..publisher..imdb..desc..'\n[TVDB-Seite besuchen](http://thetvdb.com/?id='..id..'&tab=series)'
if xml.find(result, 'banner') then if xml.find(result, 'banner') then
local image_url = 'http://www.thetvdb.com/banners/'..xml.find(result, 'banner')[1] local image_url = 'http://www.thetvdb.com/banners/'..xml.find(result, 'banner')[1]
utilities.send_typing(msg.chat.id, 'upload_photo') utilities.send_typing(msg.chat.id, 'upload_photo')
utilities.send_photo(msg.chat.id, image_url, nil, msg.message_id) utilities.send_photo(msg.chat.id, image_url, nil, msg.message_id)
end end
utilities.send_reply(msg, text, true) utilities.send_reply(msg, text, true)
end end
function tv:action(msg, config, matches) function tv:action(msg, config, matches)
local series = URL.escape(matches[1]) local series = URL.escape(matches[1])
local tv_info = tv:get_tv_info(series) local tv_info = tv:get_tv_info(series)
if tv_info == "NOTFOUND" then if tv_info == "NOTFOUND" then
utilities.send_reply(msg, config.errors.results) utilities.send_reply(msg, config.errors.results)
return return
elseif tv_info == "HTTP-ERROR" then elseif tv_info == "HTTP-ERROR" then
utilities.send_reply(msg, config.errors.connection) utilities.send_reply(msg, config.errors.connection)
return return
else else
tv:send_tv_data(tv_info, msg) tv:send_tv_data(tv_info, msg)
end end
end end
return tv return tv

View File

@ -1,36 +1,36 @@
local twitch = {} local twitch = {}
twitch.triggers = { twitch.triggers = {
"twitch.tv/([A-Za-z0-9-_-]+)" "twitch.tv/([A-Za-z0-9-_-]+)"
} }
local BASE_URL = 'https://api.twitch.tv' local BASE_URL = 'https://api.twitch.tv'
function twitch:send_twitch_info(twitch_name) function twitch:send_twitch_info(twitch_name)
local url = BASE_URL..'/kraken/channels/'..twitch_name local url = BASE_URL..'/kraken/channels/'..twitch_name
local res,code = https.request(url) local res,code = https.request(url)
if code ~= 200 then return "HTTP-FEHLER" end if code ~= 200 then return "HTTP-FEHLER" end
local data = json.decode(res) local data = json.decode(res)
local display_name = data.display_name local display_name = data.display_name
local name = data.name local name = data.name
if not data.game then if not data.game then
game = 'nichts' game = 'nichts'
else else
game = data.game game = data.game
end end
local status = data.status local status = data.status
local views = comma_value(data.views) local views = comma_value(data.views)
local followers = comma_value(data.followers) local followers = comma_value(data.followers)
local text = '*'..display_name..'* ('..name..') streamt *'..game..'*\n'..status..'\n_'..views..' Zuschauer insgesamt und '..followers..' Follower_' local text = '*'..display_name..'* ('..name..') streamt *'..game..'*\n'..status..'\n_'..views..' Zuschauer insgesamt und '..followers..' Follower_'
return text return text
end end
function twitch:action(msg, config, matches) function twitch:action(msg, config, matches)
local text = twitch:send_twitch_info(matches[1]) local text = twitch:send_twitch_info(matches[1])
if not text then utilities.send_reply(msg, config.errors.connection) return end if not text then utilities.send_reply(msg, config.errors.connection) return end
utilities.send_reply(msg, text, true) utilities.send_reply(msg, text, true)
end end
return twitch return twitch

View File

@ -1,54 +0,0 @@
local wiimmfi = {}
function wiimmfi:init(config)
wiimmfi.triggers = {
"^/(mkw)$",
"^/wiimmfi$",
"^/wfc$"
}
wiimmfi.doc = [[*
]]..config.cmd_pat..[[wfc*: Zeigt alle Wiimmfi-Spieler an
*]]..config.cmd_pat..[[mkw*: Zeigt alle Mario-Kart-Wii-Spieler an]]
end
wiimmfi.command = 'wfc, /mkw'
function wiimmfi:getplayer(game)
local url = 'http://wiimmfi.de/game'
local res,code = http.request(url)
if code ~= 200 then return "Fehler beim Abrufen von wiimmfi.de" end
if game == 'mkw' then
local players = string.match(res, "<td align%=center><a href%=\"/game/mariokartwii\".->(.-)</a>")
if players == nil then players = 0 end
text = 'Es spielen gerade '..players..' Spieler Mario Kart Wii'
else
local players = string.match(res, "</tr><tr.->(.-)<th colspan%=3")
local players = string.gsub(players, "</a></td><td>.-<a href=\".-\">", ": ")
local players = string.gsub(players, "<td.->", "")
local players = string.gsub(players, "Wii</td>", "")
local players = string.gsub(players, "WiiWare</td>", "")
local players = string.gsub(players, "NDS</td>", "")
local players = string.gsub(players, "<th.->", "")
local players = string.gsub(players, "<tr.->", "")
local players = string.gsub(players, "</tr>", "")
local players = string.gsub(players, "</th>", "")
local players = string.gsub(players, "<a.->", "")
local players = string.gsub(players, "</a>", "")
local players = string.gsub(players, "</td>", "")
if players == nil then players = 'Momentan spielt keiner auf Wiimmfi :(' end
text = players
end
return text
end
function wiimmfi:action(msg, config, matches)
if matches[1] == "mkw" then
utilities.send_reply(msg, wiimmfi:getplayer('mkw'))
return
else
utilities.send_reply(msg, wiimmfi:getplayer())
return
end
end
return wiimmfi

View File

@ -27,14 +27,14 @@ function send_wikia_article(wikia, article)
local abstract = data.items[id].abstract local abstract = data.items[id].abstract
local article_url = data.basepath..data.items[id].url local article_url = data.basepath..data.items[id].url
local text = '*'..title..'*:\n'..abstract..' [Weiterlesen]('..article_url..')' local text = '<b>'..title..'</b>:\n'..abstract..' <a href="'..article_url..'">Weiterlesen</a>'
return text return text
end end
function wikia:action(msg, config, matches) function wikia:action(msg, config, matches)
local wikia = matches[1] local wikia = matches[1]
local article = matches[2] local article = matches[2]
utilities.send_reply(msg, send_wikia_article(wikia, article), true) utilities.send_reply(msg, send_wikia_article(wikia, article), 'HTML')
end end
return wikia return wikia

View File

@ -1,53 +1,53 @@
local yourls = {} local yourls = {}
function yourls:init(config) function yourls:init(config)
if not cred_data.yourls_site_url then if not cred_data.yourls_site_url then
print('Fehlender Key: yourls_site_url.') print('Fehlender Key: yourls_site_url.')
print('yourls.lua wird nicht aktiviert.') print('yourls.lua wird nicht aktiviert.')
return return
elseif not cred_data.yourls_signature_token then elseif not cred_data.yourls_signature_token then
print('Fehlender Key: yourls_signature_token.') print('Fehlender Key: yourls_signature_token.')
print('yourls.lua wird nicht aktiviert.') print('yourls.lua wird nicht aktiviert.')
return return
end end
yourls.triggers = { yourls.triggers = {
"^/yourls (https?://[%w-_%.%?%.:/%+=&]+)" "^/yourls (https?://[%w-_%.%?%.:/%+=&]+)"
} }
end end
local SITE_URL = cred_data.yourls_site_url local SITE_URL = cred_data.yourls_site_url
local signature = cred_data.yourls_signature_token local signature = cred_data.yourls_signature_token
local BASE_URL = SITE_URL..'/yourls-api.php' local BASE_URL = SITE_URL..'/yourls-api.php'
function yourls:prot_url(url) function yourls:prot_url(url)
local url, h = string.gsub(url, "http://", "") local url, h = string.gsub(url, "http://", "")
local url, hs = string.gsub(url, "https://", "") local url, hs = string.gsub(url, "https://", "")
local protocol = "http" local protocol = "http"
if hs == 1 then if hs == 1 then
protocol = "https" protocol = "https"
end end
return url, protocol return url, protocol
end end
function yourls:create_yourls_link(long_url, protocol) function yourls:create_yourls_link(long_url, protocol)
local url = BASE_URL..'?format=simple&signature='..signature..'&action=shorturl&url='..long_url local url = BASE_URL..'?format=simple&signature='..signature..'&action=shorturl&url='..long_url
if protocol == "http" then if protocol == "http" then
link,code = http.request(url) link,code = http.request(url)
else else
link,code = https.request(url) link,code = https.request(url)
end end
if code ~= 200 then if code ~= 200 then
link = 'Ein Fehler ist aufgetreten. '..link link = 'Ein Fehler ist aufgetreten. '..link
end end
return link return link
end end
function yourls:action(msg, config, matches) function yourls:action(msg, config, matches)
local long_url = matches[1] local long_url = matches[1]
local baseurl, protocol = yourls:prot_url(SITE_URL) local baseurl, protocol = yourls:prot_url(SITE_URL)
utilities.send_reply(msg, yourls:create_yourls_link(long_url, protocol)) utilities.send_reply(msg, yourls:create_yourls_link(long_url, protocol))
return return
end end
return yourls return yourls

View File

@ -98,15 +98,15 @@ function send_youtube_data(data, msg, self, link, sendpic)
local upload_date = makeOurDate(data.snippet.publishedAt) local upload_date = makeOurDate(data.snippet.publishedAt)
local viewCount = comma_value(data.statistics.viewCount) local viewCount = comma_value(data.statistics.viewCount)
if data.statistics.likeCount then if data.statistics.likeCount then
likeCount = ', '..comma_value(data.statistics.likeCount)..' Likes und ' likeCount = ' | 👍 <i>'..comma_value(data.statistics.likeCount)..'</i> |'
dislikeCount = comma_value(data.statistics.dislikeCount)..' Dislikes' dislikeCount = ' 👎 <i>'..comma_value(data.statistics.dislikeCount)..'</i>'
else else
likeCount = '' likeCount = ''
dislikeCount = '' dislikeCount = ''
end end
if data.statistics.commentCount then if data.statistics.commentCount then
commentCount = ', '..comma_value(data.statistics.commentCount)..' Kommentare' commentCount = ' | 🗣 <i>'..comma_value(data.statistics.commentCount)..'</i>'
else else
commentCount = '' commentCount = ''
end end
@ -120,7 +120,7 @@ function send_youtube_data(data, msg, self, link, sendpic)
blocked = false blocked = false
end end
text = '<b>'..title..'</b>\n<i>('..uploader..' am '..upload_date..', '..viewCount..'x angesehen, Länge: '..duration..likeCount..dislikeCount..commentCount..')</i>\n' text = '<b>'..title..'</b>\n🎥 <b>'..uploader..'</b>, 📅 <i>'..upload_date..'</i>\n👁 <i>'..viewCount..'</i> | 🕒 <i>'..duration..'</i>'..likeCount..dislikeCount..commentCount..'\n'
if link then if link then
text = link..'\n'..text text = link..'\n'..text
end end
@ -132,7 +132,7 @@ function send_youtube_data(data, msg, self, link, sendpic)
if sendpic then if sendpic then
local image_url = get_yt_thumbnail(data) local image_url = get_yt_thumbnail(data)
-- need to change text, because Telegram captions can only be 200 characters long and don't support Markdown -- need to change text, because Telegram captions can only be 200 characters long and don't support Markdown
local text = link..'\n'..title..'\n('..uploader..' am '..upload_date..', '..viewCount..'x angesehen, Länge: '..duration..')' local text = link..'\n'..title..'\n🎥 '..uploader..', 📅 '..upload_date..'\n👁 '..viewCount..' | 🕒 '..duration..likeCount..dislikeCount..commentCount..'\n'
if blocked then if blocked then
text = text..'\nACHTUNG, In Deutschland gesperrt!' text = text..'\nACHTUNG, In Deutschland gesperrt!'
end end