Example #1
0
def test_key():
    """Test key functions."""
    check(
        weechat.key_bind(
            'mouse', {
                '@chat(plugin.test):button1': 'hsignal:test_mouse',
                '@chat(plugin.test):wheelup': '/mycommand up',
                '@chat(plugin.test):wheeldown': '/mycommand down',
                '__quiet': '',
            }) == 3)
    check(weechat.key_unbind('mouse', 'quiet:area:chat(plugin.test)') == 3)
Example #2
0
def test_key():
    """Test key functions."""
    check(
        weechat.key_bind(
            'mouse',
            {
                '@chat(plugin.test):button1': 'hsignal:test_mouse',
                '@chat(plugin.test):wheelup': '/mycommand up',
                '@chat(plugin.test):wheeldown': '/mycommand down',
                '__quiet': '',
            }
        ) == 3)
    check(weechat.key_unbind('mouse', 'quiet:area:chat(plugin.test)') == 3)
Example #3
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 #4
0
		weechat.hook_signal("input_search", "input_search_cb", "")
		weechat.hook_signal("input_text_changed", "input_text_changed_cb", "")

		weechat.hook_command(SCRIPT_COMMAND, SCRIPT_DESC,
"""enable
 || disable
 || toggle""",
""" enable: enable {0} in current buffer
disable: disable {0} in current buffer
 toggle: toggle {0} in current buffer

By default a bind in "search" context is added to toggle with "ctrl-G".
To see {0} status during search, add "{1}" item to some bar. On default configuration you can do it with:
    /set weechat.bar.input.items "[input_prompt]+(away),[{1}],[input_search],[input_paste],input_text"

Due to technical reasons with /filter it is not possible to exactly {0} in "pre|msg" search mode, thus the bar item is shown in warning color.""".format(SCRIPT_NAME, SCRIPT_BAR_ITEM),
"""enable
 || disable
 || toggle""",
		"command_cb", "")

		weechat.bar_item_new("(extra)%s" % SCRIPT_BAR_ITEM, "bar_item_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("search", KEYS)
Example #5
0
        weechat.hook_command(
            SCRIPT_COMMAND,
            SCRIPT_DESC,
            """enable || disable || toggle""",
            """ enable: enable {0} in current buffer
disable: disable {0} in current buffer
 toggle: toggle {0} in current buffer

By default a bind in "search" context is added to toggle with "ctrl-G".
To see {0} status during search, add "{1}" item to some bar. On default configuration you can do it with:
    /set weechat.bar.input.items "[input_prompt]+(away),[{1}],[input_search],[input_paste],input_text"

Due to technical reasons with /filter it is not possible to exactly {0} in "pre|msg" search mode, thus the bar item is shown in warning color."""
            .format(SCRIPT_NAME, SCRIPT_BAR_ITEM),
            """enable || disable || toggle""",
            "command_cb",
            "",
        )

        weechat.bar_item_new("(extra)%s" % SCRIPT_BAR_ITEM, "bar_item_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("search", KEYS)
Example #6
0
def translate_cmd_cb(data, buffer, args):
    """Command /translate."""
    global translate

    # create keys (do NOT overwrite existing keys)
    if args == '-keys':
        rc = weechat.key_bind(
            'default', {
                'meta-tmeta-t': '/translate',
                'meta-tmeta-r': '/translate !',
                'meta-tmeta-w': '/translate +',
                'meta-tmeta-u': '/translate <'
            })
        weechat.prnt('', 'translate: %d keys added' % rc)
        return weechat.WEECHAT_RC_OK

    # undo last translation
    if args == '<':
        current_input = weechat.buffer_get_string(buffer, 'input')
        if translate['input_before'][
                0] and current_input != translate['input_before'][0]:
            weechat.buffer_set(buffer, 'input', translate['input_before'][0])
            weechat.buffer_set(buffer, 'input_pos',
                               '%d' % translate['input_before'][1])
        elif translate['input_after'][0] != '' and current_input != translate[
                'input_after'][0]:
            weechat.buffer_set(buffer, 'input', translate['input_after'][0])
            weechat.buffer_set(buffer, 'input_pos',
                               '%d' % translate['input_after'][1])
        return weechat.WEECHAT_RC_OK

    # default options
    translate['options'] = {
        'lang': weechat.config_get_plugin('from_to').split('_'),
        'word': False,
        'before_marker': '',
        'string': args
    }

    # read options in command arguments
    translate_extract_options(translate['options'])

    # if there's no string given as argument of command, then use buffer input
    extract = False
    if translate['options']['string'] == '':
        translate['options']['string'] = weechat.buffer_get_string(
            buffer, 'input')
        extract = True

    # keep only text after marker for translation
    marker = weechat.config_get_plugin('marker')
    if marker != '':
        pos = translate['options']['string'].find(marker)
        if pos >= 0:
            translate['options']['before_marker'] = translate['options'][
                'string'][0:pos]
            translate['options']['string'] = translate['options']['string'][
                pos + len(marker):]
            extract = True

    # read options in text
    if extract:
        translate_extract_options(translate['options'])

    # keep only last word if option "1 word" is enabled
    if translate['options']['word']:
        translate['options']['string'] = translate['options']['string'].split(
            ' ')[-1]

    # no text to translate? exit!
    if not translate['options']['string']:
        return weechat.WEECHAT_RC_OK

    # cancel current process if there is one
    if translate['hook_process']:
        weechat.unhook(translate['hook_process'])
        translate['hook_process'] = ''

    # translate!
    url = '%s?%s' % (weechat.config_get_plugin('url'),
                     urllib.urlencode({
                         'client': 't',
                         'sl': translate['options']['lang'][0],
                         'tl': translate['options']['lang'][1],
                         'text': translate['options']['string']
                     }))
    translate['stdout'] = ''
    translate['hook_process'] = weechat.hook_process_hashtable(
        'url:%s' % url, {'useragent': 'Mozilla/5.0'}, 10 * 1000,
        'translate_process_cb', '')

    return weechat.WEECHAT_RC_OK
Example #7
0
def translate_cmd_cb(data, buffer, args):
    """Command /translate."""
    global translate

    # create keys (do NOT overwrite existing keys)
    if args == '-keys':
        rc = weechat.key_bind('default', { 'meta-tmeta-t': '/translate',
                                           'meta-tmeta-r': '/translate !',
                                           'meta-tmeta-w': '/translate +',
                                           'meta-tmeta-u': '/translate <' })
        weechat.prnt('', 'translate: %d keys added' % rc)
        return weechat.WEECHAT_RC_OK

    # undo last translation
    if args == '<':
        current_input = weechat.buffer_get_string(buffer, 'input')
        if translate['input_before'][0] and current_input != translate['input_before'][0]:
            weechat.buffer_set(buffer, 'input', translate['input_before'][0])
            weechat.buffer_set(buffer, 'input_pos', '%d' % translate['input_before'][1])
        elif translate['input_after'][0] != '' and current_input != translate['input_after'][0]:
            weechat.buffer_set(buffer, 'input', translate['input_after'][0])
            weechat.buffer_set(buffer, 'input_pos', '%d' % translate['input_after'][1])
        return weechat.WEECHAT_RC_OK

    # default options
    translate['options'] = { 'lang': weechat.config_get_plugin('from_to').split('_'),
                             'word': False,
                             'before_marker': '',
                             'string': args }

    # read options in command arguments
    translate_extract_options(translate['options'])

    # if there's no string given as argument of command, then use buffer input
    extract = False
    if translate['options']['string'] == '':
        translate['options']['string'] = weechat.buffer_get_string(buffer, 'input')
        extract = True

    # keep only text after marker for translation
    marker = weechat.config_get_plugin('marker')
    if marker != '':
        pos = translate['options']['string'].find(marker)
        if pos >= 0:
            translate['options']['before_marker'] = translate['options']['string'][0:pos]
            translate['options']['string'] = translate['options']['string'][pos+len(marker):]
            extract = True

    # read options in text
    if extract:
        translate_extract_options(translate['options'])

    # keep only last word if option "1 word" is enabled
    if translate['options']['word']:
        translate['options']['string'] = translate['options']['string'].split(' ')[-1]

    # no text to translate? exit!
    if not translate['options']['string']:
        return weechat.WEECHAT_RC_OK

    # cancel current process if there is one
    if translate['hook_process']:
        weechat.unhook(translate['hook_process'])
        translate['hook_process'] = ''

    # translate!
    url = '%s?%s' % (weechat.config_get_plugin('url'), urllib.urlencode({'client': 't',
                                                                         'sl': translate['options']['lang'][0],
                                                                         'tl': translate['options']['lang'][1],
                                                                         'text': translate['options']['string'] }))
    translate['stdout'] = ''
    translate['hook_process'] = weechat.hook_process_hashtable('url:%s' % url,
                                                               { 'useragent': 'Mozilla/5.0' },
                                                               10 * 1000,
                                                               'translate_process_cb', '')

    return weechat.WEECHAT_RC_OK
Example #8
0
                        SCRIPT_DESC, '', ''):
        # set default settings
        version = weechat.info_get('version_number', '') or 0
        for option, value in minesweeper_settings_default.items():
            if weechat.config_is_set_plugin(option):
                minesweeper_settings[option] = weechat.config_get_plugin(option)
            else:
                weechat.config_set_plugin(option, value[0])
                minesweeper_settings[option] = value[0]
            if int(version) >= 0x00030500:
                weechat.config_set_desc_plugin(option, '%s (default: "%s")' % (value[2], value[0]))
        minesweeper_set_colors()

        # mouse support
        if int(version) >= 0x00030600:
            weechat.key_bind('mouse', minesweeper_mouse_keys)
            weechat.hook_hsignal('minesweeper_mouse', 'minesweeper_mouse_cb', '')

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

        # add command
        weechat.hook_command(SCRIPT_COMMAND, 'Minesweeper game.', '[16col|256col]',
                             '16col: set colors using basic colors (if your terminal or your WeeChat does not support 256 colors)\n'
                             '256col: set colors using 256 colors mode (default)\n\n'
                             '256 colors mode is highly recommended (WeeChat >= 0.3.5).\n'
                             'Mouse is recommended (WeeChat >= 0.3.6).\n\n'
                             'Instructions:\n'
                             '- use mouse left button (or alt-space) to explore a square, if you think there is no mine under '
                             '(if there is a mine, you lose!)\n'
                             '- use mouse right button (or alt-f) to put/remove flag on square, if you think there is a mine under\n'
Example #9
0
        # set default settings
        version = weechat.info_get("version_number", "") or 0
        for option, value in floodit_settings_default.items():
            if weechat.config_is_set_plugin(option):
                floodit_settings[option] = weechat.config_get_plugin(option)
            else:
                weechat.config_set_plugin(option, value[0])
                floodit_settings[option] = value[0]
            if int(version) >= 0x00030500:
                weechat.config_set_desc_plugin(
                    option, '%s (default: "%s")' % (value[1], value[0]))
        floodit_set_colors()

        # mouse support
        if int(version) >= 0x00030600:
            weechat.key_bind('mouse', floodit_mouse_keys)
            weechat.hook_hsignal('floodit_mouse', 'floodit_mouse_cb', '')

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

        # add command
        weechat.hook_command(
            SCRIPT_COMMAND, 'Flood'
            'it game.', '[single|versus]',
            'single: play in single mode (default)\n'
            'versus: play versus computer\n\n'
            'Single mode:\n'
            '- Choose a color for the upper left square, this will paint '
            'this square and all squares next to this one (having same color) '
Example #10
0
                        SCRIPT_DESC, '', ''):
        # set default settings
        version = weechat.info_get("version_number", "") or 0
        for option, value in floodit_settings_default.items():
            if weechat.config_is_set_plugin(option):
                floodit_settings[option] = weechat.config_get_plugin(option)
            else:
                weechat.config_set_plugin(option, value[0])
                floodit_settings[option] = value[0]
            if int(version) >= 0x00030500:
                weechat.config_set_desc_plugin(option, '%s (default: "%s")' % (value[1], value[0]))
        floodit_set_colors()

        # mouse support
        if int(version) >= 0x00030600:
            weechat.key_bind('mouse', floodit_mouse_keys)
            weechat.hook_hsignal('floodit_mouse', 'floodit_mouse_cb', '')

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

        # add command
        weechat.hook_command(SCRIPT_COMMAND, 'Flood''it game.', '[single|versus]',
                             'single: play in single mode (default)\n'
                             'versus: play versus computer\n\n'
                             'Single mode:\n'
                             '- Choose a color for the upper left square, this will paint '
                             'this square and all squares next to this one (having same color) '
                             'with your color.\n'
                             '- You win if all squares are same color.\n'
                             '- Maximum number of floods is 25, 35 or 50 (according to size).\n\n'
Example #11
0
        version = weechat.info_get('version_number', '') or 0
        for option, value in minesweeper_settings_default.items():
            if weechat.config_is_set_plugin(option):
                minesweeper_settings[option] = weechat.config_get_plugin(
                    option)
            else:
                weechat.config_set_plugin(option, value[0])
                minesweeper_settings[option] = value[0]
            if int(version) >= 0x00030500:
                weechat.config_set_desc_plugin(
                    option, '%s (default: "%s")' % (value[2], value[0]))
        minesweeper_set_colors()

        # mouse support
        if int(version) >= 0x00030600:
            weechat.key_bind('mouse', minesweeper_mouse_keys)
            weechat.hook_hsignal('minesweeper_mouse', 'minesweeper_mouse_cb',
                                 '')

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

        # add command
        weechat.hook_command(
            SCRIPT_COMMAND, 'Minesweeper game.', '[16col|256col]',
            '16col: set colors using basic colors (if your terminal or your WeeChat does not support 256 colors)\n'
            '256col: set colors using 256 colors mode (default)\n\n'
            '256 colors mode is highly recommended (WeeChat >= 0.3.5).\n'
            'Mouse is recommended (WeeChat >= 0.3.6).\n\n'
            'Instructions:\n'
Example #12
0
# (this script requires WeeChat 0.3.6 or newer)
#
# Quick hack, to get to know hsignals
# THIS SCRIPT HAS NO USE AT ALL!!! 

import weechat

SCRIPT_NAME = "whois"
SCRIPT_AUTHOR = "Banton"
SCRIPT_VERSION = "0.1"
SCRIPT_LICENSE = "GPL3"
SCRIPT_DESC = "whois via mouse in chat area"

keys = { "@chat(irc.*):w": "hsignal:chat_whois;/cursor stop" }

def whois_hsignal(data, signa, myhash):
    if not myhash["_chat_line_nick"]:
        return weechat.WEECHAT_RC_OK

    whois = "/whois %s" % myhash["_chat_line_nick"]
    weechat.command(myhash["_buffer_name"], whois)
    return weechat.WEECHAT_RC_OK

weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE,
SCRIPT_DESC, "", "")

weechat.key_bind("cursor", keys)

weechat.hook_hsignal("chat_whois", "whois_hsignal", "")

Example #13
0
        # set default settings
        version = weechat.info_get("version_number", "") or 0
        for ttt_option, ttt_value in tictactoe_settings_default.items():
            if weechat.config_is_set_plugin(ttt_option):
                tictactoe_settings[ttt_option] = weechat.config_get_plugin(
                    ttt_option)
            else:
                weechat.config_set_plugin(ttt_option, ttt_value[0])
                tictactoe_settings[ttt_option] = ttt_value[0]
            if int(version) >= 0x00030500:
                weechat.config_set_desc_plugin(
                    ttt_option,
                    '%s (default: "%s")' % (ttt_value[1], ttt_value[0]))

        # mouse support
        weechat.key_bind('mouse', tictactoe_mouse_keys)
        weechat.hook_hsignal('tictactoe_mouse', 'tictactoe_mouse_cb', '')

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

        # add command
        weechat.hook_command(
            SCRIPT_COMMAND, 'Tic-tac-toe game.', '', 'Instructions:\n'
            '  - enter one digit, or click with mouse in an empty cell to '
            'play\n'
            '  - you must align 3 symbols: horizontally, vertically or '
            'diagonally\n'
            '  - you win if you align the symbols before the computer\n'
            '  - there is a draw game if 3 symbols are not aligned at the end '
Example #14
0
if __name__ == '__main__' and import_ok:
    if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION,
                        SCRIPT_LICENSE, SCRIPT_DESC, '', ''):
        # set default settings
        for option, value in samegame_settings_default.items():
            if weechat.config_is_set_plugin(option):
                samegame_settings[option] = weechat.config_get_plugin(option)
            else:
                weechat.config_set_plugin(option, value[0])
                samegame_settings[option] = value[0]
            weechat.config_set_desc_plugin(
                option, '%s (default: "%s")' % (value[1], value[0]))
        samegame_set_colors()

        # mouse support
        weechat.key_bind('mouse', samegame_mouse_keys)
        weechat.hook_hsignal('samegame_mouse', 'samegame_mouse_cb', '')

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

        # add command
        weechat.hook_command(
            SCRIPT_COMMAND, 'Samegame.', '', 'Instructions:\n'
            '- click on a group of adjoining blocks of the same color to remove them from the screen\n'
            '- blocks that are no longer supported will fall down, and a column without any blocks will be trimmed away by other columns sliding to the left\n'
            '- your score is increased by (N-1)², where N is the number of blocks removed by your click\n'
            '- the game ends when you can not play any more.', '',
            'samegame_cmd_cb', '')
Example #15
0

if __name__ == "__main__" and import_ok:
    if weechat.register(SCRIPT_NAME, SCRIPT_AUTHOR, SCRIPT_VERSION, SCRIPT_LICENSE, SCRIPT_DESC, "", ""):
        # set default settings
        for option, value in samegame_settings_default.items():
            if weechat.config_is_set_plugin(option):
                samegame_settings[option] = weechat.config_get_plugin(option)
            else:
                weechat.config_set_plugin(option, value[0])
                samegame_settings[option] = value[0]
            weechat.config_set_desc_plugin(option, '%s (default: "%s")' % (value[1], value[0]))
        samegame_set_colors()

        # mouse support
        weechat.key_bind("mouse", samegame_mouse_keys)
        weechat.hook_hsignal("samegame_mouse", "samegame_mouse_cb", "")

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

        # add command
        weechat.hook_command(
            SCRIPT_COMMAND,
            "Samegame.",
            "",
            "Instructions:\n"
            "- click on a group of adjoining blocks of the same color to remove them from the screen\n"
            "- blocks that are no longer supported will fall down, and a column without any blocks will be trimmed away by other columns sliding to the left\n"
            "- your score is increased by (N-1)², where N is the number of blocks removed by your click\n"
            "- the game ends when you can not play any more.",