Project

General

Profile

[Script] Session Manager » sessionManager-v3.0.0.ini

Version 3.0.0 - Trel Smith, 12/20/2016 12:59 AM

 
menu channel,status {
Session Manager
.Save
..Save New:/sessMan.save
..-
..$submenu($sessMan.menu.save($1))
.Load
..$submenu($sessMan.menu.load($1))
.$iif($chan != $null,Add $chan To Existing,-)
..$submenu($sessMan.menu.append($1))
.$iif($chan != $null,Remove $chan From Existing,-)
..$submenu($sessMan.menu.detach($1))
.-
.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))
}

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)) {
;if (%chanlist == $null) {
; var %chanlist = $chan(%i)
;} else {
; var %chanlist = %chanlist $+ , $+ $chan(%i)
;}
;
; 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 -sg Saved %chanlist
echo -sg $str($chr(160),2) to session: %sessionName
echo -sg $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.menu.delete {
;This block deals with begin since the main bit returns on a null rather than doing nothing
if ( $1 == $null ) {
var %pos = 1
}
else {
var %pos = $1
}

var %sess = $ini(sessMan-sessions.ini,$network,%pos)
if ( %sess == $null ) {
return
}
else {
return Delete %sess $+ :remini sessMan-sessions.ini $network %sess
}
}

alias sessMan.partAll {
var %i = 1
while (%i <= $chan(0)) {
part $chan(%i)
inc %i
}
}

alias sessMan.menu.save {
if ( $1 == $null ) {
var %pos = 1
}
else {
var %pos = $1
}
var %sess = $ini(sessMan-sessions.ini,$network,%pos)
if ( %sess == $null ) return
return %sess $+ :sessMan.save %sess
}

alias sessMan.menu.load {
if ( $1 == $null ) {
var %pos = 1
}
else {
var %pos = $1
}
%sess = $ini(sessMan-sessions.ini,$network,%pos)
if ( %sess == $null ) return
return %sess $+ :sessMan.load %sess
}

alias sessMan.menu.append {
if ($chan == $null) return
if ( $1 == $null ) {
var %pos = 1
}
else {
var %pos = $1
}
var %sess = $ini(sessMan-sessions.ini,$network,%pos)
if ( %sess == $null ) return
return Add To %sess $+ :sessMan.append %sess
}

alias sessMan.menu.detach {
if ($chan == $null) return
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
}
if ( $1 == $null ) {
var %pos = 1
}
else {
var %pos = $1
}
var %sess = $ini(sessMan-temp.ini,menuGen,%pos)
if ( %sess == $null ) return
return Remove $chan from %sess :sessMan.detach %sess $chan
}

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
}
}
(5-5/6)