Example #1
0
    def __init__(self, options):
        self.status_name = options['server_name']
        self.nick_name = options['nickname']
        global debug
        if options['debug'] == "true":
            debug = True
        else:
            debug = False
        self.private_chans = {}
        self.private_chans_ptr = {}
        self.status = weechat.buffer_new(self.status_name, "status_input_cb",
                                         "", "status_close_cb", "")
        weechat.buffer_set(self.status, "localvar_set_type", "server")
        weechat.buffer_set(self.status, "localvar_set_server", "keybase")
        self.init_chats()
        #self.get_history()
        self.reader = weechat.hook_process_hashtable("keybase chat api-listen",
                                                     {"buffer_flush": "1"}, 0,
                                                     "start_reading", "")
        weechat.hook_command(
            "download", "Download an attachment", "<msg_id> <outputh_path>",
            "<msg_id>: ID of the message\n<output_path>: Path to store file",
            "", "download_message", "")
        weechat.hook_command("open",
                             "Open (with default application) an attachment",
                             "<msg_id>", "<msg_id>: ID of the message\n", "",
                             "open_attachment", "")
        ## Hooking to classic weechat command
        weechat.hook_command_run("/msg", "send_new_message", "")
        weechat.hook_command_run("/reply", "reply_to_message", "")

        weechat.hook_signal("buffer_switch", "buffer_switched", "")
        weechat.hook_signal("window_scrolled", "window_scrolled", "")
        weechat.hook_command("test", "", "", "", "", "test12", "")
Example #2
0
def main():
    """ Entry point, initializes everything  """

    weechat.register(
        SCRIPT_NAME,
        SCRIPT_AUTHOR,
        SCRIPT_VERSION,
        SCRIPT_LICENSE,
        SCRIPT_DESCRIPTION,
        "", # Shutdown callback function
        "", # Charset (blank for utf-8)
    )

    # Default values for settings
    default_settings = {
        'dbfile': os.path.join(
            weechat.info_get("weechat_dir", ""), "emojis-db.dat")
    }

    # Apply default configuration values if anything is unset
    for option, default in default_settings.items():
        if not weechat.config_is_set_plugin(option):
            weechat.config_set_plugin(option, default)

    # Hook callbacks
    weechat.hook_config("plugins.var.python." + SCRIPT_NAME + ".*",
        "configuration_cb", "")
    weechat.hook_command_run("/input return", "transform_cb", "")
    weechat.hook_command_run("/input complete*", "complete_cb", "")
    #weechat.hook_modifier("input_text_display", "collapse_cb", "")

    # Command callbacks
    weechat.hook_command(  # command name
                           SCRIPT_NAME,
                           # description
                           " display :common_name: with its emoji equivalent",
                           # arguments
                           "reload"
                           " || add <name> <emoji>"
                           " || show <emoji>",
                           # description of arguments
                           " name: emoji name, sans colons\n"
                           "emoji: text that replaces :name:\n",
                           # completions
                           "reload || add || show %(emoji_name)", "emojis_cb", "")
    weechat.hook_completion("emoji_name", "Emoji name", "emoji_name_completion_cb", "")

    dbfile = weechat.config_get_plugin("dbfile")

    weechat.prnt("", "%s: Loading emojis from %s" % (SCRIPT_NAME, dbfile))

    try:
        load_emojis(dbfile)
    except IOError as e:
        weechat.prnt("",
            "%s%s: Database file %s is missing or inaccessible." \
                    % (weechat.prefix("error"), SCRIPT_NAME, dbfile))
        raise e # TODO: handle this better instead of brutally aborting
Example #3
0
 def _create(self):
     buffer = Buffer._create(self)
     weechat.buffer_set(buffer, 'nicklist', '0')
     weechat.buffer_set(buffer, 'time_for_each_line', '0')
     weechat.buffer_set(buffer, 'localvar_set_no_log', '1')
     self.color_input = weechat.color('green')
     self.color_exc = weechat.color('red')
     self.color_call = weechat.color('cyan')
     weechat.hook_command_run('/input return', callback(self.input_return), buffer)
     # print python and WeeChat version
     prnt(buffer, "Python %s" % sys.version.split(None, 1)[0])
     prnt(buffer, "WeeChat %s" % weechat.info_get('version', ''))
     return buffer
Example #4
0
 def _create(self):
     buffer = Buffer._create(self)
     weechat.buffer_set(buffer, 'nicklist', '0')
     weechat.buffer_set(buffer, 'time_for_each_line', '0')
     weechat.buffer_set(buffer, 'localvar_set_no_log', '1')
     self.color_input = weechat.color('green')
     self.color_exc = weechat.color('red')
     self.color_call = weechat.color('cyan')
     weechat.hook_command_run('/input return', callback(self.input_return), buffer)
     # print python and WeeChat version
     prnt(buffer, "Python %s" % sys.version.split(None, 1)[0])
     prnt(buffer, "WeeChat %s" % weechat.info_get('version', ''))
     return buffer
Example #5
0
    def __init__(self, options):
        self.status_name = options['server_name']
        self.nick_name = options['nickname']
        self.is_away = False
        global debug
        if options['debug'] == "true":
            debug = True
        else:
            debug = False
        self.private_chans = {}
        self.private_chans_ptr = {}
        self.status = weechat.buffer_new(self.status_name, "status_input_cb",
                                         "", "status_close_cb", "")
        weechat.buffer_set(self.status, "localvar_set_type", "server")
        weechat.buffer_set(self.status, "localvar_set_server", "keybase")
        self.init_chats()
        #self.get_history()
        self.reader = weechat.hook_process_hashtable("keybase chat api-listen",
                                                     {"buffer_flush": "1"}, 0,
                                                     "start_reading", "")
        weechat.hook_command(
            "download", "Download an attachment", "<msg_id> <outputh_path>",
            "<msg_id>: ID of the message\n<output_path>: Path to store file",
            "", "download_message", "")
        weechat.hook_command("open",
                             "Open (with default application) an attachment",
                             "<msg_id>", "<msg_id>: ID of the message\n", "",
                             "open_attachment", "")
        weechat.hook_command("attach", "Upload file to conversation",
                             "<filename>", "<filename>: File to upload\n", "",
                             "attach_file", "")
        weechat.hook_command(
            "re", "Reply to message", "<msg_id> <reply_message>",
            "<msg_id>: ID of the message to which reply\n<reply_message>: reply",
            "", "reply_message_buffer", "")
        weechat.hook_command("delete", "Delete message", "<msg_id>",
                             "<msg_id>: ID of the message to which reply", "",
                             "delete_message_buffer", "")
        weechat.hook_command(
            ":", "React to message", "<reaction> <msg_id>",
            "<reaction>: Keybase Reaction alias\n<msg_id>: ID of the message to which reply",
            "", "react_to_message", "")
        weechat.hook_command("reload", "", "", "", "", "reload_conversation",
                             "")

        ## Hooking to classic weechat command
        # weechat.hook_command_run("/msg","send_new_message","")
        weechat.hook_command_run("/away", "away_command_cb", "")

        weechat.hook_signal("buffer_switch", "buffer_switched", "")
        weechat.hook_signal("window_scrolled", "window_scrolled", "")
Example #6
0
def main():
    """ Entry point, initializes everything  """

    weechat.register(
        SCRIPT_NAME,
        SCRIPT_AUTHOR,
        SCRIPT_VERSION,
        SCRIPT_LICENSE,
        SCRIPT_DESCRIPTION,
        "",  # Shutdown callback function
        "",  # Charset (blank for utf-8)
    )

    # Default values for settings
    default_settings = {
        'dbfile': os.path.join(
            weechat.info_get("weechat_dir", ""), "emojis-db.dat")
    }

    # Apply default configuration values if anything is unset
    for option, default in default_settings.items():
        if not weechat.config_is_set_plugin(option):
            weechat.config_set_plugin(option, default)

    # Hook callbacks
    weechat.hook_config(
        "plugins.var.python." + SCRIPT_NAME + ".*",
        "configuration_cb", "")
    weechat.hook_command_run("/input return", "transform_cb", "")
    weechat.hook_command_run("/input complete*", "complete_cb", "")

    # Command callbacks
    weechat.hook_command(
        "reloademojis", "reload emojis from file",
        "", "", "", "reload_emojis_cb", "")

    dbfile = weechat.config_get_plugin("dbfile")

    weechat.prnt("", "%s: Loading emojis from %s" % (SCRIPT_NAME, dbfile))

    try:
        load_emojis(dbfile)
    except IOError as e:
        weechat.prnt(
            "",
            "%s%s: Database file %s is missing or inaccessible."
            % (weechat.prefix("error"), SCRIPT_NAME, dbfile))
        raise e  # TODO: handle this better instead of brutally aborting
