Example #1
0
def test_plugins():
    """Test plugins functions."""
    check(weechat.plugin_get_name('') == 'core')
    check(
        weechat.plugin_get_name(
            weechat.buffer_get_pointer(weechat.buffer_search_main(), 'plugin'))
        == 'core')
Example #2
0
def input_modifier_cb(data, modifier, modifier_data, string):
    """Modifier that will add help on command line (for display only)."""
    global cmdhelp_settings
    line = weechat.string_remove_color(string, '')
    if line == '':
        return string
    command = ''
    arguments = ''
    if weechat.string_input_for_buffer(line) != '':
        return string
    items = line.split(' ', 1)
    if len(items) > 0:
        command = items[0]
        if len(command) < 2:
            return string
        if len(items) > 1:
            arguments = items[1]
    if command[1:].lower() in cmdhelp_settings['ignore_commands'].split(','):
        return string
    plugin = weechat.buffer_get_pointer(weechat.current_buffer(), 'plugin')
    msg_help = get_help_command(plugin, command[1:],
                                arguments) or get_list_commands(
                                    plugin, command[1:], arguments)
    if not msg_help:
        if cmdhelp_settings['display_no_help'] != 'on':
            return string
        msg_help = weechat.color(cmdhelp_settings['color_no_help'])
        if command:
            msg_help += 'No help for command %s' % command
        else:
            msg_help += 'No help'
    color_delimiters = cmdhelp_settings['color_delimiters']
    return '%s  %s%s%s%s%s' % (
        string, weechat.color(color_delimiters), cmdhelp_settings['prefix'],
        msg_help, weechat.color(color_delimiters), cmdhelp_settings['suffix'])
Example #3
0
def input_modifier_cb(data, modifier, modifier_data, string):
    """Modifier that will add help on command line (for display only)."""
    global cmdhelp_settings
    line = weechat.string_remove_color(string, '')
    if line == '':
        return string
    command = ''
    arguments = ''
    if weechat.string_input_for_buffer(line) != '':
        return string
    items = line.split(' ', 1)
    if len(items) > 0:
        command = items[0]
        if len(command) < 2:
            return string
        if len(items) > 1:
            arguments = items[1]
    if command[1:].lower() in cmdhelp_settings['ignore_commands'].split(','):
        return string
    current_buffer = weechat.current_buffer()
    current_window = weechat.current_window()
    plugin = weechat.buffer_get_pointer(current_buffer, 'plugin')
    msg_help = (get_help_command(plugin, command[1:], arguments) or
                get_list_commands(plugin, command[1:], arguments))
    if not msg_help:
        if cmdhelp_settings['display_no_help'] != 'on':
            return string
        msg_help = weechat.color(cmdhelp_settings['color_no_help'])
        if command:
            msg_help += 'No help for command %s' % command
        else:
            msg_help += 'No help'

    if cmdhelp_settings['right_align'] == 'on':
        win_width = weechat.window_get_integer(current_window, 'win_width')
        input_length = weechat.buffer_get_integer(current_buffer,
                                                  'input_length')
        help_length = len(weechat.string_remove_color(msg_help, ""))
        min_space = int(cmdhelp_settings['space'])
        padding = int(cmdhelp_settings['right_padding'])
        space = win_width - input_length - help_length - padding
        if space < min_space:
            space = min_space
    else:
        space = int(cmdhelp_settings['space'])

    color_delimiters = cmdhelp_settings['color_delimiters']
    return '%s%s%s%s%s%s%s' % (string,
                               space * ' ',
                               weechat.color(color_delimiters),
                               cmdhelp_settings['prefix'],
                               msg_help,
                               weechat.color(color_delimiters),
                               cmdhelp_settings['suffix'])
