Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
hexchat addon for keeping dialogs open after restart
from __future__ import print_function
import hexchat
__module_name__ = "keep_dialogs"
__module_author__ = "ansiwen"
__module_version__ = "1"
__module_description__ = "Saves current dialogs for next start"
def unload_cb(userdata):
networks = {}
for chan in hexchat.get_list('channels'):
if chan.type == 3: # select dialogs
if not chan.network in networks:
networks[chan.network] = []
networks[chan.network].append(chan.channel)
for network, users in networks.items():
hexchat.set_pluginpref('keep_dialogs_' + network, ','.join(users))
hexchat.find_context(server=network).command('quit')
print(__module_name__, 'version', __module_version__, 'unloaded.')
def connected_cb(word, word_eol, userdata):
for pref in hexchat.list_pluginpref():
network = hexchat.get_info('network')
if network and pref.startswith('keep_dialogs_' + network):
print('Loading dialog session for network {}'.format(network))
users = hexchat.get_pluginpref('keep_dialogs_' + network).split(',')
for user in users:
hexchat.command('query -nofocus {}'.format(user))
hexchat.hook_unload(unload_cb)
hexchat.hook_server("376", connected_cb)
print(__module_name__, 'version', __module_version__, 'loaded.')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment