Exemplo n.º 1
0
def switch_current_buffer():
    """Save current buffer and ensure that it's visible, then if the
    buffer is elegible to be hidden, we add it to the list of the buffers
    to be hidden after a delay
    """
    global CURRENT_BUFFER
    global CURRENT_BUFFER_TIMER_HOOK

    previous_buffer = CURRENT_BUFFER
    CURRENT_BUFFER = weechat.current_buffer()

    if previous_buffer == CURRENT_BUFFER:
        return

    if weechat.buffer_get_integer(CURRENT_BUFFER, "hidden") == 1:
        weechat.buffer_set(CURRENT_BUFFER, "hidden", "0")

    if weechat.config_get_plugin("keep_open") != "off":
        if CURRENT_BUFFER_TIMER_HOOK is not None:
            weechat.unhook(CURRENT_BUFFER_TIMER_HOOK)
            CURRENT_BUFFER_TIMER_HOOK = None
            maybe_hide_buffer(previous_buffer)
        else:
            keep_alive_buffer(previous_buffer)

        CURRENT_BUFFER_TIMER_HOOK = weechat.hook_timer(
            MINIMUM_BUFFER_LIFE, 0, 1,
            "on_current_buffer_is_still_active_timeout", "")
    else:
        maybe_hide_buffer(previous_buffer)
Exemplo n.º 2
0
def set_localvars(input):
    buffers = weechat.infolist_get("buffer", "", "*")
    while weechat.infolist_next(buffers):
        pointer = weechat.infolist_pointer(buffers, "pointer")
        name = weechat.infolist_string(buffers, "short_name")

        localvar = None
        localvar_hidden = None
        if active:
            if input in name:
                localvar = "1"
                localvar_hidden = "0"
            else:
                localvar = "0"
                localvar_hidden = "1"

        buffer_set_localvar(pointer, SCRIPT_LOCALVAR, localvar)
        buffer_set_localvar(pointer, SCRIPT_LOCALVAR_HIDDEN, localvar_hidden)

    weechat.infolist_free(buffers)

    weechat.bar_item_update("buflist")

    global timer
    if active:
        # update_buflist_buffers(None, None)
        if timer:
            weechat.unhook(timer)
        timer = weechat.hook_timer(1, 0, 1, "update_buflist_buffers", "")
Exemplo n.º 3
0
def unhook_timer():
    global hooks
    if hooks["timer"] != "":
        weechat.bar_item_remove(hooks["bar_item"])
        weechat.unhook(hooks["timer"])
        hooks["timer"] = ""
        hooks["bar_item"]
Exemplo n.º 4
0
def load_config(data=None, option=None, value=None):
    """
    Load configuration options and (re)register hook_timer to clear old
    messages based on the current value of check_every.  If check_every is 0
    then messages are never cleared.
    """

    # On initial load set any unset options to the defaults.
    if not option:
        for option, default in settings.iteritems():
            if not weechat.config_is_set_plugin(option):
                weechat.config_set_plugin(option, default)

    if not option or option.endswith('check_every'):
        # If hook_timer for clearing old messages is set already, clear it.
        old_hook = globals().get('CLEAR_HOOK', None)
        if old_hook is not None:
            weechat.unhook(old_hook)

        # Register hook_timer to clear old messages.
        check_every = get_option_int('check_every') * 1000
        if check_every:
            globals()['CLEAR_HOOK'] = weechat.hook_timer(
                    check_every, 0, 0, 'clear_messages_cb', '')

    return weechat.WEECHAT_RC_OK
Exemplo n.º 5
0
def unhook_timer():
    global hooks
    if hooks["timer"] != "":
        weechat.bar_item_remove(hooks["bar_item"])
        weechat.unhook(hooks["timer"])
        hooks["timer"] = ""
        hooks["bar_item"]
Exemplo n.º 6
0
def unhook(hook):
    global HOOKS

    if hook in HOOKS:
        print_debug('Unhooking %s' % hook)
        weechat.unhook(HOOKS[hook])
        del HOOKS[hook]
Exemplo n.º 7
0
def styurl_config_cb(data, option, value):
    """Callback called when a script option is changed."""
    global styurl_settings, line_hook

    pos = option.rfind('.')
    if pos > 0:
        name = option[pos + 1:]
        if name in styurl_settings:
            # Changing the buffer target requires us to re-hook to prevent
            # obsolete buffer types from getting styled
            if name == "buffer_type":
                if value in ("free", "formatted", "*"):
                    w.unhook(line_hook)
                    line_hook = w.hook_line(value, "", "", "styurl_line_cb",
                                            "")
                else:
                    # Don't change buffer type if it is invalid
                    w.prnt(
                        "", SCRIPT_NAME + ": Invalid buffer type: '%s', "
                        "not changing." % value)
                    w.config_set_plugin(name, styurl_settings[name])
                    return w.WEECHAT_RC_ERROR

            styurl_settings[name] = value

    return w.WEECHAT_RC_OK
Exemplo n.º 8
0
def unhook(hooks):
    """Unhook something hooked by this script."""
    global cmdhelp_hooks
    for hook in hooks:
        if cmdhelp_hooks[hook]:
            weechat.unhook(cmdhelp_hooks[hook])
            cmdhelp_hooks[hook] = ''
Exemplo n.º 9
0
def switch_current_buffer():
    """Save current buffer and ensure that it's visible, then if the
    buffer is elegible to be hidden, we add it to the list of the buffers
    to be hidden after a delay
    """
    global CURRENT_BUFFER
    global CURRENT_BUFFER_TIMER_HOOK

    previous_buffer = CURRENT_BUFFER
    CURRENT_BUFFER = weechat.current_buffer()

    if previous_buffer == CURRENT_BUFFER:
        return

    if weechat.buffer_get_integer(CURRENT_BUFFER, "hidden") == 1:
        weechat.buffer_set(CURRENT_BUFFER, "hidden", "0")

    if weechat.config_get_plugin("keep_open") != "off":
        if CURRENT_BUFFER_TIMER_HOOK is not None:
            weechat.unhook(CURRENT_BUFFER_TIMER_HOOK)
            CURRENT_BUFFER_TIMER_HOOK = None
            maybe_hide_buffer(previous_buffer)
        else:
            keep_alive_buffer(previous_buffer)

        CURRENT_BUFFER_TIMER_HOOK = weechat.hook_timer(MINIMUM_BUFFER_LIFE, 0, 1,
            "on_current_buffer_is_still_active_timeout", "")
    else:
        maybe_hide_buffer(previous_buffer)
Exemplo n.º 10
0
def set_timer():
    '''Update timer hook with new interval.'''
    global TIMER
    if TIMER:
        w.unhook(TIMER)
    TIMER = w.hook_timer(int(w.config_get_plugin('interval')) * 1000, 0, 0,
                         'screen_away_timer_cb', '')
Exemplo n.º 11
0
def update_hook(*args):
    global the_print_hook
    if the_print_hook:
        weechat.unhook(the_print_hook)
    value = weechat.config_get_plugin('tags')
    the_print_hook = weechat.hook_print('', value, '', 0, 'on_print', '')
    return weechat.WEECHAT_RC_OK
Exemplo n.º 12
0
def set_timer():
    # Update timer hook with new interval. 0 means deactivated
    global TIMER
    if TIMER:
        weechat.unhook(TIMER)
    if int(weechat.config_get_plugin('interval')) >= 1:
        TIMER = weechat.hook_timer(int(weechat.config_get_plugin('interval')) * 1000,0, 0, "timer_dummy_cb", '')
Exemplo n.º 13
0
def unhook_all():
    global irc_pv_hook, irc_out_hook
    if irc_pv_hook:
        weechat.unhook(irc_pv_hook)
    if irc_out_hook:
        weechat.unhook(irc_out_hook)
    irc_pv_hook = irc_out_hook = ""
Exemplo n.º 14
0
def set_timer():
    '''Update timer hook with new interval'''

    global TIMER
    if TIMER:
        weechat.unhook(TIMER)
    TIMER = weechat.hook_timer(INTERVAL, 0, 0, "timer_cb", '')
