Include notionflux in the main repo instead of its own submodule
[notion/jeffpc.git] / contrib / statusd / statusd_dgs.lua
blob3103f56fa77f8ef8d37fb92d3d95a1f8a48f9e47
1 -- Authors: Jeremy Hankins <nowan@nowan.org>
2 -- License: Unknown
3 -- Last Changed: 2005-06-28
4 --
5 -- By Jeremy Hankins <nowan@nowan.org>
6 --
7 -- Time-stamp: <2005-06-28 15:55:31 Jeremy Hankins>
8 --
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:
22 -- dgs={
23 -- login = "mylogin",
24 -- password = "ABCxyz",
25 -- },
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
42 statusd_dgs = {
43 -- These should be set in cfg_statusbar:
44 --login = "",
45 --password = "",
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"
54 end
56 local timer
57 local meter = "dgs"
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.")
66 return
67 end
69 --
70 -- get the move count
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')
77 f:close()
78 if string.len(output) == 0 then return nil end
80 local s, e, count = 0, 0, 0
81 repeat
82 s, e = string.find(output, 'href="game%.php%?gid=%d+"', e)
83 if s then count = count + 1 end
84 until not s
86 return count
87 end
90 -- update the meter
92 local function update()
93 local moves = get_moves()
95 if moves then
96 if moves > 0 then
97 statusd.inform(meter.."_hint", "important")
98 else
99 statusd.inform(meter.."_hint", "normal")
101 statusd.inform(meter, tostring(moves))
102 timer:set(settings.interval, update)
103 else
104 statusd.inform(meter.."_hint", "critical")
105 statusd.inform(meter, "?")
106 timer:set(settings.retry, update)
111 timer = statusd.create_timer()
112 update()