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

59 lines
2.1 KiB
Lua
Raw Normal View History

local pihole = {}
function pihole:init(config)
pihole.triggers = {'/[Pp][Ii][Hh][Oo][Ll][ee]'}
end
function pihole:transeng(ger)
--Days
local ger = string.gsub(ger, "Monday", "Montag")
local ger = string.gsub(ger, "Tuesday", "Dienstag")
local ger = string.gsub(ger, "Wednesday", "Mittwoch")
local ger = string.gsub(ger, "Thursday", "Donnerstag")
local ger = string.gsub(ger, "Friday", "Freitag")
local ger = string.gsub(ger, "Saturday", "Samstag")
local ger = string.gsub(ger, "Sunday", "Sonntag")
--Months
local ger = string.gsub(ger, "January", "Januar")
local ger = string.gsub(ger, "February", "Februar")
local ger = string.gsub(ger, "March", "März")
local ger = string.gsub(ger, "April", "April")
local ger = string.gsub(ger, "May", "Mai")
local ger = string.gsub(ger, "June", "Juni")
local ger = string.gsub(ger, "July", "Juli")
local ger = string.gsub(ger, "August", "August")
local ger = string.gsub(ger, "September", "September")
local ger = string.gsub(ger, "October", "Oktober")
local ger = string.gsub(ger, "November", "November")
local ger = string.gsub(ger, "December", "Dezember")
return ger
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 time = os.date("%A den %d. %B %Y")
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 vom '..pihole:transeng(time)..'</b>\nGeblockte Domains: <i>'..domains_being_blocked..'</i>\nHeutige DNS-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