Exemplo n.º 15
0
def spotify_print_cb(data, buffer, time, tags, displayed, highlight, prefix, message):

    global spotify_hook_process, buffer_name

    msg_buffer_name = get_buffer_name(buffer)
    # Skip ignored buffers
    found = False
    for active_buffer in weechat.config_get_plugin('buffers').split(','):
        if active_buffer.lower() == msg_buffer_name.lower():
            found = True
            buffer_name = msg_buffer_name
            break

    if not found:
        return weechat.WEECHAT_RC_OK

       
    for type, spotify_id in get_spotify_ids(message):
        url = '%s?uri=spotify:%s:%s' %(gateway, type, spotify_id)
        if spotify_hook_process != "":
            weechat.unhook(spotify_hook_process)
            spotify_hook_process = ""
        python2_bin = weechat.info_get("python2_bin", "") or "python"
        spotify_hook_process = weechat.hook_process(
            python2_bin + " -c \"import urllib2; print urllib2.urlopen('" + url + "').read()\"",
            30 * 1000, "spotify_process_cb", "")

    return weechat.WEECHAT_RC_OK
Exemplo n.º 16
0
def styurl_unload_cb():
    """Callback called when the script is unloaded."""
    global line_hook

    w.unhook(line_hook)
    del line_hook
    return w.WEECHAT_RC_OK
Exemplo n.º 17
0
def remove_hooks():
    global HOOK

    for k in HOOK:
        if HOOK[k] != '':
            weechat.unhook(HOOK[k])
            HOOK[k] = ''
Exemplo n.º 18
0
def wg_update_cache():
    """ Download list of scripts and update local cache. """
    global wg_config_option, wg_hook_process, wg_stdout
    # get data from website, via hook_process
    if wg_hook_process["update"] != "":
        weechat.unhook(wg_hook_process["update"])
        wg_hook_process["update"] = ""
    weechat.prnt("", "%s: downloading list of scripts..." % SCRIPT_NAME)
    wg_stdout["update"] = ""
    wg_config_create_dir()
    url = weechat.config_string(wg_config_option["scripts_url"])
    filename = wg_config_get_cache_filename()
    wg_hook_process["update"] = weechat.hook_process(
        "python -c \"import urllib, urllib2\n"
        "req = urllib2.Request('" + url + "')\n"
        "try:\n"
        "    response = urllib2.urlopen(req)\n"
        "    file = open('" + filename + "', 'w')\n"
        "    file.write(response.read())\n"
        "    response.close()\n"
        "    file.close()\n"
        "except urllib2.URLError, e:\n"
        "    print 'error:%s' % e.code\n"
        "\"",
        TIMEOUT_UPDATE, "wg_process_update_cb", "")
Exemplo n.º 19
0
def set_timer():
    """Update timer hook with new interval"""

    global TIMER
    if TIMER:
        w.unhook(TIMER)
    TIMER = w.hook_timer(int(w.config_get_plugin("interval")) * 1000, 0, 0, "screen_away_timer_cb", "")
Exemplo n.º 20
0
def unhook(hooks):
    """Unhook something hooked by this script."""
    global cmdhelp_hooks
    for hook in hooks:
        if cmdhelp_hooks[hook]:
            weechat.unhook(cmdhelp_hooks[hook])
            cmdhelp_hooks[hook] = ''
Exemplo n.º 21
0
def unhook(hook):
    global HOOKS

    if hook in HOOKS:
        print_debug('Unhooking %s' % hook)
        weechat.unhook(HOOKS[hook])
        del HOOKS[hook]
Exemplo n.º 22
0
def spotify_print_cb(data, buffer, time, tags, displayed, highlight, prefix,
                     message):

    global spotify_hook_process, buffer_name

    msg_buffer_name = get_buffer_name(buffer)
    # Skip ignored buffers
    found = False
    for active_buffer in weechat.config_get_plugin('buffers').split(','):
        if active_buffer.lower() == msg_buffer_name.lower():
            found = True
            buffer_name = msg_buffer_name
            break

    if not found:
        return weechat.WEECHAT_RC_OK

    for type, spotify_id in get_spotify_ids(message):
        url = '%s?uri=spotify:%s:%s' % (gateway, type, spotify_id)
        if spotify_hook_process != "":
            weechat.unhook(spotify_hook_process)
            spotify_hook_process = ""
        python2_bin = weechat.info_get("python2_bin", "") or "python"
        spotify_hook_process = weechat.hook_process(
            python2_bin + " -c \"import urllib2; print urllib2.urlopen('" +
            url + "').read()\"", 30 * 1000, "spotify_process_cb", "")

    return weechat.WEECHAT_RC_OK
