Example #1
0
def test_jsonpluginpref():
    prefs = JSONPluginPref("json_prefs_test")
    other_pref_keys = hexchat.list_pluginpref()

    # perform core tests too
    core_pluginpref_tests(prefs)

    # additional tests
    a_list = list(range(10))
    a_dict = {chr(ord('A') + i): i for i in range(10)}

    prefs['a_list'] = a_list
    assert hexchat.get_pluginpref(prefs.prefix + prefs.prefix_sep + "a_list") == json.dumps(a_list)

    prefs['a_dict'] = a_dict
    assert hexchat.get_pluginpref(prefs.prefix + prefs.prefix_sep + "a_dict") == json.dumps(a_dict)
    prefs['null'] = None
    assert hexchat.get_pluginpref(prefs.prefix + prefs.prefix_sep + "null") == 'null'

    assert dict(prefs.items()) == dict([('a_list', a_list),
                                        ('a_dict', a_dict),
                                        ('null', None)])

    for key in prefs:
        prefs.delete(key)
    assert not prefs

    assert other_pref_keys == hexchat.list_pluginpref()
    print("test_jsonpluginpref passed")
Example #2
0
def core_pluginpref_tests(prefs):
    # initial cleanup
    for key in prefs:
        prefs.delete(key)
    assert not prefs  # Should be empty!

    other_pref_keys = hexchat.list_pluginpref()

    assert list(prefs.items()) == []
    assert "mute" not in prefs
    prefs["mute"] = "#test"
    assert "mute" in prefs
    assert (prefs["mute"] == "#test")

    assert prefs.get("mute", 12) == "#test"
    assert prefs.get("mute2", 12) == 12
    assert prefs.setdefault("mute", 32) == "#test"
    assert prefs.setdefault("mute2", 32) == 32

    assert dict(prefs.items()) == dict([('mute2', 32), ('mute', '#test')])
    all_prefs = (set(map(lambda x: prefs.prefix + prefs.prefix_sep + x, prefs.keys()))
                 | set(other_pref_keys))
    assert all_prefs == set(hexchat.list_pluginpref())
    assert len(prefs) == 2

    del prefs["mute"]
    assert "mute" not in prefs
    try:
        del prefs["mute"]
        assert False, "should have raised"
    except KeyError:
        pass
    prefs.delete("mute2")
    assert not prefs
    assert other_pref_keys == hexchat.list_pluginpref()
Example #3
0
def save_pref(resp_list):
    for pref in hexchat.list_pluginpref():
        if pref.startswith(ELEM_PREFIX):
            hexchat.del_pluginpref(pref)
    for resp in resp_list:
        for rpk, rpv in resp.getPrefs().items():
            hexchat.set_pluginpref(rpk, rpv)
Example #4
0
def onCommand(words, words_eol, userdata):
    if (len(words) < 2):
        print(command_help)
    else:
        if words[1] == 'config':
            if len(words) > 2:
                if words[2] == 'help':
                    result = '\n'.join(['   \002' + key + '\002  =>  ' + value for key, value in available_config.items()])
                    print('Available configuration:\n\n' + result)
                elif words[2] == 'set':
                    if (len(words) < 5):
                        print(command_help)
                    else:
                        hexchat.set_pluginpref(config_prefix + words[3], words_eol[4])
                        print('\002' + words[3] + '\002 has been set to \002' + words_eol[4] + '\002')
                elif words[2] == 'unset':
                    if (len(words) < 4):
                        print(command_help)
                    else:
                        hexchat.del_pluginpref(config_prefix + words[3])
                        print('\002' + words[3] + '\002 has been unset')
                else:
                    print(command_help)
            else:
                prefs_list = hexchat.list_pluginpref()
                result = '{\n'
                for pref in prefs_list:
                    if pref[:9] == config_prefix:
                        result = result + '    \002' + pref[len(config_prefix):] + '\002\00314 : \003\002' + hexchat.get_pluginpref(pref) + '\002\n'
                result = result + '}'
                print(result)
        else:
            print('wat')
    return hexchat.EAT_ALL