Example #7
0
def install_hooks():
    HOOKS.extend([
        wc.hook_command_run("%d|%s" % (HOOK_PRIORITY, "/input *"),
                            "input_hook", ""),
        wc.hook_modifier("%d|%s" % (HOOK_PRIORITY, "input_text_display_with_cursor"),
                              "modifier_hook", "")
    ]) # yapf: disable
Example #8
0
File: go.py Project: ronin13/seed
def hook_all():
    """ Hook command_run and modifier """
    global hook_command_run, hooks
    for hook, value in hook_command_run.iteritems():
        if hook not in hooks:
            hooks[hook] = weechat.hook_command_run(value[0], value[1], "")
    if "modifier" not in hooks:
        hooks["modifier"] = weechat.hook_modifier("input_text_display_with_cursor", "input_modifier", "")
def toggle_refresh(pointer, name, value):
    global OPTIONS
    option = name[len('plugins.var.python.' + SCRIPT_NAME + '.'):]        # get optionname
    OPTIONS[option] = value                                               # save new value

    if OPTIONS['catch_input_completion'].lower() == "off":
        if Hooks['catch_input_completion']:
            weechat.unhook(Hooks['catch_input_completion'])
            Hooks['catch_input_completion'] = ''
            weechat.unhook(Hooks['catch_input_return'])
            Hooks['catch_input_return'] = ''
    elif OPTIONS['catch_input_completion'].lower() == "on":
        if not Hooks['catch_input_completion']:
            Hooks['catch_input_completion'] = weechat.hook_command_run('/input complete*', 'input_complete_cb', '')
            Hooks['catch_input_return'] = weechat.hook_command_run('/input return', 'input_return_cb', '')

    return weechat.WEECHAT_RC_OK
def toggle_refresh(pointer, name, value):
    global OPTIONS
    option = name[len("plugins.var.python." + SCRIPT_NAME + ".") :]  # get optionname
    OPTIONS[option] = value  # save new value

    if OPTIONS["catch_input_completion"].lower() == "off":
        if Hooks["catch_input_completion"]:
            weechat.unhook(Hooks["catch_input_completion"])
            Hooks["catch_input_completion"] = ""
            weechat.unhook(Hooks["catch_input_return"])
            Hooks["catch_input_return"] = ""
    elif OPTIONS["catch_input_completion"].lower() == "on":
        if not Hooks["catch_input_completion"]:
            Hooks["catch_input_completion"] = weechat.hook_command_run("/input complete*", "input_complete_cb", "")
            Hooks["catch_input_return"] = weechat.hook_command_run("/input return", "input_return_cb", "")

    return weechat.WEECHAT_RC_OK
def toggle_refresh(pointer, name, value):
    global OPTIONS
    option = name[len('plugins.var.python.' + SCRIPT_NAME + '.'):]        # get optionname
    OPTIONS[option] = value                                               # save new value

    if OPTIONS['catch_input_completion'].lower() == "off":
        if Hooks['catch_input_completion']:
            weechat.unhook(Hooks['catch_input_completion'])
            Hooks['catch_input_completion'] = ''
            weechat.unhook(Hooks['catch_input_return'])
            Hooks['catch_input_return'] = ''
    elif OPTIONS['catch_input_completion'].lower() == "on":
        if not Hooks['catch_input_completion']:
            Hooks['catch_input_completion'] = weechat.hook_command_run('/input complete*', 'input_complete_cb', '')
            Hooks['catch_input_return'] = weechat.hook_command_run('/input return', 'input_return_cb', '')

    return weechat.WEECHAT_RC_OK
Example #12
0
def main():
    """ Entry point, initializes everything  """

    weechat.register(
        SCRIPT_NAME,
        SCRIPT_AUTHOR,
        SCRIPT_VERSION,
        SCRIPT_LICENSE,
        SCRIPT_DESCRIPTION,
        "",  # Shutdown callback function
        "",  # Charset (blank for utf-8)
    )

    # Default values for settings
    default_settings = {
        'dbfile':
        os.path.join(weechat.info_get("weechat_dir", ""), "emojis-db.dat")
    }

    # Apply default configuration values if anything is unset
    for option, default in default_settings.items():
        if not weechat.config_is_set_plugin(option):
            weechat.config_set_plugin(option, default)

    # Hook callbacks
    weechat.hook_config("plugins.var.python." + SCRIPT_NAME + ".*",
                        "configuration_cb", "")
    weechat.hook_command_run("/input return", "transform_cb", "")
    weechat.hook_command_run("/input complete*", "complete_cb", "")

    # Command callbacks
    weechat.hook_command("reloademojis", "reload emojis from file", "", "", "",
                         "reload_emojis_cb", "")

    dbfile = weechat.config_get_plugin("dbfile")

    weechat.prnt("", "%s: Loading emojis from %s" % (SCRIPT_NAME, dbfile))

    try:
        load_emojis(dbfile)
    except IOError as e:
        weechat.prnt("",
            "%s%s: Database file %s is missing or inaccessible." \
                    % (weechat.prefix("error"), SCRIPT_NAME, dbfile))
        raise e  # TODO: handle this better instead of brutally aborting
Example #13
0
def hook_all():
    """ Hook command_run and modifier """
    global hook_command_run, hooks
    for hook, value in hook_command_run.iteritems():
        if hook not in hooks:
            hooks[hook] = w.hook_command_run(value[0], value[1], "")
    if "modifier" not in hooks:
        hooks["modifier"] = w.hook_modifier(
            "input_text_display_with_cursor", "input_modifier", "")
Example #14
0
def main():
    """Main function."""
    if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION,
                        SCRIPT_LICENSE, SCRIPT_DESC, '', ''):
        # set default settings
        for option, value in ap_settings_default.items():
            if weechat.config_is_set_plugin(option):
                ap_settings[option] = weechat.config_get_plugin(option)
            else:
                weechat.config_set_plugin(option, value[0])
                ap_settings[option] = value[0]
            weechat.config_set_desc_plugin(
                option, '%s (default: "%s")' % (value[1], value[0]))

        # detect config changes
        weechat.hook_config('plugins.var.python.%s.*' % SCRIPT_NAME,
                            'ap_config_cb', '')

        # hook Return key
        weechat.hook_command_run('/input return', 'ap_input_return_cb', '')
def main():
    at_config('load')
    # hook our config
    weechat.hook_config(STRIP_VAR+'*','at_config','')
    # hook the nick complete
    weechat.hook_command_run('/input complete_next', 'at_completion', '')
    # hook the /atcomplete
    weechat.hook_command('atcomplete','manage @nick completion plugin',
        '[enable|disable|toggle] '
        ' | [servers [list | add name | del name]]'
        ' | [buffers [list | add name | del name]]',
        'args desc',
        'status %-'
        ' || enable %-'
        ' || disable %-'
        ' || toggle %-'
        ' || server list|add|del %(buffers_names)'
        ' || buffer list|add|del %(buffers_names)'
        ,
        'at_control','')
    # hook the completetion for /atcomplete
    weechat.hook_completion('plugin_at_completion','@nick completion','at_complete','')
Example #16
0
def main():
    version = weechat.info_get('version_number', '') or 0

    if int(version) < 0x00030600:
        print_error('script needs version 0.3.6 or higher')
        weechat.command('', "/wait 1ms /python unload %s" % SCRIPT_NAME)
        return

    init_config()

    description = """
{script_name} can make sure that when switching to a buffer it appears only in a particular window.
To trigger this behaviour set the localvar 'stick_buffer_to_window' to the desired window number.

You will need the script 'buffer_autoset.py' installed to make local variables persistent; see the
examples below.

Examples:
 Temporarily stick the current buffer to window 3:
   /buffer set localvar_set_stick_buffer_to_window 3
 Stick buffer #weechat to window 2:
   /buffer #weechat
   /buffer set localvar_set_stick_buffer_to_window 2
   /autosetbuffer add irc.freenode.#weechat stick_buffer_to_window 2
 Set the default stick-to window to window 5:
   /set plugins.var.python.{script_name}.default_stick_window 5
 List buffers with persistent stickiness:
   /{script_name} list
 Show this help:
   /{script_name} help
 Display local variables for current buffer:
   /buffer localvar
""".format(script_name=SCRIPT_NAME)

    weechat.hook_command(SCRIPT_NAME, SCRIPT_DESC, 'list', description,
                         'list %-', 'cmd_cb', '')

    weechat.hook_command_run('/buffer *', 'buffer_switch_cb', '')