Exemplo n.º 23
0
def remove_hooks():
    global HOOK

    for k in HOOK:
        if HOOK[k] != '':
            weechat.unhook(HOOK[k])
            HOOK[k] = ''
Exemplo n.º 24
0
def wg_update_cache():
    """ Download list of scripts and update local cache. """
    global wg_config_option, wg_hook_process, wg_stdout
    # get data from website, via hook_process
    if wg_hook_process["update"] != "":
        weechat.unhook(wg_hook_process["update"])
        wg_hook_process["update"] = ""
    weechat.prnt("", "%s: downloading list of scripts..." % SCRIPT_NAME)
    wg_stdout["update"] = ""
    wg_config_create_dir()
    url = weechat.config_string(wg_config_option["scripts_url"])
    filename = wg_config_get_cache_filename()
    python2_bin = weechat.info_get("python2_bin", "") or "python"
    wg_hook_process["update"] = weechat.hook_process(
        python2_bin + " -c \"import urllib, urllib2\n"
        "req = urllib2.Request('" + url + "')\n"
        "try:\n"
        "    response = urllib2.urlopen(req)\n"
        "    file = open('" + filename + "', 'w')\n"
        "    file.write(response.read())\n"
        "    response.close()\n"
        "    file.close()\n"
        "except urllib2.URLError, e:\n"
        "    print 'error:%s' % e.code\n"
        "\"", TIMEOUT_UPDATE, "wg_process_update_cb", "")
Exemplo n.º 25
0
def typing_chk(data, signal, signal_data):
    ''' Activity check, when to disable highlight status '''
    global input_hook
    w.unhook(input_hook)
    w.command('', '/hloff')
    timer_hook_function()
    return w.WEECHAT_RC_OK
Exemplo n.º 26
0
def zncplayback_config_cb(data, option, value):
    """Update in-memory settings when a script option is changed."""
    global zncplayback_settings
    pos = option.rfind(".")
    if pos > 0:
        name = option[pos + 1:]
        if name in zncplayback_settings:
            if name == "servers":
                old_servers = zncplayback_settings["servers"].split(",")
                new_servers = value.split(",")
                # Unhook signals for old servers
                removed_servers = \
                    [s for s in old_servers if s not in new_servers]
                for serv in removed_servers:
                    weechat.unhook(zncplayback_hooks["messages"][serv])
                    del zncplayback_last_times[serv]
                # Hook signals for new servers
                added_servers = \
                    [s for s in new_servers if s not in old_servers]
                for serv in added_servers:
                    zncplayback_hooks["messages"][serv] = weechat.hook_signal(
                        "{},irc_raw_in_PRIVMSG".format(serv),
                        "zncplayback_message_cb", serv)
                    zncplayback_last_times[serv] = 0
            zncplayback_settings[name] = value
    return weechat.WEECHAT_RC_OK
Exemplo n.º 27
0
def close_socket():
    global signald_socket
    global signald_hook

    if signald_socket is not None:
        signald_socket.close()
    if signald_hook is not None:
        weechat.unhook(signald_hook)
Exemplo n.º 28
0
def set_timer():
    """Update timer hook with new interval"""

    global TIMER
    if TIMER:
        w.unhook(TIMER)
    TIMER = w.hook_timer(
        int(w.config_get_plugin('interval')) * 1000, 0, 0, 'timer_cb', '')
Exemplo n.º 29
0
def slack_connection_persistence_cb(data, remaining_calls):
    for server in servers:
        if not server.connected:
            server.buffer_prnt("Disconnected from slack, trying to reconnect..")
            if server.ws_hook != None:
                w.unhook(server.ws_hook)
            server.connect_to_slack()
    return w.WEECHAT_RC_OK
Exemplo n.º 30
0
def config_cb(data, option, value):
    global hook
    if value == 'on':
        hook = w.hook_print("", "", "", 1, "my_print_cb", "")
    else:
        w.unhook(hook)

    return w.WEECHAT_RC_OK
Exemplo n.º 31
0
def floodit_close_buffer(data, buffer):
    """Called when floodit buffer is closed."""
    global floodit
    if floodit['timer']:
        weechat.unhook(floodit['timer'])
        floodit['timer'] = ''
    floodit['buffer'] = ''
    return weechat.WEECHAT_RC_OK
