|
26 | 26 | #
|
27 | 27 | # History:
|
28 | 28 | #
|
29 |
| -# 2013-01-11, Wil Clouser <wclouser@mozilla.com>: |
| 29 | +# 2013-01-11, Wil Clouser <clouserw@micropipes.com>: |
30 | 30 | # v0.1: Initial release
|
| 31 | +# 2015-10-30, Stanislav Ochotnicky <[email protected]> |
| 32 | +# v0.2: Reply to public pings as well and add more informative pong |
| 33 | +# |
31 | 34 |
|
32 | 35 | SCRIPT_NAME = "autopong"
|
33 | 36 | SCRIPT_AUTHOR = "Wil Clouser <[email protected]>"
|
34 |
| -SCRIPT_VERSION = "0.1" |
| 37 | +SCRIPT_VERSION = "0.2" |
35 | 38 | SCRIPT_LICENSE = "MIT"
|
36 | 39 | SCRIPT_DESC = "Auto-replies to 'ping' queries"
|
37 | 40 |
|
38 | 41 | import_ok = True
|
39 | 42 |
|
| 43 | +# This can be changed with `/set plugins.var.python.autopong.reply_text` |
| 44 | +defaults = { |
| 45 | + "reply_text": "pong (https://blogs.gnome.org/markmc/2014/02/20/naked-pings/)" |
| 46 | +} |
| 47 | + |
40 | 48 | try:
|
41 | 49 | import weechat as w
|
42 | 50 | except:
|
43 | 51 | print "Script must be run under weechat. http://www.weechat.org"
|
44 | 52 | import_ok = False
|
45 | 53 |
|
46 |
| -def privmsg(data, buffer, date, tags, displayed, is_hilight, prefix, msg): |
47 |
| - if w.buffer_get_string(buffer, "localvar_type") == "private": |
48 |
| - if msg == "ping": |
49 |
| - w.command(buffer, "pong") |
| 54 | + |
| 55 | +def msg_cb(data, buffer, date, tags, displayed, is_hilight, prefix, msg): |
| 56 | + reply = w.config_get_plugin('reply_text') |
| 57 | + if not w.buffer_get_string(buffer, "localvar_type") == "private": |
| 58 | + reply = prefix + ": " + reply |
| 59 | + if is_hilight and msg.endswith('ping'): |
| 60 | + w.command(buffer, reply) |
| 61 | + elif msg == 'ping': |
| 62 | + w.command(buffer, reply) |
| 63 | + |
50 | 64 | return w.WEECHAT_RC_OK
|
51 | 65 |
|
52 | 66 | if __name__ == "__main__" and import_ok:
|
53 |
| - if w.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, |
54 |
| - SCRIPT_DESC, "", ""): |
55 |
| - w.hook_print("", "", "", 1, "privmsg", "") |
| 67 | + if w.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, |
| 68 | + SCRIPT_DESC, "", ""): |
| 69 | + for k, v in defaults.iteritems(): |
| 70 | + if not w.config_is_set_plugin(k): |
| 71 | + w.config_set_plugin(k, v) |
| 72 | + |
| 73 | + w.hook_print("", "notify_message", "ping", 1, "msg_cb", "") |
| 74 | + w.hook_print("", "notify_private", "ping", 1, "msg_cb", "") |
0 commit comments