Example #17
0
def main():
        version = weechat.info_get('version_number', '') or 0

        if int(version) < 0x00030600:
            print_error('script needs version 0.3.6 or higher')
            weechat.command('', "/wait 1ms /python unload %s" % SCRIPT_NAME)
            return

        init_config()

        description = """
{script_name} can make sure that when switching to a buffer it appears only in a particular window.
To trigger this behaviour set the localvar 'stick_buffer_to_window' to the desired window number.

You will need the script 'buffer_autoset.py' installed to make local variables persistent; see the
examples below.

Examples:
 Temporarily stick the current buffer to window 3:
   /buffer set localvar_set_stick_buffer_to_window 3
 Stick buffer #weechat to window 2:
   /buffer #weechat
   /buffer set localvar_set_stick_buffer_to_window 2
   /buffer_autoset add irc.freenode.#weechat stick_buffer_to_window 2
 Set the default stick-to window to window 5:
   /set plugins.var.python.{script_name}.default_stick_window 5
 List buffers with persistent stickiness:
   /{script_name} list
 Show this help:
   /{script_name} help
 Display local variables for current buffer:
   /buffer localvar
""".format(script_name = SCRIPT_NAME)

        weechat.hook_command(SCRIPT_NAME, SCRIPT_DESC, 'list', description, 'list %-', 'cmd_cb', '')

        weechat.hook_command_run('/buffer *', 'buffer_switch_cb', '')
        weechat.hook_command_run('/input jump_smart', 'buffer_switch_cb', '')
Example #18
0
def hook_all():
    """ Hook command_run and modifier """
    global hook_command_run, hooks
    priority = ""
    version = weechat.info_get("version_number", "") or 0
    # use high priority for hook to prevent conflict with other plugins/scripts
    # (WeeChat >= 0.3.4 only)
    if int(version) >= 0x00030400:
        priority = "2000|"
    for hook, value in hook_command_run.items():
        if hook not in hooks:
            hooks[hook] = weechat.hook_command_run("%s%s" % (priority, value[0]), value[1], "")
    if "modifier" not in hooks:
        hooks["modifier"] = weechat.hook_modifier("input_text_display_with_cursor", "input_modifier", "")
Example #19
0
def config_cb(data, option, value):
    """Called when a script option is changed."""
    global cmdhelp_settings, cmdhelp_hooks
    pos = option.rfind('.')
    if pos > 0:
        name = option[pos + 1:]
        if name in cmdhelp_settings:
            cmdhelp_settings[name] = value
            if name == 'stop_on_enter':
                if value == 'on' and not cmdhelp_hooks['command_run']:
                    cmdhelp_hooks['command_run'] = weechat.hook_command_run(
                        '/input return', 'command_run_cb', '')
                elif value != 'on' and cmdhelp_hooks['command_run']:
                    unhook(('command_run', ))
    return weechat.WEECHAT_RC_OK
Example #20
0
def config_cb(data, option, value):
    """Called when a script option is changed."""
    global cmdhelp_settings, cmdhelp_hooks
    pos = option.rfind('.')
    if pos > 0:
        name = option[pos+1:]
        if name in cmdhelp_settings:
            cmdhelp_settings[name] = value
            if name == 'stop_on_enter':
                if value == 'on' and not cmdhelp_hooks['command_run']:
                    cmdhelp_hooks['command_run'] = weechat.hook_command_run(
                        '/input return', 'command_run_cb', '')
                elif value != 'on' and cmdhelp_hooks['command_run']:
                    unhook(('command_run',))
    return weechat.WEECHAT_RC_OK
Example #21
0
def hook_all():
    """ Hook command_run and modifier """
    global hook_command_run, hooks
    priority = ""
    version = weechat.info_get("version_number", "") or 0
    # use high priority for hook to prevent conflict with other plugins/scripts
    # (WeeChat >= 0.3.4 only)
    if int(version) >= 0x00030400:
        priority = "2000|"
    for hook, value in hook_command_run.items():
        if hook not in hooks:
            hooks[hook] = weechat.hook_command_run(
                "%s%s" % (priority, value[0]), value[1], "")
    if "modifier" not in hooks:
        hooks["modifier"] = weechat.hook_modifier(
            "input_text_display_with_cursor", "input_modifier", "")
Example #22
0
def go_hook_all():
    """Hook command_run and modifier."""
    global hooks
    priority = ''
    version = weechat.info_get('version_number', '') or 0
    # use high priority for hook to prevent conflict with other plugins/scripts
    # (WeeChat >= 0.3.4 only)
    if int(version) >= 0x00030400:
        priority = '2000|'
    for hook, value in HOOK_COMMAND_RUN.items():
        if hook not in hooks:
            hooks[hook] = weechat.hook_command_run(
                '%s%s' % (priority, value[0]), value[1], '')
    if 'modifier' not in hooks:
        hooks['modifier'] = weechat.hook_modifier(
            'input_text_display_with_cursor', 'go_input_modifier', '')
Example #23
0
def go_hook_all():
    """Hook command_run and modifier."""
    global hooks
    priority = ''
    version = weechat.info_get('version_number', '') or 0
    # use high priority for hook to prevent conflict with other plugins/scripts
    # (WeeChat >= 0.3.4 only)
    if int(version) >= 0x00030400:
        priority = '2000|'
    for hook, value in HOOK_COMMAND_RUN.items():
        if hook not in hooks:
            hooks[hook] = weechat.hook_command_run(
                '%s%s' % (priority, value[0]),
                value[1], '')
    if 'modifier' not in hooks:
        hooks['modifier'] = weechat.hook_modifier(
            'input_text_display_with_cursor', 'go_input_modifier', '')
Example #24
0
def test_hooks():
    """Test function hook_command."""
    # hook_completion / hook_completion_args / and hook_command
    hook_cmplt = weechat.hook_completion('SCRIPT_NAME', 'description',
                                         'completion_cb', 'completion_data')
    hook_cmd = weechat.hook_command('cmd' + 'SCRIPT_NAME', 'description',
                                    'arguments', 'description arguments',
                                    '%(' + 'SCRIPT_NAME' + ')',
                                    'command_cb', 'command_data')
    weechat.command('', '/input insert /cmd' + 'SCRIPT_NAME' + ' w')
    weechat.command('', '/input complete_next')
    # hook_command_run
    hook_cmd_run = weechat.hook_command_run('/cmd' + 'SCRIPT_NAME' + '*',
                                            'command_run_cb', 'command_run_data')
    weechat.command('', '/input return')
    weechat.unhook(hook_cmd_run)
    weechat.unhook(hook_cmd)
    weechat.unhook(hook_cmplt)
Example #25
0
def test_hooks():
    """Test function hook_command."""
    # hook_completion / hook_completion_args / and hook_command
    hook_cmplt = weechat.hook_completion('SCRIPT_NAME', 'description',
                                         'completion_cb', 'completion_data')
    hook_cmd = weechat.hook_command('cmd' + 'SCRIPT_NAME', 'description',
                                    'arguments', 'description arguments',
                                    '%(' + 'SCRIPT_NAME' + ')',
                                    'command_cb', 'command_data')
    weechat.command('', '/input insert /cmd' + 'SCRIPT_NAME' + ' w')
    weechat.command('', '/input complete_next')
    # hook_command_run
    hook_cmd_run = weechat.hook_command_run('/cmd' + 'SCRIPT_NAME' + '*',
                                            'command_run_cb', 'command_run_data')
    weechat.command('', '/input return')
    weechat.unhook(hook_cmd_run)
    weechat.unhook(hook_cmd)
    weechat.unhook(hook_cmplt)
Example #26
0
        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', '')
    w.hook_signal('*,irc_in2_nick', 'nick_cb', '')