Example #5
0
def setup_channels(word, word_eol, user_data):
    # Callback for: server motd-received event
    # Unhook and /join channels
    hexchat.unhook(setup_channels)
    hexchat.prnt('FOOOOOOOOOOOOOOOOOO')
    x = hexchat.list_pluginpref()
    hexchat.prnt(x)
def shign_load_list(word=None,word_eol=None,userdata=None):
    global shign_prefix
    global shign_pluginpref_list
    global shign_list
    global shign_list_last_idx
    All_Prefs = hexchat.list_pluginpref()
    shign_pluginpref_list = []
    shign_list = []
    shign_list_last_idx = 0
    if len(All_Prefs) == 0:
        #print('empty') #list is empty
        shign_list = [['shign1','All']]
        hexchat.set_pluginpref('shign1','All')
        shign_list_last_idx = 1
        return
    for Prefs in All_Prefs:
        if Prefs.find(shign_prefix) != -1: #if the prefix is found
            shign_pluginpref_list.append(Prefs) #append to the list of prefs
            if int(Prefs[5:]) > shign_list_last_idx:
                shign_list_last_idx = int(Prefs[5:])
    #print(shignpreflist)
    for shign_pluginpref in shign_pluginpref_list:
        temp_list = hexchat.get_pluginpref(shign_pluginpref).split()
        temp_list.insert(0, shign_pluginpref)
        shign_list.append(temp_list)
    print(__module_name__+'\tList loaded!')
Example #7
0
def load_pref():
    resp_list = []
    for pref in hexchat.list_pluginpref():
        if pref.startswith(ELEM_PREFIX + "name"):
            name = hexchat.get_pluginpref(pref)
            resp_list.append(Respoon.loadFromPref(name,
                                                  hexchat.get_pluginpref))
    return resp_list
def twtwlist_cb(word, word_eol, userdata):
    global twtwset_help_text, pluginprefix
    for key in hexchat.list_pluginpref():
        if key.startswith(pluginprefix):
            cleanKey = key[len(pluginprefix):]
            print("{0} = {1}".format(cleanKey, get_pref(cleanKey)))

    return hexchat.EAT_ALL
Example #9
0
def loadpm_cb(word, word_eol, userdata):
    #TODO: save dialogs to a single user across multiple networks
    for pref in hexchat.list_pluginpref():
        if pref[:10] == "persistpm_":
            saved_network = hexchat.get_pluginpref(pref)
            if saved_network == hexchat.get_info("network"):
                saved_nick = pref[10:]
                network_context = hexchat.find_context(channel=saved_network)
                network_context.command("QUERY {}".format(saved_nick))
Example #10
0
 def keys(self):
     """Return a set of all keys in this PluginPref instance."""
     shared_prefix = self._keyname()
     all_keys = hexchat.list_pluginpref()
     keys = set()
     for key in all_keys:
         if key.startswith(shared_prefix):
             keys.add(key[len(shared_prefix):])
     return keys
Example #11
0
def load_aliases():
    for pref in hexchat.list_pluginpref():
        if pref[:6] == 'alias_':
            name = pref[6:]
            hook = hexchat.hook_command(
                name,
                alias_cmd_cb,
                help='Alias: "{}" is an alias for "{}"'.format(
                    name, get_alias(name)))
            alias_hooks[name] = hook
Example #12
0
def set_option(word):
    if len(word) == 2:
        for l in [x for x in hexchat.list_pluginpref() if x.startswith("privacy_")]:
            print(l, "=", hexchat.get_pluginpref(l))
    elif len(word) == 4:
        k, v = word[2], word[3]
        hexchat.set_pluginpref(k, v)
        configure_hexchat()
        print(k, "=", v)
    else:
        do_help()
