All pastes #569284 Raw Edit

awayscript

public text v1 · immutable
·published 2007-06-16 03:04 UTC
rendered paste body
; #################################################################
; ## Away system script                                          ##
; ## Designed and written by Urza                                ##
; ## Email: Urza23@hotmail.com                                   ##
; ## Written and tested in mIRC 6.17                             ##
; ##  Also tested in mIRC 6.16                                   ##
; ##  May not work correctly in earlier versions                 ##
; ## ----------------------------------------------------------- ##
; ## Usage:                                                      ##
; ##   /Away.Config   - Opens the options dialog                 ##
; ##   /Away [Reason] - Set yourself away                        ##
; ##   /Away [Preset] - Set yourself away using a preset trigger ##
; ##   /Back          - Return from away                         ##
; ## Options are also avaliable via menus                        ##
; #################################################################


; ##############################################
; # Start Idle Away Timer                      #
; ##############################################
on *:start: if ($readini(Settings.ini,Away.Config,AutoAway) == on) .timerAway.IdleCheck -o 0 30 Away.IdleCheck

; ##############################################
; # Load Default Options                       #
; ##############################################
on *:load: {
  if (!$readini(AwaySettings.ini,Config,NickEditType))      writeini AwaySettings.ini Config NickEditType Suffix
  if (!$readini(AwaySettings.ini,Config,NickPrefix))        writeini AwaySettings.ini Config NickPrefix Away|
  if (!$readini(AwaySettings.ini,Config,NickSuffix))        writeini AwaySettings.ini Config NickSuffix |Away
  if (!$readini(AwaySettings.ini,Config,NickSetTo))         writeini AwaySettings.ini Config NickSuffix Away
  if (!$readini(AwaySettings.ini,Config,AutoAway))          writeini AwaySettings.ini Config AutoAway off
  if (!$readini(AwaySettings.ini,Config,AutoAwayTime))      writeini AwaySettings.ini Config AutoAwayTime 900
  if (!$readini(AwaySettings.ini,Config,IdleSettings))      writeini AwaySettings.ini Config IdleSettings Suffix~|Idle~Auto away after %time minutes idle
  if (!$readini(AwaySettings.ini,Config,LeavingTime))       writeini AwaySettings.ini Config LeavingTime off
  if (!$readini(AwaySettings.ini,Config,LeavingTimeFormat)) writeini AwaySettings.ini Config LeavingTimeFormat HH:nn:ss
  if (!$readini(AwaySettings.ini,Config,TimeAway))          writeini AwaySettings.ini Config TimeAway off
  if (!$readini(AwaySettings.ini,Config,TimeAwayFormat))    writeini AwaySettings.ini Config TimeAwayFormat Short
  if (!$readini(AwaySettings.ini,Config,ARChannelMessage))  writeini AwaySettings.ini Config ARChannelMessage off
  if (!$readini(AwaySettings.ini,Config,ARPrivateMessage))  writeini AwaySettings.ini Config ARPrivateMessage off
  if (!$readini(AwaySettings.ini,Config,MsgChans))          writeini AwaySettings.ini Config MsgChans on
  if (!$readini(AwaySettings.ini,Config,MsgQueries))        writeini AwaySettings.ini Config MsgQueries off
  if (!$readini(AwaySettings.ini,Config,RespondHilights))   writeini AwaySettings.ini Config RespondHilights on
  if (!$readini(AwaySettings.ini,Config,RespondPM))         writeini AwaySettings.ini Config RespondPM on
  if (!$readini(AwaySettings.ini,Config,RespondNotice))     writeini AwaySettings.ini Config RespondNotice on
  echo -a 4>>> Successfully loaded $remove($script,$scriptdir) - Away System script by Urza
}