Example #27
0
                  message):
    global latest_speaker
    alltags = tags.split(',')
    if 'notify_message' in alltags:
        nick = None
        if int(weechat_version) >= 0x00030400:
            # in version >= 0.3.4, there is a tag "nick_xxx" for each message
            for tag in alltags:
                if tag.startswith('nick_'):
                    nick = tag[5:]
                    break
        else:
            # in older versions, no tag, so extract nick from printed message
            # this is working, except for irc actions (/me ...)
            nick = prefix
            if re.match('^[@%+~*&!-]', nick):
                nick = nick[1:]
        if nick:
            local_nick = weechat.buffer_get_string(buffer, "localvar_nick")
            if nick != local_nick:
                latest_speaker[buffer] = nick
    return weechat.WEECHAT_RC_OK


if __name__ == "__main__" and import_ok:
    if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION,
                        SCRIPT_LICENSE, SCRIPT_DESC, "", ""):
        weechat_version = weechat.info_get("version_number", "") or 0
        weechat.hook_print("", "", "", 1, "hook_print_cb", "")
        weechat.hook_command_run('/input complete*', 'my_completer', '')
Example #28
0
            OPTIONS[option] = weechat.config_get_plugin(option)
        weechat.config_set_desc_plugin(option, "%s (default: '%s')" % (value[1], value[0]))

def toggle_refresh(pointer, name, value):
    global OPTIONS
    option = name[len('plugins.var.python.' + SCRIPT_NAME + '.'):]        # get optionname
    OPTIONS[option] = value                                               # save new value
    weechat.bar_item_update(SCRIPT_NAME)
    return weechat.WEECHAT_RC_OK
# ================================[ main ]===============================
if __name__ == "__main__":
#    global filter_status
    if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT_DESC, '', ''):
        version = weechat.info_get("version_number", "") or 0

        if int(version) >= 0x00030600:
            filter_status = int(weechat.info_get('filters_enabled',''))
            bar_item = weechat.bar_item_new(SCRIPT_NAME, 'show_item','')
            weechat.bar_item_update(SCRIPT_NAME)
            weechat.hook_signal('buffer_line_added','update_cb','')
            weechat.hook_signal('window_scrolled','update_cb','')
            weechat.hook_signal('buffer_switch','update_cb','')
            weechat.hook_signal('*filters*','filtered_update_cb','')
            weechat.hook_command_run('/buffer clear*','update_cb','')
            weechat.hook_command_run('/window page*','update_cb','')
            weechat.hook_command_run('/input zoom_merged_buffer','update_cb','')
            weechat.hook_config( 'plugins.var.python.' + SCRIPT_NAME + '.*', 'toggle_refresh', '' )
            init_options()
        else:
            weechat.prnt('','%s%s %s' % (weechat.prefix('error'),SCRIPT_NAME,': needs version 0.3.6 or higher'))
Example #29
0
                #w.prnt("", "%s: %s" % (c, r.body["ok"] and "ok" or "not ok"))
            except:
                w.prnt("", "Error while setting unread marker on %s" % c)
    w.prnt("", "%d channels marked as read" % len(channels))

    return w.WEECHAT_RC_OK

def conga(data, buffer, command):
    il = w.infolist_get("buffer", "", "")
    pronted = False
    if il:
        while w.infolist_next(il):
            if not pronted:
                w.prnt("", w.infolist_fields(il))
                pronted = True
            w.prnt("", "2. %i - %i - %i - %i - %s" % (w.infolist_integer(il, "first_line_not_read"), w.infolist_integer(il, "num_displayed"), w.infolist_integer(il, "lines_hidden"), w.infolist_integer(il, "num_history"), w.infolist_string(il, "name")))
        w.infolist_free(il)
    return w.WEECHAT_RC_OK

if __name__ == "__main__":
    w.register("slack", "*****@*****.**", "0.1", "MIT", "Pitiful slack integration", "", "")
    #w.hook_command_run("/input set_unread*", "conga", "")
    w.hook_command_run("/input set_unread*", "unread_cb", "")
    users = {u['id']: u['name'] for u in slack.users.list().body["members"]}
    private_groups = {g['name']: g['id'] for g in slack.groups.list().body["groups"]}
    all_channels = {c['name']: c['id'] for c in slack.channels.list().body["channels"]}
    all_channels.update({users[i["user"]]: i["id"] for i in slack.im.list().body["ims"] if i["user"] in users})
    all_channels.update(private_groups)
    #w.prnt("", "hai %d" % len(all_channels))
    #w.prnt("", str(all_channels))
Example #30
0
    init_config()
    return w.WEECHAT_RC_OK


def tc_action_cb():
    global tc_options
    if tc_options['warn_command']:
        if tc_options['warn_command'] == '$bell':
            f = open('/dev/tty', 'w')
            f.write('\a')
            f.close()
        else:
            os.system(tc_options['warn_command'])
    return w.WEECHAT_RC_OK


if __name__ == "__main__":
    if w.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE,
                  SCRIPT_DESC, "", ""):
        init_config()  # read configuration
        tc_bar_item_update()  # update status bar display

        w.hook_signal('input_text_changed', 'tc_bar_item_update', '')
        w.hook_signal('input_text_cursor_moved', 'tc_bar_item_update', '')
        w.hook_command_run('/input move_previous_char', 'command_run_cb', '')
        w.hook_command_run('/input delete_previous_char', 'command_run_cb', '')
        w.hook_signal('buffer_switch', 'tc_bar_item_update', '')
        w.hook_config('plugins.var.python.' + SCRIPT_NAME + ".*",
                      "config_changed", "")
        w.bar_item_new('tc', 'tc_bar_item', '')
Example #31
0
    if argv[0].lower() == 'list':
        weechat.command('', '/set *.localvar_set_stick_buffer_to_window')

    return weechat.WEECHAT_RC_OK


# ================================[ main ]===============================
if __name__ == "__main__":
    if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION,
                        SCRIPT_LICENSE, SCRIPT_DESC, '', ''):
        version = weechat.info_get("version_number", "") or 0

        weechat.hook_command(
            SCRIPT_NAME, SCRIPT_DESC, 'list', '\n'
            'You have to create a localvar, \"stick_buffer_to_window\", for the buffer you want to stick to a specific window.\n'
            'You will need script \"buffer_autoset.py\" to make local variabe persistent (see examples, below)!!\n'
            '\n'
            'Examples:\n'
            ' temporarily stick the current buffer to window 3:\n'
            '   /buffer set localvar_set_stick_buffer_to_window 3\n'
            ' stick buffer #weechat to window 2:\n'
            '   /autosetbuffer add irc.freenode.#weechat stick_buffer_to_window 2\n'
            ' lists buffer who are bind to a specific window (only persistent ones!):\n'
            '   /' + SCRIPT_NAME + ' list\n'
            ' display local variables for current buffer:\n'
            '   /buffer localvar\n'
            '', 'list %-', 'open_buffer_cmd_cb', '')

        weechat.hook_command_run('/buffer *', 'buffer_switch_cb', '')
#        weechat.prnt("","%s.%s" % (sys.version_info[0], sys.version_info[1]))
Example #32
0
    w.prnt(buf, "{}{}{}{} is back on the server".format(w.prefix("join"),
                                                        w.info_get("nick_color", nick),
                                                        nick, w.color("green")))

    return w.WEECHAT_RC_OK


def notify_quit_cb(data, signal, signal_data):
    """ callback for when a user in WeeChat's notify list quits IRC """
    server, nick = signal_data.split(",")

    buf = w.info_get("irc_buffer", server + ",," + nick)
    if not buf:
        return w.WEECHAT_RC_OK

    w.prnt(buf, "{}{}{}{} has disconnected".format(w.prefix("quit"),
                                                   w.info_get("nick_color", nick),
                                                   nick, w.color("red")))

    return w.WEECHAT_RC_OK


w.hook_signal("irc_notify_join", "notify_join_cb", "")
w.hook_signal("irc_notify_quit", "notify_quit_cb", "")
w.hook_modifier("weechat_print", "hide_buffer_quit_join", "")

w.hook_command_run("/notify add*", "get_notify_list", "")
w.hook_command_run("/notify del*", "get_notify_list", "")

