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)
def toggle_bookmark(chan, net): # It's a toggle because /menu sucks if chan == None: chan = hexchat.get_info('channel') if chan == '': return if net == None: try: # If from a $TAB it may be a different network. net = hexchat.find_context(None, chan).get_info('network') except AttributeError: net = hexchat.get_info('network') for channel in hexchat.get_list('channels'): if channel.channel == chan: if channel.type != 2: # Only bookmark channels return networks = get_networks(chan) pref = 'bookmark_' + chan if net in networks: # Remove if len(networks) == 1: hexchat.del_pluginpref(pref) else: networks.remove(net) hexchat.set_pluginpref(pref, ','.join(networks)) hexchat.command('menu del "Bookmarks/{}/{}"'.format(net, chan)) else: # Add networks.append(net) hexchat.set_pluginpref(pref, ','.join(networks)) hexchat.command('menu -p-2 add "Bookmarks/{}'.format(net)) hexchat.command('menu add "Bookmarks/{0}/{1}" "netjoin {1} {0}"'.format(net, chan))
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
def cleanOldVer(): if hexchat.get_pluginpref('lfmnwo_user'): hexchat.set_pluginpref('lastfm_user', hexchat.get_pluginpref('lfmnwo_user')) hexchat.del_pluginpref('lfmnwo_user') if hexchat.get_pluginpref('lfmnwo_apikey'): hexchat.del_pluginpref('lfmnwo_apikey') return
def save_colorpairs(): if len(colorpairs) > 0: colorpairs_json = json.dumps(colorpairs) if not hexchat.set_pluginpref(__module_name__ + "colorpairs", colorpairs_json): raise BaseException("Plugin ONoticeFormat couldn't save colorpairs table.") else: hexchat.del_pluginpref(__module_name__ + "colorpairs")
def mxtmPrefs(word, word_eol, userdata): if word[1] == 'enable': hexchat.set_pluginpref('mxtm', 'yes') print('mxtm enabled') elif word[1] == 'disable': hexchat.del_pluginpref('mxtm') print('mxtm disabled >:') return hexchat.EAT_ALL
def remove_alias(name, quiet=False): hexchat.del_pluginpref('alias_' + name) if name in alias_hooks: hook = alias_hooks.get(name) hexchat.unhook(hook) del alias_hooks[name] return True return False
def save_colorpairs(): if len(colorpairs) > 0: colorpairs_json = json.dumps(colorpairs) if not hexchat.set_pluginpref(__module_name__ + "colorpairs", colorpairs_json): raise BaseException( "Plugin ONoticeFormat couldn't save colorpairs table.") else: hexchat.del_pluginpref(__module_name__ + "colorpairs")
def jptab_pref(word, word_eol, userdata): network = hexchat.get_info("network") channel = hexchat.get_info("channel") if len(word) == 3: if word[2].lower() == "network" and network != tab_name: if word[1].lower() == "add": hexchat.set_pluginpref("jptab_" + network, "network") hexchat.prnt("-\00322jptab\00399-\tNetwork \00319{}\00399 added to joint/part filters".format(network)) load_jpfilters() elif word[1].lower() == "remove": hexchat.del_pluginpref("jptab_" + network) hexchat.prnt("-\00322jptab\00399-\tNetwork \00319{}\00399 removed from joint/part filters".format(network)) load_jpfilters() else: hexchat.prnt("Usage: /jptab [add|remove] network") elif word[2].lower() == "channel" and network != tab_name: if word[1].lower() == "add": hexchat.set_pluginpref("jptab_" + channel, network) hexchat.prnt("-\00322jptab\00399-\tChannel \00319{0}\00399 on network {1} added to join/part filters".format(channel, network)) load_jpfilters() elif word[1].lower() == "remove": hexchat.del_pluginpref("jptab_" + channel) hexchat.prnt("-\00322jptab\00399-\tChannel \00319{0}\00399 on network {1} removed from joint/part filters".format(channel, network)) load_jpfilters() else: hexchat.prnt("Usage: /jptab [add|remove] channel") elif word[1].lower() == "list" and word[2].lower() == "filters": if len(network_lst) > 0: network_filters = ", ".join(network_lst) hexchat.prnt("-\00322jptab\00399-\tYour join/part network filters are: {}".format(network_filters)) if len(channel_lst) > 0: channel_filters_lst = [] for channel in channel_lst: network = get_network(channel) channel_filters_lst.append(channel + "/" + network) channel_filters = ", ".join(channel_filters_lst) hexchat.prnt("-\00322jptab\00399-\tYour join/part channel filters are: {}".format(channel_filters)) if len(network_lst) < 1 and len(channel_lst) < 1: hexchat.prnt("-\00322jptab\00399-\tYou are not filtering join/part messages on any network or channel") else: hexchat.prnt("Usage: /jptab [add|remove] [network|channel]\n\t /jptab list filters") else: hexchat.prnt("Usage: /jptab [add|remove] [network|channel]\n\t /jptab list filters") return hexchat.EAT_ALL
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 del_option(key): hkey = "{}_{}".format(__module_name__, key) success = hexchat.del_pluginpref(hkey) if not success: raise PluginConfigError(key) make_argparser_and_args_after_config()
def delete(self, key): """Unlike `del`, this does not raise if the key does not exist. """ if not isinstance(key, str): raise TypeError("Key must be a string") if not hexchat.del_pluginpref(self._keyname(key)): raise RuntimeError("Could not delete %s" + key)
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 lastFM(word, word_eol, userdata): try: if word[1].lower() == 'help': print(genHelp()) elif word[1].lower() in COMMANDS: if word[2].lower() in SETTINGS: key = word[2].lower() prefKey = 'lastfm_%s' % key keyReadable = key.replace('_', ' ').title() if word[1].lower() == 'set': try: value = word[3].lower() if 'color' in key and value.lower() not in COLORS.keys(): print('LastFM: Unknown color \02%s\017. %s' % (value.lower(), HELPTEXT)) else: hexchat.set_pluginpref(prefKey, value) print('LastFM: %s set to \002%s\017' % (key, value)) except: print('LastFM: Syntax: \002/LastFM SET \037setting\037 \037value\017. %s' % HELPTEXT) elif word[1].lower() == 'reset': if hexchat.get_pluginpref(prefKey): prefValue = hexchat.get_pluginpref(prefKey) hexchat.del_pluginpref(prefKey) if 'color' in prefKey: defaultColors() print('LastFM: %s \002%s\017 removed.' % (keyReadable, prefValue)) else: print('LastFM: Value for setting \002%s\017 not found. %s' % (keyReadable, HELPTEXT)) elif word[1].lower() == 'print': prefValue = hexchat.get_pluginpref(prefKey) if hexchat.get_pluginpref(prefKey): print('LastFM: The value of %s is \002%s\017.' % (keyReadable, prefValue)) else: print('LastFM: Value for setting \002%s\017 not found. %s' % (keyReadable, HELPTEXT)) else: print('LastFM: Unknown setting \002%s\017. %s' % (word[2], HELPTEXT)) else: print('LastFM: Unknown command \002%s\017. %s' % (word[1], HELPTEXT)) except: print('LastFM: Not enough parameters. %s' % HELPTEXT) return hexchat.EAT_ALL
def np_set_message(word, word_eol, userdata): if len(word_eol) == 1: if hexchat.del_pluginpref('np_message'): hexchat.prnt('Deleted the message') else: hexchat.prnt('Failed to delete') return hexchat.EAT_ALL if hexchat.set_pluginpref('np_message', word_eol[1]): hexchat.prnt('Success') else: hexchat.prnt('Failed') return hexchat.EAT_ALL
def unset_ignore(word, word_eol, userdata): context = hexchat.get_context() try: ignore_prefs = hexchat.get_pluginpref(IGNORE_PREFS) if not ignore_prefs: context.emit_print('Channel Message', MODULE_NICK, "You aren't ignoring anyone stupid") return hexchat.EAT_HEXCHAT elif str(word_eol[1]) == 'all': hexchat.del_pluginpref(IGNORE_PREFS) context.emit_print( 'Channel Message', MODULE_NICK, 'Ignore list cleared. Nice to see you had a change of heart.') return hexchat.EAT_HEXCHAT else: prefs = str(ignore_prefs).split(' ') new_prefs = [] deletion = str(word_eol[1]).strip() for pref in prefs: if str(deletion) == str(pref): pass else: new_prefs.append(str(pref)) new_ignore_prefs = ' '.join(new_prefs) hexchat.set_pluginpref(IGNORE_PREFS, new_ignore_prefs) context.emit_print('Channel Message', MODULE_NICK, 'Unignoring %s' % (word_eol[1])) if new_ignore_prefs == '': new_ignore_prefs = 'nobody. Such a kind f****t you are.' context.emit_print('Channel Message', MODULE_NICK, 'You are now ignoring %s' % (new_ignore_prefs)) return hexchat.EAT_HEXCHAT except IndexError: context.emit_print('Channel Message', MODULE_NICK, 'No arguments given') return hexchat.EAT_HEXCHAT
def delname_cmd(word, word_eol, userdata): global nickname hexchat.del_pluginpref(__module_name__ + "name") nickname = None print("opvoice name set to default (your IRC nick)") return hexchat.EAT_ALL
def closedialog_cb(word, word_eol, userdata): #TODO: check for existing dialogs to same user on other networks if hexchat.get_info("channel")[0] != "#": nick = hexchat.get_info("channel") hexchat.del_pluginpref("persistpm_" + nick)
def soakerlistclear(word, word_eol, userdata): hexchat.del_pluginpref('soakbotignorelist') print('Ignore list cleared') return hexchat.EAT_ALL
def jptab_pref(word, word_eol, userdata): network = hexchat.get_info("network") channel = hexchat.get_info("channel") if len(word) == 3: if word[2].lower() == "network" and network != tab_name: if word[1].lower() == "add": hexchat.set_pluginpref("jptab_" + network, "network") hexchat.prnt( "-\00322jptab\00399-\tNetwork \00319{}\00399 added to joint/part filters" .format(network)) load_jpfilters() elif word[1].lower() == "remove": hexchat.del_pluginpref("jptab_" + network) hexchat.prnt( "-\00322jptab\00399-\tNetwork \00319{}\00399 removed from joint/part filters" .format(network)) load_jpfilters() else: hexchat.prnt("Usage: /jptab [add|remove] network") elif word[2].lower() == "channel" and network != tab_name: if word[1].lower() == "add": hexchat.set_pluginpref("jptab_" + channel, network) hexchat.prnt( "-\00322jptab\00399-\tChannel \00319{0}\00399 on network {1} added to join/part filters" .format(channel, network)) load_jpfilters() elif word[1].lower() == "remove": hexchat.del_pluginpref("jptab_" + channel) hexchat.prnt( "-\00322jptab\00399-\tChannel \00319{0}\00399 on network {1} removed from joint/part filters" .format(channel, network)) load_jpfilters() else: hexchat.prnt("Usage: /jptab [add|remove] channel") elif word[1].lower() == "list" and word[2].lower() == "filters": if len(network_lst) > 0: network_filters = ", ".join(network_lst) hexchat.prnt( "-\00322jptab\00399-\tYour join/part network filters are: {}" .format(network_filters)) if len(channel_lst) > 0: channel_filters_lst = [] for channel in channel_lst: network = get_network(channel) channel_filters_lst.append(channel + "/" + network) channel_filters = ", ".join(channel_filters_lst) hexchat.prnt( "-\00322jptab\00399-\tYour join/part channel filters are: {}" .format(channel_filters)) if len(network_lst) < 1 and len(channel_lst) < 1: hexchat.prnt( "-\00322jptab\00399-\tYou are not filtering join/part messages on any network or channel" ) else: hexchat.prnt( "Usage: /jptab [add|remove] [network|channel]\n\t /jptab list filters" ) else: hexchat.prnt( "Usage: /jptab [add|remove] [network|channel]\n\t /jptab list filters" ) return hexchat.EAT_ALL
def handle_command(args): """ Handles plugin commands such as list, add, remove, clear and help. """ global dirty global words global enabled if (len(args) == 0): command = 'help' else: command = args[0] if len(args) > 1: key = args[1] if len(args) > 2: msg = ' '.join(args[2:]) if command == 'help': heading('Usage:') heading('/cr <save|help|list|keys|clear|enable|disable>') heading('/cr <remove> <key>') heading('/cr <add> <key> <content>') return if command in ('enable', 'disable'): enabled = command == 'enable' heading('%sd' % command) return if command == 'keys': heading('Keys: %s' % ', '.join(sorted(words.keys()))) return if command == 'list': for key, val in words.items(): heading('%s: %s' % (key, val)) return if command == 'save': dirty = True save(None) return if command == 'clear': for key in words.keys(): hexchat.del_pluginpref(key) words = {} dirty = True return if command == 'remove' and len(args) > 1: if not key in words: heading('Error: Key (%s) not found' % key) else: del words[key] hexchat.del_pluginpref(PLUGIN_PREF_VAL % key) heading('Key removed') dirty = True return if not command == 'add' or len(args) < 3: heading('Error: Malformed command') return if KEY_SEPARATOR in key: heading('Error: Key cannot contain "%s"' % KEY_SEPARATOR) return if len(msg) > 511: # https://github.com/hexchat/hexchat/issues/1265 heading('Error: Message too long') words[key] = msg heading('"%s" %s' % (key, 'added' if command == 'add' else 'modified')) dirty = True