Example #4
0
def input_modifier_cb(data, modifier, modifier_data, string):
    """Modifier that will add help on command line (for display only)."""
    global cmdhelp_settings
    line = weechat.string_remove_color(string, '')
    if line == '':
        return string
    command = ''
    arguments = ''
    if weechat.string_input_for_buffer(line) != '':
        return string
    items = line.split(' ', 1)
    if len(items) > 0:
        command = items[0]
        if len(command) < 2:
            return string
        if len(items) > 1:
            arguments = items[1]
    if command[1:].lower() in cmdhelp_settings['ignore_commands'].split(','):
        return string
    current_buffer = weechat.current_buffer()
    current_window = weechat.current_window()
    plugin = weechat.buffer_get_pointer(current_buffer, 'plugin')
    msg_help = get_help_command(plugin, command[1:],
                                arguments) or get_list_commands(
                                    plugin, command[1:], arguments)
    if not msg_help:
        if cmdhelp_settings['display_no_help'] != 'on':
            return string
        msg_help = weechat.color(cmdhelp_settings['color_no_help'])
        if command:
            msg_help += 'No help for command %s' % command
        else:
            msg_help += 'No help'

    if cmdhelp_settings['right_align'] == 'on':
        win_width = weechat.window_get_integer(current_window, 'win_width')
        input_length = weechat.buffer_get_integer(current_buffer,
                                                  'input_length')
        help_length = len(weechat.string_remove_color(msg_help, ""))
        min_space = int(cmdhelp_settings['space'])
        padding = int(cmdhelp_settings['right_padding'])
        space = win_width - input_length - help_length - padding
        if space < min_space:
            space = min_space
    else:
        space = int(cmdhelp_settings['space'])

    color_delimiters = cmdhelp_settings['color_delimiters']
    return '%s%s%s%s%s%s%s' % (
        string, space * ' ',
        weechat.color(color_delimiters), cmdhelp_settings['prefix'], msg_help,
        weechat.color(color_delimiters), cmdhelp_settings['suffix'])
Example #5
0
def input_modifier_cb(data, modifier, modifier_data, string):
    """Modifier that will add help on command line (for display only)."""
    global cmdhelp_settings
    line = weechat.string_remove_color(string, '')
    if line == '':
        return string
    command = ''
    arguments = ''
    if weechat.string_input_for_buffer(line) != '':
        return string
    items = line.split(' ', 1)
    if len(items) > 0:
        command = items[0]
        if len(command) < 2:
            return string
        if len(items) > 1:
            arguments = items[1]
    if command[1:].lower() in cmdhelp_settings['ignore_commands'].split(','):
        return string
    plugin = weechat.buffer_get_pointer(weechat.current_buffer(), 'plugin')
    msg_help = get_help_command(plugin, command[1:], arguments) or get_list_commands(plugin, command[1:], arguments)
    if not msg_help:
        if cmdhelp_settings['display_no_help'] != 'on':
            return string
        msg_help = weechat.color(cmdhelp_settings['color_no_help'])
        if command:
            msg_help += 'No help for command %s' % command
        else:
            msg_help += 'No help'
    color_delimiters = cmdhelp_settings['color_delimiters']
    return '%s  %s%s%s%s%s' % (string,
                               weechat.color(color_delimiters),
                               cmdhelp_settings['prefix'],
                               msg_help,
                               weechat.color(color_delimiters),
                               cmdhelp_settings['suffix'])
Example #6
0
def test_plugins():
    """Test plugins functions."""
    check(weechat.plugin_get_name('') == 'core')
    check(weechat.plugin_get_name(weechat.buffer_get_pointer(weechat.buffer_search_main(), 'plugin')) == 'core')