get_notify_list()
Example #33
0
SCRIPT_AUTHOR = "Ben Hughes <*****@*****.**>"
SCRIPT_VERSION = "0.2"
SCRIPT_LICENSE = "BSD"
SCRIPT_DESC = "Stops you being yubikeyed"


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

    # Hooks we want to hook
    hook_command_run = {
        "input": ("/input return",  "command_run_input"),
    }
    # Hook all hooks !
    for hook, value in hook_command_run.iteritems():
        w.hook_command_run(value[0], value[1], "")


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.

        # Get input contents
        input_s = w.buffer_get_string(buffer, 'input')

        # Skip modification of settings
        if input_s.startswith('/'):
            return w.WEECHAT_RC_OK

        yubistring = w.config_get_plugin('yubistring')
Example #34
0
def main():
    """ Entry point, initializes everything  """

    weechat.register(
        SCRIPT_NAME,
        SCRIPT_AUTHOR,
        SCRIPT_VERSION,
        SCRIPT_LICENSE,
        SCRIPT_DESCRIPTION,
        "",  # Shutdown callback function
        "",  # Charset (blank for utf-8)
    )

    # Default values for settings
    default_settings = {
        'dbfile':
        os.path.join(weechat.info_get("weechat_dir", ""), "emojis-db.dat")
    }

    # Apply default configuration values if anything is unset
    for option, default in default_settings.items():
        if not weechat.config_is_set_plugin(option):
            weechat.config_set_plugin(option, default)

    # Hook callbacks
    weechat.hook_config("plugins.var.python." + SCRIPT_NAME + ".*",
                        "configuration_cb", "")
    weechat.hook_command_run("/input return", "transform_cb", "")
    weechat.hook_command_run("/input complete*", "complete_cb", "")
    #weechat.hook_modifier("input_text_display", "collapse_cb", "")

    # Command callbacks
    weechat.hook_command(  # command name
        SCRIPT_NAME,
        # description
        " display :common_name: with its emoji equivalent",
        # arguments
        "reload"
        " || add <name> <emoji>"
        " || show <emoji>",
        # description of arguments
        " name: emoji name, sans colons\n"
        "emoji: text that replaces :name:\n",
        # completions
        "reload || add || show %(emoji_name)",
        "emojis_cb",
        "")
    weechat.hook_completion("emoji_name", "Emoji name",
                            "emoji_name_completion_cb", "")

    dbfile = weechat.config_get_plugin("dbfile")

    weechat.prnt("", "%s: Loading emojis from %s" % (SCRIPT_NAME, dbfile))

    try:
        load_emojis(dbfile)
    except IOError as e:
        weechat.prnt("",
            "%s%s: Database file %s is missing or inaccessible." \
                    % (weechat.prefix("error"), SCRIPT_NAME, dbfile))
        raise e  # TODO: handle this better instead of brutally aborting
Example #35
0
            if weechat.config_is_set_plugin(option):
                cmdhelp_settings[option] = weechat.config_get_plugin(option)
            else:
                weechat.config_set_plugin(option, value[0])
                cmdhelp_settings[option] = value[0]
            if int(version) >= 0x00030500:
                weechat.config_set_desc_plugin(
                    option, '%s (default: "%s")' % (value[1], value[0]))

        # detect config changes
        weechat.hook_config('plugins.var.python.%s.*' % SCRIPT_NAME,
                            'config_cb', '')

        # add hook to catch "enter" key
        if cmdhelp_settings['stop_on_enter'] == 'on':
            cmdhelp_hooks['command_run'] = weechat.hook_command_run(
                '/input return', 'command_run_cb', '')

        # add command
        weechat.hook_command(
            SCRIPT_COMMAND, 'Contextual command line help.', '',
            'This comand toggles help on command line.\n\n'
            'It is recommended to bind this command on a key, for example F1:\n'
            '  /key bind <press alt-k> <press F1> /cmd_help\n'
            'which will give, according to your terminal something like:\n'
            '      /key bind meta-OP /cmd_help\n'
            '    or:\n'
            '      /key bind meta2-11~ /cmd_help\n\n'
            'To try: type "/server" (without pressing enter) and press F1 '
            '(then you can add arguments and enjoy dynamic help!)', '',
            'cmd_help_cb', '')
            'You have to set "aspell.check.suggestions" to a value >= 0 (default: -1 (off)).\n'
            'Using "aspell.check.real_time" the nick-completion will not work, until all misspelled words in input_line are replaced.\n'
            "\n"
            "You can bind following commands to key:\n"
            " /" + SCRIPT_NAME + "           : to cycle though next suggestion\n"
            " /" + SCRIPT_NAME + " previous  : to cycle though previous suggestion\n"
            " /" + SCRIPT_NAME + " replace   : to replace misspelled word\n"
            "",
            "previous|replace",
            "auto_suggest_cmd_cb",
            "",
        )

        init_options()

        weechat.hook_command_run("/input delete_*", "input_delete_cb", "")
        weechat.hook_command_run("/input move*", "input_move_cb", "")
        weechat.hook_signal("input_text_changed", "input_text_changed_cb", "")
        # multiline workaround
        weechat.hook_signal("input_flow_free", "multiline_cb", "")

        weechat.hook_signal("aspell_suggest", "aspell_suggest_cb", "")

        weechat.hook_signal("buffer_switch", "buffer_switch_cb", "")
        weechat.hook_signal("window_switch", "window_switch_cb", "")

        if OPTIONS["catch_input_completion"].lower() == "on":
            Hooks["catch_input_completion"] = weechat.hook_command_run("/input complete*", "input_complete_cb", "")
            Hooks["catch_input_return"] = weechat.hook_command_run("/input return", "input_return_cb", "")
        weechat.hook_config("plugins.var.python." + SCRIPT_NAME + ".*", "toggle_refresh", "")
        weechat.bar_item_new("spell_correction", "show_spell_correction_item_cb", "")
Example #37
0
SCRIPT_NAME    = "command_cop"
SCRIPT_AUTHOR  = "Joël Perras <*****@*****.**>"
SCRIPT_VERSION = "0.1"
SCRIPT_LICENSE = "MIT"
SCRIPT_DESC    = "Prevent entering of leading spaces before /command."


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.

        # Get input contents.
        input_s = weechat.buffer_get_string(buffer, 'input')

        # Match leading spaces before commands (slashes) and spaces just after a
        # command slash.
        matches = re.match(r'(?:\s+/|/\s+)(.*)', input_s)
        if matches is not None:
            # Alert in weechat buffer.
            weechat.prnt("", "%sLeading spaces detected in command!" % weechat.color('red'))
            return weechat.WEECHAT_RC_OK_EAT

    return weechat.WEECHAT_RC_OK


if __name__ == '__main__':

    if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT_DESC, '', ''):
        weechat.hook_command_run('/input return', 'command_run_input', '')
Example #38
0
    isaway = wc.buffer_get_string(bufferp, "localvar_away") != ""
    isprivate = wc.buffer_get_string(bufferp, "localvar_type") == "private"

    # catch private messages or highlights when away
    if isaway and (isprivate or int(ishilight)):
        logentry = "awaylog\t"

        if int(ishilight) and not isprivate:
            buffer = (wc.buffer_get_string(bufferp, "short_name")
                      or wc.buffer_get_string(bufferp, "name"))
        else:
            buffer = "priv"

        buffer = wc.color("green") + buffer + wc.color("reset")

        logentry += "[" + buffer + "]"
        logentry += wc.color("default") + " <" + wc.color(
            "blue") + prefix + wc.color("default") + "> " + wc.color(
                "reset") + message

        awaylog.append((int(time.time()), logentry))
    return wc.WEECHAT_RC_OK


if __name__ == "__main__":
    if import_ok and wc.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION,
                                 SCRIPT_LICENSE, SCRIPT_DESC, "", ""):
        wc.hook_print("", "notify_message", "", 1, "msg_cb", "")
        wc.hook_print("", "notify_private", "", 1, "msg_cb", "")
        wc.hook_command_run("/away", "away_cb", "")
