This file is indexed.

/usr/share/weechat/python/postpone.py is in weechat-scripts 20140928-1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
# -*- coding: utf-8 -*-
#
# Copyright (c) 2010 by Alexander Schremmer <alex@alexanderweb.de>
#
# 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/>.
#

#
# (this script requires WeeChat 0.3.0 or newer)
#
# History:
# 2013-11-08, Stefan Huber <shuber@sthu.org>
#   version 0.2.2: add match_prefix setting, recall timestamp of message
# 2012-12-29, Stefan Huber <shuber@sthu.org>
#   version 0.2.1: fix channel determination in join_cb
# 2010-05-20, Alexander Schremmer <alex@alexanderweb.de>
#   version 0.2: removed InfoList code
# 2010-05-15, Alexander Schremmer <alex@alexanderweb.de>
#   version 0.1: initial release

import weechat as w
import re
from datetime import datetime
from time import strftime

SCRIPT_NAME    = "postpone"
SCRIPT_AUTHOR  = "Alexander Schremmer <alex@alexanderweb.de>"
SCRIPT_VERSION = "0.2.2"
SCRIPT_LICENSE = "GPL3"
SCRIPT_DESC    = "Postpones written messages for later dispatching if target nick is not on channel"

postpone_data = {}

settings = {
        'match_prefix': ('', 'Postpone message if prefix before "nick:" is matched.')
}


def join_cb(data, signal, signal_data):
    server = signal.split(',')[0] # EFNet,irc_in_JOIN
    channel = re.match('.* JOIN :?(?P<channel>.+)$', signal_data).groups()[0]
    nick = re.match(':(?P<nick>.+)!', signal_data).groups()[0].lower()
    buffer = w.buffer_search("", "%s.%s" % (server, channel))
    if server in postpone_data and channel in postpone_data[server] and\
            nick in postpone_data[server][channel]:
        messages = postpone_data[server][channel][nick]
        for time, msg in messages:
            tstr = strftime("%Y-%m-%d %H:%M:%S", time.timetuple())
            w.command(buffer, msg + " (This message has been postponed on " + tstr + ".)")
        messages[:] = []
    return w.WEECHAT_RC_OK

def channel_has_nick(server, channel, nick):
    buffer = w.buffer_search("", "%s.%s" % (server, channel))
    return bool(w.nicklist_search_nick(buffer, "", nick))

def command_run_input(data, buffer, command):
    """ Function called when a command "/input xxxx" is run """
    if command == "/input return": # As in enter was pressed.
        input_s = w.buffer_get_string(buffer, 'input')
        server = w.buffer_get_string(buffer, 'localvar_server')
        channel = w.buffer_get_string(buffer, 'localvar_channel')
        match_prefix = w.config_get_plugin('match_prefix')

        match = re.match(match_prefix + r'([\w-]+?): (.*)$', input_s)
        if match:
            nick, message = match.groups()
            if not channel_has_nick(server, channel, nick):
                w.prnt(buffer, "| Enqueued message for %s: %s" % (nick, message))
                save = datetime.now(), nick + ": " + message
                postpone_data.setdefault(server, {}).setdefault(channel,
                        {}).setdefault(nick.lower(), []).append(save)
                w.buffer_set(buffer, 'input', "")
                # XXX why doesn't this work? i want to have the typed text
                # in the history
                #history_list = w.infolist_get("history", buffer, "")
                #history_item = w.infolist_new_item(history_list)
                #w.infolist_new_var_string(history_item, "text", input_s)
    return w.WEECHAT_RC_OK


if w.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE,
                    SCRIPT_DESC, "", ""):

    version = w.info_get('version_number', '') or 0
    for option, default_desc in settings.iteritems():
        if not w.config_is_set_plugin(option):
            w.config_set_plugin(option, default_desc[0])
        if int(version) >= 0x00030500:
            w.config_set_desc_plugin(option, default_desc[1])

    w.hook_command_run("/input return", "command_run_input", "")
    w.hook_signal('*,irc_in2_join', 'join_cb', '')