50 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
			
		
		
	
	
			50 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			Lua
		
	
	
	
	
	
do
 | 
						|
 | 
						|
local function getUrbanDictionary(term)
 | 
						|
  local url = 'http://api.urbandictionary.com/v0/define?term='..term
 | 
						|
  local res,code  = http.request(url)
 | 
						|
  local data = json:decode(res)
 | 
						|
  if code ~= 200 then return "HTTP-Fehler" end
 | 
						|
  if not data then return "Nichts gefunden!" end
 | 
						|
 
 | 
						|
  local word = data.list[1].word
 | 
						|
  local dev = data.list[1].definition
 | 
						|
  local exam = data.list[1].example
 | 
						|
  local url = data.list[1].permalink
 | 
						|
  if data.sounds[1] then
 | 
						|
    sound = data.sounds[1]
 | 
						|
  end
 | 
						|
  
 | 
						|
  local text = unescape(word..'\n'..dev..'\n\nBeispiel: "'..exam..'"\n')..url
 | 
						|
 
 | 
						|
  if data.sounds[1] then
 | 
						|
    return text, sound
 | 
						|
  else
 | 
						|
    return text
 | 
						|
  end
 | 
						|
end
 | 
						|
 | 
						|
local function run(msg, matches)
 | 
						|
  local term = string.gsub(matches[1], ' ', '%%20')
 | 
						|
  local text, sound = getUrbanDictionary(term)
 | 
						|
  local receiver = get_receiver(msg)
 | 
						|
  if sound then
 | 
						|
    local file = download_to_file(sound, term..'.mp3')
 | 
						|
    send_audio(receiver, file, ok_cb, false)
 | 
						|
  end
 | 
						|
  return text
 | 
						|
end
 | 
						|
 | 
						|
return {
 | 
						|
    description = "Zeigt eine Urban Dictionary Definition",
 | 
						|
    usage = {"#ud [Begriff]"},
 | 
						|
    patterns = {"^#[Uu][Dd] (.*)$",
 | 
						|
				"^http://([A-Za-z0-9-_-]+).urbanup.com/",
 | 
						|
				"^http://www.urbandictionary.com/define.php%?term=([A-Za-z0-9-_-]+)"
 | 
						|
				},
 | 
						|
    run = run
 | 
						|
}
 | 
						|
 | 
						|
--by Akamaru [https://ponywave.de]
 | 
						|
 | 
						|
end |