Exemplo n.º 32
0
def floodit_close_buffer(data, buffer):
    """Called when floodit buffer is closed."""
    global floodit
    if floodit['timer']:
        weechat.unhook(floodit['timer'])
        floodit['timer'] = ''
    floodit['buffer'] = ''
    return weechat.WEECHAT_RC_OK
Exemplo n.º 33
0
def set_timer():
    """Update timer hook with new interval"""

    global TIMER
    if TIMER:
        w.unhook(TIMER)
    TIMER = w.hook_timer(int(w.config_get_plugin('interval')) * 1000,
            0, 0, 'timer_cb', '')
Exemplo n.º 34
0
def set_timer():
    global TIMER
    if TIMER:
        weechat.unhook(TIMER)
    if int(OPTIONS['interval']) == 0:
        return
    TIMER = weechat.hook_timer(int(OPTIONS['interval']) * 1000,
            0, 0, 'check_buffer_timer_cb', '')
Exemplo n.º 35
0
def disable_capab(server):
    server_buffer = weechat.buffer_search('irc', 'server.%s' %server)
    if server_buffer:
        weechat.command(server_buffer, '/quote cap req :-identify-msg')
        for hook in capab_hooks[server]:
            weechat.unhook(hook)
        del capab_hooks[server]
        return True
Exemplo n.º 36
0
def cancel_target(buf):
    if buf not in targets:
        return

    tgt = targets[buf]
    del targets[buf]

    weechat.unhook(tgt['timer'])
Exemplo n.º 37
0
def idle_chk(data, remaining_calls):
    ''' Inactivity check, when to change highlightxmpp status to on'''
    global timer_hook
    if int(w.info_get('inactivity', '')) >= val_idletime() * 60:
        w.unhook(timer_hook)
        w.command('', '/hlon')
        input_hook_function()
    return w.WEECHAT_RC_OK
Exemplo n.º 38
0
def samegame_close_buffer(data, buffer):
    """Called when samegame buffer is closed."""
    global samegame
    if samegame['timer']:
        weechat.unhook(samegame['timer'])
        samegame['timer'] = ''
    samegame['buffer'] = ''
    return weechat.WEECHAT_RC_OK
Exemplo n.º 39
0
def slack_connection_persistence_cb(data, remaining_calls):
    for server in servers:
        if not server.connected:
            w.prnt("", "Disconnected from slack, trying to reconnect..")
            if server.ws_hook != None:
                w.unhook(server.ws_hook)
            server.connect_to_slack()
    return w.WEECHAT_RC_OK
Exemplo n.º 40
0
def disable_capab(server):
    server_buffer = weechat.buffer_search('irc', 'server.%s' % server)
    if server_buffer:
        weechat.command(server_buffer, '/quote cap req :-identify-msg')
        for hook in capab_hooks[server]:
            weechat.unhook(hook)
        del capab_hooks[server]
        return True
Exemplo n.º 41
0
def shell_kill_process(buffer):
    global cmd_hook_process, cmd_command
    if cmd_hook_process == "":
        weechat.prnt(buffer, "%sno process running" % SHELL_PREFIX)
    else:
        weechat.unhook(cmd_hook_process)
        weechat.prnt(buffer, "%sprocess killed (command '%s')" % (SHELL_PREFIX, cmd_command))
        shell_init()
Exemplo n.º 42
0
def cancel_target(buf):
    if buf not in targets:
        return

    tgt = targets[buf]
    del targets[buf]

    weechat.unhook(tgt['timer'])
Exemplo n.º 43
0
def samegame_close_buffer(data, buffer):
    """Called when samegame buffer is closed."""
    global samegame
    if samegame["timer"]:
        weechat.unhook(samegame["timer"])
        samegame["timer"] = ""
    samegame["buffer"] = ""
    return weechat.WEECHAT_RC_OK
Exemplo n.º 44
0
def check_timer():
  '''Sets or unsets the timer based on whether or not the plugin is enabled'''
  global TIMER
  if TIMER:
      w.unhook(TIMER)
  if w.config_get_plugin('status') == '1':
    TIMER = w.hook_timer(int(w.config_get_plugin('interval')) * 1000, 0, 0, "auto_check", "")
    w.prnt('', "fileaway timer is running.")
