Skip to content

Commit b0bbfa7

Browse files
clouserwflashcode
authored andcommitted
autopong.py 0.2: add public channel replies and a configurable response
1 parent 73d44ab commit b0bbfa7

File tree

1 file changed

+28
-9
lines changed

1 file changed

+28
-9
lines changed

python/autopong.py

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,30 +26,49 @@
2626
#
2727
# History:
2828
#
29-
# 2013-01-11, Wil Clouser <wclouser@mozilla.com>:
29+
# 2013-01-11, Wil Clouser <clouserw@micropipes.com>:
3030
# 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+
#
3134

3235
SCRIPT_NAME = "autopong"
3336
SCRIPT_AUTHOR = "Wil Clouser <[email protected]>"
34-
SCRIPT_VERSION = "0.1"
37+
SCRIPT_VERSION = "0.2"
3538
SCRIPT_LICENSE = "MIT"
3639
SCRIPT_DESC = "Auto-replies to 'ping' queries"
3740

3841
import_ok = True
3942

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+
4048
try:
4149
import weechat as w
4250
except:
4351
print "Script must be run under weechat. http://www.weechat.org"
4452
import_ok = False
4553

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+
5064
return w.WEECHAT_RC_OK
5165

5266
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

Comments
 (0)