This repository has been archived on 2021-04-24. You can view files and clone it, but cannot push or open issues or pull requests.
Mikubot-2/miku/plugins/pihole.lua

32 lines
1.0 KiB
Lua

local pihole = {}
function pihole:init(config)
pihole.triggers = {'^/[Pp][Ii][Hh][Oo][Ll][ee]'}
end
function pihole:get_pihole()
local url = 'http://nibutani.local/admin/api.php'
local b,c = http.request(url)
if c ~= 200 then return nil end
local data = json.decode(b)
local domains_being_blocked = data.domains_being_blocked
local dns_queries_today = data.dns_queries_today
local ads_blocked_today = data.ads_blocked_today
local ads_percentage_today = data.ads_percentage_today
local text = '<b>Pi-Hole Statistik der letzten 24h</b>\nGeblockte Domains: <i>'..domains_being_blocked..'</i>\nDNS-Abfragen: <i>'..dns_queries_today..'</i>\nGeblockte DNS-Abfragen: <i>'..ads_blocked_today..' ('..ads_percentage_today..'%)</i>'
return text
end
function pihole:action(msg, config, matches)
local text = pihole:get_pihole()
if not text then
utilities.send_reply(msg, config.errors.results)
return
end
utilities.send_message(msg.chat.id, text, false, msg.message_id, 'html')
end
return pihole