Merge Upstream
This commit is contained in:
		| @@ -429,7 +429,7 @@ function create_plugin_set() | ||||
|     'echo', | ||||
|     'banhammer', | ||||
| 	'plugins', | ||||
| 	'settings', | ||||
|     'respond', | ||||
|     'help' | ||||
|   } | ||||
|   print ('Aktiviere Plugins und speicher in telegram:enabled_plugins') | ||||
|   | ||||
| @@ -1,137 +0,0 @@ | ||||
| local bitly_create = {} | ||||
|  | ||||
| function bitly_create:init(config) | ||||
| 	if not cred_data.bitly_client_id then | ||||
| 		print('Fehlender Key: bitly_client_id.') | ||||
| 		print('bitly_create.lua wird nicht aktiviert.') | ||||
| 		return | ||||
| 	elseif not cred_data.bitly_client_secret then | ||||
| 		print('Fehlender Key: bitly_client_secret.') | ||||
| 		print('bitly_create.lua wird nicht aktiviert.') | ||||
| 		return | ||||
| 	elseif not cred_data.bitly_redirect_uri then | ||||
| 		print('Fehlender Key: bitly_redirect_uri.') | ||||
| 		print('bitly_create.lua wird nicht aktiviert.') | ||||
| 		return | ||||
| 	end | ||||
|  | ||||
|     bitly_create.triggers = { | ||||
|     "^/[Ss][Hh][Oo][Rr][Tt](auth)(.+)$", | ||||
|     "^/[Ss][Hh][Oo][Rr][Tt] (auth)$", | ||||
| 	"^/[Ss][Hh][Oo][Rr][Tt] (unauth)$", | ||||
| 	"^/[Ss][Hh][Oo][Rr][Tt] (me)$", | ||||
|   	"^/[Ss][Hh][Oo][Rr][Tt] (j.mp) (https?://[%w-_%.%?%.:/%+=&]+)$", | ||||
| 	"^/[Ss][Hh][Oo][Rr][Tt] (bit.ly) (https?://[%w-_%.%?%.:/%+=&]+)$", | ||||
| 	"^/[Ss][Hh][Oo][Rr][Tt] (bitly.com) (https?://[%w-_%.%?%.:/%+=&]+)$", | ||||
| 	"^/[Ss][Hh][Oo][Rr][Tt] (https?://[%w-_%.%?%.:/%+=&]+)$" | ||||
| 	} | ||||
| 	bitly_create.doc = [[* | ||||
| ]]..config.cmd_pat..[[short* _<Link>_: Kürzt einen Link mit der Standard Bitly-Adresse | ||||
| *]]..config.cmd_pat..[[short* _<j.mp|bit.ly|bitly.com>_ _[Link]_: Kürzt einen Link mit der ausgewählten Kurz-URL | ||||
| *]]..config.cmd_pat..[[short* _auth_: Loggt deinen Account ein und nutzt ihn für deine Links (empfohlen!) | ||||
| *]]..config.cmd_pat..[[short* _me_: Gibt den eingeloggten Account aus | ||||
| *]]..config.cmd_pat..[[short* _unauth_: Loggt deinen Account aus | ||||
| ]] | ||||
| end | ||||
|  | ||||
| bitly_create.command = 'short <URL>' | ||||
|  | ||||
| local BASE_URL = 'https://api-ssl.bitly.com' | ||||
|  | ||||
| local client_id = cred_data.bitly_client_id | ||||
| local client_secret = cred_data.bitly_client_secret | ||||
| local redirect_uri = cred_data.bitly_redirect_uri | ||||
|  | ||||
| function bitly_create:get_bitly_access_token(hash, code) | ||||
|   local req = post_petition(BASE_URL..'/oauth/access_token', 'client_id='..client_id..'&client_secret='..client_secret..'&code='..code..'&redirect_uri='..redirect_uri) | ||||
|   if not req.access_token then return '*Fehler beim Einloggen!*' end | ||||
|    | ||||
|   local access_token = req.access_token | ||||
|   local login_name = req.login | ||||
|   redis:hset(hash, 'bitly', access_token) | ||||
|   return 'Erfolgreich als `'..login_name..'` eingeloggt!' | ||||
| end | ||||
|  | ||||
| function bitly_create:get_bitly_user_info(bitly_access_token) | ||||
|   local url = BASE_URL..'/v3/user/info?access_token='..bitly_access_token..'&format=json' | ||||
|   local res,code  = https.request(url) | ||||
|   if code == 401 then return 'Login fehlgeschlagen!' end | ||||
|   if code ~= 200 then return 'HTTP-Fehler!' end | ||||
|    | ||||
|   local data = json.decode(res).data | ||||
|    | ||||
|   if data.full_name then | ||||
|     name = '*'..data.full_name..'* (`'..data.login..'`)' | ||||
|   else | ||||
|     name = '`'..data.login..'`' | ||||
|   end | ||||
|    | ||||
|   local text = 'Eingeloggt als '..name | ||||
|    | ||||
|   return text | ||||
| end | ||||
|  | ||||
| function bitly_create:create_bitlink (long_url, domain, bitly_access_atoken) | ||||
|   local url = BASE_URL..'/v3/shorten?access_token='..bitly_access_token..'&domain='..domain..'&longUrl='..long_url..'&format=txt' | ||||
|   local text,code  = https.request(url) | ||||
|   if code ~= 200 then return 'FEHLER: '..text end | ||||
|   return text | ||||
| end | ||||
|  | ||||
| function bitly_create:action(msg, config, matches) | ||||
|   local hash = 'user:'..msg.from.id | ||||
|   bitly_access_token = redis:hget(hash, 'bitly') | ||||
|    | ||||
|   if matches[1] == 'auth' and matches[2] then | ||||
|     utilities.send_reply(msg, bitly_create:get_bitly_access_token(hash, matches[2]), true) | ||||
| 	local message_id = redis:hget(hash, 'bitly_login_msg') | ||||
| 	utilities.edit_message(msg.chat.id, message_id, '*Anmeldung abgeschlossen!*', true, true) | ||||
| 	redis:hdel(hash, 'bitly_login_msg') | ||||
|     return | ||||
|   end | ||||
|    | ||||
|   if matches[1] == 'auth' then | ||||
|     local result = utilities.send_reply(msg, '*Bitte logge dich ein und folge den Anweisungen.*', true, '{"inline_keyboard":[[{"text":"Bei Bitly anmelden","url":"https://bitly.com/oauth/authorize?client_id='..client_id..'&redirect_uri='..redirect_uri..'&state='..self.info.username..'"}]]}') | ||||
|     redis:hset(hash, 'bitly_login_msg', result.result.message_id) | ||||
| 	return | ||||
|   end | ||||
|    | ||||
|   if matches[1] == 'unauth' and bitly_access_token then | ||||
|     redis:hdel(hash, 'bitly') | ||||
| 	utilities.send_reply(msg, '*Erfolgreich ausgeloggt!* Du kannst den Zugriff [in deinen Kontoeinstellungen](https://bitly.com/a/settings/connected) endgültig entziehen.', true) | ||||
| 	return | ||||
|   elseif matches[1] == 'unauth' and not bitly_access_token then | ||||
|     utilities.send_reply(msg, 'Wie willst du dich ausloggen, wenn du gar nicht eingeloggt bist?', true) | ||||
|     return | ||||
|   end | ||||
|    | ||||
|   if matches[1] == 'me' and bitly_access_token then | ||||
|     local text = bitly_create:get_bitly_user_info(bitly_access_token) | ||||
| 	if text then | ||||
| 	  utilities.send_reply(msg, text, true) | ||||
| 	  return | ||||
| 	else | ||||
| 	  return | ||||
| 	end | ||||
|   elseif matches[1] == 'me' and not bitly_access_token then | ||||
|     utilities.send_reply(msg, 'Du bist nicht eingeloggt! Logge dich ein mit\n/short auth', true) | ||||
|     return | ||||
|   end | ||||
|  | ||||
|   if not bitly_access_token then | ||||
|     print('Not signed in, will use global bitly access_token') | ||||
|     bitly_access_token = cred_data.bitly_access_token | ||||
|   end | ||||
|  | ||||
|   if matches[2] == nil then | ||||
|     long_url = URL.encode(matches[1]) | ||||
| 	domain = 'bit.ly' | ||||
|   else | ||||
|     long_url = URL.encode(matches[2]) | ||||
| 	domain = matches[1] | ||||
|   end | ||||
|   utilities.send_reply(msg, bitly_create:create_bitlink(long_url, domain, bitly_access_token)) | ||||
|   return | ||||
| end | ||||
|  | ||||
| return bitly_create | ||||
| @@ -1,34 +0,0 @@ | ||||
| local btc = {} | ||||
|  | ||||
| function btc:init(config) | ||||
| 	btc.triggers = { | ||||
| 	  "^/[Bb][Tt][Cc]$" | ||||
| 	} | ||||
| 	btc.doc = [[* | ||||
| ]]..config.cmd_pat..[[btc*: Zeigt aktuellen Bitcoin-Kurs an]] | ||||
| end | ||||
|  | ||||
| btc.command = 'btc' | ||||
|    | ||||
| -- See https://bitcoinaverage.com/api | ||||
| function btc:getBTCX() | ||||
|   local base_url = 'https://api.bitcoinaverage.com/ticker/global/' | ||||
|   -- Do request on bitcoinaverage, the final / is critical! | ||||
|   local res,code  = https.request(base_url.."EUR/") | ||||
|    | ||||
|   if code ~= 200 then return nil end | ||||
|   local data = json.decode(res) | ||||
|   local ask = string.gsub(data.ask, "%.", ",") | ||||
|   local bid = string.gsub(data.bid, "%.", ",") | ||||
|  | ||||
|   -- Easy, it's right there | ||||
|   text = 'BTC/EUR\n'..'*Kaufen:* '..ask..'\n'..'*Verkaufen:* '..bid | ||||
|   return text | ||||
| end | ||||
|  | ||||
|  | ||||
| function btc:action(msg, config, matches) | ||||
|   utilities.send_reply(msg, btc:getBTCX(cur), true) | ||||
| end | ||||
|  | ||||
| return btc | ||||
| @@ -1,28 +0,0 @@ | ||||
| local clypit = {} | ||||
|  | ||||
| clypit.triggers = { | ||||
|   "clyp.it/([A-Za-z0-9-_-]+)" | ||||
| } | ||||
|  | ||||
| function clypit:get_clypit_details(shortcode) | ||||
|   local BASE_URL = "http://api.clyp.it" | ||||
|   local url = BASE_URL..'/'..shortcode | ||||
|   local res,code  = http.request(url) | ||||
|   if code ~= 200 then return nil end | ||||
|   local data = json.decode(res) | ||||
|  | ||||
|   local title = data.Title | ||||
|   local duration = data.Duration | ||||
|  | ||||
|   local audio = download_to_file(data.Mp3Url) | ||||
|   return audio, title, duration | ||||
| end | ||||
|  | ||||
| function clypit:action(msg, config, matches) | ||||
|   utilities.send_typing(msg.chat.id, 'upload_audio') | ||||
|   local audio, title, duration = clypit:get_clypit_details(matches[1]) | ||||
|   if not audio then return utilities.send_reply(msg, config.errors.connection) end | ||||
|   utilities.send_audio(msg.chat.id, audio, nil, msg.message_id, duration, nil, title) | ||||
| end | ||||
|  | ||||
| return clypit | ||||
| @@ -1,34 +0,0 @@ | ||||
| local dhl = {} | ||||
|  | ||||
| function dhl:init(config) | ||||
| 	dhl.triggers = { | ||||
| 	'/[Dd][Hh][Ll] (%d+)$' | ||||
| 	} | ||||
| 	dhl.doc = [[* | ||||
| ]]..config.cmd_pat..[[dhl* _<Sendungsnummer>_: Aktueller Status der Sendung]] | ||||
| end | ||||
|  | ||||
|  | ||||
| local BASE_URL = 'https://mobil.dhl.de' | ||||
|  | ||||
| function dhl:sendungsstatus(id) | ||||
|   local url = BASE_URL..'/shipmentdetails.html?shipmentId='..id | ||||
|   local res,code = https.request(url) | ||||
|   if code ~= 200 then return "Fehler beim Abrufen von mobil.dhl.de" end | ||||
|   local status = string.match(res, "<div id%=\"detailShortStatus\">(.-)</div>") | ||||
|   local status = utilities.trim(status) | ||||
|   local zeit = string.match(res, "<div id%=\"detailStatusDateTime\">(.-)</div>") | ||||
|   local zeit = utilities.trim(zeit) | ||||
|   if not zeit or zeit == '<br />' then | ||||
|     return status | ||||
|   end | ||||
|   return '*'..status..'*\n_Stand: '..zeit..'_' | ||||
| end | ||||
|  | ||||
| function dhl:action(msg, config, matches) | ||||
|   local sendungs_id = matches[1] | ||||
|   if string.len(sendungs_id) < 8 then return end | ||||
|   utilities.send_reply(msg, dhl:sendungsstatus(sendungs_id), true) | ||||
| end | ||||
|  | ||||
| return dhl | ||||
| @@ -1,79 +0,0 @@ | ||||
| local isup = {} | ||||
|  | ||||
| function isup:init(config) | ||||
|   isup.triggers = { | ||||
|     "^/[Ii][Ss][Uu][Pp] (.*)$", | ||||
|     "^/[Pp][Ii][Nn][Gg] (.*)$" | ||||
|   } | ||||
| 	 | ||||
|   isup.doc = [[* | ||||
| ]]..config.cmd_pat..[[isup* _<URL>_: Prüft, ob die URL up ist]] | ||||
| end | ||||
|  | ||||
| function isup:is_up_socket(ip, port) | ||||
|   print('Verbinde zu ', ip, port) | ||||
|   local c = socket.try(socket.tcp()) | ||||
|   c:settimeout(3) | ||||
|   local conn = c:connect(ip, port) | ||||
|   if not conn then | ||||
|     return false | ||||
|   else | ||||
|     c:close() | ||||
|     return true | ||||
|   end | ||||
| end | ||||
|  | ||||
| function isup:is_up_http(url) | ||||
|   -- Parse URL from input, default to http | ||||
|   local parsed_url = URL.parse(url,  { scheme = 'http', authority = '' }) | ||||
|   -- Fix URLs without subdomain not parsed properly | ||||
|   if not parsed_url.host and parsed_url.path then | ||||
|     parsed_url.host = parsed_url.path | ||||
|     parsed_url.path = "" | ||||
|   end | ||||
|   -- Re-build URL | ||||
|   local url = URL.build(parsed_url) | ||||
|  | ||||
|   local protocols = { | ||||
|     ["https"] = https, | ||||
|     ["http"] = http | ||||
|   } | ||||
|   local options =  { | ||||
|     url = url, | ||||
|     redirect = false, | ||||
|     method = "GET" | ||||
|   } | ||||
|   local response = { protocols[parsed_url.scheme].request(options) } | ||||
|   local code = tonumber(response[2]) | ||||
|   if code == nil or code >= 400 then | ||||
|     return false | ||||
|   end | ||||
|   return true | ||||
| end | ||||
|  | ||||
| function isup:isup(url) | ||||
|   local pattern = '^(%d%d?%d?%.%d%d?%d?%.%d%d?%d?%.%d%d?%d?):?(%d?%d?%d?%d?%d?)$' | ||||
|   local ip,port = string.match(url, pattern) | ||||
|   local result = nil | ||||
|  | ||||
|   -- /isup 8.8.8.8:53 | ||||
|   if ip then | ||||
|     port = port or '80' | ||||
|     result = isup:is_up_socket(ip, port) | ||||
|   else | ||||
|     result = isup:is_up_http(url) | ||||
|   end | ||||
|   return result | ||||
| end | ||||
|  | ||||
| function isup:action(msg, config) | ||||
|   if isup:isup(matches[1]) then | ||||
|     utilities.send_reply(msg, matches[1]..' ist UP! ✅') | ||||
|     return | ||||
|   else | ||||
|     utilities.send_reply(msg, matches[1]..' ist DOWN! ❌') | ||||
|     return | ||||
|   end | ||||
| end | ||||
|  | ||||
| return isup | ||||
| @@ -39,12 +39,13 @@ function notify:pre_process(msg) | ||||
| 		  if redis:sismember('chat:'..chat_id..':users', id) then | ||||
| 		    -- ignore message, if user is mentioning him/herself | ||||
| 		    if id ~= tostring(msg.from.id) then | ||||
| 			  local send_date = run_command('date -d @'..msg.date..' +"%d.%m.%Y um %H:%M:%S Uhr"') | ||||
| 			  local send_date = run_command('date -d @'..msg.date..' +"<i>%d.%m.%Y</i> | 🕒 <i>%H:%M:%S Uhr</i>"') | ||||
| 			  local send_date = string.gsub(send_date, "\n", "") | ||||
| 			  local from = string.gsub(msg.from.name, "%_", " ") | ||||
| 			  local chat_name = string.gsub(msg.chat.title, "%_", " ") | ||||
| 			  local text = from..' am '..send_date..' in "'..chat_name..'":\n\n'..msg.text | ||||
| 			  utilities.send_message(id, text, true) | ||||
| 			  local text = '🔔 <b>'..utilities.html_escape(from)..'</b> hat dich erwähnt:' | ||||
|               local text = text..'\n👥 <b>'..utilities.html_escape(chat_name)..'</b> | 📅 '..send_date..'\n\n'..utilities.html_escape(msg.text) | ||||
| 			  utilities.send_message(id, text, true, false, 'HTML') | ||||
| 			end | ||||
| 		  end | ||||
| 	    end | ||||
|   | ||||
| @@ -1,35 +0,0 @@ | ||||
| local pagespeed_insights = {} | ||||
|  | ||||
| function pagespeed_insights:init(config) | ||||
|   if not cred_data.google_apikey then | ||||
| 	print('Fehlender Key: google_apikey.') | ||||
| 	print('pagespeed_insights.lua wird nicht aktiviert.') | ||||
| 	return | ||||
|   end | ||||
|  | ||||
|   pagespeed_insights.triggers = { | ||||
| 	"^/[Ss][Pp][Ee][Ee][Dd] (https?://[%w-_%.%?%.:/%+=&]+)" | ||||
|   } | ||||
| 	pagespeed_insights.doc = [[* | ||||
| ]]..config.cmd_pat..[[speed* _<Seiten-URL>_: Testet Geschwindigkeit der Seite mit PageSpeed Insights]] | ||||
| end | ||||
|  | ||||
| local BASE_URL = 'https://www.googleapis.com/pagespeedonline/v2' | ||||
|  | ||||
| function pagespeed_insights:get_pagespeed(test_url) | ||||
|   local apikey = cred_data.google_apikey | ||||
|   local url = BASE_URL..'/runPagespeed?url='..test_url..'&key='..apikey..'&fields=id,ruleGroups(SPEED(score))' | ||||
|   local res,code  = https.request(url) | ||||
|   if code ~= 200 then return "HTTP-FEHLER" end | ||||
|   local data = json.decode(res) | ||||
|   return data.id..' hat einen PageSpeed-Score von *'..data.ruleGroups.SPEED.score..' Punkten.*' | ||||
| end | ||||
|  | ||||
| function pagespeed_insights:action(msg, config, matches) | ||||
|   utilities.send_typing(msg.chat.id, 'typing') | ||||
|   local text = pagespeed_insights:get_pagespeed(matches[1]) | ||||
|   if not text then utilities.send_reply(msg, config.errors.connection) return end | ||||
|   utilities.send_reply(msg, text, true) | ||||
| end | ||||
|  | ||||
| return pagespeed_insights | ||||
| @@ -1,144 +0,0 @@ | ||||
| local pocket = {} | ||||
|  | ||||
| function pocket:init(config) | ||||
|   if not cred_data.pocket_consumer_key then | ||||
| 	print('Fehlender Key: pocket_consumer_key.') | ||||
| 	print('pocket.lua wird nicht aktiviert.') | ||||
| 	return | ||||
|   end | ||||
|  | ||||
|   pocket.triggers = { | ||||
|     "^/pocket(set)(.+)$", | ||||
| 	"^/pocket (add) (https?://.*)$", | ||||
| 	"^/pocket (archive) (%d+)$", | ||||
| 	"^/pocket (readd) (%d+)$", | ||||
| 	"^/pocket (unfavorite) (%d+)$", | ||||
| 	"^/pocket (favorite) (%d+)$", | ||||
| 	"^/pocket (delete) (%d+)$", | ||||
| 	"^/pocket (unauth)$", | ||||
|     "^/pocket$" | ||||
|   } | ||||
|  | ||||
|   pocket.doc =   [[* | ||||
| ]]..config.cmd_pat..[[pocket*: Postet Liste deiner Links | ||||
| *]]..config.cmd_pat..[[pocket* add _(url)_: Fügt diese URL deiner Liste hinzu | ||||
| *]]..config.cmd_pat..[[pocket* archive _[id]_: Archiviere diesen Eintrag | ||||
| *]]..config.cmd_pat..[[pocket* readd _[id]_: De-archiviere diesen Eintrag | ||||
| *]]..config.cmd_pat..[[pocket* favorite _[id]_: Favorisiere diesen Eintrag | ||||
| *]]..config.cmd_pat..[[pocket* unfavorite _[id]_: Entfavorisiere diesen Eintrag | ||||
| *]]..config.cmd_pat..[[pocket* delete _[id]_: Lösche diesen Eintrag | ||||
| *]]..config.cmd_pat..[[pocket* unauth: Löscht deinen Account aus dem Bot]] | ||||
| end | ||||
|  | ||||
| pocket.command = 'pocket <siehe `/hilfe pocket`>' | ||||
|  | ||||
| local BASE_URL = 'https://getpocket.com/v3' | ||||
| local consumer_key = cred_data.pocket_consumer_key | ||||
| local headers = { | ||||
|    ["Content-Type"] = "application/x-www-form-urlencoded; charset=UTF8", | ||||
|    ["X-Accept"] = "application/json" | ||||
| } | ||||
|  | ||||
| function pocket:set_pocket_access_token(hash, access_token) | ||||
|   if string.len(access_token) ~= 30 then return '*Inkorrekter Access-Token*' end | ||||
|   print('Setting pocket in redis hash '..hash..' to users access_token') | ||||
|   redis:hset(hash, 'pocket', access_token) | ||||
|   return '*Authentifizierung abgeschlossen!*\nDas Plugin kann jetzt verwendet werden.' | ||||
| end | ||||
|  | ||||
| function pocket:list_pocket_items(access_token) | ||||
|   local items = post_petition(BASE_URL..'/get', 'consumer_key='..consumer_key..'&access_token='..access_token..'&state=unread&sort=newest&detailType=simple', headers) | ||||
|    | ||||
|   if items.status == 2 then return 'Keine Elemente eingespeichert.' end | ||||
|   if items.status ~= 1 then return 'Ein Fehler beim Holen der Elemente ist aufgetreten.' end | ||||
|    | ||||
|   local text = '' | ||||
|   for element in pairs(items.list) do | ||||
|     title = items.list[element].given_title | ||||
| 	if not title or title == "" then title = items.list[element].resolved_title end | ||||
|     text = text..'#'..items.list[element].item_id..': '..title..'\n— '..items.list[element].resolved_url..'\n\n' | ||||
|   end | ||||
|    | ||||
|   return text | ||||
| end | ||||
|  | ||||
| function pocket:add_pocket_item(access_token, url) | ||||
|   local result = post_petition(BASE_URL..'/add', 'consumer_key='..consumer_key..'&access_token='..access_token..'&url='..url, headers) | ||||
|   if result.status ~= 1 then return 'Ein Fehler beim Hinzufügen der URL ist aufgetreten :(' end | ||||
|   local given_url = result.item.given_url | ||||
|   if result.item.title == "" or not result.item.title then | ||||
|     title = 'Seite' | ||||
|   else | ||||
|     title = '"'..result.item.title..'"' | ||||
|   end | ||||
|   local code = result.item.response_code | ||||
|    | ||||
|   local text = title..' ('..given_url..') hinzugefügt!' | ||||
|   if not code then return text end | ||||
|   if code ~= "200" and code ~= "0" then text = text..'\nAber die Seite liefert Fehler '..code..' zurück.' end | ||||
|   return text | ||||
| end | ||||
|  | ||||
| function pocket:modify_pocket_item(access_token, action, id) | ||||
|   local result = post_petition(BASE_URL..'/send', 'consumer_key='..consumer_key..'&access_token='..access_token..'&actions=[{"action":"'..action..'","item_id":'..id..'}]', headers) | ||||
|   if result.status ~= 1 then return 'Ein Fehler ist aufgetreten :(' end | ||||
|    | ||||
|   if action == 'readd' then | ||||
|     if result.action_results[1] == false then | ||||
| 	  return 'Dieser Eintrag existiert nicht!' | ||||
| 	end | ||||
|     local url = result.action_results[1].normal_url | ||||
| 	return url..' wieder de-archiviert' | ||||
|   end | ||||
|   if result.action_results[1] == true then | ||||
|     return 'Aktion ausgeführt.' | ||||
|   else | ||||
|     return 'Ein Fehler ist aufgetreten.' | ||||
|   end | ||||
| end   | ||||
|  | ||||
| function pocket:action(msg, config, matches) | ||||
|   local hash = 'user:'..msg.from.id | ||||
|   local access_token = redis:hget(hash, 'pocket') | ||||
|    | ||||
|   if matches[1] == 'set' then | ||||
|     local access_token = matches[2] | ||||
| 	utilities.send_reply(msg, pocket:set_pocket_access_token(hash, access_token), true) | ||||
| 	local message_id = redis:hget(hash, 'pocket_login_msg') | ||||
| 	utilities.edit_message(msg.chat.id, message_id, '*Anmeldung abgeschlossen!*', true, true) | ||||
| 	redis:hdel(hash, 'pocket_login_msg') | ||||
|     return | ||||
|   end | ||||
|    | ||||
|   if not access_token then | ||||
|     local result = utilities.send_reply(msg, '*Bitte authentifiziere dich zuerst, indem du dich anmeldest.*', true, '{"inline_keyboard":[[{"text":"Bei Pocket anmelden","url":"https://brawlbot.tk/apis/callback/pocket/connect.php"}]]}') | ||||
|     redis:hset(hash, 'pocket_login_msg', result.result.message_id) | ||||
| 	return | ||||
|   end | ||||
|    | ||||
|   if matches[1] == 'unauth' then | ||||
|     redis:hdel(hash, 'pocket') | ||||
| 	utilities.send_reply(msg, 'Erfolgreich ausgeloggt! Du kannst den Zugriff [in deinen Einstellungen](https://getpocket.com/connected_applications) endgültig entziehen.', true) | ||||
| 	return | ||||
|   end | ||||
|    | ||||
|   if matches[1] == 'add' then | ||||
|     utilities.send_reply(msg, pocket:add_pocket_item(access_token, matches[2])) | ||||
|     return | ||||
|   end | ||||
|    | ||||
|   if matches[1] == 'archive' or matches[1] == 'delete' or matches[1] == 'readd' or matches[1] == 'favorite' or matches[1] == 'unfavorite' then | ||||
|     utilities.send_reply(msg, pocket:modify_pocket_item(access_token, matches[1], matches[2])) | ||||
| 	return | ||||
|   end | ||||
|    | ||||
|   if msg.chat.type == 'chat' or msg.chat.type == 'supergroup' then | ||||
|     utilities.send_reply(msg, 'Ausgeben deiner privaten Pocket-Liste in einem öffentlichen Chat wird feige verweigert. Bitte schreibe mich privat an!', true) | ||||
|     return | ||||
|   else | ||||
|     utilities.send_reply(msg, pocket:list_pocket_items(access_token)) | ||||
|     return | ||||
|   end | ||||
| end | ||||
|  | ||||
| return pocket | ||||
| @@ -1,29 +0,0 @@ | ||||
| local roll = {} | ||||
|  | ||||
| roll.command = 'roll' | ||||
|  | ||||
| function roll:init(config) | ||||
| 	roll.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('roll', true).table | ||||
| 	roll.doc = [[* | ||||
| ]]..config.cmd_pat..[[roll*: Werfe einen Würfel]] | ||||
| end | ||||
|  | ||||
| local canroll = { | ||||
|     "1", | ||||
|     "2", | ||||
|     "3", | ||||
|     "4", | ||||
|     "5", | ||||
|     "6" | ||||
| } | ||||
|  | ||||
| function roll:roll_dice() | ||||
|     local randomroll = math.random(6) | ||||
|     return canroll[randomroll] | ||||
| end | ||||
|  | ||||
| function roll:action(msg) | ||||
|   utilities.send_reply(msg, 'Du hast eine *'..roll:roll_dice()..'* gewürfelt.', true) | ||||
| end | ||||
|  | ||||
| return roll | ||||
| @@ -1,54 +0,0 @@ | ||||
| local wiimmfi = {} | ||||
|  | ||||
| function wiimmfi:init(config) | ||||
|     wiimmfi.triggers = { | ||||
|       "^/(mkw)$", | ||||
|       "^/wiimmfi$", | ||||
|       "^/wfc$" | ||||
| 	} | ||||
| 	wiimmfi.doc = [[* | ||||
| ]]..config.cmd_pat..[[wfc*: Zeigt alle Wiimmfi-Spieler an | ||||
| *]]..config.cmd_pat..[[mkw*: Zeigt alle Mario-Kart-Wii-Spieler an]] | ||||
| end | ||||
|  | ||||
| wiimmfi.command = 'wfc, /mkw' | ||||
|  | ||||
| function wiimmfi:getplayer(game) | ||||
|   local url = 'http://wiimmfi.de/game' | ||||
|   local res,code = http.request(url) | ||||
|   if code ~= 200 then return "Fehler beim Abrufen von wiimmfi.de" end | ||||
|   if game == 'mkw' then | ||||
|     local players = string.match(res, "<td align%=center><a href%=\"/game/mariokartwii\".->(.-)</a>") | ||||
|     if players == nil then players = 0 end | ||||
|     text = 'Es spielen gerade '..players..' Spieler Mario Kart Wii' | ||||
|   else | ||||
|     local players = string.match(res, "</tr><tr.->(.-)<th colspan%=3") | ||||
|     local players = string.gsub(players, "</a></td><td>.-<a href=\".-\">", ": ") | ||||
|     local players = string.gsub(players, "<td.->", "") | ||||
|     local players = string.gsub(players, "Wii</td>", "") | ||||
|     local players = string.gsub(players, "WiiWare</td>", "") | ||||
|     local players = string.gsub(players, "NDS</td>", "") | ||||
|     local players = string.gsub(players, "<th.->", "") | ||||
|     local players = string.gsub(players, "<tr.->", "") | ||||
|     local players = string.gsub(players, "</tr>", "") | ||||
|     local players = string.gsub(players, "</th>", "") | ||||
|     local players = string.gsub(players, "<a.->", "") | ||||
|     local players = string.gsub(players, "</a>", "") | ||||
|     local players = string.gsub(players, "</td>", "") | ||||
|     if players == nil then players = 'Momentan spielt keiner auf Wiimmfi :(' end | ||||
|     text = players | ||||
|   end | ||||
|   return text | ||||
| end | ||||
|  | ||||
| function wiimmfi:action(msg, config, matches) | ||||
|   if matches[1] == "mkw" then | ||||
|     utilities.send_reply(msg, wiimmfi:getplayer('mkw')) | ||||
|     return | ||||
|   else | ||||
|     utilities.send_reply(msg, wiimmfi:getplayer()) | ||||
|     return | ||||
|   end | ||||
| end | ||||
|  | ||||
| return wiimmfi | ||||
| @@ -27,14 +27,14 @@ function send_wikia_article(wikia, article) | ||||
|   local abstract = data.items[id].abstract | ||||
|   local article_url = data.basepath..data.items[id].url | ||||
|    | ||||
|   local text = '*'..title..'*:\n'..abstract..' [Weiterlesen]('..article_url..')' | ||||
|   local text = '<b>'..title..'</b>:\n'..abstract..' <a href="'..article_url..'">Weiterlesen</a>' | ||||
|   return text | ||||
| end | ||||
|  | ||||
| function wikia:action(msg, config, matches) | ||||
|   local wikia = matches[1] | ||||
|   local article = matches[2] | ||||
|   utilities.send_reply(msg, send_wikia_article(wikia, article), true) | ||||
|   utilities.send_reply(msg, send_wikia_article(wikia, article), 'HTML') | ||||
| end | ||||
|  | ||||
| return wikia | ||||
| @@ -98,15 +98,15 @@ function send_youtube_data(data, msg, self, link, sendpic) | ||||
|   local upload_date = makeOurDate(data.snippet.publishedAt) | ||||
|   local viewCount = comma_value(data.statistics.viewCount) | ||||
|   if data.statistics.likeCount then | ||||
|     likeCount = ', '..comma_value(data.statistics.likeCount)..' Likes und ' | ||||
| 	dislikeCount = comma_value(data.statistics.dislikeCount)..' Dislikes' | ||||
|     likeCount = ' | 👍 <i>'..comma_value(data.statistics.likeCount)..'</i> |' | ||||
| 	dislikeCount = ' 👎 <i>'..comma_value(data.statistics.dislikeCount)..'</i>' | ||||
|   else | ||||
|     likeCount = '' | ||||
| 	dislikeCount = '' | ||||
|   end | ||||
|  | ||||
|   if data.statistics.commentCount then | ||||
|     commentCount = ', '..comma_value(data.statistics.commentCount)..' Kommentare' | ||||
|     commentCount = ' | 🗣 <i>'..comma_value(data.statistics.commentCount)..'</i>' | ||||
|   else | ||||
|     commentCount = '' | ||||
|   end | ||||
| @@ -120,7 +120,7 @@ function send_youtube_data(data, msg, self, link, sendpic) | ||||
|     blocked = false | ||||
|   end | ||||
|    | ||||
|   text = '<b>'..title..'</b>\n<i>('..uploader..' am '..upload_date..', '..viewCount..'x angesehen, Länge: '..duration..likeCount..dislikeCount..commentCount..')</i>\n' | ||||
|   text = '<b>'..title..'</b>\n🎥 <b>'..uploader..'</b>, 📅 <i>'..upload_date..'</i>\n👁 <i>'..viewCount..'</i> | 🕒 <i>'..duration..'</i>'..likeCount..dislikeCount..commentCount..'\n' | ||||
|   if link then | ||||
|     text = link..'\n'..text | ||||
|   end | ||||
| @@ -132,7 +132,7 @@ function send_youtube_data(data, msg, self, link, sendpic) | ||||
|   if sendpic then | ||||
|     local image_url = get_yt_thumbnail(data) | ||||
| 	-- need to change text, because Telegram captions can only be 200 characters long and don't support Markdown | ||||
| 	local text = link..'\n'..title..'\n('..uploader..' am '..upload_date..', '..viewCount..'x angesehen, Länge: '..duration..')' | ||||
|     local text = link..'\n'..title..'\n🎥 '..uploader..', 📅 '..upload_date..'\n👁 '..viewCount..' | 🕒 '..duration..likeCount..dislikeCount..commentCount..'\n' | ||||
| 	if blocked then | ||||
|       text = text..'\nACHTUNG, In Deutschland gesperrt!' | ||||
|     end | ||||
|   | ||||
		Reference in New Issue
	
	Block a user