diff --git a/miku/bot.lua b/miku/bot.lua index a8a7103..ce2fef9 100644 --- a/miku/bot.lua +++ b/miku/bot.lua @@ -429,7 +429,7 @@ function create_plugin_set() 'echo', 'banhammer', 'plugins', - 'settings', + 'respond', 'help' } print ('Aktiviere Plugins und speicher in telegram:enabled_plugins') diff --git a/miku/plugins/9gag.lua b/miku/plugins/9gag.lua index 5402a87..b04e81a 100644 --- a/miku/plugins/9gag.lua +++ b/miku/plugins/9gag.lua @@ -1,62 +1,62 @@ -local ninegag = {} - -ninegag.command = '9gag' - -function ninegag:init(config) - ninegag.triggers = { - "^/9[Gg][Aa][Gg]$", - "^/9[Ff][Aa][Gg]$" - } - ninegag.inline_triggers = { - "^9[Gg][Aa][Gg]" - } - ninegag.doc = [[* -]]..config.cmd_pat..[[9gag*: Gibt ein zufälliges Bild von den momentan populärsten 9GAG-Posts aus]] -end - -local url = "http://api-9gag.herokuapp.com/" - -function ninegag:get_9GAG() - local b,c = http.request(url) - if c ~= 200 then return nil end - local gag = json.decode(b) - -- random max json table size - local i = math.random(#gag) - - local link_image = gag[i].src - local title = gag[i].title - local post_url = gag[i].url - return link_image, title, post_url -end - -function ninegag:inline_callback(inline_query, config) - local res, code = http.request(url) - if code ~= 200 then abort_inline_query(inline_query) return end - local gag = json.decode(res) - - local results = '[' - local id = 50 - for n in pairs(gag) do - 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..'"}]]}}' - id = id+1 - if n < #gag then - results = results..',' - end - end - local results = results..']' - utilities.answer_inline_query(inline_query, results, 300) -end - -function ninegag:action(msg, config) - utilities.send_typing(msg.chat.id, 'upload_photo') - local url, title, post_url = ninegag:get_9GAG() - if not url then - utilities.send_reply(msg, config.errors.connection) - return - end - - utilities.send_photo(msg.chat.id, url, title, msg.message_id, '{"inline_keyboard":[[{"text":"Post aufrufen","url":"'..post_url..'"}]]}') -end - +local ninegag = {} + +ninegag.command = '9gag' + +function ninegag:init(config) + ninegag.triggers = { + "^/9[Gg][Aa][Gg]$", + "^/9[Ff][Aa][Gg]$" + } + ninegag.inline_triggers = { + "^9[Gg][Aa][Gg]" + } + ninegag.doc = [[* +]]..config.cmd_pat..[[9gag*: Gibt ein zufälliges Bild von den momentan populärsten 9GAG-Posts aus]] +end + +local url = "http://api-9gag.herokuapp.com/" + +function ninegag:get_9GAG() + local b,c = http.request(url) + if c ~= 200 then return nil end + local gag = json.decode(b) + -- random max json table size + local i = math.random(#gag) + + local link_image = gag[i].src + local title = gag[i].title + local post_url = gag[i].url + return link_image, title, post_url +end + +function ninegag:inline_callback(inline_query, config) + local res, code = http.request(url) + if code ~= 200 then abort_inline_query(inline_query) return end + local gag = json.decode(res) + + local results = '[' + local id = 50 + for n in pairs(gag) do + 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..'"}]]}}' + id = id+1 + if n < #gag then + results = results..',' + end + end + local results = results..']' + utilities.answer_inline_query(inline_query, results, 300) +end + +function ninegag:action(msg, config) + utilities.send_typing(msg.chat.id, 'upload_photo') + local url, title, post_url = ninegag:get_9GAG() + if not url then + utilities.send_reply(msg, config.errors.connection) + return + end + + utilities.send_photo(msg.chat.id, url, title, msg.message_id, '{"inline_keyboard":[[{"text":"Post aufrufen","url":"'..post_url..'"}]]}') +end + return ninegag \ No newline at end of file diff --git a/miku/plugins/afk.lua b/miku/plugins/afk.lua index 8af65e6..ef9f5f1 100644 --- a/miku/plugins/afk.lua +++ b/miku/plugins/afk.lua @@ -1,124 +1,124 @@ --- original plugin by Akamaru [https://ponywave.de] --- I added Redis and automatic online switching back in 2015 - -local afk = {} - -function afk:init(config) - afk.triggers = { - "^/([Aa][Ff][Kk])$", - "^/([Aa][Ff][Kk]) (.*)$" - } - afk.doc = [[* -]]..config.cmd_pat..[[afk* _[Text]_: Setzt Status auf AFK mit optionalem Text]] -end - -afk.command = 'afk [Text]' - -function afk:is_offline(hash) - local afk = redis:hget(hash, 'afk') - if afk == "true" then - return true - else - return false - end -end - -function afk:get_afk_text(hash) - local afk_text = redis:hget(hash, 'afk_text') - if afk_text ~= nil and afk_text ~= "" and afk_text ~= "false" then - return afk_text - else - return false - end -end - -function afk:switch_afk(user_name, user_id, chat_id, timestamp, text) - local hash = 'afk:'..chat_id..':'..user_id - - if afk:is_offline(hash) then - local afk_text = afk:get_afk_text(hash) - if afk_text then - return 'Du bist bereits AFK! ('..afk_text..')' - else - return 'Du bist bereits AFK!' - end - end - - print('Setting redis hash afk in '..hash..' to true') - redis:hset(hash, 'afk', true) - print('Setting redis hash timestamp in '..hash..' to '..timestamp) - redis:hset(hash, 'time', timestamp) - - if text then - print('Setting redis hash afk_text in '..hash..' to '..text) - redis:hset(hash, 'afk_text', text) - return user_name..' ist AFK! ('..text..')' - else - return user_name..' ist AFK!' - end -end - -function afk:pre_process(msg) - if msg.chat.type == "private" then - -- Ignore - return msg - end - - local user_name = get_name(msg) - local user_id = msg.from.id - local chat_id = msg.chat.id - local hash = 'afk:'..chat_id..':'..user_id - local uhash = 'user:'..user_id - - if afk:is_offline(hash) then - local afk_text = afk:get_afk_text(hash) - - -- calculate afk time - local timestamp = redis:hget(hash, 'time') - local current_timestamp = msg.date - local afk_time = current_timestamp - timestamp - local duration = makeHumanTime(afk_time) - - redis:hset(hash, 'afk', false) - local show_afk_keyboard = redis:hget(uhash, 'afk_keyboard') - if afk_text then - redis:hset(hash, 'afk_text', false) - if show_afk_keyboard == 'true' then - utilities.send_reply(msg, user_name..' ist wieder da! (war: '..afk_text..' für '..duration..')', 'HTML', '{"hide_keyboard":true,"selective":true}') - else - utilities.send_message(chat_id, user_name..' ist wieder da! (war: '..afk_text..' für '..duration..')', true, nil, 'HTML') - end - else - if show_afk_keyboard == 'true' then - utilities.send_reply(msg, user_name..' ist wieder da! (war '..duration..' weg)', nil, '{"hide_keyboard":true,"selective":true}') - else - utilities.send_message(chat_id, user_name..' ist wieder da! (war '..duration..' weg)') - end - end - end - - return msg -end - -function afk:action(msg, config, matches) - if msg.chat.type == "private" then - utilities.send_reply(msg, "Mir ist's egal, ob du AFK bist.") - return - end - - local user_id = msg.from.id - local chat_id = msg.chat.id - local user_name = get_name(msg) - local timestamp = msg.date - local uhash = 'user:'..msg.from.id - local show_afk_keyboard = redis:hget(uhash, 'afk_keyboard') - if show_afk_keyboard == 'true' then - keyboard = '{"keyboard":[[{"text":"Wieder da."}]], "one_time_keyboard":true, "selective":true, "resize_keyboard":true}' - else - keyboard = nil - end - - utilities.send_reply(msg, afk:switch_afk(user_name, user_id, chat_id, timestamp, matches[2]), false, keyboard) -end - +-- original plugin by Akamaru [https://ponywave.de] +-- I added Redis and automatic online switching back in 2015 + +local afk = {} + +function afk:init(config) + afk.triggers = { + "^/([Aa][Ff][Kk])$", + "^/([Aa][Ff][Kk]) (.*)$" + } + afk.doc = [[* +]]..config.cmd_pat..[[afk* _[Text]_: Setzt Status auf AFK mit optionalem Text]] +end + +afk.command = 'afk [Text]' + +function afk:is_offline(hash) + local afk = redis:hget(hash, 'afk') + if afk == "true" then + return true + else + return false + end +end + +function afk:get_afk_text(hash) + local afk_text = redis:hget(hash, 'afk_text') + if afk_text ~= nil and afk_text ~= "" and afk_text ~= "false" then + return afk_text + else + return false + end +end + +function afk:switch_afk(user_name, user_id, chat_id, timestamp, text) + local hash = 'afk:'..chat_id..':'..user_id + + if afk:is_offline(hash) then + local afk_text = afk:get_afk_text(hash) + if afk_text then + return 'Du bist bereits AFK! ('..afk_text..')' + else + return 'Du bist bereits AFK!' + end + end + + print('Setting redis hash afk in '..hash..' to true') + redis:hset(hash, 'afk', true) + print('Setting redis hash timestamp in '..hash..' to '..timestamp) + redis:hset(hash, 'time', timestamp) + + if text then + print('Setting redis hash afk_text in '..hash..' to '..text) + redis:hset(hash, 'afk_text', text) + return user_name..' ist AFK! ('..text..')' + else + return user_name..' ist AFK!' + end +end + +function afk:pre_process(msg) + if msg.chat.type == "private" then + -- Ignore + return msg + end + + local user_name = get_name(msg) + local user_id = msg.from.id + local chat_id = msg.chat.id + local hash = 'afk:'..chat_id..':'..user_id + local uhash = 'user:'..user_id + + if afk:is_offline(hash) then + local afk_text = afk:get_afk_text(hash) + + -- calculate afk time + local timestamp = redis:hget(hash, 'time') + local current_timestamp = msg.date + local afk_time = current_timestamp - timestamp + local duration = makeHumanTime(afk_time) + + redis:hset(hash, 'afk', false) + local show_afk_keyboard = redis:hget(uhash, 'afk_keyboard') + if afk_text then + redis:hset(hash, 'afk_text', false) + if show_afk_keyboard == 'true' then + utilities.send_reply(msg, user_name..' ist wieder da! (war: '..afk_text..' für '..duration..')', 'HTML', '{"hide_keyboard":true,"selective":true}') + else + utilities.send_message(chat_id, user_name..' ist wieder da! (war: '..afk_text..' für '..duration..')', true, nil, 'HTML') + end + else + if show_afk_keyboard == 'true' then + utilities.send_reply(msg, user_name..' ist wieder da! (war '..duration..' weg)', nil, '{"hide_keyboard":true,"selective":true}') + else + utilities.send_message(chat_id, user_name..' ist wieder da! (war '..duration..' weg)') + end + end + end + + return msg +end + +function afk:action(msg, config, matches) + if msg.chat.type == "private" then + utilities.send_reply(msg, "Mir ist's egal, ob du AFK bist.") + return + end + + local user_id = msg.from.id + local chat_id = msg.chat.id + local user_name = get_name(msg) + local timestamp = msg.date + local uhash = 'user:'..msg.from.id + local show_afk_keyboard = redis:hget(uhash, 'afk_keyboard') + if show_afk_keyboard == 'true' then + keyboard = '{"keyboard":[[{"text":"Wieder da."}]], "one_time_keyboard":true, "selective":true, "resize_keyboard":true}' + else + keyboard = nil + end + + utilities.send_reply(msg, afk:switch_afk(user_name, user_id, chat_id, timestamp, matches[2]), false, keyboard) +end + return afk \ No newline at end of file diff --git a/miku/plugins/bitly_create.lua b/miku/plugins/bitly_create.lua deleted file mode 100644 index 12366cf..0000000 --- a/miku/plugins/bitly_create.lua +++ /dev/null @@ -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* __: Kürzt einen Link mit der Standard Bitly-Adresse -*]]..config.cmd_pat..[[short* __ _[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 ' - -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 \ No newline at end of file diff --git a/miku/plugins/btc.lua b/miku/plugins/btc.lua deleted file mode 100644 index 068deb5..0000000 --- a/miku/plugins/btc.lua +++ /dev/null @@ -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 \ No newline at end of file diff --git a/miku/plugins/cats.lua b/miku/plugins/cats.lua index 2dc143a..6555e7c 100644 --- a/miku/plugins/cats.lua +++ b/miku/plugins/cats.lua @@ -1,112 +1,112 @@ -local cats = {} - -cats.command = 'kitty [gif]' - -function cats:init(config) - if not cred_data.cat_apikey then - print('Fehlender Key: cat_apikey.') - print('cats.lua wird aktiviert, aber mit einem Key gibt es mehr Features.') - end - - cats.triggers = { - "^/[Kk][Ii][Tt][Tt][Yy]$", - "^/[Kk][Ii][Tt][Tt][Yy] (gif)$" - } - - cats.inline_triggers = { - "^[Kk][Ii][Tt][Tt][Yy] (gif)$", - "^[Kk][Ii][Tt][Tt][Yy]$" - } - - cats.doc = [[* -]]..config.cmd_pat..[[kitty*: Postet eine zufällige Katze -*]]..config.cmd_pat..[[kitty* _gif_: Postet eine zufällige, animierte Katze]] -end - -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' - -function cats:inline_callback(inline_query, config, matches) - if matches[1] == 'gif' then - img_type = 'gif' - id = 100 - else - img_type = 'jpg' - id = 200 - 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 res, code = https.request(url) - if code ~= 200 then return end - local data = json.decode(res).query.results.response.data.images.image - if not data then return end - if not data[1] then return end - - local results = '[' - - for n in pairs(data) do - if img_type == 'gif' then - results = results..'{"type":"gif","id":"'..id..'","gif_url":"'..data[n].url..'","thumb_url":"'..data[n].url..'"}' - id = id+1 - else - results = results..'{"type":"photo","id":"'..id..'","photo_url":"'..data[n].url..'","thumb_url":"'..data[n].url..'"}' - id = id+1 - end - if n < #data then - results = results..',' - end - end - local results = results..']' - utilities.answer_inline_query(inline_query, results, 30) -end - -function cats:get_cat(gif) - if gif then - local url = BASE_URL..'?type=gif&apikey='..apikey - file = download_to_file(url, 'miau.gif') - else - local url = BASE_URL..'?type=jpg,png&apikey='..apikey - file = download_to_file(url, 'miau.png') - end - return file -end - -function cats:callback(callback, msg, self, config, input) - utilities.answer_callback_query(callback, 'Miau!') - utilities.send_typing(msg.chat.id, 'upload_photo') - if string.isempty(input) then - local file = cats:get_cat() - if not file then - utilities.answer_callback_query(callback, 'Beim Herunterladen ist ein Fehler aufgetreten :(', true) - return - end - utilities.send_photo(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Nochmal!","callback_data":"cats:"}]]}') - else - local file = cats:get_cat(true) - if not file then - utilities.answer_callback_query(callback, 'Beim Herunterladen ist ein Fehler aufgetreten :(', true) - return - end - utilities.send_document(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Nochmal!","callback_data":"cats:gif"}]]}') - end -end - -function cats:action(msg, config, matches) - utilities.send_typing(msg.chat.id, 'upload_photo') - if matches[1] == 'gif' then - local file = cats:get_cat(true) - if not file then - utilities.send_reply(msg, config.errors.connection) - return - end - utilities.send_document(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Nochmal!","callback_data":"cats:gif"}]]}') - else - local file = cats:get_cat() - if not file then - utilities.send_reply(msg, config.errors.connection) - return - end - utilities.send_photo(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Nochmal!","callback_data":"cats:"}]]}') - end -end - +local cats = {} + +cats.command = 'kitty [gif]' + +function cats:init(config) + if not cred_data.cat_apikey then + print('Fehlender Key: cat_apikey.') + print('cats.lua wird aktiviert, aber mit einem Key gibt es mehr Features.') + end + + cats.triggers = { + "^/[Kk][Ii][Tt][Tt][Yy]$", + "^/[Kk][Ii][Tt][Tt][Yy] (gif)$" + } + + cats.inline_triggers = { + "^[Kk][Ii][Tt][Tt][Yy] (gif)$", + "^[Kk][Ii][Tt][Tt][Yy]$" + } + + cats.doc = [[* +]]..config.cmd_pat..[[kitty*: Postet eine zufällige Katze +*]]..config.cmd_pat..[[kitty* _gif_: Postet eine zufällige, animierte Katze]] +end + +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' + +function cats:inline_callback(inline_query, config, matches) + if matches[1] == 'gif' then + img_type = 'gif' + id = 100 + else + img_type = 'jpg' + id = 200 + 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 res, code = https.request(url) + if code ~= 200 then return end + local data = json.decode(res).query.results.response.data.images.image + if not data then return end + if not data[1] then return end + + local results = '[' + + for n in pairs(data) do + if img_type == 'gif' then + results = results..'{"type":"gif","id":"'..id..'","gif_url":"'..data[n].url..'","thumb_url":"'..data[n].url..'"}' + id = id+1 + else + results = results..'{"type":"photo","id":"'..id..'","photo_url":"'..data[n].url..'","thumb_url":"'..data[n].url..'"}' + id = id+1 + end + if n < #data then + results = results..',' + end + end + local results = results..']' + utilities.answer_inline_query(inline_query, results, 30) +end + +function cats:get_cat(gif) + if gif then + local url = BASE_URL..'?type=gif&apikey='..apikey + file = download_to_file(url, 'miau.gif') + else + local url = BASE_URL..'?type=jpg,png&apikey='..apikey + file = download_to_file(url, 'miau.png') + end + return file +end + +function cats:callback(callback, msg, self, config, input) + utilities.answer_callback_query(callback, 'Miau!') + utilities.send_typing(msg.chat.id, 'upload_photo') + if string.isempty(input) then + local file = cats:get_cat() + if not file then + utilities.answer_callback_query(callback, 'Beim Herunterladen ist ein Fehler aufgetreten :(', true) + return + end + utilities.send_photo(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Nochmal!","callback_data":"cats:"}]]}') + else + local file = cats:get_cat(true) + if not file then + utilities.answer_callback_query(callback, 'Beim Herunterladen ist ein Fehler aufgetreten :(', true) + return + end + utilities.send_document(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Nochmal!","callback_data":"cats:gif"}]]}') + end +end + +function cats:action(msg, config, matches) + utilities.send_typing(msg.chat.id, 'upload_photo') + if matches[1] == 'gif' then + local file = cats:get_cat(true) + if not file then + utilities.send_reply(msg, config.errors.connection) + return + end + utilities.send_document(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Nochmal!","callback_data":"cats:gif"}]]}') + else + local file = cats:get_cat() + if not file then + utilities.send_reply(msg, config.errors.connection) + return + end + utilities.send_photo(msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Nochmal!","callback_data":"cats:"}]]}') + end +end + return cats \ No newline at end of file diff --git a/miku/plugins/clypit.lua b/miku/plugins/clypit.lua deleted file mode 100644 index 893ad62..0000000 --- a/miku/plugins/clypit.lua +++ /dev/null @@ -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 diff --git a/miku/plugins/deviantart.lua b/miku/plugins/deviantart.lua index 2cc2fc7..a826504 100644 --- a/miku/plugins/deviantart.lua +++ b/miku/plugins/deviantart.lua @@ -1,48 +1,48 @@ -local deviantart = {} - -deviantart.triggers = { - "http://(.*).deviantart.com/art/(.*)" -} - -local BASE_URL = 'https://backend.deviantart.com' - -function deviantart:get_da_data (da_code) - local url = BASE_URL..'/oembed?url='..da_code - local res,code = https.request(url) - if code ~= 200 then return nil end - local data = json.decode(res) - return data -end - -function deviantart:send_da_data (data) - local title = data.title - local category = data.category - local author_name = data.author_name - local text = title..' von '..author_name..'\n'..category - - if data.rating == "adult" then - return title..' von '..author_name..'\n'..category..'\n(NSFW)' - else - local image_url = data.fullsize_url - if image_url == nil then - image_url = data.url - end - local file = download_to_file(image_url) - return text, file - end -end - -function deviantart:action(msg, config, matches) - local data = deviantart:get_da_data('http://'..matches[1]..'.deviantart.com/art/'..matches[2]) - if not data then utilities.send_reply(msg, config.errors.connection) return end - - local text, file = deviantart:send_da_data(data) - if file then - utilities.send_photo(msg.chat.id, file, text, msg.message_id) - else - utilities.send_reply(msg, text) - return - end -end - -return deviantart +local deviantart = {} + +deviantart.triggers = { + "http://(.*).deviantart.com/art/(.*)" +} + +local BASE_URL = 'https://backend.deviantart.com' + +function deviantart:get_da_data (da_code) + local url = BASE_URL..'/oembed?url='..da_code + local res,code = https.request(url) + if code ~= 200 then return nil end + local data = json.decode(res) + return data +end + +function deviantart:send_da_data (data) + local title = data.title + local category = data.category + local author_name = data.author_name + local text = title..' von '..author_name..'\n'..category + + if data.rating == "adult" then + return title..' von '..author_name..'\n'..category..'\n(NSFW)' + else + local image_url = data.fullsize_url + if image_url == nil then + image_url = data.url + end + local file = download_to_file(image_url) + return text, file + end +end + +function deviantart:action(msg, config, matches) + local data = deviantart:get_da_data('http://'..matches[1]..'.deviantart.com/art/'..matches[2]) + if not data then utilities.send_reply(msg, config.errors.connection) return end + + local text, file = deviantart:send_da_data(data) + if file then + utilities.send_photo(msg.chat.id, file, text, msg.message_id) + else + utilities.send_reply(msg, text) + return + end +end + +return deviantart diff --git a/miku/plugins/dhl.lua b/miku/plugins/dhl.lua deleted file mode 100644 index e6b1fd2..0000000 --- a/miku/plugins/dhl.lua +++ /dev/null @@ -1,34 +0,0 @@ -local dhl = {} - -function dhl:init(config) - dhl.triggers = { - '/[Dd][Hh][Ll] (%d+)$' - } - dhl.doc = [[* -]]..config.cmd_pat..[[dhl* __: 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, "
(.-)
") - local status = utilities.trim(status) - local zeit = string.match(res, "
(.-)
") - local zeit = utilities.trim(zeit) - if not zeit or zeit == '
' 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 diff --git a/miku/plugins/flickr_search.lua b/miku/plugins/flickr_search.lua index c99e0a6..e30b3d0 100644 --- a/miku/plugins/flickr_search.lua +++ b/miku/plugins/flickr_search.lua @@ -1,73 +1,73 @@ -local flickr_search = {} - -function flickr_search:init(config) - if not cred_data.flickr_apikey then - print('Fehlender Key: flickr_apikey.') - print('flickr_search.lua wird nicht aktiviert.') - return - end - - flickr_search.triggers = { - '^/[Ff][Ll][Ii][Cc][Kk][Rr] (.*)' - } -end - -flickr_search.command = 'flickr ' - -local apikey = cred_data.flickr_apikey -local BASE_URL = 'https://api.flickr.com/services/rest' - -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 b,c = https.request(url) - if c ~= 200 then return nil end - local photo = json.decode(b).photos.photo - if not photo[1] then return nil end - - -- truly randomize - math.randomseed(os.time()) - -- random max json table size - local i = math.random(#photo) - - local link_image = photo[i].url_l or photo[i].url_o - local orig_image = photo[i].url_o or link_image - local title = photo[i].title - if title:len() > 200 then - title = title:sub(1, 197) .. '...' - end - - return link_image, title, orig_image -end - -function flickr_search:callback(callback, msg, self, config, input) - utilities.send_typing(msg.chat.id, 'upload_photo') - local input = URL.unescape(input) - utilities.answer_callback_query(callback, 'Suche nochmal nach "'..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 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)..'"}]]}') - return - 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)..'"}]]}') - return - end -end - -function flickr_search:action(msg, config, matches) - utilities.send_typing(msg.chat.id, 'upload_photo') - local url, title, orig = flickr_search:get_flickr(matches[1]) - if not url then utilities.send_reply(msg, config.errors.results) return end - - 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])..'"}]]}') - return - 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])..'"}]]}') - return - end -end - +local flickr_search = {} + +function flickr_search:init(config) + if not cred_data.flickr_apikey then + print('Fehlender Key: flickr_apikey.') + print('flickr_search.lua wird nicht aktiviert.') + return + end + + flickr_search.triggers = { + '^/[Ff][Ll][Ii][Cc][Kk][Rr] (.*)' + } +end + +flickr_search.command = 'flickr ' + +local apikey = cred_data.flickr_apikey +local BASE_URL = 'https://api.flickr.com/services/rest' + +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 b,c = https.request(url) + if c ~= 200 then return nil end + local photo = json.decode(b).photos.photo + if not photo[1] then return nil end + + -- truly randomize + math.randomseed(os.time()) + -- random max json table size + local i = math.random(#photo) + + local link_image = photo[i].url_l or photo[i].url_o + local orig_image = photo[i].url_o or link_image + local title = photo[i].title + if title:len() > 200 then + title = title:sub(1, 197) .. '...' + end + + return link_image, title, orig_image +end + +function flickr_search:callback(callback, msg, self, config, input) + utilities.send_typing(msg.chat.id, 'upload_photo') + local input = URL.unescape(input) + utilities.answer_callback_query(callback, 'Suche nochmal nach "'..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 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)..'"}]]}') + return + 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)..'"}]]}') + return + end +end + +function flickr_search:action(msg, config, matches) + utilities.send_typing(msg.chat.id, 'upload_photo') + local url, title, orig = flickr_search:get_flickr(matches[1]) + if not url then utilities.send_reply(msg, config.errors.results) return end + + 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])..'"}]]}') + return + 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])..'"}]]}') + return + end +end + return flickr_search \ No newline at end of file diff --git a/miku/plugins/games.lua b/miku/plugins/games.lua index 0cb2346..c0b6f3f 100644 --- a/miku/plugins/games.lua +++ b/miku/plugins/games.lua @@ -1,144 +1,144 @@ -local games = {} - -local xml = require("xml") - -games.command = 'game ' - -function games:init(config) - games.triggers = { - "^/[Gg][Aa][Mm][Ee] (.+)$" - } - games.doc = [[* -]]..config.cmd_pat..[[game*_ _: Sendet Infos zum Spiel]] -end - -local BASE_URL = 'http://thegamesdb.net/api' - -local makeOurDate = function(dateString) - local pattern = "(%d+)%/(%d+)%/(%d+)" - local month, day, year = dateString:match(pattern) - return day..'.'..month..'.'..year -end - - -function games:get_game_id(game) - local url = BASE_URL..'/GetGamesList.php?name='..game - local res,code = http.request(url) - if code ~= 200 then return "HTTP-FEHLER" end - local result = xml.load(res) - if xml.find(result, 'id') then - local game = xml.find(result, 'id')[1] - return game - else - return nil - end -end - -function games:send_game_photo(result, self, msg) - local BASE_URL = xml.find(result, 'baseImgUrl')[1] - local images = {} - - if xml.find(result, 'boxart', 'side', 'front') then - local boxart = xml.find(result, 'boxart', 'side', 'front')[1] - local boxart_url = BASE_URL..boxart - table.insert(images, boxart_url) - end - - local i = 0 - for k, v in pairs(images) do - i = i+1 - utilities.send_photo(msg.chat.id, v, nil, msg.message_id) - end -end - -function games:send_game_data(game_id, self, msg) - local url = BASE_URL..'/GetGame.php?id='..game_id - local res,code = http.request(url) - if code ~= 200 then return nil end - local result = xml.load(res) - - local title = xml.find(result, 'GameTitle')[1] - local platform = xml.find(result, 'Platform')[1] - - if xml.find(result, 'ReleaseDate') then - date = ', erschienen am '..makeOurDate(xml.find(result, 'ReleaseDate')[1]) - else - date = '' - end - - if xml.find(result, 'Overview') then - desc = '\n_'..string.sub(xml.find(result, 'Overview')[1], 1, 200) .. '..._' - else - desc = '' - end - - if xml.find(result, 'Genres') then - local genres = xml.find(result, 'Genres') - local genre_count = #genres-1 - if genre_count == 1 then - genre = '\nGenre: '..genres[1][1] - else - local genre_loop = '\nGenres: ' - for v in pairs(genres) do - if v == 'xml' then break; end - if v < genre_count then - genre_loop = genre_loop..genres[v][1]..', ' - else - genre_loop = genre_loop..genres[v][1] - end - end - genre = genre_loop - end - else - genre = '' - end - - if xml.find(result, 'Players') then - players = '\nSpieler: '..xml.find(result, 'Players')[1] - else - players = '' - end - - if xml.find(result, 'Youtube') then - video = '\n[Video auf YouTube ansehen]('..xml.find(result, 'Youtube')[1]..')' - else - video = '' - end - - if xml.find(result, 'Publisher') then - publisher = '\nPublisher: '..xml.find(result, 'Publisher')[1] - else - publisher = '' - end - - local text = '*'..title..'* für *'..platform..'*'..date..desc..genre..players..video..publisher - utilities.send_reply(msg, text, true) - - if xml.find(result, 'boxart') then - utilities.send_typing(msg.chat.id, 'upload_photo') - games:send_game_photo(result, self, msg) - end - return -end - -function games:action(msg, config) - local game = utilities.input(msg.text) - if not game then - if msg.reply_to_message and msg.reply_to_message.text then - game = msg.reply_to_message.text - else - utilities.send_message(msg.chat.id, fun.doc, true, msg.message_id, true) - return - end - end - - local game_id = games:get_game_id(game) - if not game_id then - utilities.send_reply(msg, 'Spiel nicht gefunden!') - return - else - games:send_game_data(game_id, self, msg) - end -end - -return games +local games = {} + +local xml = require("xml") + +games.command = 'game ' + +function games:init(config) + games.triggers = { + "^/[Gg][Aa][Mm][Ee] (.+)$" + } + games.doc = [[* +]]..config.cmd_pat..[[game*_ _: Sendet Infos zum Spiel]] +end + +local BASE_URL = 'http://thegamesdb.net/api' + +local makeOurDate = function(dateString) + local pattern = "(%d+)%/(%d+)%/(%d+)" + local month, day, year = dateString:match(pattern) + return day..'.'..month..'.'..year +end + + +function games:get_game_id(game) + local url = BASE_URL..'/GetGamesList.php?name='..game + local res,code = http.request(url) + if code ~= 200 then return "HTTP-FEHLER" end + local result = xml.load(res) + if xml.find(result, 'id') then + local game = xml.find(result, 'id')[1] + return game + else + return nil + end +end + +function games:send_game_photo(result, self, msg) + local BASE_URL = xml.find(result, 'baseImgUrl')[1] + local images = {} + + if xml.find(result, 'boxart', 'side', 'front') then + local boxart = xml.find(result, 'boxart', 'side', 'front')[1] + local boxart_url = BASE_URL..boxart + table.insert(images, boxart_url) + end + + local i = 0 + for k, v in pairs(images) do + i = i+1 + utilities.send_photo(msg.chat.id, v, nil, msg.message_id) + end +end + +function games:send_game_data(game_id, self, msg) + local url = BASE_URL..'/GetGame.php?id='..game_id + local res,code = http.request(url) + if code ~= 200 then return nil end + local result = xml.load(res) + + local title = xml.find(result, 'GameTitle')[1] + local platform = xml.find(result, 'Platform')[1] + + if xml.find(result, 'ReleaseDate') then + date = ', erschienen am '..makeOurDate(xml.find(result, 'ReleaseDate')[1]) + else + date = '' + end + + if xml.find(result, 'Overview') then + desc = '\n_'..string.sub(xml.find(result, 'Overview')[1], 1, 200) .. '..._' + else + desc = '' + end + + if xml.find(result, 'Genres') then + local genres = xml.find(result, 'Genres') + local genre_count = #genres-1 + if genre_count == 1 then + genre = '\nGenre: '..genres[1][1] + else + local genre_loop = '\nGenres: ' + for v in pairs(genres) do + if v == 'xml' then break; end + if v < genre_count then + genre_loop = genre_loop..genres[v][1]..', ' + else + genre_loop = genre_loop..genres[v][1] + end + end + genre = genre_loop + end + else + genre = '' + end + + if xml.find(result, 'Players') then + players = '\nSpieler: '..xml.find(result, 'Players')[1] + else + players = '' + end + + if xml.find(result, 'Youtube') then + video = '\n[Video auf YouTube ansehen]('..xml.find(result, 'Youtube')[1]..')' + else + video = '' + end + + if xml.find(result, 'Publisher') then + publisher = '\nPublisher: '..xml.find(result, 'Publisher')[1] + else + publisher = '' + end + + local text = '*'..title..'* für *'..platform..'*'..date..desc..genre..players..video..publisher + utilities.send_reply(msg, text, true) + + if xml.find(result, 'boxart') then + utilities.send_typing(msg.chat.id, 'upload_photo') + games:send_game_photo(result, self, msg) + end + return +end + +function games:action(msg, config) + local game = utilities.input(msg.text) + if not game then + if msg.reply_to_message and msg.reply_to_message.text then + game = msg.reply_to_message.text + else + utilities.send_message(msg.chat.id, fun.doc, true, msg.message_id, true) + return + end + end + + local game_id = games:get_game_id(game) + if not game_id then + utilities.send_reply(msg, 'Spiel nicht gefunden!') + return + else + games:send_game_data(game_id, self, msg) + end +end + +return games diff --git a/miku/plugins/get.lua b/miku/plugins/get.lua index 2f2333b..1bc5d72 100644 --- a/miku/plugins/get.lua +++ b/miku/plugins/get.lua @@ -1,56 +1,56 @@ -local get = {} - -get.command = 'get ' - -function get:init(config) - get.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('[Gg][Ee][Tt]', true).table - get.doc = [[* -]]..config.cmd_pat..[[get*: Gibt alle Variablen aus -*]]..config.cmd_pat..[[get* __: Gibt _Variable_ aus -Nutze `/set ` zum Setzen von Variablen]] -end - -function get:get_value(msg, var_name) - local hash = get_redis_hash(msg, 'variables') - if hash then - local value = redis:hget(hash, var_name) - if not value then - return'Nicht gefunden; benutze /get, um alle Variablen aufzulisten.' - else - return var_name..' = '..value - end - end -end - -function get:list_variables(msg) - local hash = get_redis_hash(msg, 'variables') - print(hash) - - if hash then - print('Hole Variable von Redis Hash '..hash) - local names = redis:hkeys(hash) - local text = '' - for i=1, #names do - variables = get:get_value(msg, names[i]) - text = text..variables.."\n" - end - if text == '' or text == nil then - return 'Keine Variablen vorhanden!' - else - return text - end - end -end - -function get:action(msg) - local input = utilities.input(msg.text) - if input then - output = get:get_value(msg, input:match('(.+)')) - else - output = get:list_variables(msg) - end - - utilities.send_message(msg.chat.id, output, true, nil, true) -end - -return get +local get = {} + +get.command = 'get ' + +function get:init(config) + get.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('[Gg][Ee][Tt]', true).table + get.doc = [[* +]]..config.cmd_pat..[[get*: Gibt alle Variablen aus +*]]..config.cmd_pat..[[get* __: Gibt _Variable_ aus +Nutze `/set ` zum Setzen von Variablen]] +end + +function get:get_value(msg, var_name) + local hash = get_redis_hash(msg, 'variables') + if hash then + local value = redis:hget(hash, var_name) + if not value then + return'Nicht gefunden; benutze /get, um alle Variablen aufzulisten.' + else + return var_name..' = '..value + end + end +end + +function get:list_variables(msg) + local hash = get_redis_hash(msg, 'variables') + print(hash) + + if hash then + print('Hole Variable von Redis Hash '..hash) + local names = redis:hkeys(hash) + local text = '' + for i=1, #names do + variables = get:get_value(msg, names[i]) + text = text..variables.."\n" + end + if text == '' or text == nil then + return 'Keine Variablen vorhanden!' + else + return text + end + end +end + +function get:action(msg) + local input = utilities.input(msg.text) + if input then + output = get:get_value(msg, input:match('(.+)')) + else + output = get:list_variables(msg) + end + + utilities.send_message(msg.chat.id, output, true, nil, true) +end + +return get diff --git a/miku/plugins/giphy.lua b/miku/plugins/giphy.lua index 755f11b..244e134 100644 --- a/miku/plugins/giphy.lua +++ b/miku/plugins/giphy.lua @@ -1,52 +1,52 @@ -local giphy = {} - -function giphy:init(config) - giphy.triggers = { - "/nil" - } - giphy.inline_triggers = { - "^(gif) (.+)", - "^(gif)$" - } -end - -local BASE_URL = 'http://api.giphy.com/v1/gifs' -local apikey = 'dc6zaTOxFJmzC' -- public beta key - -function giphy:get_gifs(query) - if not query then - url = BASE_URL..'/trending?api_key='..apikey - else - url = BASE_URL..'/search?q='..URL.escape(query)..'&api_key='..apikey - end - local res, code = http.request(url) - if code ~= 200 then return nil end - return json.decode(res).data -end - -function giphy:inline_callback(inline_query, config, matches) - if not matches[2] then - data = giphy:get_gifs() - else - data = giphy:get_gifs(matches[2]) - end - if not data then abort_inline_query(inline_query) return end - if not data[1] then abort_inline_query(inline_query) return end - local results = '[' - local id = 450 - - 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..'}' - id = id+1 - if n < #data then - results = results..',' - end - end - local results = results..']' - utilities.answer_inline_query(inline_query, results, 3600) -end - -function giphy:action() -end - +local giphy = {} + +function giphy:init(config) + giphy.triggers = { + "/nil" + } + giphy.inline_triggers = { + "^(gif) (.+)", + "^(gif)$" + } +end + +local BASE_URL = 'http://api.giphy.com/v1/gifs' +local apikey = 'dc6zaTOxFJmzC' -- public beta key + +function giphy:get_gifs(query) + if not query then + url = BASE_URL..'/trending?api_key='..apikey + else + url = BASE_URL..'/search?q='..URL.escape(query)..'&api_key='..apikey + end + local res, code = http.request(url) + if code ~= 200 then return nil end + return json.decode(res).data +end + +function giphy:inline_callback(inline_query, config, matches) + if not matches[2] then + data = giphy:get_gifs() + else + data = giphy:get_gifs(matches[2]) + end + if not data then abort_inline_query(inline_query) return end + if not data[1] then abort_inline_query(inline_query) return end + local results = '[' + local id = 450 + + 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..'}' + id = id+1 + if n < #data then + results = results..',' + end + end + local results = results..']' + utilities.answer_inline_query(inline_query, results, 3600) +end + +function giphy:action() +end + return giphy \ No newline at end of file diff --git a/miku/plugins/imgur.lua b/miku/plugins/imgur.lua index 2ff7eca..2a17d4a 100644 --- a/miku/plugins/imgur.lua +++ b/miku/plugins/imgur.lua @@ -1,55 +1,55 @@ -local imgur = {} - -function imgur:init(config) - if not cred_data.imgur_client_id then - print('Fehlender Key: imgur_client_id.') - print('imgur.lua wird nicht aktiviert.') - return - end - - imgur.triggers = { - "imgur.com/([A-Za-z0-9]+)" - } -end - -local client_id = cred_data.imgur_client_id -local BASE_URL = 'https://api.imgur.com/3' - -function imgur:get_imgur_data(imgur_code) - local response_body = {} - local request_constructor = { - url = BASE_URL..'/image/'..imgur_code, - method = "GET", - sink = ltn12.sink.table(response_body), - headers = { - Authorization = 'Client-ID '..client_id - } - } - local ok, response_code, response_headers, response_status_line = https.request(request_constructor) - if not ok then - return nil - end - - local response_body = json.decode(table.concat(response_body)) - - if response_body.status ~= 200 then return nil end - - return response_body.data.link -end - -function imgur:action(msg) - local imgur_code = matches[1] - if imgur_code == "login" then return nil end - utilities.send_typing(msg.chat.id, 'upload_photo') - local link = imgur:get_imgur_data(imgur_code) - if link then - local file = download_to_file(link) - if string.ends(link, ".gif") then - utilities.send_document(msg.chat.id, file, nil, msg.message_id) - else - utilities.send_photo(msg.chat.id, file, nil, msg.message_id) - end - end -end - -return imgur +local imgur = {} + +function imgur:init(config) + if not cred_data.imgur_client_id then + print('Fehlender Key: imgur_client_id.') + print('imgur.lua wird nicht aktiviert.') + return + end + + imgur.triggers = { + "imgur.com/([A-Za-z0-9]+)" + } +end + +local client_id = cred_data.imgur_client_id +local BASE_URL = 'https://api.imgur.com/3' + +function imgur:get_imgur_data(imgur_code) + local response_body = {} + local request_constructor = { + url = BASE_URL..'/image/'..imgur_code, + method = "GET", + sink = ltn12.sink.table(response_body), + headers = { + Authorization = 'Client-ID '..client_id + } + } + local ok, response_code, response_headers, response_status_line = https.request(request_constructor) + if not ok then + return nil + end + + local response_body = json.decode(table.concat(response_body)) + + if response_body.status ~= 200 then return nil end + + return response_body.data.link +end + +function imgur:action(msg) + local imgur_code = matches[1] + if imgur_code == "login" then return nil end + utilities.send_typing(msg.chat.id, 'upload_photo') + local link = imgur:get_imgur_data(imgur_code) + if link then + local file = download_to_file(link) + if string.ends(link, ".gif") then + utilities.send_document(msg.chat.id, file, nil, msg.message_id) + else + utilities.send_photo(msg.chat.id, file, nil, msg.message_id) + end + end +end + +return imgur diff --git a/miku/plugins/isup.lua b/miku/plugins/isup.lua deleted file mode 100644 index 1d44f5b..0000000 --- a/miku/plugins/isup.lua +++ /dev/null @@ -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* __: 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 diff --git a/miku/plugins/lyrics.lua b/miku/plugins/lyrics.lua index 899febf..c068069 100644 --- a/miku/plugins/lyrics.lua +++ b/miku/plugins/lyrics.lua @@ -1,47 +1,47 @@ -local lyrics = {} - -function lyrics:init(config) - if not cred_data.lyricsnmusic_apikey then - print('Fehlender Key: lyricsnmusic_apikey.') - print('lyrics.lua wird nicht aktiviert.') - return - end - - lyrics.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('[Ll][Yy][Rr][Ii][Cc][Ss]', true).table - lyrics.doc = [[* -]]..config.cmd_pat..[[lyrics* __: Postet Liedertext]] -end - -lyrics.command = 'lyrics ' - -function lyrics:getLyrics(text) - local apikey = cred_data.lyricsnmusic_apikey - local q = URL.encode(text) - local b = http.request("http://api.lyricsnmusic.com/songs?api_key="..apikey.."&q=" .. q) - response = json.decode(b) - local reply = "" - if #response > 0 then - -- grab first match - local result = response[1] - reply = result.title .. " - " .. result.artist.name .. "\n" .. result.snippet .. "\n[Ganzen Liedertext ansehen](" .. result.url .. ")" - else - reply = nil - end - return reply -end - -function lyrics:action(msg, config, matches) - local input = utilities.input(msg.text) - if not input then - if msg.reply_to_message and msg.reply_to_message.text then - input = msg.reply_to_message.text - else - utilities.send_message(msg.chat.id, lyrics.doc, true, msg.message_id, true) - return - end - end - - utilities.send_reply(msg, lyrics:getLyrics(input), true) -end - -return lyrics +local lyrics = {} + +function lyrics:init(config) + if not cred_data.lyricsnmusic_apikey then + print('Fehlender Key: lyricsnmusic_apikey.') + print('lyrics.lua wird nicht aktiviert.') + return + end + + lyrics.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('[Ll][Yy][Rr][Ii][Cc][Ss]', true).table + lyrics.doc = [[* +]]..config.cmd_pat..[[lyrics* __: Postet Liedertext]] +end + +lyrics.command = 'lyrics ' + +function lyrics:getLyrics(text) + local apikey = cred_data.lyricsnmusic_apikey + local q = URL.encode(text) + local b = http.request("http://api.lyricsnmusic.com/songs?api_key="..apikey.."&q=" .. q) + response = json.decode(b) + local reply = "" + if #response > 0 then + -- grab first match + local result = response[1] + reply = result.title .. " - " .. result.artist.name .. "\n" .. result.snippet .. "\n[Ganzen Liedertext ansehen](" .. result.url .. ")" + else + reply = nil + end + return reply +end + +function lyrics:action(msg, config, matches) + local input = utilities.input(msg.text) + if not input then + if msg.reply_to_message and msg.reply_to_message.text then + input = msg.reply_to_message.text + else + utilities.send_message(msg.chat.id, lyrics.doc, true, msg.message_id, true) + return + end + end + + utilities.send_reply(msg, lyrics:getLyrics(input), true) +end + +return lyrics diff --git a/miku/plugins/myanimelist.lua b/miku/plugins/myanimelist.lua index 5ffff75..1ec53b3 100644 --- a/miku/plugins/myanimelist.lua +++ b/miku/plugins/myanimelist.lua @@ -1,236 +1,236 @@ -local mal = {} - -local xml = require("xml") - -mal.command = 'anime , /manga ' - -function mal:init(config) - if not cred_data.mal_username then - print('Fehlender Key: mal_username.') - print('myanimelist.lua wird nicht aktiviert.') - return - elseif not cred_data.mal_pw then - print('Fehlender Key: mal_pw.') - print('myanimelist.lua wird nicht aktiviert.') - return - end - - mal.triggers = { - "^/(anime) (.+)$", - "^/(mal) (.+)$", - "^/(manga) (.+)$" - } - mal.doc = [[* -]]..config.cmd_pat..[[anime*_ _: Sendet Infos zum Anime -*]]..config.cmd_pat..[[manga*_ _: Sendet Infos zum Manga -]] -end - -local user = cred_data.mal_username -local password = cred_data.mal_pw - -local BASE_URL = 'https://'..user..':'..password..'@myanimelist.net/api' - -function mal:delete_tags(str) - str = string.gsub( str, '
', '') - str = string.gsub( str, '%[i%]', '') - str = string.gsub( str, '%[/i%]', '') - str = string.gsub( str, '—', ' — ') - return str -end - -local makeOurDate = function(dateString) - local pattern = "(%d+)%-(%d+)%-(%d+)" - local year, month, day = dateString:match(pattern) - if month == "00" then - return year - elseif day == "00" then - return month..'.'..year - else - return day..'.'..month..'.'..year - end -end - -function mal:get_mal_info(query, typ) - if typ == 'anime' then - url = BASE_URL..'/anime/search.xml?q='..query - elseif typ == 'manga' then - url = BASE_URL..'/manga/search.xml?q='..query - end - local res,code = https.request(url) - if code ~= 200 then return "HTTP-Fehler" end - local result = xml.load(res) - return result -end - -function mal:send_anime_data(result, receiver) - local title = '*'..xml.find(result, 'title')[1]..'*' - local id = xml.find(result, 'id')[1] - local mal_url = 'https://myanimelist.net/anime/'..id - - if xml.find(result, 'type')[1] then - typ = ' ('..xml.find(result, 'type')[1]..')' - else - typ = '' - end - - if xml.find(result, 'english')[1] then - eng = '\nEnglisch: *'..xml.find(result, 'english')[1]..'*' - else - eng = '' - end - - if xml.find(result, 'synonyms')[1] then - syno = '\nAlternativ: *'..xml.find(result, 'synonyms')[1]..'*' - else - syno = '' - end - - if xml.find(result, 'episodes')[1] then - episodes = '\nEpisoden: '..xml.find(result, 'episodes')[1] - else - episodes = '' - end - - if xml.find(result, 'status')[1] then - status = ' ('..xml.find(result, 'status')[1]..')' - else - status = '' - end - - if xml.find(result, 'score')[1] ~= "0.00" then - score = '\nScore: '..string.gsub(xml.find(result, 'score')[1], "%.", ",") - else - score = '' - end - - if xml.find(result, 'start_date')[1] ~= "0000-00-00" then - startdate = '\nAusstrahlung: '..makeOurDate(xml.find(result, 'start_date')[1]) - else - startdate = '' - end - - if xml.find(result, 'end_date')[1] ~= "0000-00-00" then - enddate = ' - '..makeOurDate(xml.find(result, 'end_date')[1]) - else - enddate = '' - end - - if xml.find(result, 'synopsis')[1] then - desc = '\n_'..unescape(mal:delete_tags(string.sub(xml.find(result, 'synopsis')[1], 1, 250)))..'..._' - else - desc = '' - end - - 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 - local image_url = xml.find(result, 'image')[1] - return text, image_url - else - return text - end -end - -function mal:send_manga_data(result) - local title = xml.find(result, 'title')[1] - local id = xml.find(result, 'id')[1] - local mal_url = 'https://myanimelist.net/manga/'..id - - if xml.find(result, 'type')[1] then - typ = ' ('..xml.find(result, 'type')[1]..')' - else - typ = '' - end - - if xml.find(result, 'synonyms')[1] then - alt_name = '\noder: '..unescape(mal:delete_tags(xml.find(result, 'synonyms')[1])) - else - alt_name = '' - end - - if xml.find(result, 'chapters')[1] then - chapters = '\nKapitel: '..xml.find(result, 'chapters')[1] - else - chapters = '' - end - - if xml.find(result, 'status')[1] then - status = ' ('..xml.find(result, 'status')[1]..')' - else - status = '' - end - - if xml.find(result, 'volumes')[1] then - volumes = '\nBände '..xml.find(result, 'volumes')[1] - else - volumes = '' - end - - if xml.find(result, 'score')[1] ~= "0.00" then - score = '\nScore: '..xml.find(result, 'score')[1] - else - score = '' - end - - if xml.find(result, 'start_date')[1] ~= "0000-00-00" then - startdate = '\nVeröffentlichungszeitraum: '..makeOurDate(xml.find(result, 'start_date')[1]) - else - startdate = '' - end - - if xml.find(result, 'end_date')[1] ~= "0000-00-00" then - enddate = ' - '..makeOurDate(xml.find(result, 'end_date')[1]) - else - enddate = '' - end - - if xml.find(result, 'synopsis')[1] then - desc = '\n'..unescape(mal:delete_tags(string.sub(xml.find(result, 'synopsis')[1], 1, 200))) .. '...' - else - desc = '' - end - - 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 - local image_url = xml.find(result, 'image')[1] - return text, image_url - else - return text - end -end - -function mal:action(msg, config, matches) - local query = URL.escape(matches[2]) - if matches[1] == 'anime' or matches[1] == 'mal' then - local anime_info = mal:get_mal_info(query, 'anime') - if anime_info == "HTTP-Fehler" then - utilities.send_reply(msg, 'Anime nicht gefunden!') - return - else - local text, image_url = mal:send_anime_data(anime_info) - if image_url then - utilities.send_typing(msg.chat.id, 'upload_photo') - utilities.send_photo(msg.chat.id, image_url, nil, msg.message_id) - end - utilities.send_reply(msg, text, true) - return - end - elseif matches[1] == 'manga' then - local manga_info = mal:get_mal_info(query, 'manga') - if manga_info == "HTTP-Fehler" then - utilities.send_reply(msg, 'Manga nicht gefunden!') - return - else - local text, image_url = mal:send_manga_data(manga_info) - if image_url then - utilities.send_typing(msg.chat.id, 'upload_photo') - utilities.send_photo(msg.chat.id, image_url, nil, msg.message_id) - end - utilities.send_reply(msg, text, true) - return - end - end -end - -return mal +local mal = {} + +local xml = require("xml") + +mal.command = 'anime , /manga ' + +function mal:init(config) + if not cred_data.mal_username then + print('Fehlender Key: mal_username.') + print('myanimelist.lua wird nicht aktiviert.') + return + elseif not cred_data.mal_pw then + print('Fehlender Key: mal_pw.') + print('myanimelist.lua wird nicht aktiviert.') + return + end + + mal.triggers = { + "^/(anime) (.+)$", + "^/(mal) (.+)$", + "^/(manga) (.+)$" + } + mal.doc = [[* +]]..config.cmd_pat..[[anime*_ _: Sendet Infos zum Anime +*]]..config.cmd_pat..[[manga*_ _: Sendet Infos zum Manga +]] +end + +local user = cred_data.mal_username +local password = cred_data.mal_pw + +local BASE_URL = 'https://'..user..':'..password..'@myanimelist.net/api' + +function mal:delete_tags(str) + str = string.gsub( str, '
', '') + str = string.gsub( str, '%[i%]', '') + str = string.gsub( str, '%[/i%]', '') + str = string.gsub( str, '—', ' — ') + return str +end + +local makeOurDate = function(dateString) + local pattern = "(%d+)%-(%d+)%-(%d+)" + local year, month, day = dateString:match(pattern) + if month == "00" then + return year + elseif day == "00" then + return month..'.'..year + else + return day..'.'..month..'.'..year + end +end + +function mal:get_mal_info(query, typ) + if typ == 'anime' then + url = BASE_URL..'/anime/search.xml?q='..query + elseif typ == 'manga' then + url = BASE_URL..'/manga/search.xml?q='..query + end + local res,code = https.request(url) + if code ~= 200 then return "HTTP-Fehler" end + local result = xml.load(res) + return result +end + +function mal:send_anime_data(result, receiver) + local title = '*'..xml.find(result, 'title')[1]..'*' + local id = xml.find(result, 'id')[1] + local mal_url = 'https://myanimelist.net/anime/'..id + + if xml.find(result, 'type')[1] then + typ = ' ('..xml.find(result, 'type')[1]..')' + else + typ = '' + end + + if xml.find(result, 'english')[1] then + eng = '\nEnglisch: *'..xml.find(result, 'english')[1]..'*' + else + eng = '' + end + + if xml.find(result, 'synonyms')[1] then + syno = '\nAlternativ: *'..xml.find(result, 'synonyms')[1]..'*' + else + syno = '' + end + + if xml.find(result, 'episodes')[1] then + episodes = '\nEpisoden: '..xml.find(result, 'episodes')[1] + else + episodes = '' + end + + if xml.find(result, 'status')[1] then + status = ' ('..xml.find(result, 'status')[1]..')' + else + status = '' + end + + if xml.find(result, 'score')[1] ~= "0.00" then + score = '\nScore: '..string.gsub(xml.find(result, 'score')[1], "%.", ",") + else + score = '' + end + + if xml.find(result, 'start_date')[1] ~= "0000-00-00" then + startdate = '\nAusstrahlung: '..makeOurDate(xml.find(result, 'start_date')[1]) + else + startdate = '' + end + + if xml.find(result, 'end_date')[1] ~= "0000-00-00" then + enddate = ' - '..makeOurDate(xml.find(result, 'end_date')[1]) + else + enddate = '' + end + + if xml.find(result, 'synopsis')[1] then + desc = '\n_'..unescape(mal:delete_tags(string.sub(xml.find(result, 'synopsis')[1], 1, 250)))..'..._' + else + desc = '' + end + + 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 + local image_url = xml.find(result, 'image')[1] + return text, image_url + else + return text + end +end + +function mal:send_manga_data(result) + local title = xml.find(result, 'title')[1] + local id = xml.find(result, 'id')[1] + local mal_url = 'https://myanimelist.net/manga/'..id + + if xml.find(result, 'type')[1] then + typ = ' ('..xml.find(result, 'type')[1]..')' + else + typ = '' + end + + if xml.find(result, 'synonyms')[1] then + alt_name = '\noder: '..unescape(mal:delete_tags(xml.find(result, 'synonyms')[1])) + else + alt_name = '' + end + + if xml.find(result, 'chapters')[1] then + chapters = '\nKapitel: '..xml.find(result, 'chapters')[1] + else + chapters = '' + end + + if xml.find(result, 'status')[1] then + status = ' ('..xml.find(result, 'status')[1]..')' + else + status = '' + end + + if xml.find(result, 'volumes')[1] then + volumes = '\nBände '..xml.find(result, 'volumes')[1] + else + volumes = '' + end + + if xml.find(result, 'score')[1] ~= "0.00" then + score = '\nScore: '..xml.find(result, 'score')[1] + else + score = '' + end + + if xml.find(result, 'start_date')[1] ~= "0000-00-00" then + startdate = '\nVeröffentlichungszeitraum: '..makeOurDate(xml.find(result, 'start_date')[1]) + else + startdate = '' + end + + if xml.find(result, 'end_date')[1] ~= "0000-00-00" then + enddate = ' - '..makeOurDate(xml.find(result, 'end_date')[1]) + else + enddate = '' + end + + if xml.find(result, 'synopsis')[1] then + desc = '\n'..unescape(mal:delete_tags(string.sub(xml.find(result, 'synopsis')[1], 1, 200))) .. '...' + else + desc = '' + end + + 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 + local image_url = xml.find(result, 'image')[1] + return text, image_url + else + return text + end +end + +function mal:action(msg, config, matches) + local query = URL.escape(matches[2]) + if matches[1] == 'anime' or matches[1] == 'mal' then + local anime_info = mal:get_mal_info(query, 'anime') + if anime_info == "HTTP-Fehler" then + utilities.send_reply(msg, 'Anime nicht gefunden!') + return + else + local text, image_url = mal:send_anime_data(anime_info) + if image_url then + utilities.send_typing(msg.chat.id, 'upload_photo') + utilities.send_photo(msg.chat.id, image_url, nil, msg.message_id) + end + utilities.send_reply(msg, text, true) + return + end + elseif matches[1] == 'manga' then + local manga_info = mal:get_mal_info(query, 'manga') + if manga_info == "HTTP-Fehler" then + utilities.send_reply(msg, 'Manga nicht gefunden!') + return + else + local text, image_url = mal:send_manga_data(manga_info) + if image_url then + utilities.send_typing(msg.chat.id, 'upload_photo') + utilities.send_photo(msg.chat.id, image_url, nil, msg.message_id) + end + utilities.send_reply(msg, text, true) + return + end + end +end + +return mal diff --git a/miku/plugins/notify.lua b/miku/plugins/notify.lua index ef98b62..54af36b 100644 --- a/miku/plugins/notify.lua +++ b/miku/plugins/notify.lua @@ -39,12 +39,13 @@ function notify:pre_process(msg) if redis:sismember('chat:'..chat_id..':users', id) then -- ignore message, if user is mentioning him/herself 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..' +"%d.%m.%Y | 🕒 %H:%M:%S Uhr"') local send_date = string.gsub(send_date, "\n", "") local from = string.gsub(msg.from.name, "%_", " ") local chat_name = string.gsub(msg.chat.title, "%_", " ") - local text = from..' am '..send_date..' in "'..chat_name..'":\n\n'..msg.text - utilities.send_message(id, text, true) + local text = '🔔 '..utilities.html_escape(from)..' hat dich erwähnt:' + local text = text..'\n👥 '..utilities.html_escape(chat_name)..' | 📅 '..send_date..'\n\n'..utilities.html_escape(msg.text) + utilities.send_message(id, text, true, false, 'HTML') end end end diff --git a/miku/plugins/pagespeed_insights.lua b/miku/plugins/pagespeed_insights.lua deleted file mode 100644 index 4a3ef6d..0000000 --- a/miku/plugins/pagespeed_insights.lua +++ /dev/null @@ -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* __: 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 diff --git a/miku/plugins/play_store.lua b/miku/plugins/play_store.lua index 4f3b626..21724dc 100644 --- a/miku/plugins/play_store.lua +++ b/miku/plugins/play_store.lua @@ -1,58 +1,58 @@ -local play_store = {} - -function play_store:init(config) - if not cred_data.x_mashape_key then - print('Fehlender Key: x_mashape_key.') - print('play_store.lua wird nicht aktiviert.') - return - end - - play_store.triggers = { - "play.google.com/store/apps/details%?id=(.*)" - } -end - -local BASE_URL = 'https://apps.p.mashape.com/google/application' - -function play_store:get_playstore_data (appid) - local apikey = cred_data.x_mashape_key - local url = BASE_URL..'/'..appid..'?mashape-key='..apikey - local res,code = https.request(url) - if code ~= 200 then return nil end - local data = json.decode(res).data - return data -end - -function play_store:send_playstore_data(data) - local title = data.title - local developer = data.developer.id - local category = data.category.name - local rating = data.rating.average - local installs = data.performance.installs - local description = unescape(data.description) - if data.version == "Varies with device" then - appversion = "variiert je nach Gerät" - else - appversion = data.version - end - if data.price == 0 then - price = "Gratis" - else - price = data.price - end - local text = '*'..title..'* von *'..developer..'* aus der Kategorie _'..category..'_, durschnittlich bewertet mit '..rating..' Sternen.\n_'..description..'_\n'..installs..' Installationen, Version '..appversion - return text -end - -function play_store:action(msg, config, matches) - local appid = matches[1] - local data = play_store:get_playstore_data(appid) - if data == nil then - return - else - utilities.send_reply(msg, play_store:send_playstore_data(data), true) - return - end -end - -return play_store +local play_store = {} + +function play_store:init(config) + if not cred_data.x_mashape_key then + print('Fehlender Key: x_mashape_key.') + print('play_store.lua wird nicht aktiviert.') + return + end + + play_store.triggers = { + "play.google.com/store/apps/details%?id=(.*)" + } +end + +local BASE_URL = 'https://apps.p.mashape.com/google/application' + +function play_store:get_playstore_data (appid) + local apikey = cred_data.x_mashape_key + local url = BASE_URL..'/'..appid..'?mashape-key='..apikey + local res,code = https.request(url) + if code ~= 200 then return nil end + local data = json.decode(res).data + return data +end + +function play_store:send_playstore_data(data) + local title = data.title + local developer = data.developer.id + local category = data.category.name + local rating = data.rating.average + local installs = data.performance.installs + local description = unescape(data.description) + if data.version == "Varies with device" then + appversion = "variiert je nach Gerät" + else + appversion = data.version + end + if data.price == 0 then + price = "Gratis" + else + price = data.price + end + local text = '*'..title..'* von *'..developer..'* aus der Kategorie _'..category..'_, durschnittlich bewertet mit '..rating..' Sternen.\n_'..description..'_\n'..installs..' Installationen, Version '..appversion + return text +end + +function play_store:action(msg, config, matches) + local appid = matches[1] + local data = play_store:get_playstore_data(appid) + if data == nil then + return + else + utilities.send_reply(msg, play_store:send_playstore_data(data), true) + return + end +end + +return play_store diff --git a/miku/plugins/pocket.lua b/miku/plugins/pocket.lua deleted file mode 100644 index 21e9190..0000000 --- a/miku/plugins/pocket.lua +++ /dev/null @@ -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 ' - -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 \ No newline at end of file diff --git a/miku/plugins/reddit.lua b/miku/plugins/reddit.lua index 04706e8..72d94a0 100644 --- a/miku/plugins/reddit.lua +++ b/miku/plugins/reddit.lua @@ -1,77 +1,77 @@ -local reddit = {} - -reddit.command = 'reddit [r/subreddit | Suchbegriff]' - -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.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.]] -end - -local format_results = function(posts) - local output = '' - for _,v in ipairs(posts) do - local post = v.data - local title = post.title:gsub('%[', '('):gsub('%]', ')'):gsub('&', '&') - if title:len() > 256 then - title = title:sub(1, 253) - title = utilities.trim(title) .. '...' - end - local short_url = 'https://redd.it/' .. post.id - local s = '[' .. unescape(title) .. '](' .. short_url .. ')' - if post.domain and not post.is_self and not post.over_18 then - s = '`[`[' .. post.domain .. '](' .. post.url:gsub('%)', '\\)') .. ')`]` ' .. s - end - output = output .. '• ' .. s .. '\n' - end - return output -end - -reddit.subreddit_url = 'https://www.reddit.com/%s/.json?limit=' -reddit.search_url = 'https://www.reddit.com/search.json?q=%s&limit=' -reddit.rall_url = 'https://www.reddit.com/.json?limit=' - -function reddit:action(msg, config) - -- Eight results in PM, four results elsewhere. - local limit = 4 - if msg.chat.type == 'private' then - limit = 8 - end - local text = msg.text_lower - if text:match('^/r/.') then - -- Normalize input so this hack works easily. - text = msg.text_lower:gsub('^/r/', config.cmd_pat..'r r/') - end - local input = utilities.input(text) - local source, url - if input then - if input:match('^r/.') then - input = utilities.get_word(input, 1) - url = reddit.subreddit_url:format(input) .. limit - source = '*/' .. utilities.md_escape(input) .. '*\n' - else - input = utilities.input(msg.text) - source = '*Ergebnisse für* _' .. utilities.md_escape(input) .. '_ *:*\n' - input = URL.escape(input) - url = reddit.search_url:format(input) .. limit - end - else - url = reddit.rall_url .. limit - source = '*/r/all*\n' - end - local jstr, res = https.request(url) - if res ~= 200 then - utilities.send_reply(msg, config.errors.results) - else - local jdat = json.decode(jstr) - if #jdat.data.children == 0 then - utilities.send_reply(msg, config.errors.results) - else - local output = format_results(jdat.data.children) - output = source .. output - utilities.send_message(msg.chat.id, output, true, nil, true) - end - end -end - -return reddit +local reddit = {} + +reddit.command = 'reddit [r/subreddit | Suchbegriff]' + +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.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.]] +end + +local format_results = function(posts) + local output = '' + for _,v in ipairs(posts) do + local post = v.data + local title = post.title:gsub('%[', '('):gsub('%]', ')'):gsub('&', '&') + if title:len() > 256 then + title = title:sub(1, 253) + title = utilities.trim(title) .. '...' + end + local short_url = 'https://redd.it/' .. post.id + local s = '[' .. unescape(title) .. '](' .. short_url .. ')' + if post.domain and not post.is_self and not post.over_18 then + s = '`[`[' .. post.domain .. '](' .. post.url:gsub('%)', '\\)') .. ')`]` ' .. s + end + output = output .. '• ' .. s .. '\n' + end + return output +end + +reddit.subreddit_url = 'https://www.reddit.com/%s/.json?limit=' +reddit.search_url = 'https://www.reddit.com/search.json?q=%s&limit=' +reddit.rall_url = 'https://www.reddit.com/.json?limit=' + +function reddit:action(msg, config) + -- Eight results in PM, four results elsewhere. + local limit = 4 + if msg.chat.type == 'private' then + limit = 8 + end + local text = msg.text_lower + if text:match('^/r/.') then + -- Normalize input so this hack works easily. + text = msg.text_lower:gsub('^/r/', config.cmd_pat..'r r/') + end + local input = utilities.input(text) + local source, url + if input then + if input:match('^r/.') then + input = utilities.get_word(input, 1) + url = reddit.subreddit_url:format(input) .. limit + source = '*/' .. utilities.md_escape(input) .. '*\n' + else + input = utilities.input(msg.text) + source = '*Ergebnisse für* _' .. utilities.md_escape(input) .. '_ *:*\n' + input = URL.escape(input) + url = reddit.search_url:format(input) .. limit + end + else + url = reddit.rall_url .. limit + source = '*/r/all*\n' + end + local jstr, res = https.request(url) + if res ~= 200 then + utilities.send_reply(msg, config.errors.results) + else + local jdat = json.decode(jstr) + if #jdat.data.children == 0 then + utilities.send_reply(msg, config.errors.results) + else + local output = format_results(jdat.data.children) + output = source .. output + utilities.send_message(msg.chat.id, output, true, nil, true) + end + end +end + +return reddit diff --git a/miku/plugins/roll.lua b/miku/plugins/roll.lua deleted file mode 100644 index bf82667..0000000 --- a/miku/plugins/roll.lua +++ /dev/null @@ -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 diff --git a/miku/plugins/set.lua b/miku/plugins/set.lua index ca1a441..77aff3f 100644 --- a/miku/plugins/set.lua +++ b/miku/plugins/set.lua @@ -1,52 +1,52 @@ -local set = {} - -set.command = 'set ' - -function set:init(config) - set.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('set', true).table - set.doc = [[* -]]..config.cmd_pat..[[set* __ __: Speichert eine Variable mit einem Wert -*]]..config.cmd_pat..[[set* __ _nil_: Löscht Variable -Nutze `/get ` zum Abrufen]] -end - -function set:save_value(msg, name, value) - local hash = get_redis_hash(msg, 'variables') - if hash then - print('Saving variable to redis hash '..hash) - redis:hset(hash, name, value) - return "Gespeichert: "..name.." = "..value - end -end - -function set:delete_value(msg, name) - local hash = get_redis_hash(msg, 'variables') - if redis:hexists(hash, name) == true then - print('Deleting variable from redis hash '..hash) - redis:hdel(hash, name) - return 'Variable "'..name..'" erfolgreich gelöscht!' - else - return 'Du kannst keine Variable löschen, die nicht existiert .-.' - end -end - -function set:action(msg) - local input = utilities.input(msg.text) - if not input or not input:match('([^%s]+) (.+)') then - utilities.send_message(msg.chat.id, set.doc, true, msg.message_id, true) - return - end - - local name = input:match('([^%s]+) ') - local value = input:match(' (.+)') - - if value == "nil" then - output = set:delete_value(msg, name) - else - output = set:save_value(msg, name, value) - end - - utilities.send_message(msg.chat.id, output, true, nil, true) -end - -return set +local set = {} + +set.command = 'set ' + +function set:init(config) + set.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('set', true).table + set.doc = [[* +]]..config.cmd_pat..[[set* __ __: Speichert eine Variable mit einem Wert +*]]..config.cmd_pat..[[set* __ _nil_: Löscht Variable +Nutze `/get ` zum Abrufen]] +end + +function set:save_value(msg, name, value) + local hash = get_redis_hash(msg, 'variables') + if hash then + print('Saving variable to redis hash '..hash) + redis:hset(hash, name, value) + return "Gespeichert: "..name.." = "..value + end +end + +function set:delete_value(msg, name) + local hash = get_redis_hash(msg, 'variables') + if redis:hexists(hash, name) == true then + print('Deleting variable from redis hash '..hash) + redis:hdel(hash, name) + return 'Variable "'..name..'" erfolgreich gelöscht!' + else + return 'Du kannst keine Variable löschen, die nicht existiert .-.' + end +end + +function set:action(msg) + local input = utilities.input(msg.text) + if not input or not input:match('([^%s]+) (.+)') then + utilities.send_message(msg.chat.id, set.doc, true, msg.message_id, true) + return + end + + local name = input:match('([^%s]+) ') + local value = input:match(' (.+)') + + if value == "nil" then + output = set:delete_value(msg, name) + else + output = set:save_value(msg, name, value) + end + + utilities.send_message(msg.chat.id, output, true, nil, true) +end + +return set diff --git a/miku/plugins/settings.lua b/miku/plugins/settings.lua index b206e99..6121778 100644 --- a/miku/plugins/settings.lua +++ b/miku/plugins/settings.lua @@ -1,54 +1,54 @@ -local settings = {} - -settings.triggers = { - "^(⚙ [Ee]instellungen)$", - "^(/settings)$", - "^(💤 [Aa][Ff][Kk]%-[Kk]eyboard einschalten)", - "^(💤 [Aa][Ff][Kk]%-[Kk]eyboard ausschalten)", - "^(❌ [Ee]instellungen verstecken)" -} - ---[[ -[ - [ "Top Left", "Top Right" ], - [ "Bottom Left", "Bottom Right" ] -] -]] - -function settings:keyboard(user_id) - if redis:hget('user:'..user_id, 'afk_keyboard') == 'true' then - afk_button = '{"text":"💤 AFK-Keyboard ausschalten"}' - else - afk_button = '{"text":"💤 AFK-Keyboard einschalten"}' - end - local hide_settings_button = '{"text":"❌ Einstellungen verstecken"}' - - local settings_keyboard = '[['..afk_button..','..hide_settings_button..']]' - return settings_keyboard -end - -function settings:action(msg, config, matches) - if msg.chat.type ~= "private" then - return - end - - local hash = 'user:'..msg.from.id - - 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}') - return - elseif matches[1] == '💤 AFK-Keyboard einschalten' then - 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}') - return - elseif matches[1] == '💤 AFK-Keyboard ausschalten' then - 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}') - return - elseif matches[1] == '❌ Einstellungen verstecken' then - utilities.send_reply(msg, 'Um die Einstellungen wieder einzublenden, führe /settings aus.', true, '{"hide_keyboard":true}') - return - end -end - +local settings = {} + +settings.triggers = { + "^(⚙ [Ee]instellungen)$", + "^(/settings)$", + "^(💤 [Aa][Ff][Kk]%-[Kk]eyboard einschalten)", + "^(💤 [Aa][Ff][Kk]%-[Kk]eyboard ausschalten)", + "^(❌ [Ee]instellungen verstecken)" +} + +--[[ +[ + [ "Top Left", "Top Right" ], + [ "Bottom Left", "Bottom Right" ] +] +]] + +function settings:keyboard(user_id) + if redis:hget('user:'..user_id, 'afk_keyboard') == 'true' then + afk_button = '{"text":"💤 AFK-Keyboard ausschalten"}' + else + afk_button = '{"text":"💤 AFK-Keyboard einschalten"}' + end + local hide_settings_button = '{"text":"❌ Einstellungen verstecken"}' + + local settings_keyboard = '[['..afk_button..','..hide_settings_button..']]' + return settings_keyboard +end + +function settings:action(msg, config, matches) + if msg.chat.type ~= "private" then + return + end + + local hash = 'user:'..msg.from.id + + 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}') + return + elseif matches[1] == '💤 AFK-Keyboard einschalten' then + 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}') + return + elseif matches[1] == '💤 AFK-Keyboard ausschalten' then + 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}') + return + elseif matches[1] == '❌ Einstellungen verstecken' then + utilities.send_reply(msg, 'Um die Einstellungen wieder einzublenden, führe /settings aus.', true, '{"hide_keyboard":true}') + return + end +end + return settings \ No newline at end of file diff --git a/miku/plugins/soundcloud.lua b/miku/plugins/soundcloud.lua index 8f0f6bf..4187015 100644 --- a/miku/plugins/soundcloud.lua +++ b/miku/plugins/soundcloud.lua @@ -1,37 +1,37 @@ -local soundcloud = {} - -soundcloud.triggers = { - "soundcloud.com/([A-Za-z0-9-/-_-.]+)" -} - -local BASE_URL = 'http://api.soundcloud.com/resolve.json' -local client_id = cred_data.soundcloud_client_id - -function soundcloud:send_soundcloud_info(sc_url) - local url = BASE_URL..'?url=http://soundcloud.com/'..sc_url..'&client_id='..client_id - - local res,code = http.request(url) - if code ~= 200 then return nil end - local data = json.decode(res) - - local title = data.title - local description = data.description - local user = data.user.username - local user = 'Unbekannt' - local genre = data.genre - local playback_count = data.playback_count - local milliseconds = data.duration - local totalseconds = math.floor(milliseconds / 1000) - local duration = makeHumanTime(totalseconds) - - local text = '*'..title..'* von _'..user..'_\n_(Tag: '..genre..', '..duration..'; '..playback_count..' mal angehört)_\n'..description - return text -end - -function soundcloud:action(msg, config, matches) - local text = soundcloud:send_soundcloud_info(matches[1]) - if not text then utilities.send_reply(msg, config.errors.connection) return end - utilities.send_reply(msg, text, true) -end - -return soundcloud +local soundcloud = {} + +soundcloud.triggers = { + "soundcloud.com/([A-Za-z0-9-/-_-.]+)" +} + +local BASE_URL = 'http://api.soundcloud.com/resolve.json' +local client_id = cred_data.soundcloud_client_id + +function soundcloud:send_soundcloud_info(sc_url) + local url = BASE_URL..'?url=http://soundcloud.com/'..sc_url..'&client_id='..client_id + + local res,code = http.request(url) + if code ~= 200 then return nil end + local data = json.decode(res) + + local title = data.title + local description = data.description + local user = data.user.username + local user = 'Unbekannt' + local genre = data.genre + local playback_count = data.playback_count + local milliseconds = data.duration + local totalseconds = math.floor(milliseconds / 1000) + local duration = makeHumanTime(totalseconds) + + local text = '*'..title..'* von _'..user..'_\n_(Tag: '..genre..', '..duration..'; '..playback_count..' mal angehört)_\n'..description + return text +end + +function soundcloud:action(msg, config, matches) + local text = soundcloud:send_soundcloud_info(matches[1]) + if not text then utilities.send_reply(msg, config.errors.connection) return end + utilities.send_reply(msg, text, true) +end + +return soundcloud diff --git a/miku/plugins/streamable.lua b/miku/plugins/streamable.lua index 96ea2e5..8403e0d 100644 --- a/miku/plugins/streamable.lua +++ b/miku/plugins/streamable.lua @@ -1,49 +1,49 @@ -local streamable = {} - -streamable.triggers = { - "streamable.com/([A-Za-z0-9-_-]+)", -} - -function streamable:send_streamable_video(shortcode, msg) - local BASE_URL = "https://api.streamable.com" - local url = BASE_URL..'/videos/'..shortcode - local res,code = https.request(url) - if code ~= 200 then return 'HTTP-Fehler' end - local data = json.decode(res) - if data.status ~= 2 then utilities.send_reply(msg, "Video ist (noch) nicht verfügbar.") return end - - if data.files.webm then - if data.title == "" then title = shortcode..'.webm' else title = data.title..'.webm' end - url = 'https:'..data.files.webm.url - width = data.files.webm.width - height = data.files.webm.height - if data.files.webm.size > 50000000 then - 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) - return - end - elseif data.files.mp4 then - if data.title == "" then title = shortcode..'.mp4' else title = data.title..'.mp4' end - url = 'https:'..data.files.mp4.url - width = data.files.mp4.width - height = data.files.mp4.height - if data.files.mp4.size > 50000000 then - 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) - return - end - end - - utilities.send_typing(msg.chat.id, 'upload_video') - local file = download_to_file(url, title) - utilities.send_video(msg.chat.id, file, nil, msg.message_id, nil, width, height) - return -end - -function streamable:action(msg, config, matches) - local shortcode = matches[1] - streamable:send_streamable_video(shortcode, msg) - return -end - -return streamable +local streamable = {} + +streamable.triggers = { + "streamable.com/([A-Za-z0-9-_-]+)", +} + +function streamable:send_streamable_video(shortcode, msg) + local BASE_URL = "https://api.streamable.com" + local url = BASE_URL..'/videos/'..shortcode + local res,code = https.request(url) + if code ~= 200 then return 'HTTP-Fehler' end + local data = json.decode(res) + if data.status ~= 2 then utilities.send_reply(msg, "Video ist (noch) nicht verfügbar.") return end + + if data.files.webm then + if data.title == "" then title = shortcode..'.webm' else title = data.title..'.webm' end + url = 'https:'..data.files.webm.url + width = data.files.webm.width + height = data.files.webm.height + if data.files.webm.size > 50000000 then + 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) + return + end + elseif data.files.mp4 then + if data.title == "" then title = shortcode..'.mp4' else title = data.title..'.mp4' end + url = 'https:'..data.files.mp4.url + width = data.files.mp4.width + height = data.files.mp4.height + if data.files.mp4.size > 50000000 then + 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) + return + end + end + + utilities.send_typing(msg.chat.id, 'upload_video') + local file = download_to_file(url, title) + utilities.send_video(msg.chat.id, file, nil, msg.message_id, nil, width, height) + return +end + +function streamable:action(msg, config, matches) + local shortcode = matches[1] + streamable:send_streamable_video(shortcode, msg) + return +end + +return streamable diff --git a/miku/plugins/thetvdb.lua b/miku/plugins/thetvdb.lua index dba8a70..f4c645e 100644 --- a/miku/plugins/thetvdb.lua +++ b/miku/plugins/thetvdb.lua @@ -1,92 +1,92 @@ -local tv = {} - -local xml = require("xml") - -tv.command = 'tv ' - -function tv:init(config) - tv.triggers = { - "^/tv (.+)$" - } - tv.doc = [[* -]]..config.cmd_pat..[[tv*_ _: Sendet Infos zur TV-Serie]] -end - -local BASE_URL = 'http://thetvdb.com/api' - -local makeOurDate = function(dateString) - local pattern = "(%d+)%-(%d+)%-(%d+)" - local year, month, day = dateString:match(pattern) - return day..'.'..month..'.'..year -end - - -function tv:get_tv_info(series) - local url = BASE_URL..'/GetSeries.php?seriesname='..series..'&language=de' - local res,code = http.request(url) - if code ~= 200 then return "HTTP-ERROR" end - local result = xml.load(res) - if not xml.find(result, 'seriesid') then return "NOTFOUND" end - return result -end - -function tv:send_tv_data(result, msg) - local title = xml.find(result, 'SeriesName')[1] - local id = xml.find(result, 'seriesid')[1] - - if xml.find(result, 'AliasNames') and xml.find(result, 'AliasNames')[1] ~= title then - alias = '\noder: '..xml.find(result, 'AliasNames')[1] - else - alias = '' - end - - if xml.find(result, 'Overview') then - desc = '\n_'..string.sub(xml.find(result, 'Overview')[1], 1, 250) .. '..._' - else - desc = '' - end - - if xml.find(result, 'FirstAired') then - aired = '\n*Erstausstrahlung:* '..makeOurDate(xml.find(result, 'FirstAired')[1]) - else - aired = '' - end - - - if xml.find(result, 'Network') then - publisher = '\n*Publisher:* '..xml.find(result, 'Network')[1] - else - publisher = '' - end - - if xml.find(result, 'IMDB_ID') then - imdb = '\n[IMDB-Seite](http://www.imdb.com/title/'..xml.find(result, 'IMDB_ID')[1]..')' - else - imdb = '' - end - - 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 - local image_url = 'http://www.thetvdb.com/banners/'..xml.find(result, 'banner')[1] - utilities.send_typing(msg.chat.id, 'upload_photo') - utilities.send_photo(msg.chat.id, image_url, nil, msg.message_id) - end - utilities.send_reply(msg, text, true) -end - - -function tv:action(msg, config, matches) - local series = URL.escape(matches[1]) - local tv_info = tv:get_tv_info(series) - if tv_info == "NOTFOUND" then - utilities.send_reply(msg, config.errors.results) - return - elseif tv_info == "HTTP-ERROR" then - utilities.send_reply(msg, config.errors.connection) - return - else - tv:send_tv_data(tv_info, msg) - end -end - -return tv +local tv = {} + +local xml = require("xml") + +tv.command = 'tv ' + +function tv:init(config) + tv.triggers = { + "^/tv (.+)$" + } + tv.doc = [[* +]]..config.cmd_pat..[[tv*_ _: Sendet Infos zur TV-Serie]] +end + +local BASE_URL = 'http://thetvdb.com/api' + +local makeOurDate = function(dateString) + local pattern = "(%d+)%-(%d+)%-(%d+)" + local year, month, day = dateString:match(pattern) + return day..'.'..month..'.'..year +end + + +function tv:get_tv_info(series) + local url = BASE_URL..'/GetSeries.php?seriesname='..series..'&language=de' + local res,code = http.request(url) + if code ~= 200 then return "HTTP-ERROR" end + local result = xml.load(res) + if not xml.find(result, 'seriesid') then return "NOTFOUND" end + return result +end + +function tv:send_tv_data(result, msg) + local title = xml.find(result, 'SeriesName')[1] + local id = xml.find(result, 'seriesid')[1] + + if xml.find(result, 'AliasNames') and xml.find(result, 'AliasNames')[1] ~= title then + alias = '\noder: '..xml.find(result, 'AliasNames')[1] + else + alias = '' + end + + if xml.find(result, 'Overview') then + desc = '\n_'..string.sub(xml.find(result, 'Overview')[1], 1, 250) .. '..._' + else + desc = '' + end + + if xml.find(result, 'FirstAired') then + aired = '\n*Erstausstrahlung:* '..makeOurDate(xml.find(result, 'FirstAired')[1]) + else + aired = '' + end + + + if xml.find(result, 'Network') then + publisher = '\n*Publisher:* '..xml.find(result, 'Network')[1] + else + publisher = '' + end + + if xml.find(result, 'IMDB_ID') then + imdb = '\n[IMDB-Seite](http://www.imdb.com/title/'..xml.find(result, 'IMDB_ID')[1]..')' + else + imdb = '' + end + + 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 + local image_url = 'http://www.thetvdb.com/banners/'..xml.find(result, 'banner')[1] + utilities.send_typing(msg.chat.id, 'upload_photo') + utilities.send_photo(msg.chat.id, image_url, nil, msg.message_id) + end + utilities.send_reply(msg, text, true) +end + + +function tv:action(msg, config, matches) + local series = URL.escape(matches[1]) + local tv_info = tv:get_tv_info(series) + if tv_info == "NOTFOUND" then + utilities.send_reply(msg, config.errors.results) + return + elseif tv_info == "HTTP-ERROR" then + utilities.send_reply(msg, config.errors.connection) + return + else + tv:send_tv_data(tv_info, msg) + end +end + +return tv diff --git a/miku/plugins/twitch.lua b/miku/plugins/twitch.lua index a3b0570..e837723 100644 --- a/miku/plugins/twitch.lua +++ b/miku/plugins/twitch.lua @@ -1,36 +1,36 @@ -local twitch = {} - -twitch.triggers = { - "twitch.tv/([A-Za-z0-9-_-]+)" -} - -local BASE_URL = 'https://api.twitch.tv' - -function twitch:send_twitch_info(twitch_name) - local url = BASE_URL..'/kraken/channels/'..twitch_name - local res,code = https.request(url) - if code ~= 200 then return "HTTP-FEHLER" end - local data = json.decode(res) - - local display_name = data.display_name - local name = data.name - if not data.game then - game = 'nichts' - else - game = data.game - end - local status = data.status - local views = comma_value(data.views) - local followers = comma_value(data.followers) - local text = '*'..display_name..'* ('..name..') streamt *'..game..'*\n'..status..'\n_'..views..' Zuschauer insgesamt und '..followers..' Follower_' - - return text -end - -function twitch:action(msg, config, matches) - local text = twitch:send_twitch_info(matches[1]) - if not text then utilities.send_reply(msg, config.errors.connection) return end - utilities.send_reply(msg, text, true) -end - -return twitch +local twitch = {} + +twitch.triggers = { + "twitch.tv/([A-Za-z0-9-_-]+)" +} + +local BASE_URL = 'https://api.twitch.tv' + +function twitch:send_twitch_info(twitch_name) + local url = BASE_URL..'/kraken/channels/'..twitch_name + local res,code = https.request(url) + if code ~= 200 then return "HTTP-FEHLER" end + local data = json.decode(res) + + local display_name = data.display_name + local name = data.name + if not data.game then + game = 'nichts' + else + game = data.game + end + local status = data.status + local views = comma_value(data.views) + local followers = comma_value(data.followers) + local text = '*'..display_name..'* ('..name..') streamt *'..game..'*\n'..status..'\n_'..views..' Zuschauer insgesamt und '..followers..' Follower_' + + return text +end + +function twitch:action(msg, config, matches) + local text = twitch:send_twitch_info(matches[1]) + if not text then utilities.send_reply(msg, config.errors.connection) return end + utilities.send_reply(msg, text, true) +end + +return twitch diff --git a/miku/plugins/wiimmfi.lua b/miku/plugins/wiimmfi.lua deleted file mode 100644 index 0b4bec7..0000000 --- a/miku/plugins/wiimmfi.lua +++ /dev/null @@ -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, "(.-)") - if players == nil then players = 0 end - text = 'Es spielen gerade '..players..' Spieler Mario Kart Wii' - else - local players = string.match(res, "(.-).-", ": ") - local players = string.gsub(players, "", "") - local players = string.gsub(players, "Wii", "") - local players = string.gsub(players, "WiiWare", "") - local players = string.gsub(players, "NDS", "") - local players = string.gsub(players, "", "") - local players = string.gsub(players, "", "") - local players = string.gsub(players, "", "") - local players = string.gsub(players, "", "") - local players = string.gsub(players, "", "") - local players = string.gsub(players, "", "") - local players = string.gsub(players, "", "") - 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 \ No newline at end of file diff --git a/miku/plugins/wikia.lua b/miku/plugins/wikia.lua index 0b204b7..346c158 100644 --- a/miku/plugins/wikia.lua +++ b/miku/plugins/wikia.lua @@ -27,14 +27,14 @@ function send_wikia_article(wikia, article) local abstract = data.items[id].abstract local article_url = data.basepath..data.items[id].url - local text = '*'..title..'*:\n'..abstract..' [Weiterlesen]('..article_url..')' + local text = ''..title..':\n'..abstract..' Weiterlesen' return text end function wikia:action(msg, config, matches) local wikia = matches[1] 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 return wikia \ No newline at end of file diff --git a/miku/plugins/yourls.lua b/miku/plugins/yourls.lua index 48c93ec..5956925 100644 --- a/miku/plugins/yourls.lua +++ b/miku/plugins/yourls.lua @@ -1,53 +1,53 @@ -local yourls = {} - -function yourls:init(config) - if not cred_data.yourls_site_url then - print('Fehlender Key: yourls_site_url.') - print('yourls.lua wird nicht aktiviert.') - return - elseif not cred_data.yourls_signature_token then - print('Fehlender Key: yourls_signature_token.') - print('yourls.lua wird nicht aktiviert.') - return - end - - yourls.triggers = { - "^/yourls (https?://[%w-_%.%?%.:/%+=&]+)" - } -end - -local SITE_URL = cred_data.yourls_site_url -local signature = cred_data.yourls_signature_token -local BASE_URL = SITE_URL..'/yourls-api.php' - -function yourls:prot_url(url) - local url, h = string.gsub(url, "http://", "") - local url, hs = string.gsub(url, "https://", "") - local protocol = "http" - if hs == 1 then - protocol = "https" - end - return url, protocol -end - -function yourls:create_yourls_link(long_url, protocol) - local url = BASE_URL..'?format=simple&signature='..signature..'&action=shorturl&url='..long_url - if protocol == "http" then - link,code = http.request(url) - else - link,code = https.request(url) - end - if code ~= 200 then - link = 'Ein Fehler ist aufgetreten. '..link - end - return link -end - -function yourls:action(msg, config, matches) - local long_url = matches[1] - local baseurl, protocol = yourls:prot_url(SITE_URL) - utilities.send_reply(msg, yourls:create_yourls_link(long_url, protocol)) - return -end - -return yourls +local yourls = {} + +function yourls:init(config) + if not cred_data.yourls_site_url then + print('Fehlender Key: yourls_site_url.') + print('yourls.lua wird nicht aktiviert.') + return + elseif not cred_data.yourls_signature_token then + print('Fehlender Key: yourls_signature_token.') + print('yourls.lua wird nicht aktiviert.') + return + end + + yourls.triggers = { + "^/yourls (https?://[%w-_%.%?%.:/%+=&]+)" + } +end + +local SITE_URL = cred_data.yourls_site_url +local signature = cred_data.yourls_signature_token +local BASE_URL = SITE_URL..'/yourls-api.php' + +function yourls:prot_url(url) + local url, h = string.gsub(url, "http://", "") + local url, hs = string.gsub(url, "https://", "") + local protocol = "http" + if hs == 1 then + protocol = "https" + end + return url, protocol +end + +function yourls:create_yourls_link(long_url, protocol) + local url = BASE_URL..'?format=simple&signature='..signature..'&action=shorturl&url='..long_url + if protocol == "http" then + link,code = http.request(url) + else + link,code = https.request(url) + end + if code ~= 200 then + link = 'Ein Fehler ist aufgetreten. '..link + end + return link +end + +function yourls:action(msg, config, matches) + local long_url = matches[1] + local baseurl, protocol = yourls:prot_url(SITE_URL) + utilities.send_reply(msg, yourls:create_yourls_link(long_url, protocol)) + return +end + +return yourls diff --git a/miku/plugins/youtube.lua b/miku/plugins/youtube.lua index 621e4b4..09570f4 100644 --- a/miku/plugins/youtube.lua +++ b/miku/plugins/youtube.lua @@ -98,15 +98,15 @@ function send_youtube_data(data, msg, self, link, sendpic) local upload_date = makeOurDate(data.snippet.publishedAt) local viewCount = comma_value(data.statistics.viewCount) if data.statistics.likeCount then - likeCount = ', '..comma_value(data.statistics.likeCount)..' Likes und ' - dislikeCount = comma_value(data.statistics.dislikeCount)..' Dislikes' + likeCount = ' | 👍 '..comma_value(data.statistics.likeCount)..' |' + dislikeCount = ' 👎 '..comma_value(data.statistics.dislikeCount)..'' else likeCount = '' dislikeCount = '' end if data.statistics.commentCount then - commentCount = ', '..comma_value(data.statistics.commentCount)..' Kommentare' + commentCount = ' | 🗣 '..comma_value(data.statistics.commentCount)..'' else commentCount = '' end @@ -120,7 +120,7 @@ function send_youtube_data(data, msg, self, link, sendpic) blocked = false end - text = ''..title..'\n('..uploader..' am '..upload_date..', '..viewCount..'x angesehen, Länge: '..duration..likeCount..dislikeCount..commentCount..')\n' + text = ''..title..'\n🎥 '..uploader..', 📅 '..upload_date..'\n👁 '..viewCount..' | 🕒 '..duration..''..likeCount..dislikeCount..commentCount..'\n' if link then text = link..'\n'..text end @@ -132,7 +132,7 @@ function send_youtube_data(data, msg, self, link, sendpic) if sendpic then 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 - 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 text = text..'\nACHTUNG, In Deutschland gesperrt!' end