; ##############################################
; # Check for away on connect                  #
; ##############################################
on *:connect: {
  if ($group(#away) == on) {
    if ($($+(%,Away.Newnick.,$network),2) != $me) nick $ifmatch
    ame is currently away $iif(%Away.Reason,- %Away.Reason) $iif(%Away.leavetime,- Left at %Away.Leavtime) $iif($Away.Gonefor,- Gone for $Away.Gonefor)
    !away Away: $iif(%Away.Reason,- %Away.Reason) $iif(%Away.leavetime,- Left at %Away.Leavtime) $iif($Away.Gonefor,- Gone for $Away.Gonefor)
  }
}
; ##############################################
; # Remove Away if unloaded                    #
; ##############################################
on *:unload: { 
  disable #away
  unset %away.*
  hfree away.*.responses
  timerAway.Idlecheck off
}
; ##############################################
; # Cancel Away on exit                        #
; ##############################################
on *:exit: {
  disable #away
  unset %away.*
  timerAway.Idlecheck off
}
; ##############################################
; # Popup Menus                                #
; ##############################################
menu status,channel,query,menubar,@Away.Logs {
  -
  Away Settings
  .Open away options: dialog $iif($dialog(away),-o,-m) away away
  .$iif($active == @Away.Logs,Close window):window -c $active
  . -
  . Set away $+ $chr(58) $iif($group(#away) == off,on,off): {
    if ($group(#away) == off) away $?="Enter away reason or leave black for default (if set)"
    else back
  }
  .-
  .$iif($group(#away) == on && %Away.Preset == 1,$style(3),$iif($group(#away) == on || !$readini(AwaySettings.ini,Presets,1),$style(2))) Preset 1 - $iif($readini(AwaySettings.ini,Presets,1),$gettok($v1,1,126),Not set):away $gettok($readini(AwaySettings.ini,Presets,1),1,126)
  .$iif($group(#away) == on && %Away.Preset == 2,$style(3),$iif($group(#away) == on || !$readini(AwaySettings.ini,Presets,2),$style(2))) Preset 2 - $iif($readini(AwaySettings.ini,Presets,2),$gettok($v1,1,126),Not set):away $gettok($readini(AwaySettings.ini,Presets,2),1,126)
  .$iif($group(#away) == on && %Away.Preset == 3,$style(3),$iif($group(#away) == on || !$readini(AwaySettings.ini,Presets,3),$style(2))) Preset 3 - $iif($readini(AwaySettings.ini,Presets,3),$gettok($v1,1,126),Not set):away $gettok($readini(AwaySettings.ini,Presets,3),1,126)
  .$iif($group(#away) == on && %Away.Preset == 4,$style(3),$iif($group(#away) == on || !$readini(AwaySettings.ini,Presets,4),$style(2))) Preset 4 - $iif($readini(AwaySettings.ini,Presets,4),$gettok($v1,1,126),Not set):away $gettok($readini(AwaySettings.ini,Presets,4),1,126)
  .$iif($group(#away) == on && %Away.Preset == 5,$style(3),$iif($group(#away) == on || !$readini(AwaySettings.ini,Presets,5),$style(2))) Preset 5 - $iif($readini(AwaySettings.ini,Presets,5),$gettok($v1,1,126),Not set):away $gettok($readini(AwaySettings.ini,Presets,5),1,126)
  .$iif($group(#away) == on && %Away.Preset == 6,$style(3),$iif($group(#away) == on || !$readini(AwaySettings.ini,Presets,6),$style(2))) Preset 6 - $iif($readini(AwaySettings.ini,Presets,6),$gettok($v1,1,126),Not set):away $gettok($readini(AwaySettings.ini,Presets,6),1,126)
  .$iif($group(#away) == on && %Away.Preset == 7,$style(3),$iif($group(#away) == on || !$readini(AwaySettings.ini,Presets,7),$style(2))) Preset 7 - $iif($readini(AwaySettings.ini,Presets,7),$gettok($v1,1,126),Not set):away $gettok($readini(AwaySettings.ini,Presets,7),1,126)

}

; ##############################################
; # Main Dialog                                #
; ##############################################
dialog away {
  title Away System Settings
  size -1 -1 150 177
  option dbu
  tab "Basic Settings"                 100,0   0     150 156
  tab "Exceptions and Messaging"       200,0   0     150 156
  Box "Default Away Settings",         2,  4   15    142 45, tab 100
  text "Nick:",                        1,  8   28    12  10, tab 100
  combo                                3,  22  26    50  10, drop tab 100
  edit "",                             5,  75  26    50  10, tab 100
  button "?",                          6,  130 26    10  10, tab 100
  text "Default Away Message:",        24, 8   39    100 10, tab 100
  edit "",                             25, 8   47    117 10, autohs tab 100
  button "?",                          26, 130 47    10  10, tab 100
  box "Global Options"                 4,  4   62    142 92, tab 100
  check "A&uto Away After",            7,  12  71    50  10, tab 100
  edit "",                             8,  63  71    10  10, tab 100
  text "minutes.",                     9,  75  72.5  40  10, tab 100
  button "?",                          10, 130 71    10  10, tab 100
  button "options",                    27, 98  71    30  10, tab 100
  check "Show &Leaving Time?"          11, 12  85    60  10, tab 100
  edit ""                              12, 75  85    50  10, tab 100
  button "?",                          13, 130 85    10  10, tab 100
  check "Show &Time Away?"             14, 12  100   55  10, tab 100
  combo                                15, 75  100   50  10, drop tab 100
  button "?",                          16, 130 100   10  10, tab 100
  box "Auto Return"                    17, 7   115   136 35, tab 100
  text "Cancel away on:"               18, 12  125   80  10, tab 100
  check  "&Channel Message"            19, 60  124   50  10, tab 100
  check  "&Private Message"            20, 60  134   50  10, tab 100
  button "?",                          21, 130 134   10  10, tab 100

  ;Exception + messaging options:  - display only does nothing yet
  box "Messaging",                     30, 4   15   142  90, tab 200
  text "Send messages to:",            31, 8   26   50   10, tab 200
  check "All open channels"            32, 60  25   50   10, tab 200
  check "All open queries"             33, 60  35   50   10, tab 200 
  button "?",                          34, 130 26   10   10, tab 200
  box "Response Messages",             35, 8   48   134  38, tab 200
  text "Respond to:",                  36, 12  56   50   10, tab 200
  check "Channel highlight",           37, 60  55   50   10, tab 200
  check "Private message",             38, 60  65   50   10, tab 200
  check "Private notice",              39, 60  75   50   10, tab 200
  button "?",                          40, 130 55   10   10, tab 200
  button "Get mIRC hilights",          42, 18  90   50   10, tab 200
  button "Modify Hilights",            43, 70  90   50   10, tab 200
  button "?",                          44, 130 90   10   10, tab 200
  box "Exceptions",                    45, 4   109  142  24, tab 200
  button "Modify Away System Exceptions"   46, 8   118  100  10, tab 200
  button "?",                          48, 130 118  10   10, tab 200

  button "Edit &Presets"               22, 12  159  60  15
  button "&Ok"                         23, 80  159  60  15, ok
}
; ##############################################
; # Custom presets dialog                      #
; ##############################################
dialog Custom.Aways {
  title Custom Away Messages
  size -1 -1 236 110 
  option dbu
  box  "Custom Away Triggers"          1,  4   4  227 85
  text "Trigger",                      2,  16  12 30  10
  text "Nick Settings",                3,  50  12 50  10
  text "Away Message",                 4,  130 12 50  10
  list                                 5,  10  20 30  50
  list                                 6,  40  20 50  50 
  list                                 7,  90  20 134 50, autohs
  button "Add",                        8,  10  70 50  15
  button "Edit",                       10, 65  70 50  15
  button "Delete",                     9,  120 70 50  15
  button "Clear",                      12, 175 70 50  15
  button "OK",                         11, 90  90 50  15, OK

}
; ##############################################
; # Idle Away Settings + Help dialogs          #
; ##############################################
dialog Idle.Away.Settings {
  title Idle Away Settings
  size -1 -1 120 85
  option dbu
  box "Idle away settings",           1, 4  4  112 55
  text "Nick Settings:",              2, 8  12 50  10
  combo                               3, 8  20 50  10, drop
  edit "",                            4, 62 20 50  10
  text "Idle away message:",          5, 8  35 50  10
  edit "",                            6, 8  43 104 10, autohs
  button "&Help"                      7, 5  65 50  15
  button "&Ok",                       8, 65 65 50  15, OK
}
Dialog Idle.Away.Help {
  title Away System Help
  size -1 -1 150 90
  option dbu
  box "Idle away help",           1, 4  4  142 60
  text "Idle away nick and automatic message settings work in the same way as the default away settings in the main dialog, except that they define the settings used when you are automatically set away from Idle"   2, 8  15  133 25
  text "you can use %time to refer to the time you must idle before being set as away",  3, 8  45  133 20                                                                                                                                                
  button "&Ok",                   4, 50 70 50 15, OK
}
; ##############################################
; # Preset Settings + Help dialogs             #
; ##############################################
dialog Preset.Settings {
  title Preset Settings
  size -1 -1 120 100
  option dbu
  box "Preset settings",              1,  4  4  112 70
  text "Trigger:",                    2,  8  14 50  10
  edit "",                            3,  30 13 50  10
  text "Nick Settings:",              4,  8  27 50  10
  combo                               5,  8  35 50  10, drop
  edit "",                            6,  62 35 50  10
  text "Away message:",               7,  8  50 50  10
  edit "",                            8,  8  58 104 10, autohs
  button "&Help"                      9,  5  80 50  15
  button "&Ok",                       10, 65 80 50  15, OK
}
Dialog Preset.Help {
  title Away System Help
  size -1 -1 150 90
  option dbu
  box "Presets help",             1, 4  4  142 60
  text "Preset nick and Away message settings work in the same way as the default away settings in the main dialog, except that they define the settings used for the preset you are creating"   2, 8  15  133 27
  text "To use a preset once you have created it simply type /Away TRIGGER",  3, 8  45  133 20                                                                                                                                                
  button "&Ok",                   4, 50 70 50 15, OK
}
; ##############################################
; # Exceptions dialogs                         #
; ##############################################
dialog Away.Exceptions {
  title Away System Exceptions
  size -1 -1 120 100
  option dbu
  box "Exceptions"         1,  4  4  112 75
  text "Networks"          2,  8  12  50 10, center
  list                     3,  8  19 50 58
  button "Add"             6,  61 20 50 10
  button "Delete"          7,  61 34 50 10
  button "Edit"            8,  61 49 50 10
  button "Clear"           9,  61 63 50 10
  button "OK"              10, 35 82 50 15, oks
}
dialog Away.AddException {
  title Add Exception
  size -1 -1 156 190
  option dbu
  box "Add Exception"                                                                              1,  4  4   148 165
  text "Network Name:"                                                                             2,  8  16  40  10
  edit ""                                                                                          3,  50 15  60  10
  text "If you are unsure of a network name you can type: //echo -a $network in mIRC to view it."  20, 8  30  130 15
  box "Exception scope"                                                                            4,  8  50  140 55
  Text "This exception affects:"                                                                   5,  12 60  55  10
  radio "Entire network"                                                                           6,  69 59  65  10
  radio "certain channels only"                                                                    7,  69 69  65  10
  Text "Enter Channels to be excepted, seperated by spaces."                                       8,  12 80  130 10
  edit ""                                                                                          9,  12 90  130 10
  box "Exception Options"                                                                          10, 8  110  140 55
  text "On this network:"                                                                          11, 12 120 45  10
  check "Do not change nick"                                                                       12, 55 120 55  10
  check "Do not send away messages"                                                                13, 55 130 80  10
  check "Do not send hilight responses"                                                            14, 55 140 80  10
  check "Do not send PM responses"                                                                 15, 55 150 80  10
  button "OK"                                                                                      16, 53 172 50  15, Ok
}

; ##############################################
; # Help Dialogs                               #
; ##############################################
dialog Away.Help.6 {
  title Away System Help
  size -1 -1 150 120 
  option dbu
  box "Nick Settings Help",                                                                   1, 5  5   140 90
  text "Nick PREFIX: Adds the specified text to the FRONT of your nick when going away",      2, 8  15  133 20
  text "Nick SUFFIX: Adds the specified text to the END of your nick when going away",        3, 8  35  133 20
  text "Set to: Sets your nick to the specified nick when you set away",                      4, 9  55  133 20   
  text "Don’t Change: Means that you’re nick will not change when going away or coming back", 5, 8  75  133 20          
  button "OK",                                                                                7, 50 100 50 15, OK
}
dialog Away.Help.10 {
  title Away System Help
  size -1 -1 150 90 
  option dbu
  box "Auto Away Help",                                                                                1, 5  5  140 60
  text "Enabling Auto-Away will automatically set you as away if you are idle for the specified time", 2, 8  15 134 20
  text "Time must be between 1 and 60 minutes",                                                        3, 8  35 134 20
  text "Options for settings Idle nick and message can be found by clicking the options button",       4, 8  45 134 20
  button "OK",                                                                                         5, 50 70 50 15, ok
}
dialog Away.Help.13 {
  title Away System Help
  size -1 -1 150 80 
  option dbu
  box "Show Leaving Time Help",                                                                                                    1, 5 5 140 50
  text "Enabling 'Show Leaving Time' will display the time you went away in all your away messages in the specified Time Format",  2, 8 15 134 20
  button "Click Here for a list of codes used in time format",                                                                     3, 8 40 134 10
  button "OK",                                                                                                                     4, 50 60 50 15, ok
}
dialog Away.Help.16 {
  title Away System Help
  size -1 -1 150 90 
  option dbu
  box "Show Time Away Help",                                                                                                         1, 5 5 140 60
  text "Enabling 'Show Time Away' will display how long you have been away in all your away messages in the specified Time Format",  2, 8 15 134 20
  text "Example of Short format: 5h 6m 10s"                                                                                          3, 8 40 134 10
  text "Example of Medium format: 5hrs 6mins 10secs"                                                                                 4, 8 48 134 10
  text "Example of long format: 5 hours 6 minutes 10 seconds"                                                                        5, 8 56 134 10
  button "OK",                                                                                                                       6, 50 70 50 15, ok
}
dialog Away.Help.21 {
  title Away System Help
  size -1 -1 150 65 
  option dbu
  box "Automatic Return Help",                                                                                                    1, 5 5 140 35
  text "Enabling 'Automatic Return' will automatically bring you back from away if you send any Channel And/Or Private message",  2, 8 15 134 20
  button "OK",                                                                                                                    5, 50 45 50 15, ok
}
dialog Away.Help.26 {
  title Away System Help
  size -1 -1 150 55
  option dbu
  box "Default Message Help",                                                    1, 5  5  140 27
  text "If you do not enter a reason when going away this default will be used", 2, 8  15 134 20
  button "OK",                                                                   3, 50 35 50 15, ok
}
dialog Away.Help.34 {
  title Away System Help
  size -1 -1 150 60
  option dbu
  box "Message sending help",                                                                                                         1, 5  5  140 32
  text "These options refer to weather your away message will be sent to channels and/or Pm's (Queries) when leaving and returning.", 2, 8  15 134 20
  button "OK",                                                                                                                        3, 50 40 50 15, ok
}
dialog Away.Help.40 {
  title Away System Help
  size -1 -1 150 80
  option dbu
  box "Auto Response Help",                                                                                       1, 5  5  140 50
  text "These options refer to what actions will trigger an auto message alerting the person that you are away.", 2, 8  15 134 20
  text "Channel highlight is triggered whenever someone says a word that is in your hilights list",               3, 8  35 134 20
  button "OK",                                                                                                    4, 50 60 50  15, ok
}
dialog Away.Help.44 {
  title Away System Help
  size -1 -1 150 120
  option dbu
  box "Hilight help",                                                                                                                                                        1, 5  5  140 92
  text "'Hilight' occurs whenever somebody says a word that is in your hilights list.",                                                                                      2, 8  15 134 20
  text "Your away hilights determine what words, when said, will cause the script to notify the person that you are away, and log the message",                              3, 8  31 134 20
  text "If you have hilights set in mIRC you can click 'Get mIRC Hilights' to have the away system use these same hilights",                                                 4, 8  54 134 20
  text "You may also add or modify seperate ones using the 'Modify Hilights' button. Note that Identifiers such as $me (which refers to your current nick) are also allowed" 5, 8  75 134 20
  button "OK",                                                                                                                                                               6, 50 100 50  15, ok
}
dialog Away.Help.48 {
  title Away System Help
  size -1 -1 150 65
  option dbu
  box "Exceptions help",                                                                                                                        1, 5  5  140 35
  text "Exceptions allow you to specify networks/channels in which away messages are not sent, or networks in which your nick is not changed",  2, 8  15 134 25      
  button "OK",                                                                                                                                  3, 50 45 50  15, ok
}

dialog Away.Help.Time {
  title Away System Help
  size -1 -1 150 155
  option dbu
  box "Time Format Help",                                                   1, 5 5 140 120
  text "The following is a list of Codes that can be used in Time Formats", 2, 8 15 134 20
  box "Time Format Codes",                                                  3, 8 30 134 88
  list                                                                      4, 20 40 20 75
  list                                                                      5, 40 40 90 75
  button "OK",                                                              6, 50 130 50 15, ok
}


; ##############################################
; # Dialog Initiation events                   #
; ##############################################
; ----- Populate Time help
on *:dialog:Away.Help.Time:init:*: {
  did -a $dname 4 HH
  did -a $dname 5 Hours - 2 Digit 24 hour time - $time(HH)
  did -a $dname 4 H 
  did -a $dname 5 Hours - 1 Digit 24 hour time - $time(H)
  did -a $dname 4 hh
  did -a $dname 5 Hours - 2 Digit 12 hour time - $time(hh)
  did -a $dname 4 h
  did -a $dname 5 Hours - 1 Digit 12 hour time - $time(h)
  did -a $dname 4 nn 
  did -a $dname 5 Minutes - 2 Digit - $time(nn)
  did -a $dname 4 n
  did -a $dname 5 Minutes - 1 Digit - $time(n)
  did -a $dname 4 ss 
  did -a $dname 5 Seconds - 2 Digit - $time(ss)
  did -a $dname 4 s
  did -a $dname 5 Seconds - 1 Digit - $time(s)
  did -a $dname 4 tt
  did -a $dname 5 am/pm - Lower case - $time(tt)
  did -a $dname 4 TT
  did -a $dname 5 AM/PM - Upper Case - $time(TT)
}
; ----- Populate main dialog settings
on *:dialog:away:init:*: {
  ;Tab 100 Controls
  did -a $+ $iif($readini(AwaySettings.ini,Config,NickEditType) == Prefix,c) $dname 3 Prefix
  did -a $+ $iif($readini(AwaySettings.ini,Config,NickEditType) == Suffix,c) $dname 3 Suffix
  did -a $+ $iif($readini(AwaySettings.ini,Config,NickEditType) == Set to,c) $dname 3 Set to
  did -a $+ $iif($readini(AwaySettings.ini,Config,NickEditType) == Don't Change,c) $dname 3 Don't Change
  if ($readini(AwaySettings.ini,Config,NickEditType) == Don't Change) did -m $dname 5
  if ($readini(AwaySettings.ini,Config,NickPrefix)) && ($did(away,3).seltext == Prefix) did -ra $dname 5 $readini(AwaySettings.ini,Config,NickPrefix) 
  if ($readini(AwaySettings.ini,Config,NickSuffix)) && ($did(away,3).seltext == Suffix) did -ra $dname 5 $readini(AwaySettings.ini,Config,NickSuffix)
  if ($readini(AwaySettings.ini,Config,NickSetTo)) && ($did(away,3).seltext == Set To) did -ra $dname 5 $readini(AwaySettings.ini,Config,NickSetTo)
  if ($readini(AwaySettings.ini,Config,AutoAway) == on) did -c $dname 7 | else did -m $dname 8
  if ($readini(AwaySettings.ini,Config,AutoAwayTime)) did -a $dname 8 $calc($ifmatch / 60) | else did -a $dname 8 900
  if ($readini(AwaySettings.ini,Config,LeavingTime) == on) did -c $dname 11                | else did -m $dname 12
  if ($readini(AwaySettings.ini,Config,LeavingTimeFormat)) did -a $dname 12 $ifmatch       | else did -a $dname 12 HH:nn:ss
  if ($readini(AwaySettings.ini,Config,TimeAway) == on) did -c $dname 14                   | else did -b $dname 15
  if ($readini(AwaySettings.ini,Config,TimeAwayFormat) == Short) did -ac $dname 15 Short   | else did -a $dname 15 Short
  if ($readini(AwaySettings.ini,Config,TimeAwayFormat) == Medium) did -ac $dname 15 Medium | else did -a $dname 15 Medium
  if ($readini(AwaySettings.ini,Config,TimeAwayFormat) == Long) did -ac $dname 15 Long     | else did -a $dname 15 Long
  if ($readini(AwaySettings.ini,Config,ARChannelMessage) == on) did -c $dname 19
  if ($readini(AwaySettings.ini,Config,ARPrivateMessage) == on) did -c $dname 20
  if ($readini(AwaySettings.ini,Config,DefaultMessage)) did -a $dname 25 $ifmatch
  ;Tab 200 controls
  if ($readini(AwaySettings.ini,Config,MsgChans) == on) did -c $dname 32
  if ($readini(AwaySettings.ini,Config,MsgQueries) == on) did -c $dname 33
  if ($readini(AwaySettings.ini,Config,RespondHilights) == on) did -c $dname 37
  if ($readini(AwaySettings.ini,Config,RespondPM) == on) did -c $dname 38
  if ($readini(AwaySettings.ini,Config,RespondNotice) == on) did -c $dname 39
}
; ----- Populate Custom presets list
on *:dialog:Custom.Aways:init:*: {
  var %x = 1
  while (%x <= 7) {
    if ($readini(AwaySettings.ini,Presets,%x)) {
      did -a $dname 5 $gettok($v1,1,126)
      did -a $dname 6 $gettok($v1,2,126)
      did -a $dname 7 $gettok($v1,3-,126)
    } 
    else halt
    inc %x
  }
}
; ----- Populate Idle Away Settings
on *:dialog:Idle.Away.Settings:init:*: {
  tokenize 126 $readini(AwaySettings.ini,n,Config,IdleSettings)
  did -a $+ $iif($1 == Prefix,c) $dname 3 Prefix
  did -a $+ $iif($1 == Suffix,c) $dname 3 Suffix
  did -a $+ $iif($1 == Set to,c) $dname 3 Set to
  did -a $+ $iif($1 == Don't Change,c) $dname 3 Don't Change
  if ($1 == Don't Change) did -m $dname 5
  else did -ra $dname 4 $2
  if ($3) did -a $dname 6 $3-
}
; ----- Populate Preset settings
on *:dialog:Away.Preset:init:*: {
  if (%Away.EditPreset) {
    var %pre = %Away.EditPreset, %trigger = $did(Custom.Aways,5).seltext
    var %edittype = $gettok($did(Custom.Aways,6).seltext,1,58), %nickedit = $gettok($did(Custom.Aways,6).seltext,2,58)
    var %reason = $did(Custom.Aways,7).seltext
    did -a $dname  3 %trigger
    did -a $+ $iif(%edittype == Prefix,c) $dname 5 Prefix
    did -a $+ $iif(%edittype == Suffix,c) $dname 5 Suffix
    did -a $+ $iif(%edittype == Set to,c) $dname 5 Set to
    did -a $+ $iif(%edittype == Don't Change,c) $dname 5 Don't Change
    if (%edittype == Don't Change) did -m $dname 6
    else did -ra $dname 6 %nickedit
    if (%reason) did -a $dname 8 %reason
  }
  else {
    did -a $dname 5 Prefix
    did -a $dname 5 Suffix
    did -a $dname 5 Set to
    did -a $dname 5 Don't Change
  }
}
; Exception initiation events
on *:dialog:Away.Exceptions:init:*: {
  var %x = 1,%total = $ini(AwaySettings.ini,Exceptions,0)
  while (%x <= %total) {
    did -a $dname 3 $ini(AwaySettings.ini,Exceptions,%x)
    inc %x
  }
}
on *:dialog:Away.AddException:init:*: {
  if (%Away.Exception) {
    var %info = $readini(AwaySettings.ini,Exceptions,%away.Exception)
    var %scope = $gettok(%info,1,126), %options = $gettok(%info,2,126), %chans = $gettok(%info,3-,126)
    did -a $dname 3 %Away.Exception
    if (%scope == 1) {
      did -c $dname 6
      did -b $dname 9
    }
    else {
      did -c $dname 7
      did -b $dname 12,15
      did -e $dname 9
      did -a $dname 9 %chans
    }
    if ($left(%options,1) == 1) && (%scope == 1) did -c $dname 12
    if ($mid(%options,2,1) == 1) did -c $dname 13
    if ($mid(%options,3,1) == 1) did -c $dname 14
    if ($right(%options,1) == 1) && (%scope == 1) did -c $dname 15
  }
  else {
    did -c $dname 6
    did -b $dname 9
  }
}

; ##############################################
; # Dialog Sclick Events                       #
; ##############################################
; ----- Open Time Help dialog
on *:dialog:Away.Help.13:sclick:3: {
  dialog $iif($dialog(Away.Help.Time),-o,-m) Away.Help.Time Away.Help.Time
  dialog -x $dname
}
; ----- Select same line in each column in time help dialog
on *:dialog:Away.Help.Time:sclick:*: {
  if ($did == 4) did -c $dname 5 $did(4).sel
  elseif ($did == 5) did -c $dname 4 $did(5).sel
}
; ----- Processing clicks for main dialog
on *:dialog:away:sclick:*: {
  ; Tab 100
  if ($did == 3) {
    writeini AwaySettings.ini Config NickEditType $did(3).seltext
    if ($did(3).seltext == Prefix) did -nra $dname 5 $readini(AwaySettings.ini,Config,NickPrefix)
    elseif ($did(3).seltext == suffix) did -nra $dname 5 $readini(AwaySettings.ini,Config,NickSuffix)
    elseif ($did(3).seltext == Set to) did -nra $dname 5 $readini(AwaySettings.ini,Config,NickSetTo)
    else did -rm $dname 5 
  }
  if ($did == 7) && ($did(7).state == 0)  did -m $dname 8 
  elseif ($did == 7) && ($did(7).state == 1) did -n $dname 8
  elseif ($did == 11) && ($did(11).state == 0) did -m $dname 12
  elseif ($did == 11) && ($did(11).state == 1) did -n $dname 12
  elseif ($did == 14) && ($did(14).state == 0) did -b $dname 15
  elseif ($did == 14) && ($did(14).state == 1) did -e $dname 15
  elseif ($istok(6|10|13|16|21|26|34|40|44|48,$did,124)) dialog $iif($dialog($+(Away.Help.,$did)),-o,-m) $+(Away.Help.,$did) $+(Away.Help.,$did)
  elseif ($did == 22) dialog $iif($dialog(Custom.Aways),-o,-m) Custom.Aways Custom.Aways 
  elseif ($did == 27) dialog $iif($dialog(Idle.Away.Settings),-o,-m) Idle.Away.Settings Idle.Away.Settings
  ; Tab 200
  elseif ($did == 42) {
    if ($input(Retrieved the following hilights from your current mIRC settings: $crlf $crlf $+ $Get.Highlights $Crlf $crlf $+ Would you like to use these as your away system highlights? You can use the 'Modify Hilights' button to modify or add to these.,yi,Highlights)) {
      writeini AwaySettings.ini Config Hilights $Get.Highlights
    }
  }
  elseif ($did == 43) {
    var %hilights = $input(Enter Hilight words or identifiers seperated by commans ONLY. $crlf $+ Eg: $+($me,$chr(44),ALTNICK,$chr(44),$ $+ me),oe,Modify Hilights,$readini(AwaySettings.ini,n,Config,Hilights)))
    if (%hilights) writeini AwaySettings.ini Config Hilights $remove(%hilights,$chr(32))
    else remini Settings.ini Away.Config Hilights
  }
  elseif ($did == 46) { 
    dialog $iif($dialog(Away.Exceptions),-v,-m) Away.Exceptions Away.Exceptions
  }
}
; ----- Process button clicks and keep selection of all columns the same in presets dialog
on *:dialog:Custom.Aways:sclick:*: { 
  if ($did == 5)     did -c $dname 6,7 $did(5).sel
  elseif ($did == 6) did -c $dname 5,7 $did(6).sel
  elseif ($did == 7) did -c $dname 5,6 $did(7).sel
  elseif ($did == 8) dialog $iif($dialog(Away.Preset),-v,-m) Away.Preset Preset.Settings
  elseif ($did == 9) {
    if (!$did(5).sel) var %x = $input(Error: You must select an entry to delete,wo,Invalid Selection) 
    elseif ($?!="Are you sure you want to delete this entry - $did(5).seltext ") {
      did -d $dname 5 $did(5).sel  
      did -d $dname 6 $did(6).sel  
      did -d $dname 7 $did(7).sel  
    }
  }
  elseif ($did == 10) {
    if (!$did(5).sel) { var %x = $input(Error: You must select an entry to edit,wo,Invalid Selection) | halt } 
    set %Away.EditPreset $did(5).sel
    dialog $iif($dialog(Away.Preset),-v,-m) Away.Preset Preset.Settings
  }
  elseif ($did == 12) {
    if ($input(Are you sure you want to clear all your presets?,qy,Validation Prompt)) {
      var %x = 7
      while (%x > 0) {
        did -c $dname 5 %x
        if ($did(5).seltext) did -d $dname 5,6,7 $did(5).sel
        dec %x
      }
    }
  }
} 

; ----- Process Idle Away clicks/settings
on *:dialog:Idle.Away.Settings:sclick:*: {
  var %time = $calc($readini(AwaySettings.ini,Config,AutoAwayTime) / 60)
  if ($did == 3) {
    if ($did(3).seltext == Don't Change) did -rm $dname 4
    else did -n $dname 4
  } 
  elseif ($did == 7) dialog $iif($dialog(Idle.Away.help),-v,-m) Idle.Away.help Idle.Away.Help
}
; ----- Process Preset dialog clicks/settings
on *:dialog:Away.Preset:sclick:*: {
  if ($did == 5) {
    if ($did(5).seltext == Don't Change) did -rm $dname 6
    else did -n $dname 6
  }
  elseif ($did == 9) dialog $iif($dialog(Preset.Help),-v,-m) Preset.Help Preset.Help
}
; ----- Exception Clicks
on *:dialog:Away.Exceptions:sclick:*: {
  if ($did == 6) dialog $iif($dialog(Away.AddException),-v,-m) Away.AddException Away.AddException
  elseif ($did == 7) {
    if (!$did(3).sel) var %x = $input(You must select an entry to delete,wo,Invalid Selection)
    elseif ($?!="Are you sure you want to delete this entry - $did(3).seltext ") {
      remini AwaySettings.ini Exceptions $did(3).seltext
      did -d $dname 3 $did(3).sel
    }
  }
  elseif ($did == 8) {
    if (!$did(3).sel) var %x = $input(You must select an entry to edit,wo,Invalid Selection)
    else { 
      set %Away.Exception $did(3).seltext
      set %Away.ExceptionNum $did(3).sel
      dialog $iif($dialog(Away.AddException),-v,-m) Away.AddException Away.AddException
    }
  }
  elseif ($did == 9) {
    if ($input(Are you sure you want to clear all your network exceptions?,qy,Validation Prompt)) {
      var %x = $did(3).lines
      remini AwaySettings.ini Exceptions
      while (%x > 0) {
        did -c $dname 3 %x
        if ($did(3).seltext) did -d $dname 3 $did(3).sel
        dec %x
      }
    }
  }
}
on *:dialog:Away.AddException:Sclick:*: { 
  if ($did == 6) { 
    did -e $dname 12,15 
    did -b $dname 9 
    did -r $dname 9
  } 
  elseif ($did == 7) { 
    did -b $dname 12,15 
    did -e $dname 9 
    if ($did(12).state == 1) did -u $dname 12
    if ($did(15).state == 1) did -u $dname 15
  }
}
; ##############################################
; # Dialog Close Events                        #
; ##############################################
; ----- Main dialog - save data
on *:dialog:Away:close:*: {
  ; tab 100 settings
  if ($did(5)) {
    if ($did(3).seltext == Prefix) writeini AwaySettings.ini Config NickPrefix $did(5)
    elseif ($did(3).seltext == Suffix) writeini AwaySettings.ini Config NickSuffix $did(5)
    elseif ($did(3).seltext == Set to) writeini AwaySettings.ini Config  NickSetTo $did(5)
  }  
  else { 
    writeini AwaySettings.ini Config NickPrefix Away|
    writeini AwaySettings.ini Config NickSuffix |Away
  }
  writeini AwaySettings.ini Config AutoAway $iif($did(7).state == 0,off,on)
  writeini AwaySettings.ini Config AutoAwayTime $iif($did(8),$calc($did(8) * 60),900)
  writeini AwaySettings.ini Config LeavingTime $iif($did(11).state == 0,off,on)
  writeini AwaySettings.ini Config LeavingTimeFormat $iif($did(12),$did(12),HH:nn:ss)
  writeini AwaySettings.ini Config TimeAway $iif($did(14).state == 0,off,on)
  writeini AwaySettings.ini Config TimeAwayFormat $iif($did(15),$did(15),Shorts)
  writeini AwaySettings.ini Config ARChannelMessage $iif($did(19).state == 0,off,on)
  writeini AwaySettings.ini Config ARPrivateMessage $iif($did(20).state == 0,off,on)
  if ($did(25)) writeini AwaySettings.ini Config DefaultMessage $did(25)
  else remini Settings.ini Away.Config DefaultMessage
  if ($readini(AwaySettings.ini,Config,AutoAway) == on) .timerAway.IdleCheck -o 0 30 Away.IdleCheck
  elseif ($timer(Away.IdleCheck)) .timerAway.IdleCheck off

  ;Tab 200 settings
  writeini AwaySettings.ini Config MsgChans $iif($did(32).state == 0,off,on)
  writeini AwaySettings.ini Config MsgQueries $iif($did(33).state == 0,off,on)
  writeini AwaySettings.ini Config RespondHilights $iif($did(37).state == 0,off,on)
  writeini AwaySettings.ini Config RespondPM $iif($did(38).state == 0,off,on)
  writeini AwaySettings.ini Config RespondNotice $iif($did(39).state == 0,off,on)
}
; ----- Save presets
on *:dialog:Custom.Aways:close:*: {
  var %x = 1, %lines = $did(5).lines
  while (%x <= %lines) {
    did -c $dname 5,6,7 %x
    writeini AwaySettings.ini presets %x $+($did(5).seltext,~,$did(6).seltext,~,$did(7).seltext)
    inc %x
  }
  dec %x
  while (%x < 7) {
    inc %x
    if ($readini(AwaySettings.ini,presets,%x)) remini AwaySettings.ini Presets %x
  }
}
; ----- Save Idle away settings
on *:dialog:Idle.Away.Settings:close:*: {
  writeini AwaySettings.ini Config IdleSettings $+($did(3).seltext,~,$iif($did(4),$ifmatch,IDLE),~,$iif($did(6),$ifmatch,Auto away after % $+ time minutes idle))
}
; ----- Save Preset settings
on *:dialog:Away.Preset:close:*: {
  var %pre = %away.EditPreset
  if (!$did(3)) var %x = $input(Error: No trigger was specified,ow,Input Error)
  elseif (!$did(6)) && ($did(5).seltext != Don't Change) var %x = $input(Error: You did not specify $iif($did(5).seltext,a nick $iif($did(5).seltext == set to,to change to,$ifmatch),any nick settings),ow,Input Error)
  elseif ($remove($did(6),$chr(91),$chr(93),$chr(92),$chr(45),$chr(95),$chr(123),$chr(124),$chr(125)) !isalnum) && ($did(6)) { var %x = $input(Error: Invalid Characters detected in specified nick,wo,Input Error) | halt }
  elseif (!$did(5).seltext) var %x = $input(Error: You have not specified how to change your nick - Select an option from the nick settings drop down,ow,Error)
  elseif ($numtok($did(3),32) > 1) || ($numtok($did(6),32) > 1) var %x = $input(Error: Trigger and nick Settings can each only be one word long,wo,Input Error)
  else {
    did $iif(%pre,-o,-a) Custom.Aways 5 $iif(%pre,%pre) $did(3)
    did $iif(%pre,-o,-a) Custom.Aways 6 $iif(%pre,%pre) $did(5).seltext $+ $iif($did(5).seltext != Don't Change,: $did(6))
    did $iif(%pre,-o,-a) Custom.Aways 7 $iif(%pre,%pre) $did(8)
    unset %away.EditPreset
  }
}
; ---- Save Exception settings
on *:dialog:Away.AddException:close:*: {
  if (!$did(3)) var %x = $input(No Network name was entered,wo,Input Error)
  elseif ($numtok($did(3),32) > 1) var %x = $input(Network name may not contain spaces,wo,Input Error)
  else {
    var %scope = $iif($did(6).state == 1,1,2)
    var %x = 1, %numchans = $numtok($did(9),32)
    while (%x <= %numchans) {
      var %token = $gettok($did(9),%x,32) 
      if (#?* iswm %token) var %chans = %chans %token
      elseif (%token != $chr(35)) var %chans = %chans $+($chr(35),%token)
      inc %x
    }
    var %x = 12
    while (%x <= 15) {
      var %options = %options $+ $did(%x).state
      inc %x
    }  
    did $iif(%Away.ExceptionNum,-o,-a) Away.Exceptions 3 $iif(%Away.ExceptionNum,$ifmatch) $did(3)
    writeini AwaySettings.ini Exceptions $did(3) $+(%scope,~,%options,~,%chans)
    unset %Away.Exception*
  }
}
; ##############################################
; # /Away And /back aliases                    #
; ##############################################
alias away {
  ; ----- Unset Idle timer, Get highlights, enable #away group for logging etc
  if ($timer(Away.IdleCheck)) .timerAway.IdleCheck off
  set %Away.Hilights $readini(awaySettings.ini,n,Config,Hilights)
  .enable #away

  ; ---- Retrieve away settings from config/User entry
  var %time = $calc($readini(AwaySettings.ini,Config,AutoAwayTime) / 60)
  if ($1) set %away.Reason $1- 
  elseif ($readini(AwaySettings.ini,Config,DefaultMessage)) set %away.Reason $v1
  set %Away.LeftAt $ctime
  if ($readini(AwaySettings.ini,Config,LeavingTime) == on) {
    var %LeavingTimeFormat = $readini(AwaySettings.ini,Config,LeavingTimeFormat)
    set %away.LeaveTime $time(%LeavingTimeFormat)
  }
  ; ---- Check for idleaway
  If ($1- = Auto.Idle.Away) {
    var %IdleInfo = $readini(AwaySettings.ini,Config,IdleSettings)
    var %edittype = $gettok(%IdleInfo,1,126)
    if (%edittype == Set to) var %nickset = $gettok(%IdleInfo,2,126)
    else var %nickadd = $gettok(%IdleInfo,2,126)
    set %Away.Reason $($gettok(%IdleInfo,3-,126),2)
  }
  else {
    var %edittype = $readini(AwaySettings.ini,Config,NickEditType)
    if (%edittype == Set To) var %nickset = $readini(AwaySettings.ini,Config,NickSetTo)
    else var %nickadd = $readini(AwaySettings.ini,Config,Nick $+ %edittype) 
  }
  ; ----- Check for presets
  var %x 1 
  while (%x <= 7) {
    if ($readini(AwaySettings.ini,Presets,%x)) {
      var %preset = $v1
      if ($1- == $gettok(%preset,1,126)) {
        var %edittype = $gettok($gettok(%preset,2,126),1,58)
        var %nickadd = $remove($gettok($gettok(%preset,2,126),2,58),$chr(32))
        set %Away.Reason $gettok(%preset,3-,126)
        set %Away.Preset %x
        var %x = 7
      }
    }
    inc %x
  }
  ; ----- Cycle Connections to change nick/send msg
  var %x = 1, %connections = $scon(0) 
  while (%x <= %connections) {
    scon %x
    if ($status == connected) {
      unset %Except.*
      if ($readini(AwaySettings.ini,Exceptions,$network)) {
        var %Except.info = $v1
        var %Except.Scope = $gettok(%Except.info,1,126)
        var %Except.Options = $gettok(%Except.info,2,126)
        if (%Except.Scope == 2) && ($mid(%Except.Options,2,1) == 1) var %Except.NoMsgChans = $gettok(%Except.Info,3-,126)
        if (%Except.Scope == 1) && ($left(%Except.Options,1) == 1) var %Except.NoNickChange = 1
        if (%Except.Scope == 1) && ($mid(%Except.Options,2,1) == 1) var %Except.NoAwayMsg = 1
      }
      set $+(%,Away.Oldnick.,$network) $me
      if ($readini(AwaySettings.ini,Config,NickEditType) != Don't Change) && (!%Except.NoNickChange) {
        if (%edittype == Set To) && (%NickSet != $me) var %newnick = %NickSet 
        if (%edittype == Prefix) && ($+(%nickadd,*) !iswm $me) var %newnick = $+(%nickadd,$me)
        if (%edittype == Suffix) && ($+(*,%nickadd) !iswm $me) var %newnick = $+($me,%nickadd)
        set $+(%,Away.Newnick.,$network) $iif(%newnick,$ifmatch,$me)
        if (%newnick) nick %newnick
      }
      if ($chan(0)) && ($readini(AwaySettings.ini,Config,MsgChans) == on) && (!%Except.NoAwayMsg) {
        var %Chan = 1, %TotalChans = $chan(0)
        while (%chan <= %TotalChans) {
          if (!$istok(%Except.NoMsgChans,$chan(%chan),32)) describe $chan(%chan) is now away $iif(%Away.Reason,- %Away.Reason) $iif(%Away.leavetime,- Left at %Away.Leavetime)           
          inc %chan
        }
      }
      if ($readini(AwaySettings.ini,Config,MsgQueries) == on) && (!%Except.NoAwayMsg)  {
        qme is now away $iif(%Away.Reason,- %Away.Reason) $iif(%Away.leavetime,- Left at %Away.Leavetime)
      }
      !away Away: $iif(%Away.Reason,- %Away.Reason) $iif(%Away.leavetime,- Left at %Away.Leavetime) 
    }
    inc %x
  }
}

alias back {
  var %x = 1, %connections = $scon(0) 
  while (%x <= %connections) {
    scon %x
    if ($status == connected) {
      unset %Except.*
      if ($readini(AwaySettings.ini,Exceptions,$network)) {
        var %Except.info = $v1
        var %Except.Scope = $gettok(%Except.info,1,126)
        var %Except.Options = $gettok(%Except.info,2,126)
        if (%Except.Scope == 2) && ($mid(%Except.Options,2,1) == 1) var %Except.NoMsgChans = $gettok(%Except.Info,3-,126)
        if (%Except.Scope == 1) && ($left(%Except.Options,1) == 1) var %Except.NoNickChange = 1
        if (%Except.Scope == 1) && ($mid(%Except.Options,2,1) == 1) var %Except.NoAwayMsg = 1
      }

      if (!%Except.NoNickChange) && ($($+(%,Away.Oldnick.,$network),2)) nick $ifmatch 

      ; ----- Cycle Connections to change nick/send msg
      if ($chan(0)) && ($readini(AwaySettings.ini,Config,MsgChans) == on) && (!%Except.NoAwayMsg) {
        var %Chan = 1, %TotalChans = $chan(0)
        while (%chan <= %TotalChans) {
          if (!$istok(%Except.NoMsgChans,$chan(%chan),32)) describe $chan(%chan) is back $iif(%away.Reason,- from %Away.Reason) $iif(%Away.Leavetime,- Left at %Away.Leavetime) $iif($Away.GoneFor,- Gone for $Away.GoneFor)   
          inc %chan
        }
      }
      if ($readini(AwaySettings.ini,Config,MsgQueries) == on) && (!%Except.NoAwayMsg) {
        qme is now away $iif(%Away.Reason,- %Away.Reason) $iif(%Away.leavetime,- Left at %Away.Leavetime)
      }
      !away
    }
    inc %x
  }
  .disable #away 
  unset %away.* 
  if ($hget(Away.PM.Responses)) || ($hget(Away.Highlight.Responses)) hfree -w Away.*.Responses 
  if ($readini(AwaySettings.ini,Config,AutoAway) == on) .timerAway.IdleCheck -o 0 30 Away.IdleCheck
}
; ##############################################
; # Other Aliases                              #
; ##############################################
alias -l Away.Gonefor {
  if ($readini(AwaySettings.ini,Config,TimeAway) == on) {
    var %TimeAwayFormat = $readini(AwaySettings.ini,Config,TimeAwayFormat)
    if (%Away.LeftAt) {
      var %duration = $duration($calc($ctime - %Away.LeftAt),%TimeAwayFormat)
      if (%TimeAwayFormat == Short) return $Short.Duration(%duration)
      elseif (%TimeAwayFormat == medium) return %duration
      elseif (%TimeAwayFormat == long) return $Long.Duration(%duration)
    }
  }
  else return $false
}
alias -l Short.Duration return $replacex($1-,secs,s,sec,s,mins,m,min,m,hrs,h,hr,h,days,d,day,d,wks,w,wk,w)
alias -l Long.Duration return $replacex($1-,sec,second,secs,seconds,min,minute,mins,minutes,hr,hour,hrs,hours,wk,week,wks,weeks)

alias -l Get.Highlights {
  var %x = 1, %Groups = $ini(mirc.ini,highlight,0)
  while (%x <= %groups) {
    var %Away.Highlights = $addtok(%Away.highlights,$highlight(%x),44)
    inc %x
  }
  return %Away.Highlights
}
alias -l Check.For.highlights { 
  if (!%Away.Highlights) set %Away.Highlights $readini(AwaySettings.ini,n,Config,Hilights)
  var %x = 1, %highlights = $numtok(%Away.highlights,44)
  while (%x <= %highlights) {
    var %chighlight = $($gettok(%Away.Highlights,%x,44),2)
    if ($istok($1-,%chighlight,32)) return %chighlight
    inc %x
  }
  return $false
}
alias -l Away.Logwin {
  if (!$window(@Away.Logs)) window -eknz @Away.Logs
  echo -ti2 @Away.Logs $1-
}
alias -l Highlight.Response {
  if (!$hget(Away.highlight.Responses,$+($1,.,$2))) {
    scid $1 .notice $2 I am currently away $iif(%Away.Reason,- %Away.Reason) $iif(%Away.LeaveTime,- Left at %Away.LeaveTime) $iif($away.gonefor,- Gone for $away.gonefor) - One time response to highlight
    hadd -m Away.Highlight.Responses $+($1,.,$2) 1
  }
}
alias -l Private.Message.Response {
  if (!$hget(Away.PM.Responses,$+($1,.,$2))) {
    scid $1 .notice $2 I am currently away $iif(%Away.Reason,- %Away.Reason) $iif(%Away.LeaveTime,- Left at %Away.LeaveTime) $iif($away.gonefor,- Gone for $away.gonefor) - One time response to Private Message
    hadd -m Away.PM.Responses $+($1,.,$2) 1
  }
}
alias -l Away.IdleCheck {
  var %x = 1, %networks = $scon(0) 
  var  %AutoAwayTime = $readini(AwaySettings.ini,Config,AutoAwayTime)
  while (%x <= %networks) {
    scon %x {
      if ($status == Connected) && ($idle < %AutoAwayTime) var %Idle = off
    }    
    inc %x
  }
  if (%idle != off) away Auto.Idle.Away
}
alias Away.Config dialog  $iif($dialog(Away),-v,-m) Away Away
; ##############################################
; # Logging and hilight resposes               #
; ##############################################
#away off
;Hilight responses
on *:text:*:#: {
  if (!$Check.For.highlights($1-)) && (!$istok($1-,$me,32)) && (!$istok($1-,$($+(%,Away.Oldnick.,$network),2),32)) return
  else {
    Away.Logwin 4[10CHANNEL MESSAGE4] $+(4[10,$iif($scon(0) > 1,$+($network,12/10)),$chan,12/10,$nick,4]) $1-
    if ($readini(AwaySettings.ini,Exceptions,$network)) {
      var -s %Except.info = $v1
      var -s %Except.Scope = $gettok(%Except.info,1,126), %Except.Options = $gettok(%Except.info,2,126)
      if (%Except.Scope == 2) && ($mid(%Except.Options,3,1) == 1) var %Except.NoHilight = $gettok(%Except.Info,3-,126)
      elseif (%Except.Scope == 1) && ($mid(%Except.Options,3,1) == 1) return
    }
    if (!$istok(%Except.NoHilight,$chan,32)) && ($readini(AwaySettings.ini,Config,RespondHilights) == on) Highlight.Response $cid $nick 
  }
}
on *:action:*:#: {
  if (!$check.for.highlights($1-)) && (!$istok($1-,$me,32)) && (!$istok($1-,$($+(%,Away.Oldnick.,$network),2),32)) return
  else {
    Away.Logwin 4[10CHANNEL  10ACTION4] $+(4[10,$iif($scon(0) > 1,$+($network,12/10)),$chan,12/10,$nick,4]) * $nick $1-
    if ($readini(AwaySettings.ini,Exceptions,$network)) {
      var %Except.info = $v1
      var %Except.Scope = $gettok(%Except.info,1,126), %Except.Options = $gettok(%Except.info,2,126)
      if (%Except.Scope == 2) && ($mid(%Except.Options,3,1) == 1) var %Except.NoHilight = $gettok(%Except.Info,3-,126)
      elseif (%Except.Scope == 1) && ($mid(%Except.Options,3,1) == 1) return
    }    
    if (!$istok(%Except.NoHilight,$chan,32)) && ($readini(AwaySettings.ini,Config,RespondHilights) == on) Highlight.Response $cid $nick 
  }
}
; Private notice response
on *:notice:*:?: {
  if (*serv !iswm $nick) {
    Away.Logwin 4[10PRIVATE NOTICE4] $+(4[10,$iif($scon(0) > 1,$+($network,12/10)),Private,12/10,$nick,4]) $1-
    if ($readini(AwaySettings.ini,Exceptions,$network)) {
      var %Except.info = $v1
      var %Except.Scope = $gettok(%Except.info,1,126), %Except.Options = $gettok(%Except.info,2,126)
      if (%Except.Scope == 1) && ($right(%Except.Options,1) == 1) return
    }   
    if ($readini(AwaySettings.ini,Config,RespondNotice) == on) Private.Message.Response $cid $nick 
  }
}
;PM responses
on *:text:*:?: {
  if ($readini(AwaySettings.ini,Config,RespondPM) == on) && (*serv !iswm $nick) {
    if ($readini(AwaySettings.ini,Exceptions,$network)) {
      var %Except.info = $v1
      var %Except.Scope = $gettok(%Except.info,1,126), %Except.Options = $gettok(%Except.info,2,126)
      if (%Except.Scope == 2) && ($mid(%Except.Options,3,1) == 1) var %Except.NoHilight = $gettok(%Except.Info,3-,126)
      elseif (%Except.Scope == 1) && ($right(%Except.Options,1) == 1) return
    }   
    Private.Message.Response $cid $nick
  }
}
;Return from away on input if set
on *:input:#: {
  if ($left($1,1) != $readini(mirc.ini,text,commandchar)) {
    if ($readini(AwaySettings.ini,Config,ARChannelMessage) == on) back
  }
}
on *:input:?: {
  if ($left($1,1) != $readini(mirc.ini,text,commandchar)) {
    if ($readini(AwaySettings.ini,Config,ARPrivateMessage) == on) back
  }
}
#away end

; #############################################################################
; ## Auto Startup script                                                     ## 
; ## Written by Urza                                                         ##
; ## urza23@hotmail.com                                                      ##  
; #############################################################################

; #############################################################################
; # Options alias/menu                                                        #
; #############################################################################
alias Startup_Manager {
  dialog $iif($dialog(Startup),-v,-m) Startup Startup
}
menu * {
  Startup Manager:/Startup_Manager
}

; #############################################################################
; # Options dialog                                                            #
; #############################################################################
dialog -l Startup {
  title "Auto Startup Manager"
  size -1 -1 275 240
  option dbu

  box "Networks",                                          1,  4  2 130 100
  list                                                     2, 10 10 65   85, size
  button "Add",                                            3, 78 10 40   15
  button "Delete",                                         4, 78 30 40   15
  button "Move up",                                        5, 78 50 40   15
  button "Move down",                                      6, 78 70 40   15

  box "Channels",                                          7, 140  2 130 100
  list                                                     8, 146 10  65  85, size
  button "Add",                                            9, 214 11  40  15
  button "Delete",                                        10, 214 30  40  15
  button "Move up",                                       11, 214 50  40  15
  button "Move down",                                     12, 214 70  40  15

  box "Network Information and Options",                  13,   4 105 130 125
  text "Address:",                                        16,   8 112  42   8
  text "Port:",                                           17, 101 112  14   8
  edit "",                                                18,   8 120  86  10
  text ":",                                               19,  94 120   4   8, center
  edit "",                                                20,  97 120  19  10, limit 4
  text "Description:",                                    21,   8 132  30   8
  edit "",                                                22,   8 140 121  10, autohs
  text "Nick on this network:",                           23,   8 155  53   8
  edit "",                                                24,  59 153  50  10
  check "Connect on startup",                             25,   8 165  58  10
  button "Perform commands",                              14,  70 165  60  10    
  check "Enable Auto ID/Auth",                            26,   8 176  63  10
  check "Enable auto ghost",                              27,  72 176  54  10
  text "Auth Type:",                                      28,   6 190  30   8, right
  combo                                                   29,  38 190  50  10, drop
  text "User name:",                                      30,   6 203  30   8, right
  edit "",                                                31,  38 202  50  10, autohs
  text Pasword:,                                          32,   6 214  30   8, right
  edit "",                                                33,  38 213  50  10, password autohs

  box "Channel Information and Options",                  34, 140 105 130 117
  text "Description:",                                    35, 144 112  34   8
  edit "",                                                36, 144 120 121  10, autohs
  check "Message when you join (identifiers allowed)",    37, 144 133 115  10
  edit "",                                                38, 144 143 121  10, autohs
  check "Message when others join (identifiers allowed)", 43, 144 156 120  10 
  edit "",                                                44, 144 166 121  10, autohs
  check "Join on connect",                                45, 144 180  50  10
  text "Key:",                                            46, 195 181  10  10
  edit "",                                                47, 210 180  50  10, password autohs
  check "Identify to Chanserv",                           39, 144 190  63  10
  text Pasword:,                                          40, 145 200  30   8, right
  edit "",                                                41, 176 200  50  10, password autohs
  check "Set +q (founder access)",                        42, 152 210  71  10

  button "Close",                                         48, 229 224  40  15, ok
}
; #############################################################################
; # Perform dialog                                                            #
; #############################################################################
dialog -l Perform {
  title "Perfoms"
  size -1 -1 135 139
  option dbu
  box "",                                                                           2,  3   3 128 115
  box "Performs",                                                                   1,  3   3 128  25
  text "Enter any commands to be performed upon connecting. One command per line.", 3,  9  11 119  16, center
  text "Network:",                                                                  4,  8  32  23   8
  combo                                                                             5, 33  31  60  10, drop
  edit "",                                                                          6,  7  45 120  70, multi hsbar vsbar return
  button "Close",                                                                   7, 94 121  37  15, ok
}
; #############################################################################
; # Dialog Initiation events                                                  #
; #############################################################################
on *:dialog:Startup:init:*: {
  var %x = 1, %networks = $readini(Startup.ini,Config,networks), %total = $numtok(%networks,44) 
  while (%x <= %total) {
    var %network = $gettok(%networks,%x,44)
    did -a $dname 2 %network
    inc %x
  }
  did -a $dname 29 Nickserv
  did -a $dname 29 Authserv
  did -a $dname 29 Quakenet (Q)
  did -a $dname 29 Undernet (X)
  did -a $dname 29 NetGamers (P)
  did -b $dname 9,10,11,12,14,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33,35,36,37,38,39,40,41,42,43,44,45,46,47
}
on *:dialog:Perform:init:*: {
  var %Network = %Perform.Network | unset %Perform.Network
  var %networks = $readini(Startup.ini,config,networks)
  var %x = 1, %total = $numtok(%networks,44)
  while (%x <= %total) {
    var %net = $gettok(%networks,%x,44)
    if (%net == %Network) did -ac $dname 5 %net
    else did -a $dname 5 %net
    inc %x
  }
  LoadPerforms %network
}

; #############################################################################
; # Dialog Sclick events                                                      #
; #############################################################################
on *:dialog:Startup:sclick:*: {
  var %network = $did(2).seltext, %networks = $readini(Startup.ini,config,networks)
  var %channel = $did(8).seltext, %chans = $readini(Startup.ini,$replace(%network,$chr(32),-),channels)
  if ($did == 2) && ($did(2).sel) {
    did -e $dname 9,10,11,12,14,16,17,18,19,20,21,22,23,24,25,26,27
    LoadOptions network $did(2).seltext
    ClearChanOptions
  }
  elseif ($did == 3) {
    var %network = $$?="Enter the name of the network you wish to add $crlf $crlf $+ Note: This MUST be proper name of the network. If you are unsure of the proper name type //echo -a $ $+ network and copy the result."
    if ($istok(%networks,%network,44)) var %x = $input(%network has already been added,oh,Error)
    else {
      did -a $dname 2 %network
      writeini -n Startup.ini $replace(%network,$chr(32),-) name %network
      writeini -n Startup.ini $replace(%network,$chr(32),-) nick $me
      writeini -n Startup.ini $replace(%network,$chr(32),-) connect 1
      writeini -n Startup.ini $replace(%network,$chr(32),-) Authtype 1
      var %x = 1, %total = $scon(0) 
      while (%x <= %total) {
        if ($scon(%x).network == %network) {
          writeini -n Startup.ini $replace(%network,$chr(32),-) nick $scon(%x).me
          writeini -n Startup.ini $replace(%network,$chr(32),-) address $scon(%x).server
          writeini -n Startup.ini $replace(%network,$chr(32),-) port $scon(%x).port
        }
        inc %x
      }
      var %x = $input(%network has been successfully added. $crlf $+ Edit the network information and options below. $crlf $+ Edit channel options for this server to the right,oi,Success)
    }
    ArrangeNetworks
  }
  elseif ($did == 4) {
    if ($did(2).sel) {
      if ($input(Would you also like to delete the settings saved for %network $+ ?,yq,Delete settings?)) {    
        remini Startup.ini $replace(%network,$chr(32),-)
      }
      did -d $dname 2 $did(2).sel
      did -b $dname 9,10,11,12,14,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32,33
      did -r $dname 8,18,20,22,24,31,33
      did -u $dname 25,26,27
      did -c $dname 29 0
    }
    ArrangeNetworks
  }
  elseif ($did isnum 5-6) {
    var %pos = $did(2).sel, %newpos = $calc($did(2).sel $iif($did == 5,-,+) 1)
    if (%newpos == 0) || (%newpos > $did(2).lines) return 
    else {
      did -d $dname 2 %pos
      did -i $dname 2 %newpos %network
      did -c $dname 2 %newpos
    }
    ArrangeNetworks
  }
  elseif ($did == 14) {
    set %Perform.network %network
    dialog $iif($dialog(Perform),-v,-m) Perform Perform
  }
  elseif ($did == 25) {
    writeini -n Startup.ini %network Connect $did(25).state
  }
  elseif ($did == 26) {
    writeini -n Startup.ini %network Auth $did(26).state
    if ($did(26).state == 1) {
      did -e $dname 28,29,32,33
      if ($did(29).sel > 1) did -e $dname 30,31
      else did -b $dname 30,31
    }
    elseif ($did(27).state == 0) did -b $dname 28,29,30,31,32,33
  }
  elseif ($did == 27) {
    writeini -n Startup.ini %network Ghost $did(27).state
    if ($did(27).state == 1) {
      did -e $dname 28,29,32,33
      if ($did(29).sel > 1) did -e $dname 30,31
      else did -b $dname 30,31
    }
    elseif ($did(26).state == 0) did -b $dname 28,29,30,31,32,33
  }
  elseif ($did == 29) {
    var %Authtype = $did(29).sel
    if (%Authtype == 1) { did -b $dname 30,31 | LoadOptions Channel %network %channel }
    else { did -e $dname 30,31 | did -b $dname 39,40,41,42 }
    if (%Authtype isnum 3-4) did -b $dname 27
    else did -e $dname 27
    writeini -n Startup.ini %network AuthType %Authtype
  }
  elseif ($did == 8) && ($did(8).sel) {
    did -e $dname 35,36,37,38,43,44,45,46,47
    LoadOptions Channel %network $did(8).seltext
  }
  elseif ($did == 9) {
    var %channel = $$?="Enter the name of the channel you wish to add"
    var %chans = $readini(Startup.ini,%network,channels)
    if ($istok(%chans,%channel,44)) var %x = $input(%channel has already been added,oh,Error)
    elseif ($istok(%chans,$+($chr(35),%channel),44)) var %x = $input($+($chr(35),%channel) has already been added,oh,Error)
    elseif ($numtok(%channel,32) > 1) var %x = $input(Channel names can not contain spaces,oh,Error)
    else {
      if ($left(%channel,1) != $chr(35)) var %channel = $+($chr(35),%channel)
      did -a $dname 8 %channel
      writeini -n Startup.ini $replace(%network,$chr(32),-) %channel NULL¦0¦NULL¦0¦NULL¦1¦0¦NULL¦0
      writeini -n Startup.ini $replace(%network,$chr(32),-) channels $addtok(%chans,%channel,44)
    }
  }
  elseif ($did == 10) {
    if ($did(8).sel) {
      if ($input(Would you also like to delete the settings saved for %channel $+ ?,yq,Delete settings?)) {    
        remini Startup.ini $replace(%network,$chr(32),-) %channel
      }
      if ($did(8).lines == 1) remini Startup.ini $replace(%network,$chr(32),-) channels
      else writeini -n Startup.ini $replace(%network,$chr(32),-) channels $remtok(%chans,%channel,1,44)
      ClearChanOptions
      did -d $dname 8 $did(8).sel
    }
  }
  elseif ($did isnum 11-12) {
    var %pos = $did(8).sel, %newpos = $calc($did(8).sel $iif($did == 11,-,+) 1)
    if (%newpos == 0) || (%newpos > $did(8).lines) return 
    else {
      did -d $dname 8 %pos
      did -i $dname 8 %newpos %channel
      did -c $dname 8 %newpos
    } 
    ArrangeChans %network
  } 
  elseif ($did == 39) {
    if ($did(39).state == 1) did -e $dname 40,41,42
    else did -b $dname 40,41,42
    SaveChanOptions %network %channel
  }
  elseif ($did == 37) {
    SaveChanOptions %network %channel
    if ($did(37).state == 1) did -e $dname 38
    else did -b $dname 38
  }
  elseif ($did == 43) {
    SaveChanOptions %network %channel
    if ($did(43).state == 1) did -e $dname 44
    else did -b $dname 44
  }
  elseif ($did == 42) || ($did == 45) {
    SaveChanOptions %network %channel
  }
}
on *:dialog:Perform:sclick:5: {
  LoadPerforms $did(5).seltext
}

; #############################################################################
; # Dialog Edit events                                                        #
; #############################################################################
on *:dialog:Startup:edit:*: {
  var %network = $did(2).seltext, %pos = $did(2).sel
  var %channel = $did(8).seltext
  if ($did($did)) {
    if ($did == 18) writeini -n Startup.ini %network Address $did(18)
    elseif ($did == 20) writeini -n Startup.ini %network Port $did(20)
    elseif ($did == 22) writeini -n Startup.ini %network Description $did(22)
    elseif ($did == 24) writeini -n Startup.ini %network Nick $did(24)
    elseif ($did == 31) writeini -n Startup.ini %network User $did(31)
    elseif ($did == 33) writeini -n Startup.ini %network Pass $ifencode($did(33),m)
  }
  else {
    if ($did == 18) remini Startup.ini %network Address
    elseif ($did == 20) remini Startup.ini %network Port 
    elseif ($did == 22) remini Startup.ini %network Description 
    elseif ($did == 24) remini Startup.ini %network Nick 
    elseif ($did == 31) remini Startup.ini %network User
    elseif ($did == 33) remini Startup.ini %network Pass 
  }
  if ($did == 36) || ($did == 38) || ($did == 41) || ($did == 44) || ($did == 47) {
    if ($chr(166) isin $did($did)) {
      did -ra $dname $did $remove($did($did),$chr(166))
      var %x = $input(Due to the character $+(',$chr(166),') being used as a data seperator it may not be used here,oh,Error)
    }
    SaveChanOptions %network %channel
  }
}
on *:dialog:Perform:edit:6: {
  var %network = $did(5).seltext
  var %x = 1, %total = $did(6).lines
  remini StartupPerform.ini %network
  while (%x <= %total) {
    if ($did(6,%x)) writeini -n StartupPerform.ini %network %x $did(6,%x)
    inc %x
  }
}


; #############################################################################
; # Aliases                                                                   #
; #############################################################################
alias -l SaveChanOptions {
  var %dname = Startup, %network = $1, %channel = $2
  var %desc = $iif($did(%dname,36),$ifmatch,NULL)
  var %sendmsgme = $did(%dname,37).state
  var %joinmsgme = $iif($did(%dname,38),$ifmatch,NULL)
  var %sendmsgother = $did(%dname,43).state
  var %joinmsgother = $iif($did(%dname,44),$ifmatch,NULL)
  var %join = $did(%dname,45).state
  var %ID = $did(%dname,39).state
  var %Pass = $iif($did(%dname,41),$ifencode($ifmatch,m),NULL)
  var %Setq = $did(%dname,42).state
  var %key = $iif($did(%dname,47),$ifencode($ifmatch,m),NULL)
  var %s = $chr(166)
  var %data = $+(%desc,%s,%sendmsgme,%s,%joinmsgme,%s,%sendmsgother,%s,%joinmsgother,%s,%join,%s,%ID,%s,%pass,%s,%Setq,%s,%key)
  writeini Startup.ini %network %channel %data
}
alias -l ClearChanOptions {
  var %dname = Startup
  did -b %dname 35,36,37,38,39,40,41,42,43,44,45,46,47
  did -r %dname 36,38,41,44,47
  did -u %dname 37,39,42,43,45
}
alias -l LoadOptions {
  var %dname = Startup
  if ($1 == network) {
    var %network = $2
    did -r %dname 8
    if ($readini(Startup.ini,%network,channels)) {
      var %chans = $v1
      var %x = 1, %total = $numtok(%chans,44)
      while (%x <= %total) {
        var %chan = $gettok(%chans,%x,44)
        did -a %dname 8 %chan
        inc %x
      }
    }

    did -ra %dname 18 $readini(Startup.ini,%network,Address)
    did -ra %dname 20 $readini(Startup.ini,%network,Port)
    did -ra %dname 22 $readini(Startup.ini,%network,Description)
    did -ra %dname 24 $readini(Startup.ini,%network,Nick)
    if ($readini(Startup.ini,%network,Connect) == 1) did -c %dname 25 | else did -u %dname 25
    if ($readini(Startup.ini,%network,Auth) == 1)    did -c %dname 26 | else did -u %dname 26
    if ($readini(Startup.ini,%network,Ghost) == 1)   did -c %dname 27 | else did -u %dname 27
    did -c %dname 29 $readini(Startup.ini,%network,AuthType)
    did -ra %dname 31 $readini(Startup.ini,%network,User)
    did -ra %dname 33 $ifdecode($readini(Startup.ini,%network,Pass),m)

    if ($readini(Startup.ini,%network,Auth) == 1) || ($readini(Startup.ini,%network,Ghost) == 1) {
      did -e $dname 28,29,30,31,32,33
      if ($readini(Startup.ini,%network,Authtype == 1)) did -b $dname 31
      else did -e $dname 31
    }
    else did -b $dname 28,29,30,31,32,33
  }
  else {
    var %network = $2, %channel = $3
    if (!%network) || (!%channel) return
    var %data = $readini(Startup.ini,n,%network,%channel)
    tokenize 166 %data
    if ($1 != NULL) did -ra %dname 36 $1
    if ($2 == 1) { did -c %dname 37 | did -e %dname 38 }
    else { did -u %dname 37 | did -b %dname 38 }
    if ($3 != NULL) did -ra %dname 38 $3
    if ($4 == 1) { did -c %dname 43 | did -e %dname 44  }
    else { did -u %dname 43 | did -b %dname 44 }
    if ($5 != NULL) did -ra %dname 44 $5
    if ($6 == 1) did -c %dname 45
    else did -u %dname 45
    if ($7 == 1) { did -c %dname 39 | did -e %dname 40,41,42 }
    else { did -u %dname 39 | did -b %dname 40,41,42 }    
    if ($8 != NULL) did -ra %dname 41 $ifdecode($8,m)
    if ($9 == 1) did -c %dname 42 | else did -u %dname 42
    if ($10 != NULL) did -ra %dname 47 $ifdecode($10,m)

    if ($did(29).sel != 1) did -b $dname 39,40,41,42
    else did -e $dname 39
  }
}

alias -l LoadPerforms {
  var %dname = Perform, %network = $1
  did -r %dname 6
  var %x = 1, %total = $ini(StartupPerform.ini,%network,0)
  while (%x <= %total) {
    did -i %dname 6 %x $readini(StartupPerform.ini,-n,%network,%x)
    inc %x
  }
}
alias -l ArrangeNetworks {
  var %dname = Startup, %x = 1, %total = $did(%dname,2).lines
  while (%x <= %total) { 
    var %networks = $addtok(%networks,$did(2,%x),44)
    inc %x
  }
  if (%networks) writeini -n Startup.ini Config Networks %networks
}
alias -l ArrangeChans {
  var  %dname = Startup, %network = $1, %x = 1, %total = $did(%dname,8).lines
  while (%x <= %total) { 
    var %chans = $addtok(%chans,$did(8,%x),44)
    inc %x
  }
  if (%chans) writeini -n Startup.ini %network channels %chans
}
; #############################################################################
; # Start event                                                               #
; #############################################################################
on *:start: {
  var %networks = $readini(Startup.ini,config,networks) 
  var %x = 1, %total = $numtok(%networks,44), %connects = 1
  while (%x <= %total) {
    var %network = $gettok(%networks,%x,44), %server = $readini(Startup.ini,%network,address)
    var %port = $iif($readini(Startup.ini,%network,port),$ifmatch,6667)
    if ($readini(Startup.ini,%network,connect) == 1) {
      if (%connects == 1) server %server %port
      else server -m %server %port
      inc %connects
    }
    inc %x
  }
}

; #############################################################################
; # Connect event                                                             #
; #############################################################################
on *:connect: {
  if ($ini(Startup.ini,$network)) {
    nick $readini(Startup.ini,$network,nick)

    if ($readini(Startup.ini,$network,auth) == 1) {
      var %authtype = $readini(Startup.ini,$network,AuthType)
      var %user = $readini(Startup.ini,$network,User)
      var %pass = $ifdecode($readini(Startup.ini,$network,pass),m)
      if (%authtype == 1) .msg nickserv identify %pass
      elseif (%authtype == 2) .msg AuthServ auth %user %pass
      elseif (%authtype == 3) .msg Q@CServe.quakenet.org auth %user %pass
      elseif (%authtype == 4) .msg x@channels.undernet.org login %user %pass
      elseif (%authtype == 5) .msg P@cservice.netgamers.org login %user %pass
    }
    var %x = 1
    while ($readini(StartupPerform.ini,$network,%x)) {
      $v1
      inc %x
    }

    var %chans = $readini(Startup.ini,$network,channels)
    var %x = 1, %total = $numtok(%chans,44)
    while (%x <= %total) {
      var %chan = $gettok(%chans,%x,44), %chandata = $readini(Startup.ini,n,$network,%chan)
      var %key = $iif($gettok(%chandata,10,166) != $null,$ifdecode($v1,m))
      if ($gettok(%chandata,6,166) == 1) join %chan %key
      inc %x
    }
  }
}
; #############################################################################
; # Join event                                                                #
; #############################################################################
on *:join:#: {
  if ($readini(Startup.ini,n,$network,$chan)) {
    tokenize 166 $v1
    if ($nick == $me) {
      if ($2 == 1) && ($3 != NULL) msg $chan $($3,2)
      if ($7 == 1) {
        if ($8 != NULL) .msg chanserv identify $chan $ifdecode($8,m)
        if ($9 == 1) .msg chanserv owner $chan
      }
    }
    else {
      if ($4 == 1) && ($5 != NULL) msg $chan $($5,2)
    }
  }
}

; #############################################################################
; # Auto ID on nickserv notice. Auth to authserv if @... is required          #
; #############################################################################
on *:notice:*:?: {
  if ($readini(Startup.ini,$network,auth) == 1) {
    if ($nick == nickserv) || ($nick == authserv) {
      var %user = $readini(Startup.ini,$network,user)
      var %pass = $ifdecode($readini(Startup.ini,$network,pass),m)
      if (*registered and protected* iswm $1-) .msg nickserv identify %pass
      elseif ($regex($1-,/Authserv@([^ ]*)/Si)) .msg $regml(1) auth %user %pass
    }
  }
}


; #############################################################################
; # Nick in use raw - Auto ghost/recover                                      #
; #############################################################################
raw 433:*: {
  if ($2 == $readini(Startup.ini,$network,nick)) && (!%GhostTimer) {
    var %nick = $2
    var %authtype = $readini(Startup.ini,$network,AuthType)
    var %user = $readini(Startup.ini,$network,User)
    var %pass = $ifdecode($readini(Startup.ini,$network,pass),m)

    if (%authtype == 1) {
      if ($($+(%,dc.,$network),2)) .msg nickserv ghost %nick %pass
      else {
        .msg nickserv recover %nick %pass
        .msg nickserv release %nick %pass
      }
    }
    elseif (%authtype == 2) .msg authserv ghost %nick %pass
    elseif (%authtype == 5) .msg P@cservice.netgamers.org recover %nick %user %pass 
    set -u5 %GhostTimer on 
    .timer 1 2 nick %nick
  }
}

; #############################################################################
; # Disconnect event. Set variable to decide between ns ghost and ns release  #
; #############################################################################
on *:disconnect: {
  set -u120 $+(%,dc.,$network)
}