new plugins
4chan.lua notizen.lua
This commit is contained in:
parent
bd5ae0d642
commit
8c037629a7
94
plugins/4chan.lua
Normal file
94
plugins/4chan.lua
Normal file
@ -0,0 +1,94 @@
|
||||
local max_characters = 1000
|
||||
local display_thread_subject = true -- Doesn't count for max_characters
|
||||
local send_image = true
|
||||
|
||||
|
||||
local function html2text(data)
|
||||
data = string.gsub(data, "<br><br>", "\n")
|
||||
data = string.gsub(data, "<br>", "\n")
|
||||
data = string.gsub(data, "<a.->", " ")
|
||||
data = string.gsub(data, "</a>", " ")
|
||||
data = string.gsub(data, "<p.->(.-)</p>", "%1\n")
|
||||
data = string.gsub(data, "<b.->", "")
|
||||
data = string.gsub(data, "</b>", "")
|
||||
data = string.gsub(data, "<i.->", "")
|
||||
data = string.gsub(data, "</i>", "")
|
||||
data = string.gsub(data, "<sup.->", "")
|
||||
data = string.gsub(data, "</sup>", "")
|
||||
data = string.gsub(data, "<span.->", "\n")
|
||||
data = string.gsub(data, "</span>", "\n")
|
||||
data = string.gsub(data, "<div.->(.-)</div>", "%1\n")
|
||||
--data = string.gsub(data, "[.-]", "")
|
||||
data = string.gsub(data, "<table.->.-</table>", "")
|
||||
data = string.gsub(data, "<li.->(.-)</li>", " - %1\n")
|
||||
data = string.gsub(data, "<.->", "")
|
||||
data = string.gsub(data, ">", ">")
|
||||
data = string.gsub(data, "&", "&")
|
||||
data = string.gsub(data, "&..;", "")
|
||||
data = string.gsub(data, "&...;", "")
|
||||
data = string.gsub(data, "&....;", "")
|
||||
return data
|
||||
end
|
||||
|
||||
|
||||
local function get4chanRandomThread()
|
||||
local api = "http://a.4cdn.org/vg/catalog.json"
|
||||
local res, code = http.request(api)
|
||||
if code ~= 200 then return nil end
|
||||
local jsonCatalog = json:decode(res)
|
||||
|
||||
local data = jsonCatalog
|
||||
if not data then
|
||||
return nil
|
||||
end
|
||||
|
||||
if #data == 0 then
|
||||
return nil
|
||||
end
|
||||
|
||||
-- Random page from catalog
|
||||
local i = math.random(#data)
|
||||
local page = data[i]
|
||||
if not page then
|
||||
print("page = nil")
|
||||
return nil
|
||||
end
|
||||
if #page.threads == 0 then
|
||||
print("#page.threads = 0")
|
||||
return nil
|
||||
end
|
||||
--Random thread from page
|
||||
local j = math.random(#page.threads)
|
||||
local thread = page.threads[j]
|
||||
return thread
|
||||
end
|
||||
|
||||
|
||||
local function run(msg, matches)
|
||||
local receiver = get_receiver(msg)
|
||||
local thread = get4chanRandomThread()
|
||||
if thread == nil then return "ERROR!" end
|
||||
if thread.com == nil then return "ERROR!" end
|
||||
local text = thread.com
|
||||
text = string.gsub(text, "<a href=\"/.-\" class=\"quotelink\">.-</a>", "")
|
||||
text = string.gsub(text, "%s.-%sThread", "")
|
||||
text = html2text(text)
|
||||
if string.len(text) >= max_characters then
|
||||
text = string.sub(text, 1, max_characters).."\n[...]"
|
||||
end
|
||||
|
||||
if thread.tim ~= nill and thread.ext ~= nil and send_image then
|
||||
send_photo_from_url(get_receiver(msg), "http://i.4cdn.org/vg/"..thread.tim..thread.ext)
|
||||
end
|
||||
if thread.sub ~= nill and display_thread_subject then
|
||||
text = thread.sub..":\n"..text
|
||||
end
|
||||
return text
|
||||
end
|
||||
|
||||
return {
|
||||
description = "Get a random thread.",
|
||||
usage = "/4chan: get a random thread",
|
||||
patterns = {"^/4chan$"},
|
||||
run = run
|
||||
}
|
@ -36,7 +36,7 @@ local function run(msg, matches)
|
||||
local post = get_post(url)
|
||||
|
||||
if post then
|
||||
vardump(post)
|
||||
--vardump(post)
|
||||
local img = URL .. post.large_file_url
|
||||
send_photo_from_url(get_receiver(msg), img)
|
||||
|
||||
|
27
plugins/notizen.lua
Normal file
27
plugins/notizen.lua
Normal file
@ -0,0 +1,27 @@
|
||||
local function run(msg, matches)
|
||||
local user_name = get_name(msg)
|
||||
if msg.to.type == 'chat' then
|
||||
local text = matches[1]
|
||||
local b = 1
|
||||
|
||||
while b ~= 0 do
|
||||
text,b = text:gsub('^/+','')
|
||||
text = text:trim()
|
||||
end
|
||||
|
||||
send_msg('chat#id' .. msg.to.id, 'Hey '..user_name..', ich hab dir gerade deine Nachricht gesendet!', ok_cb, false)
|
||||
send_msg('user#id' .. msg.from.id, text, ok_cb, false)
|
||||
else
|
||||
return "Das Plugin solltest du nur in Gruppen nutzen."
|
||||
end
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
||||
return {
|
||||
description = "Sendet eine Nachricht an dich selbst",
|
||||
usage = {"/note [Nachricht]"},
|
||||
patterns = {"^/note (.*)$","^/notiz (.*)$"},
|
||||
run = run
|
||||
}
|
Reference in New Issue
Block a user