2016-08-18 17:23:55 +02:00
|
|
|
local rpic = {}
|
|
|
|
|
|
|
|
function rpic:init(config)
|
|
|
|
rpic.triggers = utilities.triggers(self.info.username, config.cmd_pat):t('rpic', true).table
|
|
|
|
rpic.doc = [[*
|
|
|
|
]]..config.cmd_pat..[[rpic* _<Thema>_
|
|
|
|
*Themen:*
|
|
|
|
- anime
|
|
|
|
- mlp
|
|
|
|
- doge
|
|
|
|
- faktillion
|
|
|
|
- faktastisch
|
|
|
|
- gamefakt
|
|
|
|
- faktglaublich]]
|
|
|
|
end
|
|
|
|
|
|
|
|
rpic.command = 'rpic <Thema>'
|
|
|
|
|
|
|
|
function rpic:get_random_image(dir)
|
|
|
|
files = scandir(dir)
|
|
|
|
if not files[1] then return ': Keine Dateien vorhanden!' end
|
|
|
|
file = files[math.random(#files)]
|
|
|
|
return file
|
|
|
|
end
|
|
|
|
|
|
|
|
function rpic:action(msg, config)
|
|
|
|
local input = utilities.input_from_msg(msg)
|
|
|
|
if not input then
|
2016-08-24 17:18:17 +02:00
|
|
|
utilities.send_reply(msg, rpic.doc, true)
|
2016-08-18 17:23:55 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local pics = {
|
|
|
|
["test"] = "../Festplatten/Dragoran/Mikubot/sfw/test/",
|
|
|
|
["anime"] = "../Festplatten/Dragoran/Mikubot/sfw/anime/",
|
|
|
|
["mlp"] = "../Festplatten/Dragoran/Mikubot/sfw/mlp/",
|
|
|
|
["doge"] = "../Festplatten/Dragoran/Mikubot/sfw/doge/",
|
|
|
|
["faktillon"] = "../Festplatten/Dragoran/Mikubot/sfw/faktillon/",
|
|
|
|
["faktastisch"] = "../Festplatten/Dragoran/Mikubot/sfw/faktastisch/",
|
|
|
|
["gamefakt"] = "../Festplatten/Dragoran/Mikubot/sfw/gamefakt/",
|
|
|
|
["faktglaublich"] = "../Festplatten/Dragoran/Mikubot/sfw/faktglaublich/"
|
|
|
|
}
|
|
|
|
|
|
|
|
if pics[input] then
|
|
|
|
local img = pics[input]..rpic:get_random_image(pics[input])
|
|
|
|
print("Sende... "..img)
|
|
|
|
if string.ends(img, ".gif") or string.ends(img, ".mp4") then
|
2016-08-24 17:18:17 +02:00
|
|
|
utilities.send_document(msg.chat.id, img)
|
2016-08-18 17:23:55 +02:00
|
|
|
return
|
|
|
|
elseif string.ends(img, ".jpg") or string.ends(img, ".jpeg") or string.ends(img, ".png") then
|
2016-08-24 17:18:17 +02:00
|
|
|
utilities.send_photo(msg.chat.id, img)
|
2016-08-18 17:23:55 +02:00
|
|
|
return
|
|
|
|
else
|
2016-08-24 17:18:17 +02:00
|
|
|
utilities.send_reply(msg, 'Fehler: '..img)
|
2016-08-18 17:23:55 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
else
|
2016-08-24 17:18:17 +02:00
|
|
|
utilities.send_reply(msg, '*Dieses Thema gibt es nicht!*'..rpic.doc, true)
|
2016-08-18 17:23:55 +02:00
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return rpic
|