Example #13
0
def load_bookmarks():
	hexchat.command('menu -p-2 add "$TAB/Bookmark" "bookmark %s"')
	hexchat.command('menu add "$CHAN/Bookmark Channel" "bookmark %s"')
	hexchat.command('menu -p3 add "Bookmarks"')
	hexchat.command('menu add "Bookmarks/-"')
	hexchat.command('menu add "Bookmarks/Add or Remove Current Channel" "bookmark"')
	for pref in hexchat.list_pluginpref():
		if pref[:9] == 'bookmark_':
			chan = pref[9:]
			for net in get_networks(chan):
				hexchat.command('menu -p-2 add "Bookmarks/{}'.format(net))
				hexchat.command('menu add "Bookmarks/{0}/{1}" "netjoin {1} {0}"'.format(net, chan))
Example #14
0
def load_bookmarks():
	hexchat.command('menu -p-2 add "$TAB/Bookmark" "bookmark %s"')
	hexchat.command('menu add "$CHAN/Bookmark Channel" "bookmark %s"')
	hexchat.command('menu -p-3 add "Bookmarks"')
	hexchat.command('menu add "Bookmarks/-"')
	hexchat.command('menu add "Bookmarks/Add or Remove Current Channel" "bookmark"')
	for pref in hexchat.list_pluginpref():
		if pref[:9] == 'bookmark_':
			chan = pref[9:]
			for net in get_networks(chan):
				hexchat.command('menu -p-2 add "Bookmarks/{}'.format(net))
				hexchat.command('menu add "Bookmarks/{0}/{1}" "netjoin {1} {0}"'.format(net, chan))
Example #15
0
def set_option(word):
    if len(word) == 2:
        for l in [
                x for x in hexchat.list_pluginpref()
                if x.startswith("privacy_")
        ]:
            print(l, "=", hexchat.get_pluginpref(l))
    elif len(word) == 4:
        k, v = word[2], word[3]
        hexchat.set_pluginpref(k, v)
        configure_hexchat()
        print(k, "=", v)
    else:
        do_help()
Example #16
0
def get_tab_data():
    # Returns a dict of network=[channels]. Uses addon_python.conf:
    # session_freenode = #test,#foo
    # list_pluginpref() returns the key 'session_freenode'
    # get_pluginpref('session_freenode') returns the comma delimited channel list
    tab_data = {}
    for pref in hexchat.list_pluginpref():
        if len(pref) > 8 and pref[:8] == 'session_':
            network = pref[8:]
            channels = hexchat.get_pluginpref('session_' + network).split(',')
            if len(channels):
                tab_data[network] = channels
            else:
                tab_data[network] = None
    return tab_data
Example #17
0
def load_session():
	for pref in hexchat.list_pluginpref():
		if len(pref) > 8 and pref[:8] == 'session_':
			network = pref[8:]
			channels = hexchat.get_pluginpref('session_' + network).split(',')
			hexchat.command('url irc://"{}"/'.format(network)) # Using url avoids autojoin
			hexchat.find_context(server=network).set()
			delay = hexchat.get_prefs('irc_join_delay') + 10
			for chan in channels:
				if chan[0] != '#':
					hexchat.command('timer {} query -nofocus {}'.format(delay, chan))
				else:
					hexchat.command('timer {} join {}'.format(delay, chan))

			hexchat.del_pluginpref('session_' + network)
Example #18
0
def load_session():
    for pref in hexchat.list_pluginpref():
        if len(pref) > 8 and pref[:8] == 'session_':
            network = pref[8:]
            channels = hexchat.get_pluginpref('session_' + network).split(',')
            hexchat.command(
                'url irc://"{}"/'.format(network))  # Using url avoids autojoin
            hexchat.find_context(server=network).set()
            delay = hexchat.get_prefs('irc_join_delay') + 10
            for chan in channels:
                if chan[0] != '#':
                    hexchat.command('timer {} query -nofocus {}'.format(
                        delay, chan))
                else:
                    hexchat.command('timer {} join {}'.format(delay, chan))

            hexchat.del_pluginpref('session_' + network)
