TS[Script] Session Manager
Added by Trel Smith almost 9 years ago
This is a session manager script.
It allows you to create/load/delete named sessions of channels.
It has an additional option to part all currently joined channels prior to "restoring" a session
It adds a menu item to the status and channel menus.
Updated to Version 3.2.0
This adds
1. Additional code cleanup
2. Change in menu generation to make play nicely in AdiIRC and mIRC at the same time
3. A bit of optimization
4. Some comments to explain some sh....stuff.
Updated to Version 3.2.0
This Adds
1. Code Cleanup
2. Option to add a single channel to existing session
3. Option to remove a single channel from existing session
Updated to Version 2
This adds
1. Ability to save over a previous session without typing
2. Option to auto save a session named 'previous' on disconnect
3. Option to auto join a session named 'previous' or 'default' on connect
Version 3.0.0
menu channel,status {
Session Manager
.Save
..Save New:/sessMan.save
..-
..$submenu($sessMan.menu.save($1))
.Load
..$submenu($sessMan.menu.load($1))
}
menu channel {
;By separating it into three parts,
;I don't have to use those $iif bits that seem to break mIRC or AdiIRC depending on which way I do it
Session Manager
..$submenu($sessMan.menu.load($1))
.Add $chan To Existing
..$submenu($sessMan.menu.append($1))
.Remove $chan From Existing
..$submenu($sessMan.menu.detach($1))
}
menu channel,status {
Session Manager
.-
.Options
..Auto Part current channels on loading
...$iif($readini(sessMan-options.ini,config,autoPart) == true,$style(1),$null) $+ Enable:writeini sessMan-options.ini config autoPart true
...$iif($readini(sessMan-options.ini,config,autoPart) == $null,$style(1),$null) $+ Disable:remini sessMan-options.ini config autoPart
..Auto Join Session on Connect
...$iif($readini(sessMan-options.ini,config,autoJoin) == truedef,$style(1),$null) $+ Join Default:writeini sessMan-options.ini config autoJoin truedef
...$iif($readini(sessMan-options.ini,config,autoJoin) == trueprev,$style(1),$null) $+ Join Previous:writeini sessMan-options.ini config autoJoin trueprev
...$iif($readini(sessMan-options.ini,config,autoJoin) == $null,$style(1),$null) $+ Disable:remini sessMan-options.ini config autoJoin
..Auto Save 'previous' on Disconnect
...$iif($readini(sessMan-options.ini,config,autoSave) == true,$style(1),$null) $+ Enable:writeini sessMan-options.ini config autoSave true
...$iif($readini(sessMan-options.ini,config,autoSave) == $null,$style(1),$null) $+ Disable:remini sessMan-options.ini config autoSave
..-
..Delete Session
...$submenu($sessMan.menu.delete($1))
}
on *:DISCONNECT:{
if ( $readini(sessMan-options.ini,config,autoSave) == true ) {
echo -ag Saving currently connected channels to session 'previous'
sessMan.save previous
}
}
on *:CONNECT:{
if ( $readini(sessMan-options.ini,config,autoJoin) == truedef ) {
sessMan.load default quiet
}
elseif ( $readini(sessMan-options.ini,config,autoJoin) == trueprev ) {
sessMan.load previous quiet
}
}
alias sessMan.save {
var %i = 1
var %chanlist = $null
if ($1 == $null) {
%sessionName = $?"Session Name. (If blank, will use 'default')"
}
else {
%sessionName = $1
}
if (%sessionName == $null) {
%sessionName = default
}
while (%i <= $chan(0)) {
;
; Turns out using tokens makes this a one liner without needing an if at all
; Who knew? (Apparently everyone who knows AdiIRC/mIRC scripting)
;
%chanlist = $addtok(%chanlist,$chan(%i),44)
inc %i
}
if ( %chanlist != $null ) {
writeini sessMan-sessions.ini $network %sessionName %chanlist
echo -ag Saved %chanlist
echo -ag $str($chr(160),2) to session: %sessionName
echo -ag $str($chr(160),2) for network: $network
}
}
alias sessMan.load {
if ($1 == $null) {
%sessionName = default
}
else {
%sessionName = $1
}
%chanlist = $readini(sessMan-sessions.ini,$network,%sessionName)
if (%chanlist == $null) {
if ( $2 != quiet ) {
echo -ag Session Does Not Exist
}
return
}
else {
if ( $readini(sessMan-options.ini,config,autoPart) == true ) {
sessman.partAll
}
join %chanlist
}
}
alias sessMan.append {
if ( $1 == $null ) return
var %session = $1
var %chanlist = $readini(sessMan-sessions.ini,$network,%session)
if ( %chanlist == $null ) {
return
}
var %chanlist = $addtok(%chanlist,$chan,44)
writeini sessMan-sessions.ini $network %session %chanlist
}
alias sessMan.detach {
if ( $1 == $null || $2 == $null ) return
var %sess = $1
var %chan = $2 $+ ,?
var %chanlist = $readini(sessMan-sessions.ini,$network,%sess)
noop $regsub(detach,%chanlist,/ $+ %chan $+ /g,,%newchanlist)
if (%newchanlist == $null) {
echo -ag That was the only channel in the session
echo -ag Deleting the session instead
remini sessMan-sessions.ini $network %sess
return
}
writeini sessMan-sessions.ini $network %sess %newchanlist
echo -ag Channel: $2 removed from Session: %sess
}
alias sessMan.partAll {
var %i = 1
while (%i <= $chan(0)) {
part $chan(%i)
inc %i
}
}
alias sessMan.menu.save {
var %pos = $sessMan.func.menupos($1)
var %sess = $ini(sessMan-sessions.ini,$network,%pos)
;This bit isn't stricly needed because it seems to immediately return null if the return STARTS with null.
;However, if there's text first, it will loop indefinitely since it will never return null, so I will include this anyway to be safe.
;Basically if I was just returning the variable, it would work right without the forced return on null.
if ( %sess == $null ) return
return %sess $+ :sessMan.save %sess
}
alias sessMan.menu.load {
var %pos = $sessMan.func.menupos($1)
%sess = $ini(sessMan-sessions.ini,$network,%pos)
;This bit isn't stricly needed because it seems to immediately return null if the return STARTS with null.
;However, if there's text first, it will loop indefinitely since it will never return null, so I will include this anyway to be safe.
;Basically if I was just returning the variable, it would work right without the forced return on null.
if ( %sess == $null ) return
return %sess $+ :sessMan.load %sess
}
alias sessMan.menu.delete {
var %pos = $sessMan.func.menupos($1)
var %sess = $ini(sessMan-sessions.ini,$network,%pos)
;See the comment in save and load for an explanation on why this line is here
if ( %sess == $null ) return
return Delete %sess $+ :remini sessMan-sessions.ini $network %sess
}
alias sessMan.menu.append {
var %pos = $sessMan.func.menupos($1)
var %sess = $ini(sessMan-sessions.ini,$network,%pos)
;See the comment in save and load for an explanation on why this line is here
if ( %sess == $null ) return
return Add To %sess $+ :sessMan.append %sess
}
alias sessMan.menu.detach {
if ( $1 == begin ) {
%i = 1
%count = $ini(sessMan-sessions.ini,$network,0)
while (%i <= %count) {
%position = $ini(sessMan-sessions.ini,$network,%i)
if ($pos($readini(sessMan-sessions.ini,$network,%position),$chan,0) == 1) {
writeini sessMan-temp.ini menuGen $ini(sessMan-sessions.ini,$network,%i) 1
}
inc %i
}
}
if ( $1 == end ) {
remini sessMan-temp.ini menuGen
}
var %pos = $sessMan.func.menupos($1)
var %sess = $ini(sessMan-temp.ini,menuGen,%pos)
;See the comment in save and load for an explanation on why this line is here
if ( %sess == $null ) return
return Remove $chan from %sess :sessMan.detach %sess $chan
}
alias sessMan.func.menupos {
;This is because for menus, I need it to not return null for 'begin' and 'end'
if ( $1 == $null ) {
return 1
}
else {
return $1
}
}
alias sessMan.func.menuini {
;This doesn't do anything because it was stupid
;Seriously, the line to load the ini is one line long
;It doesn't make sense to make it a function when the function call would ALSO be one line
;Go away, it's like fetch, it's never going to happen
}
| sessionManager.ini (2.67 KB) sessionManager.ini | |||
| sessionManager-v1.ini (2.67 KB) sessionManager-v1.ini | Origional | ||
| sessionManager-v2.ini (3.85 KB) sessionManager-v2.ini | Version 2 | ||
| sessionManager-v2.0.1.ini (3.9 KB) sessionManager-v2.0.1.ini | |||
| sessionManager-v3.0.0.ini (6.18 KB) sessionManager-v3.0.0.ini | Version 3.0.0 | ||
| sessionManager-v3.2.0.ini (7.28 KB) sessionManager-v3.2.0.ini |