Example #7
0
def buf_get(ctx, known):
	global _tmp_room_queue_hash, _tmp_room_initial

	haveBzz = False
	# \todo integrity check of input data
	bufname = ctx.to_buffer_name()

	wOut(
		PSS_BUFPFX_DEBUG,
		[],
		"!!!",
		"generated bufname " + bufname
	)

	buf = weechat.buffer_search("python", bufname)

	if ctx.is_room() and ctx.get_bzz() == None:
		raise RuntimeError("gateway needed for multiuser chats over swarm")

	
	if buf == "":

		# for debug only
		pss_publickey_hex = pss.rpchex(ctx.get_pss().get_public_key())
		pss_overlay_hex = pss.rpchex(ctx.get_pss().get_overlay())

		# chat is DM between two parties
		if ctx.is_chat():
		
			shortname = "pss:" + ctx.get_name()
			# set up the buffer
			ctx.set_buffer(weechat.buffer_new(bufname, "buf_in", ctx.get_node(), "buf_close", ctx.get_node()), bufname)
			weechat.buffer_set(ctx.get_buffer(), "short_name", shortname)
			weechat.buffer_set(ctx.get_buffer(), "title", ctx.get_name() + " @ PSS '" + ctx.get_node() + "' | node: " + weechat.config_get_plugin(ctx.get_pss().get_host() + "_url") + ":" + weechat.config_get_plugin(ctx.get_pss().get_port() + "_port") + " | key  " + pss.label(pss_publickey_hex) + " | address " + pss.label(pss_overlay_hex))
			weechat.buffer_set(ctx.get_buffer(), "hotlist", weechat.WEECHAT_HOTLIST_PRIVATE)
			weechat.buffer_set(ctx.get_buffer(), "display", "1")
			plugin = weechat.buffer_get_pointer(ctx.get_buffer(), "plugin")

			bufs[bufname] = buf


		# room is multiuser conversation
		elif ctx.is_room():
	
			shortname = "pss#" + ctx.get_name()

			buf = weechat.buffer_new(bufname, "buf_in", ctx.get_node(), "buf_close", ctx.get_node())
			weechat.buffer_set(buf, "short_name", shortname)
			weechat.buffer_set(buf, "title", "#" + ctx.get_node() + " @ PSS '" + ctx.get_node() + "' | node: " + weechat.config_get_plugin(ctx.get_pss().get_host() + "_url") + ":" + weechat.config_get_plugin(ctx.get_pss().get_port() + "_port") + " | key  " + pss.label(ctx.get_pss().get_public_key().encode("hex")) + " | address " + pss.label(ctx.get_pss().get_overlay().encode("hex")))
			weechat.buffer_set(buf, "hotlist", weechat.WEECHAT_HOTLIST_PRIVATE)
			weechat.buffer_set(buf, "nicklist", "1")
			weechat.buffer_set(buf, "display", "1")
			weechat.nicklist_add_group(buf, "", "me", "weechat.color.nicklist_group", 1)
			weechat.nicklist_add_nick(buf, "me", ctx.get_node(), "bar_fg", "", "bar_fg", 1)
	
			plugin = weechat.buffer_get_pointer(buf, "plugin")
			bufs[bufname] = buf
			
			if cache.get_room_count() == 0:
				hookTimers.append(weechat.hook_timer(PSS_ROOM_PERIOD, 0, 0, "roomRead", ctx.get_node()))

			# create new room
			(room, loaded) = cache.add_room(ctx.get_name(), ctx.get_node())
			_tmp_room_initial[ctx.get_name()] = False
			if loaded:
				_tmp_room_queue_hash[ctx.get_name()] = room.feedcollection.senderfeed.lasthsh
				try:
					cache.have_room_initial(ctx.get_name())
					_tmp_room_initial[ctx.get_name()] = True
				except Exception as e:
					sys.stderr.write("no initial update, not pulling: " + repr(e) + "\n")

			wOut(
				PSS_BUFPFX_DEBUG,
				[],
				"",
				"loaded room " + repr(cache.get_room(ctx.get_name()))
			)

			for p in room.get_participants():
				pubkey = p.get_public_key()
				if pubkey == ctx.get_pss().get_public_key():
					continue
				nick = ""
				try:
					c = cache.get_contact_by_public_key(pubkey)
					nick = c.get_nick()
					buf_room_add(buf, c.get_nick())
				except:
					nick = p.get_nick()
				buf_room_add(buf, nick)

		else:
			raise RuntimeError("invalid buffer type")

	else:
		ctx.set_buffer(buf, bufname)

	return ctx.get_buffer()
