Project

General

Profile

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

Trel Smith, 12/20/2016 06:55 PM

 
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
}
10

    
11
menu channel {
12
  ;By separating it into three parts,
13
  ;I don't have to use those $iif bits that seem to break mIRC or AdiIRC depending on which way I do it
14
  Session Manager
15
    ..$submenu($sessMan.menu.load($1))
16
    .Add $chan To Existing
17
    ..$submenu($sessMan.menu.append($1))
18
    .Remove $chan From Existing
19
    ..$submenu($sessMan.menu.detach($1))
20
}
21

    
22
menu channel,status {
23
  Session Manager
24
    .-
25
    .Options
26
    ..Auto Part current channels on loading
27
    ...$iif($readini(sessMan-options.ini,config,autoPart) == true,$style(1),$null) $+ Enable:writeini sessMan-options.ini config autoPart true
28
    ...$iif($readini(sessMan-options.ini,config,autoPart) == $null,$style(1),$null) $+ Disable:remini sessMan-options.ini config autoPart
29
    ..Auto Join Session on Connect
30
    ...$iif($readini(sessMan-options.ini,config,autoJoin) == truedef,$style(1),$null) $+ Join Default:writeini sessMan-options.ini config autoJoin truedef
31
    ...$iif($readini(sessMan-options.ini,config,autoJoin) == trueprev,$style(1),$null) $+ Join Previous:writeini sessMan-options.ini config autoJoin trueprev
32
    ...$iif($readini(sessMan-options.ini,config,autoJoin) == $null,$style(1),$null) $+ Disable:remini sessMan-options.ini config autoJoin
33
    ..Auto Save 'previous' on Disconnect
34
    ...$iif($readini(sessMan-options.ini,config,autoSave) == true,$style(1),$null) $+ Enable:writeini sessMan-options.ini config autoSave true
35
    ...$iif($readini(sessMan-options.ini,config,autoSave) == $null,$style(1),$null) $+ Disable:remini sessMan-options.ini config autoSave
36
    ..-
37
    ..Delete Session
38
    ...$submenu($sessMan.menu.delete($1))
39
}
40

    
41
on *:DISCONNECT:{
42
  if ( $readini(sessMan-options.ini,config,autoSave) == true ) {
43
    echo -ag Saving currently connected channels to session 'previous'
44
    sessMan.save previous
45
  }
46
}
47

    
48
on *:CONNECT:{
49
  if ( $readini(sessMan-options.ini,config,autoJoin) == truedef ) {
50
    sessMan.load default quiet
51
  } 
52
  elseif ( $readini(sessMan-options.ini,config,autoJoin) == trueprev ) {
53
    sessMan.load previous quiet
54
  }
55
}
56

    
57
alias sessMan.save {
58
  var %i = 1
59
  var %chanlist = $null
60
  
61
  if ($1 == $null) {
62
    %sessionName = $?"Session Name. (If blank, will use 'default')"
63
  }
64
  else {
65
    %sessionName = $1
66
  }
67
    
68
  if (%sessionName == $null) {
69
    %sessionName = default
70
  }
71
  
72
  while (%i <= $chan(0)) {
73
    ;
74
    ; Turns out using tokens makes this a one liner without needing an if at all
75
    ; Who knew? (Apparently everyone who knows AdiIRC/mIRC scripting)
76
    ;
77
    %chanlist = $addtok(%chanlist,$chan(%i),44)
78
    inc %i
79
  }
80
    
81
  if ( %chanlist != $null ) {
82
    writeini sessMan-sessions.ini $network %sessionName %chanlist
83
    echo -ag Saved %chanlist
84
    echo -ag $str($chr(160),2) to session: %sessionName
85
    echo -ag $str($chr(160),2) for network: $network
86
  }
87
}
88

    
89
alias sessMan.load {
90
  if ($1 == $null) {
91
    %sessionName = default
92
  }
93
  else {
94
      %sessionName = $1
95
  }
96
  
97
  %chanlist = $readini(sessMan-sessions.ini,$network,%sessionName)
98
  if (%chanlist == $null) {
99
    if ( $2 != quiet ) {
100
      echo -ag Session Does Not Exist
101
    }
102
    return
103
  } 
104
  else {
105
    if ( $readini(sessMan-options.ini,config,autoPart) == true ) {
106
      sessman.partAll
107
    }
108
    join %chanlist
109
  }
110
}
111

    
112
alias sessMan.append {
113
  if ( $1 == $null ) return
114
  var %session = $1
115
  var %chanlist = $readini(sessMan-sessions.ini,$network,%session)
116
  if ( %chanlist == $null ) {
117
    return
118
  }
119
  var %chanlist = $addtok(%chanlist,$chan,44)
120
  writeini sessMan-sessions.ini $network %session %chanlist
121
}
122

    
123
alias sessMan.detach {
124
  if ( $1 == $null || $2 == $null ) return
125
  var %sess = $1
126
  var %chan = $2 $+ ,?
127
  var %chanlist = $readini(sessMan-sessions.ini,$network,%sess)
128
  noop $regsub(detach,%chanlist,/ $+ %chan $+ /g,,%newchanlist)
129
  
130
  if (%newchanlist == $null) {
131
    echo -ag That was the only channel in the session
132
    echo -ag Deleting the session instead
133
    remini sessMan-sessions.ini $network %sess
134
    return
135
  }
136
  
137
  writeini sessMan-sessions.ini $network %sess %newchanlist
138
  echo -ag Channel: $2 removed from Session: %sess
139
}
140

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

    
149
alias sessMan.menu.save {
150
  var %pos = $sessMan.func.menupos($1)
151
  var %sess = $ini(sessMan-sessions.ini,$network,%pos)
152
  
153
  ;This bit isn't stricly needed because it seems to immediately return null if the return STARTS with null.
154
  ;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.
155
  ;Basically if I was just returning the variable, it would work right without the forced return on null.
156
  if ( %sess == $null ) return
157
  
158
  return %sess $+ :sessMan.save %sess
159
}
160

    
161
alias sessMan.menu.load {
162
  var %pos = $sessMan.func.menupos($1)
163
  %sess = $ini(sessMan-sessions.ini,$network,%pos)
164
  
165
  ;This bit isn't stricly needed because it seems to immediately return null if the return STARTS with null.
166
  ;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.
167
  ;Basically if I was just returning the variable, it would work right without the forced return on null.
168
  if ( %sess == $null ) return
169
  return %sess $+ :sessMan.load %sess
170
}
171

    
172
alias sessMan.menu.delete {
173
  var %pos = $sessMan.func.menupos($1)
174
  var %sess = $ini(sessMan-sessions.ini,$network,%pos)
175
  
176
  ;See the comment in save and load for an explanation on why this line is here
177
  if ( %sess == $null ) return
178
  return Delete %sess $+ :remini sessMan-sessions.ini $network %sess
179
}
180

    
181
alias sessMan.menu.append {
182
  var %pos = $sessMan.func.menupos($1)  
183
  var %sess = $ini(sessMan-sessions.ini,$network,%pos)
184

    
185
  ;See the comment in save and load for an explanation on why this line is here
186
  if ( %sess == $null ) return 
187
  return Add To %sess $+ :sessMan.append %sess
188
}
189

    
190
alias sessMan.menu.detach {
191
  if ( $1 == begin ) {
192
    %i = 1
193
    %count = $ini(sessMan-sessions.ini,$network,0)
194
    while (%i <= %count) {
195
      %position = $ini(sessMan-sessions.ini,$network,%i)
196
      if ($pos($readini(sessMan-sessions.ini,$network,%position),$chan,0) == 1) {
197
        writeini sessMan-temp.ini menuGen $ini(sessMan-sessions.ini,$network,%i) 1
198
      }   
199
      inc %i
200
    }
201
  }
202
  
203
  if ( $1 == end ) {
204
    remini sessMan-temp.ini menuGen
205
  }
206
  
207
  var %pos = $sessMan.func.menupos($1)  
208
  var %sess = $ini(sessMan-temp.ini,menuGen,%pos)
209

    
210
  ;See the comment in save and load for an explanation on why this line is here
211
  if ( %sess == $null ) return
212
  return Remove $chan from %sess :sessMan.detach %sess $chan  
213
}
214

    
215
alias sessMan.func.menupos {
216
  ;This is because for menus, I need it to not return null for 'begin' and 'end'
217
  if ( $1 == $null ) {
218
    return 1
219
  }
220
  else {
221
    return $1
222
  }
223
}
224

    
225
alias sessMan.func.menuini {
226
  ;This doesn't do anything because it was stupid
227
  ;Seriously, the line to load the ini is one line long
228
  ;It doesn't make sense to make it a function when the function call would ALSO be one line
229
  ;Go away, it's like fetch, it's never going to happen
230
}
(6-6/6)