Exemplo n.º 45
0
def on_signal(*args, **kwargs):
	global timer
	''' Called whenever the buffer list changes. '''
	if timer is not None:
		weechat.unhook(timer)
		timer = None
	weechat.hook_timer(config.signal_delay, 0, 1, "on_timeout", "")
	return weechat.WEECHAT_RC_OK
Exemplo n.º 46
0
def set_timer():
    '''Update timer hook with new interval'''

    global TIMER
    if TIMER:
        w.unhook(TIMER)
    TIMER = w.hook_timer(int(w.config_get_plugin('interval')) * 1000,
            0, 0, "screen_away_timer_cb", '')
Exemplo n.º 47
0
def remove_hooks():
    global HOOK

    if HOOK['timer'] != '':
        weechat.unhook(HOOK['timer'])
        HOOK['timer'] = ''
    if HOOK['redirect'] != '':
        weechat.unhook(HOOK['redirect'])
        HOOK['redirect'] = ''
Exemplo n.º 48
0
def check_timer():
    """Sets or unsets the timer
    based on whether or not the plugin is enabled"""
    global TIMER
    if TIMER:
        weechat.unhook(TIMER)
    TIMER = weechat.hook_timer(
            int(weechat.config_get_plugin('interval')) * 1000,
            0, 0, "auto_check", "")
Exemplo n.º 49
0
def set_timer() -> None:
    """ set timer hook """
    global TIMER_HOOK

    if TIMER_HOOK:
        w.unhook(TIMER_HOOK)

    TIMER_HOOK = w.hook_timer(config_get_int(
        "interval") * 1000, 0, 0, "screen_check_timer_cb", "")
Exemplo n.º 50
0
def floodit_timer_cb(data, remaining_calls):
    """Timer for demo mode."""
    global floodit
    floodit['color'] = floodit_find_best(0, 0)
    floodit_user_flood()
    if floodit['end']:
        weechat.unhook(floodit['timer'])
        floodit['timer'] = ''
    return weechat.WEECHAT_RC_OK
Exemplo n.º 51
0
def apply_config():
	# Unhook all signals and hook the new ones.
	for hook in hooks:
		weechat.unhook(hook)
	for signal in config.signals:
		hooks.append(weechat.hook_signal(signal, 'on_signal', ''))

	if config.sort_on_config:
		do_sort()
Exemplo n.º 52
0
def check_timer():
    """Sets or unsets the timer
    based on whether or not the plugin is enabled"""
    global TIMER
    if TIMER:
        weechat.unhook(TIMER)
    TIMER = weechat.hook_timer(
        int(weechat.config_get_plugin('interval')) * 1000, 0, 0, "auto_check",
        "")
Exemplo n.º 53
0
def shell_kill_process(buffer):
    """Kill running process."""
    global cmd_hook_process, cmd_command
    if cmd_hook_process:
        weechat.unhook(cmd_hook_process)
        weechat.prnt(buffer, '%sprocess killed (command "%s")' % (SHELL_PREFIX, cmd_command))
        shell_init()
    else:
        weechat.prnt(buffer, '%sno process running' % SHELL_PREFIX)
Exemplo n.º 54
0
def switch_chk(data, option, value):
    ''' Checks when idletime setting is changed '''
    global timer_hook, input_hook
    if timer_hook:
        w.unhook(timer_hook)
    if input_hook:
        w.unhook(input_hook)
    timer_hook_function()
    return w.WEECHAT_RC_OK
Exemplo n.º 55
0
def remove_hooks():
    global HOOK

    if HOOK['timer'] != '':
        weechat.unhook(HOOK['timer'])
        HOOK['timer'] = ''
    if HOOK['redirect'] != '':
        weechat.unhook(HOOK['redirect'])
        HOOK['redirect'] = ''
Exemplo n.º 56
0
def switch_chk(data, option, value):
    ''' Checks when idletime setting is changed '''
    global timer_hook, input_hook
    if timer_hook:
        w.unhook(timer_hook)
    if input_hook:
        w.unhook(input_hook)
    timer_hook_function()
    return w.WEECHAT_RC_OK