Exemplo n.º 1
0
def prepare_and_send_signal(buffer, nick, action):
    global PENDING_ACTIONS
    # needed to get the server buffer (irc.server.#somechannel)
    buffer_info = weechat.buffer_get_string(buffer, "full_name").split(".")
    if buffer_info.pop(0) != "irc":
        log_warning("aban can only be used in irc channel buffers")
        return weechat.WEECHAT_RC_ERROR

    server, channel = buffer_info
    if not channel.startswith("#"):
        log_warning("aban can only be used in irc channel buffers")
        return weechat.WEECHAT_RC_ERROR
    if weechat.info_get('irc_nick', server) == nick:
        log_warning(f"You probably do not want to {action} yourself.")
        return weechat.WEECHAT_RC_ERROR
    # see known issues section in the README
    PENDING_ACTIONS[nick] = {
        "server": server,
        "channel": channel,
        "action": action
    }

    weechat.hook_hsignal_send("irc_redirect_command", {
        "server": server,
        "pattern": "who",
        "signal": "action"
    })
    weechat.hook_signal_send('irc_input_send',
                             weechat.WEECHAT_HOOK_SIGNAL_STRING,
                             f"{server};;2;;/who {nick} %a")

    # to please pylint
    return weechat.WEECHAT_RC_OK
Exemplo n.º 2
0
def owl_init(buff_ptr):
    # get more info about this buffer
    buff_name = weechat.buffer_get_string(buff_ptr, 'name')
    buff_server = weechat.buffer_get_string(buff_ptr, 'localvar_server')
    buff_channel = weechat.buffer_get_string(buff_ptr, 'localvar_channel')
    if DEBUG:
        weechat.prnt('', 'ptr:{} name:{}\n'.format(buff_ptr, buff_name))

    # is owl active in this channel?
    if (buff_name in owl_on_buffers
            or (buff_name not in owl_off_buffers and owl_default_on)):
        # analyze nicks in the buffer
        iln = weechat.infolist_get('irc_nick', '',
                                   '{},{}'.format(buff_server, buff_channel))
        while weechat.infolist_next(iln):
            nick_ptr = weechat.infolist_pointer(iln, 'pointer')
            nick = weechat.infolist_string(iln, 'name')
            user_host = weechat.infolist_string(iln, 'host')
            # should we use /userhost to get hostname?
            if len(user_host) == 0:
                # track nick-buffer relationship
                if buff_server in owl_state['nick_buffs']:
                    if nick in owl_state['nick_buffs'][buff_server]:
                        owl_state['nick_buffs'][buff_server][nick].append(
                            buff_name)
                    else:
                        owl_state['nick_buffs'][buff_server][nick] = [
                            buff_name
                        ]
                else:
                    owl_state['nick_buffs'][buff_server] = {nick: [buff_name]}
                # do hookie things
                weechat.hook_hsignal_send(
                    'irc_redirect_command', {
                        'server': buff_server,
                        'pattern': 'userhost',
                        'signal': 'owl',
                        'string': nick,
                        'timeout': owl_settings['userhost_timeout'],
                    })
                weechat.hook_signal_send(
                    'irc_input_send', weechat.WEECHAT_HOOK_SIGNAL_STRING,
                    '{};;;;/userhost {}'.format(buff_server, nick))
                user_host = '****PENDING****'
            else:
                user, host = user_host.split('@')
                owl_analyze(nick, user, host, buff_name, DIR_IN)
            if DEBUG:
                weechat.prnt('', '  {}!{}\n'.format(nick, user_host))
        weechat.infolist_free(iln)

    return weechat.WEECHAT_RC_OK
Exemplo n.º 3
0
def search_cb(data, buffer, args):
    w.hook_hsignal("irc_redirection_search_whois", "search_whois_cb", "")
    w.hook_hsignal_send(
        "irc_redirect_command",
        {
            "server": w.buffer_get_string(buffer, "name").split(".")[0],  # <- server name
            "pattern": "whois",
            "signal": "search",
            "string": "",
        },
    )
    w.command(w.current_buffer(), "/whois {}".format(args))
    return w.WEECHAT_RC_OK
