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/dhl.lua
Akamaru b7ed1dbc80 Alles miku
Erste Anpassungen für Mikudayobot
2016-07-17 13:22:27 +02:00

39 lines
1.1 KiB
Lua

local dhl = {}
local https = require('ssl.https')
local json = require('dkjson')
local utilities = require('miku.utilities')
function dhl:init(config)
dhl.triggers = {
"/dhl (%d+)$"
}
dhl.doc = [[*
]]..config.cmd_pat..[[dhl* _<Sendungsnummer>_: Aktueller Status der Sendung]]
end
local BASE_URL = 'https://mobil.dhl.de'
function dhl:sendungsstatus(id)
local url = BASE_URL..'/shipmentdetails.html?shipmentId='..id
local res,code = https.request(url)
if code ~= 200 then return "Fehler beim Abrufen von mobil.dhl.de" end
local status = string.match(res, "<div id%=\"detailShortStatus\">(.-)</div>")
local status = all_trim(status)
local zeit = string.match(res, "<div id%=\"detailStatusDateTime\">(.-)</div>")
local zeit = all_trim(zeit)
if not zeit or zeit == '<br />' then
return status
end
return '*'..status..'*\n_Stand: '..zeit..'_'
end
function dhl:action(msg, config, matches)
local sendungs_id = matches[1]
if string.len(sendungs_id) < 8 then return end
utilities.send_reply(self, msg, dhl:sendungsstatus(sendungs_id), true)
end
return dhl