-
Notifications
You must be signed in to change notification settings - Fork 41
/
session.py
52 lines (43 loc) · 1.8 KB
/
session.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from __future__ import print_function
import hexchat
__module_name__ = "session"
__module_author__ = "TingPing"
__module_version__ = "1"
__module_description__ = "Saves current session for next start"
# To use just disable auto-connect and start using 'Quit and Save' from the menu.
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 quit_cb(word, word_eol, userdata):
networks = {}
for chan in hexchat.get_list('channels'):
if chan.type == 2 or chan.type == 3: # Ignore notices and server tabs
if not chan.network in networks:
networks[chan.network] = []
if (chan.channelkey):
networks[chan.network].append(chan.channel + ' ' + chan.channelkey)
else:
networks[chan.network].append(chan.channel)
for network, channels in networks.items():
hexchat.set_pluginpref('session_' + network, ','.join(channels))
hexchat.find_context(server=network).command('quit')
hexchat.command('timer 1 killall')
return hexchat.EAT_ALL
def unload_cb(userdata):
print(__module_name__, 'version', __module_version__, 'unloaded.')
load_session()
hexchat.hook_command('quitandsave', quit_cb)
hexchat.hook_unload(unload_cb)
hexchat.command('menu -p-1 add "HexChat/Quit and Save" "quitandsave"')
print(__module_name__, 'version', __module_version__, 'loaded.')