Exemplo n.º 4
0
def ison(bufpointer, servername, nick, nicklist):
    command = ISON % ' '.join(nicklist)
    weechat.hook_hsignal_send(
        'irc_redirect_command', {
            'server': servername,
            'pattern': 'ison',
            'signal': SCRIPT_NAME,
            'count': '1',
            'string': servername,
            'timeout': OPTIONS['timeout'],
            'cmd_filter': ''
        })
    weechat.hook_signal_send('irc_input_send',
                             weechat.WEECHAT_HOOK_SIGNAL_STRING,
                             '%s;;;;%s' % (servername, command))
Exemplo n.º 5
0
def ison(bufpointer, servername, nick, nicklist):
    command = ISON % " ".join(nicklist)
    weechat.hook_hsignal_send(
        "irc_redirect_command",
        {
            "server": servername,
            "pattern": "ison",
            "signal": SCRIPT_NAME,
            "count": "1",
            "string": servername,
            "timeout": OPTIONS["timeout"],
            "cmd_filter": "",
        },
    )
    weechat.hook_signal_send("irc_input_send", weechat.WEECHAT_HOOK_SIGNAL_STRING, "%s;;;;%s" % (servername, command))
Exemplo n.º 6
0
def stalker_cmd(data, buffer, args):
    args = args.strip()
    if ' ' in args:
        return w.WEECHAT_RC_ERROR

    server = w.buffer_get_string(buffer, "localvar_server")

    # it's a hostname
    if '@' in args:
        stalker_cmd_bottom(buffer, server, args.split('@')[-1])
    else:
        # Check if the user's in our database already.
        cur = conn.cursor()
        cur.execute('SELECT host_id FROM nicks WHERE nick = "%s"' % (args))
        rows = cur.fetchall()
        cur.close()

        if len(rows):
            host_id = rows[0][0]
            cur = conn.cursor()
            cur.execute('SELECT host FROM hosts WHERE id = %d' % host_id)
            hostnames = [c[0] for c in cur.fetchall()]
            for hostname in hostnames:
                who_cache_update(args, server, hostname)
            stalker_cmd_bottom(buffer, server, hostnames)
            cur.close()
        else:
            if (args + server) in who_cache:
                stalker_cmd_bottom(buffer, server, who_cache[args + server])
            else:
                w.hook_hsignal ("irc_redirection_stalker_who", "stalker_cmd_cb", buffer)
                w.hook_hsignal_send("irc_redirect_command",
                                          { "server": server, "pattern": "who", "signal": "stalker" })
                w.hook_signal_send("irc_input_send", w.WEECHAT_HOOK_SIGNAL_STRING,
                                         ("%s;;2;;/who %s") % (server, args))
        
    return w.WEECHAT_RC_OK
Exemplo n.º 7
0
def ison(servername,nick,nicklist):
    command = ISON % ' '.join(nicklist)
    debug_print("Checking nicks on server %s with command: %s" % (servername, command) )
    weechat.hook_hsignal_send('irc_redirect_command',
                                  { 'server': servername, 'pattern': 'ison', 'signal': SCRIPT_NAME, 'count': '1', 'string': servername, 'timeout': OPTIONS['timeout'], 'cmd_filter': '' })
    weechat.hook_signal_send('irc_input_send', weechat.WEECHAT_HOOK_SIGNAL_STRING, '%s;;;;%s' % (servername,command))
Exemplo n.º 8
0
def buffer_open_full_name(full_name, noswitch=None):
    hashtable = {"full_name": full_name}
    if noswitch is not None:
        hashtable["noswitch"] = str(int(noswitch))  # must be str for API

    weechat.hook_hsignal_send("buffer_open_full_name", hashtable)