Example #39
0
        return w.WEECHAT_RC_OK

    if command == "/input return":
        # in case the line's empty, do nothing
        if uinput == "":
            return w.WEECHAT_RC_OK
        # bypass this using a backslash as the first character
        elif uinput.startswith("\\"):
            uinput = uinput.replace("\\", "", 1)
        # we don't want to capitalize basic URLs
        elif uinput[:4] == "http": # I'M TOO LAZY FOR REGEX MATCHING
            return w.WEECHAT_RC_OK
        # if we point to a user, don't capitalise this
        elif isnick(buffer, uinput.split()[0][:-1]):
            return w.WEECHAT_RC_OK
        # if everything else is fine, replace the first char with its capital
        else:
            uinput = uinput.replace(uinput[0], uinput[0].upper(), 1)
        # set the new string into the input
        w.buffer_set(buffer, "input", uinput)
    return w.WEECHAT_RC_OK

if w.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION,
        SCRIPT_LICENSE, SCRIPT_DESC, "", ""):
    for option, value in settings.items():
        if not w.config_is_set_plugin(option):
            w.config_set_plugin(option, value[0])
        w.config_set_desc_plugin(option, "%s (default '%s')" % (value[1],
            value[0]))
    w.hook_command_run("/input return", "word_magic", "")
Example #40
0
                cmdhelp_settings[option] = weechat.config_get_plugin(option)
            else:
                weechat.config_set_plugin(option, value[0])
                cmdhelp_settings[option] = value[0]
            if int(version) >= 0x00030500:
                weechat.config_set_desc_plugin(
                    option,
                    '%s (default: "%s")' % (value[1], value[0]))

        # detect config changes
        weechat.hook_config('plugins.var.python.%s.*' % SCRIPT_NAME,
                            'config_cb', '')

        # add hook to catch "enter" key
        if cmdhelp_settings['stop_on_enter'] == 'on':
            cmdhelp_hooks['command_run'] = weechat.hook_command_run(
                '/input return', 'command_run_cb', '')

        # add command
        weechat.hook_command(
            SCRIPT_COMMAND,
            'Contextual command line help.',
            '',
            'This comand toggles help on command line.\n\n'
            'It is recommended to bind this command on a key, for example '
            'F1:\n'
            '  /key bind <press alt-k> <press F1> /cmd_help\n'
            'which will give, according to your terminal something like:\n'
            '      /key bind meta-OP /cmd_help\n'
            '    or:\n'
            '      /key bind meta2-11~ /cmd_help\n\n'
            'To try: type "/server" (without pressing enter) and press F1 '
                            'with current suggestion.\n'
                            '\n'
                            'You have to set "aspell.check.suggestions" to a value >= 0 (default: -1 (off)).\n'
                            'Using "aspell.check.real_time" the nick-completion will not work, until all misspelled words in input_line are replaced.\n'
                            '\n'
                            'You can bind following commands to key:\n'
                            ' /' + SCRIPT_NAME + '           : to cycle though next suggestion\n'
                            ' /' + SCRIPT_NAME + ' previous  : to cycle though previous suggestion\n'
                            ' /' + SCRIPT_NAME + ' replace   : to replace misspelled word\n'
                            '',
                            'previous|replace',
                            'auto_suggest_cmd_cb', '')

        init_options()

        weechat.hook_command_run('/input delete_*', 'input_delete_cb', '')
        weechat.hook_command_run('/input move*', 'input_move_cb', '')
        weechat.hook_signal ('input_text_changed', 'input_text_changed_cb', '')
        # multiline workaround
        weechat.hook_signal('input_flow_free', 'multiline_cb', '')

        weechat.hook_signal ('aspell_suggest', 'aspell_suggest_cb', '')

        weechat.hook_signal ('buffer_switch', 'buffer_switch_cb','')
        weechat.hook_signal ('window_switch', 'window_switch_cb','')

        if OPTIONS['catch_input_completion'].lower() == "on":
            Hooks['catch_input_completion'] = weechat.hook_command_run('/input complete*', 'input_complete_cb', '')
            Hooks['catch_input_return'] = weechat.hook_command_run('/input return', 'input_return_cb', '')
        weechat.hook_config('plugins.var.python.' + SCRIPT_NAME + '.*', 'toggle_refresh', '')
        weechat.bar_item_new('spell_correction', 'show_spell_correction_item_cb', '')
    else:
        OPTIONS[option] = weechat.config_get_plugin(option)
    weechat.config_set_desc_plugin(option, '%s (default: "%s")' % (value[1], value[0]))


def toggle_refresh(pointer, name, value):
    global OPTIONS
    option = name[len("plugins.var.python." + SCRIPT_NAME + ".") :]  # get optionname
    OPTIONS[option] = value  # save new value
    weechat.bar_item_update(SCRIPT_NAME)
    return weechat.WEECHAT_RC_OK


# ================================[ main ]===============================
if __name__ == "__main__":
    if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT_DESC, "", ""):
        version = weechat.info_get("version_number", "") or 0

        if int(version) >= 0x00030600:
            bar_item = weechat.bar_item_new(SCRIPT_NAME, "show_item", "")
            weechat.bar_item_update(SCRIPT_NAME)
            weechat.hook_signal("buffer_line_added", "update_cb", "")
            weechat.hook_signal("window_scrolled", "update_cb", "")
            weechat.hook_signal("buffer_switch", "update_cb", "")
            weechat.hook_command_run("/buffer clear*", "update_cb", "")
            weechat.hook_command_run("/window page*", "update_cb", "")
            weechat.hook_config("plugins.var.python." + SCRIPT_NAME + ".*", "toggle_refresh", "")
            init_options()
        else:
            weechat.prnt("", "%s%s %s" % (weechat.prefix("error"), SCRIPT_NAME, ": needs version 0.3.6 or higher"))
Example #43
0
def config_changed(data, option, value):
    init_config()
    return w.WEECHAT_RC_OK

def tc_action_cb():
    global tc_options
    if tc_options['warn_command']:
        if tc_options['warn_command'] == '$bell':
            f = open('/dev/tty', 'w')
            f.write('\a')
            f.close()
        else:
            os.system(tc_options['warn_command'])
    return w.WEECHAT_RC_OK

if __name__ == "__main__" and import_ok:
    if w.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION,
                  SCRIPT_LICENSE, SCRIPT_DESC,
                  "", ""):
        version = w.info_get("version_number", "") or 0
        init_config() # read configuration
        tc_bar_item_update() # update status bar display

        w.hook_signal('input_text_changed', 'tc_bar_item_update', '')
        w.hook_signal('input_text_cursor_moved','tc_bar_item_update','')
        w.hook_command_run('/input move_previous_char','command_run_cb','')
        w.hook_command_run('/input delete_previous_char','command_run_cb','')
        w.hook_signal('buffer_switch','tc_bar_item_update','')
        w.hook_config('plugins.var.python.' + SCRIPT_NAME + ".*", "config_changed", "")
        w.bar_item_new('tc', 'tc_bar_item', '')
Example #44
0
#        return WEECHAT_RC_OK
    pos = weechat.buffer_get_integer(buffer, 'input_pos')
    #debug('%r %s %s' %(input, len(input), pos))
    if pos >= 8 and (pos == len(input) or input[pos] == ' '):
        n = input.rfind(' ', 0, pos)
        word = input[n+1:pos]
        #debug(word)
        if not word:
            return WEECHAT_RC_OK
        replace = ''
        if is_hexip(word):
            replace = hex_to_ip(word)
        elif is_ip(word):
            replace = ip_to_hex(word)
        if replace:
            n = len(word)
            weechat.buffer_set(buffer, 'input', '%s%s%s' %(input[:pos-n], replace, input[pos:]))
            weechat.buffer_set(buffer, 'input_pos', str(pos - n + len(replace)))
            return WEECHAT_RC_OK_EAT
    return WEECHAT_RC_OK

### Main ###
if __name__ == '__main__' and import_ok and \
        weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, \
        SCRIPT_DESC, '', ''):

    weechat.hook_command_run('/input complete_next', 'hexip_completion', '')

    
# vim:set shiftwidth=4 tabstop=4 softtabstop=4 expandtab textwidth=100:
Example #45
0

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 = re.match(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))
                postpone_data.setdefault(server, {}).setdefault(
                    channel, {}).setdefault(nick.lower(), []).append(input_s)
                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, "", ""):
    w.hook_command_run("/input return", "command_run_input", "")
    w.hook_signal('*,irc_in2_join', 'join_cb', '')
Example #46
0
def toggle_refresh(pointer, name, value):
    global OPTIONS
    option = name[len("plugins.var.python." + SCRIPT_NAME + ".") :]  # get optionname
    OPTIONS[option] = value  # save new value
    weechat.bar_item_update(SCRIPT_NAME)
    return weechat.WEECHAT_RC_OK