Example #8
0
def buf_get(pssName, typ, name, known):

    haveBzz = False
    # \todo integrity check of input data
    bufname = buf_generate_name(pssName, typ, name)

    wOut(
        PSS_BUFPFX_DEBUG, [], "!!!", "generated bufname " + bufname + " for " +
        pssName + " / " + typ + " / " + name)

    try:
        buf = weechat.buffer_search("python", bufname)
    # \todo re-evaluate why exception can occur here, and which one specifically
    except Exception as e:
        return ""

    if pssName in bzzs:
        haveBzz = True
    elif typ == "room":
        raise RuntimeException("gateway needed for multiuser chats over swarm")

    if buf == "":

        shortname = ""

        # chat is DM between two parties
        if typ == "chat":
            ispubkey = False
            if known:
                shortname = "pss:" + name
            else:
                shortname = "pss:" + name[:8]
                ispubkey = True

            buf = weechat.buffer_new(bufname, "buf_in", pssName, "buf_close",
                                     pssName)
            weechat.buffer_set(buf, "short_name", shortname)
            weechat.buffer_set(
                buf, "title", name + " @ PSS '" + pssName + "' | node: " +
                weechat.config_get_plugin(psses[pssName].host + "_url") + ":" +
                weechat.config_get_plugin(psses[pssName].port + "_port") +
                " | key  " + pss.label(psses[pssName].key) + " | address " +
                pss.label(psses[pssName].base))
            weechat.buffer_set(buf, "hotlist", weechat.WEECHAT_HOTLIST_PRIVATE)
            weechat.buffer_set(buf, "display", "1")
            plugin = weechat.buffer_get_pointer(buf, "plugin")
            bufs[bufname] = buf
            debugstr = "have " + repr(
                psses[pssName].have_account()) + " + " + repr(haveBzz)
            wOut(PSS_BUFPFX_DEBUG, [], "have", debugstr)

            if psses[pssName].have_account() and haveBzz:
                pubkey = ""
                if ispubkey:
                    pubkey = name.decode("hex")
                else:
                    pubkey = remotekeys[name].decode("hex")
                    pubkey = "\x04" + pubkey
                try:
                    feeds[bufname] = pss.Feed(
                        bzzs[pssName].agent, psses[pssName].get_account(),
                        PSS_BUFTYPE_CHAT + pss.publickey_to_account(pubkey))
                    wOut(
                        PSS_BUFPFX_DEBUG, [], "", "added feed with topic " +
                        feeds[bufname].topic.encode("hex"))
                except ValueError as e:
                    wOut(PSS_BUFPFX_ERROR, [], "???",
                         "could not set up feed: " + str(e))

        # room is multiuser conversation
        elif typ == "room":

            shortname = "pss#" + name

            buf = weechat.buffer_new(bufname, "buf_in", pssName, "buf_close",
                                     pssName)
            weechat.buffer_set(buf, "short_name", shortname)
            weechat.buffer_set(
                buf, "title",
                "#" + name + " @ PSS '" + pssName + "' | node: " +
                weechat.config_get_plugin(psses[pssName].host + "_url") + ":" +
                weechat.config_get_plugin(psses[pssName].port + "_port") +
                " | key  " + pss.label(psses[pssName].key) + " | address " +
                pss.label(psses[pssName].base))
            weechat.buffer_set(buf, "hotlist", weechat.WEECHAT_HOTLIST_PRIVATE)
            weechat.buffer_set(buf, "nicklist", "1")
            weechat.buffer_set(buf, "display", "1")
            #weechat.nicklist_add_group(buf, "", "me", "weechat.color.nicklist_group", 1)
            #weechat.nicklist_add_nick(buf, "me", psses[pssName].name, "bar_fg", "", "bar_fg", 1)

            plugin = weechat.buffer_get_pointer(buf, "plugin")
            bufs[bufname] = buf

            if len(rooms) == 0:
                hookTimers.append(
                    weechat.hook_timer(roomPeriod, 0, 0, "roomRead",
                                       psses[pssName].name))
            rooms[bufname] = pss.Room(bzzs[pssName], name,
                                      psses[pssName].get_account())
            # \todo test load first, only init if not found
            try:
                roomhsh = rooms[bufname].get_state_hash()
                rooms[bufname].load(roomhsh, psses[pssName].get_account())
                wOut(
                    PSS_BUFPFX_DEBUG, [], "", "loaded room with topic " +
                    rooms[bufname].feed_out.topic.encode("hex") + " account " +
                    rooms[bufname].feed_out.account.address.encode("hex") +
                    " roomfeed " +
                    rooms[bufname].feed_room.topic.encode("hex"))
                for k, p in rooms[bufname].participants.iteritems():
                    nick = ""
                    if p.key == selfs[pssName].key:
                        nick = selfs[pssName].nick
                    else:
                        if not p.key in nicks:
                            nicks[p.nick] = pss.PssContact(
                                p.nick, p.key, p.addr, p.src)
                            remotekeys[p.key] = p.nick
                        nick = nicks[p.key].nick
                    buf_room_add(buf, nick)
            # \todo correct expect to disambiguate unexpected fails
            except Exception as e:
                wOut(PSS_BUFPFX_DEBUG, [], "", "fail room load: " + str(e))
                rooms[bufname].start(PSS_DEFAULT_NICK)
                wOut(
                    PSS_BUFPFX_DEBUG, [], "", "added room with topic " +
                    rooms[bufname].feed_out.topic.encode("hex") + " account " +
                    rooms[bufname].feed_out.account.address.encode("hex") +
                    " roomfeed " +
                    rooms[bufname].feed_room.topic.encode("hex"))
        else:
            raise RuntimeError("invalid buffer type")

    return buf