Project

General

Profile

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

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

 
1
menu channel,status {
2
  Session Manager
3
    .Save
4
    ..Save New:/sessMan.save
5
    ..-
6
    ..$submenu($sessMan.menu.save($1))
7
    .Load
8
    ..$submenu($sessMan.menu.load($1))
9
    .$iif($chan != $null,Add $chan To Existing,-)
10
    ..$submenu($sessMan.menu.append($1))
11
    .$iif($chan != $null,Remove $chan From Existing,-)
12
    ..$submenu($sessMan.menu.detach($1))
13
    .-
14
    .Options
15
    ..Auto Part current channels on loading
16
    ...$iif($readini(sessMan-options.ini,config,autoPart) == true,$style(1),$null) $+ Enable:writeini sessMan-options.ini config autoPart true
17
    ...$iif($readini(sessMan-options.ini,config,autoPart) == $null,$style(1),$null) $+ Disable:remini sessMan-options.ini config autoPart
18
    ..Auto Join Session on Connect
19
    ...$iif($readini(sessMan-options.ini,config,autoJoin) == truedef,$style(1),$null) $+ Join Default:writeini sessMan-options.ini config autoJoin truedef
20
    ...$iif($readini(sessMan-options.ini,config,autoJoin) == trueprev,$style(1),$null) $+ Join Previous:writeini sessMan-options.ini config autoJoin trueprev
21
    ...$iif($readini(sessMan-options.ini,config,autoJoin) == $null,$style(1),$null) $+ Disable:remini sessMan-options.ini config autoJoin
22
    ..Auto Save 'previous' on Disconnect
23
    ...$iif($readini(sessMan-options.ini,config,autoSave) == true,$style(1),$null) $+ Enable:writeini sessMan-options.ini config autoSave true
24
    ...$iif($readini(sessMan-options.ini,config,autoSave) == $null,$style(1),$null) $+ Disable:remini sessMan-options.ini config autoSave
25
    ..-
26
    ..Delete Session
27
    ...$submenu($sessMan.menu.delete($1))
28
}
29

    
30
alias sessMan.save {
31
  var %i = 1
32
  var %chanlist = $null
33
  
34
  if ($1 == $null) {
35
    %sessionName = $?"Session Name. (If blank, will use 'default')"
36
  }
37
  else {
38
    %sessionName = $1
39
  }
40
    
41
  if (%sessionName == $null) {
42
    %sessionName = default
43
  }
44
  
45
  while (%i <= $chan(0)) {
46
    ;if (%chanlist == $null) {
47
    ;  var %chanlist = $chan(%i)
48
    ;} else {
49
    ;  var %chanlist = %chanlist $+ , $+ $chan(%i)
50
    ;}
51
    
52
    ;
53
    ; Turns out using tokens makes this a one liner without needing an if at all
54
    ; Who knew? (Apparently everyone who knows AdiIRC/mIRC scripting)
55
    ;
56
    %chanlist = $addtok(%chanlist,$chan(%i),44)
57
    inc %i
58
  }
59
    
60
  if ( %chanlist != $null ) {
61
    writeini sessMan-sessions.ini $network %sessionName %chanlist
62
    echo -sg Saved %chanlist
63
    echo -sg $str($chr(160),2) to session: %sessionName
64
    echo -sg $str($chr(160),2) for network: $network
65
  }
66
}
67

    
68
alias sessMan.load {
69
  if ($1 == $null) {
70
    %sessionName = default
71
  }
72
  else {
73
      %sessionName = $1
74
  }
75
  
76
  %chanlist = $readini(sessMan-sessions.ini,$network,%sessionName)
77
  if (%chanlist == $null) {
78
    if ( $2 != quiet ) {
79
      echo -ag Session Does Not Exist
80
    }
81
    return
82
  } 
83
  else {
84
    if ( $readini(sessMan-options.ini,config,autoPart) == true ) {
85
      sessman.partAll
86
    }
87
    join %chanlist
88
  }
89
}
90

    
91
alias sessMan.append {
92
  if ( $1 == $null ) return
93
  
94
  var %session = $1
95
  var %chanlist = $readini(sessMan-sessions.ini,$network,%session)
96
  if ( %chanlist == $null ) {
97
    return
98
  }
99
  var %chanlist = $addtok(%chanlist,$chan,44)
100
  writeini sessMan-sessions.ini $network %session %chanlist
101
}
102

    
103
alias sessMan.detach {
104
  if ( $1 == $null || $2 == $null ) return
105
  var %sess = $1
106
  var %chan = $2 $+ ,?
107
  var %chanlist = $readini(sessMan-sessions.ini,$network,%sess)
108
  noop $regsub(detach,%chanlist,/ $+ %chan $+ /g,,%newchanlist)
109
  
110
  if (%newchanlist == $null) {
111
    echo -ag That was the only channel in the session
112
    echo -ag Deleting the session instead
113
    remini sessMan-sessions.ini $network %sess
114
    return
115
  }
116
  
117
  writeini sessMan-sessions.ini $network %sess %newchanlist
118
  echo -ag Channel: $2 removed from Session: %sess
119
}
120

    
121
alias sessMan.menu.delete {
122
  ;This block deals with begin since the main bit returns on a null rather than doing nothing
123
  if ( $1 == $null ) {
124
    var %pos = 1
125
  } 
126
  else {
127
    var %pos = $1
128
  }
129

    
130
  var %sess = $ini(sessMan-sessions.ini,$network,%pos)
131
  if ( %sess == $null ) {
132
    return
133
  } 
134
  else {
135
    return Delete %sess $+ :remini sessMan-sessions.ini $network %sess
136
  }
137
}
138

    
139
alias sessMan.partAll {
140
  var %i = 1
141
  while (%i <= $chan(0)) {
142
    part $chan(%i)
143
    inc %i
144
  }
145
}
146

    
147
alias sessMan.menu.save {
148
  if ( $1 == $null ) {
149
    var %pos = 1
150
  } 
151
  else {
152
    var %pos = $1
153
  }  
154
  var %sess = $ini(sessMan-sessions.ini,$network,%pos)
155
  if ( %sess == $null ) return
156
  return %sess $+ :sessMan.save %sess
157
}
158

    
159
alias sessMan.menu.load {
160
  if ( $1 == $null ) {
161
    var %pos = 1
162
  } 
163
  else {
164
    var %pos = $1
165
  }  
166
  %sess = $ini(sessMan-sessions.ini,$network,%pos)
167
  if ( %sess == $null ) return
168
  return %sess $+ :sessMan.load %sess
169
}
170

    
171
alias sessMan.menu.append {
172
  if ($chan == $null) return
173
  if ( $1 == $null ) {
174
    var %pos = 1
175
  } 
176
  else {
177
    var %pos = $1
178
  }
179
  
180
  var %sess = $ini(sessMan-sessions.ini,$network,%pos)
181
  if ( %sess == $null ) return 
182
  return Add To %sess $+ :sessMan.append %sess
183
}
184

    
185
alias sessMan.menu.detach {
186
  if ($chan == $null) return
187
  if ( $1 == begin ) {
188
    %i = 1
189
    %count = $ini(sessMan-sessions.ini,$network,0)
190
    while (%i <= %count) {
191
      %position = $ini(sessMan-sessions.ini,$network,%i)
192
      if ($pos($readini(sessMan-sessions.ini,$network,%position),$chan,0) == 1) {
193
        writeini sessMan-temp.ini menuGen $ini(sessMan-sessions.ini,$network,%i) 1
194
      }   
195
      inc %i
196
    }
197
  }
198
  
199
  if ( $1 == end ) {
200
    remini sessMan-temp.ini menuGen
201
  }
202
  
203
  if ( $1 == $null ) {
204
    var %pos = 1
205
  } 
206
  else {
207
    var %pos = $1
208
  }
209
  
210
  var %sess = $ini(sessMan-temp.ini,menuGen,%pos)
211
  if ( %sess == $null ) return
212
  return Remove $chan from %sess :sessMan.detach %sess $chan  
213
}
214

    
215
on *:DISCONNECT:{
216
  if ( $readini(sessMan-options.ini,config,autoSave) == true ) {
217
    echo -ag Saving currently connected channels to session 'previous'
218
    sessMan.save previous
219
  }
220
}
221

    
222
on *:CONNECT:{
223
  if ( $readini(sessMan-options.ini,config,autoJoin) == truedef ) {
224
    sessMan.load default quiet
225
  } 
226
  elseif ( $readini(sessMan-options.ini,config,autoJoin) == trueprev ) {
227
    sessMan.load previous quiet
228
  }
229
}
(5-5/6)