# ================================[ main ]===============================
if __name__ == "__main__":
    #    global filter_status
    if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT_DESC, "", ""):
        version = weechat.info_get("version_number", "") or 0

        if int(version) >= 0x00030600:
            filter_status = weechat.info_get("filters_enabled", "")
            bar_item = weechat.bar_item_new(SCRIPT_NAME, "show_item", "")
            weechat.bar_item_update(SCRIPT_NAME)
            weechat.hook_signal("buffer_line_added", "update_cb", "")
            weechat.hook_signal("window_scrolled", "update_cb", "")
            weechat.hook_signal("buffer_switch", "update_cb", "")
            weechat.hook_signal("filters_*", "filtered_update_cb", "")
            weechat.hook_command_run("/buffer clear*", "update_cb", "")
            weechat.hook_command_run("/window page*", "update_cb", "")
            weechat.hook_command_run("/input zoom_merged_buffer", "update_cb", "")
            weechat.hook_config("plugins.var.python." + SCRIPT_NAME + ".*", "toggle_refresh", "")
            init_options()
        else:
            weechat.prnt("", "%s%s %s" % (weechat.prefix("error"), SCRIPT_NAME, ": needs version 0.3.6 or higher"))
Example #47
0
            'HINTS:'
            '\n'
            'You have to set "aspell.check.suggestions" to a value >= 0 (default: -1 (off)).\n'
            'Using "aspell.check.real_time" the nick-completion will not work, until all misspelled words in input_line are replaced.\n'
            '\n'
            'You can bind following commands to key (as a fallback solution):\n'
            ' /' + SCRIPT_NAME +
            '           : to cycle though next suggestion\n'
            ' /' + SCRIPT_NAME +
            ' previous  : to cycle though previous suggestion\n'
            ' /' + SCRIPT_NAME + ' replace   : to replace misspelled word\n'
            '', 'previous|replace|addword', 'auto_suggest_cmd_cb', '')

        init_options()

        weechat.hook_command_run('/input delete_*', 'input_delete_cb', '')
        weechat.hook_command_run('/input move*', 'input_move_cb', '')
        weechat.hook_signal('input_text_changed', 'input_text_changed_cb', '')
        # multiline workaround
        weechat.hook_signal('input_flow_free', 'multiline_cb', '')

        weechat.hook_signal('aspell_suggest', 'aspell_suggest_cb', '')

        weechat.hook_signal('buffer_switch', 'buffer_switch_cb', '')
        weechat.hook_signal('window_switch', 'window_switch_cb', '')

        if OPTIONS['catch_input_completion'].lower() == "on":
            Hooks['catch_input_completion'] = weechat.hook_command_run(
                '/input complete*', 'input_complete_cb', '')
            Hooks['catch_input_return'] = weechat.hook_command_run(
                '/input return', 'input_return_cb', '')
Example #48
0
        servers = SearchList()
        for token in slack_api_token.split(','):
            servers.append(SlackServer(token))
        channels = Meta('channels', servers)
        users = Meta('users', servers)


        w.hook_config("plugins.var.python." + SCRIPT_NAME + ".*", "config_changed_cb", "")
        w.hook_timer(10, 0, 0, "async_queue_cb", "")
        w.hook_timer(6000, 0, 0, "slack_connection_persistence_cb", "")

        ### attach to the weechat hooks we need
        w.hook_timer(1000, 0, 0, "typing_update_cb", "")
        w.hook_timer(1000, 0, 0, "buffer_list_update_cb", "")
        w.hook_timer(1000, 0, 0, "hotlist_cache_update_cb", "")
        w.hook_timer(1000 * 3, 0, 0, "slack_never_away_cb", "")
        w.hook_timer(1000 * 60* 29, 0, 0, "slack_never_away_cb", "")
        w.hook_signal('buffer_closing', "buffer_closing_cb", "")
        w.hook_signal('buffer_switch', "buffer_switch_cb", "")
        w.hook_signal('window_switch', "buffer_switch_cb", "")
        w.hook_signal('input_text_changed', "typing_notification_cb", "")
        w.hook_command('slack','Plugin to allow typing notification and sync of read markers for slack.com', 'stuff', 'stuff2', '|'.join(cmds.keys()), 'slack_command_cb', '')
        w.hook_command('me','', 'stuff', 'stuff2', '', 'me_command_cb', '')
#        w.hook_command('me', 'me_command_cb', '')
        w.hook_command_run('/join', 'join_command_cb', '')
        w.hook_command_run('/part', 'part_command_cb', '')
        w.hook_command_run('/leave', 'part_command_cb', '')
        w.bar_item_new('slack_typing_notice', 'typing_bar_item_cb', '')
        ### END attach to the weechat hooks we need

Example #49
0
# script options
settings = {}

if w.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE,
              SCRIPT_DESC, "", ""):
    for option, default_value in settings.iteritems():
        if w.config_get_plugin(option) == "":
            w.config_set_plugin(option, default_value)

    # Hooks we want to hook
    hook_command_run = {
        "input": ("/input return", "command_run_input"),
    }
    # Hook all hooks !
    for hook, value in hook_command_run.iteritems():
        w.hook_command_run(value[0], value[1], "")


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.

        # Get input contents
        input_s = w.buffer_get_string(buffer, 'input')
        if input_s.startswith('/') and not input_s.startswith(
                '//') and not input_s.startswith('/me'):
            return w.WEECHAT_RC_OK
        # Transform it
        input_s = input_s.strip()
        # Spit it out
        w.buffer_set(buffer, 'input', input_s)
Example #50
0
latest_speaker = {}


def my_completer(data, buffer, command):
    global latest_speaker
    str_input = weechat.buffer_get_string(weechat.current_buffer(), "input")
    if command == "/input complete_next" and str_input == "":
        nick = latest_speaker.get(buffer, "")
        if nick != "":
            weechat.command(buffer, "/input insert " + nick)
    return weechat.WEECHAT_RC_OK


def hook_print_cb(data, buffer, date, tags, displayed, highlight, prefix, message):
    global latest_speaker
    if tags.find("irc_privmsg") >= 0:
        nick = prefix
        if re.match("^[@%+~*&!-]", nick):
            nick = nick[1:]
        local_nick = weechat.buffer_get_string(buffer, "localvar_nick")
        if nick != local_nick:
            latest_speaker[buffer] = nick
    return weechat.WEECHAT_RC_OK


if __name__ == "__main__" and import_ok:
    if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT_DESC, "", ""):
        weechat.hook_print("", "", "", 1, "hook_print_cb", "")
        weechat.hook_command_run("/input complete*", "my_completer", "")
Example #51
0

def signal_unaway(data, signal, signal_data):
    _action()
    return w.WEECHAT_RC_OK


def command_input(data, buffer, command):
    _action()
    return w.WEECHAT_RC_OK


if import_ok and w.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION,
                            SCRIPT_LICENSE, SCRIPT_DESC, "", ""):
    for name, (default, description) in SETTINGS.items():
        if not w.config_is_set_plugin(name):
            w.config_set_plugin(name, default)
            w.config_set_desc_plugin(name, description)

    # every 60 seconds, on 00
    w.hook_timer(60 * 1000, 60, 0, "idle_check", "")

    # these hooks are to also catch activity from weechat-android

    # catch us sending a PRIVMSG
    w.hook_signal("*,irc_out_privmsg", "signal_privmsg", "")
    # catch us no longer being marked as away, for manual /away
    w.hook_signal("*,irc_in_305", "signal_unaway", "")
    # catch weechat-android switching buffers
    w.hook_command_run("/input set_unread_current_buffer", "command_input", "")
