Weitere Anpassungen
Patterns angepasst Ungenutzte Plugins entfernt Kleine Änderungen & Fixes Stabilitätsverbesserungen
This commit is contained in:
		| @@ -311,7 +311,6 @@ function create_plugin_set() | ||||
|     'channels', | ||||
| 	'plugins', | ||||
|     'help', | ||||
|     'greetings' | ||||
|   } | ||||
|   print ('Aktiviere Plugins und speicher in telegram:enabled_plugins') | ||||
|   for _,plugin in pairs(enabled_plugins) do | ||||
|   | ||||
| @@ -9,9 +9,12 @@ local bindings = require('miku.bindings') | ||||
| ninegag.command = '9gag' | ||||
|  | ||||
| function ninegag:init(config) | ||||
| 	ninegag.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('9gag', true):t('9fag', true).table | ||||
| 	ninegag.triggers = { | ||||
| 	  "^/9[Gg][Aa][Gg]$", | ||||
|       "^/9[Ff][Aa][Gg]$" | ||||
| 	} | ||||
| 	ninegag.inline_triggers = { | ||||
| 	  "^9gag" | ||||
| 	  "^9[Gg][Aa][Gg]" | ||||
| 	} | ||||
| 	ninegag.doc = [[* | ||||
| ]]..config.cmd_pat..[[9gag*: Gibt ein zufälliges Bild von den momentan populärsten 9GAG-Posts aus]] | ||||
|   | ||||
| @@ -7,8 +7,8 @@ about.command = 'about' | ||||
| about.doc = '`Sendet Informationen über den Bot.`' | ||||
|  | ||||
| about.triggers = { | ||||
| 	'/about', | ||||
| 	'/start' | ||||
| 	'/[Aa][Bb][Oo][Uu][Tt]', | ||||
| 	'/[Ss][Tt][Aa][Rr][Tt]' | ||||
| } | ||||
|  | ||||
| function about:action(msg, config) | ||||
|   | ||||
| @@ -8,8 +8,8 @@ local redis = (loadfile "./miku/redis.lua")() | ||||
|  | ||||
| function afk:init(config) | ||||
| 	afk.triggers = { | ||||
| 	  "^/([A|a][F|f][K|k])$", | ||||
|       "^/([A|a][F|f][K|k]) (.*)$" | ||||
| 	  "^/([Aa][Ff][Kk])$", | ||||
|       "^/([Aa][Ff][Kk]) (.*)$" | ||||
| 	} | ||||
| 	afk.doc = [[* | ||||
| ]]..config.cmd_pat..[[afk* _[Text]_: Setzt Status auf AFK mit optionalem Text]] | ||||
| @@ -41,7 +41,7 @@ function afk:switch_afk(user_name, user_id, chat_id, timestamp, text) | ||||
|   if afk:is_offline(hash) then | ||||
|     local afk_text = afk:get_afk_text(hash) | ||||
|     if afk_text then | ||||
|       return 'Du bist bereits AFK ('..afk_text..')!' | ||||
|       return 'Du bist bereits AFK! ('..afk_text..')' | ||||
| 	else | ||||
| 	  return 'Du bist bereits AFK!' | ||||
| 	end | ||||
| @@ -55,9 +55,9 @@ function afk:switch_afk(user_name, user_id, chat_id, timestamp, text) | ||||
|   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..')' | ||||
|     return user_name..' ist AFK! ('..text..')' | ||||
|   else | ||||
|     return user_name..' ist AFK' | ||||
|     return user_name..' ist AFK!' | ||||
|   end | ||||
| end | ||||
|  | ||||
| @@ -97,9 +97,9 @@ function afk:pre_process(msg, self) | ||||
| 	  redis:hset(hash, 'afk_text', false) | ||||
| 	  local afk_text = afk_text:gsub("%*","") | ||||
| 	  local afk_text = afk_text:gsub("_","") | ||||
| 	  utilities.send_message(self, msg.chat.id, user_name..' ist wieder da (war: *'..afk_text..'* für '..duration..')!', true, nil, true) | ||||
| 	  utilities.send_message(self, msg.chat.id, user_name..' ist wieder da! (war: *'..afk_text..'* für '..duration..')', true, nil, true) | ||||
| 	else | ||||
| 	  utilities.send_message(self, msg.chat.id, user_name..' ist wieder da (war '..duration..' weg)!') | ||||
| 	  utilities.send_message(self, msg.chat.id, user_name..' ist wieder da! (war '..duration..' weg)') | ||||
| 	end | ||||
|   end | ||||
|    | ||||
| @@ -108,7 +108,7 @@ end | ||||
|  | ||||
| function afk:action(msg) | ||||
|   if msg.chat.type == "private" then | ||||
|     utilities.send_reply(self, msg, "Mir ist's egal, ob du AFK bist ._.") | ||||
|     utilities.send_reply(self, msg, "Mir ist's egal, ob du AFK bist.") | ||||
|     return | ||||
|   end | ||||
|    | ||||
|   | ||||
| @@ -7,7 +7,7 @@ local redis = (loadfile "./miku/redis.lua")() | ||||
|  | ||||
| app_store.triggers = { | ||||
| 	"itunes.apple.com/(.*)/app/(.*)/id(%d+)", | ||||
| 	"^/itunes (%d+)$", | ||||
| 	"^/[Ii][Tt][Uu][Nn][Ee][Ss] (%d+)$", | ||||
| 	"itunes.apple.com/app/id(%d+)" | ||||
| } | ||||
| 	 | ||||
|   | ||||
| @@ -17,7 +17,7 @@ function bImages:init(config) | ||||
|  | ||||
|   bImages.triggers = {"^/nil$"} | ||||
|   bImages.inline_triggers = { | ||||
| 	"^b (.*)" | ||||
| 	"^[Ii][Mm][Gg] (.*)" | ||||
|   } | ||||
| end | ||||
|  | ||||
|   | ||||
| @@ -25,14 +25,14 @@ function bitly_create:init(config) | ||||
| 	end | ||||
|  | ||||
|     bitly_create.triggers = { | ||||
|     "^/short(auth)(.+)$", | ||||
|     "^/short (auth)$", | ||||
| 	"^/short (unauth)$", | ||||
| 	"^/short (me)$", | ||||
|   	"^/short (j.mp) (https?://[%w-_%.%?%.:/%+=&]+)$", | ||||
| 	"^/short (bit.ly) (https?://[%w-_%.%?%.:/%+=&]+)$", | ||||
| 	"^/short (bitly.com) (https?://[%w-_%.%?%.:/%+=&]+)$", | ||||
| 	"^/short (https?://[%w-_%.%?%.:/%+=&]+)$" | ||||
|     "^/[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 | ||||
|   | ||||
| @@ -8,7 +8,7 @@ local bindings = require('miku.bindings') | ||||
|  | ||||
| function btc:init(config) | ||||
| 	btc.triggers = { | ||||
| 	  "^/btc$" | ||||
| 	  "^/[Bb][Tt][Cc]$" | ||||
| 	} | ||||
| 	btc.doc = [[* | ||||
| ]]..config.cmd_pat..[[btc*: Zeigt aktuellen Bitcoin-Kurs an]] | ||||
|   | ||||
| @@ -8,14 +8,14 @@ calc.command = 'calc <Ausdruck>' | ||||
|  | ||||
| function calc:init(config) | ||||
| 	calc.triggers = { | ||||
| 	"^/calc (.*)$" | ||||
| 	"^/[Cc][Aa][Ll][Cc] (.*)$" | ||||
| 	} | ||||
| 	calc.doc = [[* | ||||
| ]]..config.cmd_pat..[[calc* _[Ausdruck]_: Rechnet]] | ||||
| end | ||||
|  | ||||
| function calc:mathjs(exp) | ||||
|   local exp = string.gsub(exp, ",", "%.") | ||||
|   local exp = string.gsub(exp, ",", ".") | ||||
|   local url = 'http://api.mathjs.org/v1/' | ||||
|   url = url..'?expr='..URL.escape(exp) | ||||
|   local b,c = http.request(url) | ||||
|   | ||||
| @@ -3,7 +3,7 @@ local cats = {} | ||||
| local HTTP = require('socket.http') | ||||
| local utilities = require('miku.utilities') | ||||
|  | ||||
| cats.command = 'cat [gif]' | ||||
| cats.command = 'kitty [gif]' | ||||
|  | ||||
| function cats:init(config) | ||||
| 	if not cred_data.cat_apikey then | ||||
| @@ -12,13 +12,13 @@ function cats:init(config) | ||||
| 	end | ||||
|  | ||||
| 	cats.triggers = { | ||||
|       "^/cat$", | ||||
| 	  "^/cat (gif)$" | ||||
|       "^/[Kk][Ii][Tt][Tt][Yy]$", | ||||
| 	  "^/[Kk][Ii][Tt][Tt][Yy] (gif)$" | ||||
| 	} | ||||
| 	 | ||||
| 	cats.doc = [[* | ||||
| ]]..config.cmd_pat..[[cat*: Postet eine zufällige Katze | ||||
| *]]..config.cmd_pat..[[cat* _gif_: Postet eine zufällige, animierte Katze]] | ||||
| ]]..config.cmd_pat..[[kitty*: Postet eine zufällige Katze | ||||
| *]]..config.cmd_pat..[[kitty* _gif_: Postet eine zufällige, animierte Katze]] | ||||
| end | ||||
|  | ||||
|  | ||||
|   | ||||
| @@ -8,8 +8,8 @@ channels.command = 'channel <nur für Superuser>' | ||||
|  | ||||
| function channels:init(config) | ||||
| 	channels.triggers = { | ||||
| 	"^/channel? (enable)", | ||||
| 	"^/channel? (disable)" | ||||
| 	"^/[Cc][Hh][Aa][Nn][Nn][Ee][Ll] (enable)", | ||||
| 	"^/[Cc][Hh][Aa][Nn][Nn][Ee][Ll] (disable)" | ||||
| 	} | ||||
| 	channels.doc = [[* | ||||
| ]]..config.cmd_pat..[[channel* _<enable>_/_<disable>_: Aktiviert/deaktiviert den Bot im Chat]] | ||||
|   | ||||
| @@ -7,7 +7,7 @@ local json = require('dkjson') | ||||
|  | ||||
| function cleverbot:init(config) | ||||
| 	cleverbot.triggers = { | ||||
| 	"^/cbot (.*)$" | ||||
| 	"^/[Cc][Bb][Oo][Tt] (.*)$" | ||||
| 	} | ||||
| 	 | ||||
| 	cleverbot.doc = [[* | ||||
|   | ||||
| @@ -7,10 +7,10 @@ currency.command = 'cash [Menge] <von> <zu>' | ||||
|  | ||||
| function currency:init(config) | ||||
| 	currency.triggers = { | ||||
|       "^/cash ([A-Za-z]+)$", | ||||
|       "^/cash ([A-Za-z]+) ([A-Za-z]+)$", | ||||
| 	  "^/cash (%d+[%d%.,]*) ([A-Za-z]+) ([A-Za-z]+)$", | ||||
|   	"^(/eur)$" | ||||
|       "^/[Cc][Aa][Ss][Hh] ([A-Za-z]+)$", | ||||
|       "^/[Cc][Aa][Ss][Hh] ([A-Za-z]+) ([A-Za-z]+)$", | ||||
| 	  "^/[Cc][Aa][Ss][Hh] (%d+[%d%.,]*) ([A-Za-z]+) ([A-Za-z]+)$", | ||||
|   	"^(/[Ee][Uu][Rr])$" | ||||
| 	} | ||||
| 	currency.doc = [[* | ||||
| ]]..config.cmd_pat..[[cash* _[Menge]_ _<von>_ _<zu>_ | ||||
|   | ||||
| @@ -6,7 +6,7 @@ local utilities = require('miku.utilities') | ||||
|  | ||||
| function dhl:init(config) | ||||
| 	dhl.triggers = { | ||||
| 	"/dhl (%d+)$" | ||||
| 	"/[Dd][Hh][Ll] (%d+)$" | ||||
| 	} | ||||
| 	dhl.doc = [[* | ||||
| ]]..config.cmd_pat..[[dhl* _<Sendungsnummer>_: Aktueller Status der Sendung]] | ||||
|   | ||||
| @@ -5,9 +5,10 @@ local utilities = require('miku.utilities') | ||||
| echo.command = 'echo <Text>' | ||||
|  | ||||
| function echo:init(config) | ||||
| 	echo.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('echo', true).table | ||||
| 	echo.triggers = {"/[Ee][Cc][Hh][Oo] (.*)$"} | ||||
| 	echo.inline_triggers = { | ||||
| 	  "^e (.*)" | ||||
| 	  "^echo (.*)", | ||||
| 	  "^bold (.*)" | ||||
| 	} | ||||
| 	echo.doc = [[* | ||||
| ]]..config.cmd_pat..[[echo* _<Text>_: Gibt den Text aus]] | ||||
|   | ||||
| @@ -5,7 +5,7 @@ local utilities = require('miku.utilities') | ||||
|  | ||||
| function expand:init(config) | ||||
|   expand.triggers = { | ||||
|     "^/expand (https?://[%w-_%.%?%.:/%+=&]+)$" | ||||
|     "^/[Ee][Xx][Pp][Aa][Nn][Dd] (https?://[%w-_%.%?%.:/%+=&]+)$" | ||||
|   } | ||||
|   expand.inline_triggers = { | ||||
|     "^ex (https?://[%w-_%.%?%.:/%+=&]+)$" | ||||
|   | ||||
| @@ -1,36 +0,0 @@ | ||||
| local fefe = {} | ||||
|  | ||||
| local https = require('ssl.https') | ||||
| local json = require('dkjson') | ||||
| local utilities = require('miku.utilities') | ||||
|  | ||||
| fefe.triggers = { | ||||
|   "blog.fefe.de/%?ts=%w%w%w%w%w%w%w%w" | ||||
| } | ||||
|  | ||||
| function fefe:post(id) | ||||
|   local url = 'http://'..id | ||||
|   local results, code = https.request(url) | ||||
|   if code ~= 200 then return "HTTP-Fehler" end | ||||
|   if string.match(results, "No entries found.") then return "Eintrag nicht gefunden." end | ||||
|  | ||||
|   local line = string.sub( results, string.find(results, "<li><a href[^\n]+")) | ||||
|   local text = line:gsub("<div style=.+", "") | ||||
|   -- remove link at begin | ||||
|   local text = text:gsub("<li><a href=\"%?ts=%w%w%w%w%w%w%w%w\">%[l]</a>", "") | ||||
|   -- replace "<p>" with newline; "<b>" and "</b>" with "*" | ||||
|   local text = text:gsub("<p>", "\n\n"):gsub("<p u>", "\n\n") | ||||
|   local text = text:gsub("<b>", "*"):gsub("</b>", "*") | ||||
|   local text = text:gsub("<i>", "_"):gsub("</i>", "_") | ||||
|   -- format quotes and links markdown-like | ||||
|   local text = text:gsub("<a href=\"", "("):gsub("\">", ")["):gsub("</a>", "]") | ||||
|   local text = text:gsub("<blockquote>", "\n\n> "):gsub("</blockquote>", "\n\n") | ||||
|  | ||||
|   return text | ||||
| end | ||||
|  | ||||
| function fefe:action(msg, config, matches) | ||||
|   utilities.send_reply(self, msg, fefe:post(matches[1])) | ||||
| end | ||||
|  | ||||
| return fefe | ||||
| @@ -22,7 +22,10 @@ function gImages:init(config) | ||||
| 		return | ||||
| 	end | ||||
|  | ||||
| 	gImages.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('img', true):t('i', true).table | ||||
| 	gImages.triggers = { | ||||
| 	"^/[Ii][Mm][Gg] (.*)$", | ||||
| 	"^/[Ii] (.*)$" | ||||
| 	} | ||||
| 	gImages.doc = [[* | ||||
| ]]..config.cmd_pat..[[img* _<Suchbegriff>_ | ||||
| Sucht Bild mit Google und versendet es (SafeSearch aktiv) | ||||
| @@ -72,11 +75,11 @@ function gImages:callback(callback, msg, self, config, input) | ||||
|  | ||||
|     -- It's important to save the image with the right ending! | ||||
|     if mimetype == 'image/gif' then | ||||
|       file = download_to_file(img_url, 'img.gif') | ||||
|       file = download_to_file(img_url) | ||||
|     elseif mimetype == 'image/png' then | ||||
|      file = download_to_file(img_url, 'img.png') | ||||
|      file = download_to_file(img_url) | ||||
|     elseif mimetype == 'image/jpeg' then | ||||
|       file = download_to_file(img_url, 'img.jpg') | ||||
|       file = download_to_file(img_url) | ||||
|     else | ||||
|       file = nil | ||||
|     end | ||||
|   | ||||
							
								
								
									
										245
									
								
								miku/plugins/gImages_nsfw.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										245
									
								
								miku/plugins/gImages_nsfw.lua
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,245 @@ | ||||
|  -- You need a Google API key and a Google Custom Search Engine set up to use this, in config.google_api_key and config.google_cse_key, respectively. | ||||
|  -- You must also sign up for the CSE in the Google Developer Console, and enable image results. | ||||
|  | ||||
| local gImages_nsfw = {} | ||||
|  | ||||
| local HTTPS = require('ssl.https') | ||||
| HTTPS.timeout = 10 | ||||
| local URL = require('socket.url') | ||||
| local JSON = require('dkjson') | ||||
| local redis = (loadfile "./miku/redis.lua")() | ||||
| local utilities = require('miku.utilities') | ||||
| local bindings = require('miku.bindings') | ||||
|  | ||||
| function gImages_nsfw:init(config) | ||||
| 	if not cred_data.google_apikey then | ||||
| 		print('Missing config value: google_apikey.') | ||||
| 		print('gImages_nsfw.lua will not be enabled.') | ||||
| 		return | ||||
| 	elseif not cred_data.google_cse_id then | ||||
| 		print('Missing config value: google_cse_id.') | ||||
| 		print('gImages_nsfw.lua will not be enabled.') | ||||
| 		return | ||||
| 	end | ||||
|  | ||||
| 	gImages_nsfw.triggers = { | ||||
| 	"^/[Ii][Mm][Gg]2 (.*)$", | ||||
| 	"^/[Ii]2 (.*)$" | ||||
| 	} | ||||
| 	gImages_nsfw.doc = [[* | ||||
| ]]..config.cmd_pat..[[img2* _<Suchbegriff>_ | ||||
| Sucht Bild mit Google und versendet es | ||||
| Alias: *]]..config.cmd_pat..[[i2*]] | ||||
| end | ||||
|  | ||||
| gImages_nsfw.command = 'img2 <Suchbegriff>' | ||||
|  | ||||
| -- Yes, the callback is copied from below, but I can't think of another method :\ | ||||
| function gImages_nsfw:callback(callback, msg, self, config, input) | ||||
|   if not msg then return end | ||||
|   utilities.answer_callback_query(self, callback, 'Suche nochmal nach "'..URL.unescape(input)..'"') | ||||
|   utilities.send_typing(self, msg.chat.id, 'upload_photo') | ||||
|   local hash = 'telegram:cache:gImages_nsfw' | ||||
|   local results = redis:smembers(hash..':'..string.lower(URL.unescape(input))) | ||||
|    | ||||
|   if not results[1] then | ||||
|     print('doing web request') | ||||
|     results = gImages_nsfw:get_image(input) | ||||
| 	if results == 403 then | ||||
| 	  utilities.send_reply(self, msg, config.errors.quotaexceeded, true) | ||||
| 	  return | ||||
|     elseif not results then | ||||
|       utilities.send_reply(self, msg, config.errors.results, true) | ||||
| 	  return | ||||
|     end | ||||
|     gImages_nsfw:cache_result(results, input) | ||||
|   end | ||||
|  | ||||
|   -- Random image from table | ||||
|   local i = math.random(#results) | ||||
|    | ||||
|   -- Thanks to Amedeo for this! | ||||
|   local failed = true | ||||
|   local nofTries = 0 | ||||
|    | ||||
|   while failed and nofTries < #results do | ||||
|     if results[i].image then | ||||
|       img_url = results[i].link | ||||
|       mimetype = results[i].mime | ||||
|       context = results[i].image.contextLink | ||||
|     else -- from cache | ||||
|       img_url = results[i] | ||||
| 	  mimetype = redis:hget(hash..':'..img_url, 'mime') | ||||
| 	  context = redis:hget(hash..':'..img_url, 'contextLink') | ||||
|     end | ||||
|  | ||||
|     -- It's important to save the image with the right ending! | ||||
|     if mimetype == 'image/gif' then | ||||
|       file = download_to_file(img_url) | ||||
|     elseif mimetype == 'image/png' then | ||||
|      file = download_to_file(img_url) | ||||
|     elseif mimetype == 'image/jpeg' then | ||||
|       file = download_to_file(img_url) | ||||
|     else | ||||
|       file = nil | ||||
|     end | ||||
| 	 | ||||
| 	if not file then | ||||
| 	  nofTries = nofTries + 1 | ||||
| 	  i = i+1 | ||||
| 	  if i > #results then | ||||
| 	    i = 1 | ||||
| 	  end | ||||
| 	else | ||||
| 	  failed = false | ||||
| 	end | ||||
|  | ||||
|   end | ||||
|    | ||||
|   if failed then | ||||
|     utilities.send_reply(self, msg, 'Fehler beim Herunterladen eines Bildes.', true, '{"inline_keyboard":[[{"text":"Nochmal versuchen","callback_data":"@'..self.info.username..' gImages_nsfw:'..input..'"}]]}') | ||||
| 	return | ||||
|   end | ||||
|    | ||||
|   if mimetype == 'image/gif' then | ||||
|     result = utilities.send_document(self, msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..context..'"},{"text":"Bild aufrufen","url":"'..img_url..'"},{"text":"Nochmal suchen","callback_data":"@'..self.info.username..' gImages_nsfw:'..input..'"}]]}') | ||||
|   else | ||||
|     result = utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..context..'"},{"text":"Bild aufrufen","url":"'..img_url..'"},{"text":"Nochmal suchen","callback_data":"@'..self.info.username..' gImages_nsfw:'..input..'"}]]}') | ||||
|   end | ||||
|  | ||||
|   if not result then | ||||
|     utilities.send_reply(self, msg, config.errors.connection, true, '{"inline_keyboard":[[{"text":"Nochmal versuchen","callback_data":"@'..self.info.username..' gImages_nsfw:'..input..'"}]]}') | ||||
| 	return | ||||
|   end | ||||
| end | ||||
|  | ||||
| function gImages_nsfw:get_image(input) | ||||
|   local apikey = cred_data.google_apikey -- 100 requests is RIDICULOUS, Google! | ||||
|   local cseid = cred_data.google_cse_id | ||||
|   local BASE_URL = 'https://www.googleapis.com/customsearch/v1' | ||||
|   local url = BASE_URL..'/?searchType=image&alt=json&num=10&key='..apikey..'&cx='..cseid..'&q=' .. input .. '&fields=items(link,mime,image(contextLink))' | ||||
|   local jstr, res = HTTPS.request(url) | ||||
|   local jdat = JSON.decode(jstr).items | ||||
|    | ||||
|   if not jdat then | ||||
| 	return 'NORESULTS' | ||||
|   end | ||||
|  | ||||
|   if jdat.error then | ||||
|     if jdat.error.code == 403 then | ||||
| 	  return 403 | ||||
|     else | ||||
| 	  return false | ||||
| 	end | ||||
|   end | ||||
|    | ||||
|   return jdat | ||||
| end | ||||
|  | ||||
| function gImages_nsfw:cache_result(results, text) | ||||
|   local cache = {} | ||||
|   for v in pairs(results) do | ||||
|     table.insert(cache, results[v].link) | ||||
|   end | ||||
|   for n, link in pairs(cache) do | ||||
|    redis:hset('telegram:cache:gImages_nsfw:'..link, 'mime', results[n].mime) | ||||
|    redis:hset('telegram:cache:gImages_nsfw:'..link, 'contextLink', results[n].image.contextLink) | ||||
|    redis:expire('telegram:cache:gImages_nsfw:'..link, 1209600) | ||||
|   end | ||||
|   cache_data('gImages_nsfw', string.lower(text), cache, 1209600, 'set') | ||||
| end | ||||
|  | ||||
| function gImages_nsfw:action(msg, config, matches) | ||||
|   local input = utilities.input(msg.text) | ||||
|   if not input then | ||||
|     if msg.reply_to_message and msg.reply_to_message.text then | ||||
|       input = msg.reply_to_message.text | ||||
|     else | ||||
| 	  utilities.send_message(self, msg.chat.id, gImages_nsfw.doc, true, msg.message_id, true) | ||||
| 	  return | ||||
| 	end | ||||
|   end | ||||
|    | ||||
|   print ('Checking if search contains blacklisted word: '..input) | ||||
|   if is_blacklisted(input) then | ||||
|     utilities.send_reply(self, msg, 'Vergiss es! ._.') | ||||
| 	return | ||||
|   end | ||||
|  | ||||
|   utilities.send_typing(self, msg.chat.id, 'upload_photo') | ||||
|  | ||||
|   local hash = 'telegram:cache:gImages_nsfw' | ||||
|   local results = redis:smembers(hash..':'..string.lower(input)) | ||||
|    | ||||
|   if not results[1] then | ||||
|     print('doing web request') | ||||
|     results = gImages_nsfw:get_image(URL.escape(input)) | ||||
| 	if results == 403 then | ||||
| 	  utilities.send_reply(self, msg, config.errors.quotaexceeded, true) | ||||
| 	  return | ||||
|     elseif not results or results == 'NORESULTS' then | ||||
|       utilities.send_reply(self, msg, config.errors.results, true) | ||||
| 	  return | ||||
|     end | ||||
|     gImages_nsfw:cache_result(results, input) | ||||
|   end | ||||
|  | ||||
|   -- Random image from table | ||||
|   local i = math.random(#results) | ||||
|    | ||||
|   -- Thanks to Amedeo for this! | ||||
|   local failed = true | ||||
|   local nofTries = 0 | ||||
|    | ||||
|   while failed and nofTries < #results do | ||||
|     if results[i].image then | ||||
|       img_url = results[i].link | ||||
|       mimetype = results[i].mime | ||||
|       context = results[i].image.contextLink | ||||
|     else -- from cache | ||||
|       img_url = results[i] | ||||
| 	  mimetype = redis:hget(hash..':'..img_url, 'mime') | ||||
| 	  context = redis:hget(hash..':'..img_url, 'contextLink') | ||||
|     end | ||||
|  | ||||
|     -- It's important to save the image with the right ending! | ||||
|     if mimetype == 'image/gif' then | ||||
|       file = download_to_file(img_url, 'img.gif') | ||||
|     elseif mimetype == 'image/png' then | ||||
|      file = download_to_file(img_url, 'img.png') | ||||
|     elseif mimetype == 'image/jpeg' then | ||||
|       file = download_to_file(img_url, 'img.jpg') | ||||
|     else | ||||
|       file = nil | ||||
|     end | ||||
| 	 | ||||
| 	if not file then | ||||
| 	  nofTries = nofTries + 1 | ||||
| 	  i = i+1 | ||||
| 	  if i > #results then | ||||
| 	    i = 1 | ||||
| 	  end | ||||
| 	else | ||||
| 	  failed = false | ||||
| 	end | ||||
|  | ||||
|   end | ||||
|    | ||||
|   if failed then | ||||
|     utilities.send_reply(self, msg, 'Fehler beim Herunterladen eines Bildes.', true, '{"inline_keyboard":[[{"text":"Nochmal versuchen","callback_data":"@'..self.info.username..' gImages_nsfw:'..URL.escape(input)..'"}]]}') | ||||
| 	return | ||||
|   end | ||||
|    | ||||
|   if mimetype == 'image/gif' then | ||||
|     result = utilities.send_document(self, msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..context..'"},{"text":"Bild aufrufen","url":"'..img_url..'"},{"text":"Nochmal suchen","callback_data":"@'..self.info.username..' gImages_nsfw:'..URL.escape(input)..'"}]]}') | ||||
|   else | ||||
|     result = utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id, '{"inline_keyboard":[[{"text":"Seite aufrufen","url":"'..context..'"},{"text":"Bild aufrufen","url":"'..img_url..'"},{"text":"Nochmal suchen","callback_data":"@'..self.info.username..' gImages_nsfw:'..URL.escape(input)..'"}]]}') | ||||
|   end | ||||
|  | ||||
|   if not result then | ||||
|     utilities.send_reply(self, msg, config.errors.connection, true, '{"inline_keyboard":[[{"text":"Nochmal versuchen","callback_data":"@'..self.info.username..' gImages_nsfw:'..URL.escape(input)..'"}]]}') | ||||
| 	return | ||||
|   end | ||||
| end | ||||
|  | ||||
| return gImages_nsfw | ||||
| @@ -8,7 +8,7 @@ local utilities = require('miku.utilities') | ||||
| gSearch.command = 'google <Suchbegriff>' | ||||
|  | ||||
| function gSearch:init(config) | ||||
| 	gSearch.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('g', true):t('google', true):t('gnsfw', true).table | ||||
| 	gSearch.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('g', true):t('google', true).table | ||||
| 	gSearch.doc = [[* | ||||
| ]]..config.cmd_pat..[[google* _<Suchbegriff>_: Sendet Suchergebnisse von Google | ||||
| Alias: _]]..config.cmd_pat..[[g_]] | ||||
|   | ||||
| @@ -10,7 +10,7 @@ games.command = 'game <Spiel>' | ||||
|  | ||||
| function games:init(config) | ||||
|   games.triggers = { | ||||
| 	"^/game (.+)$" | ||||
| 	"^/[Gg][Aa][Mm][Ee] (.+)$" | ||||
| 	} | ||||
|   games.doc = [[* | ||||
| ]]..config.cmd_pat..[[game*_ <Spiel>_: Sendet Infos zum Spiel]] | ||||
| @@ -42,12 +42,6 @@ function games:send_game_photo(result, self, msg) | ||||
|   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 | ||||
| @@ -125,7 +119,7 @@ function games:send_game_data(game_id, self, msg) | ||||
|   local text = '*'..title..'* für *'..platform..'*'..date..desc..genre..players..video..publisher | ||||
|   utilities.send_reply(self, msg, text, true) | ||||
|    | ||||
|   if xml.find(result, 'fanrt') or xml.find(result, 'boxart') then | ||||
|   if xml.find(result, 'boxart') then | ||||
|     utilities.send_typing(self, msg.chat.id, 'upload_photo') | ||||
|     games:send_game_photo(result, self, msg) | ||||
|   end | ||||
|   | ||||
| @@ -10,7 +10,7 @@ function get:init(config) | ||||
| 	get.doc = [[* | ||||
| ]]..config.cmd_pat..[[get*: Gibt alle Variablen aus | ||||
| *]]..config.cmd_pat..[[get* _<Variable>_: Gibt _Variable_ aus | ||||
| Nutze `!set <Variable> <Wert>` zum Setzen von Variablen]] | ||||
| Nutze `/set <Variable> <Wert>` zum Setzen von Variablen]] | ||||
| end | ||||
|  | ||||
| function get:get_value(msg, var_name) | ||||
|   | ||||
| @@ -32,7 +32,7 @@ function media_download:download_to_file_permanently(url, file_name) | ||||
|  | ||||
|   -- TODO: Save, when folder doesn't exist | ||||
|   -- Create necessary folders in this folder! | ||||
|   local file_path = "/home/YOURPATH/tmp/"..file_name | ||||
|   local file_path = "tmp/"..file_name | ||||
|   file = io.open(file_path, "w+") | ||||
|   file:write(table.concat(respbody)) | ||||
|   file:close() | ||||
|   | ||||
| @@ -1,68 +0,0 @@ | ||||
| local golem = {} | ||||
|  | ||||
| local http = require('socket.http') | ||||
| local json = require('dkjson') | ||||
| local utilities = require('miku.utilities') | ||||
| local bindings = require('miku.bindings') | ||||
|  | ||||
| function golem:init(config) | ||||
| 	if not cred_data.golem_apikey then | ||||
| 		print('Missing config value: golem_apikey.') | ||||
| 		print('golem.lua will not be enabled.') | ||||
| 		return | ||||
| 	end | ||||
|  | ||||
|   golem.triggers = { | ||||
| 	"golem.de/news/([A-Za-z0-9-_-]+)-(%d+).html" | ||||
|   } | ||||
| end | ||||
|  | ||||
| local BASE_URL = 'http://api.golem.de/api' | ||||
|  | ||||
| function golem:get_golem_data (article_identifier) | ||||
|   local apikey = cred_data.golem_apikey | ||||
|   local url = BASE_URL..'/article/meta/'..article_identifier..'/?key='..apikey..'&format=json' | ||||
|   local res,code  = http.request(url) | ||||
|   if code ~= 200 then return "HTTP-FEHLER" end | ||||
|   local data = json.decode(res).data | ||||
|  | ||||
|   local url = BASE_URL..'/article/images/'..article_identifier..'/?key='..apikey..'&format=json' | ||||
|   local res,code  = http.request(url) | ||||
|   if code ~= 200 then return "HTTP-FEHLER" end | ||||
|   local image_data = json.decode(res).data | ||||
|   return data, image_data | ||||
| end | ||||
|  | ||||
| function golem:send_golem_data(data, image_data) | ||||
|   local headline = '*'..data.headline..'*' | ||||
|   if data.subheadline ~= "" then | ||||
|     subheadline = '\n_'..data.subheadline..'_' | ||||
|   else | ||||
|     subheadline = "" | ||||
|   end | ||||
|   local subheadline = data.subheadline | ||||
|   local abstracttext = data.abstracttext | ||||
|   local text = headline..subheadline..'\n'..abstracttext | ||||
|   if image_data[1] then | ||||
|     image_url = image_data[1].native.url | ||||
|   else | ||||
| 	image_url = data.leadimg.url | ||||
|   end | ||||
|   return text, image_url | ||||
| end | ||||
|  | ||||
| function golem:action(msg, config, matches) | ||||
|   local article_identifier = matches[2] | ||||
|   local data, image_data = golem:get_golem_data(article_identifier) | ||||
|   if not data and not image_data then utilities.send_reply(self, msg, config.errors.connection) return end | ||||
|   local text, image_url = golem:send_golem_data(data, image_data) | ||||
|    | ||||
|   if image_url then | ||||
|     utilities.send_typing(self, msg.chat.id, 'upload_photo') | ||||
|     local file = download_to_file(image_url) | ||||
|     utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id) | ||||
|   end | ||||
|   utilities.send_reply(self, msg, text, true) | ||||
| end | ||||
|  | ||||
| return golem | ||||
| @@ -7,7 +7,7 @@ gps.command = 'gps <Breitengrad>,<Längengrad>' | ||||
|  | ||||
| function gps:init(config) | ||||
| 	gps.triggers = { | ||||
|     "^/gps ([^,]*)[,%s]([^,]*)$", | ||||
|     "^/[Gg][Pp][Ss] ([^,]*)[,%s]([^,]*)$", | ||||
| 	"google.de/maps/@([^,]*)[,%s]([^,]*)", | ||||
| 	"google.com/maps/@([^,]*)[,%s]([^,]*)", | ||||
| 	"google.de/maps/place/@([^,]*)[,%s]([^,]*)", | ||||
|   | ||||
| @@ -1,63 +0,0 @@ | ||||
|  -- Put this on the bottom of your plugin list, after help.lua. | ||||
|  -- If you want to configure your own greetings, copy the following table | ||||
|  -- (without the "config.") to your config.lua file. | ||||
|  | ||||
| local greetings = {} | ||||
|  | ||||
| local utilities = require('miku.utilities') | ||||
|  | ||||
| function greetings:init(config) | ||||
| 	config.greetings = config.greetings or { | ||||
| 		['Hello, #NAME.'] = { | ||||
| 			'hello', | ||||
| 			'hey', | ||||
| 			'sup', | ||||
| 			'hi', | ||||
| 			'good morning', | ||||
| 			'good day', | ||||
| 			'good afternoon', | ||||
| 			'good evening' | ||||
| 		}, | ||||
| 		['Goodbye, #NAME.'] = { | ||||
| 			'bye', | ||||
| 			'later', | ||||
| 			'see ya', | ||||
| 			'good night' | ||||
| 		}, | ||||
| 		['Welcome back, #NAME.'] = { | ||||
| 			'i\'m home', | ||||
| 			'i\'m back' | ||||
| 		}, | ||||
| 		['You\'re welcome, #NAME.'] = { | ||||
| 			'thanks', | ||||
| 			'thank you' | ||||
| 		} | ||||
| 	} | ||||
|  | ||||
| 	greetings.triggers = { | ||||
| 		self.info.first_name:lower() .. '%p*$' | ||||
| 	} | ||||
| end | ||||
|  | ||||
| function greetings:action(msg, config) | ||||
|  | ||||
| 	local nick = utilities.build_name(msg.from.first_name, msg.from.last_name) | ||||
| 	if self.database.userdata[tostring(msg.from.id)] then | ||||
| 		nick = self.database.userdata[tostring(msg.from.id)].nickname or nick | ||||
| 	end | ||||
|  | ||||
| 	for trigger,responses in pairs(config.greetings) do | ||||
| 		for _,response in pairs(responses) do | ||||
| 			if msg.text_lower:match(response..',? '..self.info.first_name:lower()) then | ||||
| 				local output = utilities.char.zwnj .. trigger:gsub('#NAME', nick) | ||||
| 				utilities.send_message(self, msg.chat.id, output) | ||||
| 				return | ||||
| 			end | ||||
| 		end | ||||
| 	end | ||||
|  | ||||
| 	return true | ||||
|  | ||||
| end | ||||
|  | ||||
| return greetings | ||||
| @@ -1,45 +0,0 @@ | ||||
| local hackernews = {} | ||||
|  | ||||
| local https = require('ssl.https') | ||||
| local json = require('dkjson') | ||||
| local URL = require('socket.url') | ||||
| local utilities = require('miku.utilities') | ||||
|  | ||||
| hackernews.triggers = { | ||||
|   "news.ycombinator.com/item%?id=(%d+)" | ||||
| } | ||||
|  | ||||
| local BASE_URL = 'https://hacker-news.firebaseio.com/v0' | ||||
|  | ||||
| function hackernews:send_hackernews_post (hn_code) | ||||
|   local url = BASE_URL..'/item/'..hn_code..'.json' | ||||
|   local res,code  = https.request(url) | ||||
|   if code ~= 200 then return "HTTP-FEHLER" end | ||||
|   local data = json.decode(res) | ||||
|    | ||||
|   local by = data.by | ||||
|   local title = data.title | ||||
|    | ||||
|   if data.url then | ||||
|     url = '\n[Link besuchen]('..data.url..')' | ||||
|   else | ||||
|     url = '' | ||||
|   end | ||||
|  | ||||
|   if data.text then | ||||
|     post = '\n'..unescape_html(data.text) | ||||
| 	post = string.gsub(post, '<p>', ' ') | ||||
|   else | ||||
|     post = '' | ||||
|   end | ||||
|   local text = '*'..title..'* von _'..by..'_'..post..url | ||||
|    | ||||
|   return text | ||||
| end | ||||
|  | ||||
| function hackernews:action(msg, config, matches) | ||||
|   local hn_code = matches[1] | ||||
|   utilities.send_reply(self, msg, hackernews:send_hackernews_post(hn_code), true) | ||||
| end | ||||
|  | ||||
| return hackernews | ||||
| @@ -1,48 +0,0 @@ | ||||
| local heise = {} | ||||
|  | ||||
| local https = require('ssl.https') | ||||
| local URL = require('socket.url') | ||||
| local json = require('dkjson') | ||||
| local utilities = require('miku.utilities') | ||||
| local bindings = require('miku.bindings') | ||||
|  | ||||
| heise.triggers = { | ||||
|       "heise.de/newsticker/meldung/(.*).html$" | ||||
|   } | ||||
|  | ||||
| function heise:get_heise_article(article) | ||||
|   local url = 'https://query.yahooapis.com/v1/public/yql?q=select%20content,src,strong%20from%20html%20where%20url=%22http://www.heise.de/newsticker/meldung/'..article..'.html%22%20and%20xpath=%22//div[@id=%27mitte_news%27]/article/header/h2|//div[@id=%27mitte_news%27]/article/div/p[1]/strong|//div[@id=%27mitte_news%27]/article/div/figure/img%22&format=json' | ||||
|   local res,code  = https.request(url) | ||||
|   local data = json.decode(res).query.results | ||||
|   if code ~= 200 then return "HTTP-Fehler" end | ||||
|    | ||||
|   local title = data.h2 | ||||
|   if data.strong then | ||||
|     teaser = '\n'..data.strong | ||||
|   else | ||||
|     teaser = '' | ||||
|   end | ||||
|   if data.img then | ||||
|     image_url = 'https:'..data.img.src | ||||
|   end | ||||
|   local text = '*'..title..'*'..teaser | ||||
|    | ||||
|   if data.img then | ||||
|     return text, image_url | ||||
|   else | ||||
|     return text | ||||
|   end | ||||
| end | ||||
|  | ||||
| function heise:action(msg, config, matches) | ||||
|   local article = URL.escape(matches[1]) | ||||
|   local text, image_url = heise:get_heise_article(article) | ||||
|   if image_url then | ||||
|     utilities.send_typing(self, msg.chat.id, 'upload_photo') | ||||
|     local file = download_to_file(image_url, 'heise_teaser.jpg') | ||||
|     utilities.send_photo(self, msg.chat.id, file, nil, msg.message_id) | ||||
|   end | ||||
|   utilities.send_reply(self, msg, text, true) | ||||
| end | ||||
|  | ||||
| return heise | ||||
| @@ -1,13 +0,0 @@ | ||||
| local hello = {} | ||||
|  | ||||
| local utilities = require('miku.utilities') | ||||
|  | ||||
| hello.triggers = { | ||||
|   "^[Ss][Aa][Gg] [Hh][Aa][Ll][Ll][Oo] [Zz][Uu] (.*)$" | ||||
| } | ||||
|  | ||||
| function hello:action(msg, config, matches) | ||||
|   utilities.send_reply(self, msg, 'Hallo, '..matches[1]..'!') | ||||
| end | ||||
|  | ||||
| return hello | ||||
| @@ -11,10 +11,7 @@ function id:init(config) | ||||
|     "^/id$", | ||||
|     "^/ids? (chat)$" | ||||
| 	} | ||||
| 	id.doc = [[``` | ||||
| Returns user and chat info for you or the replied-to message. | ||||
| Alias: ]]..config.cmd_pat..[[who | ||||
| ```]] | ||||
| 	id.doc = [[```Zeige dir deine ID und die IDs aller Gruppenmitglieder an.``]] | ||||
| end | ||||
|  | ||||
| function id:get_member_count(self, msg, chat_id) | ||||
|   | ||||
| @@ -1,80 +0,0 @@ | ||||
| local ifttt = {} | ||||
|  | ||||
| local https = require('ssl.https') | ||||
| local URL = require('socket.url') | ||||
| local redis = (loadfile "./miku/redis.lua")() | ||||
| local utilities = require('miku.utilities') | ||||
| local bindings = require('miku.bindings') | ||||
|  | ||||
| function ifttt:init(config) | ||||
|   ifttt.triggers = { | ||||
|     "^/ifttt (!set) (.*)$", | ||||
| 	"^/ifttt (!unauth)$", | ||||
| 	"^/ifttt (.*)%&(.*)%&(.*)%&(.*)", | ||||
| 	"^/ifttt (.*)%&(.*)%&(.*)", | ||||
| 	"^/ifttt (.*)%&(.*)", | ||||
| 	"^/ifttt (.*)$" | ||||
|   } | ||||
|    | ||||
|   ifttt.doc = [[* | ||||
| ]]..config.cmd_pat..[[ifttt* _!set_ _<Key>_: Speichere deinen Schlüssel ein (erforderlich) | ||||
| *]]..config.cmd_pat..[[ifttt* _!unauth_: Löscht deinen Account aus dem Bot | ||||
| *]]..config.cmd_pat..[[ifttt* _<Event>_&_<Value1>_&_<Value2>_&_<Value3>_: Führt [Event] mit den optionalen Parametern Value1, Value2 und Value3 aus | ||||
| Beispiel: `/ifttt DeinFestgelegterName&Hallo&NochEinHallo`: Führt 'DeinFestgelegterName' mit den Parametern 'Hallo' und 'NochEinHallo' aus.]] | ||||
| end | ||||
|  | ||||
| ifttt.command = 'ifttt <Event>&<Value1>&<Value2>&<Value3>' | ||||
|  | ||||
| local BASE_URL = 'https://maker.ifttt.com/trigger' | ||||
|  | ||||
| function ifttt:set_ifttt_key(hash, key) | ||||
|   print('Setting ifttt in redis hash '..hash..' to '..key) | ||||
|   redis:hset(hash, 'ifttt', key) | ||||
|   return '*Schlüssel eingespeichert!* Das Plugin kann jetzt verwendet werden.' | ||||
| end | ||||
|  | ||||
| function ifttt:do_ifttt_request(key, event, value1, value2, value3) | ||||
|   if not value1 then | ||||
|     url = BASE_URL..'/'..event..'/with/key/'..key | ||||
|   elseif not value2 then | ||||
|     url = BASE_URL..'/'..event..'/with/key/'..key..'/?value1='..URL.escape(value1) | ||||
|   elseif not value3 then | ||||
|     url = BASE_URL..'/'..event..'/with/key/'..key..'/?value1='..URL.escape(value1)..'&value2='..URL.escape(value2) | ||||
|   else | ||||
|     url = BASE_URL..'/'..event..'/with/key/'..key..'/?value1='..URL.escape(value1)..'&value2='..URL.escape(value2)..'&value3='..URL.escape(value3) | ||||
|   end | ||||
|  | ||||
|   local res,code = https.request(url) | ||||
|   if code ~= 200 then return "*Ein Fehler ist aufgetreten!* Aktion wurde nicht ausgeführt." end | ||||
|    | ||||
|   return "*Event \""..event.."\" getriggert!*" | ||||
| end | ||||
|  | ||||
| function ifttt:action(msg, config, matches) | ||||
|   local hash = 'user:'..msg.from.id | ||||
|   local key = redis:hget(hash, 'ifttt') | ||||
|   local event = matches[1] | ||||
|   local value1 = matches[2] | ||||
|   local value2 = matches[3] | ||||
|   local value3 = matches[4] | ||||
|    | ||||
|   if event == '!set' then | ||||
|     utilities.send_reply(self, msg, ifttt:set_ifttt_key(hash, value1), true) | ||||
|     return | ||||
|   end | ||||
|    | ||||
|   if not key then | ||||
|     utilities.send_reply(self, msg, '*Bitte speichere zuerst deinen Schlüssel ein!* Aktiviere dazu den [Maker Channel](https://ifttt.com/maker) und speichere deinen Schlüssel mit `/ifttt !set KEY` ein', true) | ||||
|     return | ||||
|   end | ||||
|    | ||||
|   if event == '!unauth' then | ||||
|     redis:hdel(hash, 'ifttt') | ||||
| 	utilities.send_reply(self, msg, '*Erfolgreich ausgeloggt!*', true) | ||||
| 	return | ||||
|   end | ||||
|    | ||||
|   utilities.send_reply(self, msg, ifttt:do_ifttt_request(key, event, value1, value2, value3), true) | ||||
| end | ||||
|  | ||||
| return ifttt | ||||
| @@ -1,80 +0,0 @@ | ||||
| local instagram = {} | ||||
|  | ||||
| local https = require('ssl.https') | ||||
| local json = require('dkjson') | ||||
| local URL = require('socket.url') | ||||
| local utilities = require('miku.utilities') | ||||
|  | ||||
| function instagram:init(config) | ||||
|   if not cred_data.instagram_access_token then | ||||
| 	print('Missing config value: instagram_access_token.') | ||||
| 	print('instagram.lua will not be enabled.') | ||||
| 	return | ||||
|   end | ||||
|  | ||||
|   instagram.triggers = { | ||||
| 	"instagram.com/p/([A-Za-z0-9-_-]+)" | ||||
|   } | ||||
| end | ||||
|  | ||||
| local BASE_URL = 'https://api.instagram.com/v1' | ||||
| local access_token = cred_data.instagram_access_token | ||||
|  | ||||
| function instagram: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 nil end | ||||
|   local data = json.decode(res).data | ||||
|   return data | ||||
| end | ||||
|  | ||||
| function instagram:send_instagram_data(data) | ||||
|   -- 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 | ||||
|    | ||||
|   return header..caption..footer, image_url | ||||
| end | ||||
|  | ||||
| function instagram:action(msg, config, matches) | ||||
|   local insta_code = matches[1] | ||||
|   local data = instagram:get_insta_data(insta_code) | ||||
|   if not data then utilities.send_reply(self, msg, config.errors.connection) return end | ||||
|    | ||||
|   local text, image_url = instagram:send_instagram_data(data) | ||||
|   if not image_url then utilities.send_reply(self, msg, config.errors.connection) return end | ||||
|    | ||||
|   utilities.send_typing(self, msg.chat.id, 'upload_photo') | ||||
|   local file = download_to_file(image_url) | ||||
|   utilities.send_photo(self, msg.chat.id, file, text, msg.message_id) | ||||
| end | ||||
|  | ||||
| return instagram | ||||
| @@ -8,8 +8,8 @@ local utilities = require('miku.utilities') | ||||
|  | ||||
| function isup:init(config) | ||||
|   isup.triggers = { | ||||
|     "^/isup (.*)$", | ||||
|     "^/ping (.*)$" | ||||
|     "^/[Ii][Ss][Uu][Pp] (.*)$", | ||||
|     "^/[Pp][Ii][Nn][Gg] (.*)$" | ||||
|   } | ||||
| 	 | ||||
|   isup.doc = [[* | ||||
|   | ||||
| @@ -5,9 +5,9 @@ local redis = (loadfile "./miku/redis.lua")() | ||||
|  | ||||
| function loc_manager:init(config) | ||||
|     loc_manager.triggers = { | ||||
| 	  "^/location (set) (.*)$", | ||||
|       "^/location (del)$", | ||||
| 	  "^/location$" | ||||
| 	  "^/[Ll][Oo][Cc][Aa][Tt][Ii][Oo][Nn] (set) (.*)$", | ||||
|       "^/[Ll][Oo][Cc][Aa][Tt][Ii][Oo][Nn] (del)$", | ||||
| 	  "^/[Ll][Oo][Cc][Aa][Tt][Ii][Oo][Nn]$" | ||||
| 	} | ||||
| 	loc_manager.doc = [[* | ||||
| ]]..config.cmd_pat..[[location*: Gibt deinen gesetzten Wohnort aus | ||||
|   | ||||
| @@ -1,53 +0,0 @@ | ||||
| local luarun = {} | ||||
|  | ||||
| local utilities = require('miku.utilities') | ||||
| local URL = require('socket.url') | ||||
| local JSON = require('dkjson') | ||||
|  | ||||
| function luarun:init(config) | ||||
| 	luarun.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('lua', true):t('return', true).table | ||||
| end | ||||
|  | ||||
| function luarun:action(msg, config) | ||||
|  | ||||
| 	if msg.from.id ~= config.admin then | ||||
| 		return true | ||||
| 	end | ||||
|  | ||||
| 	local input = utilities.input(msg.text) | ||||
| 	if not input then | ||||
| 		utilities.send_reply(self, msg, 'Please enter a string to load.') | ||||
| 		return | ||||
| 	end | ||||
|  | ||||
| 	if msg.text_lower:match('^'..config.cmd_pat..'return') then | ||||
| 		input = 'return ' .. input | ||||
| 	end | ||||
|  | ||||
| 	local output = loadstring( [[ | ||||
| 		local bot = require('miku.bot') | ||||
| 		local bindings = require('miku.bindings') | ||||
| 		local utilities = require('miku.utilities') | ||||
| 		local JSON = require('dkjson') | ||||
| 		local URL = require('socket.url') | ||||
| 		local HTTP = require('socket.http') | ||||
| 		local HTTPS = require('ssl.https') | ||||
| 		return function (self, msg, config) ]] .. input .. [[ end | ||||
| 	]] )()(self, msg, config) | ||||
| 	if output == nil then | ||||
| 		output = 'Done!' | ||||
| 	else | ||||
| 		if type(output) == 'table' then | ||||
| 			local s = JSON.encode(output, {indent=true}) | ||||
| 			if URL.escape(s):len() < 4000 then | ||||
| 				output = s | ||||
| 			end | ||||
| 		end | ||||
| 		output = '```\n' .. tostring(output) .. '\n```' | ||||
| 	end | ||||
| 	utilities.send_message(self, msg.chat.id, output, true, msg.message_id, true) | ||||
|  | ||||
| end | ||||
|  | ||||
| return luarun | ||||
|  | ||||
| @@ -3,7 +3,7 @@ local muschel = {} | ||||
| local utilities = require('miku.utilities') | ||||
|  | ||||
| muschel.triggers = { | ||||
| 	"^[Mm][Aa][Gg][Ii][Ss][Cc][Hh][Ee] [Mm][Ii][Ee][Ss][Mm][Uu][Ss][Cc][Hh][Ee][Ll], (.*)$" | ||||
| 	"^[Mm][Aa][Gg][Ii][Ss][Cc][Hh][Ee] [Mm][Ii][Ee][Ss][Mm][Uu][Ss][Cc][Hh][Ee][Ll] (.*)$" | ||||
| } | ||||
|  | ||||
| function muschel:frag_die_muschel() | ||||
|   | ||||
| @@ -21,6 +21,7 @@ media.triggers = { | ||||
|     	"^(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(avi))$", | ||||
| 		"(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(wav))$", | ||||
| 		"(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(apk))$", | ||||
| 		"(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(ipa))$", | ||||
| 		"(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(webm))$", | ||||
| 		"^(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(ogv))$", | ||||
| 		"(https?://[%w-_%.%?%.:,/%+=&%[%]]+%.(webp))$" | ||||
|   | ||||
| @@ -9,8 +9,8 @@ local bindings = require('miku.bindings') | ||||
| mal.command = 'anime <Anime>, /manga <Manga>' | ||||
|  | ||||
| function mal:init(config) | ||||
| 	if not cred_data.mal_user then | ||||
| 		print('Missing config value: mal_user.') | ||||
| 	if not cred_data.mal_username then | ||||
| 		print('Missing config value: mal_username.') | ||||
| 		print('myanimelist.lua will not be enabled.') | ||||
| 		return | ||||
| 	elseif not cred_data.mal_pw then | ||||
| @@ -21,6 +21,7 @@ function mal:init(config) | ||||
|  | ||||
|   mal.triggers = { | ||||
| 	"^/(anime) (.+)$", | ||||
| 	"^/(mal) (.+)$", | ||||
| 	"^/(manga) (.+)$" | ||||
| 	} | ||||
|   mal.doc = [[* | ||||
| @@ -29,7 +30,7 @@ function mal:init(config) | ||||
| ]] | ||||
| end | ||||
|  | ||||
| local user = cred_data.mal_user | ||||
| local user = cred_data.mal_username | ||||
| local password = cred_data.mal_pw | ||||
|  | ||||
| local BASE_URL = 'http://'..user..':'..password..'@myanimelist.net/api' | ||||
| @@ -192,7 +193,7 @@ end | ||||
|  | ||||
| function mal:action(msg, config, matches) | ||||
|   local query = URL.escape(matches[2]) | ||||
|   if matches[1] == 'anime' then | ||||
|   if matches[1] == 'anime' or matches[1] == 'mal' then | ||||
|     local anime_info = mal:get_mal_info(query, 'anime') | ||||
|     if anime_info == "HTTP-Fehler" then | ||||
|       utilities.send_reply(self, msg, 'Anime nicht gefunden!') | ||||
|   | ||||
| @@ -78,6 +78,18 @@ function unescape_for_rss(str) | ||||
|   return str | ||||
| end | ||||
|  | ||||
| function cleanRSS(cleantext) | ||||
|   cleantext = string.gsub(cleantext, '%[mehr%]', '') | ||||
|   cleantext = string.gsub(cleantext, '%[video%]', '') | ||||
|   cleantext = string.gsub(cleantext, '...%[more%]', '') | ||||
|   cleantext = string.gsub(cleantext, '%[more%]', '') | ||||
|   cleantext = string.gsub(cleantext, 'Click for full.', '') | ||||
|   cleantext = string.gsub(cleantext, 'Read more »', '') | ||||
|   cleantext = string.gsub(cleantext, 'Meldung bei www.tagesschau.de lesen', '') | ||||
|    | ||||
|   return cleantext | ||||
| end | ||||
|  | ||||
| function get_base_redis(id, option, extra) | ||||
|    local ex = '' | ||||
|    if option ~= nil then | ||||
| @@ -344,7 +356,8 @@ function rss:cron(self_plz) | ||||
| 		 else | ||||
| 		   content = '' | ||||
| 		 end | ||||
| 		 text = text..'\n*[*#RSS*] '..title..'*\n'..utilities.trim(utilities.markdown_escape_simple(content))..' [Weiterlesen]('..link..')\n' | ||||
| 		 content = cleanRSS(content) | ||||
| 		 text = text..'\n*[*#RSS*] '..title..'*\n'..utilities.trim(utilities.md_escape(content))..' [Weiterlesen]('..link..')\n' | ||||
|       end | ||||
|       if text ~= '' then | ||||
|          local newlast = newentr[1].id | ||||
|   | ||||
| @@ -34,6 +34,13 @@ local makeOurDate = function(dateString) | ||||
|   return day..'.'..month..'.'..year | ||||
| end | ||||
|  | ||||
| function markdown_escape_simple(text) | ||||
| 	text = text:gsub('_', '\\_') | ||||
| 	text = text:gsub('%*', '\\*') | ||||
| 	text = text:gsub('`', '\\`') | ||||
| 	return text | ||||
| end | ||||
|  | ||||
| function get_yt_data (yt_code) | ||||
|   local apikey = cred_data.google_apikey | ||||
|   local url = BASE_URL..'/videos?part=snippet,statistics,contentDetails&key='..apikey..'&id='..yt_code..'&fields=items(snippet(publishedAt,channelTitle,localized(title,description),thumbnails),statistics(viewCount,likeCount,dislikeCount,commentCount),contentDetails(duration,regionRestriction(blocked)))' | ||||
| @@ -98,7 +105,7 @@ function get_yt_thumbnail(data) | ||||
| end | ||||
|  | ||||
| function send_youtube_data(data, msg, self, link, sendpic) | ||||
|   local title = utilities.markdown_escape_simple(data.snippet.localized.title) | ||||
|   local title = markdown_escape_simple(data.snippet.localized.title) | ||||
|   -- local description = data.snippet.localized.description | ||||
|   local uploader = data.snippet.channelTitle | ||||
|   local upload_date = makeOurDate(data.snippet.publishedAt) | ||||
|   | ||||
| @@ -491,14 +491,6 @@ end | ||||
| function utilities.markdown_escape(text) | ||||
| 	text = text:gsub('_', '\\_') | ||||
| 	text = text:gsub('%[', '\\[') | ||||
| 	text = text:gsub('%]', '\\]') | ||||
| 	text = text:gsub('%*', '\\*') | ||||
| 	text = text:gsub('`', '\\`') | ||||
| 	return text | ||||
| end | ||||
|  | ||||
| function utilities.markdown_escape_simple(text) | ||||
| 	text = text:gsub('_', '\\_') | ||||
| 	text = text:gsub('%*', '\\*') | ||||
| 	text = text:gsub('`', '\\`') | ||||
| 	return text | ||||
|   | ||||
		Reference in New Issue
	
	Block a user