1 -- Authors: Jeremy Hankins <nowan@nowan.org>
3 -- Last Changed: 2005-06-28
5 -- By Jeremy Hankins <nowan@nowan.org>
7 -- Time-stamp: <2005-06-28 15:55:31 Jeremy Hankins>
9 -- statusd_dgs.lua: Check for moves waiting on www.dragongoserver.net
11 -- This monitor will check your status page on www.dragongoserver.net
12 -- for games waiting on a move. Simply add %dgs to the statusd
13 -- template, and set a login and password.
15 -- In all honesty, I'd be surprised if there are more than a couple of
16 -- people who might use this script -- the intersection of go players
17 -- (and dgs users at that) and ion users can't be that large.
19 -- TO USE: Put %dgs in the template in cfg_statusbar.lua (e.g.,
20 -- "dgs:% %dgs") and set the login and password. Something like:
24 -- password = "ABCxyz",
27 -- in mod_statusbar.launch_statusd.
29 -- NOTE: the wget command is used to fetch the status page and the
30 -- account info is passed on the command line. This means that you need
31 -- wget for this monitor to work, and that your account info (including
32 -- password) will be available on your local system via ps. If that
33 -- concerns you, don't use this script -- or provide a patch. :)
35 -- BUG: Occasionally get_moves returns nil because it gets no output
36 -- from the wget. This is either because I'm not using io.popen()
37 -- properly (I don't have docs for it) or, perhaps, a bug elsewhere.
38 -- When this happens you'll see a ? (with the critical hint set) instead
39 -- of a number for waiting moves.
41 if not statusd_dgs
then
43 -- These should be set in cfg_statusbar:
47 interval
= 20*60*1000, -- update every 20 minutes,
48 retry
= 60 * 1000, -- on error, retry in a minute
50 -- These shouldn't need to be changed.
51 login_url
= "http://www.dragongoserver.net/login.php",
52 --qick_url = "http://www.dragongoserver.net/quick_status.php"
59 local settings
= table.join(statusd
.get_config(meter
), statusd_dgs
)
61 local check_cmd
= "wget -qO - --post-data 'userid="..settings
.login
62 .."&passwd="..settings
.password
.."' '"..settings
.login_url
.."'"
64 if not settings
.login
or not settings
.password
then
65 statusd
.warn("You need to set a login and password.")
72 local function get_moves()
73 local f
= io
.popen(check_cmd
, 'r')
74 if not f
then return nil end
76 local output
= f
:read('*a')
78 if string.len(output
) == 0 then return nil end
80 local s
, e
, count
= 0, 0, 0
82 s
, e
= string.find(output
, 'href="game%.php%?gid=%d+"', e
)
83 if s
then count
= count
+ 1 end
92 local function update()
93 local moves
= get_moves()
97 statusd
.inform(meter
.."_hint", "important")
99 statusd
.inform(meter
.."_hint", "normal")
101 statusd
.inform(meter
, tostring(moves
))
102 timer
:set(settings
.interval
, update
)
104 statusd
.inform(meter
.."_hint", "critical")
105 statusd
.inform(meter
, "?")
106 timer
:set(settings
.retry
, update
)
111 timer
= statusd
.create_timer()