Example #52
0
if __name__ == '__main__':
    global version
    if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION,
                        SCRIPT_LICENSE, SCRIPT_DESC, '', ''):
        version = weechat.info_get('version_number', '') or 0

        weechat.hook_command(
            SCRIPT_NAME, SCRIPT_DESC, 'last_written||last_sent',
            'script provide two items:\n'
            '"last_written", will print name of buffer you typed text last time\n'
            '"last_sent", will print name of buffer you sent text last time\n\n'
            'You can use both items with /eval or in /key using variable "${info:last_written}" and "${info:last_sent}"\n\n'
            'Example:\n'
            'bind key to jump to last buffer you sent text\n'
            ' /key bind meta-# /eval /buffer ${info:last_sent}\n'
            'creates an item for text_item.py script (item name ""ti_last_written"\n'
            ' /set plugins.var.python.text_item.ti_last_written "all|input_text_changed ${info:last_written} ${info:last_sent}"'
            '', '', '', '')

        weechat.bar_item_new(item_last_written, 'bar_item_last_written_cb', '')
        weechat.bar_item_new(item_last_sent, 'bar_item_last_sent_cb', '')
        weechat.hook_info('last_written',
                          'Return name of last buffer text was written', '',
                          'last_written_info_cb', '')
        weechat.hook_info('last_sent',
                          'Return name of last buffer text was sent', '',
                          'last_sent_info_cb', '')

        weechat.hook_command_run('/input return', 'input_return_cb', '')
        weechat.hook_signal('input_text_changed', 'input_text_changed_cb', '')
Example #53
0
    weechat.bar_item_update(SCRIPT_NAME)
    return weechat.WEECHAT_RC_OK


# ================================[ main ]===============================
if __name__ == "__main__":
    #    global filter_status
    if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION,
                        SCRIPT_LICENSE, SCRIPT_DESC, '', ''):
        version = weechat.info_get("version_number", "") or 0

        if int(version) >= 0x00030600:
            filter_status = int(weechat.info_get('filters_enabled', ''))
            bar_item = weechat.bar_item_new(SCRIPT_NAME, 'show_item', '')
            weechat.bar_item_update(SCRIPT_NAME)
            weechat.hook_signal('buffer_line_added', 'update_cb', '')
            weechat.hook_signal('window_scrolled', 'update_cb', '')
            weechat.hook_signal('buffer_switch', 'update_cb', '')
            weechat.hook_signal('*filters*', 'filtered_update_cb', '')
            weechat.hook_command_run('/buffer clear*', 'update_cb', '')
            weechat.hook_command_run('/window page*', 'update_cb', '')
            weechat.hook_command_run('/input zoom_merged_buffer', 'update_cb',
                                     '')
            weechat.hook_config('plugins.var.python.' + SCRIPT_NAME + '.*',
                                'toggle_refresh', '')
            init_options()
        else:
            weechat.prnt(
                '', '%s%s %s' % (weechat.prefix('error'), SCRIPT_NAME,
                                 ': needs version 0.3.6 or higher'))
Example #54
0
  
  blurb = re.sub(ur'\[(?P<markup>\w+)\]', lambda match: u'{0}'.format(markup2code(match.group(1))), blurb)
  blurb = re.sub(ur'\[(?P<foreground>\w+) (?P<background>\w+)\]', lambda match: u"\u0003{0},{1}".format(to_color(match.group(1)),to_color(match.group(2))), blurb)
  args = header  + ':' + blurb
  return args

def markup_autocomplete(data, buffer, command):
  str_input = weechat.buffer_get_string(weechat.current_buffer(), "input")
  if command == u"/input complete_next":# and str_input == '':
    try:
      last_pos = str_input.rindex('[')#fails if not found.
      last = str_input[last_pos:]
      first = str_input[:last_pos]
      for m in markup():
        if m.startswith(last) and m != last and last != "":
          weechat.command(buffer, '/input delete_line')
          weechat.command(buffer, "/input insert "+ first + m)
          break
    except ValueError:
      pass
  return weechat.WEECHAT_RC_OK

 
if __name__ == "__main__":
  if import_ok and weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT_DESC, "", ""):
    weechat.hook_modifier("irc_out1_privmsg", "process_markup", "")
    weechat.hook_modifier("irc_out1_topic", "process_markup", "")
    #attempt to autocomplete markup text in input area
    weechat.hook_command_run('/input complete*', 'markup_autocomplete', '')

Example #55
0
            SCRIPT_DESC,
            """""",  # TODO
            """Prepend to weechat.bar.buflist.items:
    go_buflist,

Append to buflist.look.display_conditions:
    && ${buffer.local_variables.go_buflist_hidden}==0

Prepend to buflist.format.buffer:
    ${eval:${plugins.var.python.go_buflist.format}}""",  # TODO
            """""".replace("\n", ""),  # TODO
            "command_cb",
            "")

        weechat.bar_item_new("(extra)%s" % SCRIPT_BAR_ITEM, "bar_item_cb", "")

        weechat.hook_command_run("/input *", "command_run_input_cb", "")
        weechat.hook_modifier("input_text_display_with_cursor",
                              "input_text_display_with_cursor_cb", "")

        for option, value in SETTINGS.items():
            if not weechat.config_is_set_plugin(option):
                weechat.config_set_plugin(option, value[0])

            weechat.config_set_desc_plugin(
                option, "%s (default: \"%s\")" % (value[1], value[0]))

        weechat.key_bind("default", KEYS)

        set_localvars("")
Example #56
0
    return weechat.WEECHAT_RC_OK

def hook_print_cb(data, buffer, date, tags, displayed, highlight, prefix, message):
    global latest_speaker
    nick = None
    if int(weechat_version) >= 0x00030400:
        # in version >= 0.3.4, there is a tag "nick_xxx" for each message
        alltags = tags.split(',')
        for tag in alltags:
            if tag.startswith('nick_'):
                nick = tag[5:]
                break
    else:
        # in older versions, no tag, so extract nick from printed message
        # this is working, except for irc actions (/me ...)
        if tags.find('irc_privmsg') >= 0:
            nick = prefix
            if re.match('^[@%+~*&!-]', nick):
                nick = nick[1:]
    if nick:
        local_nick = weechat.buffer_get_string(buffer, "localvar_nick")
        if nick != local_nick:
            latest_speaker[buffer] = nick
    return weechat.WEECHAT_RC_OK

if __name__ == "__main__" and import_ok:
    if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT_DESC, "", ""):
        weechat_version = weechat.info_get("version_number", "") or 0
        weechat.hook_print("", "", "", 1, "hook_print_cb", "")
        weechat.hook_command_run('/input complete*', 'my_completer', '')
Example #57
0
    if command == "/input return":
        # in case the line's empty, do nothing
        if uinput == "":
            return w.WEECHAT_RC_OK
        # bypass this using a backslash as the first character
        elif uinput.startswith("\\"):
            uinput = uinput.replace("\\", "", 1)
        # we don't want to capitalize basic URLs
        elif uinput[:4] == "http":  # I'M TOO LAZY FOR REGEX MATCHING
            return w.WEECHAT_RC_OK
        # if we point to a user, don't capitalise this
        elif isnick(buffer, uinput.split()[0][:-1]):
            return w.WEECHAT_RC_OK
        # if everything else is fine, replace the first char with its capital
        else:
            uinput = uinput.replace(uinput[0], uinput[0].upper(), 1)
        # set the new string into the input
        w.buffer_set(buffer, "input", uinput)
    return w.WEECHAT_RC_OK


if w.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE,
              SCRIPT_DESC, "", ""):
    for option, value in settings.items():
        if not w.config_is_set_plugin(option):
            w.config_set_plugin(option, value[0])
        w.config_set_desc_plugin(option,
                                 "%s (default '%s')" % (value[1], value[0]))
    w.hook_command_run("/input return", "word_magic", "")
Example #58
0
if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE,
                    SCRIPT_DESC, "", ""):

    for option, default_value in settings.iteritems():
        if weechat.config_get_plugin(option) == "":
            weechat.config_set_plugin(option, default_value)

    # Hooks we want to hook
    hook_command_run = {
        "input" : ("/input return",  "command_input_callback"),
    }

    # Hook all hooks !
    for hook, value in hook_command_run.iteritems():
        weechat.hook_command_run(value[0], value[1], "")

    weechat.hook_print("", "notify_message", "://", 1, "hook_print_callback", "")
    weechat.hook_print("", "notify_private", "://", 1, "hook_print_callback", "")
    weechat.hook_print("", "notify_highlight", "://", 1, "hook_print_callback", "")


def command_input_callback(data, buffer, command):
    """ Function called when a command "/input xxxx" is run """
    if command == '/input return':
        input = weechat.buffer_get_string(buffer, 'input')
        input = match_url(input, buffer, True)

        weechat.buffer_set(buffer, 'input', input)
    return weechat.WEECHAT_RC_OK