diff --git a/.gitignore b/.gitignore index 646705e..f1be7ef 100644 --- a/.gitignore +++ b/.gitignore @@ -1,53 +1,8 @@ res/ .luarocks *.db -plugins/bitly.lua -plugins/danbooru2.lua -plugins/deviantart.lua -plugins/facebook.lua -plugins/facebook_photo.lua -plugins/facebook_video.lua -plugins/gender.lua -plugins/github.lua -plugins/googl.lua -plugins/ip_info.lua -plugins/konachan.lua -plugins/konachan_nsfw.lua -plugins/page2image.lua -plugins/pagespeed_insights.lua -plugins/ping_adress.lua plugins/test.lua -plugins/twitch.lua -plugins/derpibooru_nsfw.lua -plugins/derpibooru.lua -plugins/app_store.lua -plugins/dailymotion.lua -plugins/dns.lua -plugins/gdrive.lua -plugins/instagram.lua -plugins/play_store.lua -plugins/reddit.lua -plugins/soundcloud.lua -plugins/spotify.lua -plugins/vimeo.lua -plugins/vine.lua -plugins/youtube_playlist.lua -plugins/yandere.lua -plugins/e621.lua -plugins/ponyfaces.lua -plugins/rss_old.lua -plugins/gfycat.lua -plugins/yourls.lua -plugins/youtube_channel.lua -plugins/pr0gramm.lua plugins/licht.lua plugins/dantest.lua -plugins/flickr.lua -plugins/flickr_search.lua -plugins/google_books.lua -plugins/safebrowsing.lua plugins/stats2.lua -plugins/help2.lua -plugins/miiverse.lua -plugins/videotogif.lua -plugins/music163.lua \ No newline at end of file +plugins/help2.lua \ No newline at end of file diff --git a/bot/bot.lua b/bot/bot.lua index b374c90..7a3730c 100644 --- a/bot/bot.lua +++ b/bot/bot.lua @@ -1,26 +1,25 @@ -package.path = package.path .. ';.luarocks/share/lua/5.2/?.lua' - ..';.luarocks/share/lua/5.2/?/init.lua' -package.cpath = package.cpath .. ';.luarocks/lib/lua/5.2/?.so' - +package.path = './.luarocks/share/lua/5.2/?.lua;./.luarocks/share/lua/5.2/?/init.lua;./.luarocks/lib/lua/5.2/?.lua;./.luarocks/lib/lua/5.2/?/init.lua;' .. package.path +require("luarocks.loader") require("./bot/utils") -VERSION = '2.5-reloaded' +VERSION = '20151003' -- This function is called when tg receive a msg function on_msg_receive (msg) + if not started then return end local receiver = get_receiver(msg) - + -- vardump(msg) msg = pre_process_service_msg(msg) if msg_valid(msg) then msg = pre_process_msg(msg) - if msg then - match_plugins(msg) - --mark_read(receiver, ok_cb, false) + if msg then + match_plugins(msg) + -- mark_read(receiver, ok_cb, false) end end end @@ -33,9 +32,10 @@ function on_binlog_replay_end() postpone (cron_plugins, false, 60*5.0) -- See plugins/isup.lua as an example for cron - _config = load_config() + -- load sudo_users and credentials + sudo_users = load_sudo_users() cred_data = load_cred() - + -- load plugins plugins = {} load_plugins() @@ -53,11 +53,6 @@ function msg_valid(msg) print('\27[36mNicht gültig: alte Nachricht\27[39m') return false end - - if msg.unread == 0 then - print('\27[36mNicht gültig: gelesen\27[39m') - return false - end if not msg.to.id then print('\27[36mNicht gültig: To id not provided\27[39m') @@ -68,6 +63,11 @@ function msg_valid(msg) print('\27[36mNicht gültig: From id not provided\27[39m') return false end + + if msg.unread == 0 then + print('\27[36mNicht gültig: gelesen\27[39m') + return false + end if msg.from.id == our_id then print('\27[36mNicht gültig: Nachricht von unserer ID\27[39m') @@ -83,11 +83,10 @@ function msg_valid(msg) print('\27[36mNicht gültig: Telegram Nachricht\27[39m') return false end - + return true end --- function pre_process_service_msg(msg) if msg.service then local action = msg.action or {type=""} @@ -111,7 +110,7 @@ function pre_process_msg(msg) for name,plugin in pairs(plugins) do if plugin.pre_process and msg then -- print('Preprocess', name) - msg = plugin.pre_process(msg) + msg = plugin.pre_process(msg) end end @@ -125,22 +124,18 @@ function match_plugins(msg) end end --- Check if plugin is on _config.disabled_plugin_on_chat table -local function is_plugin_disabled_on_chat(plugin_name, receiver) - local disabled_chats = _config.disabled_plugin_on_chat - -- Table exists and chat has disabled plugins - if disabled_chats and disabled_chats[receiver] then - -- Checks if plugin is disabled on this chat - for disabled_plugin,disabled in pairs(disabled_chats[receiver]) do - if disabled_plugin == plugin_name and disabled then - local warning = 'Plugin '..disabled_plugin..' ist in diesem Chat deaktiviert' - print(warning) - -- send_msg(receiver, warning, ok_cb, false) - return true - end - end +-- Check if plugin is deactivated in this chat +local function is_plugin_disabled_on_chat(plugin_name, msg) + local hash = get_redis_hash(msg, 'disabled_plugins') + local disabled = redis:hget(hash, plugin_name) + + -- Plugin is disabled + if disabled == 'true' then + print('Plugin '..plugin_name..' ist in diesem Chat deaktiviert') + return true + else + return false end - return false end function match_plugin(plugin, plugin_name, msg) @@ -151,20 +146,13 @@ function match_plugin(plugin, plugin_name, msg) local matches = match_pattern(pattern, msg.text) if matches then print("Nachricht stimmt überein mit ", pattern) - -- Send typing - --if pattern ~= ".*" then send_typing(receiver, ok_cb, true) end - if is_plugin_disabled_on_chat(plugin_name, receiver) then + if is_plugin_disabled_on_chat(plugin_name, msg) then return nil end -- Function exists if plugin.run then - -- check if user has privileges - if can_use_bot(msg) then - print("Gesperrt") - -- local text = 'Du darfst den Bot nicht nutzen!' - -- send_msg(receiver, text, ok_cb, false) - else + if not plugin.notyping then send_typing(receiver, ok_cb, true) end -- If plugin is for privileged users only if not warns_user_not_allowed(plugin, msg) then local result = plugin.run(msg, matches) @@ -173,7 +161,6 @@ function match_plugin(plugin, plugin_name, msg) end end end - end -- One patterns matches return end @@ -185,61 +172,37 @@ function _send_msg(destination, text) send_large_msg(destination, text) end --- Save the content of _config to config.lua -function save_config( ) - serialize_to_file(_config, './data/config.lua') - print ('Configuration in ./data/config.lua gespeichert') +-- Load superusers from redis +function load_sudo_users() + if redis:exists("telegram:sudo_users") == false then + -- If sudo_users set doesnt exists + print ("Created new sudo_users set: telegram:sudo_users") + create_sudo_users() + end + local sudo_users = redis:smembers("telegram:sudo_users") + for v,user in pairs(sudo_users) do + print("Superuser: " .. user) + end + return sudo_users end --- Returns the config from config.lua file. --- If file doesn't exist, create it. -function load_config( ) - local f = io.open('./data/config.lua', "r") - -- If config.lua doesn't exist - if not f then - print ("Neue Config-Datei erstellt: data/config.lua") - create_config() - else - f:close() - end - local config = loadfile ("./data/config.lua")() - for v,user in pairs(config.sudo_users) do - print("Erlaubter Benutzer: " .. user) - end - return config -end - -function load_cred( ) - local cf = io.open('./data/credentials.lua', "r") - -- If credentials.lua doesnt exists - if not cf then - print ("Neue Credentials-Datei erstellt: data/credentials.lua") +-- Load credentials from redis +function load_cred() + if redis:exists("telegram:credentials") == false then + -- If credentials hash doesnt exists + print ("Neuen Credentials-Hash erstellt: telegram:credentials") create_cred() - else - cf:close() end - local _file_cred = loadfile ("./data/credentials.lua")() - return _file_cred + return redis:hgetall("telegram:credentials") end --- Create a basic config.json file and saves it. -function create_config( ) - -- A simple config with basic plugins and ourselves as privileged user - config = { - enabled_plugins = { - "help", - "plugins" }, - sudo_users = {our_id}, - disabled_channels = {} - } - serialize_to_file(config, './data/config.lua') - print ('Configuration in ./data/config.lua gespeichert') -end - -function create_cred( ) +-- create credentials hash with redis +function create_cred() cred = { bitly_access_token = "", - cloudconvert_apikey = "", + cloudinary_apikey = "", + cloudinary_api_secret = "", + cloudinary_public_id = "", derpibooru_apikey = "", fb_access_token = "", flickr_apikey = "", @@ -247,15 +210,20 @@ function create_cred( ) ftp_username = "", ftp_password = "", gender_apikey = "", + golem_apikey = "", google_apikey = "", google_cse_id = "", + gitlab_private_token = "", + gitlab_project_id = "", instagram_access_token = "", lyricsnmusic_apikey = "", + mal_username = "", + mal_pw = "", neutrino_userid = "", neutrino_apikey = "", + owm_apikey = "", page2images_restkey = "", soundcloud_client_id = "", - superfeedr_authorization = "", tw_consumer_key = "", tw_consumer_secret = "", tw_access_token = "", @@ -266,8 +234,28 @@ function create_cred( ) yourls_site_url = "", yourls_signature_token = "" } - serialize_to_file(cred, './data/credentials.lua') - print ('Credentials gespeichert in ./data/credentials.lua') + redis:hmset("telegram:credentials", cred) + print ('Credentials gespeichert in telegram:credentials') +end + +function create_sudo_users() + redis:sadd("telegram:sudo_users", '0') + redis:sadd("telegram:sudo_users", '1') + redis:sadd("telegram:sudo_users", our_id) + print('Speichere Superuser in telegram:sudo_users') + print('Adde deine ID mit Redis: SADD telegram:sudo_users YOURID') +end + +-- create plugin set if it doesn't exist +function create_plugin_set() + enabled_plugins = { + "plugins", + "manager" + } + print ('enabling a few plugins - saving to redis set telegram:enabled_plugins') + for _,plugin in pairs(enabled_plugins) do + redis:sadd("telegram:enabled_plugins", plugin) + end end function on_our_id (id) @@ -291,7 +279,11 @@ end -- Enable plugins in config.json function load_plugins() - for k, v in pairs(_config.enabled_plugins) do + enabled_plugins = redis:smembers('telegram:enabled_plugins') + if not enabled_plugins[1] then + create_plugin_set() + end + for k, v in pairs(enabled_plugins) do print("Lade Plugin", v) local ok, err = pcall(function() @@ -300,9 +292,10 @@ function load_plugins() end) if not ok then - print('\27[31mFehler beim laden des Plugins '..v..'\27[39m') + print('\27[31mFehler beim Laden vom Plugin '..v..'\27[39m') print('\27[31m'..err..'\27[39m') end + end end @@ -324,4 +317,5 @@ end our_id = 0 now = os.time() math.randomseed(now) -started = false + +started = false \ No newline at end of file diff --git a/bot/utils.lua b/bot/utils.lua index 2e032a7..51c6198 100644 --- a/bot/utils.lua +++ b/bot/utils.lua @@ -1,14 +1,14 @@ -URL = require "socket.url" -http = require "socket.http" -https = require "ssl.https" +http = require("socket.http") +https = require("ssl.https") ltn12 = require "ltn12" -serpent = require "serpent" -feedparser = require "feedparser" +URL = require("socket.url") +feedparser = require ("feedparser") json = (loadfile "./libs/JSON.lua")() +serpent = (loadfile "./libs/serpent.lua")() mimetype = (loadfile "./libs/mimetype.lua")() redis = (loadfile "./libs/redis.lua")() -http.TIMEOUT = 10 +http.TIMEOUT = 5 function get_receiver(msg) if msg.to.type == 'user' then @@ -19,7 +19,7 @@ function get_receiver(msg) end if msg.to.type == 'encr_chat' then return msg.to.print_name - end + end end function is_chat_msg( msg ) @@ -45,15 +45,9 @@ function string:split(sep) return fields end --- DEPRECATED -function string.trim(s) - print("string.trim(s) is DEPRECATED use string:trim() instead") - return s:gsub("^%s*(.-)%s*$", "%1") -end - -- Removes spaces -function string:trim() - return self:gsub("^%s*(.-)%s*$", "%1") +function string.trim(s) + return s:gsub("^%s*(.-)%s*$", "%1") end function get_http_file_name(url, headers) @@ -63,17 +57,18 @@ function get_http_file_name(url, headers) file_name = file_name or url:match("[^%w]+(%w+)[^%w]+$") -- Random name, hope content-type works file_name = file_name or str:random(5) - - local content_type = headers["content-type"] + + local content_type = headers["content-type"] local extension = nil if content_type then - extension = mimetype.get_mime_extension(content_type) + extension = mimetype.get_mime_extension(content_type) end + if extension then file_name = file_name.."."..extension end - + local disposition = headers["content-disposition"] if disposition then -- attachment; filename=CodeCogsEqn.png @@ -95,7 +90,7 @@ function download_to_file(url, file_name) url = url, sink = ltn12.sink.table(respbody), redirect = true - } + } -- nil, code, headers, status local response = nil @@ -147,16 +142,15 @@ function run_command(str) return result end --- User has privileges function is_sudo(msg) - local var = false - -- Check users id in config - for v,user in pairs(_config.sudo_users) do - if user == msg.from.id then - var = true - end - end - return var + local var = false + -- Check if user id is in sudoers table + for v,user in pairs(sudo_users) do + if string.match(user, msg.from.id) then + var = true + end + end + return var end function can_use_bot(msg) @@ -172,11 +166,11 @@ end -- Returns the name of the sender function get_name(msg) - local name = msg.from.first_name - if name == nil then - name = msg.from.id - end - return name + local name = msg.from.first_name + if name == nil then + name = msg.from.id + end + return name end -- Returns at table of lua files inside plugins @@ -255,27 +249,33 @@ end -- Download the image and send to receiver, it will be deleted. -- cb_function and cb_extra are optionals callback -function send_photo_from_url(receiver, url, cb_function, cb_extra) +function send_photo_from_url(receiver, url, cb_function, cb_extra, sendNotErrMsg) -- If callback not provided cb_function = cb_function or ok_cb cb_extra = cb_extra or false local file_path = download_to_file(url, false) if not file_path then -- Error - local text = 'Fehler beim laden des Bildes' - send_msg(receiver, text, cb_function, cb_extra) + if sendNotErrMsg then + return false + else + local text = 'Fehler beim Laden des Bildes' + send_msg(receiver, text, cb_function, cb_extra) + end else print("Datei Pfad: "..file_path) _send_photo(receiver, file_path, cb_function, cb_extra) + return true end end -- Same as send_photo_from_url but as callback function -function send_photo_from_url_callback(cb_extra, success, result) +function send_photo_from_url_callback(cb_extra, success, result, sendErrMsg) local receiver = cb_extra.receiver local url = cb_extra.url + local file_path = download_to_file(url, false) if not file_path then -- Error - local text = 'Fehler beim laden des Bildes' + local text = 'Fehler beim Herunterladen des Bildes' send_msg(receiver, text, ok_cb, false) else print("Datei Pfad: "..file_path) @@ -283,6 +283,21 @@ function send_photo_from_url_callback(cb_extra, success, result) end end +-- Same as above, but with send_as_document +function send_document_from_url_callback(cb_extra, success, result) + local receiver = cb_extra.receiver + local url = cb_extra.url + + local file_path = download_to_file(url, false) + if not file_path then -- Error + local text = 'Fehler beim Herunterladen des Dokumentes' + send_msg(receiver, text, ok_cb, false) + else + print("File path: "..file_path) + _send_document(receiver, file_path, ok_cb, false) + end +end + -- Send multiple images asynchronous. -- param urls must be a table. function send_photos_from_url(receiver, urls) @@ -355,10 +370,24 @@ end -- Download the image and send to receiver, it will be deleted. -- cb_function and cb_extra are optionals callback -function send_document_from_url(receiver, url, cb_function, cb_extra) +function send_document_from_url(receiver, url, cb_function, cb_extra, sendNotErrMsg) + -- If callback not provided + cb_function = cb_function or ok_cb + cb_extra = cb_extra or false + local file_path = download_to_file(url, false) - print("Datei Pfad: "..file_path) - _send_document(receiver, file_path, cb_function, cb_extra) + if not file_path then -- Error + if sendNotErrMsg then + return false + else + local text = 'Fehler beim Herunterladen des Dokumentes' + send_msg(receiver, text, cb_function, cb_extra) + end + else + print("Datei Pfad: "..file_path) + _send_document(receiver, file_path, cb_function, cb_extra) + return true + end end -- Parameters in ?a=1&b=2 style @@ -409,48 +438,6 @@ function send_order_msg(destination, msgs) send_order_msg_callback(cb_extra, true) end -function send_order_msg_callback(cb_extra, success, result) - local destination = cb_extra.destination - local msgs = cb_extra.msgs - local file_path = cb_extra.file_path - if file_path ~= nil then - os.remove(file_path) - print("Deleted: " .. file_path) - end - if type(msgs) == 'string' then - send_large_msg(destination, msgs) - elseif type(msgs) ~= 'table' then - return - end - if #msgs < 1 then - return - end - local msg = table.remove(msgs, 1) - local new_cb_extra = { - destination = destination, - msgs = msgs - } - if type(msg) == 'string' then - send_msg(destination, msg, send_order_msg_callback, new_cb_extra) - elseif type(msg) == 'table' then - local typ = msg[1] - local nmsg = msg[2] - new_cb_extra.file_path = nmsg - if typ == 'document' then - send_document(destination, nmsg, send_order_msg_callback, new_cb_extra) - elseif typ == 'image' or typ == 'photo' then - send_photo(destination, nmsg, send_order_msg_callback, new_cb_extra) - elseif typ == 'audio' then - send_audio(destination, nmsg, send_order_msg_callback, new_cb_extra) - elseif typ == 'video' then - send_video(destination, nmsg, send_order_msg_callback, new_cb_extra) - else - send_file(destination, nmsg, send_order_msg_callback, new_cb_extra) - end - end -end - --- Same as send_large_msg_callback but friendly params function send_large_msg(destination, text) local cb_extra = { destination = destination, @@ -486,17 +473,13 @@ function send_large_msg_callback(cb_extra, success, result) end -- Returns a table with matches or nil -function match_pattern(pattern, text, lower_case) +--function match_pattern(pattern, text, lower_case) +function match_pattern(pattern, text) if text then - local matches = {} - if lower_case then - matches = { string.match(text:lower(), pattern) } - else - matches = { string.match(text, pattern) } - end - if next(matches) then - return matches - end + local matches = { string.match(text, pattern) } + if next(matches) then + return matches + end end -- nil end @@ -521,7 +504,7 @@ function load_from_file(file, default_data) return loadfile (file)() end - function run_bash(str) +function run_bash(str) local cmd = io.popen(str) local result = cmd:read('*all') cmd:close() @@ -536,11 +519,26 @@ function run_sh(msg) return text end +function round(num, idp) + if idp and idp>0 then + local mult = 10^idp + return math.floor(num * mult + 0.5) / mult + end + return math.floor(num + 0.5) +end + function unescape(str) str = string.gsub( str, '<', '<' ) str = string.gsub( str, '>', '>' ) str = string.gsub( str, '"', '"' ) str = string.gsub( str, ''', "'" ) + str = string.gsub( str, "Ä", "Ä") + str = string.gsub( str, "ä", "ä") + str = string.gsub( str, "Ö", "Ö") + str = string.gsub( str, "ö", "ö") + str = string.gsub( str, "Uuml;", "Ü") + str = string.gsub( str, "ü", "ü") + str = string.gsub( str, "ß", "ß") str = string.gsub( str, '&#(%d+);', function(n) return string.char(n) end ) str = string.gsub( str, '&#x(%d+);', function(n) return string.char(tonumber(n,16)) end ) str = string.gsub( str, '&', '&' ) -- Be sure to do this after all others @@ -563,4 +561,83 @@ function unescape_html(str) return var end) return new +end + +function post_petition(url, arguments) + local url, h = string.gsub(url, "http://", "") + local url, hs = string.gsub(url, "https://", "") + local post_prot = "http" + if hs == 1 then + post_prot = "https" + end + local response_body = {} + local request_constructor = { + url = post_prot..'://'..url, + method = "POST", + sink = ltn12.sink.table(response_body), + headers = {}, + redirect = false + } + + local source = arguments + if type(arguments) == "table" then + local source = helpers.url_encode_arguments(arguments) + end + request_constructor.headers["Content-Type"] = "application/x-www-form-urlencoded" + request_constructor.headers["Content-Length"] = tostring(#source) + request_constructor.source = ltn12.source.string(source) + if post_prot == "http" then + ok, response_code, response_headers, response_status_line = http.request(request_constructor) + else + ok, response_code, response_headers, response_status_line = https.request(request_constructor) + end + + if not ok then + return nil + end + + response_body = json:decode(table.concat(response_body)) + + return response_body +end + +function get_redis_hash(msg, var) + if msg.to.type == 'chat' then + return 'chat:'..msg.to.id..':'..var + end + if msg.to.type == 'user' then + return 'user:'..msg.from.id..':'..var + end +end + +function tablelength(T) + local count = 0 + for _ in pairs(T) do count = count + 1 end + return count +end + +function comma_value(amount) + local formatted = amount + while true do + formatted, k = string.gsub(formatted, "^(-?%d+)(%d%d%d)", '%1.%2') + if (k==0) then + break + end + end + return formatted +end + + +function string.ends(str, fin) + return fin=='' or string.sub(str,-string.len(fin)) == fin +end + +function get_location(user_id) + local hash = 'user:'..user_id + local set_location = redis:hget(hash, 'location') + if set_location == 'false' or set_location == nil then + return false + else + return set_location + end end \ No newline at end of file diff --git a/pictures/inlove.gif b/pictures/inlove.gif new file mode 100644 index 0000000..08e5d5a Binary files /dev/null and b/pictures/inlove.gif differ diff --git a/plugins/9gag.lua b/plugins/9gag.lua index b354fa0..94afe03 100644 --- a/plugins/9gag.lua +++ b/plugins/9gag.lua @@ -6,8 +6,7 @@ local function get_9GAG() 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 i = math.random(#gag) local link_image = gag[i].src local title = gag[i].title if link_image:sub(0,2) == '//' then link_image = msg.text:sub(3,-1) @@ -15,23 +14,22 @@ local function get_9GAG() return link_image, title end -local function send_title(cb_extra, success, result) - if success then - send_msg(cb_extra[1], cb_extra[2], ok_cb, false) - end -end - local function run(msg, matches) local receiver = get_receiver(msg) local url, title = get_9GAG() - send_photo_from_url(receiver, url, send_title, {receiver, title}) - return false + local cb_extra = { + receiver=receiver, + url=url + } + send_msg(receiver, title, send_photo_from_url_callback, cb_extra) end return { - description = "9GAG", - usage = {"/9gag"}, - patterns = {"^/9gag$"}, + description = "Sendet ein zufälliges Bild von 9GAG", + usage = "/9gag: Sendet ein zufälliges Bild von 9GAG.", + patterns = { + "^/9gag$" + }, run = run } diff --git a/plugins/afk.lua b/plugins/afk.lua index 7f4263a..3957976 100644 --- a/plugins/afk.lua +++ b/plugins/afk.lua @@ -1,23 +1,102 @@ -function run(msg, matches) - local text = matches[2] +do + +local function is_offline(hash) + local afk = redis:hget(hash, 'afk') + if afk == "true" then + return true + else + return false + end +end + +local function 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 + +local function switch_afk(user_name, user_id, chat_id, text) + local hash = 'afk:'..chat_id..':'..user_id + + if is_offline(hash) then + local afk_text = 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) + + 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 + +local function pre_process(msg) + if msg.to.type ~= "chat" then + -- Ignore + return msg + end + + local receiver = get_receiver(msg) + local user_name = get_name(msg) + local user_id = msg.from.id + local chat_id = msg.to.id + local hash = 'afk:'..chat_id..':'..user_id + + + if is_offline(hash) then + local afk_text = get_afk_text(hash) + redis:hset(hash, 'afk', false) + if afk_text then + redis:hset(hash, 'afk_text', false) + send_msg(receiver, user_name..' ist wieder da (war: '..afk_text..')!', ok_cb, false) + else + send_msg(receiver, user_name..' ist wieder da!', ok_cb, false) + end + end + + return msg +end + +local function run(msg, matches) + if msg.to.type ~= "chat" then + return "Mir ist's egal, ob du AFK bist ._." + end + + local user_id = msg.from.id + local chat_id = msg.to.id local user_name = get_name(msg) - if string.starts(msg.text, '/afk') and (text == nil) then - return user_name .. ' ist nun AFK' - else - return user_name .. ' ist nun AFK (' .. text .. ')' - end - - --[[if string.starts(msg.text, '/re') or string.starts(msg.text, '/wd') then - return user_name .. ' ist wieder da!' - end]] - + if matches[2] then + return switch_afk(user_name, user_id, chat_id, matches[2]) + else + return switch_afk(user_name, user_id, chat_id) + end end return { - description = 'Sagt dass ihr afk oder wieder da seid', - usage = {'/afk','/re','/wd'}, - patterns = {'^/([A|a][F|f][K|k])$','^/([A|a][F|f][K|k]) (.*)$','^/([R|r][E|e])$','^/([W|w][D|d])$'}, - run = run + description = 'AFK und online schalten', + usage = "/afk (Text): Setzt Status auf AFK mit optionalem Text", + patterns = { + "^/([A|a][F|f][K|k])$", + "^/([A|a][F|f][K|k]) (.*)$" + }, + run = run, + pre_process = pre_process } ---by Akamaru [https://ponywave.de] \ No newline at end of file + +-- by Akamaru [https://ponywave.de] +-- modified by iCON [http://wiidatabase.de] + +end \ No newline at end of file diff --git a/plugins/aktien.lua b/plugins/aktien.lua new file mode 100644 index 0000000..6059ca8 --- /dev/null +++ b/plugins/aktien.lua @@ -0,0 +1,54 @@ +-- This is a proprietary plugin, property of Andreas Bielawski, (c) 2015 +-- DO NOT USE WITHOUT PERMISSION + +do + +local function get_stock (symbol) + local BASE_URL = 'https://query.yahooapis.com/v1/public/yql' + local url = BASE_URL..'?q=select%20*%20from%20yahoo.finance.quotes%20where%20symbol="'..symbol..'"&env=http%3A%2F%2Fdatatables.org%2Falltables.env&format=json' + local res,code = https.request(url) + if code ~= 200 then return "HTTP-FEHLER" end + local data = json:decode(res).query.results.quote + return data +end + +function send_stock_data(data, receiver) + -- local ask = data.Ask + local bid = data.Bid + local change = data.Change + local percent = data.ChangeinPercent + local currency = data.Currency + local range = data.DaysRange + local name = data.Name + local yesterday = data.PreviousClose + local year_range = data.YearRange + local symbol = data.symbol + + local text = name..' ('..symbol..') Aktien in '..currency..':\nAktueller Preis: '..bid..' ('..change..' / '..percent..')\nGestriger Preis: '..yesterday..'\nHeute: '..range..'\nDieses Jahr: '..year_range + send_msg(receiver, text, ok_cb, false) +end + +local function run(msg, matches) + local symbol = string.upper(matches[1]) + local data = get_stock(symbol) + local receiver = get_receiver(msg) + if data.Bid ~= nil then + send_stock_data(data, receiver) + else + return "Dieses Symbol existiert nicht." + end +end + +return { + description = "Sendet Aktieninfos", + usage = "/aktien [Symbol]: Sendet Aktieninfos", + patterns = { + "^/aktien ([A-Za-z0-9]+)$", + "^/stocks ([A-Za-z0-9]+)$", + "^/aktie ([A-Za-z0-9]+)$", + "^/stock ([A-Za-z0-9]+)$" + }, + run = run +} + +end \ No newline at end of file diff --git a/plugins/alive.lua b/plugins/alive.lua index 43dd334..6d4d600 100644 --- a/plugins/alive.lua +++ b/plugins/alive.lua @@ -8,7 +8,9 @@ end return { description = "Ist der Bot noch da?", usage = {"Miku"}, - patterns = {"^[M|m]iku(?)$","^[M|m]iku$"}, + patterns = {"^[Mm][Ii][Kk][Uu](?)$", + "^[Mm][Ii][Kk][Uu]$" + }, run = run } --by Akamaru [https://ponywave.de] \ No newline at end of file diff --git a/plugins/app_store.lua b/plugins/app_store.lua new file mode 100644 index 0000000..e3e4185 --- /dev/null +++ b/plugins/app_store.lua @@ -0,0 +1,122 @@ +-- This is a proprietary plugin, property of Andreas Bielawski, (c) 2015 +-- DO NOT USE WITHOUT PERMISSION + +do + +local BASE_URL = 'https://itunes.apple.com/lookup' + +local makeOurDate = function(dateString) + local pattern = "(%d+)%-(%d+)%-(%d+)T" + local year, month, day = dateString:match(pattern) + return day..'.'..month..'.'..year +end + +local function get_appstore_data() + local url = BASE_URL..'/?id='..appid..'&country=de' + local res,code = https.request(url) + if code ~= 200 then return "HTTP-FEHLER" end + local data = json:decode(res).results[1] + + if data == nil then return 'NOTFOUND' end + if data.wrapperType ~= 'software' then return nil end + + return data +end + +local function send_appstore_data(data, receiver) + -- Header + local name = data.trackName + local author = data.sellerName + local price = data.formattedPrice + local version = data.version + + -- Body + local description = string.sub(unescape(data.description), 1, 150) .. '...' + local min_ios_ver = data.minimumOsVersion + local size = string.gsub(round(data.fileSizeBytes / 1000000, 2), "%.", "%,") -- wtf Apple, it's 1024, not 1000! + local release = makeOurDate(data.releaseDate) + if data.isGameCenterEnabled then + game_center = '\nUnterstützt Game Center' + else + game_center = '' + end + local category_count = tablelength(data.genres) + if category_count == 1 then + category = '\nKategorie: '..data.genres[1] + else + local category_loop = '\nKategorien: ' + for v in pairs(data.genres) do + if v < category_count then + category_loop = category_loop..data.genres[v]..', ' + else + category_loop = category_loop..data.genres[v] + end + end + category = category_loop + end + + -- Footer + if data.averageUserRating and data.userRatingCount then + avg_rating = 'Bewertung: '..string.gsub(data.averageUserRating, "%.", "%,")..' Sterne ' + ratings = 'von '..comma_value(data.userRatingCount)..' Bewertungen' + else + avg_rating = "" + ratings = "" + end + + + local header = name..' v'..version..' von '..author..' ('..price..'):' + local body = '\n'..description..'\nBenötigt mind. iOS '..min_ios_ver..'\nGröße: '..size..' MB\nErstveröffentlicht am '..release..game_center..category + local footer = '\n'..avg_rating..ratings + local text = header..body..footer + + -- Picture + if data.screenshotUrls[1] and data.ipadScreenshotUrls[1] then + image_url = data.screenshotUrls[1] + elseif data.screenshotUrls[1] and not data.ipadScreenshotUrls[1] then + image_url = data.screenshotUrls[1] + elseif not data.screenshotUrls[1] and data.ipadScreenshotUrls[1] then + image_url = data.ipadScreenshotUrls[1] + else + image_url = nil + end + + if image_url then + local cb_extra = { + receiver=receiver, + url=image_url + } + send_msg(receiver, text, send_photo_from_url_callback, cb_extra) + else + send_msg(receiver, text, ok_cb, false) + end +end + +local function run(msg, matches) + local receiver = get_receiver(msg) + if not matches[3] then + appid = matches[1] + else + appid = matches[3] + end + local data = get_appstore_data() + if data == nil then print('Das Appstore-Plugin unterstützt zurzeit nur Apps!') end + if data == 'HTTP-FEHLER' or data == 'NOTFOUND' then + return 'App nicht gefunden!' + else + send_appstore_data(data, receiver) + end +end + +return { + description = "Sendet iPhone App-Store Info.", + usage = {"Link zu App auf iTunes", + "/itunes (ID)" + }, + patterns = {"itunes.apple.com/(.*)/app/(.*)/id(%d+)", + "^/itunes (%d+)$" + }, + run = run +} + +end \ No newline at end of file diff --git a/plugins/birthday_get.lua b/plugins/birthday_get.lua new file mode 100644 index 0000000..92406a5 --- /dev/null +++ b/plugins/birthday_get.lua @@ -0,0 +1,51 @@ +local function get_value(msg, var_name) + local hash = 'telegram:birthdays' + if hash then + local value = redis:hget(hash, var_name) + if not value then + return'Geburtstag nicht gefunden, benutze "/getbd", um alle Geburtstage aufzulisten.' + else + return var_name..' hat am '..value..' Geburtstag' + end + end +end + +local function list_variables(msg) + local hash = 'telegram:birthdays' + + if hash then + print('Getting variable from redis hash '..hash) + local names = redis:hkeys(hash) + local text = '' + for i=1, #names do + variables = get_value(msg, names[i]) + text = text..variables.."\n" + end + if text == '' or text == nil then + return 'Keine Geburtstage vorhanden!' + else + return text + end + end +end + +local function run(msg, matches) + if matches[2] then + return get_value(msg, matches[2]) + else + return 'Geburtstagsliste:\n\n'..list_variables(msg) + end +end + +return { + description = "Zeigt Geburtstage, die mit /setbd gesetzt wurden", + usage = { + "/getbd: Gibt alle Geburtstage aus", + "/getbd (Name): Gibt den Geburtstag aus." + }, + patterns = { + "^(/getbd) (.+)$", + "^/getbd$" + }, + run = run +} \ No newline at end of file diff --git a/plugins/birthday_set.lua b/plugins/birthday_set.lua new file mode 100644 index 0000000..c7d4a6b --- /dev/null +++ b/plugins/birthday_set.lua @@ -0,0 +1,47 @@ +local function save_value(msg, name, value) + if (not name or not value) then + return "Benutzung: /setbd [Name] [Tag. Monat]" + end + + local hash = 'telegram:birthdays' + if hash then + print('Saving variable to redis hash '..hash) + redis:hset(hash, name, value) + return "Geburtstag von "..name.." am "..value.." gespeichert!" + end +end + +local function delete_value(msg, name) + local hash = 'telegram:birthdays' + if redis:hexists(hash, name) == true then + print('Deleting birthday from redis hash '..hash) + redis:hdel(hash, name) + return 'Geburtstag von "'..name..'" erfolgreich gelöscht!' + else + return 'Du kannst keinen Geburtstag löschen, der nicht existiert ._.' + end +end + +local function run(msg, matches) + local name = string.sub(matches[1], 1, 50) + local value = string.sub(matches[2], 1, 1000) + + if value == "nil" then + text = delete_value(msg, name, value) + else + text = save_value(msg, name, value) + end + return text +end + +return { + description = "Speichert Geburtstage.", + usage = { + "/setbd [Name] [Tag. Monat]: Speichert ein Geburtstag.", + "/setbd (Name) nil: Löscht Geburtstag" + }, + patterns = { + "^/setbd ([^%s]+) (.+)$" + }, + run = run +} \ No newline at end of file diff --git a/plugins/bitly.lua b/plugins/bitly.lua new file mode 100644 index 0000000..404701e --- /dev/null +++ b/plugins/bitly.lua @@ -0,0 +1,34 @@ +-- This is a proprietary plugin, property of Andreas Bielawski, (c) 2015 +-- DO NOT USE WITHOUT PERMISSION + +do + +local BASE_URL = 'https://api-ssl.bitly.com/v3/expand' + +local function expand_bitly_link (shorturl) + local access_token = cred_data.bitly_access_token + local url = BASE_URL..'?access_token='..access_token..'&shortUrl=https://bit.ly/'..shorturl + local res,code = https.request(url) + if code ~= 200 then return "HTTP-FEHLER" end + local data = json:decode(res).data + return data.expand[1].long_url +end + +local function run(msg, matches) + local shorturl = matches[1] + return expand_bitly_link(shorturl) +end + +return { + description = "Verlängert Bitly-Links", + usage = "Verlängert bit.ly, bitly.com, j.mp und andib.tk Links", + patterns = { + "bit.ly/([A-Za-z0-9-_-]+)", + "bitly.com/([A-Za-z0-9-_-]+)", + "j.mp/([A-Za-z0-9-_-]+)", + "andib.tk/([A-Za-z0-9-_-]+)" + }, + run = run +} + +end \ No newline at end of file diff --git a/plugins/bitly_create.lua b/plugins/bitly_create.lua new file mode 100644 index 0000000..ee28a87 --- /dev/null +++ b/plugins/bitly_create.lua @@ -0,0 +1,43 @@ +-- This is a proprietary plugin, property of Andreas Bielawski, (c) 2015 +-- DO NOT USE WITHOUT PERMISSION + +do + +local BASE_URL = 'https://api-ssl.bitly.com/v3/shorten' +local access_token = cred_data.bitly_access_token + +function create_bitlink (long_url, domain) + local url = BASE_URL..'?access_token='..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 run(msg, matches) + 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 + return create_bitlink(long_url, domain) +end + +return { + description = "Krzt einen Link", + usage = { + "/short [Link]: Krzt einen Link mit Bitly", + "/short [j.mp|bit.ly|bitly.com|andib.tk] [Link]: Krzt einen Link mit der ausgewhlten Kurz-URL" + }, + patterns = { + "^/short (j.mp) (https?://[%w-_%.%?%.:/%+=&]+)$", + "^/short (bit.ly) (https?://[%w-_%.%?%.:/%+=&]+)$", + "^/short (bitly.com) (https?://[%w-_%.%?%.:/%+=&]+)$", + "^/short (andib.tk) (https?://[%w-_%.%?%.:/%+=&]+)$", + "^/short (https?://[%w-_%.%?%.:/%+=&]+)$" + }, + run = run +} + +end \ No newline at end of file diff --git a/plugins/pluginsold/btc.lua b/plugins/btc.lua similarity index 68% rename from plugins/pluginsold/btc.lua rename to plugins/btc.lua index 8183070..b8428e9 100644 --- a/plugins/pluginsold/btc.lua +++ b/plugins/btc.lua @@ -6,9 +6,11 @@ local function getBTCX(amount,currency) 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/"..currency..'\n'..'Buy: '..data.ask..'\n'..'Sell: '..data.bid + text = "BTC/"..currency..'\n'..'Kaufen: '..ask..'\n'..'Verkaufen: '..bid -- If we have a number as second parameter, calculate the bitcoin amount if amount~=nil then @@ -39,14 +41,17 @@ local function run(msg, matches) end return { - description = "Bitcoin global average market value (in EUR or USD)", - usage = "!btc [EUR|USD] [amount]", + description = "Globaler Bitcoin-Wert (in EUR oder USD)", + usage = { + "/btc: Zeigt aktuellen Bitcoin-Kurs", + "/btc [EUR|USD] [Menge]: Rechnet Bitcoin in Euro/USD um" + }, patterns = { - "^!btc$", - "^!btc ([Ee][Uu][Rr])$", - "^!btc ([Uu][Ss][Dd])$", - "^!btc (EUR) (%d+[%d%.]*)$", - "^!btc (USD) (%d+[%d%.]*)$" + "^/btc$", + "^/btc ([Ee][Uu][Rr])$", + "^/btc ([Uu][Ss][Dd])$", + "^/btc (EUR) (%d+[%d%.]*)$", + "^/btc (USD) (%d+[%d%.]*)$" }, run = run -} +} \ No newline at end of file diff --git a/plugins/change_pic.lua b/plugins/change_pic.lua index 88f9db7..4cbc88f 100644 --- a/plugins/change_pic.lua +++ b/plugins/change_pic.lua @@ -10,6 +10,7 @@ return { description = "", usage = {""}, patterns = {"^/pic (.*)$"}, - run = run + run = run, + notyping = true } --by Akamaru [https://ponywave.de] \ No newline at end of file diff --git a/plugins/channels.lua b/plugins/channels.lua index a4ce5fd..8c378bb 100644 --- a/plugins/channels.lua +++ b/plugins/channels.lua @@ -1,53 +1,50 @@ -- Checks if bot was disabled on specific chat -local function is_channel_disabled( receiver ) - if not _config.disabled_channels then +local function is_channel_disabled(msg) + local hash = 'chat:'..msg.to.id..':disabled' + local disabled = redis:get(hash) + + if not disabled or disabled == "false" then return false end - if _config.disabled_channels[receiver] == nil then - return false - end - - return _config.disabled_channels[receiver] + return disabled end -local function enable_channel(receiver) - if not _config.disabled_channels then - _config.disabled_channels = {} - end - - if _config.disabled_channels[receiver] == nil then - return 'Channel ist nicht deaktiviert!' - end - - _config.disabled_channels[receiver] = false - - save_config() - return "Channel wieder aktiviert!" +local function enable_channel(msg) + local hash = 'chat:'..msg.to.id..':disabled' + local disabled = redis:get(hash) + if disabled then + print('Setze Redis Variable "'..hash..'" auf false') + redis:set(hash, false) + return 'Channel aktiviert' + else + return 'Channel ist nicht deaktiviert!' + end end -local function disable_channel( receiver ) - if not _config.disabled_channels then - _config.disabled_channels = {} - end - - _config.disabled_channels[receiver] = true - - save_config() - return "Channel deaktiviert!" +local function disable_channel(msg) + local hash = 'chat:'..msg.to.id..':disabled' + local disabled = redis:get(hash) + if disabled ~= "true" then + print('Setze Redis Variable "'..hash..'" auf true') + redis:set(hash, true) + return 'Channel deaktiviert' + else + return 'Channel ist bereits deaktiviert!' + end end local function pre_process(msg) - local receiver = get_receiver(msg) - -- If sender is sudo then re-enable the channel + -- If is sudo can reeanble the channel if is_sudo(msg) then if msg.text == "/channel enable" then - enable_channel(receiver) + enable_channel(msg) end end - if is_channel_disabled(receiver) then + if is_channel_disabled(msg) then + print('Channel wurde deaktiviert') msg.text = "" end @@ -55,22 +52,28 @@ local function pre_process(msg) end local function run(msg, matches) - local receiver = get_receiver(msg) -- Enable a channel if matches[1] == 'enable' then - return enable_channel(receiver) + return enable_channel(msg) end -- Disable a channel if matches[1] == 'disable' then - return disable_channel(receiver) + return disable_channel(msg) end end return { - description = "", - usage = {"/channel kann nur Akamaru"}, - patterns = {"^/channel? (enable)","^/channel? (disable)" }, - run = run, - privileged = true, - pre_process = pre_process + description = "(De)aktiviert den Bot im Chat (nur Superuser).", + usage = { + "/channel enable: Aktiviert den Bot im Chat", + "/channel disable: Deaktiviert den Bot im Chat" + }, + patterns = { + "^/channel? (enable)", + "^/channel? (disable)" + }, + run = run, + privileged = true, + pre_process = pre_process, + notyping = true } \ No newline at end of file diff --git a/plugins/cleverbot.lua b/plugins/cleverbot.lua new file mode 100644 index 0000000..be6daad --- /dev/null +++ b/plugins/cleverbot.lua @@ -0,0 +1,27 @@ +do + +function run(msg, matches) + local text = msg.text + local url = "http://nocf.andibi.tk/dl/chatter-bot-api/cleverbot.php?text="..URL.escape(text) + local query = http.request(url) + if query == nil then return 'Ein Fehler ist aufgetreten :(' end + local decode = json:decode(query) + local answer = string.gsub(decode.clever, "Ä", "") + local answer = string.gsub(answer, "ä", "") + local answer = string.gsub(answer, "Ö", "") + local answer = string.gsub(answer, "ö", "") + local answer = string.gsub(answer, "Ü", "") + local answer = string.gsub(answer, "ü", "") + local answer = string.gsub(answer, "ß", "") + return answer +end + + +return { + description = "Chat mit CleverBot", + usage = "/cbot [Text]: Befragt den Cleverbot", + patterns = {"^/cbot (.*)$"}, + run = run +} + +end \ No newline at end of file diff --git a/plugins/create_sticker.lua b/plugins/create_sticker.lua new file mode 100644 index 0000000..4deb9ec --- /dev/null +++ b/plugins/create_sticker.lua @@ -0,0 +1,57 @@ +-- This is a proprietary plugin, property of Andreas Bielawski, (c) 2015 +-- DO NOT USE WITHOUT PERMISSION + +do + +local apikey = cred_data.cloudinary_apikey +local api_secret = cred_data.cloudinary_api_secret +local public_id = cred_data.cloudinary_public_id +local BASE_URL = 'https://api.cloudinary.com/v1_1/'..public_id..'/image' + +local function upload_image(file_url) + local timestamp = os.time() + local signature = sha1('timestamp='..timestamp..api_secret) + local upload_url = BASE_URL..'/upload?api_key='..apikey..'&file='..file_url..'×tamp='..timestamp..'&signature='..signature + local res,code = https.request(upload_url) + if code ~= 200 then return "HTTP-FEHLER" end + local data = json:decode(res) + return data.public_id +end + +local function destroy_image(image_id) + local timestamp = os.time() + local signature = sha1('public_id='..image_id..'×tamp='..timestamp..api_secret) + local destroy_url = BASE_URL..'/destroy?api_key='..apikey..'&public_id='..image_id..'×tamp='..timestamp..'&signature='..signature + local res,code = https.request(destroy_url) + if code ~= 200 then print("Lschen fehlgeschlagen") end + local data = json:decode(res) + if data.result == "ok" then + print("Datei von Cloudinary-Server gelscht") + else + print("Lschen fehlgeschlagen") + end +end + +local function run(msg, matches) + if not sha1 then + print('sha1 Library wird zum ersten Mal geladen...') + sha1 = (loadfile "./libs/sha1.lua")() + end + local file_url = matches[1] + local image_id = upload_image(file_url) + local file_url = 'https://res.cloudinary.com/'..public_id..'/image/upload/w_512/'..image_id..'.webp' + local receiver = get_receiver(msg) + send_document_from_url(receiver, file_url, cb_extra) + destroy_image(image_id) +end + +return { + description = "Erstellt einen Sticker on-the-fly.", + usage = "/sticker [Bilder-URL]: Erstelt einen Sticker aus einem Bild", + patterns = { + "^/sticker (https?://[%w-_%.%?%.:/%+=&]+)" + }, + run = run +} + +end \ No newline at end of file diff --git a/plugins/credentials_manager.lua b/plugins/credentials_manager.lua new file mode 100644 index 0000000..e499134 --- /dev/null +++ b/plugins/credentials_manager.lua @@ -0,0 +1,118 @@ +-- This file is part of the Telegram Bot "Brawlbot" (telegram.me/Brawlbot) by Andreas Bielawski (telegram.me/Brawl) +-- Released unter the MPLv2 + +local hash = "telegram:credentials" + +-- See: http://www.lua.org/pil/19.3.html +function pairsByKeys (t, f) + local a = {} + for n in pairs(t) do table.insert(a, n) end + table.sort(a, f) + local i = 0 -- iterator variable + local iter = function () -- iterator function + i = i + 1 + if a[i] == nil then + return nil + else + return a[i], t[a[i]] + end + end + return iter +end + +function reload_creds() + cred_data = redis:hgetall(hash) +end + +function list_creds() + reload_creds() + if redis:exists("telegram:credentials") == true then + local text = "" + for var, key in pairsByKeys(cred_data) do + text = text..var..' = '..key..'\n' + end + return text + else + create_cred() + return "Es wurden noch keine Logininformationen gespeichert, lege Tabelle an...\nSpeichere Keys mit !creds add [Variable] [Key] ein!" + end +end + +function add_creds(var, key) + print('Saving credential for '..var..' to redis hash '..hash) + redis:hset(hash, var, key) + reload_creds() + return var..' = '..key..'\neingespeichert!' +end + +function del_creds(var) + if redis:hexists(hash, var) == true then + print('Deleting credential for '..var..' from redis hash '..hash) + redis:hdel(hash, var) + reload_creds() + return 'Key von "'..var..'" erfolgreich gelscht!' + else + return 'Du hast keine Logininformationen fr diese Variable eingespeichert.' + end +end + +function rename_creds(var, newvar) + if redis:hexists(hash, var) == true then + local key = redis:hget(hash, var) + if redis:hsetnx(hash, newvar, key) == true then + redis:hdel(hash, var) + reload_creds() + return '"'..var..'" erfolgreich zu "'..newvar..'" umbenannt.' + else + return "Variable konnte nicht umbenannt werden: Zielvariable existiert bereits." + end + else + return 'Die zu umbennende Variable existiert nicht.' + end +end + +function run(msg, matches) + local receiver = get_receiver(msg) + + if not is_sudo(msg) then + return 'Du bist kein Superuser. Dieser Vorfall wird gemeldet!' + end + + if msg.to.type == 'chat' then + return 'Das Plugin solltest du nur per PN nutzen!' + end + + if matches[1] == "!creds" then + return list_creds() + elseif matches[1] == "!creds add" then + local var = string.lower(string.sub(matches[2], 1, 50)) + local key = string.sub(matches[3], 1, 1000) + return add_creds(var, key) + elseif matches[1] == "!creds del" then + local var = string.lower(matches[2]) + return del_creds(var) + elseif matches[1] == "!creds rename" then + local var = string.lower(string.sub(matches[2], 1, 50)) + local newvar = string.lower(string.sub(matches[3], 1, 1000)) + return rename_creds(var, newvar) + end +end + +return { + description = "Loginmanager fr Telegram (nur Superuser)", + usage = { + "/creds: Zeigt alle Logindaten und API-Keys", + "/creds add [Variable] [Key]: Speichert Key mit der Variable ein", + "/creds del [Variable]: Lscht Key mit der Variable", + "/creds rename [Variable] [Neuer Name]: Benennt Variable um, behlt Key bei" + }, + patterns = { + "^(/creds)$", + "^(/creds add) ([^%s]+) (.+)$", + "^(/creds del) (.+)$", + "^(/creds rename) ([^%s]+) (.+)$" + }, + run = run, + privileged = true, + notyping = true +} \ No newline at end of file diff --git a/plugins/curl_head.lua b/plugins/curl_head.lua index ac7b467..5ffe390 100644 --- a/plugins/curl_head.lua +++ b/plugins/curl_head.lua @@ -5,9 +5,12 @@ function run(msg, matches) return 'Vergiss es' end - if string.match(msg.text, '/[Hh][Ee][Aa][Dd]') then + if string.match(msg.text, '[Hh][Ee][Aa][Dd]') then text = run_bash('curl --head --insecure ' .. URL) send_msg(receiver, text, ok_cb, false) + elseif string.match(msg.text, '[Dd][Ii][Gg]') then + text = run_bash('dig ' .. URL .. ' ANY') + send_msg(receiver, text, ok_cb, false) end end @@ -15,6 +18,7 @@ end return { description = "Fhrt Befehle in der Konsole aus", usage = {""}, - patterns = {"^/[Hh][Ee][Aa][Dd] (https?://[%w-_%.%?%.:/%+=&]+)$"}, + patterns = {"^/[Hh][Ee][Aa][Dd] (.*)$","^/[Dd][Ii][Gg] (.*)"}, run = run -} \ No newline at end of file +} +--by Akamaru [https://ponywave.de] \ No newline at end of file diff --git a/plugins/currency.lua b/plugins/currency.lua new file mode 100644 index 0000000..1c4d83a --- /dev/null +++ b/plugins/currency.lua @@ -0,0 +1,64 @@ +-- This is a proprietary plugin, property of Andreas Bielawski, (c) 2015 +-- DO NOT USE WITHOUT PERMISSION + +do + +local BASE_URL = 'https://currencyconverter.p.mashape.com' + +local function get_currency_data (from, to, amount) + local apikey = cred_data.x_mashape_key + local url = BASE_URL..'/?from='..from..'&from_amount='..amount..'&to='..to..'&mashape-key='..apikey + local res,code = https.request(url) + if code ~= 200 then return "HTTP-FEHLER" end + local data = json:decode(res) + return data +end + +local function send_currency_data(data, receiver) + if data.error ~= nil then + return + else + local from = data.from + local to = data.to + local from_amount = string.gsub(data.from_amount, "%.", "%,") + local dot_to_amount = round(data.to_amount, 2) + local to_amount = string.gsub(dot_to_amount, "%.", "%,") + local text = from_amount..' '..from..' = '..to_amount..' '..to + send_msg(receiver, text, ok_cb, false) + end +end + +local function run(msg, matches) + local from = string.upper(matches[1]) + if matches[2] == nil then + to = "EUR" + else + to = string.upper(matches[2]) + end + if matches[3] == nil then + amount = 1 + else + amount = string.gsub(matches[3],"%,","%.") + end + if matches[1] == "/eur" then + to = "USD" + from = "EUR" + end + local data = get_currency_data(from, to, amount) + local receiver = get_receiver(msg) + send_currency_data(data, receiver) +end + +return { + description = "Wandelt Geldeinheiten um. ?? ?? ??", + usage = "/money [von] [zu] [Menge]: Wandelt Geldeinheiten um (Symbole: ponywave.de/a/botmoney)", + patterns = { + "^/money ([A-Za-z]+)$", + "^/money ([A-Za-z]+) ([A-Za-z]+)$", + "^(money ([A-Za-z]+) ([A-Za-z]+) (%d+[%d%.,]*)$", + "^(/eur)$" + }, + run = run +} + +end \ No newline at end of file diff --git a/plugins/dailymotion.lua b/plugins/dailymotion.lua new file mode 100644 index 0000000..c8a87d4 --- /dev/null +++ b/plugins/dailymotion.lua @@ -0,0 +1,37 @@ +-- This is a proprietary plugin, property of Andreas Bielawski, (c) 2015 +-- DO NOT USE WITHOUT PERMISSION + +do + +local BASE_URL = 'https://api.dailymotion.com' + +function get_dm_data (dm_code) + local url = BASE_URL..'/video/'..dm_code + local res,code = https.request(url) + if code ~= 200 then return "HTTP-FEHLER" end + local data = json:decode(res) + return data +end + +function send_dailymotion_data(data, receiver) + local title = data.title + local channel = data.channel + local text = title..'\nHochgeladen in die Kategorie "'..channel..'"' + send_msg(receiver, text, ok_cb, false) +end + +function run(msg, matches) + local dm_code = matches[1] + local data = get_dm_data(dm_code) + local receiver = get_receiver(msg) + send_dailymotion_data(data, receiver) +end + +return { + description = "Sendet Dailymotion-Info.", + usage = "URL zu Dailymotion-Video", + patterns = {"dailymotion.com/video/([A-Za-z0-9-_-]+)"}, + run = run +} + +end \ No newline at end of file diff --git a/plugins/danbooru2.lua b/plugins/danbooru2.lua new file mode 100644 index 0000000..9315483 --- /dev/null +++ b/plugins/danbooru2.lua @@ -0,0 +1,41 @@ +-- This is a proprietary plugin, property of Andreas Bielawski, (c) 2015 +-- DO NOT USE WITHOUT PERMISSION + +do + +local function get_db(tag) + local BASE_URL = 'http://danbooru.donmai.us' + local url = BASE_URL..'/posts.json?tags='..tag + local b,c = http.request(url) + if c ~= 200 then return nil end + local db = json:decode(b) + -- truly randomize + math.randomseed(os.time()) + -- random max json table size + local i = math.random(#db) + local link_image = BASE_URL..db[i].file_url + return link_image +end + +local function run(msg, matches) + local tag = matches[1] + local tag = string.gsub(tag, " ", '_' ) + local tag = string.gsub(tag, ":", '%%3A' ) + local receiver = get_receiver(msg) + local url = get_db(tag) + if string.ends(url, ".gif") or string.ends(url, ".zip") or string.ends(url, ".webm") then + send_document_from_url(receiver, url) + else + send_photo_from_url(receiver, url, send_title, {receiver, title}) + end + return "Source: "..url +end + +return { + description = "Sendet ein zufälliges Bild von Danbooru.", + usage = {"/danbooru [Tags]","/db [Tags]"}, + patterns = {"^/danbooru (.*)$","^/db (.*)$"}, + run = run +} + +end \ No newline at end of file diff --git a/plugins/derpibooru.lua b/plugins/derpibooru.lua new file mode 100644 index 0000000..f9cbf80 --- /dev/null +++ b/plugins/derpibooru.lua @@ -0,0 +1,45 @@ +-- This is a proprietary plugin, property of Andreas Bielawski, (c) 2015 +-- DO NOT USE WITHOUT PERMISSION + +do + +local function get_dp(tag) + local BASE_URL = 'https://derpiboo.ru/' + local apikey = "" + + -- Ohne API-Key: Safe for work - mit API-Key: Not safe for work + if apikey == nil then + url = BASE_URL..'/search.json?q='..tag + else + url = BASE_URL..'/search.json?key='..apikey..'&q='..tag + end + + local b,c = https.request(url) + if c ~= 200 then return nil end + local dp = json:decode(b).search + -- truly randomize + math.randomseed(os.time()) + -- random max json table size + local i = math.random(#dp) + local link_image = 'https:'..dp[i].image + source = 'https://derpiboo.ru/'..dp[i].id_number + return link_image +end + +local function run(msg, matches) + local tag = matches[1] + local tag = string.gsub(tag, " ", '+' ) + local receiver = get_receiver(msg) + local url = get_dp(tag) + send_photo_from_url(receiver, url, send_title, {receiver, title}) + return "Source: "..source +end + +return { + description = "Sendet zuflliges Bild von Derpibooru.", + usage = {"/derpibooru [Tags]","/dp [Tags]"}, + patterns = {"^/derpibooru (.*)$","^/dp (.*)$"}, + run = run +} + +end \ No newline at end of file diff --git a/plugins/derpibooru_nsfw.lua b/plugins/derpibooru_nsfw.lua new file mode 100644 index 0000000..9b35c1d --- /dev/null +++ b/plugins/derpibooru_nsfw.lua @@ -0,0 +1,45 @@ +-- This is a proprietary plugin, property of Andreas Bielawski, (c) 2015 +-- DO NOT USE WITHOUT PERMISSION + +do + +local function get_dp2(tag) + local BASE_URL = 'https://derpiboo.ru/' + local apikey = cred_data.derpibooru_apikey + + -- Ohne API-Key: Safe for work - mit API-Key: Not safe for work + if apikey == nil then + url = BASE_URL..'/search.json?q='..tag + else + url = BASE_URL..'/search.json?key='..apikey..'&q='..tag + end + + local b,c = https.request(url) + if c ~= 200 then return nil end + local dp = json:decode(b).search + -- truly randomize + math.randomseed(os.time()) + -- random max json table size + local i = math.random(#dp) + local link_image = 'https:'..dp[i].image + source = 'https://derpiboo.ru/'..dp[i].id_number + return link_image +end + +local function run(msg, matches) + local tag = matches[1] + local tag = string.gsub(tag, " ", '+' ) + local receiver = get_receiver(msg) + local url = get_dp2(tag) + send_photo_from_url(receiver, url, send_title, {receiver, title}) + return "Source: "..source +end + +return { + description = "Sendet zuflliges Bild von Derpibooru.", + usage = {"/derpibooru2 [Tags]","/dp2 [Tags]"}, + patterns = {"^/derpibooru2 (.*)$","^/dp2 (.*)$"}, + run = run +} + +end \ No newline at end of file diff --git a/plugins/deviantart.lua b/plugins/deviantart.lua new file mode 100644 index 0000000..9463490 --- /dev/null +++ b/plugins/deviantart.lua @@ -0,0 +1,48 @@ +-- This is a proprietary plugin, property of Andreas Bielawski, (c) 2015 +-- DO NOT USE WITHOUT PERMISSION + +do + +local BASE_URL = 'https://backend.deviantart.com' + +function get_da_data (da_code) + local url = BASE_URL..'/oembed?url='..da_code + local res,code = https.request(url) + if code ~= 200 then return "HTTP-FEHLER" end + local data = json:decode(res) + return data +end + +function send_da_data(data, receiver) + local title = data.title + local category = data.category + local author_name = data.author_name + local text = title..' von '..author_name..'\n'..category + local image_url = data.fullsize_url + if image_url == nil then + image_url = data.url + end + local cb_extra = { + receiver=receiver, + url=image_url + } + send_msg(receiver, text, send_photo_from_url_callback, cb_extra) +end + +function run(msg, matches) + local da_code = 'http://'..matches[1]..'.deviantart.com/art/'..matches[2] + local data = get_da_data(da_code) + local receiver = get_receiver(msg) + send_da_data(data, receiver) +end + + + +return { + description = "Sendet deviantArt-Info.", + usage = {"deviantArt Link"}, + patterns = {"http://(.*).deviantart.com/art/(.*)"}, + run = run +} + +end \ No newline at end of file diff --git a/plugins/dns.lua b/plugins/dns.lua new file mode 100644 index 0000000..3e25f55 --- /dev/null +++ b/plugins/dns.lua @@ -0,0 +1,40 @@ +-- This is a proprietary plugin, property of Andreas Bielawski, (c) 2015 +-- DO NOT USE WITHOUT PERMISSION + +do + +local BASE_URL = 'https://jack-dns-tools.p.mashape.com/dnstools.php' + +local function get_domain_data (domain) + local apikey = cred_data.x_mashape_key + local url = BASE_URL..'?_method=DNS2IP&dns='..domain..'&mashape-key='..apikey + local res,code = https.request(url) + if code ~= 200 then return "HTTP-FEHLER" end + local data = json:decode(res) + return data +end + +local function send_domain_data(data, receiver) + if domain == data.ip then + return + else + local text = data.ip + send_msg(receiver, text, ok_cb, false) + end +end + +local function run(msg, matches) + domain = matches[1] + local data = get_domain_data(domain) + local receiver = get_receiver(msg) + send_domain_data(data, receiver) +end + +return { + description = "Löst Domain nach IP auf.", + usage = "/dns [Domain]", + patterns = {"^/dns (.*)$"}, + run = run +} + +end diff --git a/plugins/dogify.lua b/plugins/dogify.lua index 7f84225..71e47f4 100644 --- a/plugins/dogify.lua +++ b/plugins/dogify.lua @@ -15,6 +15,6 @@ end return { description = "Erstelle ein Doge Bild mit Wörtern", usage = {"/dogify das/was/du/willst"}, - patterns = {"^/dogify (.+)$"}, + patterns = {"^/dogify (.+)$","^/doge (.+)$"}, run = run } \ No newline at end of file diff --git a/plugins/dropbox.lua b/plugins/dropbox.lua new file mode 100644 index 0000000..9fdb162 --- /dev/null +++ b/plugins/dropbox.lua @@ -0,0 +1,41 @@ +-- This is a proprietary plugin, property of Andreas Bielawski, (c) 2015 +-- DO NOT USE WITHOUT PERMISSION + +do + +local function send_dropbox_data(link, receiver) + if string.ends(link, ".png") or string.ends(link, ".jpeg") or string.ends(link, ".jpg") then + send_photo_from_url(receiver, link) + elseif string.ends(link, ".webp") or string.ends(link, ".gif") then + send_document_from_url(receiver, link) + else + send_msg(receiver, link, ok_cb, false) + end +end + +local function run(msg, matches) + local folder = matches[1] + local file = matches[2] + local receiver = get_receiver(msg) + local link = 'https://dl.dropboxusercontent.com/s/'..folder..'/'..file + + local v,code = https.request(link) + if code == 200 then + send_dropbox_data(link, receiver) + else + return nil + end +end + + +return { + description = "Dropbox-Plugin", + usage = { + "Dropbox-URL: Postet Bild oder Direktlink" + }, + patterns = { + "dropbox.com/s/([a-z0-9]+)/([A-Za-z0-9-_-.-.-]+)" + }, + run = run +} +end \ No newline at end of file diff --git a/plugins/e621.lua b/plugins/e621.lua new file mode 100644 index 0000000..41c2005 --- /dev/null +++ b/plugins/e621.lua @@ -0,0 +1,36 @@ +-- This is a proprietary plugin, property of Andreas Bielawski, (c) 2015 +-- DO NOT USE WITHOUT PERMISSION +-- Modified by Akamaru [https://ponywave.de] + +do + +local function get_e621(tag) + local BASE_URL = 'https://e621.net' + local url = BASE_URL..'/post/index.json?tags='..tag + local b,c = https.request(url) + if c ~= 200 then return nil end + local e621 = json:decode(b) + -- truly randomize + math.randomseed(os.time()) + -- random max json table size + local i = math.random(#e621) + local link_image = e621[i].file_url + return link_image +end + +local function run(msg, matches) + local tag = matches[1] + local receiver = get_receiver(msg) + local url = get_e621(tag) + send_photo_from_url(receiver, url, send_title, {receiver, title}) + return "Source: "..url +end + +return { + description = "Sendet zufälliges Bild von e621.", + usage = {"/e621 [Tags]"}, + patterns = {"^/e621 (.*)$"}, + run = run +} + +end \ No newline at end of file diff --git a/plugins/facebook.lua b/plugins/facebook.lua new file mode 100644 index 0000000..5f4e08a --- /dev/null +++ b/plugins/facebook.lua @@ -0,0 +1,40 @@ +-- This is a proprietary plugin, property of Andreas Bielawski, (c) 2015 +-- DO NOT USE WITHOUT PERMISSION + +do + +local BASE_URL = 'https://graph.facebook.com' + +function get_fb_data (fb_code) + local access_token = cred_data.fb_access_token + local url = BASE_URL..'/'..fb_code..'?access_token='..access_token..'&locale=de_DE' + local res,code = https.request(url) + if code ~= 200 then return "HTTP-FEHLER" end + local data = json:decode(res) + return data +end + +function send_fb_data(data, receiver) + local from = data.from.name + local message = data.message + local name = data.name + local link = data.link + local text = from..' hat gepostet:\n'..message..'\n'..name..' '..link + send_msg(receiver, text, ok_cb, false) +end + +function run(msg, matches) + local fb_code = matches[2] + local data = get_fb_data(fb_code) + local receiver = get_receiver(msg) + send_fb_data(data, receiver) +end + +return { + description = "Sendet Facebook-Post.", + usage = {"Link zu einem Facebook-Post"}, + patterns = {"facebook.com/([A-Za-z0-9-_-]+)/posts/([0-9-]+)","facebook.com/permalink.([a-z-]+)%?story_fbid=([0-9-]+)"}, + run = run +} + +end diff --git a/plugins/facebook_photo.lua b/plugins/facebook_photo.lua new file mode 100644 index 0000000..a007728 --- /dev/null +++ b/plugins/facebook_photo.lua @@ -0,0 +1,46 @@ +-- This is a proprietary plugin, property of Andreas Bielawski, (c) 2015 +-- DO NOT USE WITHOUT PERMISSION + +do + +local BASE_URL = 'https://graph.facebook.com' + +function get_fbphoto_data (fbphoto_code) + local access_token = cred_data.fb_access_token + local url = BASE_URL..'/'..fbphoto_code..'?access_token='..access_token..'&locale=de_DE' + local res,code = https.request(url) + if code ~= 200 then return "HTTP-FEHLER" end + local data = json:decode(res) + return data +end + +function send_fbphoto_data(data, receiver) + local from = data.from.name + local name = data.name + if name then + text = from..' hat ein Bild gepostet:\n'..name + else + text = from..' hat ein Bild gepostet' + end + local image_url = data.source + local cb_extra = { + receiver=receiver, + url=image_url + } + send_msg(receiver, text, send_photo_from_url_callback, cb_extra) +end + +function run(msg, matches) + local fbphoto_code = matches[3] + local data = get_fbphoto_data(fbphoto_code) + local receiver = get_receiver(msg) + send_fbphoto_data(data, receiver) +end + +return { + description = "Sendet Facebook-Bilder-Post", + usage = "URL zu öffentlichem Facebook-Bild", + patterns = {"facebook.com/([A-Za-z0-9-._-]+)/photos/([A-Za-z0-9-._-]+)/([A-Za-z0-9-._-]+)"}, + run = run +} +end \ No newline at end of file diff --git a/plugins/facebook_video.lua b/plugins/facebook_video.lua new file mode 100644 index 0000000..166d6e1 --- /dev/null +++ b/plugins/facebook_video.lua @@ -0,0 +1,39 @@ +-- This is a proprietary plugin, property of Andreas Bielawski, (c) 2015 +-- DO NOT USE WITHOUT PERMISSION + +do + +local BASE_URL = 'https://graph.facebook.com' + +function get_fbvid_data (fbvid_code) + local access_token = cred_data.fb_access_token + local url = BASE_URL..'/'..fbvid_code..'?access_token='..access_token..'&locale=de_DE' + local res,code = https.request(url) + if code ~= 200 then return "HTTP-FEHLER" end + local data = json:decode(res) + return data +end + +function send_fbvid_data(data, receiver) + local from = data.from.name + local description = data.description + local source = data.source + local text = from..' hat ein Video gepostet:\n'..description..'\n'..source + send_msg(receiver, text, ok_cb, false) +end + +function run(msg, matches) + local fbvid_code = matches[1] + local data = get_fbvid_data(fbvid_code) + local receiver = get_receiver(msg) + send_fbvid_data(data, receiver) +end + +return { + description = "Sendet Facebook-Video.", + usage = {"Link zu einem Video auf Facebook"}, + patterns = {"facebook.com/video.php%?v=([0-9-]+)"}, + run = run +} + +end diff --git a/plugins/flickr.lua b/plugins/flickr.lua new file mode 100644 index 0000000..5d485de --- /dev/null +++ b/plugins/flickr.lua @@ -0,0 +1,50 @@ +-- This is a proprietary plugin, property of Andreas Bielawski, (c) 2015 +-- DO NOT USE WITHOUT PERMISSION + +do + +local BASE_URL = 'https://api.flickr.com/services/rest' + +function get_flickr_photo_data (photo_id) + local apikey = cred_data.flickr_apikey + local url = BASE_URL..'/?method=flickr.photos.getInfo&api_key='..apikey..'&photo_id='..photo_id..'&format=json&nojsoncallback=1' + local res,code = https.request(url) + if code ~= 200 then return "HTTP-FEHLER" end + local data = json:decode(res).photo + return data +end + +function send_flickr_photo_data(data, receiver) + local title = data.title._content + local username = data.owner.username + local taken = data.dates.taken + local views = data.views + if data.usage.candownload == 1 then + local image_url = 'https://farm'..data.farm..'.staticflickr.com/'..data.server..'/'..data.id..'_'..data.originalsecret..'_o_d.'..data.originalformat + local cb_extra = { + receiver=receiver, + url=image_url + } + local text = '"'..title..'", aufgenommen '..taken..' von '..username..' ('..data.views..' Aufrufe)' + send_msg(receiver, text, send_photo_from_url_callback, cb_extra) + else + local text = '"'..title..'", aufgenommen '..taken..' von '..username..' ('..data.views..' Aufrufe)\nBild kann nicht gepostet werden (Keine Berechtigung)' + send_msg(receiver, text, ok_cb, false) + end +end + +function run(msg, matches) + local photo_id = matches[2] + local data = get_flickr_photo_data(photo_id) + local receiver = get_receiver(msg) + send_flickr_photo_data(data, receiver) +end + +return { + description = "Sendet Flickr-Info.", + usage = "Flickr-URL: Sendet Bild von Flickr", + patterns = {"flickr.com/photos/([A-Za-z0-9-_-]+)/([0-9]+)"}, + run = run +} + +end \ No newline at end of file diff --git a/plugins/flickr_search.lua b/plugins/flickr_search.lua new file mode 100644 index 0000000..6202d11 --- /dev/null +++ b/plugins/flickr_search.lua @@ -0,0 +1,38 @@ +-- This is a proprietary plugin, property of Andreas Bielawski, (c) 2015 +-- DO NOT USE WITHOUT PERMISSION + +do + +local function get_flickr(term) + local BASE_URL = 'https://api.flickr.com/services/rest' + local url = BASE_URL..'/?method=flickr.photos.search&api_key=c34eff1b204eaecae0de7141bd60d578&format=json&nojsoncallback=1&privacy_filter=1&extras=url_o&text='..term + local b,c = https.request(url) + if c ~= 200 then return nil end + local photo = json:decode(b).photos.photo + -- truly randomize + math.randomseed(os.time()) + -- random max json table size + local i = math.random(#photo) + local link_image = photo[i].url_o + return link_image +end + +local function run(msg, matches) + local term = matches[1] + local receiver = get_receiver(msg) + local url = get_flickr(term) + if string.ends(url, ".gif") then + send_document_from_url(receiver, url) + else + send_photo_from_url(receiver, url) + end +end + +return { + description = "Sendet zuflliges Bild von Flickr.", + usage = "/flickr [Suchbegriff]: Postet Bild von Flickr", + patterns = {"^/flickr (.*)$"}, + run = run +} + +end \ No newline at end of file diff --git a/plugins/forecast.lua b/plugins/forecast.lua new file mode 100644 index 0000000..8e9ee23 --- /dev/null +++ b/plugins/forecast.lua @@ -0,0 +1,117 @@ +do + +local BASE_URL = "http://api.openweathermap.org/data/2.5/forecast/daily" + +local function get_condition_symbol(weather, n) + if weather.list[n].weather[1].main == 'Clear' then + return ' ☀' + elseif weather.list[n].weather[1].main == 'Clouds' then + return ' ☁☁' + elseif weather.list[n].weather[1].main == 'Rain' then + return ' ☔' + elseif weather.list[n].weather[1].main == 'Thunderstorm' then + return ' ☔☔☔☔' + elseif weather.list[n].weather[1].main == 'Snow' then + return ' ❄️' + else + return '' + end +end + +local function get_temp(weather, n) + local day = string.gsub(round(weather.list[n].temp.day, 1), "%.", "%,") + local night = string.gsub(round(weather.list[n].temp.night, 1), "%.", "%,") + local condition = weather.list[n].weather[1].description + return '☀️ '..day..'°C | 🌙 '..night..'°C | '..condition +end + +local function get_forecast(location, days) + print("Bekomme Wettervorhersage für ", location) + local location = string.gsub(location," ","+") + local url = BASE_URL + local apikey = cred_data.owm_apikey + local url = url..'?q='..location + local url = url..'&lang=de&units=metric&cnt='..days..'&APPID='..apikey + + local b, c, h = http.request(url) + if c ~= 200 then return nil end + + local weather = json:decode(b) + local city = weather.city.name + if weather.city.country == "" then + country = '' + else + country = ' ('..weather.city.country..')' + end + local header = 'Vorhersage für '..city..country..':\n' + + local text = 'Heute: '..get_temp(weather, 1)..get_condition_symbol(weather, 1) + + if days > 1 then + text = text..'\nMorgen: '..get_temp(weather, 2)..get_condition_symbol(weather, 2) + end + if days > 2 then + text = text..'\nÜbermorgen: '..get_temp(weather, 3)..get_condition_symbol(weather, 3) + end + + if days > 3 then + for day in pairs(weather.list) do + if day > 3 then + local actual_day = day-1 + text = text..'\n'..actual_day..' Tage: '..get_temp(weather, day)..get_condition_symbol(weather, day) + end + end + end + + return header..text +end + +local function run(msg, matches) + local user_id = msg.from.id + local city = get_location(user_id) + if not city then city = 'Berlin' end + + if tonumber(matches[1]) then + days = matches[1]+1 + else + days = 4 + end + + if matches[2] then + days = matches[1]+1 + city = matches[2] + end + + if not tonumber(matches[1]) and matches[1] ~= '!/orecast' then + city = matches[1] + end + + if days > 17 then + return 'Wettervorhersagen gehen nur von 1-16 Tagen!' + end + + local text = get_forecast(city, days) + if not text then + text = 'Konnte die Wettervorhersage für diese Stadt nicht bekommen.' + end + return text +end + +return { + description = "Wettervorhersage für deinen oder einen gewählten Ort", + usage = { + "/forecast: Wettervorhersage für deine Stadt (!location set [Ort])", + "/forecast [0-16]: Wettervorhersage für X Tage für deine Stadt (!location set [Ort])", + "/forecast (Stadt): Wettervorhersage für diese Stadt", + "/forecast [0-16] (Stadt): Wettervorhersage für X Tage für diese Stadt" + }, + patterns = { + "^/forecast$", + "^/forecast (%d+) (.*)$", + "^/forecast (%d+)", + "^/forecast (.*)$" + }, + run = run +} + +end \ No newline at end of file diff --git a/plugins/ftp.lua b/plugins/ftp.lua index ac1353a..75b7242 100644 --- a/plugins/ftp.lua +++ b/plugins/ftp.lua @@ -1,7 +1,5 @@ do -local ftp = (loadfile "./libs/ftp.lua")() - local function send_ftp_data (text_file, receiver) local BASE_URL = cred_data.ftp_site local username = cred_data.ftp_username @@ -16,6 +14,10 @@ local function send_ftp_data (text_file, receiver) end local function run(msg, matches) + if not ftp then + print('ftp Library wird zum ersten Mal geladen...') + ftp = (loadfile "./libs/ftp.lua")() + end local text_file = matches[1] local receiver = get_receiver(msg) send_ftp_data(text_file, receiver) diff --git a/plugins/gamesdb.lua b/plugins/gamesdb.lua new file mode 100644 index 0000000..6b44f17 --- /dev/null +++ b/plugins/gamesdb.lua @@ -0,0 +1,139 @@ +-- This is a proprietary plugin, property of Andreas Bielawski, (c) 2015 +-- DO NOT USE WITHOUT PERMISSION + +do + +local xml = require("xml") + +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 + +local function 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 + +local function send_game_photo(result, receiver) + local BASE_URL = xml.find(result, 'baseImgUrl')[1] + local images = {} + + --[[if xml.find(result, 'fanart') then + local fanart = xml.find(result, 'fanart')[1] + local fanrt_url = BASE_URL..fanart[1] + table.insert(images, fanrt_url) + end]] + + 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 + local file = download_to_file(v, 'game'..i..'.jpg') + send_photo(receiver, file, ok_cb, false) + end +end + +local function send_game_data(game_id, receiver) + local url = BASE_URL..'/GetGame.php?id='..game_id + local res,code = http.request(url) + if code ~= 200 then return "HTTP-FEHLER" 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 = 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 = tablelength(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 = '\nVideo: '..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 = 'Titel: '..title..'\nPlattform: '..platform..'\nRelease: '..date..genre..players..publisher..video..'\nBeschreibung: '..desc + send_msg(receiver, text, ok_cb, false) + + if xml.find(result, 'fanrt') or xml.find(result, 'boxart') then + send_game_photo(result, receiver) + end +end + +local function run(msg, matches) + local game = URL.escape(matches[1]) + local receiver = get_receiver(msg) + local game_id = get_game_id(game) + if not game_id then + return "Spiel nicht gefunden!" + else + send_game_data(game_id, receiver) + end +end + +return { + description = "Sendet Infos zu einem Spiel.", + usage = "/game [Spiel]: Sendet Infos zum Spiel", + patterns = {"^/game (.+)$"}, + run = run +} + +end \ No newline at end of file diff --git a/plugins/gay.lua b/plugins/gay.lua index 7dafbb0..9954a30 100644 --- a/plugins/gay.lua +++ b/plugins/gay.lua @@ -22,30 +22,45 @@ function getGay(text) end -- Random image from table - local i = math.random(#data.results) - return data.results[i].url + -- local i = math.random(#data.results) + -- return data.results[i].url + return data.results end function run(msg, matches) local receiver = get_receiver(msg) local text = matches[1] - local url = getGay(text) - if not url then + local results = getGay(text) + if not results then return "Kein Bild gefunden." end + local i = math.random(#results) + local url = nil; - if string.ends(url, ".svg") then - return "Fehler beim laden des Bildes." + local failed = true + local nofTries = 0 + while failed and nofTries < #results do + url = results[i].url; + print("Bilder-URL: ", url) + + if string.ends(url, ".gif") then + failed = not send_document_from_url(receiver, url, nil, nil, true) + elseif string.ends(url, ".jpg") or string.ends(url, ".jpeg") or string.ends(url, ".png") then + failed = not send_photo_from_url(receiver, url, nil, nil, true) + end + + nofTries = nofTries + 1 + i = i+1 + if i > #results then + i = 1 + end end - - print("Bilder-URL: ", url) - if string.ends(url, ".gif") then - send_document_from_url(receiver, url) - return "Source: "..url + + if failed then + return "Fehler beim Laden des Bildes." else - send_photo_from_url(receiver, url) - return "Source: "..url + return "Source: "..url end end diff --git a/plugins/gdrive.lua b/plugins/gdrive.lua new file mode 100644 index 0000000..b053262 --- /dev/null +++ b/plugins/gdrive.lua @@ -0,0 +1,82 @@ +-- This is a proprietary plugin, property of Andreas Bielawski, (c) 2015 +-- DO NOT USE WITHOUT PERMISSION + +do + +local BASE_URL = 'https://www.googleapis.com/drive/v2' + +local function get_drive_document_data (docid) + local apikey = cred_data.google_apikey + local url = BASE_URL..'/files/'..docid..'?key='..apikey..'&fields=id,title,mimeType,ownerNames,exportLinks,fileExtension' + local res,code = https.request(url) + local res = string.gsub(res, 'image/', '') + local res = string.gsub(res, 'application/', '') + if code ~= 200 then return "HTTP-FEHLER" end + local data = json:decode(res) + return data +end + +local function send_drive_document_data(data, receiver) + local title = data.title + local mimetype = data.mimeType + local id = data.id + local owner = data.ownerNames[1] + local text = '"'..title..'", freigegeben von '..owner + if data.exportLinks then + if data.exportLinks.png then + local image_url = data.exportLinks.png + local cb_extra = { + receiver=receiver, + url=image_url + } + send_msg(receiver, text, send_photo_from_url_callback, cb_extra) + else + local pdf_url = data.exportLinks.pdf + send_msg(receiver, text, ok_cb, false) + send_document_from_url(receiver, pdf_url) + end + else + local get_file_url = 'https://drive.google.com/uc?id='..id + local ext = data.fileExtension + if mimetype == "png" or mimetype == "jpg" or mimetype == "jpeg" or mimetype == "gif" or mimetype == "webp" then + local respbody = {} + local options = { + url = get_file_url, + sink = ltn12.sink.table(respbody), + redirect = false + } + local response = {https.request(options)} -- luasec doesn't support 302 redirects, so we must contact gdrive again + local code = response[2] + local headers = response[3] + local file_url = headers.location + if ext == "jpg" or ext == "jpeg" or ext == "png" then + send_photo_from_url(receiver, file_url) + else + send_document_from_url(receiver, file_url) + end + else + local text = '"'..title..'", freigegeben von '..owner..'\nDirektlink: '..get_file_url + send_msg(receiver, text, ok_cb, false) + end + end +end + +local function run(msg, matches) + local docid = matches[2] + local data = get_drive_document_data(docid) + local receiver = get_receiver(msg) + send_drive_document_data(data, receiver) +end + +return { + description = "Sendet Google-Drive-Info und PDF", + usage = "URL zu Google-Drive-Dateien", + patterns = { + "docs.google.com/(.*)/d/([A-Za-z0-9-_-]+)", + "drive.google.com/(.*)/d/([A-Za-z0-9-_-]+)", + "drive.google.com/(open)%?id=([A-Za-z0-9-_-]+)" + }, + run = run +} + +end \ No newline at end of file diff --git a/plugins/gender.lua b/plugins/gender.lua new file mode 100644 index 0000000..cb58c1f --- /dev/null +++ b/plugins/gender.lua @@ -0,0 +1,46 @@ +-- This is a proprietary plugin, property of Andreas Bielawski, (c) 2015 +-- DO NOT USE WITHOUT PERMISSION + +do + +local BASE_URL = 'https://gender-api.com/get' + +function get_gender_data (name) + local apikey = cred_data.gender_apikey + local url = BASE_URL..'?name='..name..'&key='..apikey + local res,code = https.request(url) + if code ~= 200 then return "HTTP-FEHLER" end + local data = json:decode(res) + return data +end + +function send_gender_data(data, receiver) + if data.gender == "female" then + gender = 'weiblich' + end + if data.gender == "male" then + gender = 'männlich' + end + if data.gender == "unknown" then + gender = 'unbekanntem Geschlechts' + end + local accuracy = data.accuracy + local text = name..' ist zu '..accuracy..'% '..gender + send_msg(receiver, text, ok_cb, false) +end + +function run(msg, matches) + name = matches[1] + local data = get_gender_data(name) + local receiver = get_receiver(msg) + send_gender_data(data, receiver) +end + +return { + description = "Sendet Geschlecht", + usage = {"/geschlecht [Name]","/gender [Name]"}, + patterns = {"^/geschlecht (.*)$","^/gender (.*)$"}, + run = run +} + +end diff --git a/plugins/get.lua b/plugins/get.lua index cba79a2..f00a4cb 100644 --- a/plugins/get.lua +++ b/plugins/get.lua @@ -1,37 +1,34 @@ -local function get_variables_hash(msg) - if msg.to.type == 'chat' then - return 'chat:'..msg.to.id..':variables' - end - if msg.to.type == 'user' then - return 'user:'..msg.from.id..':variables' - end -end - -local function list_variables(msg) - local hash = get_variables_hash(msg) - - if hash then - local names = redis:hkeys(hash) - local text = '' - for i=1, #names do - text = text..names[i]..'\n' - end - return text - end -end - local function get_value(msg, var_name) - local hash = get_variables_hash(msg) + local hash = get_redis_hash(msg, 'variables') if hash then local value = redis:hget(hash, var_name) if not value then - return'Not found, use "/get" to list variables' + return'Nicht gefunden, benutze "!get", um alle Variablen aufzulisten.' else - return var_name..' => '..value + return var_name..' = '..value end end end +local function list_variables(msg) + local hash = get_redis_hash(msg, 'variables') + + if hash then + print('Getting variable from redis hash '..hash) + local names = redis:hkeys(hash) + local text = '' + for i=1, #names do + variables = 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 + local function run(msg, matches) if matches[2] then return get_value(msg, matches[2]) @@ -41,9 +38,14 @@ local function run(msg, matches) end return { - description = "Bekommt Variable, die mit /set gesetzt wurde", - usage = {"/get (Variable)"}, - patterns = {"^/get (%a+)$","^/get$"}, - run = run, - pre_process = lex -} + description = "Bekommt Variablen, die mit !set gesetzt wurden", + usage = { + "/get: Gibt alle Variablen aus", + "/get (Variable): Gibt die Variable aus." + }, + patterns = { + "^(/get) (.+)$", + "^/get$" + }, + run = run +} \ No newline at end of file diff --git a/plugins/get_data.lua b/plugins/get_data.lua new file mode 100644 index 0000000..2abd563 --- /dev/null +++ b/plugins/get_data.lua @@ -0,0 +1,21 @@ +local function run(msg, matches) + local receiver = get_receiver(msg) + local url = matches[1] + if string.match(msg.text, "[Gg][Ee][Tt][Dd][Aa][Tt][Aa]") or string.match(msg.text, "[Ww][Gg][Ee][Tt]") then + send_document_from_url(receiver, url) + elseif string.match(msg.text, "[Gg][Ee][Tt][Ii][Mm][Gg]") then + send_photo_from_url(receiver, url) + end +end + +return { + description = "Ein plugin, um Bilder oder Dateien zu downloaden", + usage = {"/getdata [URL]", + "/getimg [URL]"}, + patterns = {"^/getdata (.*)$", + "/[Ww][Gg][Ee][Tt]", + "^/getimg (.*)$" + }, + run = run +} +--by Akamaru [https://ponywave.de] \ No newline at end of file diff --git a/plugins/get_txt.lua b/plugins/get_txt.lua new file mode 100644 index 0000000..873ab32 --- /dev/null +++ b/plugins/get_txt.lua @@ -0,0 +1,13 @@ +local function run(msg, matches) + local res,code = http.request(matches[1]..'.txt') + if code ~= 200 then return nil end + return res +end + + +return { + description = "", + usage = "", + patterns = {"^(.*).txt$"}, + run = run +} \ No newline at end of file diff --git a/plugins/gfycat.lua b/plugins/gfycat.lua new file mode 100644 index 0000000..2d9a62d --- /dev/null +++ b/plugins/gfycat.lua @@ -0,0 +1,46 @@ +do + +local function send_gfycat_gif(name, receiver) + local BASE_URL = "https://gfycat.com" + local url = BASE_URL..'/cajax/get/'..name + local res,code = https.request(url) + if code ~= 200 then return "HTTP-FEHLER" end + local data = json:decode(res).gfyItem + local file = download_to_file(data.gifUrl) + local cb_extra = {file_path=file} + if file == nil then + send_msg(receiver, 'Fehler beim Herunterladen von '..name, ok_cb, false) + else + send_document(receiver, file, rmtmp_cb, cb_extra) + end +end + +local function send_gfycat_thumb(name, receiver) + local BASE_URL = "https://thumbs.gfycat.com" + local url = BASE_URL..'/'..name..'-poster.jpg' + local file = download_to_file(url) + local cb_extra = {file_path=file} + if file == nil then + print('Fehler beim Herunterladen des Thumbnails von '..name) + else + send_photo(receiver, file, rmtmp_cb, cb_extra) + end +end + +local function run(msg, matches) + local name = matches[1] + local receiver = get_receiver(msg) + send_gfycat_gif(name, receiver) + send_gfycat_thumb(name, receiver) +end + +return { + description = "Postet Gfycat-Video", + usage = "gfycat-Link: Postet Gfycat-Video", + patterns = { + "gfycat.com/([A-Za-z0-9-_-]+)", + }, + run = run +} + +end \ No newline at end of file diff --git a/plugins/github.lua b/plugins/github.lua new file mode 100644 index 0000000..8f146d5 --- /dev/null +++ b/plugins/github.lua @@ -0,0 +1,76 @@ +-- This is a proprietary plugin, property of Andreas Bielawski, (c) 2015 +-- DO NOT USE WITHOUT PERMISSION + +do + +local BASE_URL = 'https://api.github.com' + +function get_gh_data() + if gh_commit_sha == nil then + url = BASE_URL..'/repos/'..gh_code + else + url = BASE_URL..'/repos/'..gh_code..'/git/commits/'..gh_commit_sha + end + local res,code = https.request(url) + if code ~= 200 then return "HTTP-FEHLER" end + local data = json:decode(res) + return data +end + +function send_github_data(data, receiver) + local name = data.name + local description = data.description + local owner = data.owner.login + local clone_url = data.clone_url + if data.language == nil or data.language == "" then + language = '' + else + language = '\nSprache: '..data.language + end + if data.open_issues_count == 0 then + issues = '' + else + issues = '\nOffene Bugreports: '..data.open_issues_count + end + if data.homepage == nil or data.homepage == "" then + homepage = '' + else + homepage = '\nHomepage: '..data.homepage + end + local text = name..' von '..owner..'\n'..description..'\ngit clone '..clone_url..language..issues..homepage + send_msg(receiver, text, ok_cb, false) +end + +function send_gh_commit_data(data, receiver) + local committer = data.committer.name + local message = data.message + local text = gh_code..'@'..gh_commit_sha..' von '..committer..':\n'..message + send_msg(receiver, text, ok_cb, false) +end + +function run(msg, matches) + gh_code = matches[1]..'/'..matches[2] + gh_commit_sha = matches[3] + local data = get_gh_data() + local receiver = get_receiver(msg) + if not gh_commit_sha then + send_github_data(data, receiver) + else + send_gh_commit_data(data, receiver) + end +end + +return { + description = "Sendet GitHub-Info.", + usage = { + "Link zu GitHub-Repo", + "Link zu GitHub-Commit" + }, + patterns = { + "github.com/([A-Za-z0-9-_-.-.]+)/([A-Za-z0-9-_-.-.]+)/commit/([a-z0-9-]+)", + "github.com/([A-Za-z0-9-_-.-.]+)/([A-Za-z0-9-_-.-.]+)/?$" + }, + run = run +} + +end \ No newline at end of file diff --git a/plugins/googl.lua b/plugins/googl.lua new file mode 100644 index 0000000..94b1871 --- /dev/null +++ b/plugins/googl.lua @@ -0,0 +1,38 @@ +-- This is a proprietary plugin, property of Andreas Bielawski, (c) 2015 +-- DO NOT USE WITHOUT PERMISSION + +do + +local BASE_URL = 'https://www.googleapis.com/urlshortener/v1' + +local function get_shortlink_data (shorturl) + local apikey = cred_data.google_apikey + local url = BASE_URL..'/url?key='..apikey..'&shortUrl=http://goo.gl/'..shorturl..'&projection=FULL' + local res,code = https.request(url) + if code ~= 200 then return "HTTP-FEHLER" end + local data = json:decode(res) + return data +end + +local function send_shortlink_data(data, receiver) + local longUrl = data.longUrl + local shortUrlClicks = data.analytics.allTime.shortUrlClicks + local text = longUrl..'\n'..shortUrlClicks..' mal geklickt' + send_msg(receiver, text, ok_cb, false) +end + +local function run(msg, matches) + local shorturl = matches[1] + local data = get_shortlink_data(shorturl) + local receiver = get_receiver(msg) + send_shortlink_data(data, receiver) +end + +return { + description = "Sendet Goo.gl-Info.", + usage = {"goo.gl URL"}, + patterns = {"goo.gl/([A-Za-z0-9-_-]+)"}, + run = run +} + +end diff --git a/plugins/google.lua b/plugins/google.lua index 70c1092..f159fcd 100644 --- a/plugins/google.lua +++ b/plugins/google.lua @@ -1,38 +1,53 @@ -local function googlethat(query) - local api = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&safe=active&hl=de&" +function googlethat(query) + local BASE_URL = 'https://www.googleapis.com/customsearch/v1' + local apikey = cred_data.google_apikey + local cseid = cred_data.google_cse_id + local number = 5 -- Set number of results + + local api = BASE_URL.."/?key="..apikey.."&cx="..cseid.."&gl=de&num="..number.."&safe=medium&fields=searchInformation%28formattedSearchTime,formattedTotalResults%29,items%28title,link%29&" local parameters = "q=".. (URL.escape(query) or "") -- Do the request local res, code = https.request(api..parameters) - if code ~=200 then return nil end + if code ~=200 then return nil end local data = json:decode(res) + if data.searchInformation.formattedTotalResults == "0" then return nil end - local results = {} - for key,result in ipairs(data.responseData.results) do + local results={} + for key,result in ipairs(data.items) do table.insert(results, { - result.titleNoFormatting, - result.unescapedUrl or result.url + result.title, + result.link }) end - return results + + local stats = data.searchInformation.formattedTotalResults..' Ergebnisse, gefunden in '..data.searchInformation.formattedSearchTime..' Sekunden' + return results, stats end -local function stringlinks(results) +function stringlinks(results, stats) local stringresults="" for key,val in ipairs(results) do stringresults=stringresults..val[1].." - "..val[2].."\n" end - return stringresults + return stringresults..stats end -local function run(msg, matches) - local results = googlethat(matches[1]) - return stringlinks(results) +function run(msg, matches) + local results, stats = googlethat(matches[1]) + if results == nil then + return 'Nichts gefunden!' + else + return stringlinks(results, stats) + end end return { - description = "Durchsucht Google und sendet die ersten 5 Ergebnisse", - usage = {"/google [Begriff]","/Google [Begriff]"}, - patterns = {"^/google (.*)$","^/Google (.*)$"}, - run = run + description = "Durchsucht Google", + usage = "/google [Suchbegriff]: Durchsucht Google", + patterns = { + "^/[Gg][Oo][Oo][Gg][Ll][Ee] (.*)$", + "^%.[Gg][Oo][Oo][Gg][Ll][Ee] (.*)$" + }, + run = run } \ No newline at end of file diff --git a/plugins/google_books.lua b/plugins/google_books.lua new file mode 100644 index 0000000..147daab --- /dev/null +++ b/plugins/google_books.lua @@ -0,0 +1,70 @@ +-- This is a proprietary plugin, property of Andreas Bielawski, (c) 2015 +-- DO NOT USE WITHOUT PERMISSION + +do + +local BASE_URL = 'https://www.googleapis.com/books/v1' + + +local function get_books_data (term) + local url = BASE_URL..'/volumes?q='..term..'&maxResults=3&fields=totalItems,items%28volumeInfo%28title,authors,publisher,publishedDate,pageCount,canonicalVolumeLink%29,saleInfo%28country,listPrice%29%29' + local res,code = https.request(url) + if code ~= 200 then return "HTTP-FEHLER" end + local data = json:decode(res) + return data +end + +local function send_books_data(data, receiver) + local text = "" + for book in pairs(data.items) do + text = text..'"'..data.items[book].volumeInfo.title..'"' + + if data.items[book].volumeInfo.publisher == nil and data.items[book].volumeInfo.pageCount ~= nil then + text = text..'\n'..data.items[book].volumeInfo.authors[1]..', ' + else + text = text..'\n'..data.items[book].volumeInfo.authors[1]..'' + end + + if data.items[book].volumeInfo.authors[1] == data.items[book].volumeInfo.publisher then data.items[book].volumeInfo.publisher = nil end + + if data.items[book].volumeInfo.publisher then + if data.items[book].volumeInfo.pageCount then + text = text..', '..data.items[book].volumeInfo.publisher..', ' + else + text = text..', '..data.items[book].volumeInfo.publisher + end + end + + if data.items[book].volumeInfo.pageCount then + text = text..data.items[book].volumeInfo.pageCount..' Seiten' + end + + if data.items[book].volumeInfo.publishedDate then + text = text..', erschienen '..data.items[book].volumeInfo.publishedDate + end + + if data.items[book].saleInfo.listPrice then + text = text..'\nPreis: '..data.items[book].saleInfo.listPrice.amount..' '..data.items[book].saleInfo.listPrice.currencyCode + end + + text = text..'\n'..data.items[book].volumeInfo.canonicalVolumeLink + text = text..'\n\n' + end + send_large_msg(receiver, text, ok_cb, false) +end + +local function run(msg, matches) + local term = URL.escape(matches[1]) + local data = get_books_data(term) + local receiver = get_receiver(msg) + send_books_data(data, receiver) +end + +return { + description = "Sucht nach Bchern in Google Books.", + usage = "/books [Suchbegriff]: Sucht nach Bchern in Google Books", + patterns = {"^/books (.*)$"}, + run = run +} + +end \ No newline at end of file diff --git a/plugins/gronkh_soundboard.lua b/plugins/gronkh_soundboard.lua new file mode 100644 index 0000000..e2d00bc --- /dev/null +++ b/plugins/gronkh_soundboard.lua @@ -0,0 +1,33 @@ +#Sounds from http://xufox.bplaced.net/GronkhSoundboard/ + +do + +local function run(msg, matches) + local receiver = get_receiver(msg) + local url = "http://code.ponywave.de/workspace/mikubot/gronkhsounds/"..matches[1]..".mp3" + local file = download_to_file(url) + local cb_extra = {file_path=file} + + if string.match(msg.text, "[Ll][Ii][Ss][Tt][Ee]") then + return "PonyWave.de/a/gronkhsounds" + end + + if not file then + return "Nichts gefunden!" + else + print('Sende Sound') + send_document(receiver, file, rmtmp_cb, cb_extra) + end + +end + +return { + description = "Gronkh Soundboard", + usage = {"/gronkh [Name]"}, + patterns = { + "^/gronkh (.*)$" + }, + run = run +} + +end \ No newline at end of file diff --git a/plugins/help.lua b/plugins/help.lua index 15249ed..dceecba 100644 --- a/plugins/help.lua +++ b/plugins/help.lua @@ -39,7 +39,7 @@ do end else plugin = plugins[name] - if not plugin then return nil end + if not plugin then return 'Dieses Plugin existiert nicht.' end end local text = "" diff --git a/plugins/images.lua b/plugins/images.lua index 9541474..c988997 100644 --- a/plugins/images.lua +++ b/plugins/images.lua @@ -10,7 +10,7 @@ end return { description = "Wenn ein Link zu einem Bild gesendet wird, läd und sendet der Bot das Bild.", usage = {"Link zum Bild"}, - patterns = {"^(https?://[%w-_%.%?%.:/%+=&]+%.png)$","^(https?://[%w-_%.%?%.:/%+=&]+%.jpg)$","^(https?://[%w-_%.%?%.:/%+=&]+%.jpeg)$",}, + patterns = {"^(https?://[%w-_%.%?%.:/%+=&]+%.png)","^(https?://[%w-_%.%?%.:/%+=&]+%.jpg)","^(https?://[%w-_%.%?%.:/%+=&]+%.jpeg)",}, run = run } diff --git a/plugins/imdb.lua b/plugins/imdb.lua index 1387e4d..d6eaefe 100644 --- a/plugins/imdb.lua +++ b/plugins/imdb.lua @@ -1,10 +1,14 @@ do -local BASE_URL = 'http://www.imdbapi.com' +local BASE_URL = 'https://www.omdbapi.com' -function get_imdb_data (movie) - local url = BASE_URL..'/?t='..movie - local res,code = http.request(url) +function get_imdb_data (movie, id) + if id then + url = BASE_URL..'/?i=tt'..movie + else + url = BASE_URL..'/?t='..movie + end + local res,code = https.request(url) if code ~= 200 then return "HTTP-FEHLER" end local data = json:decode(res) return data @@ -17,6 +21,7 @@ function send_imdb_data(data, receiver) else local title = data.Title local release = data.Released + if data.Type ~= "movie" then Type = '\nTyp: '..data.Type else Type = '' end if data.Runtime ~= "N/A" then runtime = '\nLaufzeit: '..data.Runtime else runtime = '' end if data.Genre ~= "N/A" then genre = '\nGenre: '..data.Genre else genre = '' end local director = data.Director @@ -33,8 +38,8 @@ function send_imdb_data(data, receiver) score = '' end local link = 'http://imdb.com/title/'..data.imdbID - local text = title..'\nErscheinungsdatm: '..release..runtime..genre..'\nDirector: '..director..writer..'\nSchauspieler: '..actors..plot..score..'\n-- '..link - if data.Poster ~= "N/A" then + local text = title..Type..'\nErscheinungsdatm: '..release..runtime..genre..'\nDirector: '..director..writer..'\nSchauspieler: '..actors..plot..score..'\n-- '..link + if data.Poster ~= "N/A" then local image_url = data.Poster local cb_extra = { receiver=receiver, @@ -48,8 +53,13 @@ function send_imdb_data(data, receiver) end function run(msg, matches) - local movie = matches[1]:gsub(' ', '+') - local data = get_imdb_data(movie) + if matches[2] then + local movie = matches[2] + data = get_imdb_data(movie, true) + else + local movie = url_encode(matches[1]:gsub(' ', '+')) + data = get_imdb_data(movie, nil) + end local receiver = get_receiver(msg) send_imdb_data(data, receiver) end @@ -57,7 +67,9 @@ end return { description = "Zeigt Info zu einem Film (von IMDB, englisch)", usage = "/imdb [Film]: Zeigt Info zu Film", - patterns = {"^/imdb (.+)"}, + patterns = {"^/imdb (.+)", + "imdb.com/title/(tt)(%d+[%d%.,]*)" + }, run = run } diff --git a/plugins/img_google.lua b/plugins/img_google.lua index 750629e..dcc654a 100644 --- a/plugins/img_google.lua +++ b/plugins/img_google.lua @@ -1,6 +1,8 @@ do -function getGoogleImage(text) +local _blacklist + +local function getGoogleImage(text) local text = URL.escape(text) local api = "https://ajax.googleapis.com/ajax/services/search/images?v=1.0&rsz=8&safe=active&q=" local res, code = http.request(api..text) @@ -21,38 +23,144 @@ function getGoogleImage(text) return nil end - -- Random image from table - local i = math.random(#data.results) - return data.results[i].url + return data.results end -function run(msg, matches) +local function is_blacklisted(msg) + local var = false + for v,word in pairs(_blacklist) do + if string.find(string.lower(msg), string.lower(word)) then + print("Wort steht auf der Blacklist!") + var = true + break + end + end + return var +end + +local function show_blacklist() + if not _blacklist[1] then + return "Keine Wörter geblacklisted!\nBlackliste welche mit /imgblacklist add [Wort]" + else + local sort_alph = function( a,b ) return a < b end + table.sort( _blacklist, sort_alph ) + local blacklist = "Folgende Wörter stehen auf der Blacklist:\n" + for v,word in pairs(_blacklist) do + blacklist = blacklist..'- '..word..'\n' + end + return blacklist + end +end + +local function add_blacklist() + print('Blacklisting '..word..' - saving to redis set telegram:img_blacklist') + if redis:sismember("telegram:img_blacklist", word) == true then + return '"'..word..'" steht schon auf der Blacklist.' + else + redis:sadd("telegram:img_blacklist", word) + return '"'..word..'" blacklisted!' + end +end + +local function remove_blacklist() + print('De-blacklisting '..word..' - removing from redis set telegram:img_blacklist') + if redis:sismember("telegram:img_blacklist", word) == true then + redis:srem("telegram:img_blacklist", word) + return '"'..word..'" erfolgreich von der Blacklist gelöscht!' + else + return '"'..word..'" steht nicht auf der Blacklist.' + end +end + +local function run(msg, matches) local receiver = get_receiver(msg) local text = matches[1] - local url = getGoogleImage(text) + if matches[2] then word = string.lower(matches[2]) end - if not url then - return "Kein Bild gefunden." + _blacklist = redis:smembers("telegram:img_blacklist") + + if text == "/imgblacklist show" then + if is_sudo(msg) then + return show_blacklist() + else + return "Du bist kein Superuser. Dieser Vorfall wird gemeldet!" + end end - if string.ends(url, ".svg") then - return "Fehler beim laden des Bildes." + if text == "/imgblacklist add" and word == nil then + return "Benutzung: /imgblacklist add [Wort]" + elseif text == "/imgblacklist add" and word then + if is_sudo(msg) then + return add_blacklist() + else + return "Du bist kein Superuser. Dieser Vorfall wird gemeldet!" + end end - - print("Bilder-URL: ", url) - if string.ends(url, ".gif") then - send_document_from_url(receiver, url) - return "Source: "..url + + if text == "/imgblacklist del" and word == nil then + return "Benutzung: /imgblacklist del [Wort]" + elseif text == "/imgblacklist del" and word then + if is_sudo(msg) then + return remove_blacklist() + else + return "Du bist kein Superuser. Dieser Vorfall wird gemeldet!" + end + end + + print ('Checking if search contains blacklisted words: '..text) + if is_blacklisted(text) then + return "Vergiss es ._." + end + + local results = getGoogleImage(text) + if not results then + return "Kein Bild gefunden!" + end + + -- Random image from table + local i = math.random(#results) + local url = nil; + + local failed = true + local nofTries = 0 + while failed and nofTries < #results do + url = results[i].url; + print("Bilder-URL: ", url) + + if string.ends(url, ".gif") then + failed = not send_document_from_url(receiver, url, nil, nil, true) + elseif string.ends(url, ".jpg") or string.ends(url, ".jpeg") or string.ends(url, ".png") then + failed = not send_photo_from_url(receiver, url, nil, nil, true) + end + + nofTries = nofTries + 1 + i = i+1 + if i > #results then + i = 1 + end + end + + if failed then + return "Fehler beim Herunterladen eines Bildes." else - send_photo_from_url(receiver, url) - return "Source: "..url + return "Source: "..url end end return { - description = "Sucht Bild mit Google-API und versendet es (SafeSearch aktiv)", - usage = {"/img [Suchbegriff]"}, - patterns = {"^/img (.*)$"}, - run = run + description = "Sucht Bild mit Google-API und versendet es (SafeSearch aktiv)", + usage = { + "/img [Suchbegriff]", + "/imgblacklist show: Zeigt Blacklist (nur Superuser)", + "/imgblacklist add [Wort]: Fügt Wort der Blacklist hinzu (nur Superuser)", + "/imgblacklist del [Wort]: Entfernt Wort aus der Blacklist (nur Superuser)" + }, + patterns = { + "^/img (.*)$", + "^(/imgblacklist show)$", + "^(/imgblacklist add) (.*)$", + "^(/imgblacklist del) (.*)$" + }, + run = run } -end +end \ No newline at end of file diff --git a/plugins/img_google_nsfw.lua b/plugins/img_google_nsfw.lua index 182e4fe..7732690 100644 --- a/plugins/img_google_nsfw.lua +++ b/plugins/img_google_nsfw.lua @@ -1,6 +1,8 @@ do -function getGoogleImage2(text) +local _blacklist + +local function getNSFWImage(text) local text = URL.escape(text) local api = "https://ajax.googleapis.com/ajax/services/search/images?v=1.0&rsz=8&q=" local res, code = http.request(api..text) @@ -21,38 +23,139 @@ function getGoogleImage2(text) return nil end - -- Random image from table - local i = math.random(#data.results) - return data.results[i].url + return data.results end -function run(msg, matches) +local function is_blacklisted(msg) + local var = false + for v,word in pairs(_blacklist) do + if string.find(string.lower(msg), string.lower(word)) then + print("Wort steht auf der Blacklist!") + var = true + break + end + end + return var +end + +local function show_blacklist() + if not _blacklist[1] then + return "Keine Wörter geblacklisted!\nBlackliste welche mit /imgblacklist add [Wort]" + else + local sort_alph = function( a,b ) return a < b end + table.sort( _blacklist, sort_alph ) + local blacklist = "Folgende Wörter stehen auf der Blacklist:\n" + for v,word in pairs(_blacklist) do + blacklist = blacklist..'- '..word..'\n' + end + return blacklist + end +end + +local function add_blacklist() + print('Blacklisting '..word..' - saving to redis set telegram:img_blacklist') + if redis:sismember("telegram:img_blacklist", word) == true then + return '"'..word..'" steht schon auf der Blacklist.' + else + redis:sadd("telegram:img_blacklist", word) + return '"'..word..'" blacklisted!' + end +end + +local function remove_blacklist() + print('De-blacklisting '..word..' - removing from redis set telegram:img_blacklist') + if redis:sismember("telegram:img_blacklist", word) == true then + redis:srem("telegram:img_blacklist", word) + return '"'..word..'" erfolgreich von der Blacklist gelöscht!' + else + return '"'..word..'" steht nicht auf der Blacklist.' + end +end + +local function run(msg, matches) local receiver = get_receiver(msg) local text = matches[1] - local url = getGoogleImage2(text) + if matches[2] then word = string.lower(matches[2]) end - if not url then - return "Kein Bild gefunden." + _blacklist = redis:smembers("telegram:img_blacklist") + + if text == "/imgblacklist show" then + if is_sudo(msg) then + return show_blacklist() + else + return "Du bist kein Superuser. Dieser Vorfall wird gemeldet!" + end end - if string.ends(url, ".svg") then - return "Fehler beim laden des Bildes." + if text == "/imgblacklist add" and word == nil then + return "Benutzung: /imgblacklist add [Wort]" + elseif text == "/imgblacklist add" and word then + if is_sudo(msg) then + return add_blacklist() + else + return "Du bist kein Superuser. Dieser Vorfall wird gemeldet!" + end end - - print("Bilder-URL: ", url) - if string.ends(url, ".gif") then - send_document_from_url(receiver, url) - return "Source: "..url + + if text == "/imgblacklist del" and word == nil then + return "Benutzung: /imgblacklist del [Wort]" + elseif text == "/imgblacklist del" and word then + if is_sudo(msg) then + return remove_blacklist() + else + return "Du bist kein Superuser. Dieser Vorfall wird gemeldet!" + end + end + + print ('Checking if search contains blacklisted words: '..text) + if is_blacklisted(text) then + return "Vergiss es ._." + end + + local results = getNSFWImage(text) + if not results then + return "Kein Bild gefunden!" + end + + -- Random image from table + local i = math.random(#results) + local url = nil; + + local failed = true + local nofTries = 0 + while failed and nofTries < #results do + url = results[i].url; + print("Bilder-URL: ", url) + + if string.ends(url, ".gif") then + failed = not send_document_from_url(receiver, url, nil, nil, true) + elseif string.ends(url, ".jpg") or string.ends(url, ".jpeg") or string.ends(url, ".png") then + failed = not send_photo_from_url(receiver, url, nil, nil, true) + end + + nofTries = nofTries + 1 + i = i+1 + if i > #results then + i = 1 + end + end + + if failed then + return "Fehler beim Herunterladen eines Bildes." else - send_photo_from_url(receiver, url) - return "Source: "..url + return "Source: "..url end end return { description = "Sucht Bild mit Google-API und versendet es [NSFW]", usage = {"/img2 [Suchbegriff]","/nsfwimg [Suchbegriff]"}, - patterns = {"^/img2 (.*)$","^/nsfwimg (.*)$"}, + patterns = {"^/img2 (.*)$", + "^/nsfwimg (.*)$"--[[, + "^(/imgblacklist show)$", + "^(/imgblacklist add) (.*)$", + "^(/imgblacklist del) (.*)$"]] + }, run = run } end \ No newline at end of file diff --git a/plugins/instagram.lua b/plugins/instagram.lua new file mode 100644 index 0000000..d2e5f61 --- /dev/null +++ b/plugins/instagram.lua @@ -0,0 +1,72 @@ +-- This is a proprietary plugin, property of Andreas Bielawski, (c) 2015 +-- DO NOT USE WITHOUT PERMISSION + +do + +local BASE_URL = 'https://api.instagram.com/v1' +local access_token = cred_data.instagram_access_token + +function get_insta_data (insta_code) + local url = BASE_URL..'/media/shortcode/'..insta_code..'?access_token='..access_token + local res,code = https.request(url) + if code ~= 200 then return "HTTP-FEHLER" end + local data = json:decode(res).data + return data +end + +function send_instagram_data(data, receiver) + -- Header + local username = data.user.username + local full_name = data.user.full_name + if username == full_name then + header = full_name..' hat ein' + else + header = full_name..' ('..username..') hat ein' + end + if data.type == 'video' then + header = header..' Video gepostet' + else + header = header..' Foto gepostet' + end + + -- Caption + if data.caption == nil then + caption = '' + else + caption = ':\n'..data.caption.text + end + + -- Footer + local comments = comma_value(data.comments.count) + local likes = comma_value(data.likes.count) + local footer = '\n'..likes..' Likes, '..comments..' Kommentare' + if data.type == 'video' then + footer = '\n'..data.videos.standard_resolution.url..footer + end + + -- Image + local image_url = data.images.standard_resolution.url + local cb_extra = { + receiver=receiver, + url=image_url + } + + -- Send all + send_msg(receiver, header..caption..footer, send_photo_from_url_callback, cb_extra) +end + +function run(msg, matches) + local insta_code = matches[1] + local data = get_insta_data(insta_code) + local receiver = get_receiver(msg) + send_instagram_data(data, receiver) +end + +return { + description = "Sendet Instagram-Info.", + usage = "URL zu Instagram-Post", + patterns = {"instagram.com/p/([A-Za-z0-9-_-]+)"}, + run = run +} + +end \ No newline at end of file diff --git a/plugins/ip_info.lua b/plugins/ip_info.lua new file mode 100644 index 0000000..666e893 --- /dev/null +++ b/plugins/ip_info.lua @@ -0,0 +1,63 @@ +-- This is a proprietary plugin, property of Andreas Bielawski, (c) 2015 +-- DO NOT USE WITHOUT PERMISSION + +do + +local BASE_URL = 'http://ipinfo.io' + +function get_ip_data (ip) + local url = BASE_URL..'/'..ip..'/json' + local res,code = http.request(url) + if code == 404 then return "Diese IP gibt es nicht!" end + if code ~= 200 then return "HTTP-FEHLER: "..code end + local data = json:decode(res) + + if data.hostname == "No Hostname" then + hostname = "" + else + hostname = ' ('..data.hostname..')' + end + + if data.org then + org = data.org + else + org = 'Unbekannt' + end + + + if data.city == "" or data.city == nil then + city = "Unbekannt" + else + city = data.city + end + + local country = data.country + + if data.region == "" or data.region == nil then + region = "" + else + region = ', '..data.region + end + + if data.postal then + postal = ' (PLZ: '..data.postal..')' + else + postal = '' + end + local text = 'Der Server von '..ip..' gehört zu '..org..hostname..' und steht in '..country..', genauer in '..city..region..postal + return text +end + +function run(msg, matches) + local ip = matches[1] + return get_ip_data(ip) +end + +return { + description = "Sendet IP-Info", + usage = "/ip [IP]: Sendet Server-Infos", + patterns = {"^/ip (.*)$"}, + run = run +} + +end \ No newline at end of file diff --git a/plugins/isup.lua b/plugins/isup.lua index ea9b2dc..8b46232 100644 --- a/plugins/isup.lua +++ b/plugins/isup.lua @@ -1,25 +1,79 @@ do -local socket = require("socket") -local cronned = load_from_file('data/isup.lua') -local function save_cron(msg, url, delete) - local origin = get_receiver(msg) - if not cronned[origin] then - cronned[origin] = {} - end - if not delete then - table.insert(cronned[origin], url) - else - for k,v in pairs(cronned[origin]) do - if v == url then - table.remove(cronned[origin], k) - end - end - end - serialize_to_file(cronned, 'data/isup.lua') - return 'Gespeichert!' +local function 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 +local function get_base_redis(id, option, extra) + local ex = '' + if option ~= nil then + ex = ex .. ':' .. option + if extra ~= nil then + ex = ex .. ':' .. extra + end + end + return 'isup:' .. id .. ex +end + +local function print_cron(id) + local uhash = get_base_redis(id) + local subs = redis:smembers(uhash) + local text = id .. ' prüft folgende Webseiten:\n---------\n' + for k,v in pairs(subs) do + text = text .. k .. ") " .. v .. '\n' + end + return text +end + +local function save_cron(id, url) + local url = string.lower(url) + local baseurl, protocol = prot_url(url) + local prothash = get_base_redis(baseurl, "protocol") + local checkhash = get_base_redis(baseurl, "check") + local uhash = get_base_redis(id) + + if redis:sismember(uhash, baseurl) then + return url..' wird bereits geprüft.' + end + + print('Saving...') + redis:set(prothash, protocol) + redis:sadd(checkhash, id) + redis:sadd(uhash, baseurl) + return url.." wird jetzt alle fünf Minuten geprüft!" +end + +local function delete_cron(id, n) + n = tonumber(n) + + local uhash = get_base_redis(id) + local subs = redis:smembers(uhash) + if n < 1 or n > #subs then + return "ID zu hoch!" + end + local sub = subs[n] + local lhash = get_base_redis(sub, "check") + + redis:srem(uhash, sub) + redis:srem(lhash, id) + + local left = redis:smembers(lhash) + if #left < 1 then -- no one subscribed, remove it + local prothash = get_base_redis(sub, "protocol") + local downhash = get_base_redis(sub, "down") + redis:del(prothash) + redis:del(downhash) + end + + return sub.." wird nicht mehr geprüft." +end + local function is_up_socket(ip, port) print('Connect to', ip, port) local c = socket.try(socket.tcp()) @@ -73,56 +127,96 @@ local function isup(url) else result = is_up_http(url) end - return result end local function cron() - for chan, urls in pairs(cronned) do - for k,url in pairs(urls) do - print('Checking', url) - if not isup(url) then - local text = url..' scheint DOWN zu sein' - send_msg(chan, text, ok_cb, false) - end + local keys = redis:keys(get_base_redis("*", "check")) + for k,v in pairs(keys) do + local base = string.match(v, "isup:(.+):check") -- Get the URL base + + print('ISUP: '..base) + local prot = redis:get(get_base_redis(base, "protocol")) + local url = prot .. "://" .. base + local hash = 'isup:'..base..':down' + local isdown = redis:get(hash) + if not isup(url) then + if isdown ~= 'true' then + redis:set(hash, 'true') + local text = url..' ist DOWN! ❌' + for e, receiver in pairs(redis:smembers(v)) do + send_msg(receiver, text, ok_cb, false) + end + else + print(base..' ist immer noch down') + end + else + if isdown == 'true' then + redis:set(hash, 'false') + local text = url..' ist wieder UP! ✅' + for e, receiver in pairs(redis:smembers(v)) do + send_msg(receiver, text, ok_cb, false) + end + end end end end local function run(msg, matches) - if matches[1] == 'remove' then - if not is_sudo(msg) then - return 'Du darfst diesen Befehl nicht nutzen!' - end - return save_cron(msg, matches[2], true) + local id = "user#id" .. msg.from.id - elseif matches[1] == 'save' then + if is_chat_msg(msg) then + id = "chat#id" .. msg.to.id + end + + + if matches[1] == 'cron show' then if not is_sudo(msg) then - return 'Du darfst diesen Befehl nicht nutzen!' + return 'Du darfst diesen Befehl nicht benutzen!' end - return save_cron(msg, matches[2]) + return print_cron(id) + + elseif matches[1] == 'cron check' then + if not is_sudo(msg) then + return 'Du darfst diesen Befehl nicht benutzen!' + end + return cron() + + elseif matches[1] == 'cron delete' then + if not is_sudo(msg) then + return 'Du darfst diesen Befehl nicht benutzen!' + end + return delete_cron(id, matches[2]) + + elseif matches[1] == 'cron' then + if not is_sudo(msg) then + return 'Du darfst diesen Befehl nicht benutzen!' + end + return save_cron(id, matches[2]) elseif isup(matches[1]) then - return matches[1]..' ist UP ✔' + return matches[1]..' ist UP! ✅' else - return matches[1]..' scheint DOWN zu sein ❌' + return matches[1]..' ist DOWN! ❌' end end return { - description = "Check if a website or server is up.", + description = "Checkt, ob eine Webseite up ist.", usage = { - "/isup [host]: Performs a HTTP request or Socket (ip:port) connexion", - "/isup save [host]: Every 5mins check if host is up. (Requires privileged user)", - "/isup remove [host]: Disable checking that host." + "/isup [Host]: Checkt, ob die Seite up ist", + "/isup cron [Host]: Checkt diese Seite alle 5 Minuten (nur Superuser)", + "/isup cron check: Prüfe alle Seiten jetzt", + "/isup cron show: Listet alle zu prüfenden Seiten auf", + "/isup cron delete [ID]: Checkt diese Seite nicht mehr" }, patterns = { - "^/isup (remove) (.*)$", - "^/isup (save) (.*)$", + "^/isup (cron check)$", + "^/isup (cron show)$", + "^/isup (cron delete) (%d+)$", + "^/isup (cron) (.*)$", "^/isup (.*)$", - "^/ping (.*)$", - "^/ping (remove) (.*)$", - "^/ping (save) (.*)$" + "^/ping (.*)$" }, run = run, cron = cron diff --git a/plugins/konachan.lua b/plugins/konachan.lua new file mode 100644 index 0000000..f79ef04 --- /dev/null +++ b/plugins/konachan.lua @@ -0,0 +1,32 @@ +do + +local function get_kc(tag) + local url = 'http://konachan.net/post.json?tags='..tag..' -rating:explicit' + local b,c = http.request(url) + if c ~= 200 then return nil end + local kc = json:decode(b) + -- truly randomize + math.randomseed(os.time()) + -- random max json table size + local i = math.random(#kc) + local link_image = kc[i].file_url + return link_image +end + +local function run(msg, matches) + local tag = matches[1] + local tag = string.gsub(tag, " ", '_' ) + local receiver = get_receiver(msg) + local url = get_kc(tag) + send_photo_from_url(receiver, url, send_title, {receiver, title}) + return "Source: "..url +end + +return { + description = "Sendet ein Bild von Konachan.net [SFW]", + usage = {"/konachan [Tags]","/kc"}, + patterns = {"^/konachan (.*)$","^/kc (.*)$"}, + run = run +} + +end \ No newline at end of file diff --git a/plugins/konachan_nsfw.lua b/plugins/konachan_nsfw.lua new file mode 100644 index 0000000..0c718ad --- /dev/null +++ b/plugins/konachan_nsfw.lua @@ -0,0 +1,32 @@ +do + +local function get_kc2(tag) + local url = 'http://konachan.com/post.json?tags='..tag..'' + local b,c = http.request(url) + if c ~= 200 then return nil end + local kc = json:decode(b) + -- truly randomize + math.randomseed(os.time()) + -- random max json table size + local i = math.random(#kc) + local link_image = kc[i].file_url + return link_image +end + +local function run(msg, matches) + local tag = matches[1] + local tag = string.gsub(tag, " ", '_' ) + local receiver = get_receiver(msg) + local url = get_kc2(tag) + send_photo_from_url(receiver, url, send_title, {receiver, title}) + return "Source: "..url +end + +return { + description = "Sendet Bild von Konachan.com [NSFW]", + usage = {"/konansfw [Tags]","/kcn [Tags]"}, + patterns = {"^/konansfw (.*)$","^/kcn (.*)$"}, + run = run +} + +end \ No newline at end of file diff --git a/plugins/location_manager.lua b/plugins/location_manager.lua new file mode 100644 index 0000000..0831b16 --- /dev/null +++ b/plugins/location_manager.lua @@ -0,0 +1,63 @@ +-- This file is part of the Telegram Bot "Brawlbot" (telegram.me/Brawlbot) by Andreas Bielawski (telegram.me/Brawl) +-- Released unter the MPLv2 + +do + +local function set_location(user_id, location) + local hash = 'user:'..user_id + local set_location = get_location(user_id) + if set_location == location then + return 'Dieser Ort wurde bereits gesetzt' + else + print('Setting location in redis hash '..hash..' to location') + redis:hset(hash, 'location', location) + return 'Dein Wohnort wurde auf "'..location..'" festgelegt.' + end +end + +local function del_location(user_id) + local hash = 'user:'..user_id + local set_location = get_location(user_id) + if not set_location then + return 'Du hast keinen Ort gesetzt' + else + print('Setting location in redis hash '..hash..' to false') + -- We set the location to false, because deleting the value blocks redis for a few milliseconds + redis:hset(hash, 'location', false) + return 'Dein Wohnort "'..set_location..'" wurde gelscht!' + end +end + +local function run(msg, matches) + local user_id = msg.from.id + + if matches[1] == 'set' then + return set_location(user_id, matches[2]) + elseif matches[1] == 'del' then + return del_location(user_id) + else + local set_location = get_location(user_id) + if not set_location then + return 'Du hast keinen Ort gesetzt' + else + return 'Gesetzter Wohnort: '..set_location + end + end +end + +return { + description = "Orte-Manager", + usage = { + "/location: Gibt deinen gesetzten Wohnort aus", + "/location set (Ort): Setzt deinen Wohnort auf diesen Ort", + "/location del: Lscht deinen angegebenen Wohnort" + }, + patterns = { + "^/location (set) (.*)$", + "^/location (del)$", + "^/location$" + }, + run = run +} + +end \ No newline at end of file diff --git a/plugins/love_calculator.lua b/plugins/love_calculator.lua new file mode 100644 index 0000000..c1674cd --- /dev/null +++ b/plugins/love_calculator.lua @@ -0,0 +1,37 @@ +-- This is a proprietary plugin, property of Andreas Bielawski, (c) 2015 +-- DO NOT USE WITHOUT PERMISSION + +do + +local BASE_URL = 'https://love-calculator.p.mashape.com' + +local function love_result(first_name, second_name) + local apikey = cred_data.x_mashape_key + local url = BASE_URL..'/getPercentage?mashape-key='..apikey..'&fname='..first_name..'&sname='..second_name + print(url) + local res,code = https.request(url) + if code ~= 200 then return "HTTP-FEHLER" end + local data = json:decode(res) + local first_name = data.fname + local second_name = data.sname + local percentage = data.percentage + local result = data.result + return first_name..' und '..second_name..' lieben sich zu '..percentage..'% ❤️\n'..result +end + +local function run(msg, matches) + local first_name = url_encode(matches[1]) + local second_name = url_encode(matches[2]) + return love_result(first_name, second_name) +end + +return { + description = "Liebestest ❤️ (kommt sogar ohne Jamba-Abo!)", + usage = "/love [Erster Name]+[Zweiter Name]: Führt einen Liebestest durch ❤️", + patterns = { + "^/love (.+)+(.+)$" + }, + run = run +} + +end \ No newline at end of file diff --git a/plugins/manager.lua b/plugins/manager.lua index f8079a9..e400b7a 100644 --- a/plugins/manager.lua +++ b/plugins/manager.lua @@ -30,6 +30,34 @@ local function is_banned(user_id, chat_id) return banned or false end +local function makesudo(user_id, msg, delete) + local set = 'telegram:sudo_users' + local is_sudo = redis:sismember(set, user_id) + if delete then + if not is_sudo then + return user_id..' ist kein Superuser.' + else + if string.match(user_id, msg.from.id) then + return 'Das Löschen deiner User-ID aus den Superusern wird feige verweigert.' + else + print('deleting user id '..user_id..' from redis set '..set) + redis:srem(set, user_id) + sudo_users = load_sudo_users() + return user_id..' ist jetzt kein Superuser mehr.' + end + end + else + if not is_sudo then + print('saving user id '..user_id..' to redis set '..set) + redis:sadd(set, user_id) + sudo_users = load_sudo_users() + return user_id..' ist jetzt ein Superuser.' + else + return user_id..' ist bereits ein Superuser.' + end + end +end + local function pre_process(msg) -- SERVICE MESSAGE @@ -86,6 +114,10 @@ local function pre_process(msg) else --print ('Chat '..msg.to.id..' whitelisted :)') end + else + local user_name = get_name(msg) + local receiver = get_receiver(msg) + send_msg(receiver, "Hey "..user_name..", dies ist der Bot von @Akamaru und kann nur nach Freischaltung durch ihn benutzt werden." , ok_cb, false) end else --print('User '..msg.from.id..' allowed :)') @@ -127,6 +159,16 @@ local function run(msg, matches) return 'Das hier ist keine Chat-Gruppe' end end + + if matches[1] == 'makesudo' then + local user_id = matches[3] + if matches[2] == 'user' then + return makesudo(user_id) + end + if matches[2] == 'delete' then + return makesudo(user_id, msg, true) + end + end if matches[1] == 'kick' then if msg.to.type == 'chat' then @@ -183,16 +225,18 @@ local function run(msg, matches) end return { - description = "Plugin to manage bans, kicks and white/black lists.", + description = "Manager-Plugin für Whitelist, Kicks und Banns (nur Superuser)", usage = { - "/whitelist /: Enable or disable whitelist mode", - "/whitelist user : Allow user to use the bot when whitelist mode is enabled", - "/whitelist chat: Allow everybody on current chat to use the bot when whitelist mode is enabled", - "/whitelist delete user : Remove user from whitelist", - "/whitelist delete chat: Remove chat from whitelist", - "/ban user : Kick user from chat and kicks it if joins chat again", - "/ban delete : Unban user", - "/kick Kick user from chat group" + "/whitelist /: Aktiviert/deaktiviert Whitelist", + "/whitelist user : Whiteliste User", + "/whitelist chat: Whiteliste ganze Gruppe", + "/whitelist delete user : Lösche User von der Whitelist", + "/whitelist delete chat: Lösche ganze Gruppe von der Whitelist", + "/ban user : Kicke User vom Chat und kicke ihn, wenn er erneut beitritt", + "/ban delete : Entbanne User", + "/kick : Kicke User vom Chat", + "/makesudo user : Macht User zum Superuser", + "/makesudo delete : Macht User zum Superuser" }, patterns = { "^/(whitelist) (enable)$", @@ -205,6 +249,8 @@ return { "^/(ban) (delete) (%d+)$", "^/(kick) (%d+)$", --"^//tgservice (.+)$", + "^/(makesudo) (user) (%d+)$", + "^/(makesudo) (delete) (%d+)$" }, run = run, pre_process = pre_process, diff --git a/plugins/media_download.lua b/plugins/media_download.lua index 1425480..76e7485 100644 --- a/plugins/media_download.lua +++ b/plugins/media_download.lua @@ -36,5 +36,6 @@ return { usage = {'Irgendeine Datei'}, run = run, patterns = {'%[(document)%]','%[(photo)%]','%[(video)%]','%[(audio)%]'}, - pre_process = pre_process + pre_process = pre_process, + notyping = true } diff --git a/plugins/miiverse.lua b/plugins/miiverse.lua new file mode 100644 index 0000000..4b52fa8 --- /dev/null +++ b/plugins/miiverse.lua @@ -0,0 +1,89 @@ +-- This is a proprietary plugin, property of Andreas Bielawski, (c) 2015 +-- DO NOT USE WITHOUT PERMISSION + +do + +-- TODO: Language selector (for e.g. this post: https://miiverse.nintendo.net/posts/AYMHAAACAAADVHkSrNJ-9Q) +-- + +local function get_miiverse_data(res, post) + username = string.match(res, "

(.-)") + userid = string.match(res, "(.-)") + timestamp = string.match(res, "(.-)") + if string.starts(timestamp, 'Vor') then + timestamp = string.gsub(timestamp, "Vor","") + timestamp = "vor"..timestamp + else + timestamp = "am "..timestamp + end + community = string.match(res, "

(.-)
") + --community = string.gsub(community, "™","") + yeahs = string.match(res, "(.-)") + if yeahs == "1" then yeahs = "1 Yeah" else yeahs = yeahs.." Yeahs" end + replys = string.match(res, "(.-)") + if replys == "1" then replys = "1 Kommentar" else replys = replys.." Kommentaren" end + youtube_link = string.match(res, "