65 lines
2.3 KiB
Python
65 lines
2.3 KiB
Python
# -*- coding: utf-8 -*-
|
|
#
|
|
# Copyright (C) 2013 Brian S. Stephan <bss@incorporeal.org>
|
|
#
|
|
# This program is free software; you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation; either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
#
|
|
# Convenience commands for appending/prepending text to the channel topic
|
|
# or other buffer title.
|
|
#
|
|
# 2013-02-16 v0.1
|
|
# initial script, /topicpre
|
|
|
|
try:
|
|
import weechat
|
|
except:
|
|
print("This script must be run under WeeChat.")
|
|
print("Get WeeChat now at: http://www.weechat.org/")
|
|
|
|
SCRIPT_NAME = "topicutil"
|
|
SCRIPT_AUTHOR = "Brian S. Stephan <bss@incorporeal.org>"
|
|
SCRIPT_VERSION = "0.1"
|
|
SCRIPT_LICENSE = "GPL3"
|
|
SCRIPT_DESC = "Easily add text to the start of a channel topic"
|
|
|
|
settings = {
|
|
'splitter': " | ",
|
|
}
|
|
|
|
def topic_prepend_cb(data, buffer, args):
|
|
"""Prepend some text to the current buffer's topic."""
|
|
|
|
if args:
|
|
splitter = weechat.config_get_plugin('splitter')
|
|
topic = weechat.buffer_get_string(buffer, 'title')
|
|
if topic != "":
|
|
new_topic = "{0:s}{1:s}{2:s}".format(''.join(args), splitter,
|
|
topic)
|
|
else:
|
|
new_topic = "{0:s}".format(' '.join(args))
|
|
|
|
weechat.command(buffer, '/topic {0:s}'.format(new_topic))
|
|
return weechat.WEECHAT_RC_OK
|
|
|
|
if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE,
|
|
SCRIPT_DESC, "", ""):
|
|
# initialize default settings
|
|
for option, default in settings.items():
|
|
if weechat.config_get_plugin(option) == "":
|
|
weechat.config_set_plugin(option, default)
|
|
|
|
hook = weechat.hook_command("topicpre", topic_prepend_cb.__doc__,
|
|
"<text>", "text: data to add to topic",
|
|
'', 'topic_prepend_cb', '')
|