def load_jpfilters():
    global network_lst
    global channel_lst
    global chan_net_lst
    # reset the lists so that the script doesn't have to be reloaded
    network_lst = []
    channel_lst = []
    chan_net_lst = []
    for pref in hexchat.list_pluginpref():
        if pref[:6] == "jptab_":
            if pref[6] == "#":
                channel = pref[6:]
                network = get_network(channel)
                channel_lst.append(channel)
                chan_net_lst.append(network)
            else:
                network = pref[6:]
                network_lst.append(network)
Example #20
0
def load_jpfilters():
    global network_lst
    global channel_lst
    global chan_net_lst
    # reset the lists so that the script doesn't have to be reloaded
    network_lst = []
    channel_lst = []
    chan_net_lst = []
    for pref in hexchat.list_pluginpref():
        if pref[:6] == "jptab_":
            if pref[6] == "#":
                channel = pref[6:]
                network = get_network(channel)
                channel_lst.append(channel)
                chan_net_lst.append(network)
            else:
                network = pref[6:]
                network_lst.append(network)
Example #21
0
def aliases_cb(word, word_eol, userdata):
    print('\026{0: <10}{1: <50}'.format('NAME', 'CMD'))
    for pref in hexchat.list_pluginpref():
        if pref[:6] == 'alias_':
            print('{0: <10}{1: <50}'.format(pref[6:], get_alias(pref[6:])))
    return hexchat.EAT_ALL
Example #22
0
def load_aliases ():
	for pref in hexchat.list_pluginpref():
		if pref[:6] == 'alias_':
			name = pref[6:]
			hook = hexchat.hook_command(name, alias_cmd_cb, help='Alias: "{}" is an alias for "{}"'.format(name, get_alias(name)))
			alias_hooks[name] = hook
Example #23
0
            del channel_keys[server + channel]
        hexchat.prnt('AESKEY: key for {} @ {} cleared'.format(channel, server))
        return hexchat.EAT_ALL
    if len(server) == 0 or '#' not in channel:
        hexchat.prnt('AESKEY: no key set; use while in a channel')
        return hexchat.EAT_ALL
    channel_keys[server + channel] = word[1]
    # base64 encode so passwords don't show up with grep or something similar
    hexchat.set_pluginpref(
        __module_name__, base64.standard_b64encode(repr(channel_keys))
    )
    hexchat.prnt('AESKEY: key for {} @ {} set'.format(channel, server))
    return hexchat.EAT_ALL


if __module_name__ in hexchat.list_pluginpref():
    import ast
    keys_b64 = hexchat.get_pluginpref(__module_name__)
    try:
        keys_string = base64.standard_b64decode(keys_b64)
        channel_keys = ast.literal_eval(keys_string)
    except TypeError as ex:
        pass


hexchat.hook_print('Channel Message', decrypt_privmsg)
hexchat.hook_command('', encrypt_privmsg)  # sending regular message
hexchat.hook_command('ACTION', encrypt_privmsg, 'CTCP')
hexchat.hook_command('ME', encrypt_privmsg, 'CTCP')
hexchat.hook_command('AESKEY', set_aes_key,
                     help='/AESKEY "<key>"  Set an encryption key for '
Example #24
0
def aliases_cb(word, word_eol, userdata):
	print('\026{0: <10}{1: <50}'.format('NAME', 'CMD'))
	for pref in hexchat.list_pluginpref():
		if pref[:6] == 'alias_':
			print('{0: <10}{1: <50}'.format(pref[6:], get_alias(pref[6:])))
	return hexchat.EAT_ALL
def be_listprefs():
	prefs = hexchat.list_pluginpref()
	hexchat.prnt("\002\00302Bitlbee Extras plugin preferences:\003\002")
	for key in prefs:
		value = hexchat.get_pluginpref(item)
		hexchat.prnt(key + " => " + value)