Moved from luasec to pure curl implementation. mcstatus is now async.
This commit is contained in:
parent
0ab3c47607
commit
f490e6e8ef
|
@ -4,7 +4,6 @@ lanxu awesome scripts
|
||||||
Requirements
|
Requirements
|
||||||
------------
|
------------
|
||||||
|
|
||||||
- luasec (for https connections)
|
|
||||||
- dkjson (for parsing json. Available with this widget)
|
- dkjson (for parsing json. Available with this widget)
|
||||||
|
|
||||||
How to use
|
How to use
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
local naughty = require("naughty")
|
local naughty = require("naughty")
|
||||||
local wibox = require("wibox")
|
local wibox = require("wibox")
|
||||||
local json = require("lanxu/dkjson")
|
local json = require("lanxu/dkjson")
|
||||||
local https = require("ssl.https")
|
local gears = require("gears")
|
||||||
local gears = require("gears")
|
local focused = require("awful.screen").focused
|
||||||
local focused = require("awful.screen").focused
|
local easy_async = require("awful.spawn").easy_async
|
||||||
|
|
||||||
local function factory(args)
|
local function factory(args)
|
||||||
local args = args or {}
|
local args = args or {}
|
||||||
|
@ -26,11 +26,11 @@ local function factory(args)
|
||||||
end
|
end
|
||||||
|
|
||||||
minecraft.notification = naughty.notify({
|
minecraft.notification = naughty.notify({
|
||||||
text = minecraft.notification_text,
|
text = minecraft.notification_text,
|
||||||
-- icon = minecraft.icon
|
-- icon = minecraft.icon
|
||||||
timeout = 0,
|
timeout = 0,
|
||||||
preset = notification_preset,
|
preset = notification_preset,
|
||||||
})
|
})
|
||||||
end
|
end
|
||||||
|
|
||||||
function minecraft.hide()
|
function minecraft.hide()
|
||||||
|
@ -55,47 +55,50 @@ local function factory(args)
|
||||||
end
|
end
|
||||||
|
|
||||||
function minecraft.update()
|
function minecraft.update()
|
||||||
local response, error = https.request(calluri)
|
local cmd = string.format("curl -s " .. "'" .. calluri .. "'")
|
||||||
local obj, pos, err = json.decode (response, 1, nil)
|
|
||||||
|
|
||||||
totalplayers = 0
|
easy_async(cmd, function(response, stderr, reason, exit_code)
|
||||||
|
local obj, pos, err = json.decode(response, 1, nil)
|
||||||
|
|
||||||
if not err then
|
totalplayers = 0
|
||||||
-- First get the length of the longest server name, for proper column alignment
|
|
||||||
local max_len = 6 -- Initialize to the length of "Server"
|
|
||||||
for k, v in pairs(obj) do
|
|
||||||
if (tonumber(v.num_players) > 0 or not hideempty) and (v.status == "online" or not hideoffline) then
|
|
||||||
local tmp = string.len(v.server_name)
|
|
||||||
if tmp > max_len then
|
|
||||||
max_len = tmp
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local fmt = string.format("%%-%ds %%-8s %%-7s\n", max_len)
|
if not err then
|
||||||
local text = string.format(fmt, "Server", "Version", "Players")
|
-- First get the length of the longest server name, for proper column alignment
|
||||||
|
local max_len = 6 -- Initialize to the length of "Server"
|
||||||
for k, v in pairs(obj) do
|
for k, v in pairs(obj) do
|
||||||
local players = tonumber(v.num_players)
|
if (tonumber(v.num_players) > 0 or not hideempty) and (v.status == "online" or not hideoffline) then
|
||||||
|
local tmp = string.len(v.server_name)
|
||||||
if (players > 0 or not hideempty) and (v.status == "online" or not hideoffline) then
|
if tmp > max_len then
|
||||||
text = text .. string.format(fmt, v.server_name, v.version, v.num_players)
|
max_len = tmp
|
||||||
|
|
||||||
if v.players then
|
|
||||||
for i, p in pairs(v.players) do
|
|
||||||
text = text .. ' > ' .. p .. '\n'
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
totalplayers = totalplayers + players
|
local fmt = string.format("%%-%ds %%-8s %%-7s\n", max_len)
|
||||||
end
|
local text = string.format(fmt, "Server", "Version", "Players")
|
||||||
|
|
||||||
minecraft.notification_text = text
|
for k, v in pairs(obj) do
|
||||||
minecraft.totalplayers = totalplayers;
|
local players = tonumber(v.num_players)
|
||||||
widget = minecraft.widget
|
|
||||||
settings()
|
if (players > 0 or not hideempty) and (v.status == "online" or not hideoffline) then
|
||||||
end
|
text = text .. string.format(fmt, v.server_name, v.version, v.num_players)
|
||||||
|
|
||||||
|
if v.players then
|
||||||
|
for i, p in pairs(v.players) do
|
||||||
|
text = text .. ' > ' .. p .. '\n'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
totalplayers = totalplayers + players
|
||||||
|
end
|
||||||
|
|
||||||
|
minecraft.notification_text = text
|
||||||
|
minecraft.totalplayers = totalplayers;
|
||||||
|
widget = minecraft.widget
|
||||||
|
settings()
|
||||||
|
end
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
minecraft.attach(minecraft.widget)
|
minecraft.attach(minecraft.widget)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user