mirror of https://github.com/SeanOMik/znc-push.git
Implement notification uri keyword expansion
Resolves #198. Four keywords are supported: context, nick, datetime, and unixtime.
This commit is contained in:
parent
df891c0c69
commit
94ad55784e
14
README.md
14
README.md
|
@ -202,7 +202,18 @@ Configuration
|
||||||
* `message_url = ""`
|
* `message_url = ""`
|
||||||
|
|
||||||
URI that will be sent with the notification to Notifo. This could be a web address or a
|
URI that will be sent with the notification to Notifo. This could be a web address or a
|
||||||
local scheme to access a mobile application.
|
local scheme to access a mobile application. Keyword expansion is performed on this
|
||||||
|
value each time a notification is sent; the following keywords will be replaced with
|
||||||
|
the appropriate value:
|
||||||
|
|
||||||
|
* `{context}`: the channel or query window context
|
||||||
|
* `{nick}`: the nick that sent the message
|
||||||
|
* `{datetime}`: [ISO 8601][] date string, in server-local time
|
||||||
|
* `{unixtime}`: unix-style integer timestamp
|
||||||
|
|
||||||
|
As an example, a value of "http://domain/{context}/{datetime}" would be expanded to
|
||||||
|
something similar to "http://domain/#channel/2011-03-09 14:25:09", or
|
||||||
|
"http://domain/{nick}/{unixtime}" to "http://domain/somenick/1299685136".
|
||||||
|
|
||||||
### Advanced
|
### Advanced
|
||||||
|
|
||||||
|
@ -256,5 +267,6 @@ This project is licensed under the MIT license. See the `LICENSE` file for deta
|
||||||
[mantis]: http://leetcode.net/mantis
|
[mantis]: http://leetcode.net/mantis
|
||||||
[Notifo]: http://notifo.com "Notifo, Mobile Notifications for Everything"
|
[Notifo]: http://notifo.com "Notifo, Mobile Notifications for Everything"
|
||||||
[ZNC]: http://en.znc.in "ZNC, an advanced IRC bouncer"
|
[ZNC]: http://en.znc.in "ZNC, an advanced IRC bouncer"
|
||||||
|
[ISO 8601]: http://en.wikipedia.org/wiki/ISO_8601 "ISO 8601 Date Format"
|
||||||
|
|
||||||
<!-- vim:set ft= expandtab tabstop=4 shiftwidth=4: -->
|
<!-- vim:set ft= expandtab tabstop=4 shiftwidth=4: -->
|
||||||
|
|
20
notifo.cpp
20
notifo.cpp
|
@ -167,7 +167,7 @@ class CNotifoMod : public CModule
|
||||||
* @param title Message title to use
|
* @param title Message title to use
|
||||||
* @param context Channel or nick context
|
* @param context Channel or nick context
|
||||||
*/
|
*/
|
||||||
void send_message(const CString& message, const CString& title="New Message", const CString& context="")
|
void send_message(const CString& message, const CString& title="New Message", const CString& context="*notifo", const CNick& nick=CString("*notifo"))
|
||||||
{
|
{
|
||||||
// Set the last notification time
|
// Set the last notification time
|
||||||
last_notification_time[context] = time(NULL);
|
last_notification_time[context] = time(NULL);
|
||||||
|
@ -180,12 +180,28 @@ class CNotifoMod : public CModule
|
||||||
short_message = message.Ellipsize(message_length);
|
short_message = message.Ellipsize(message_length);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Generate an ISO8601 date string
|
||||||
|
time_t rawtime;
|
||||||
|
struct tm * timeinfo;
|
||||||
|
time(&rawtime);
|
||||||
|
timeinfo = localtime(&rawtime);
|
||||||
|
char iso8601 [20];
|
||||||
|
strftime(iso8601, 20, "%Y-%m-%d %H:%M:%S", timeinfo);
|
||||||
|
|
||||||
|
// URI string replacements
|
||||||
|
MCString replace;
|
||||||
|
replace["{context}"] = context;
|
||||||
|
replace["{nick}"] = nick.GetNick();
|
||||||
|
replace["{datetime}"] = CString(iso8601);
|
||||||
|
replace["{unixtime}"] = CString(time(NULL));
|
||||||
|
CString uri = expand(options["message_uri"], replace);
|
||||||
|
|
||||||
// POST body parameters for the request
|
// POST body parameters for the request
|
||||||
CString post = "to=" + urlencode(options["username"]);
|
CString post = "to=" + urlencode(options["username"]);
|
||||||
post += "&msg=" + urlencode(short_message);
|
post += "&msg=" + urlencode(short_message);
|
||||||
post += "&label=" + urlencode(app);
|
post += "&label=" + urlencode(app);
|
||||||
post += "&title=" + urlencode(title);
|
post += "&title=" + urlencode(title);
|
||||||
post += "&uri=" + urlencode(options["message_uri"]);
|
post += "&uri=" + urlencode(uri);
|
||||||
|
|
||||||
// Request headers and POST body
|
// Request headers and POST body
|
||||||
CString request = "POST " + notifo_url + " HTTP/1.1" + crlf;
|
CString request = "POST " + notifo_url + " HTTP/1.1" + crlf;
|
||||||
|
|
Loading…
Reference in New Issue