XDCC Autoresume/Autoqueue Stealth Script — File Browser

XDCCAutoresumeAutoqueueStealthScriptv4.2.0 / XDCCAutoresumeAutoqueueStealthScriptv4.2.0 / xdccscript.mrc

xdccscript.mrc — 389.1 KB — Download this file

;
; Name: XDCC Autoresume/Autoqueue Stealth Script
; Version: 3.7
; Author: Werecow
; Date: 13-03-2004
;
; WARNING: many channels will ban you for using XDCC leech scripts. While this is a silly rule,
; it is your responsibility. Use this wisely. Don't use it in such channels, or don't get caught.
; And play nice for the other people that want to use the XDCCs! If you leech em dry other people 
; may be unable to get on.
;
; And hey, the code may be unreadable by now, but it works fairly well. Msg me if you find any bugs or have 
; suggestions. Oh, and thanx for the help to Matt and anyone else who helped me out }|;o).
;
; Possible future features (dare i dream): 
;    -Add support for multiple triggers {HMC}raynev666:
;       ...
;       [10:44:38] <{HMC}RAYNEv666> [#5] [_53.5kB] - the_egyptian_book_of_the_dead [11 Gets]
;       [10:44:40] <{HMC}RAYNEv666> Usage: /ctcp {HMC}RAYNEv666 XDCC GET BOOKS #<pack number>
;       [10:44:45] <{HMC}RAYNEv666> [XDCC Active] - Sends:[1/1] - Queues:[3/10] - Record CPS:[15.9kB/s by aad] - Files Sent:[44] - Current Bandwidth:[13.2kB/s] - List Trigger:[/ctcp {HMC}RAYNEv666 XDCC LIST MOVIES] - SysReset 2.53
;       [10:44:46] <{HMC}RAYNEv666> [#1] [700.7MB] - 28.Days.Later.DVDRip.XviD-DMT-VeN [10 Gets]
;       [10:44:47] <{HMC}RAYNEv666> [#2] [346.5MB] - Blood - The Last Vampire [5 Gets]
;       [10:44:49] <{HMC}RAYNEv666> [#3] [404.7MB] - Evil Dead II [11 Gets]
;       [10:44:50] <{HMC}RAYNEv666> [#4] [606.1MB] - Evil Dead III - Army Of Darkness [8 Gets]
;       [10:44:50] <{HMC}RAYNEv666> [#5] [682.8MB] - Hellraiser I [ ....
;       ...
;       [10:45:00] <{HMC}RAYNEv666> Usage: /ctcp {HMC}RAYNEv666 XDCC GET MOVIES #<pack number>
;       ^^That gives annoying trigger updates and pack change warnings, and it makes one unable to 
;         request any packs from the first list.
;    -[17:16:48] -MWXDCC01- Your request for ("1437_Stabwoundz-Embrace_Solitude-2004-BUTT") is now number 2 in my send queue. If you would like to remove your queues at a later time Type: /msg MWXDCC01 xdcc remove
;    -Make it so that if %scon == $null > go to next bot (or connect to network in new window).
;    -Make an option to do an automatic xdcc list for a bot if it advertises according to that principle. 
;     Make time interval about 5 mins +/- random of 2 or 3 mins (test on #punkmusic).
;    -/msg $nick xdcc remove <--- menu item for that. - DONE. Untested, but i doubt anything could go wrong here.
;    -raw 401:*No such nick/channel*:/outputxdccinfo 4Request failed: Bot7 $2 is currently not connected to3 $network $+ .
;     use that raw to keep better track of who's online and who isn't. 
;    -Check out possibilities of more raw commands.
;    -Make this less of a resource hog. - HOW? Reduce procedure calls, optimise inner loop. Optimise pack capture test. Reduce disk reads.
;    -Make nicknames (and, if possible, channels and networks) clickable.
;    -Make the script resume sends when a target person rejoins a channel.
;    -Enhance the colour coding for messages (readability). - never DONE, but ok for now.
;    -Enhance the help file. - never DONE, but improved.
;    -Add a file settings help file.
;    -Enhance the menu layout. - never DONE, but not too bad at the moment.
;    -Make an option for upper limit to number of retries per bot or recipient (%maxnumberresumes = Unlimited).
;     Find a way to stop the script from requesting a file more than %maxnumberresumes times (otherwise temp 
;     queue may become troublesome. Increasing delay offset to 2000 should help though).
;    -Enhance remove a pack from all queue files with pack comparisons instead of just filename (watch packchanges!).
;    -Make colour codes variable. Nicklist especially. Add to settings dialog color tab.
;    -Rename files where appropriate upon loading a profile.
;    -Start timed b/w or d/l slot testing upon opening a profile if appropriate.
;    -Add debugging statements. Use $scriptline when doing so.
;    -Save nicklist size settings. - Impossible?
;    -Add support for !XDCC list notices (and maybe the tv-central xdccfind, but that's just a bonus).
;    -Use menu styles to disable or check menu items where appropriate.
;    -Make an option to colorise indexed bot nicknames in a CHANNEL nicklistbox.
;    -Encode the chankey file with a simple algorithm for safety (will need to encode $network $chan before comparing).
;    -Add dialog wizard items for min/max bandwidth/transfers, system connection bw, bot queue mode, testing setting.
;    -Multi-source: If a bot goes offline, search other bots for the same pack and autoqueue (if option enabled).
;    -Make a browsable and clickable bot pack dialog. - DONE.
;    -Adapt the timed bandwidth checker to function as a statistics gatherer dialog that only starts bot queues if the 
;     test feature is enabled. Use statistics to draw a graphic b/w usage representation if possible.
;    -Make the searches word order independent.
;    -Make the script neater, for instance: 
;        -Write a single block of code for all aliases that use that block, where the code is now 
;         (more or less) copy/pasted.
;        -Unset all local vars at the end of a method.
;        -Reduce the /'s where possible; /window @XDCC_Info should just be window @XDCC_Info.
;        -Create temp variables for String Tokens whereever they're used more than once.
;        -If possible, use something like the identifier aliases below. $remove strings for the pack/trigger
;         capture codes. Handy for maintainability
;         alias replxdccfile { return $replace($strip($1-,burc),|,_,*,_,?,_,$chr(60),_,$chr(62),_,$chr(92),_,$chr(47),_) }
;         alias remvxdccpack { return $remove($strip($1-,burc),$chr(35),[,],$chr(41),$chr(40)) } - DONE, for as far 
;         as i can imagine. Just make one more for /cline tests.
;        -Add line specific comments where appropriate. 
;        -Add comments on which aliases a part of the script call on, and which it was called by.
;        -Replace the filename extensions by variables.
;        -Make a lil scripted index that holds the linenumbers for each key part of the script relative to
;         it's predecessor, but that's not something that's important right now (use $scriptline).
;
;
; ...but we'll see what the future brings. If anyone has any suggestions, feel free to /msg me.
;
;








;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
;-------------------------Hash Table Functions----------------------------
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------








;-------------------------------------------------------------------------
; /hashtable.init $1 $2:
; $1: Hash table name.
; $2: Hash table size.
; Loads a hash table if a file of name $1 exists, and creates a new table 
; if it doesn't exist.
;-------------------------------------------------------------------------
alias hashTable.init {
  if ($isFile($1)) { 
    hmake $1 $2
    /debuglog Trigger Hash File found: Made hash table $1 $2    
    hload $1 $1 
    /debuglog Loaded file $1
  }
  else {
    /debuglog No Trigger Hash File found: Made hash table $1 $2    
    hmake $1 $2
    /debuglog Saved file $1
    hsave -o $1 $1
  }
}
;-------------------------------------------------------------------------



;-------------------------------------------------------------------------
; Trigger Hash Table Aliases:
;-------------------------------------------------------------------------
; /triggerHash.init, /triggerHash.add $1 $2 $3 $4 $5 $6-, 
; /triggerHash.updatePackSchemeNr $1 $2 $3, /triggerHash.del $1 $2, 
; /triggerHash.delmatch $1-, /triggerHash.free, /triggerHash.remove, 
; /triggerHash.restore:
; $1 (.add): $network.
; $2 (.add): $nick.
; $3 (.add): $chan.
; $4 (.add): Trigger Scheme Nr..
; $5 (.add): Pack Scheme Nr..
; $6-(.add): Trigger.
; $1 (.updatePackSchemeNr): $network.
; $2 (.updatePackSchemeNr): $nick.
; $3 (.updatePackSchemeNr): Pack Scheme Nr..
; $1 (.del): $network.
; $2 (.del): $nick.
; $1-(.delmatch): Wildcard string to be matched in DATA fields.
; Initiate/Create/Load, add items to, update pack scheme number for, 
; delete item from, find and delete item with wildcard match for, 
; free memory used for, remove file and free memory for, and recover
; broken table from backup file for Trigger Hash table.
;-------------------------------------------------------------------------
alias triggerHash.init { 
  hashTable.init $triggerHash 200 
  if ($triggerHash.items < $lines($triggerbackup)) {
    /outputxdccinfo 4ERROR: Less items in trigger file than in backup file -> Possible XDCC Trigger Hash file corruption. Adding items from backup file to trigger file.
    /triggerHash.restore
  }
  else {
    /outputxdccinfo Trigger Hash table loaded. No restore necessary.
  }
}
;-------------------------------------------------------------------------
alias triggerHash.add {
  if (!$hget($triggerHash)) { triggerHash.init }
  hadd -m $triggerHash $1 $+ ¦ $+ $2 $2 $1 $3 $4 $5 $6-
  hsave -o $triggerHash $triggerHash
  if (!$read($triggerbackup, wnt, $1 $2 *)) {
    /write -a $triggerbackup $1 $2 $3 $4 $5 $6-
  }
  elseif (!$read($triggerbackup, wnt, $1 $2 $3 $4 $5 $6-)) {
    /write -dw" $+ $1 $2 *" $triggerbackup
    /write -a $triggerbackup $1 $2 $3 $4 $5 $6-
  }
}
;-------------------------------------------------------------------------
alias triggerHash.updatePackSchemeNr {
  /triggerHash.add $1 $2 $triggerHash.getChan($1, $2) $triggerHash.getTsnr($1, $2) $3 $triggerHash.getTrigger($1, $2)
}
;-------------------------------------------------------------------------
alias triggerHash.updateChannel {
  if ($triggerHash.exists($1,$2) && $3 !isin $triggerHash.getChans($1, $2)) {
    if ($triggerHash.getChans($1, $2) != |UNKNOWN|) {
      /triggerHash.add $1 $2 $replace($remove($triggerHash.getChans($1, $2),|UNKNOWN|,|UNKNOWN|) $+  $+ $3,,) $triggerHash.getTsnr($1, $2) $triggerHash.getPsnr($1, $2) $triggerHash.getTrigger($1, $2) 
    }
    else {
      /triggerHash.add $1 $2 $3 $triggerHash.getTsnr($1, $2) $triggerHash.getPsnr($1, $2) $triggerHash.getTrigger($1, $2) 
    }
    /outputxdccinfo Updated channel for "3 $+ $1 7 $+ $2 $+ 12 $triggerHash.getChans($1, $2) ||5 " $+ $triggerHash.getTrigger($1, $2) $+ " 14(Trigger Scheme $triggerHash.getTsnr($1, $2) $+ ).
    /outputxdccinfo 
  } 
}
;-------------------------------------------------------------------------
alias triggerHash.del {
  hdel $triggerHash $1 $+ ¦ $+ $2
  hsave -o $triggerHash $triggerHash
  /write -dw" $+ $1 $2 *" $triggerbackup
  dline -lc7 @XDCC_Info $fline(@XDCC_Info,$2,1,1)
}
;-------------------------------------------------------------------------
alias triggerHash.delMatch {
  set %botnick $triggerHash.findNick(* $+ $1- $+ *)
  hdel -w $triggerHash $1-
  hsave -o $triggerHash $triggerHash
  /write -dw"* $+ $1- $+ *" $triggerbackup
  /dline -lc7 @XDCC_Info $fline(@XDCC_Info,%botnick,1,1)
}
;-------------------------------------------------------------------------
alias triggerHash.free { 
  hsave -o $triggerHash $triggerHash
  /hfree $triggerHash 
}
;-------------------------------------------------------------------------
alias triggerHash.remove { 
  /hfree $triggerHash 
  .remove $triggerHash
  .remove $triggerbackup
  /dline -lc7 @XDCC_Info 1- $+ $line(@XDCC_Info,0,1)
}
;-------------------------------------------------------------------------
alias triggerHash.restore {
  /outputxdccinfo Adding all items in backup file to Trigger Hash file, please wait (this can take a while)5...
  set %i 1   
  while (%i <= $lines($triggerbackup) && %i < 1000000) {
    /triggerHash.add $read($triggerbackup, nt, %i)
    inc %i
  }
  if ($triggerHash.items >= $lines($triggerbackup)) {
    /outputxdccinfo 4 $+ %i $+ : Restored Trigger Hash file from triggerbackup file (There should be at least $lines($triggerbackup) bots in the library right now).
  }
  else { /outputxdccinfo 4 $+ %i $+ : 4May Have Failed to Restore Trigger Hash file from triggerbackup file (less items in hash table than lines in backup file). }
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------



;-------------------------------------------------------------------------
; Trigger Hash Table Identifiers:
;-------------------------------------------------------------------------
; $triggerHash, $triggerHash.exists($1, $2), 
; $triggerHash.findAll[...]($1, $2-), $triggerHash.find[...]($1-), 
; $triggerHash.get[...]($1, $2), $triggerHash.network($1), 
; $triggerHash.item($1), $triggerHash.item.[...]($1), $triggerHash.items:
; $1 (.exists): $network.
; $2 (.exists): $nick.
; $1 (.findAll*): Item Number.
; $2-(.findAll*): Wildcard string to be matched in DATA fields.
; $1-(.find*): Wildcard string to be matched in DATA fields.
; $1 (.get*): $network.
; $2 (.get*): $nick.
; $1 (.network): $nick.
; $1 (.item): Trigger Hash Table Entry Number.
; $1 (.item.*): Trigger Hash Table Entry Number.
; Return filename, check for existance, find nr $1 that matches $2, find 
; first match for $2, retrieve data field from key, retrieve network for 
; nick, retrieve data for entry nr $1, retrieve specific item for entry 
; $1, retrieve total number of entries in Trigger Hash Table.
;-------------------------------------------------------------------------
alias triggerHash { return $preventdoubleslash($xdccdir $+ \ $+ $replxdccfile(%xdcctriggerfile)) }
;-------------------------------------------------------------------------
alias triggerHash.exists { 
  if ($hget($triggerHash, $1 $+ ¦ $+ $2) != $null) { return TRUE }
  else { return $null }
}
;-------------------------------------------------------------------------
alias triggerHash.findAllNetwork { return $gettok($hget($triggerHash, $hfind($triggerHash, $2-, $1, w).data), 2, 32) }
alias triggerHash.findAllNick { return $gettok($hget($triggerHash, $hfind($triggerHash, $2-, $1, w).data), 1, 32) }
alias triggerHash.findAllChans { return $replace($gettok($hget($triggerHash, $hfind($triggerHash, $2-, $1, w).data), 3, 32),,$chr(32)) }
alias triggerHash.findAllChan { return $gettok($triggerHash.findAllChans($1, $2-), 1, 32) }
alias triggerHash.findAllTsnr { return $gettok($hget($triggerHash, $hfind($triggerHash, $2-, $1, w).data), 4, 32) }
alias triggerHash.findAllTsnr { return $gettok($hget($triggerHash, $hfind($triggerHash, $2-, $1, w).data), 5, 32) }
alias triggerHash.findAllTrigger { return $gettok($hget($triggerHash, $hfind($triggerHash, $2-, $1, w).data), 6-, 32) }
;-------------------------------------------------------------------------
alias triggerHash.findNetwork { return $gettok($hget($triggerHash, $hfind($triggerHash, $1-, 1, w).data), 2, 32) }
alias triggerHash.findNick { return $gettok($hget($triggerHash, $hfind($triggerHash, $1-, 1, w).data), 1, 32) }
alias triggerHash.findChans { return $replace($gettok($hget($triggerHash, $hfind($triggerHash, $1-, 1, w).data), 3, 32),,$chr(32)) }
alias triggerHash.findChan { return $gettok($triggerHash.findChans($1-), 1, 32) }
alias triggerHash.findTsnr { return $gettok($hget($triggerHash, $hfind($triggerHash, $1-, 1, w).data), 4, 32) }
alias triggerHash.findPsnr { return $gettok($hget($triggerHash, $hfind($triggerHash, $1-, 1, w).data), 5, 32) }
alias triggerHash.findTrigger { return $gettok($hget($triggerHash, $hfind($triggerHash, $1-, 1, w).data), 6-, 32) }
;-------------------------------------------------------------------------
alias triggerHash.getNetwork { return $gettok($hget($triggerHash, $1 $+ ¦ $+ $2), 2, 32) }
alias triggerHash.getNick { return $gettok($hget($triggerHash, $1 $+ ¦ $+ $2), 1, 32) }
alias triggerHash.getChans { return $replace($gettok($hget($triggerHash, $1 $+ ¦ $+ $2), 3, 32),,$chr(32)) }
alias triggerHash.getChan { return $gettok($triggerHash.getChans($1, $2), 1, 32) }
alias triggerHash.getTsnr { return $gettok($hget($triggerHash, $1 $+ ¦ $+ $2), 4, 32) }
alias triggerHash.getPsnr { return $gettok($hget($triggerHash, $1 $+ ¦ $+ $2), 5, 32) }
alias triggerHash.getTrigger { return $gettok($hget($triggerHash, $1 $+ ¦ $+ $2), 6-, 32) }
;-------------------------------------------------------------------------
alias triggerHash.network { 
  if (!$1) { return $null }
  elseif ($triggerHash.exists($network, $1) != $null) { return $network }
  else { return $triggerHash.findNetwork($1 *) }
}
;-------------------------------------------------------------------------
alias triggerHash.item { return $hget($triggerHash,$1).item }
;-------------------------------------------------------------------------
alias triggerHash.item.network { return $gettok($triggerHash.item($1), 1, 166) }
alias triggerHash.item.nick { return $gettok($triggerHash.item($1), 2, 166) }
alias triggerHash.item.chans { return $triggerHash.getChans($triggerHash.item.network($1), $triggerHash.item.nick($1)) }
alias triggerHash.item.chan { return $gettok($triggerHash.item.chans($1),1,32) }
alias triggerHash.item.tsnr { return $triggerHash.getTsnr($triggerHash.item.network($1), $triggerHash.item.nick($1)) }
alias triggerHash.item.tsnr { return $triggerHash.getPsnr($triggerHash.item.network($1), $triggerHash.item.nick($1)) }
alias triggerHash.item.trigger { return $triggerHash.getTrigger($triggerHash.item.network($1), $triggerHash.item.nick($1)) }
;-------------------------------------------------------------------------
alias triggerHash.items { return $hget($triggerHash,0).item }
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------








;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
;--------------------------Identifiers Section----------------------------
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------








;-------------------------------------------------------------------------
; $replxdccfile($1-), $replxdccdir($1-), $replxdccpack($1-), 
; $remvextent($1-), $remvall($1-), $remvallnonum($1-) & $remvqnotice($1-):
; $1-: String or filename.
; Do replacent/removal/codestripping on $1-. 
;-------------------------------------------------------------------------
alias preventdoubleslash { return $replace($1-,$chr(92) $+ $chr(92),$chr(92),$chr(47) $+ $chr(47),$chr(47)) }
alias replxdccdir { return $replace($strip($1-,burc),|,_,*,_,?,_,",_,$chr(60),_,$chr(62),_) }
alias replxdccfile { return $replace($replxdccdir($1-),$chr(92),_,$chr(47),_) }
alias replxdccpack { return $replace($strip($1-,burc)," **, ,**,,$chr(35) $+ x,$chr(35),$chr(35) $+ $chr(60) $+ pack number $+ $chr(62),$chr(35),$chr(35) $+ <number>,$chr(35),$chr(58),,$chr(46),,•«UPP»•,,type,,",, ‹‹UPP››,) }
alias replaceallwishlist { return $replace($strip($1-,burc),$chr(32),*,_,*,$chr(32) $+ and,*,&,*) }
alias remvextentnodot { return $remove($strip($1-,burc),avi,asf,txt,mp3,mpg,mpeg,rar,tar,zip,mov,nfo,sfv,doc,mrc,exe,ini) }
alias remvextent { return $remove($strip($1-,burc),.avi,.asf,.txt,.mp3,.mpg,.mpeg,.rar,.tar,.zip,.mov,.nfo,.sfv,.doc,.mrc,.exe,.ini) }
alias remvallnonum { return $remove($remvextent($1-),$chr(32),???K,[,],<,>,$chr(35),$chr(40),$chr(41),_,$chr(47),$chr(92)) }
alias remvall { return $remove($remvallnonum($1-),1,2,3,4,5,6,7,8,9,0,n/a,MB,KB,GB,BYTE) }
alias remvqnotice { return $remove($remvextent($1-),",$chr(44)) }
alias replallnum { $replace($1,1,¦,2,¦,3,¦,4,¦,5,¦,6,¦,7,¦,8,¦,9,¦,0,¦) }
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------




;-------------------------------------------------------------------------
; $xdccdir & $preventdoubleslash & $[filename]:
; $1 (in $networkfile($1)): Network.
; $1 (in $statsfile($1)): Stats file number.
; Returns the xdccdir or -file with illegal characters replaced and double
; directory slashes removed.
;-------------------------------------------------------------------------
alias xdccdir { return $replxdccdir(%XDCCdir) }
alias triggerbackup { return $preventdoubleslash($xdccdir $+ \ $+ $replxdccfile(%triggerbackup)) }
alias autoresumedisablefile { return $preventdoubleslash($xdccdir $+ \ $+ $replxdccfile(%autoresumedisablefile)) }
alias autoresumesenddisablefile { return $preventdoubleslash($xdccdir $+ \ $+ $replxdccfile(%autoresumesenddisablefile)) }
alias xdccsinprogress { return $preventdoubleslash($xdccdir $+ \ $+ $replxdccfile(%xdccsinprogress)) }
alias xdcchandelingq { return $preventdoubleslash($xdccdir $+ \ $+ $replxdccfile(%xdcchandelingq)) }
alias botqueuefile { return $preventdoubleslash($xdccdir $+ \ $+ $replxdccfile(%botqueuefile)) }
alias tempbotqueuefile { return $preventdoubleslash($xdccdir $+ \ $+ $replxdccfile(%tempbotqueuefile)) }
alias networksendfile { return $preventdoubleslash($xdccdir $+ \ $+ $replxdccfile(%networksendfile)) }
alias xdccsessiongetfile { return $preventdoubleslash($xdccdir $+ \ $+ $replxdccfile(%xdccsessiongetfile)) }
alias xdccsessionsendfile { return $preventdoubleslash($xdccdir $+ \ $+ $replxdccfile(%xdccsessionsendfile)) }
alias xdccqueueposfile { return $preventdoubleslash($xdccdir $+ \ $+ $replxdccfile(%xdccqueueposfile)) }
alias networkfile { return $preventdoubleslash($xdccdir $+ \ $+ $replxdccfile($1) $+ .apq) }
alias chankeyfile { return $preventdoubleslash($xdccdir $+ \ $+ $replxdccfile(%chankeyfile)) }
alias dccallownetworkfile { return $preventdoubleslash($xdccdir $+ \ $+ $replxdccfile(%dccallownetworkfile)) }
alias xdccdebugfile { return $preventdoubleslash($xdccdir $+ \ $+ $replxdccfile(%xdccdebugfile)) }
alias xdccwishlist { return $preventdoubleslash($xdccdir $+ \ $+ $replxdccfile(%xdccwishlist)) }
alias alternatedccserverfile { return $preventdoubleslash($xdccdir $+ \ $+ $replxdccfile(%alternatedccserverfile)) }
alias statsfile { return $xdccdir $+ \ $+ $replxdccfile(%statsfile) $+ . $+ $1 $+ .stats }
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------

;-------------------------------------------------------------------------
; $getpfffilenm($1, $2), $getqfilenm($1, $2) & $getoldfilenm($1, $2):
; $1: Botnetwork.
; $2: Botnick.
; Return the .pff/.q/.old filename in the XDCCdir based on $network and 
; $nick input strings. Illegal characters are replaced.
;-------------------------------------------------------------------------
alias getpfffilenm { return $preventdoubleslash($xdccdir $+ \ $+ $replxdccfile($1 $+ ¦ $+ $2 $+ .pff)) }
alias getqfilenm { return $replace($getpfffilenm($1, $2),.pff,.q) }
alias getoldfilenm { return $getpfffilenm($1, $2) $+ .old }
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------



;-------------------------------------------------------------------------
; $botliston:
; Returns TRUE if the @XDCC_Info nick list currently exists.
;-------------------------------------------------------------------------
alias botliston {
  if (%showbotlist == on && (%infochoise == special window || %infochoise == both active and special windows) && $window(@XDCC_Info) != $null) { return TRUE }
  else { return $null }
}
;-------------------------------------------------------------------------

;-------------------------------------------------------------------------
; $botqueue.exists:
; Returns TRUE if a bot queue or temporary bot queue exists.
;-------------------------------------------------------------------------
alias botqueue.exists {
  if (($exists($botqueuefile) && $lines($botqueuefile) > 0) || ($exists($tempbotqueuefile) && $lines($tempbotqueuefile) > 0)) { 
    return TRUE 
  }
  else { return $null }
}
;-------------------------------------------------------------------------
; $shouldstartmaxbotq:
; Returns TRUE if a new bot queue can be started on grounds of the maximum
; number of transfers (used by getfails, filercvds, etc.).
;-------------------------------------------------------------------------
alias shouldstartmaxbotq { 
  if (%botqueuemode == number of transfers  && (%maxtransfers == unlimited || %maxtransfers == 0 || $calc($activesends + $activeautoresumesends) < %maxtransfers)) { return TRUE }
  elseif (%botqueuemode == bandwidth) {
    set %averagebw 0
    ;set %z 1
    ;while (%z <= $get(0)) {
    ;  if ($get(%z).status == active) { write -a $statsfile(1) $get(%z) $get(%z).rcvd }
    ;  inc %z      
    ;}
    set %totalbytes 0
    set %oldtotalbytes 0
    if ($exists($statsfile(2))) {
      set %z 1
      while (%z <= $lines($statsfile(2))) {
        if ($get($gettok($read($statsfile(2),%z),1,32)).status == active) { set %oldtotalbytes $calc(%oldtotalbytes + $gettok($read($statsfile(2),%z),2,32)) }
        inc %z
      }
    }
    set %newtotalbytes 0
    if ($exists($statsfile(1))) {
      set %z 1
      while (%z <= $get(0)) {
        set %newtotalbytes $calc(%newtotalbytes + $get(%z).rcvd)
        inc %z
      }
    }
    set %averagebw $calc($calc(%totalbytes / $calc(%statisticstime - $1)) / 1024)

    set %totalbytes $calc(%newtotalbytes - %oldtotalbytes)
    set %totaltimers 0
    set %timeroverhead 0
    set %z 1
    while (%z <= $timer(0)) {
      if ($isXDCCTimer(%z) == TRUE) { 
        inc %totaltimers 
        set %timeroverhead $calc(%timeroverhead + $calc($calc(10 * $sqrt(%connectionbandwidth)) / $sqrt($timer(%z).secs)))
      }
      inc %z
    }

    ;/debuglog ALIAS SHOULDSTARTMAXBOTQUEUE: %averagebw %timeroverhead
    ;/timexdcctransferstest
    if ($calc(%averagebw + %timeroverhead) <= %maxbandwidth) { return TRUE }
    else { return $null }
  }  
}
;-------------------------------------------------------------------------
; $shouldstartminbotq:
; Returns TRUE if a new bot queue can be started on grounds of the minimum
; number of transfers (used by timed test).
;-------------------------------------------------------------------------
alias shouldstartminbotq { 
  if (%botqueuemode == number of transfers  && (%mintransfers != unlimited && %mintransfers != 0 && $calc($activesends + $activeautoresumesends) < %mintransfers)) { return TRUE }
  elseif (%botqueuemode == bandwidth) {
    set %averagebw 0
    ;set %z 1
    ;while (%z <= $get(0)) {
    ;  if ($get(%z).status == active) { write -a $statsfile(1) $get(%z) $get(%z).rcvd }
    ;  inc %z      
    ;}
    set %totalbytes 0
    set %oldtotalbytes 0
    if ($exists($statsfile(2))) {
      set %z 1
      while (%z <= $lines($statsfile(2))) {
        if ($get($gettok($read($statsfile(2),%z),1,32)).status == active) { set %oldtotalbytes $calc(%oldtotalbytes + $gettok($read($statsfile(2),%z),2,32)) }
        inc %z
      }
    }
    set %newtotalbytes 0
    if ($exists($statsfile(1))) {
      set %z 1
      while (%z <= $get(0)) {
        set %newtotalbytes $calc(%newtotalbytes + $get(%z).rcvd)
        inc %z
      }
    }
    set %averagebw $calc($calc(%totalbytes / $calc(%statisticstime - $1)) / 1024)

    set %totalbytes $calc(%newtotalbytes - %oldtotalbytes)
    set %totaltimers 0
    set %timeroverhead 0
    set %z 1
    while (%z <= $timer(0)) {
      if ($isXDCCTimer(%z) == TRUE) { 
        inc %totaltimers 
        set %timeroverhead $calc(%timeroverhead + $calc($calc(10 * $sqrt(%connectionbandwidth)) / $sqrt($timer(%z).secs)))
      }
      inc %z
    }
    ;/debuglog ALIAS SHOULDSTARTMAXBOTQUEUE: %averagebw %timeroverhead
    ;.timexdcctransferstest
    if ($calc(%averagebw + %timeroverhead) <= %minbandwidth) { return TRUE }
    else { return $null }
  }
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------



;-------------------------------------------------------------------------
; $activesends:
; Returns the number of active incoming transfers.
;-------------------------------------------------------------------------
alias activesends {
  set %activesends 0
  set %m 1
  while (%m <= $get(0)) {
    if ($get(%m).status == active) { inc %activesends }
    inc %m
  }  
  return %activesends
}
;-------------------------------------------------------------------------
; $activeautoresumesends:
; Returns the number of active pack request timers.
;-------------------------------------------------------------------------
alias activeautoresumesends {
  set %activeautoresumesends 0
  set %n 1
  while (%n <= $timer(0)) {
    if ($isXDCCTimer(%n)) { inc %activeautoresumesends }
    inc %n
  }
  return %activeautoresumesends
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------


;-------------------------------------------------------------------------
; $isXDCCTimer($1):
; $1: Timer number.
; Returns TRUE if timer is a timer to start a bot, $null if otherwise.
;-------------------------------------------------------------------------
alias isXDCCTimer { 
  if (xdccautoresume isin $timer($1) || xdccstartq isin $timer($1) || xdccstartbotq isin $timer($1) || xdccjoin isin $timer($1) || xdccnonewconnect isin $timer($1)) { return TRUE }
  else { return $null }
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------






;-------------------------------------------------------------------------
; $averagexdcccps($1), $estimatedxdcccompltime($1):
; $1: $nick of active transfer.
; Returns average CPS of the current transfer or estimated time untill the 
; transfer is completed respectively.
;-------------------------------------------------------------------------
alias averagexdcccps { return $int($calc($calc($get($1).rcvd - $get($1).resume) / $get($1).secs)) }
;-------------------------------------------------------------------------
alias estimatedxdcccompltime {
  set %totsecs $ceil($calc($calc($get($1).size - $get($1).rcvd) / $averagexdcccps($1)))
  set %totmins $floor($calc(%totsecs / 60))
  set %tothours $floor($calc(%totmins / 60))
  set %totdays $floor($calc(%tothours / 24))

  set %daysleft $floor(%totdays)
  set %hoursleft $floor($calc(%tothours - $calc(%totdays * 24)))
  set %minsleft $floor($calc(%totmins - $calc(%tothours * 60)))
  set %secsleft $ceil($calc(%totsecs - $calc(%totmins * 60)))

  if (%daysleft > 0) {
    set %estimatedxdcccompltime 4 $+ %daysleft $+ 5d4 $+ %hoursleft $+ 5h4 $+ %minsleft $+ 5m4 $+ %secsleft $+ 5s
  }
  elseif (%hoursleft > 0) {
    set %estimatedxdcccompltime 4 $+ %hoursleft $+ 5h4 $+ %minsleft $+ 5m4 $+ %secsleft $+ 5s
  }
  elseif (%minsleft > 0) {
    set %estimatedxdcccompltime 4 $+ %minsleft $+ 5m4 $+ %secsleft $+ 5s
  }
  else {
    set %estimatedxdcccompltime 4 $+ %secsleft $+ 5s
  }
  return %estimatedxdcccompltime
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------









;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
;----------------------------Dialog Section------------------------------
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------









;-------------------------------------------------------------------------
; /xdccpreferencesdialog:
; Initiates the preferences menu dialog and sets the appropriate values.
;-------------------------------------------------------------------------
alias xdccpreferencesdialog {
  set %newxdccdir $null
  dialog -m xdccpreferencesdialog xdccpreferencesdialog
  /did -a xdccpreferencesdialog 132 bandwidth is available
  /did -a xdccpreferencesdialog 132 download slots are open
  /did -a xdccpreferencesdialog 220 available bandwidth
  /did -a xdccpreferencesdialog 220 open download slots
  /did -a xdccpreferencesdialog 130 %sendlimit 
  /did -a xdccpreferencesdialog 206 %sendlimit 
  /did -a xdccpreferencesdialog 201 %minbandwidth
  /did -a xdccpreferencesdialog 202 %maxbandwidth
  /did -a xdccpreferencesdialog 203 %mintransfers
  /did -a xdccpreferencesdialog 204 %maxtransfers
  /did -a xdccpreferencesdialog 205 %connectionbandwidth


  /did -a xdccpreferencesdialog 501 $nopath($triggerHash)
  /did -a xdccpreferencesdialog 502 $nopath($triggerbackup)
  /did -a xdccpreferencesdialog 503 $nopath($xdccsinprogress)
  /did -a xdccpreferencesdialog 504 $nopath($autoresumedisablefile)
  /did -a xdccpreferencesdialog 505 $nopath($autoresumesenddisablefile)
  /did -a xdccpreferencesdialog 506 $nopath($tempbotqueuefile)
  /did -a xdccpreferencesdialog 507 $nopath($xdccsessiongetfile)
  /did -a xdccpreferencesdialog 508 $nopath($xdccsessionsendfile)
  /did -a xdccpreferencesdialog 509 $nopath($networksendfile)
  /did -a xdccpreferencesdialog 510 $nopath($xdccqueueposfile)
  /did -a xdccpreferencesdialog 511 $nopath($chankeyfile)
  /did -a xdccpreferencesdialog 512 $nopath($dccallownetworkfile)
  /did -a xdccpreferencesdialog 513 $nopath($xdccdebugfile)
  /did -a xdccpreferencesdialog 514 %statsfile
  /did -a xdccpreferencesdialog 515 $nopath($xdccwishlist)
  /did -a xdccpreferencesdialog 516 $nopath($alternatedccserverfile )
  /did -a xdccpreferencesdialog 517 $nopath($botqueuefile)

  /did -a xdccpreferencesdialog 551 Current XDCC dir: $xdccdir

  if ($exists($chankeyfile) && $lines($chankeyfile) > 0) {
    set %i 1
    while (%i <= $lines($chankeyfile)) {
      /did -a xdccpreferencesdialog 610 $gettok($read($chankeyfile,%i),1-2,32)
      inc %i
    }
  }
  if ($exists($dccallownetworkfile) && $lines($dccallownetworkfile) > 0) {
    set %i 1
    while (%i <= $lines($dccallownetworkfile)) {
      /did -a xdccpreferencesdialog 611 $read($dccallownetworkfile,%i)
      inc %i
    }
  }
  if ($exists($alternatedccserverfile) && $lines($alternatedccserverfile) > 0) {
    set %i 1
    while (%i <= $lines($alternatedccserverfile)) {
      /did -a xdccpreferencesdialog 612 $read($alternatedccserverfile,%i)
      inc %i
    }
  }
  if ($exists($xdccwishlist) && $lines($xdccwishlist) > 0) {
    set %i 1
    while (%i <= $lines($xdccwishlist)) {
      /did -a xdccpreferencesdialog 613 $read($xdccwishlist,%i)
      inc %i
    }
  }

  if (%showbotlist == ON) { /did -c xdccpreferencesdialog 307 }
  if (%infochoise == special window) { /did -c xdccpreferencesdialog 303 }
  elseif (%infochoise == server status window) { /did -c xdccpreferencesdialog 304 }
  elseif (%infochoise == active window) { /did -c xdccpreferencesdialog 305 }
  elseif (%infochoise == both active and special windows) { /did -c xdccpreferencesdialog 306 }
  /did -a xdccpreferencesdialog 301 %xdccfont
  /did -a xdccpreferencesdialog 310 Current Font Used (use prefix -b for bold) $+ $chr(58) %xdccfont

  /did -a xdccpreferencesdialog 401 %minresumedelay 
  /did -a xdccpreferencesdialog 402 %maxresumedelay 
  /did -a xdccpreferencesdialog 403 %resumedelay
  /did -a xdccpreferencesdialog 405 %sendresumetime
  /did -a xdccpreferencesdialog 407 %sendresumedelay
  /did -a xdccpreferencesdialog 409 %minautoqdelay 
  /did -a xdccpreferencesdialog 410 %maxautoqdelay 
  /did -a xdccpreferencesdialog 411 %minqfulldelay
  /did -a xdccpreferencesdialog 412 %maxqfulldelay
  /did -a xdccpreferencesdialog 413 %minnoconnect
  /did -a xdccpreferencesdialog 414 %maxnoconnect
  /did -a xdccpreferencesdialog 415 %startresumeoffset
  /did -a xdccpreferencesdialog 417 %statisticstime
  /did -a xdccpreferencesdialog 419 %packchangechecktime
  /did -a xdccpreferencesdialog 421 %liblimitdate

  if (%botqueuemode == bandwidth) { 
    /did -c xdccpreferencesdialog 132 1 
    /did -c xdccpreferencesdialog 220 1 
    /did -m xdccpreferencesdialog 203 
    /did -m xdccpreferencesdialog 204 
  }
  else { 
    /did -c xdccpreferencesdialog 132 2 
    /did -c xdccpreferencesdialog 220 2
    /did -m xdccpreferencesdialog 201 
    /did -m xdccpreferencesdialog 202 
  }
  if (%sendlimit == Unlimited) { 
    /did -m xdccpreferencesdialog 130
    /did -m xdccpreferencesdialog 206
  }
  else { 
    /did -c xdccpreferencesdialog 131
    /did -c xdccpreferencesdialog 235
  }
  if ($group(#groupautoxdccresume) == on) { /did -c xdccpreferencesdialog 102 }
  if ($group(#groupautosendresume) == on) { 
    /did -c xdccpreferencesdialog 103 
    /did -c xdccpreferencesdialog 211
  }
  else { 
    /did -m xdccpreferencesdialog 206
    /did -m xdccpreferencesdialog 130 
    /did -b xdccpreferencesdialog 131 
    /did -b xdccpreferencesdialog 235
  }
  if ($group(#groupautoxdccresumejoin) == on) { /did -c xdccpreferencesdialog 104 }
  if ($group(#groupautoxdccq) == on) { /did -c xdccpreferencesdialog 105 }
  if (%botqueuehandling == on) { /did -c xdccpreferencesdialog 106 }
  if (%testnumoftransferspeed == on) { 
    /did -c xdccpreferencesdialog 210
    /did -c xdccpreferencesdialog 107 
  }
  else { 
    /did -b xdccpreferencesdialog 132 
    /did -b xdccpreferencesdialog 220
    /did -m xdccpreferencesdialog 201 
    /did -m xdccpreferencesdialog 202 
    /did -m xdccpreferencesdialog 203
    /did -m xdccpreferencesdialog 204
  }
  if ($group(#groupautoresumestart) == on) { /did -c xdccpreferencesdialog 108 }
  if ($group(#groupnonewconnects) == on) { /did -c xdccpreferencesdialog 109 }
  if ($group(#groupautoxdccresume) == on) { /did -c xdccpreferencesdialog 110 }
  if ($group(#groupautoremove) == on) { /did -c xdccpreferencesdialog 111 }
  if ($group(#groupautoxdccresume) == on) { /did -c xdccpreferencesdialog 112 }
  if ($group(#grouppackchangedetect) == on) { /did -c xdccpreferencesdialog 113 }
  if ($group(#grouptrackqueuepos) == on) { /did -c xdccpreferencesdialog 114 }
  if (%autocleanatstart == on) { /did -c xdccpreferencesdialog 115 }
  if (%debugxdccinfo == on) { /did -c xdccpreferencesdialog 116 }
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------


;-------------------------------------------------------------------------
; /applyallsettings:
; Sets all variables, filenames and groups to the values you entered in 
; the menu. If the botlist setting has changed, the @XDCC_Info window is
; closed and reopened to initiate the botlist. If the XDCCdir has changed, 
; the contents of the old dir are moved to the new one.
;-------------------------------------------------------------------------
alias applyallxdccsettings {
  if ($exists($xdcctriggerfile) && $xdcctriggerfile != $xdccdir $+ \ + $replxdccfile($did(xdccpreferencesdialog, 501).text)) { .rename $xdcctriggerfile $preventdoubleslash($xdccdir $+ \ $+ $replxdccfile($did(xdccpreferencesdialog, 501).text)) }
  set %xdcctriggerfile $did(xdccpreferencesdialog, 501).text
  if ($exists($triggerbackup) && $triggerbackup != $xdccdir $+ \ + $replxdccfile($did(xdccpreferencesdialog, 502).text)) { .rename $triggerbackup $preventdoubleslash($xdccdir $+ \ $+ $replxdccfile($did(xdccpreferencesdialog, 502).text)) }
  set %triggerbackup $did(xdccpreferencesdialog, 502).text
  if ($exists($xdccsinprogress) && $xdccsinprogress != $xdccdir $+ \ + $replxdccfile($did(xdccpreferencesdialog, 503).text)) { .rename $xdccsinprogress $preventdoubleslash($xdccdir $+ \ $+ $replxdccfile($did(xdccpreferencesdialog, 503).text)) }
  set %xdccsinprogress $did(xdccpreferencesdialog, 503).text
  if ($exists($autoresumedisablefile) && $autoresumedisablefile != $xdccdir $+ \ + $replxdccfile($did(xdccpreferencesdialog, 504).text)) { .rename $autoresumedisablefile $preventdoubleslash($xdccdir $+ \ $+ $replxdccfile($did(xdccpreferencesdialog, 504).text)) }
  set %autoresumedisablefile $did(xdccpreferencesdialog, 504).text
  if ($exists($autoresumesenddisablefile) && $autoresumesenddisablefile != $xdccdir $+ \ + $replxdccfile($did(xdccpreferencesdialog, 505).text)) { .rename $autoresumesenddisablefile $preventdoubleslash($xdccdir $+ \ $+ $replxdccfile($did(xdccpreferencesdialog, 505).text)) }
  set %autoresumesenddisablefile $did(xdccpreferencesdialog, 505).text
  if ($exists($botqueuefile) && $botqueuefile != $xdccdir $+ \ + $replxdccfile($did(xdccpreferencesdialog, 517).text)) { .rename $botqueuefile $preventdoubleslash($xdccdir $+ \ $+ $replxdccfile($did(xdccpreferencesdialog, 517).text)) }
  set %botqueuefile $did(xdccpreferencesdialog, 517).text
  if ($exists($tempbotqueuefile) && $tempbotqueuefile != $xdccdir $+ \ + $replxdccfile($did(xdccpreferencesdialog, 506).text)) { .rename $tempbotqueuefile $preventdoubleslash($xdccdir $+ \ $+ $replxdccfile($did(xdccpreferencesdialog, 506).text)) }
  set %tempbotqueuefile $did(xdccpreferencesdialog, 506).text
  if ($exists($xdccsessiongetfile) && $xdccsessiongetfile != $xdccdir $+ \ + $replxdccfile($did(xdccpreferencesdialog, 507).text)) { .rename $xdccsessiongetfile $preventdoubleslash($xdccdir $+ \ $+ $replxdccfile($did(xdccpreferencesdialog, 507).text)) }
  set %xdccsessiongetfile $did(xdccpreferencesdialog, 507).text
  if ($exists($xdccsessionsendfile) && $xdccsessionsendfile != $xdccdir $+ \ + $replxdccfile($did(xdccpreferencesdialog, 508).text)) { .rename $xdccsessionsendfile $preventdoubleslash($xdccdir $+ \ $+ $replxdccfile($did(xdccpreferencesdialog, 508).text)) }
  set %xdccsessionsendfile $did(xdccpreferencesdialog, 508).text
  if ($exists($networksendfile) && $networksendfile != $xdccdir $+ \ + $replxdccfile($did(xdccpreferencesdialog, 509).text)) { .rename $networksendfile $preventdoubleslash($xdccdir $+ \ $+ $replxdccfile($did(xdccpreferencesdialog, 509).text)) }
  set %networksendfile $did(xdccpreferencesdialog, 509).text
  if ($exists($xdccqueueposfile) && $xdccqueueposfile != $xdccdir $+ \ + $replxdccfile($did(xdccpreferencesdialog, 510).text)) { .rename $xdccqueueposfile $preventdoubleslash($xdccdir $+ \ $+ $replxdccfile($did(xdccpreferencesdialog, 510).text)) }
  set %xdccqueueposfile $did(xdccpreferencesdialog, 510).text
  if ($exists($chankeyfile) && $chankeyfile != $xdccdir $+ \ + $replxdccfile($did(xdccpreferencesdialog, 511).text)) { .rename $chankeyfile $preventdoubleslash($xdccdir $+ \ $+ $replxdccfile($did(xdccpreferencesdialog, 511).text)) }
  set %chankeyfile $did(xdccpreferencesdialog, 511).text
  if ($exists($dccallownetworkfile) && $dccallownetworkfile != $xdccdir $+ \ + $replxdccfile($did(xdccpreferencesdialog, 512).text)) { .rename $dccallownetworkfile $preventdoubleslash($xdccdir $+ \ $+ $replxdccfile($did(xdccpreferencesdialog, 512).text)) }
  set %dccallownetworkfile $did(xdccpreferencesdialog, 512).text
  if ($exists($alternatedccserverfile) && $alternatedccserverfile != $xdccdir $+ \ + $replxdccfile($did(xdccpreferencesdialog, 516).text)) { .rename $alternatedccserverfile $preventdoubleslash($xdccdir $+ \ $+ $replxdccfile($did(xdccpreferencesdialog, 516).text)) }
  set %alternatedccserverfile $did(xdccpreferencesdialog, 516).text
  if ($exists($xdccwishlist) && $xdccwishlist != $xdccdir $+ \ + $replxdccfile($did(xdccpreferencesdialog, 515).text)) { .rename $xdccwishlist $preventdoubleslash($xdccdir $+ \ $+ $replxdccfile($did(xdccpreferencesdialog, 515).text)) }
  set %xdccwishlist $did(xdccpreferencesdialog, 515).text
  if ($exists($statsfile) && $statsfile != $xdccdir $+ \ + $replxdccfile($did(xdccpreferencesdialog, 514).text)) { .rename $statsfile $preventdoubleslash($xdccdir $+ \ $+ $replxdccfile($did(xdccpreferencesdialog, 514).text)) }
  set %statsfile $did(xdccpreferencesdialog, 514).text
  if ($exists($xdccdebugfile) && $xdccdebugfile != $xdccdir $+ \ + $replxdccfile($did(xdccpreferencesdialog, 513).text)) { .rename $xdccdebugfile $preventdoubleslash($xdccdir $+ \ $+ $replxdccfile($did(xdccpreferencesdialog, 513).text)) }
  set %xdccdebugfile $did(xdccpreferencesdialog, 513).text

  if ($did(xdccpreferencesdialog, 403).text isnum && $did(xdccpreferencesdialog, 403).text >= 0) { set %resumedelay $did(xdccpreferencesdialog, 403).text }
  if ($did(xdccpreferencesdialog, 407).text isnum && $did(xdccpreferencesdialog, 407).text >= 0) { set %sendresumedelay $did(xdccpreferencesdialog, 407).text }
  if ($did(xdccpreferencesdialog, 401).text isnum && $did(xdccpreferencesdialog, 401).text >= 0) { set %minresumedelay $did(xdccpreferencesdialog, 401).text }
  if ($did(xdccpreferencesdialog, 402).text isnum && $did(xdccpreferencesdialog, 402).text >= 0) { set %maxresumedelay $did(xdccpreferencesdialog, 402).text }
  if ($did(xdccpreferencesdialog, 409).text isnum && $did(xdccpreferencesdialog, 409).text >= 0) { set %minautoqdelay $did(xdccpreferencesdialog, 409).text }
  if ($did(xdccpreferencesdialog, 410).text isnum && $did(xdccpreferencesdialog, 410).text >= 0) { set %maxautoqdelay $did(xdccpreferencesdialog, 410).text }
  if ($did(xdccpreferencesdialog, 411).text isnum && $did(xdccpreferencesdialog, 411).text >= 0) { set %minqfulldelay $did(xdccpreferencesdialog, 411).text }
  if ($did(xdccpreferencesdialog, 412).text isnum && $did(xdccpreferencesdialog, 412).text >= 0) { set %maxqfulldelay $did(xdccpreferencesdialog, 412).text }
  if ($did(xdccpreferencesdialog, 413).text isnum && $did(xdccpreferencesdialog, 413).text >= 0) { set %minnoconnect $did(xdccpreferencesdialog, 413).text }
  if ($did(xdccpreferencesdialog, 414).text isnum && $did(xdccpreferencesdialog, 414).text >= 0) { set %maxnoconnect $did(xdccpreferencesdialog, 414).text }
  if ($did(xdccpreferencesdialog, 415).text isnum && $did(xdccpreferencesdialog, 415).text >= 0) { set %startresumeoffset $did(xdccpreferencesdialog, 415).text }
  if ($did(xdccpreferencesdialog, 405).text isnum && $did(xdccpreferencesdialog, 405).text >= 0) { set %sendresumetime $did(xdccpreferencesdialog, 405).text }
  if ($did(xdccpreferencesdialog, 417).text isnum && $did(xdccpreferencesdialog, 417).text >= 0) { set %statisticstime $did(xdccpreferencesdialog, 417).text } 
  if ($did(xdccpreferencesdialog, 419).text isnum && $did(xdccpreferencesdialog, 419).text >= 0) { set %packchangechecktime $did(xdccpreferencesdialog, 419).text }
  if ($did(xdccpreferencesdialog, 421).text isnum && $did(xdccpreferencesdialog, 421).text >= 0) { set %liblimitdate $did(xdccpreferencesdialog, 421).text }

  if ($did(xdccpreferencesdialog, 131).state == 1) { set %sendlimit $did(xdccpreferencesdialog, 130).text }
  else { set %sendlimit Unlimited }
  ;  set %maxnumberresumes unlimited
  set %maxtransfers $did(xdccpreferencesdialog, 203).text
  set %mintransfers $did(xdccpreferencesdialog, 204).text
  set %connectionbandwidth $did(xdccpreferencesdialog, 205).text
  set %maxbandwidth $did(xdccpreferencesdialog, 202).text
  set %minbandwidth $did(xdccpreferencesdialog, 201).text
  if ($did(xdccpreferencesdialog, 132).sel == 1) { set %botqueuemode bandwidth }
  else { set %botqueuemode number of transfers }

  if ($did(xdccpreferencesdialog, 303).state == 1) { set %infochoise special window }
  elseif ($did(xdccpreferencesdialog, 304).state == 1) { set %infochoise server status window }
  elseif ($did(xdccpreferencesdialog, 305).state == 1) { set %infochoise active window }
  else { set %infochoise both active and special windows }
  ;  set %xdccfont @XDCC_Info 12 Verdana
  if ($did(xdccpreferencesdialog, 307).state == 1) { set %showbotlist on }
  else { set %showbotlist off }

  if ($did(xdccpreferencesdialog, 106).state == 1) { set %botqueuehandling on }
  else { set %botqueuehandling off }
  if ($did(xdccpreferencesdialog, 107).state == 1) { set %testnumoftransferspeed on }
  else { set %testnumoftransferspeed off }
  if ($did(xdccpreferencesdialog, 115).state == 1) { set %autocleanatstart on }
  else { set %autocleanatstart off }
  if ($did(xdccpreferencesdialog, 112).state == 1) { set %clearallqueuesoncomplete on }
  else { set %clearallqueuesoncomplete off }
  if ($did(xdccpreferencesdialog, 112).state == 1) { set %debugxdccinfo on }
  else { set %debugxdccinfo off }
  if ($did(xdccpreferencesdialog, 102).state == 1) { .enable #groupautoxdccresume }
  else { .disable #groupautoxdccresume }
  if ($did(xdccpreferencesdialog, 104).state == 1) { .enable #groupautoxdccresumejoin }
  else { .disable #groupautoxdccresumejoin }
  if ($did(xdccpreferencesdialog, 105).state == 1) { .enable #groupautoxdccq } 
  else { .disable #groupautoxdccq } 
  if ($did(xdccpreferencesdialog, 108).state == 1) { .enable #groupautoresumeatstart }
  else { .disable #groupautoresumeatstart }
  if ($did(xdccpreferencesdialog, 108).state == 1) { .enable #groupautoresumestart }
  else { .disable #groupautoresumestart }
  if ($did(xdccpreferencesdialog, 110).state == 1) { .enable #groupautojoinxdcc }
  else { .disable #groupautojoinxdcc }
  if ($did(xdccpreferencesdialog, 109).state == 1) { .enable #groupnonewconnects } 
  else { .disable #groupnonewconnects } 
  if ($did(xdccpreferencesdialog, 111).state == 1) { .enable #groupautoremove } 
  else { .disable #groupautoremove } 
  if ($did(xdccpreferencesdialog, 103).state == 1) { .enable #groupautosendresume }
  else { .disable #groupautosendresume }
  if ($did(xdccpreferencesdialog, 114).state == 1) { .enable #grouptrackqueuepos }
  else { .disable #grouptrackqueuepos }
  if ($did(xdccpreferencesdialog, 116).state == 1) { .set %debugxdccinfo on }
  else { .set %debugxdccinfo off }

  if ($did(xdccpreferencesdialog, 113).state == 1) { 
    .enable #grouppackchangedetect 
    set %comparepacks on
  }
  else {
    .disable #grouppackchangedetect 
    set %comparepacks off
  }

  if (%newxdccdir != $null && $remove($replxdccdir(%newxdccdir),$mircdir) != $remove($replxdccdir(%xdccdir),$mircdir)) {
    .mkdir %newxdccdir
    /movexdccdir2 %newxdccdir
  }

  if ($did(xdccpreferencesdialog,301).text != %xdccfont && ($gettok($did(xdccpreferencesdialog,301).text,1,32) == @XDCC_Info || $gettok($did(xdccpreferencesdialog,301).text,1-2,32) == -b @XDCC_Info)) { 
    set %xdccfont $did(xdccpreferencesdialog,301).text 
    .timer 1 1 /font $did(xdccpreferencesdialog,301).text 
  }

  if ($did(xdccpreferencesdialog, 307).state == 1) { 
    if (%showbotlist != on) {
      window -c @XDCC_Info
      /makexdccwindow 
    }
    set %showbotlist on 
  }
  elseif ($did(xdccpreferencesdialog, 307).state == 0) { 
    if (%showbotlist != off) {
      window -c @XDCC_Info
      /makexdccwindow 
    }
    set %showbotlist off 
  }
  else {}
  /outputxdccinfo 14Applied All Settings.
  /outputxdccinfo 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------

;-------------------------------------------------------------------------
; /dialog xdccpreferencesdialog:
; 14 editboxes, 1 ok button, 1 cancel button.
; 3rd manual setup window. Sets the timer settings.
;-------------------------------------------------------------------------
dialog xdccpreferencesdialog {
  title "XDCC Script Preferences"
  size -1 -1 700 600
  button "OK", 1, 170 565 100 25, ok
  button "Apply", 2, 290 565 100 25
  button "Cancel", 3, 410 565 100 25, cancel

  tab "Main", 4, 3 3 694 550
  tab "Connection Settings", 5
  tab "Window Settings", 6
  tab "Timer Settings", 7
  tab "File Settings", 8
  tab "Lists", 9
  tab "Nicklist Colors", 10

  text "Check the script features that you want to enable:", 101, 40 50 300 15, tab 4
  check "Automatically resume incoming transfers (downloads) when they fail", 102, 45 80 500 15, tab 4
  check "Automatically resume outgoing transfers (uploads) when they fail", 103, 45 100 330 15, tab 4
  check "Automatically resume transfers when an offline bot rejoins a channel", 104, 45 120 500 15, tab 4
  check "Automatically queue up next requested pack when a transfer completes", 105, 45 140 500 15, tab 4
  check "Automatically start queue for the next bot in the Bot Queue when a previous bot completes it's queue", 106, 45 160 600 15, tab 4
  check "Automatically test every few seconds and start queue for the next bot in the Bot Queue when ", 107, 45 180 475 15, tab 4
  check "Automatically resume incomplete transfers at IRC start that were active during the last time IRC closed", 108, 45 200 600 15, tab 4
  check "Automatically retry after N secs if a bot says it will refuse all connections for next N secs", 109, 45 220 600 15, tab 4
  check "Automatically join a channel if a bot requires it", 110, 45 240 500 15, tab 4
  check "Automatically remove packs that you manually removed from a bot's remote queue using /msg bot xdcc remove", 111, 45 260 600 15, tab 4
  check "Automatically attempt to remove a completed pack from queues on all bots, instead of just the bot that completed it", 112, 45 280 603 15, tab 4
  check "Automatically inform me if a bot's pack listing appears to have changed", 113, 45 300 500 15, tab 4
  check "Automatically inform me if my remote queue position changes on a bot", 114, 45 320 500 15, tab 4
  check "Automatically clean XDCC library from old files at IRC startup", 115, 45 340 500 15, tab 4
  check "Write a debugging Log file", 116, 45 380 400 15, tab 4

  edit "", 130, 590 97 80 20, tab 4
  check "Bandwidth limit (Per Send, in KB/s):", 131, 395 100 185 15, tab 4
  combo 132, 520 176 150 20, drop, tab 4

  box "Main Options:", 140, 15 30 670 505, tab 4



  edit "", 201, 500 117 120 20, tab 5
  edit "", 202, 500 137 120 20, tab 5
  edit "", 203, 500 187 120 20, tab 5
  edit "", 204, 500 207 120 20, tab 5
  edit "", 205, 500 257 120 20, tab 5
  edit "", 206, 500 460 120 20, tab 5

  check "Enable timed testing for ", 210, 55 67 131 20, tab 5
  check "Enable DCC send autoresume ", 211, 55 420 180 20, tab 5
  combo 220, 190 67 150 20, drop, tab 5
  text "Minimum bandwidth that should be used at any time (in KByte):", 230, 45 120 390 20, tab 5
  text "Maximum bandwidth for which to start a new XDCC transfer when file completes (in KByte):", 231, 45 140 440 20, tab 5
  text "Minimum number of downloads that should be active at any time:", 232, 45 190 390 20, tab 5
  text "Maximum number of downloads that should be active at any time:", 233, 45 210 390 20, tab 5
  text "Your approximate connection speed (in KByte):", 234, 45 260 390 20, tab 5
  check "Limit maximum bandwidth to be used by a resumed DCC Send to:", 235, 55 460 360 20, tab 5

  box "Connection Options:", 250, 15 30 670 505, tab 5
  box "System Options:", 251, 35 240 630 45, tab 5
  box "Timed Botqueue Handling Settings:", 252, 25 45 650 350, tab 5
  box "Used bandwidth method:", 253, 35 100 630 65, tab 5
  box "Number of active transfers method:", 254, 35 170 630 65, tab 5

  box "Auto Send Resume Options:", 255, 25 400 650 120, tab 5



  edit "", 301, 45 240 250 25, tab 6
  text "Where do you want the script's messages to go?", 302, 40 50 300 15, tab 6
  text "", 310, 40 220 250 15, tab 6
  radio "Write messages to a separate XDCC_Info window", 303, 45 80 300 15, group, tab 6
  radio "Write messages to the server status window", 304, 45 100 300 15, tab 6
  radio "Write messages to the currently active window", 305, 45 120 300 15, tab 6
  radio "Write messages to the currently active window and to a separate XDCC_Info window", 306, 45 140 430 15, tab 6
  check "Show a list of all known bots in the separate XDCC_Info window", 307, 45 180 400 15, tab 6

  box "Window Options:", 320, 15 30 670 505, tab 6




  edit "", 401, 348 78 53 20, tab 7
  edit "", 402, 414 78 53 20, tab 7
  edit "", 403, 348 98 53 20, tab 7
  text "N/A", 404, 420 100 53 20, tab 7
  edit "", 405, 348 118 53 20, tab 7
  text "N/A", 406, 420 120 53 20, tab 7
  edit "", 407, 348 138 53 20, tab 7
  text "N/A", 408, 420 140 53 20, tab 7
  edit "", 409, 348 158 53 20, tab 7
  edit "", 410, 414 158 53 20, tab 7
  edit "", 411, 348 178 53 20, tab 7
  edit "", 412, 414 178 53 20, tab 7
  edit "", 413, 348 198 53 20, tab 7
  edit "", 414, 414 198 53 20, tab 7
  edit "", 415, 348 218 53 20, tab 7
  text "N/A", 416, 420 220 53 20, tab 7
  edit "", 417, 348 238 53 20, tab 7
  text "N/A", 418, 420 240 53 20, tab 7
  edit "", 419, 348 258 53 20, tab 7
  text "N/A", 420, 420 260 53 20, tab 7
  edit "", 421, 348 278 53 20, tab 7
  text "N/A", 422, 420 280 53 20, tab 7

  text "Delay for failed download auto resume (in secs):", 430, 45 80 300 15, tab 7
  text "Disable time for failed download auto resume (in secs):", 431, 45 100 300 15, tab 7
  text "Delay for failed upload auto resume (in secs):", 432, 45 120 300 15, tab 7
  text "Disable time for failed upload auto resume (in secs):", 433, 45 140 300 15, tab 7
  text "Delay for next pack auto queue (in secs):", 434, 45 160 300 15, tab 7
  text "Delay for retry on remote queue full (in secs):", 435, 45 180 300 15, tab 7
  text "Added delay for retry on 'no new connections' notice:", 436, 45 200 300 15, tab 7
  text "Offset for auto download resume at IRC start (in secs):", 437, 45 220 300 15, tab 7
  text "Delay for open download slot or available bandwidth test:", 438, 45 240 300 15, tab 7
  text "Delay for updated pack listing comparison (in secs):", 439, 45 260 300 15, tab 7
  text "Idle XDCC library entry timeout date (in days):", 440, 45 280 300 15, tab 7

  text "The time intervals used by the XDCC script are as follows: ", 451, 40 50 300 15, tab 7
  box "Min Time", 460, 345 63 60 239, tab 7
  box "Max Time", 461, 410 63 60 239, tab 7

  box "Timer Settings:", 462, 15 30 670 505, tab 7



  edit "", 501, 318 48 165 20, tab 8
  edit "", 502, 318 68 165 20, tab 8
  edit "", 503, 318 88 165 20, tab 8
  edit "", 504, 318 108 165 20, tab 8
  edit "", 505, 318 128 165 20, tab 8
  edit "", 506, 318 168 165 20, tab 8
  edit "", 507, 318 188 165 20, tab 8
  edit "", 508, 318 208 165 20, tab 8
  edit "", 509, 318 228 165 20, tab 8
  edit "", 510, 318 248 165 20, tab 8
  edit "", 511, 318 268 165 20, tab 8
  edit "", 512, 318 288 165 20, tab 8
  edit "", 513, 318 328 165 20, tab 8
  edit "", 514, 318 368 165 20, tab 8
  edit "", 515, 318 348 165 20, tab 8
  edit "", 516, 318 308 165 20, tab 8
  edit "", 517, 318 148 165 20, tab 8

  button "Choose Script Directory", 530, 318 400 165 25, tab 8

  text "", 551, 45 405 150 15, tab 8
  text "Trigger Hash File:", 552, 45 50 250 15, tab 8
  text "Trigger Hash Backup File:", 553, 45 70 250 15, tab 8
  text "Active Transfers File:", 554, 45 90 250 15, tab 8
  text "Auto Resume Get Temp Disable File:", 555, 45 110 250 15, tab 8
  text "Auto Resume Send Temp Disable File:", 556, 45 130 200 15, tab 8
  text "Temp Bot Queue File:", 557, 45 170 250 15, tab 8
  text "Session Gets File:", 558, 45 190 250 15, tab 8
  text "Session Sends File:", 559, 45 210 250 15, tab 8
  text "Active Transfers On Networks File:", 560, 45 230 250 15, tab 8
  text "Remote Queue Positions File:", 561, 45 250 250 15, tab 8
  text "Channel Key File:", 562, 45 270 250 15, tab 8
  text "DCCALLOW Network File:", 563, 45 290 250 15, tab 8
  text "Debug Log File:", 564, 45 330 250 15, tab 8
  text "Statistics file mask:", 565, 45 370 250 15, tab 8
  text "Wishlist File:",566, 45 350 250 15, tab 8
  text "Alternate DCC Server Send Method File:",567, 45 310 250 15, tab 8
  text "Bot Queue File:", 568, 45 150 250 15, tab 8

  box "Timer Settings:", 580, 15 30 670 505, tab 8


  button "Add Channel Key", 601, 33 110 150 25, tab 9
  button "Delete Channel Key", 602, 189 110 150 25, tab 9
  button "Add DCCALLOW Network", 603, 363 110 150 25, tab 9
  button "Remove DCCALLOW Network", 604, 518 110 150 25, tab 9
  button "Add Alt. DCC Server", 605, 33 350 150 25, tab 9
  button "Remove Alt. DCC Server", 606, 189 350 150 25, tab 9
  button "Add Wishlist Item", 607, 363 350 150 25, tab 9
  button "Remove Wishlist Item", 608, 518 350 150 25, tab 9

  list 610, 33 145 305 145, tab 9
  list 611, 363 145 305 145, tab 9
  list 612, 33 385 305 145, tab 9
  list 613, 363 385 305 145, tab 9
  box "Miscelaneous Options: ", 630, 15 30 670 505, tab 9
  box "Channel Keys: ", 631, 25 45 322 235, tab 9
  box "Networks with /DCCALLOW + support: ", 632, 353 45 322 235, tab 9
  box "DCC Alternate Send Method Support: ", 633, 25 285 322 235, tab 9
  box "Wishlist Items: ", 634, 353 285 322 235, tab 9

  text "Add or remove channels that require a key to join.",650, 32 65 250 25, tab 9
  text "Syntax: NETWORK CHANNEL KEY (E.g.: EFnet #chan 1337key)",651, 32 85 250 15, tab 9
  text "Add or remove networks that require /DCCALLOW +NICKNAME to receive files.",652, 362 63 290 25, tab 9
  text "Syntax: NETWORK (E.g.: EFnet)",653, 362 90 250 15, tab 9

  text "Add or remove bots that use a '/dccserver ?? on PORT' method.",654, 32 303 320 25, tab 9
  text "Syntax: NETWORK NICK COMMAND (E.g.: EFnet guest1234 /dccserver +sc on 1337)",655, 32 319 320 25, tab 9
  text "Add or remove items the script should warn you about if they are seen. More general description will give more matches, more specific description to prevent false alarms.",656, 362 303 290 40, tab 9


  text "Future project.",700, 300 300 250 25, tab 10

}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------

;-------------------------------------------------------------------------
; Settings and Options menu dialog listeners.
;-------------------------------------------------------------------------
on 1:dialog:xdccpreferencesdialog:edit:130:{ 
  /did -o xdccpreferencesdialog 206 1 $did(xdccpreferencesdialog,130,1).text
}
;-------------------------------------------------------------------------
on 1:dialog:xdccpreferencesdialog:edit:206:{ 
  /did -o xdccpreferencesdialog 130 1 $did(xdccpreferencesdialog,206,1).text
}
;-------------------------------------------------------------------------
on 1:dialog:xdccpreferencesdialog:sclick:103:{ 
  if ($did(xdccpreferencesdialog,103).state == 1) { 
    /did -c xdccpreferencesdialog 211
    /did -e xdccpreferencesdialog 131
    /did -e xdccpreferencesdialog 235
    if ($did(xdccpreferencesdialog,131).state == 1) {
      /did -n xdccpreferencesdialog 130 
      /did -n xdccpreferencesdialog 206
    }
  }
  else { 
    /did -u xdccpreferencesdialog 211
    /did -b xdccpreferencesdialog 131
    /did -b xdccpreferencesdialog 235 
    /did -m xdccpreferencesdialog 130
    /did -m xdccpreferencesdialog 206
  }
}
;-------------------------------------------------------------------------
on 1:dialog:xdccpreferencesdialog:sclick:211:{
  if ($did(xdccpreferencesdialog,211).state == 1) { 
    /did -c xdccpreferencesdialog 103 
    /did -e xdccpreferencesdialog 131
    /did -e xdccpreferencesdialog 235
    if ($did(xdccpreferencesdialog,235).state == 1) {
      /did -n xdccpreferencesdialog 130
      /did -n xdccpreferencesdialog 206
    }
  }
  else { 
    /did -u xdccpreferencesdialog 103 
    /did -b xdccpreferencesdialog 131
    /did -b xdccpreferencesdialog 235
    /did -m xdccpreferencesdialog 130
    /did -m xdccpreferencesdialog 206
  }
}
;-------------------------------------------------------------------------
on 1:dialog:xdccpreferencesdialog:sclick:235:{ 
  if ($did(xdccpreferencesdialog,235).state == 1) { 
    /did -c xdccpreferencesdialog 131
    /did -n xdccpreferencesdialog 130
    /did -n xdccpreferencesdialog 206
  }
  else {
    /did -u xdccpreferencesdialog 131
    /did -m xdccpreferencesdialog 130
    /did -m xdccpreferencesdialog 206
  }
}
;-------------------------------------------------------------------------
on 1:dialog:xdccpreferencesdialog:sclick:131:{ 
  if ($did(xdccpreferencesdialog,131).state == 1) { 
    /did -c xdccpreferencesdialog 235
    /did -n xdccpreferencesdialog 130
    /did -n xdccpreferencesdialog 206
  }
  else {
    /did -u xdccpreferencesdialog 235
    /did -m xdccpreferencesdialog 130
    /did -m xdccpreferencesdialog 206
  }
}
;-------------------------------------------------------------------------
on 1:dialog:xdccpreferencesdialog:sclick:132:{ 
  /did -c xdccpreferencesdialog 220 $did(132).sel 
  if ($did(xdccpreferencesdialog,132).sel == 1) { 
    /did -m xdccpreferencesdialog 230 
    /did -m xdccpreferencesdialog 231 
    /did -n xdccpreferencesdialog 232
    /did -n xdccpreferencesdialog 233
  }
  else {
    /did -n xdccpreferencesdialog 230 
    /did -n xdccpreferencesdialog 231 
    /did -m xdccpreferencesdialog 232
    /did -m xdccpreferencesdialog 233
  }
} 
;-------------------------------------------------------------------------
on 1:dialog:xdccpreferencesdialog:sclick:220:{ 
  /did -c xdccpreferencesdialog 132 $did(220).sel 
  if ($did(xdccpreferencesdialog,220).sel == 1) { 
    /did -n xdccpreferencesdialog 201 
    /did -n xdccpreferencesdialog 202 
    /did -m xdccpreferencesdialog 203
    /did -m xdccpreferencesdialog 204
  }
  else {
    /did -m xdccpreferencesdialog 201 
    /did -m xdccpreferencesdialog 202 
    /did -n xdccpreferencesdialog 203
    /did -n xdccpreferencesdialog 204
  }
}
;-------------------------------------------------------------------------
on 1:dialog:xdccpreferencesdialog:sclick:107:{ 
  if ($did(xdccpreferencesdialog,107).state == 1) { 
    /did -e xdccpreferencesdialog 132 
    /did -c xdccpreferencesdialog 210
    /did -e xdccpreferencesdialog 220
    if ($did(xdccpreferencesdialog,220).sel == 1) { 
      /did -n xdccpreferencesdialog 201 
      /did -n xdccpreferencesdialog 202 
      /did -m xdccpreferencesdialog 203
      /did -m xdccpreferencesdialog 204
    }
    else {
      /did -m xdccpreferencesdialog 201 
      /did -m xdccpreferencesdialog 202 
      /did -n xdccpreferencesdialog 203
      /did -n xdccpreferencesdialog 204
    }
  }
  else { 
    /did -b xdccpreferencesdialog 132 
    /did -u xdccpreferencesdialog 210
    /did -b xdccpreferencesdialog 220
    /did -m xdccpreferencesdialog 201 
    /did -m xdccpreferencesdialog 202 
    /did -m xdccpreferencesdialog 203 
    /did -m xdccpreferencesdialog 204 
  }
}
;-------------------------------------------------------------------------
on 1:dialog:xdccpreferencesdialog:sclick:210:{ 
  if ($did(xdccpreferencesdialog,210).state == 1) { 
    /did -e xdccpreferencesdialog 132 
    /did -c xdccpreferencesdialog 107
    /did -e xdccpreferencesdialog 220
    if ($did(xdccpreferencesdialog,220).sel == 1) { 
      /did -n xdccpreferencesdialog 201
      /did -n xdccpreferencesdialog 202
      /did -m xdccpreferencesdialog 203 
      /did -m xdccpreferencesdialog 204
    }
    else {
      /did -m xdccpreferencesdialog 201 
      /did -m xdccpreferencesdialog 202 
      /did -n xdccpreferencesdialog 203
      /did -n xdccpreferencesdialog 204
    }
  }
  else { 
    /did -b xdccpreferencesdialog 132 
    /did -u xdccpreferencesdialog 107
    /did -b xdccpreferencesdialog 220
    /did -m xdccpreferencesdialog 201 
    /did -m xdccpreferencesdialog 202 
    /did -m xdccpreferencesdialog 203 
    /did -m xdccpreferencesdialog 204 
  }
}
;-------------------------------------------------------------------------
on *:dialog:xdccpreferencesdialog:sclick:530:{ 
  set %tempdir $sdir($xdccdir, Select directory to be used for XDCC script) 
  if (%tempdir != $null) {
    set %newxdccdir %tempdir
    //did -o xdccpreferencesdialog 551 1 New XDCC dir $+ $chr(58) $replxdccdir(%newxdccdir)
  }
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
on *:dialog:xdccpreferencesdialog:sclick:601: {
  set %chankey $?*="Please input network, channel and required key separated by a space (E.g.: EFnet #channel 1337key)."
  if ($numtok(%chankey, 32) >= 3) { 
    /did -a xdccpreferencesdialog 610 $gettok(%chankey,1-2,32) 
    if ($read($chankeyfile,snt,$gettok(%chankey,1-2,32))) { /write -ds" $+ $gettok(%chankey,1-2,32) $+ " $chankeyfile }
    /write -a $chankeyfile %chankey
  }
}
;-------------------------------------------------------------------------
on *:dialog:xdccpreferencesdialog:sclick:603: {
  set %networks $?="Please input networks that should support DCCALLOW options, separated by a space (E.g.: DALnet EFnet irchighway). Do not add networks that don't use DCCALLOW."
  set %i 1
  while (%i <= $numtok(%networks, 32)) { 
    if (!$read($dccallownetworkfile,wnt,$gettok(%networks,%i,32))) { 
      /did -a xdccpreferencesdialog 611 $gettok(%networks,%i,32) 
      /write -a $dccallownetworkfile $gettok(%networks,%i,32) 
    }
    inc %i
  }
}
;-------------------------------------------------------------------------
on *:dialog:xdccpreferencesdialog:sclick:605: {
  set %altserv $?="Please input network, nickname and dccserver command separated by a space (E.g.: EFnet guest1234 /dccserver +sc on 1337)."
  if ($numtok(%altserv, 32) > 4) { 
    /did -a xdccpreferencesdialog 612 %altserv 
    if (!$read($alternatedccserverfile,wnt,$gettok(%altserv,1-2,32))) { /write -ds" $+ $gettok(%altserv,1-2,32) $+ " $alternatedccserverfile }
    /write -a $alternatedccserverfile %altserv  
  }
}
;-------------------------------------------------------------------------
on *:dialog:xdccpreferencesdialog:sclick:607: {
  set %newwishlistitem $?="Please input a (partial) pack description to add to the wishlist."
  if (!$read($xdccwishlist,wnt,%newwishlistitem)) { 
    /did -a xdccpreferencesdialog 613 %newwishlistitem 
    /write -a $xdccwishlist %newwishlistitem 
  }
}
;-------------------------------------------------------------------------
on *:dialog:xdccpreferencesdialog:sclick:602: { 
  if ($read($chankeyfile,snt,$did(xdccpreferencesdialog, 610).seltext)) { /write -ds" $+ $did(xdccpreferencesdialog, 610).seltext $+ " $chankeyfile }
  /did -d xdccpreferencesdialog 610 $did(xdccpreferencesdialog, 610).sel 
}
;-------------------------------------------------------------------------
on *:dialog:xdccpreferencesdialog:sclick:604: { 
  if ($read($dccallownetworkfile,wnt,$did(xdccpreferencesdialog, 611).seltext)) { /write -dw" $+ $did(xdccpreferencesdialog, 611).seltext $+ " $dccallownetworkfile }
  /did -d xdccpreferencesdialog 611 $did(xdccpreferencesdialog, 611).sel 
}
;-------------------------------------------------------------------------
on *:dialog:xdccpreferencesdialog:sclick:606: {
  if ($read($alternatedccserverfile,wnt,$did(xdccpreferencesdialog, 612).seltext)) { /write -dw" $+ $did(xdccpreferencesdialog, 612).seltext $+ " $alternatedccserverfile }
  /did -d xdccpreferencesdialog 612 $did(xdccpreferencesdialog, 612).sel 
}
;-------------------------------------------------------------------------
on *:dialog:xdccpreferencesdialog:sclick:608: { 
  if ($read($xdccwishlist,wnt,$did(xdccpreferencesdialog, 613).seltext)) { /write -dw" $+ $did(xdccpreferencesdialog, 613).seltext $+ " $xdccwishlist }
  /did -d xdccpreferencesdialog 613 $did(xdccpreferencesdialog, 613).sel 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
on *:dialog:xdccpreferencesdialog:sclick:1,2: { /applyallxdccsettings }
;-------------------------------------------------------------------------
on *:dialog:xdccpreferencesdialog:sclick:3: { 
  /outputxdccinfo 14Settings not saved, options dialog cancelled. 
  /outputxdccinfo 
}
;-------------------------------------------------------------------------













;-------------------------------------------------------------------------
; /dialog xdccinitwizard:
; 3 radio buttons, 1 ok button.
; Here you can choose to open an existing profile, revert to default 
; settings, or continue with the wizard manually.
;-------------------------------------------------------------------------
dialog xdccinitwizard {
  title "XDCC Autoresume/Autoqueue Stealth Script Wizard"
  size -1 -1 300 200
  button "Next", 1, 100 160 100 25, Ok 
  text "What do you want to do:", 3, 30 40 130 15
  radio "I want to open an existing profile", 4, 35 60 200 15, group
  radio "I want to use default values", 5, 35 80 200 15
  radio "I want to configure the script manually now", 6, 35 100 240 15
  box "Choose Configuration Method", 7, 5 5 290 190
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------

;-------------------------------------------------------------------------
; Remote identifiers for /dialog xdccinitwizard:
; init: Selects revert to default.
; sclick 5 & 4,6: Renames the ok button.
; sclick 1: Loads or reverts settings, or continues the wizard with 
;           /dialog xdccmanualwizard3.
;-------------------------------------------------------------------------
on *:dialog:xdccinitwizard:init:*: { /did -c xdccinitwizard 5 }
;-------------------------------------------------------------------------
on *:dialog:xdccinitwizard:sclick:5: {
  /did -r xdccinitwizard 1
  /did -a xdccinitwizard 1 OK
}
;-------------------------------------------------------------------------
on *:dialog:xdccinitwizard:sclick:4,6: {
  /did -r xdccinitwizard 1
  /did -a xdccinitwizard 1 Next
}
;-------------------------------------------------------------------------
on *:dialog:xdccinitwizard:sclick:1: {
  if ($did(4).state == 1) { /xdccloadwizard }
  elseif ($did(5).state == 1) { /reverttodefaults2 }
  elseif ($did(6).state == 1) { /xdccmanualwizard1 }
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------


;-------------------------------------------------------------------------
; Wizard dialog aliases:
; /xdccinitwizard: Set default values, then open xdccinitwizard dialog.
; /xdccloadwizard: Show file dialog and load settings from selected file.
; /xdccmanualwizard1-4: Open /xdccmanualwizard1-4 dialog.
;-------------------------------------------------------------------------
alias xdccinitwizard { 
  /reverttodefaults2
  /dialog -m xdccinitwizard XDCCInitWizard 
}
;-------------------------------------------------------------------------
alias xdccloadwizard {
  if ($isdir($xdccdir)) { set %filenm $sfile($xdccdir $+ \ $+ *.set,Select profile to load) }
  else { set %filenm $sfile($mircdir $+ \ $+ *.set,Select profile to load) }
  /loadxdccscriptsettings $remove(%filenm,.set)
}
;-------------------------------------------------------------------------





;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
alias xdccmanualwizard1 { 
  /dialog -m xdccmanualwizard1 xdccmanualwizard1 
  /did -b xdccmanualwizard1 1
}
;-------------------------------------------------------------------------
dialog xdccmanualwizard1 {
  title "XDCC Script Manual Wizard: System and bandwidth settings"
  size -1 -1 400 250
  button "Next", 1, 140 200 100 25, ok 
  box "Main Options:", 17, 5 5 390 240
  text "Your system's approximate total Bandwidth limit (in KB/s):", 19, 25 80 300 15
  edit "", 18, 330 75 50 20
}
;-------------------------------------------------------------------------
on *:dialog:xdccmanualwizard1:edit:18:{
  if ($did(xdccmanualwizard1,18).text isnum &&  $did(xdccmanualwizard1,18).text > 0) { /did -e xdccmanualwizard1 1 }
}
;-------------------------------------------------------------------------
on *:dialog:xdccmanualwizard1:sclick:1:{
  if ($did(xdccmanualwizard1,18).text isnum &&  $did(xdccmanualwizard1,18).text > 0) {
    set %connectionbandwidth $did(xdccmanualwizard1,18).text
    set %maxbandwidth %connectionbandwidth * 0.75
    set %minbandwidth %connectionbandwidth * 0.50
    set %maxtransfers $ceil($sqrt($sqrt($calc(2 * $did(xdccmanualwizard1,18).text))))
    set %mintransfers $floor($sqrt($sqrt($calc($did(xdccmanualwizard1,18).text))))
    /xdccmanualwizard2
  }
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------







;-------------------------------------------------------------------------
; /dialog xdccmanualwizard2:
; 13 checkboxes, 1 editbox, 1 ok button, 1 cancel button.
; 1st manual setup window. Sets the main features for the script, and the 
; send bandwidth for auto resume send. 
;-------------------------------------------------------------------------
dialog xdccmanualwizard2 {
  title "XDCC Script Manual Wizard: Features"
  size -1 -1 750 420
  button "Next", 1, 250 360 100 25, ok 
  button "Cancel", 2, 375 360 100 25, cancel
  text "Check the script features that you want to enable:", 3, 70 40 300 15
  check "Automatically resume incoming transfers when they fail", 4, 75 60 500 15, group
  check "Automatically resume outgoing transfers when they fail", 16, 75 80 300 15
  check "Automatically resume transfers when an offline bot rejoins a channel", 5, 75 100 500 15
  check "Automatically queue up next requested pack when a transfer completes", 6, 75 120 500 15
  check "Automatically start queue for the next bot in the Bot Queue when a previous bot completes it's queue", 7, 75 140 600 15
  check "Automatically resume incomplete transfers that were active during last IRC close at IRC start", 8, 75 180 600 15
  check "Automatically retry after N secs if bot says it will refuse all connections for next N secs", 9, 75 200 600 15
  check "Automatically join a channel if a bot requires it", 10, 75 220 500 15
  check "Automatically remove packs that you manually removed from a bot's remote queue using /msg bot xdcc remove", 11, 75 240 600 15
  check "Automatically attempt to remove a completed pack from all queues on all bots instead of just the one bot that completed it", 12, 75 260 603 15
  check "Automatically inform me if a bot's pack listing appears to have changed", 13, 75 280 500 15
  check "Automatically inform me if my remote queue position changes on a bot", 14, 75 300 500 15
  check "Automatically clean XDCC library from old files at IRC startup", 15, 75 320 500 15
  check "Automatically check every few minutes to see if bandwidth is available", 20, 75 160 500 15
  box "Main Options:", 17, 5 5 740 410
  text "Bandwidth limit (Per Send, in KB/s):", 19, 395 80 200 15
  edit "Unlimited", 18, 570 77 80 20
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------

;-------------------------------------------------------------------------
; Remote identifiers for /dialog xdccmanualwizard2:
; init: Selects default features.
; sclick 2: Cancel.
; sclick 1: Enables the appropriate groups and sets variables, then 
;           continues the wizard with /dialog xdccmanualwizard3.
;-------------------------------------------------------------------------
on *:dialog:xdccmanualwizard2:init:*: {
  /did -c xdccmanualwizard2 4
  /did -c xdccmanualwizard2 5
  /did -c xdccmanualwizard2 6
  /did -c xdccmanualwizard2 10
}
;-------------------------------------------------------------------------
on *:dialog:xdccmanualwizard2:sclick:1: {
  if ($did(4).state == 1) { .enable #groupautoxdccresume }
  else { .disable #groupautoxdccresume }
  if ($did(5).state == 1) { .enable #groupautoxdccresumejoin }
  else { .disable #groupautoxdccresumejoin }
  if ($did(6).state == 1) { .enable #groupautoxdccq }
  else { .disable #groupautoxdccq }
  if ($did(9).state == 1) { .enable #groupnonewconnects }
  else { .disable #groupnonewconnects }
  if ($did(10).state == 1) { .enable #groupautojoinxdcc }
  else { .disable #groupautojoinxdcc }
  if ($did(11).state == 1) { .enable #groupautoremove }
  else { .disable #groupautoremove }
  if ($did(14).state == 1) { .enable #grouptrackqueuepos }
  else { .disable #grouptrackqueuepos }
  if ($did(16).state == 1) { .enable #groupautosendresume }
  else { .disable #groupautosendresume }
  if ($did(8).state == 1) {
    .enable #groupautoresumeatstart
    .enable #groupautoresumestart
  }
  else { 
    .disable #groupautoresumeatstart
    .disable #groupautoresumestart
  }
  if ($did(13).state == 1) { 
    set %comparepacks on
    .enable #grouppackchangedetect
  }
  else { 
    set %comparepacks off
    .disable #grouppackchangedetect
  }
  if ($did(7).state == 1) { set %botqueuehandling on }
  else { set %botqueuehandling off }
  if ($did(15).state == 1) { set %autocleanatstart on }
  else { set %autocleanatstart off }
  if ($did(12).state == 1) { set %clearallqueuesoncomplete on }
  else { set %clearallqueuesoncomplete off }
  if ($did(20).state == 1) { set testnumoftransferspeed on }
  else { set testnumoftransferspeed off }

  if ($did(18).text isnum) { set %sendlimit $did(18).text }
  else { set %sendlimit Unlimited }
  /xdccmanualwizard3
}
;-------------------------------------------------------------------------
on *:dialog:xdccmanualwizard2:sclick:2: { 
  /outputxdccinfo 14Wizard manual configuration setup 4aborted14 during general settings, using default values for all settings. 
  /outputxdccinfo 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
alias xdccmanualwizard2 { /dialog -m xdccmanualwizard2 xdccmanualwizard2 }
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------









;-------------------------------------------------------------------------
; /dialog xdccmanualwizard3:
; 2 checkboxes, 4 radiobuttons, 1 ok button, 1 cancel button.
; 2nd manual setup window. Sets the window output for the script, and the 
; debug logging.
;-------------------------------------------------------------------------
dialog xdccmanualwizard3 {
  title "XDCC Script Manual Wizard: Output Settings"
  size -1 -1 480 290
  button "Next", 1, 125 250 100 25, ok
  button "Cancel", 2, 245 250 100 25, cancel
  text "Where do you want the script's messages to go?", 3, 20 40 300 15
  radio "Write messages to separate XDCC_Info window", 4, 25 60 300 15, group
  radio "Write messages to server status window", 5, 25 80 300 15
  radio "Write messages to the currently active window", 6, 25 100 300 15
  radio "Write messages to the currently active window and the separate XDCC_Info window", 7, 25 120 430 15
  check "Show a list of all known bots in the separate XDCC_Info window", 8, 25 160 400 15

  check "Write a debugging Log file", 9, 25 210 400 15

  box "Window Options:", 11, 15 20 450 170
  box "Log file Options:", 12, 15 190 450 50
  box "Output Options:", 13, 5 5 470 280
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------

;-------------------------------------------------------------------------
; Remote identifiers for /dialog xdccmanualwizard3:
; init: Selects default features.
; sclick 2: Cancel.
; sclick 1: Sets window variables, then continues the wizard with /dialog 
;           xdccmanualwizard3.
;-------------------------------------------------------------------------
on *:dialog:xdccmanualwizard3:init:*: { /did -c xdccmanualwizard3 4 }
;-------------------------------------------------------------------------
on *:dialog:xdccmanualwizard3:sclick:1: {
  if ($did(4).state == 1) { set %infochoise special window }
  elseif ($did(5).state == 1) { set %infochoise server status window }
  elseif ($did(6).state == 1) { set %infochoise active window }
  elseif ($did(7).state == 1) { set %infochoise both active and special windows }

  if ($did(8).state == 1) { set %showbotlist ON }
  else { set %showbotlist off }
  if ($did(9).state == 1) { set %debugxdccinfo on }
  else { set %debugxdccinfo off }
  /xdccmanualwizard4
}
;-------------------------------------------------------------------------
on *:dialog:xdccmanualwizard3:sclick:2: { 
  /outputxdccinfo 14Wizard manual configuration setup 4aborted14 during window settings, using default values for remaining settings. 
  /outputxdccinfo 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
alias xdccmanualwizard3 { /dialog -m xdccmanualwizard3 xdccmanualwizard3 }
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------





;-------------------------------------------------------------------------
; /dialog xdccmanualwizard4:
; 13 editboxes, 4 buttons, 1 ok button, 1 cancel button.
; 4th manual setup window. Sets the filename and directory settings, and 
; the DCCALLOW and Channel Key options. 
;-------------------------------------------------------------------------
dialog xdccmanualwizard4 {
  title "XDCC Script Manual Wizard: Filename Settings"
  size -1 -1 500 500
  button "Finish", 1, 127 465 120 25, ok
  button "Cancel", 2, 253 465 120 25, cancel
  box "File settings:", 3, 5 5 490 110

  button "Choose Script Directory", 17, 175 50 230 25
  button "Add Channel Key", 18, 20 140 110 25
  button "Add DCCALLOW Net", 19, 255 140 105 25
  button "Delete Channel Key", 20, 135 140 110 25
  button "Delete DCCALLOW Net", 21, 365 140 120 25

  text "Default XDCC dir: XDCC\", 23, 27 55 135 15
  box "Miscelaneous Options: ", 37, 5 117 490 330
  list 38, 17 170 230 280
  list 39, 255 170 230 280
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------

;-------------------------------------------------------------------------
; Remote identifiers for /dialog xdccmanualwizard4:
; sclick 17: Sets future XDCC dir (does not set %XDCCdir yet). 
; sclick 18: Add channel/key pair to the list (doesn't write to file yet).
; sclick 19: Add network to the list (doesn't write to file yet).
; sclick 20: Del channel/key pair from list.
; sclick 21: Del network from list.
; sclick 2: Cancel.
; sclick 1: Sets filename variables, directory variable, and adds DCCALLOW
;           networks to $dccallownetworkfile, and channel/key pairs to
;           $chankeyfile. Wizard is finished.
;-------------------------------------------------------------------------
on *:dialog:xdccmanualwizard4:sclick:17: { set %wiznewdir $sdir($xdccdir,Choose main XDCC script directory:) }
;-------------------------------------------------------------------------
on *:dialog:xdccmanualwizard4:sclick:18: {
  set %chankey $?="Please input network, channel and required key separated by a space (E.g.: EFnet #channel 1337key)."
  if ($numtok(%chankey, 32) >= 3) { /did -a xdccmanualwizard4 38 %chankey }
}
;-------------------------------------------------------------------------
on *:dialog:xdccmanualwizard4:sclick:19: {
  set %networks $?="Please input networks that should support DCCALLOW options, separated by a space (E.g.: DALnet EFnet irchighway). Do not add networks that don't use DCCALLOW."
  set %i 1
  while (%i <= $numtok(%networks, 32)) { 
    /did -a xdccmanualwizard4 39 $gettok(%networks, %i, 32) 
    inc %i
  }
}
;-------------------------------------------------------------------------
on *:dialog:xdccmanualwizard4:sclick:20: { /did -d xdccmanualwizard4 38 $did(38).sel }
;-------------------------------------------------------------------------
on *:dialog:xdccmanualwizard4:sclick:21: { /did -d xdccmanualwizard4 39 $did(39).sel }
;-------------------------------------------------------------------------
on *:dialog:xdccmanualwizard4:sclick:1: { 
  if (%wiznewdir != $null && $isdir(%newdir)) {
    set %XDCCdir $replxdccdir(%wiznewdir) 
    unset %wiznewdir
  }

  set %i 1
  while (%i <= $did(38).lines) {
    if ($read($chankeyfile,snt,$gettok($did(38,%i).text, 1, 32))) { /write -l $+ $readn $chankeyfile $did(38,%i).text }
    else { /write -a $chankeyfile $did(38,%i).text }
    inc %i
  }
  set %i 1
  while (%i <= $did(39).lines) {
    if ($exists($dccallownetworkfile) && $read($dccallownetworkfile,wnt,$did(39,%i).text)) { /write -l $+ $readn $dccallownetworkfile $did(39,%i).text }
    else { /write -a $dccallownetworkfile $did(39,%i).text }
    inc %i
  }
  /outputxdccinfo 14Wizard manual configuration setup successfully completed. You may need to restart your IRC to get all features to fully function. 
  /outputxdccinfo 
}
;-------------------------------------------------------------------------
on *:dialog:xdccmanualwizard4:sclick:2: { 
  /outputxdccinfo 14Wizard manual configuration setup 4aborted14 during directory & special chan/network settings, using default values for remaining settings. 
  /outputxdccinfo 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
alias xdccmanualwizard4 { /dialog -m xdccmanualwizard4 xdccmanualwizard4 }
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------









;-------------------------------------------------------------------------
; /dialog xdccbrowsebots:
; Contains lists for networks, channels, bots, packs, xdcc queues and the
; botqueue, and manipulates the queues. This way you can browse all known
; XDCC packs.
;-------------------------------------------------------------------------
dialog xdccbrowsebots {
  title "VisualQ"
  size -1 -1 800 590
  button "OK", 1, 350 555 100 25, ok
  button "Add To Queue >>", 30, 395 360 130 25
  button "<< Remove From Queue", 31, 540 360 130 25
  button "Add Bot Queue >>", 32, 110 355 130 25
  button "Remove Bot Queue <<", 33, 110 390 130 25
  button "MOVE UP", 34, 305 360 80 25
  button "MOVE DOWN", 35, 680 360 80 25

  list 3, 5 45 100 180, sort
  list 4, 5 240 100 310, sort
  list 5, 110 45 130 310, sort, extsel
  list 8, 110 422 130 140, extsel
  list 6, 245 45 550 310, extsel
  list 7, 245 395 550 165, extsel
  text "Choose Network:", 20, 15 25 90 15
  text "Choose Channel:", 21, 15 225 90 15
  text "Choose Bot:", 22, 135 25 100 15
  text "Packs:", 23, 255 25 80 15
  text "Queues:", 24, 255 370 45 15  
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------


;-------------------------------------------------------------------------
; Remote identifiers for /dialog xdccbrowsebots:
; init: Adds all networks to the first list in the browser, and all 
;       botqueues to the sixth list.
; sclick 1: OK, Frees all hash tables and exists program.
; sclick 3: Adds all channels for selected network to the second list in 
;           the browser.
; sclick 4: Adds all nicks for selected channel to the third list in the 
;           browser.
; sclick 5: Adds all packs for selected bot/network to the fourth list in 
;           the browser, and all queues for that pair to the fifth list.
; dclick 8: Adds all packs for selected bot in botqueue to the fourth list 
;           in the browser, and all queues for that bot to the fifth list.
; sclick 30: Adds all selected packs to selected bot's queue and reloads 
;            the queue list.
; sclick 31: Removes all selected queues from selected bot's queue and 
;            reloads the queue list.
; sclick 32: Adds the selected bot to the botqueue and reloads the bot 
;            queue list.
; sclick 33: Removes the selected bot from the botqueue and reloads the 
;            bot queue list.
; sclick 34: Moves the selected xdcc queue item up in the queue.
; sclick 35: Moves the selected xdcc queue item down in the queue.
;-------------------------------------------------------------------------
on 1:dialog:xdccbrowsebots:init:*:{
  set %u 1
  while (%u <= $hget(xdccBrowserHash,0).item) {
    if ($gettok($hget(xdccBrowserHash,network),%u,32) != $null) { /did -a xdccbrowsebots 3 $gettok($hget(xdccBrowserHash,network),%u,32) }
    inc %u 
  }
  set %u 1
  while (%u <= $lines($botqueuefile)) {
    if ($read($botqueuefile, nt, %u) != $null) { /did -a xdccbrowsebots 8 $read($botqueuefile, nt, %u) }
    inc %u 
  }
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
on 1:dialog:xdccbrowsebots:sclick:3:{
  set %additems $hget(xdccBrowserHash,$did(xdccbrowsebots,3).seltext)
  /did -r xdccbrowsebots 4,5,6,7
  set %u 1
  while (%u <= $numtok(%additems,32)) {
    if ($gettok(%additems,%u,32) != $null) { //did -a xdccbrowsebots 4 $gettok(%additems,%u,32) }
    inc %u 
  }
  unset %additems
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
on 1:dialog:xdccbrowsebots:sclick:4:{
  set %additems $remove($did(xdccbrowsebots,4).seltext,$chr(35))
  /did -r xdccbrowsebots 5,6,7
  set %u 1
  while (%u <= $hget(%additems,0).item) {
    if ($hget(%additems,%u).item != $null) { //did -a xdccbrowsebots 5 $hget(%additems,%u).item }
    inc %u 
  }
  unset %additems
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
on 1:dialog:xdccbrowsebots:sclick:5:{
  set %additems $getpfffilenm($did(xdccbrowsebots,3).seltext, $did(xdccbrowsebots,5).seltext)
  /did -r xdccbrowsebots 6
  set %u 1
  while (%u <= $lines(%additems)) {
    if ($strip($read(%additems,%u),burc) != $null) { //did -a xdccbrowsebots 6 $strip($read(%additems,%u),burc) }
    inc %u 
  }
  unset %additems

  set %additems $getpfffilenm($did(xdccbrowsebots,3).seltext, $did(xdccbrowsebots,5).seltext)
  /did -r xdccbrowsebots 7
  set %u 1
  while (%u <= $lines(%additems)) {
    if ($strip($read(%additems,snt,$read($replace(%additems,.pff,.q),nt,%u)),burc) != $null) { //did -a xdccbrowsebots 7 $read($replace(%additems,.pff,.q),nt,%u) $strip($read(%additems,snt,$read($replace(%additems,.pff,.q),nt,%u)),burc) }
    inc %u 
  }
  unset %additems
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
on 1:dialog:xdccbrowsebots:dclick:8:{
  set %botnetwork $triggerHash.network($did(xdccbrowsebots,8).seltext)
  set %botchan $triggerHash.getChan(%botnetwork, $did(xdccbrowsebots,8).seltext)

  /did -c xdccbrowsebots 3 $didwm(xdccbrowsebots,3,%botnetwork)
  set %additems $hget(xdccBrowserHash,$did(xdccbrowsebots,3).seltext)
  /did -r xdccbrowsebots 4
  set %u 1
  while (%u <= $numtok(%additems,32)) {
    if ($gettok(%additems,%u,32) != $null) { //did -a xdccbrowsebots 4 $gettok(%additems,%u,32) }
    inc %u 
  }
  unset %additems

  /did -c xdccbrowsebots 4 $didwm(xdccbrowsebots,4,%botchan)

  set %additems $remove(%botchan,$chr(35))
  /did -r xdccbrowsebots 5
  set %u 1
  while (%u <= $hget(%additems).size) {
    if ($hget(%additems,%u).item != $null) { //did -a xdccbrowsebots 5 $hget(%additems,%u).item }
    inc %u 
  }
  unset %additems

  /did -c xdccbrowsebots 5 $didwm(xdccbrowsebots,5,$did(xdccbrowsebots,8).seltext)

  set %additems $getpfffilenm(%botnetwork, $did(xdccbrowsebots,8).seltext)
  /did -r xdccbrowsebots 6
  set %u 1
  while (%u <= $lines(%additems)) {
    if ($read(%additems,%u) != $null) { //did -a xdccbrowsebots 6 $strip($read(%additems,%u),burc) }
    inc %u 
  }
  unset %additems

  set %additems $getpfffilenm(%botnetwork, $did(xdccbrowsebots,8).seltext)
  /did -r xdccbrowsebots 7
  set %u 1
  while (%u <= $lines($replace(%additems,.pff,.q))) {
    if ($read(%additems,snt,$read($replace(%additems,.pff,.q),nt,%u)) != $null) { //did -a xdccbrowsebots 7 $read($replace(%additems,.pff,.q),nt,%u) $strip($read(%additems,snt,$read($replace(%additems,.pff,.q),nt,%u)),burc) }
    inc %u 
  }
  unset %additems
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
on 1:dialog:xdccbrowsebots:sclick:30:{
  set %botnetwork $did(xdccbrowsebots,3).seltext
  set %botnick $did(xdccbrowsebots,5).seltext

  set %u 1
  while (%u <= $did(xdccbrowsebots,6,0).sel) {
    if (!$read($getqfilenm(%botnetwork, %botnick), wnt, $gettok($did(xdccbrowsebots,6,$did(xdccbrowsebots,6,%u).sel).text,1,32))) { //write -a $getqfilenm(%botnetwork, %botnick) $gettok($did(xdccbrowsebots,6,$did(xdccbrowsebots,6,%u).sel).text,1,32) }
    inc %u
  }
  /did -r xdccbrowsebots 7
  set %u 1
  while (%u <= $lines($getqfilenm(%botnetwork, %botnick))) {
    if ($read($getpfffilenm(%botnetwork, %botnick),snt,$read($getqfilenm(%botnetwork, %botnick),nt,%u)) != $null) { //did -a xdccbrowsebots 7 $read($getqfilenm(%botnetwork, %botnick),nt,%u) $strip($read($getpfffilenm(%botnetwork, %botnick),snt,$read($getqfilenm(%botnetwork, %botnick),nt,%u)),burc) }
    inc %u 
  }
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
on 1:dialog:xdccbrowsebots:sclick:31:{
  set %botnetwork $did(xdccbrowsebots,3).seltext
  set %botnick $did(xdccbrowsebots,5).seltext

  set %u 1
  while (%u <= $did(xdccbrowsebots,7,0).sel) {
    if ($read($getqfilenm(%botnetwork, %botnick), wnt, $gettok($did(xdccbrowsebots,7,$did(xdccbrowsebots,7, %u).sel).text,1,32))) { /write -dw" $+ $gettok($did(xdccbrowsebots,7,$did(xdccbrowsebots,7,%u).sel).text,1,32) $+ " $getqfilenm(%botnetwork, %botnick) }
    inc %u
  }
  if ($lines($getqfilenm(%botnetwork, %botnick)) < 1) { .remove $getqfilenm(%botnetwork, %botnick) }

  /did -r xdccbrowsebots 7
  set %u 1
  while (%u <= $lines($getqfilenm(%botnetwork, %botnick))) {
    if ($read($getpfffilenm(%botnetwork, %botnick),snt,$read($getqfilenm(%botnetwork, %botnick),nt,%u)) != $null) { //did -a xdccbrowsebots 7 $read($getqfilenm(%botnetwork, %botnick),nt,%u) $strip($read($getpfffilenm(%botnetwork, %botnick),snt,$read($getqfilenm(%botnetwork, %botnick),nt,%u)),burc) }
    inc %u 
  }
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
on 1:dialog:xdccbrowsebots:sclick:32:{
  set %u 1
  while (%u <= $did(xdccbrowsebots,5,0).sel) {
    if (!$read($botqueuefile, wnt, $did(xdccbrowsebots,5,$did(xdccbrowsebots,5,%u).sel).text)) { //write -a $botqueuefile $did(xdccbrowsebots,5,$did(xdccbrowsebots,5,%u).sel).text }
    inc %u
  }
  /did -r xdccbrowsebots 8
  set %u 1
  while (%u <= $lines($botqueuefile)) {
    if ($read($botqueuefile, nt, %u) != $null) { /did -a xdccbrowsebots 8 $read($botqueuefile, nt, %u) }
    inc %u 
  }
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
on 1:dialog:xdccbrowsebots:sclick:33:{
  set %u 1
  while (%u <= $did(xdccbrowsebots,8,0).sel) {
    if ($read($botqueuefile, wnt, $gettok($did(xdccbrowsebots,8,$did(xdccbrowsebots,8, %u).sel).text,1,32))) { /write -dw" $+ $gettok($did(xdccbrowsebots,8,$did(xdccbrowsebots,8,%u).sel).text,1,32) $+ " $botqueuefile }
    inc %u
  }
  if ($lines($botqueuefile) < 1) { .remove $botqueuefile }

  /did -r xdccbrowsebots 8
  set %u 1
  while (%u <= $lines($botqueuefile)) {
    if ($read($botqueuefile, nt, %u) != $null) { /did -a xdccbrowsebots 8 $read($botqueuefile, nt, %u) }
    inc %u 
  }
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
on 1:dialog:xdccbrowsebots:sclick:34:{
  if ($did(xdccbrowsebots,7,$calc($did(xdccbrowsebots,7,1).sel - 1)).text != $null) {
    set %botnetwork $did(xdccbrowsebots,3).seltext
    set %botnick $did(xdccbrowsebots,5).seltext
    set %aline $did(xdccbrowsebots,7,$calc($did(xdccbrowsebots,7,1).sel - 1)).text
    set %bline $did(xdccbrowsebots,7,1).seltext 
    //write -l $+ $calc($did(xdccbrowsebots,7,1).sel - 1) $getqfilenm(%botnetwork, %botnick) $gettok(%bline,1,32)
    //write -l $+ $did(xdccbrowsebots,7,1).sel $getqfilenm(%botnetwork, %botnick) $gettok(%aline,1,32)
    /did -r xdccbrowsebots 7
    set %u 1
    while (%u <= $lines($getqfilenm(%botnetwork, %botnick))) {
      if ($read($getpfffilenm(%botnetwork, %botnick),snt,$read($getqfilenm(%botnetwork, %botnick),nt,%u)) != $null) { //did -a xdccbrowsebots 7 $read($getqfilenm(%botnetwork, %botnick),nt,%u) $strip($read($getpfffilenm(%botnetwork, %botnick),snt,$read($getqfilenm(%botnetwork, %botnick),nt,%u)),burc) }
      inc %u 
    }
    /did -c xdccbrowsebots 7 $didwm(xdccbrowsebots,7,%bline)
  }
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
on 1:dialog:xdccbrowsebots:sclick:35:{
  if ($did(xdccbrowsebots,7,$calc($did(xdccbrowsebots,7,1).sel + 1)).text) {
    set %botnetwork $did(xdccbrowsebots,3).seltext
    set %botnick $did(xdccbrowsebots,5).seltext
    set %aline $did(xdccbrowsebots,7,$calc($did(xdccbrowsebots,7,1).sel + 1)).text
    set %bline $did(xdccbrowsebots,7,1).seltext 
    //write -l $+ $calc($did(xdccbrowsebots,7,1).sel + 1) $getqfilenm(%botnetwork, %botnick) $gettok(%bline,1,32)
    //write -l $+ $did(xdccbrowsebots,7,1).sel $getqfilenm(%botnetwork, %botnick) $gettok(%aline,1,32)

    /did -r xdccbrowsebots 7
    set %u 1
    while (%u <= $lines($getqfilenm(%botnetwork, %botnick))) {
      if ($read($getpfffilenm(%botnetwork, %botnick),snt,$read($getqfilenm(%botnetwork, %botnick),nt,%u)) != $null) { //did -a xdccbrowsebots 7 $read($getqfilenm(%botnetwork, %botnick),nt,%u) $strip($read($getpfffilenm(%botnetwork, %botnick),snt,$read($getqfilenm(%botnetwork, %botnick),nt,%u)),burc) }
      inc %u 
    }
    /did -c xdccbrowsebots 7 $didwm(xdccbrowsebots,7,%bline)
  }
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
on 1:dialog:xdccbrowsebots:sclick:1:{
  set %u 1
  /hfree xdccBrowserHash 
  while (%u <= $triggerHash.items) {
    if ($hget($remove($triggerHash.item.chan(%u),$chr(35))) != $null) { //hfree $remove($triggerHash.item.chan(%u),$chr(35)) }
    inc %u
  }
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------


;-------------------------------------------------------------------------
; /xdccBrowserHash:
; Creates a number of hash tables (one for every channel, containing 
; appropriate nicknames, plus one that lists networks and their 
; appropriate channels).
;-------------------------------------------------------------------------
alias xdccBrowserHash {
  set %u 1
  while (%u <= $triggerHash.items) {
    if ($triggerHash.item.network(%u) !isin $hget(xdccBrowserHash,network)) { /hadd -m xdccBrowserHash network $hget(xdccBrowserHash,network) $triggerHash.item.network(%u) }
    if ($triggerHash.item.chan(%u) !isin $hget(xdccBrowserHash,$triggerHash.item.network(%u))) { /hadd -m xdccBrowserHash $triggerHash.item.network(%u) $hget(xdccBrowserHash,$triggerHash.item.network(%u)) $triggerHash.item.chan(%u) }
    if ($hget($remove($triggerHash.item.chan(%u),$chr(35)), $triggerHash.item.nick(%u)) == $null) { //hadd -m $remove($triggerHash.item.chan(%u),$chr(35)) $triggerHash.item.nick(%u) $triggerHash.item.nick(%u) $getpfffilenm($triggerHash.item.network(%u),$triggerHash.item.nick(%u)) }
    inc %u
  }
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------


;-------------------------------------------------------------------------
; /xdccbrowsebots:
; Creates the necessary hash tables and starts the VisualQ pack browser.
;-------------------------------------------------------------------------
alias xdccbrowsebots { 
  /xdccBrowserHash
  /dialog -m xdccbrowsebots xdccbrowsebots 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------




;-------------------------------------------------------------------------
; /pleasewaitdialog & /closewaitdialog:
; Opens/closes the please wait dialog box.
;-------------------------------------------------------------------------
alias pleasewaitdialog /dialog -m pleasewaitdialog pleasewaitdialog
alias closewaitdialog /dialog -c pleasewaitdialog
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------

;-------------------------------------------------------------------------
; /dialog pleasewaitdialog:
; Shows a small dialog with a "please wait" request.
;-------------------------------------------------------------------------
dialog pleasewaitdialog {
  title "Please wait (this can take a few minutes)..."
  size -1 -1 300 50
  text "Please wait, this can take a few minutes...", 1, 50 20 300 15
}
;-------------------------------------------------------------------------








;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
;----------------------------Aliases Section------------------------------
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------










;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
; /makexdccwindow:
; Makes a status window to print xdcc info to.
;-------------------------------------------------------------------------
alias makexdccwindow {
  if (%showbotlist == ON) {
    if (!$window(@XDCC_Info)) {
      window -ak0mnel17S @XDCC_Info
      font %xdccfont

      set %i 1
      var %llen = $triggerHash.items
      while (%i <= %llen) {
        if ($me ison $triggerHash.item.chan(%i) && $triggerHash.item.nick(%i) ison $triggerHash.item.chan(%i)) { aline -lnc7 @XDCC_Info $triggerHash.item.nick(%i) }
        elseif ($me ison $triggerHash.item.chan(%i)) { aline -lnc10 @XDCC_Info $triggerHash.item.nick(%i) }
        else { aline -lnc14 @XDCC_Info $triggerHash.item.nick(%i) }
        inc %i
      }
      unset %llen
    }
    window -S @XDCC_Info
  }
  else {
    if (!$window(@XDCC_Info)) {
      window -ak0mne @XDCC_Info
      font %xdccfont
    }
  }
  ; unset %i
}
;-------------------------------------------------------------------------


;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
; /debuglog $1-:
; $1-: Information on XDCC script workings and xdcc pack finds.
; Outputs $1- to a log file.
;-------------------------------------------------------------------------
alias debuglog {
  if (%debugxdccinfo == on) {
    /write -a $xdccdebugfile $asctime([HH:nn:ss]) $1-
  }
}
alias debuglog.sessionstart {
  /debuglog 
  /debuglog ----------------------------------------------------------------
  /debuglog ----------- Session start $date(<dddd mmmm d yyyy>) -----------
  /debuglog ----------------------------------------------------------------
  /debuglog 
}
alias debuglog.sessionend {
  /debuglog 
  /debuglog ****************************************************************
  /debuglog *********** Session end $date(<dddd mmmm d yyyy>) **************
  /debuglog ****************************************************************
  /debuglog 
}
;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
; /outputxdccinfo $1-:
; $1-: Information on XDCC script workings and xdcc pack finds.
; Outputs $1- to the prefered window.
;-------------------------------------------------------------------------
alias outputxdccinfo {
  if (%infochoise == special window) {
    /makexdccwindow
    //aline -hp @XDCC_Info $asctime([HH:nn:ss]) $1-
  }
  elseif (%infochoise == active window) { //echo -a $1- }
  elseif (%infochoise == server status window) { //echo -s $1- }
  elseif (%infochoise == both active and special windows ) { 
    /makexdccwindow
    //aline -hp @XDCC_Info $asctime([HH:nn:ss]) $1-
    //echo -a $1- 
  }
  /debuglog $scriptline $+ : ALIAS OUTPUTXDCCINFO: $1-
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------





;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
; Sets the font and fontsize for the separate output window.
;-------------------------------------------------------------------------
alias setxdccfont {
  /makexdccwindow
  window -a @XDCC_Info
  font
  if ($window(@XDCC_Info).fontbold) { %xdccfont = -b @XDCC_Info $window(@XDCC_Info).fontsize $window(@XDCC_Info).font }
  else { %xdccfont = @XDCC_Info $window(@XDCC_Info).fontsize $window(@XDCC_Info).font }

  /outputxdccinfo 14XDCC Info window font set to %xdccfont $+ .
  /outputxdccinfo 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------






;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
; /checknewversion:
; Checks for new versions with me, the author.
;-------------------------------------------------------------------------
alias checknewversion {
  .enable #groupcheckversion
  .notice %scriptauthor Script versioncheck %xdccscriptversion 
  .timerxdcccheckversion 1 90 .disable #groupcheckversion
  /outputxdccinfo 14Checking for new XDCC script version... (Timeout 90 seconds).
  /outputxdccinfo 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------



;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
; /versioninfo:
; Short info about the script.
;-------------------------------------------------------------------------
alias versioninfo {
  /outputxdccinfo 5Name: XDCC Autoresume/Autoqueue Stealth Script
  /outputxdccinfo 5File: $script
  /outputxdccinfo 5Version: %xdccscriptversion
  /outputxdccinfo 5Author: %scriptauthor
  /outputxdccinfo 5Release Date: 13/03/2004
  /outputxdccinfo 5Installation date: %installdate
  /outputxdccinfo 5XDCC directory used: $xdccdir
  /xdccgetstats
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------



;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
; /xdccgetstats:
; Retrieve the number of known bots and packs.
;-------------------------------------------------------------------------
alias xdccgetstats {
  set %i 1
  set %numofpackslisted 0
  var %llen = $triggerHash.items
  while (%i <= %llen) {
    set %botpacknum $lines($getpfffilenm($triggerHash.item.network(%i), $triggerHash.item.nick(%i)))
    set %numofpackslisted $calc(%numofpackslisted + %botpacknum)
    inc %i
  }
  unset %llen
  /outputxdccinfo 13 $+ %numofpackslisted 5packs listed on7 $triggerHash.items 5XDCC Bots known in library.
  /outputxdccinfo 5 $+ %filesgettotal files received and %filessenttotal files sent since last script version install ( $+ %installdate $+ ).

  /outputxdccinfo 
  ; unset %i %numofpackslisted %botpacknum
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------






;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
; /movexdccdir & /movexdccdir $1:
; $1: New directory.
; This moves all files to the newly entered directory and then removes the 
; old copies of those files, and the old directory. It also sets the 
; %XDCCdir variable.
;-------------------------------------------------------------------------
alias movexdccdir { movexdccdir2 $sdir($xdccdir, Select directory to be used for XDCC script) }
;-------------------------------------------------------------------------
alias movexdccdir2 {
  /pleasewaitdialog  
  set %tempname $1

  if (%tempname != $null && $replxdccdir(%tempname) != $xdccdir) {
    set %newdirname $replxdccdir(%tempname)
    if ($chr(92) isin %newdirname) {
      if ($chr(47) !isin %newdirname && $isdir($remove(%newdirname,$gettok(%newdirname, $numtok(%newdirname,92),92)))) {
        .mkdir %newdirname
      }
      else {
        /outputxdccinfo 4Creating directory failed:14 Cannot created nested directory, " $+ $chr(92) $+ " or " $+ $chr(47) $+ " in input:2 %newdirname $+ . 
      }
    }
    elseif ($chr(47) isin %newdirname) {
      if ($chr(92) !isin %newdirname && $isdir($remove(%newdirname,$gettok(%newdirname, $numtok(%newdirname,47),47)))) {
        .mkdir %newdirname
      }
      else {
        /outputxdccinfo 4Creating directory failed:14 Cannot created nested directory, " $+ $chr(47) $+ " or " $+ $chr(92) $+ " in input:2 %newdirname $+ . 
      }
    }
    else {
      .mkdir %newdirname
    }
    if ($isdir(%newdirname)) {
      set %i 1
      set %olddirname $XDCCdir
      /outputxdccinfo 2Directory %newdirname 14created succesfully. Starting file transfer, please wait5...

      while ($findfile(%olddirname,*,%i,1)) {
        .copy -o $findfile(%olddirname,*,%i,1) %newdirname $+ \ $+ $nopath($findfile(%olddirname,*,%i,1))
        inc %i
      }
      /outputxdccinfo 3Copied14 %i files from %olddirname to %newdirname $+ , deleting old files...

      set %XDCCdir %newdirname
      set %j 1
      while ($findfile(%olddirname,*,%j,1)) {
        if ($exists(%newdirname $+ \ $+ $nopath($findfile(%olddirname,*,%j,1)))) {
          .remove $findfile(%olddirname,*,%j,1)
        }
        else { 
          /outputxdccinfo 4Not deleting old file:14 File does not exist, %newdirname $+ \ $+ $nopath($findfile(%olddirname,*,%j,1)) $+ .
          inc %j
        }
      }
      /outputxdccinfo 4Removed14 $calc($calc(%i - %j) + 1) files from %olddirname $+ , deleting old directory %olddirname $+ ...

      if ($findfile(%olddirname,*,0) == 0) {
        rmdir %olddirname
        /outputxdccinfo 14Directory 4Deleted14, files 3moved14. New directory name is now2 %newdirname $+ .
      }
      else { /outputxdccinfo 14Directory 4Could not be deleted14 because it is not empty (Possible cause: New dir is nested in old dir?). Files 3moved14. New working directory name is now2 %newdirname $+ . }
    }
    else { /outputxdccinfo 4ERROR:14 Directory creation failed ( $+ %newdirname $+ ). }
  }
  else { /outputxdccinfo 4ERROR:14 No name entered, new directory is the same as old directory or directory renaming cancelled. }

  /outputxdccinfo 
  /closewaitdialog
  ; unset %i %j %olddirname %newdirname %tempname 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------



;-------------------------------------------------------------------------
; /timeoff $1 $2
; $1: Botnick.
; $2: Botnetwork.
; Stops requests for bots that appear to already have an item queued.
;-------------------------------------------------------------------------
alias timeoff {
  .timerxdccautoresume $+ $1 $+ ? off
  .timerxdccautoresume $+ $2 $+ $1 $+ ? off
  .timerxdccstartbotq $+ $1 $+ ? off
  .timerxdccstartq $+ $1 $+ ? off
  .timerxdccnonewconnect $+ $1 $+ ? off
  .timerxdccjoin $+ $1 $+ * off
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------




;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
; /triggercapture $1 $2 $3 $4 $5-
; $1: $network.
; $2: $nick.
; $3: $chan.
; $4: triggerscheme number.
; $5-: trigger (%xdccfilegetcommand).
; This alias is called from text triggers that respond to text patterns 
; that appear to be XDCC trigger ads.
; The triggers are written to $triggerHash together with bot nick and
; network.
;-------------------------------------------------------------------------
alias triggercapture {
  if ($5- != $null) {
    if ($triggerHash.exists($1, $2) == $null) {
      /triggerHash.add $1 $2 $3 $4 default $5-
      if (%showbotlist == ON) { /aline -lnc7 @XDCC_Info $2 }
      /outputxdccinfo 4 $+ $triggerHash.items $+ : Added "3 $+ $1 7 $+ $2 $+ 12 $3 ||5 $5- $+ " to $triggerHash 14(Trigger Scheme $4 $+ ).
      /outputxdccinfo 
    }
    elseif ($triggerHash.getTrigger($1, $2) != $5-) {
      if ($3 !isin $triggerHash.getChans($1, $2)) {
        if ($triggerHash.getPsnr($1, $2) != $null) { /triggerHash.add $1 $2 $triggerHash.getChans($1, $2) $+  $+ $3 $4 $triggerHash.getPsnr($1, $2) $5- }
        else { /triggerHash.add $1 $2 $triggerHash.getChans($1, $2) $+  $+ $3 $4 default $5- }
      }
      else {
        if ($triggerHash.getPsnr($1, $2) != $null) { /triggerHash.add $1 $2 $3 $4 $triggerHash.getPsnr($1, $2) $5- }
        else { /triggerHash.add $1 $2 $3 $4 default $5- }
      }
      /outputxdccinfo Updated trigger for "3 $+ $1 7 $+ $2 $+ 12 $3 ||5 $5- $+ " 14(Trigger Scheme $4 $+ ).
      /outputxdccinfo 
    }
    elseif ($3 !isin $triggerHash.getChans($1, $2)) {
      if ($triggerHash.getChans($1, $2) != $null && $triggerHash.getChans($1, $2) != |UNKNOWN|) {
        if ($triggerHash.getPsnr($1, $2) != $null) { /triggerHash.add $1 $2 $triggerHash.getChans($1, $2) $+  $+ $3 $4 $triggerHash.getPsnr($1, $2) $5- }
        else { /triggerHash.add $1 $2 $triggerHash.getChans($1, $2) $+  $+ $3 $4 default $5- }
      }
      else {
        if ($triggerHash.getPsnr($1, $2) != $null) { /triggerHash.add $1 $2 $3 $4 $triggerHash.getPsnr($1, $2) $5- }
        else { /triggerHash.add $1 $2 $3 $4 default $5- }
      }
      /outputxdccinfo Updated channel for "3 $+ $1 7 $+ $2 $+ 12 $triggerHash.getChans($1, $2) ||5 $5- $+ " 14(Trigger Scheme $4 $+ ).
      /outputxdccinfo 
    } 
    elseif ($triggerHash.getTsnr($1, $2) != $4) {
      if ($3 !isin $triggerHash.getChans($1, $2)) {
        if ($triggerHash.getPsnr($1, $2) != $null) { /triggerHash.add $1 $2 $triggerHash.getChans($1, $2) $+  $+ $3 $4 $triggerHash.getPsnr($1, $2) $5- }
        else { /triggerHash.add $1 $2 $triggerHash.getChans($1, $2) $+  $+ $3 $4 default $5- }
      }
      else {
        if ($triggerHash.getPsnr($1, $2) != $null) { /triggerHash.add $1 $2 $3 $4 $triggerHash.getPsnr($1, $2) $5- }
        else { /triggerHash.add $1 $2 $3 $4 default $5- }
      }
    }
  }
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------




#grouppackcapture on
;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
; /packcapture $1 $2 $3 $4 $5-:
; $1: $network.
; $2: $nick.
; $3: $chan.
; $4: Packscheme number.
; $5: Packnumber token number (mostly 1).
; $6-: Text Pack description input.
; This alias is called from text triggers that respond to text patterns 
; that appear to be XDCC pack listings.
; The pack listings are written to a specific file for each bot, with
; a NETWORK¦BOTNICK.pff filename scheme (the same is used for queue 
; <*.q> files). 
;-------------------------------------------------------------------------
alias packcapture {
  if ($triggerHash.exists($1, $2) != $null) {
    ;/debuglog ALIAS PACKCAPTURE: $1-
    set %packnum $int($remove($strip($gettok($6-,$5,32),burc),$chr(35),[,],$chr(41),$chr(40),$chr(46)))
    if (%packnum isnum && %packnum > 0) { 
      /matchwishlistpack $2 $1 $3 $6-
      if (%packnum == 1) { 
        if ($exists($getpfffilenm($1, $2))) {
          if ($timer(packcapturetest $+ $2) == $null) {
            .copy -o $getpfffilenm($1, $2) $getoldfilenm($1, $2)
            .remove $getpfffilenm($1, $2) 
          }
          else { .timerpackcapturetest $+ $2 off }
          if (%comparepacks == on) {
            .timerpackcapturetest $+ $2 1 %packchangechecktime /comparepackfiles $getpfffilenm($1, $2) $getoldfilenm($1, $2)
          }
        }
        else { 
          if (%comparepacks == on) {
            .timerpackcapturetest $+ $2 1 %packchangechecktime /comparepackfiles $getpfffilenm($1, $2) $getpfffilenm($1, $2) 
          }
          /outputxdccinfo 13First pack capture 14just started for bot3 $1 $+ ¦7 $+ $2 $+ 14 (Bot is using Pack Scheme $4 $+ ). 
          /outputxdccinfo 
        }
      }
      elseif (%comparepacks == on) {
        if ($timer(packcapturetest $+ $2) == $null && $exists($getpfffilenm($1, $2))) { .copy -o $getpfffilenm($1, $2) $getoldfilenm($1, $2) }
        else { .timerpackcapturetest $+ $2 off }
        .timerpackcapturetest $+ $2 1 %packchangechecktime /comparepackfiles $getpfffilenm($1, $2) $getoldfilenm($1, $2)
      }

      if ($triggerHash.getPsnr($network, $nick) != $4 && $4 != default) { /triggerHash.updatePackSchemeNr $1 $2 $4 }   

      if ($4 == default) {
        if ($3 !isin $6-) { //write -a $getpfffilenm($1, $2) %packnum $strip($6-, burc) $asctime(14[dd/mm/yy]) }
        else { 
          /outputxdccinfo 4ERROR:12 $3 in packname while using default packscheme? %packnum $strip($6-, burc) $+ . 
          /debuglog $scriptline $+ : ALIAS PACKCAPTURE: 4ERROR:12 $3 in packname while using default packscheme? %packnum $strip($6-, burc) $+ . 
        }
      }
      else { 
        if ($exists($getpfffilenm($network, $nick))) { set %k $lines($getpfffilenm($network, $nick)) }
        else { set %k 0 }
        var %llen = $calc(%packnum - 1)
        if (%k < %llen) {
          while (%k < %llen) {
            inc %k
            //write -a $getpfffilenm($network, $nick) %k Unknown Pack $chr(35) $+ %k
          }
        }
        //write -l $+ %packnum $getpfffilenm($network, $nick) %packnum $strip($6-, burc) $asctime(14[dd/mm/yy]) 
      }
    }
  }
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
#grouppackcapture end





;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
; /cleanxdcclib:
; Should remove xdcc library entries older than %liblimitdate days.
;-------------------------------------------------------------------------
alias cleanxdcclib {
  /outputxdccinfo 4Cleaning XDCC library, please wait (this can take a while)5...
  set %h 0
  set %i 1
  set %j 0
  set %l 0  
  set %expirationtime $calc($ctime - $calc(3600 * 24 * %liblimitdate))

  while ($findfile($xdccdir,*.pff,%i) && %h < 1000000000) {
    set %currentfile $findfile($xdccdir,*.pff,%i)
    if ($file(%currentfile).mtime < %expirationtime) {
      if (!$exists($replace(%currentfile,.pff,.q))) {
        .remove %currentfile
        /triggerHash.del $remove($gettok(%currentfile,1,166),.pff) $remove($gettok(%currentfile,2,166),.pff)
        dec %i
        inc %j
      }
      else { inc %l }
    }
    inc %i
    inc %h
  }

  set %h 0
  set %i 1
  set %k 0
  set %m 0
  while ($findfile($xdccdir,*.pff.old,%i) && %h < 1000000000) {
    set %currentfile $findfile($xdccdir,*.pff.old,%i)

    if ($timer(packcapturetest $+ $gettok($remove(%currentfile,.pff.old),2,166)) == $null) {
      .remove %currentfile
      dec %i
      inc %k
    }
    else { inc %m }

    inc %i
    inc %h
  }

  /outputxdccinfo 4Removed %j 14.pff files older than %liblimitdate days ( $+ $calc(3600 * 24 * %liblimitdate) secs) and %k 14.old files from library. %l 14.pff files were not removed because they had a queue file and %m 14.old files were not removed because a pack capture test was pending.
  /outputxdccinfo 
  ; unset %h %i %j %k %l %m %n %currentfile %expirationtime
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------





;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
; /removebot:
; $1: botnick.
; $2: botnetwork.
; This removes a bot from the trigger file and autoresume files, and 
; deletes it's pack and queue files. Uses one yes/no querybox.
;-------------------------------------------------------------------------
alias removebot {
  if ($triggerHash.exists($2, $1) != $null) {
    if ($?!="This will delete all files and entries related to $1 $2 $+ , are you sure you want to do this?") {
      .remove $getpfffilenm($2, $1)
      .remove $getoldfilenm($2, $1)
      .remove $getqfilenm($2, $1)
      /triggerhash.del $2 $1

      if ($read($xdccsinprogress, wnt, $1 *)) { .write -ds $+ $1 $xdccsinprogress }
      if ($read($networkfile($2), wn, * $1 *)) { 
        if ($lines($networkfile($2)) <= 1) { .remove $networkfile($2) }
        else { /write -dw"* $1 *" $networkfile($2) }
      } 

      /outputxdccinfo 4Bot3 $2 $+ ¦7 $+ $1 4removed from triggerfile. Packs and queues removed. Autoresume entries removed.
    }
    else { /outputxdccinfo 14Bot7 $1 14 not removed from triggerfile, remove operation cancelled. } 
  }
  else { 
    set %nicklistline $fline(@XDCC_Info,$1,1,1)
    /outputxdccinfo Removing line %nicklistline $1 from the nicklistbox.
    //dline -l @XDCC_Info %nicklistline $+ - $+ %nicklistline
    /outputxdccinfo Bot not listed (3 $+ $2 $+ ¦7 $+ $1 $+ ). 
  }

  /outputxdccinfo 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------






;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
; /findpack $1-:
; $1-: search string of one or more (partial) words.
; Finds all packs with the listed words in specific order and echoes them 
; to the chosen window(s).
;-------------------------------------------------------------------------
alias findpack {
  /outputxdccinfo 5Starting new searchstring pack search for "10 $+ $1- $+ 5": 4....
  set %i 1
  set %foundpacks 1
  while (%i <= $triggerHash.items) {
    set %j 1
    set %botnetwork $triggerHash.item.network(%i)
    set %botnick $triggerHash.item.nick(%i)
    set %botchan $triggerHash.item.chan(%i)
    set %botpacksnum $lines($getpfffilenm(%botnetwork, %botnick))

    while (%j <= %botpacksnum) {
      set %matchpack $read($getpfffilenm(%botnetwork, %botnick), %j)
      if (* $+ $replace($1-,$chr(32),*) $+ * iswm $strip(%matchpack,burc)) {
        /outputxdccinfo 10Match found:4 %foundpacks $+ 3 %botnetwork $+ 12 %botchan $+ 7 %botnick $+  $replace(%matchpack, $1-, 12 $+ $1- $+ )
        inc %foundpacks
      }
      inc %j
    }
    inc %i
  }
  dec %foundpacks
  if (%foundpacks == 0) { /outputxdccinfo 5No matches found for "10 $+ $1- $+ 5" (Searched $triggerHash.items XDCC Bots) (N.B.: 10The packfinder is sensitive to word order5). }
  elseif (%foundpacks == 1) { /outputxdccinfo 5 $+ %foundpacks match found for "10 $+ $1- $+ 5" (4Caution:5 information in the library may be outdated). }
  else { /outputxdccinfo 5 $+ %foundpacks matches found for "10 $+ $1- $+ 5" (4Caution:5 information in the library may be outdated). } 

  /outputxdccinfo 
  ; unset %i %j %botpacksnum %matchpack %foundpacks
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------



;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
; /botpacks $1 $2:
; $1: botnetwork.
; $2: botnick.
; Finds all packs for that bot on that network and echoes them to the 
; chosen window(s).
;-------------------------------------------------------------------------
alias botpacks {
  /outputxdccinfo 5Starting new bot packs search for7 $2 5on3 $1 $+ 5: 4....
  if ($exists($getpfffilenm($1, $2))) {
    set %j 1

    /outputxdccinfo 5Searching bot7 $2 5on network3 $1 5( $+ $getpfffilenm($1, $2) $+ ).
    while (%j <= $lines($getpfffilenm($1, $2))) {
      /outputxdccinfo 10Match found:4 %j $+ 3 $1 $+ 7 $2 $+  $read($getpfffilenm($1, $2), %j)
      inc %j 
    }

    dec %j
    if (%j == 0) { /outputxdccinfo 5No matches found for3 $1 7 $+ $2- 5(Note: The script needs to catch the bot's ad before it can search the bot). }
    elseif (%j == 1) { /outputxdccinfo 5 $+ %j match found for3 $1 7 $+ $2- 5(4Caution:5 information in the library may be outdated). }
    else { /outputxdccinfo 5 $+ %j matches found for3 $1 7 $+ $2- 5(4Caution:5 information in the library may be outdated). } 
  }
  else { /outputxdccinfo 5No matches found for3 $1 7 $+ $2- 5(Note: The script needs to catch the bot's ad before it can search the bot). }

  /outputxdccinfo 
  ; unset %j
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------


;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
; /chanpacks $1 $2:
; $1: botnetwork.
; $2: botchan.
; Finds all packs for all bots on that chan on that network and echoes 
; them to the chosen window(s). Uses one yes/no querybox.
;-------------------------------------------------------------------------
alias chanpacks {
  if ($?!="List all packs for channel $2 $+ ? (Warning: The listing for an entire channel can be huge)") {
    set %i 1
    set %foundpacks 1

    /outputxdccinfo 5Starting new channel packs search for channel12 $2 5on network3 $1 $+ 5: 4....

    while (%i <= $triggerHash.items) {
      set %botnick $triggerHash.item.nick(%i)
      set %botchan $triggerHash.item.chan(%i)
      set %botnetwork $triggerHash.item.network(%i)
      if (%botnetwork %botchan == $1 $2 && $exists($getpfffilenm($1, %botnick))) {
        set %j 1
        while (%j <= $lines($getpfffilenm($1, %botnick))) {
          /outputxdccinfo 10Match found:4 %foundpacks $+ 3 $1 $+ 7 %botnick $+  $read($getpfffilenm($1, %botnick), %j)
          inc %foundpacks
          inc %j
        }
      }
      inc %i
    }

    dec %foundpacks 
    if (%foundpacks == 0) { /outputxdccinfo 5No matches found for3 $1 12 $+ $2- 5(Note: The script needs to catch the bot's ad before it can search the bot) }
    elseif (%foundpacks == 1) { /outputxdccinfo 5 $+ %foundpacks match found for3 $1 12 $+ $2- 5(4Caution:5 information in the library may be outdated) }
    else { /outputxdccinfo 5 $+ %foundpacks matches found for3 $1 12 $+ $2- 5(4Caution:5 information in the library may be outdated) } 

    /outputxdccinfo   
    ; unset %i %j %botnick %botchan %botnetwork %foundpacks
  }
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------


;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
; /networkpacks $1:
; $1: botnetwork.
; Finds all packs for all bots on that network and echoes them to the 
; chosen window(s). Uses one yes/no querybox.
;-------------------------------------------------------------------------
alias networkpacks {
  if ($?!="List all packs for network $1 $+ ? (Warning: The listing for an entire network can be huge)") {
    set %i 1
    set %foundpacks 1

    /outputxdccinfo 5Starting new network packs search for network3 $1 $+ 5: 4....

    while (%i <= $triggerHash.items) {
      if ($triggerHash.item.network(%i) == $1) {
        set %botnick $triggerHash.item.nick(%i)
        if ($exists($getpfffilenm($1, %botnick))) {
          set %j 1
          while (%j <= $lines($getpfffilenm($1, %botnick))) {
            /outputxdccinfo 10Match found:4 %foundpacks $+ 3 $1 $+ 7 %botnick $+  $read($getpfffilenm($1, %botnick), %j)
            inc %foundpacks
            inc %j
          }
        }
      }
      inc %i
    }
    dec %foundpacks

    if (%foundpacks == 0) { /outputxdccinfo 5No matches found for3 $1- 5(Note: The script needs to catch the bot's ad before it can search the bot). }
    elseif (%foundpacks == 1) { /outputxdccinfo 5 $+ %foundpacks match found for3 $1- 5(4Caution:5 information in the library may be outdated). }
    else { /outputxdccinfo 5 $+ %foundpacks matches found for3 $1- 5(4Caution:5 information in the library may be outdated). } 

    /outputxdccinfo 
    ; unset %i %j %botnick %foundpacks
  }
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------





;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
; /showqueues:
; Shows all queues for all bots in number list form.
;-------------------------------------------------------------------------
alias showqueues {
  set %i 1
  set %k 0
  /outputxdccinfo 5You have the following queue files listed:

  while ($findfile($xdccdir,*.q,%i) && %i <= 10000) {
    set %filenm $nopath($findfile($xdccdir,*.q,%i))
    set %j 0
    set %queue $null
    while (%j <= $lines($xdccdir $+ \ $+ %filenm)) {
      set %queue %queue $read($xdccdir $+ \ $+ %filenm, %j)
      inc %j
      inc %k
    }
    dec %k
    if ($calc(%j - 1) == 1) { /outputxdccinfo 10Queue exists for bot3 $replace($gettok(%filenm,1,166),.q,) $+ ¦7 $+ $replace($gettok(%filenm,2,166),.q,) ( $+ $calc(%j - 1) item):13 %queue }
    else { /outputxdccinfo 10Queue exists for bot3 $replace($gettok(%filenm,1,166),.q,) $+ ¦7 $+ $replace($gettok(%filenm,2,166),.q,) ( $+ $calc(%j - 1) items):13 %queue }
    inc %i
  }

  dec %i
  if (%i == 1) {
    if (%k == 1) { /outputxdccinfo 5 $+ %i queue listed ( $+ %k item). }
    else { /outputxdccinfo 5 $+ %i queue listed ( $+ %k items). }
  }
  else {
    if (%k == 1) { /outputxdccinfo 5 $+ %i queues listed ( $+ %k item). }
    else { /outputxdccinfo 5 $+ %i queues listed ( $+ %k items). }
  }
  /outputxdccinfo 
  ; unset %i %j %k %filenm %queue
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------


;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
; /showdetailedqueues:
; Shows all queues for all bots in number form and in detailed pack 
; description form.
;-------------------------------------------------------------------------
alias showdetailedqueues {
  set %i 1
  set %k 0
  /outputxdccinfo 5You have the following queue files listed:

  while ($findfile($xdccdir,*.q,%i) && %i <= 10000) {
    set %filenm $nopath($findfile($xdccdir,*.q,%i))
    set %j 0
    set %queue $null
    while (%j <= $lines($xdccdir $+ \ $+ %filenm)) {
      set %queue %queue $read($xdccdir $+ \ $+ %filenm, %j)
      inc %j
      inc %k
    }
    dec %k

    if (%j == 2) { /outputxdccinfo 10Queue exists for bot3 $replace($gettok(%filenm,1,166),.q,) $+ ¦7 $+ $replace($gettok(%filenm,2,166),.q,) ( $+ $calc(%j - 1) item):13 %queue }
    else { /outputxdccinfo 10Queue exists for bot3 $replace($gettok(%filenm,1,166),.q,) $+ ¦7 $+ $replace($gettok(%filenm,2,166),.q,) ( $+ $calc(%j - 1) items):13 %queue }

    set %j 0
    while (%j < $lines($xdccdir $+ \ $+ %filenm)) {
      /outputxdccinfo 4 $calc(%j + 1) 3 $+ $replace($gettok(%filenm,1,166),.q,) $+ ¦7 $+ $replace($gettok(%filenm,2,166),.q,) $+ :13 $read($xdccdir $+ \ $+ $replace(%filenm,.q,.pff), snt, $gettok($read($xdccdir $+ \ $+ %filenm,%j),1,32))
      inc %j
    }
    inc %i
  }

  if (%i == 2) {
    if (%k == 1) { /outputxdccinfo 5 $+ $calc(%i - 1) queue listed ( $+ %k item). }
    else { /outputxdccinfo 5 $+ $calc(%i - 1) queue listed ( $+ %k items). }
  }
  else {
    if (%k == 1) { /outputxdccinfo 5 $+ $calc(%i - 1) queues listed ( $+ %k item). }
    else { /outputxdccinfo 5 $+ $calc(%i - 1) queues listed ( $+ %k items). }
  }

  /outputxdccinfo 
  ; unset %i %j %k %filenm %queue
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------



;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
; /showdetailedqueue:
; Shows all queues for a single bot in number form and in pack description
; form. Uses one popup editbox if no nickname is selected.
;-------------------------------------------------------------------------
alias showdetailedqueue {
  set %k 0
  set %j 0

  if ($1 == $null) { set %botnick $$?="Enter the bot's nick (Ex: XDCC|DCC01)." }
  else { set %botnick $1 }
  set %botnetwork $triggerHash.network(%botnick)

  if (%botnetwork != $null) {
    /outputxdccinfo Bot7 %botnick in database at network3 %botnetwork $+ .

    set %filenm $getqfilenm(%botnetwork, %botnick)
    if ($exists(%filenm) && $lines(%filenm) > 0) {
      /outputxdccinfo 5You have the following queue listed for3 %botnetwork $+ ¦7 $+ %botnick $+ :

      while (%j < $lines(%filenm)) {
        /outputxdccinfo 4   $calc(%j + 1) 3 $+ %botnetwork $+ ¦7 $+ %botnick $+ :13 $read($replace(%filenm,.q,.pff), snt, $gettok($read(%filenm,%j),1,32))
        inc %j
      }

      if (%j == 1) { /outputxdccinfo 5Queue listed ( $+ %j item). }
      else { /outputxdccinfo 5Queue listed ( $+ %j items). }
    }
    else { /outputxdccinfo 5No queue file for3 %botnetwork $+ ¦7 $+ %botnick $+ . }
  }
  else { /outputxdccinfo Bot not listed (7 $+ %botnick $+ ). }

  /outputxdccinfo 
  ; unset %j %botnick %botnetwork
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------




;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
; /viewbotqueues:
; Lists the current Bot Queue file.
;-------------------------------------------------------------------------
alias viewbotqueues {
  /outputxdccinfo 5Starting listing of Bot Queues...
  set %i 0
  if ($exists($tempbotqueuefile) && $lines($tempbotqueuefile) > 0) {
    while (%i < $lines($tempbotqueuefile)) {
      inc %i
      /outputxdccinfo 4 %i 10Temporary Priority Bot Queue 10found:7 $read($tempbotqueuefile, %i)
    }

    if (%i == 1) { /outputxdccinfo 5 $+ %i Temporary Priority Bot Queue found. }
    else { /outputxdccinfo 5 $+ %i Temporary Priority Bot Queues found. }
  } 
  else { /outputxdccinfo 5No Temporary Priority Bot Queue found. }


  set %i 0
  if ($exists($botqueuefile) && $lines($botqueuefile) > 0) {
    while (%i < $lines($botqueuefile)) {
      inc %i
      /outputxdccinfo 4 %i 10Bot Queue 10found:7 $read($botqueuefile, %i)
    }

    if (%i == 1) { /outputxdccinfo 5 $+ %i Bot Queue found. }
    else { /outputxdccinfo 5 $+ %i Bot Queues found. }
  } 
  else { /outputxdccinfo 5No Bot Queue found. }

  /outputxdccinfo 
  ; unset %i
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------




;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
; /getxdccsending:
; Lists all bots and packs listed in the active transfer files. These are 
; the bots that the script will auto resume or process the queue from.
;-------------------------------------------------------------------------
alias getxdccsending {
  set %i 0
  /outputxdccinfo 5Listing currently active bots (sends, queues and offline bots)...
  if ($exists($xdccsinprogress) && $lines($xdccsinprogress) > 0) {
    while (%i < $lines($xdccsinprogress)) {
      inc %i
      if ($get($gettok($read($xdccsinprogress, %i),1,32)).status == active) {
        /outputxdccinfo 10Bot7 $gettok($read($xdccsinprogress, %i),1,32) 10is active 14(transfering:4 $get($gettok($read($xdccsinprogress, %i),1,32)).secs 14secs,4 $get($gettok($read($xdccsinprogress, %i),1,32)).cps 14cps,4 $get($gettok($read($xdccsinprogress, %i),1,32)).rcvd 14bytes rcvd,4 $get($gettok($read($xdccsinprogress, %i),1,32)).pc $+ $chr(37) 14done,4 $round($calc($averagexdcccps($gettok($read($xdccsinprogress, %i),1,32)) / 1024), 2) $+ 14 kbps avg,4 $estimatedxdcccompltime($gettok($read($xdccsinprogress, %i),1,32)) $+ 14 left)10 for pack number13 $gettok($read($xdccsinprogress, %i),2,32)
      }
      else {
        /outputxdccinfo 10Bot7 $gettok($read($xdccsinprogress, %i),1,32) 10is active 14(queued, failed, or offline and waiting)10 for pack number13 $gettok($read($xdccsinprogress, %i),2,32)
      }      
    }
  }
  set %sendsactive %i
  if ($exists($networksendfile) && $lines($networksendfile) > 0) {
    set %i 1
    while (%i <= $lines($networksendfile)) {
      if ($exists($networkfile($read($networksendfile,%i))) && $lines($networkfile($read($networksendfile,%i))) > 0) {
        set %j 0
        set %l 0
        while (%j < $lines($networkfile($read($networksendfile,%i)))) {
          inc %j
          if (!$read($xdccsinprogress, snt, $gettok($read($networkfile($read($networksendfile,%i)), %j),2,32))) {
            inc %l
            if ($get($gettok($read($networkfile($read($networksendfile,%i)), %j),2,32)).status == active) {
              /outputxdccinfo 10Bot7 $gettok($read($networkfile($read($networksendfile,%i)), %j),2,32) 10is active 14(transfering:4 $get($gettok($read($networkfile($read($networksendfile,%i)), %j),2,32)).secs 14secs,4 $get($gettok($read($networkfile($read($networksendfile,%i)), %j),2,32)).cps 14cps,4 $get($gettok($read($networkfile($read($networksendfile,%i)), %j),2,32)).rcvd 14bytes rcvd,4 $get($gettok($read($networkfile($read($networksendfile,%i)), %j),2,32)).pc $+ $chr(37) 14done)10 for pack number13 $&
                $replace($gettok($read($networkfile($read($networksendfile,%i)), %j),$numtok($networkfile($read($networksendfile,%i)), %j),32),$chr(35),)
            }
            else {
              /outputxdccinfo 10Bot7 $gettok($read($networkfile($read($networksendfile,%i)), %j),2,32) 10is active 14(queued, failed, or offline and waiting)10 for pack number13 $replace($gettok($read($networkfile($read($networksendfile,%i)), %j),$numtok($read($networkfile($read($networksendfile,%i)), %j),32),32),$chr(35),)
            }   
          }
        }
        set %sendsactive $calc(%sendsactive + %l)
      }
      inc %i
    }
  }
  if (%sendsactive == 0) { /outputxdccinfo 5There are no active or waiting transfers at this time. }
  elseif (%sendsactive == 1) { /outputxdccinfo 5Found %sendsactive entry in sends file(s). }
  else { /outputxdccinfo 5Found %sendsactive entries in sends file(s). }
  /outputxdccinfo 
  ; unset %i %j %sendsactive
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------







;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
; /getsessiongets:
; Shows all completed downloads since the last IRC start (including those 
; not handled by this script).
;-------------------------------------------------------------------------
alias getsessiongets {
  set %i 1
  if ($lines($xdccsessiongetfile) < 1) {
    /outputxdccinfo 5No files received so far this session.
  }
  else {
    /outputxdccinfo 5So far you have received the following files since the last IRC restart ( $+ $lines($xdccsessiongetfile) $+ )5:
    while (%i <= $lines($xdccsessiongetfile)) {
      /outputxdccinfo %i $read($xdccsessiongetfile, %i)
      inc %i
    }
  }
  /outputxdccinfo 5 $+ $lines($xdccsessiongetfile) packs in total (including non-XDCC sends).
  /outputxdccinfo 
  ; unset %i
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------


;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
; /getsessionsends:
; Shows all completed uploads since the last IRC start (including those 
; not handled by this script).
;-------------------------------------------------------------------------
alias getsessionsends {
  set %i 1
  if ($lines($xdccsessionsendfile) < 1) {
    /outputxdccinfo 5No files sent so far this session.
  }
  else {
    /outputxdccinfo 5So far you have sent the following files since the last IRC restart ( $+ $lines($xdccsessionsendfile) $+ )5:
    while (%i <= $lines($xdccsessionsendfile)) {
      /outputxdccinfo %i $read($xdccsessionsendfile, %i)
      inc %i
    }
  }
  /outputxdccinfo 5 $+ $lines($xdccsessionsendfile) sends in total.
  /outputxdccinfo 
  ; unset %i
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------





;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
; /addtoq $1 $2 $3:
; $1: xdcc bot nick.
; $2: network.
; $3: packnr.
; No longer used. Queues one pack at a time on a specific bot on a specific
; network.
;-------------------------------------------------------------------------
alias addtoq { //write -a $getqfilenm($2, $1) $3 }
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------

;-------------------------------------------------------------------------
;**********************************DONE***********************************
;------------------------------------------------------------------------- 
; /removefromq $1 $2 $3:
; $1: xdcc bot nick.
; $2: network.
; $3: packnr.
; Removes one pack at a time from queue of a specific bot on a specific 
; network.
;-------------------------------------------------------------------------
alias removefromq { 
  if ($read($getqfilenm($2, $1), wnt, $3)) {
    if ($lines($getqfilenm($2, $1)) <= 1) {
      .remove $getqfilenm($2, $1)
      /outputxdccinfo Packnumber $3 6dequeued for3 $2 $+ ¦7 $+ $1 ( $+ $3 $+ ) (Either you removed the queue entry or a transfer was completed). No more packs queued for $1 $+ .
    }
    else {
      //write -dw $+ $3 $getqfilenm($2, $1) 
      /outputxdccinfo Packnumber13 $3 6dequeued for3 $2 $+ ¦7 $+ $1 ( $+ $3 $+ ) (Either you removed the queue entry or a transfer was completed).
    }
  }
  else { /outputxdccinfo 6Dequeue: No such packnumber queued for3 $2 $+ ¦7 $+ $1 ( $+ $3 $+ ). }

  if ($read($xdccsinprogress, wnt,$1 $3)) {
    /write -dw" $+ $1 $3 $+ " $xdccsinprogress
  }
  if ($read($networkfile($2), wnt, * $1 * $+ $3)) {
    /write -dw" $+ * $1 * $+ $3 $+ " $networkfile($2)
  }
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------



;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
; /addrequest $1 & /addrequest2 $1:
; $1: xdcc bot nick.
; Queues multiple packs at a time on a specific bot on a specific network.
; Can be triggered from the channel and nicklist menus. Uses 1 or 2 popup 
; editboxes.
;-------------------------------------------------------------------------
alias addrequest { 
  if ($1 == $null) { set %botnick $$?="Enter the bot's nick (Ex: XDCC|DCC01)." }
  else { set %botnick $1 }
  set %botnetwork $triggerHash.network(%botnick)

  if (%botnetwork != $null && %botnick != $null) {
    if ($triggerHash.exists(%botnetwork, %botnick) != $null) {
      /outputxdccinfo Bot7 %botnick in database at network3 %botnetwork $+ .
      set %packnum $$?="Enter packnumbers for %botnetwork $+ ¦ $+ %botnick (Ex: 1 3 5-8 10)."
      set %i 1
      while (%i <= $numtok(%packnum,32)) {
        if ($gettok(%packnum, %i, 32) isnum) {
          if ($exists($getpfffilenm(%botnetwork, %botnick))) {
            if (!$read($getqfilenm(%botnetwork, %botnick), wnt, $gettok(%packnum, %i, 32))) {
              if ($read($getpfffilenm(%botnetwork, %botnick), snt, $gettok(%packnum, %i, 32))) {
                /write -a $getqfilenm(%botnetwork, %botnick) $gettok(%packnum, %i, 32)
              }
              else { 
                if ($?!="Pack $gettok(%packnum, %i, 32) does not appear to be a valid pack for %botnetwork $+ ¦ $+ %botnick $+ . Add anyway (WARNING: Requesting invalid packs may get you banned)? (NOTE: if you're sure this pack is valid, this message could be caused when the script is updating the bot's packfile.)") {
                  /write -a $getqfilenm(%botnetwork, %botnick) $gettok(%packnum, %i, 32)
                  /outputxdccinfo 4Warning: Pack13 $gettok(%packnum, %i, 32) is not a valid pack for3 %botnetwork $+ ¦7 $+ %botnick (Pack added anyway). 
                }
                else { /outputxdccinfo Pack13 $gettok(%packnum, %i, 32) does not appear to be a valid pack for3 %botnetwork $+ ¦7 $+ %botnick (Pack not added). }
              }
            }
            else { /outputxdccinfo Pack13 $gettok(%packnum, %i, 32) already in queue for3 %botnetwork $+ ¦7 $+ %botnick (Pack not added). }
          }
          else {
            if (!$read($getqfilenm(%botnetwork, %botnick), wnt, $gettok(%packnum, %i, 32))) {
              /write -a $getqfilenm(%botnetwork, %botnick) $gettok(%packnum, %i, 32)
              /outputxdccinfo 4Warning: No pack file for3 %botnetwork $+ ¦7 $+ %botnick $+ , unable to validate pack13 $gettok(%packnum, %i, 32) (Pack added).
            }
            else { /outputxdccinfo Pack13 $gettok(%packnum, %i, 32) already in queue for3 %botnetwork $+ ¦7 $+ %botnick $+ . Pack not added. }
          }
        }
        elseif (- isin $gettok(%packnum, %i, 32) && $gettok($gettok(%packnum, %i, 32), 1, 45) isnum && $gettok($gettok(%packnum, %i, 32), 2, 45) isnum) {
          set %j $gettok($gettok(%packnum, %i, 32), 1, 45)
          while (%j <= $gettok($gettok(%packnum, %i, 32), 2, 45)) {
            if ($exists($getpfffilenm(%botnetwork, %botnick))) {
              if (!$read($getqfilenm(%botnetwork, %botnick), wnt, %j)) {
                if ($read($getpfffilenm(%botnetwork, %botnick), snt, %j)) {
                  /write -a $getqfilenm(%botnetwork, %botnick) %j
                }
                else { 
                  if ($?!="Pack %j is not a valid pack for %botnetwork $+ ¦ $+ %botnick $+ . Add anyway (WARNING: Requesting invalid packs may get you banned)? (NOTE: if you're sure this pack is valid, this message could be caused when the script is updating the bot's packfile.)") {
                    /write -a $getqfilenm(%botnetwork, %botnick) %j
                    /outputxdccinfo 4Warning: Pack13 %j does not appear to be a valid pack for3 %botnetwork $+ ¦7 $+ %botnick (Pack added anyway). 
                  }
                  else {
                    /outputxdccinfo Pack13 %j does not appear to be a valid pack for3 %botnetwork $+ ¦7 $+ %botnick (Pack not added). 
                  }
                }
              }
              else { /outputxdccinfo Pack13 %j already in queue for3 %botnetwork $+ ¦7 $+ %botnick (Pack not added). }
            }
            else {
              if (!$read($getqfilenm(%botnetwork, %botnick), wnt, %j)) {
                /write -a $getqfilenm(%botnetwork, %botnick) %j
                /outputxdccinfo 4Warning: No pack file for3 %botnetwork $+ ¦7 $+ %botnick $+ , unable to validate pack13 %j (Pack added).
              }
              else { /outputxdccinfo Pack13 %j already in queue for3 %botnetwork $+ ¦7 $+ %botnick $+ . }
            }
            inc %j
          }
        }
        else { /outputxdccinfo Invalid input ( $+ $gettok(%packnum, %i, 32) $+ ). }
        inc %i
      }
      /outputxdccinfo 6Queued up packs on bot3 %botnetwork $+ ¦7 $+ %botnick (Pack Number(s):13 %packnum $+ ).
      ; unset %i %j %packnum
    }
    else {
      set %trigger $$?="Unknown bot or not a bot ( $+ %botnick $+ ). Enter bot's EXACT trigger or cancel and wait for bot ads to reach the script's awareness. (Ex.: /msg %botnick xdcc send $chr(35) $+ ). $crlf $+ $crlf $+ WARNING: It is not adviced to enter a trigger manually. If you enter the wrong trigger the script will not correct this and you will have to remove the bot to remove the error. Proceed ONLY if you know how to enter the bot trigger correctly! Proceed ONLY if %botnick is an XDCC bot!"  
      if (%trigger != $null) {
        if ($?!="Add %botnetwork %botnick ¦ %trigger to $triggerHash $+ , IS THIS INFORMATION CORRECT AND 100 $+ $chr(37) CERTAIN?") {
          if ($chan != $null) { %botchan = $chan }
          else { %botchan = unknown }
          /triggerHash.add %botnetwork %botnick %botchan default default %trigger
          /outputxdccinfo Added "4 $+ %botnetwork 7 $+ %botnick ||5 %trigger $+ " to $triggerHash $+ .
          /addrequest2 %botnick
          ; unset %botchan %trigger
        }
        else { /outputxdccinfo Unknown Bot or not a bot (7 $+ %botnick $+ ). Manual entry aborted. }
      }
      else { /outputxdccinfo Unknown Bot or not a bot (7 $+ %botnick $+ ). Manual entry aborted. }
    } 
  }
  else { /outputxdccinfo Bot not listed (7 $+ %botnick $+ ). }

  /outputxdccinfo 
  ; unset %botnick %botnetwork
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
alias addrequest2 { /addrequest $1- }
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------




;-------------------------------------------------------------------------
;**********************************DONE***********************************
;------------------------------------------------------------------------- 
; /removerequest $1:
; $1: xdcc bot nick.
; Dequeues multiple packs at a time from a specific bot on a specific 
; network. Can be triggered from the channel and nicklist menus. Uses 1 or 
; 2 popup editboxes.
;-------------------------------------------------------------------------
alias removerequest { 
  if ($1 == $null) { set %botnick $$?="Enter the bot's nick (Ex: XDCC|DCC01)." }
  else { set %botnick $1 }
  set %botnetwork $triggerHash.network(%botnick)

  if (%botnetwork != $null && %botnick != $null) {
    if ($exists($getqfilenm(%botnetwork, %botnick))) {
      /outputxdccinfo Bot7 %botnick in database at network3 %botnetwork $+ .
      set %packnum $$?="Enter packnumbers to remove (Ex: 1 3 5-8 10)."
      set %i 1
      if ($?!="Remove pack(s) %packnum from bot %botnick queue $+ ?") {
        while (%i <= $numtok(%packnum,32)) {
          if ($gettok(%packnum, %i, 32) isnum) {
            if ($read($getqfilenm(%botnetwork, %botnick), wnt, $gettok(%packnum, %i, 32))) {
              /removefromq %botnick %botnetwork $gettok(%packnum, %i, 32)
            }
            else { /outputxdccinfo Pack13 $gettok(%packnum, %i, 32) not in queue for3 %botnetwork $+ ¦7 $+ %botnick (Pack not removed). }
          }
          elseif (- isin $gettok(%packnum, %i, 32) && $gettok($gettok(%packnum, %i, 32), 1, 45) isnum && $gettok($gettok(%packnum, %i, 32), 2, 45) isnum) {
            set %j $gettok($gettok(%packnum, %i, 32), 1, 45)
            while (%j <= $gettok($gettok(%packnum, %i, 32), 2, 45)) {
              if ($read($getqfilenm(%botnetwork, %botnick), wnt, %j)) {
                /removefromq %botnick %botnetwork %j
              }
              else { /outputxdccinfo Pack13 %j not in queue for3 %botnetwork $+ ¦7 $+ %botnick (Pack not removed). }

              inc %j
            }
            ; unset %j
          }
          else { /outputxdccinfo Invalid input ( $+ $gettok(%packnum, %i, 32) $+ ). }
          inc %i
        }
        /outputxdccinfo 6Removed packs from bot3 %botnetwork $+ ¦7 $+ %botnick (Pack Number(s):13 %packnum $+ ).
      }
      else { /outputxdccinfo Remove specific pack operation aborted. }
      ; unset %i %packnum
    }
    else { /outputxdccinfo No queue file for bot3 %botnetwork $+ ¦7 $+ %botnick $+ . }
  }
  else { /outputxdccinfo Bot7 $nick not listed. }

  /outputxdccinfo 
  ; unset %botnick %botnetwork
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------



;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
; /clrq $1:
; $1: xdcc bot nick.
; Removes queue file for a specific bot on a specific network.
; Can be triggered from the nicklist menu. Uses 1 popup editbox if no nick
; is selected and one popup yes/no querybox.
;-------------------------------------------------------------------------
alias clrq {
  if ($1 == $null) { set %botnick $$?="Enter the bot's nick (Ex: XDCC|DCC01)." }
  else { set %botnick $1 }
  set %botnetwork $triggerHash.network(%botnick)

  if (%botnetwork != $null) {
    if ($exists($getqfilenm(%botnetwork, %botnick))) {
      if ($?!="Clear XDCC queue for %botnick $+ ?") { 
        .remove $getqfilenm(%botnetwork, %botnick)
        /outputxdccinfo Cleared XDCC request queue for7 %botnick on3 %botnetwork $+ .
      }
    }
    else { /outputxdccinfo No such queue exists (3 $+ %botnetwork $+ ¦7 $+ %botnick $+ ). }

    if ($read($xdccsinprogress, wnt,$1 *)) { /write -dw" $+ $1 *" $xdccsinprogress }
    if ($read($networkfile(%botnetwork), wnt, * $1 *)) { /write -dw"* $1 *" $networkfile(%botnetwork) }
  }
  else { /outputxdccinfo Bot7 %botnick not listed. }


  if ($read($botqueuefile,wnt,$1) && $?!="Remove Bot from Bot Queue File?") { /removebotqueue $1 }
  else { /outputxdccinfo  }
  ; unset %botnick %botnetwork 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------






;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
; /removepackfromallbots $1 $2 $3-:
; $1: $replace($nick, ....).
; $2: $replace($network, ...).
; $3-: $filename.
; Tries to match a completed filename to pack descriptions in the pff file
; entry matching each q file entry. If a match is found, the appropriate 
; pack should be removed from the queue
;-------------------------------------------------------------------------
alias removepackfromallbots {
  set %searchpack $remvallnonum($nopath($3-))
  set %h 0
  set %g 1

  /outputxdccinfo 6Clearing Pack13 %searchpack (3 $+ $2 $+ ¦7 $+ $1 $+ .q) from All Bot Queues...
  while ($findfile($xdccdir,*.q,%g)) {
    set %currentqfile $findfile($xdccdir,*.q,%g)
    if ($nopath(%currentqfile) != $nopath($getqfilenm($2, $1))) {
      set %f 0
      while (%f <= $lines(%currentqfile)) {
        set %ntoks $calc($numtok($strip($read($replace(%currentqfile,.q,.pff), nt, $read(%currentqfile, nt, %f)),burc),32) - 1)
        set %matchpack $remvallnonum($gettok($read($replace(%currentqfile,.q,.pff), nt, $read(%currentqfile, nt, %f)),3- $+ %ntoks,32))

        if (* $+ %searchpack $+ * iswm %matchpack) {
          /outputxdccinfo 3 $+ $gettok($nopath(%currentqfile),1,166) $+ ¦7 $+ $remove($gettok($nopath(%currentqfile),2,166),.q) $+ .q:4 Filename2 %searchpack 4matches pack description13 %matchpack $+ 4, removing pack $gettok($strip($read($replace(%currentqfile,.q,.pff), nt, $read(%currentqfile, nt, %f)),burc),1,32) from queue file.
          .removefromq $gettok($strip($remove($nopath(%currentqfile),.q),burc),2,166) $gettok($strip($remove($nopath(%currentqfile),.q),burc),1,166) $gettok($strip($read($replace(%currentqfile,.q,.pff), nt, $read(%currentqfile, nt, %f)),burc),1,32)
          dec %g
          inc %h
        }

        inc %f
      }
      ; unset %f %ntoks %matchpack
    }
    inc %g
  }

  if (%h == 0) { /outputxdccinfo 5Found no packs in other bot queues matching %searchpack $+ . }
  elseif (%h == 1) { /outputxdccinfo 5Found and removed %h pack in other bot queues matching %searchpack $+ . }
  else { /outputxdccinfo 5Found and removed %h packs in other bot queues matching %searchpack $+ . }

  /outputxdccinfo 
  ; unset %g %h %searchpack
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------





;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
; /startqueue $1-:
; $1: String of one or more individual botnames.
; Starts handeling the queue for one or more given bots, if such queues 
; exist.
;-------------------------------------------------------------------------
alias startqueue {
  if ($1- != $null) { set %xdccnickstring $1- }
  else { set %xdccnickstring $?="Enter XDCC bot nicks to start queue for:" }

  if (%xdccnickstring == $null) { /outputxdccinfo No bots entered. }
  if ($numtok(%xdccnickstring, 32) == 1 || $?!="WARNING: you have entered more than 1 bot to start queues for at the same time. This may result in detection and is not recommended. Proceed?" != $null) {
    set %i 1
    while (%i <= $numtok(%xdccnickstring, 32)) {
      set %botnick $gettok(%xdccnickstring, %i, 32)
      set %botnetwork $triggerHash.network(%botnick)
      set %trigger $triggerHash.getTrigger(%botnetwork, %botnick) $+ $read($getqfilenm(%botnetwork, %botnick), t, 0)

      if (%trigger != $null) {        
        if ($read($autoresumedisablefile, wnt, %botnick $+ ¦ $+ %botnetwork)) {
          /write -dw" $+ %botnick $+ ¦ $+ %botnetwork $+ " $autoresumedisablefile
        }

        if ($exists($getqfilenm(%botnetwork, %botnick))) {
          set %upperbound $calc($numtok(%xdccnickstring, 32) * 30)
          set %j 0
          set %con $null
          while (%con == $null && %j < 1000) {
            if ($scon(%j).network == %botnetwork) { set %con %j }
            inc %j
          }

          if ($numtok(%xdccnickstring, 32) == 1) { 
            set %bt.rand 0 
            /outputxdccinfo 3 $+ %botnetwork $+ : 5Starting queue for bot7 %botnick on3 $scon(%con).network $+ . Single bot, no timer necessary. ( $+ $lines($getqfilenm(%botnetwork, %botnick)) items) ( $+ %trigger $+ ).
          }
          else { 
            set %bt.rand $rand(1,%upperbound)
            /outputxdccinfo 3 $+ %botnetwork $+ : 5Starting queue for bot7 %botnick on3 $scon(%con).network $+ . Multiple bots: Bot on %bt.rand sec timer, ( $+ $lines($getqfilenm(%botnetwork, %botnick)) items) ( $+ %trigger $+ ).
          }

          if ($exists($dccallownetworkfile) && $read($dccallownetworkfile,wnt,%botnetwork)) { /scon %con /DCCALLOW + $+ %botnick }
          if ($exists($alternatedccserverfile) && $read($alternatedccserverfile,snt,%botnick)) { $read($alternatedccserverfile,snt,%botnetwork %botnick) }

          if ($gettok(%trigger, 1, 32) == /msg) { /scon %con .timerxdccstartq $+ %botnick $+ %i 1 %bt.rand /msg $gettok(%trigger, 2-, 32) }
          elseif ($gettok(%trigger, 1, 32) == /ctcp) { /scon %con .timerxdccstartq $+ %botnick $+ %i 1 %bt.rand /ctcp $gettok(%trigger, 2-, 32) }
          elseif ($gettok(%trigger, 1, 32) == /notice) { /scon %con .timerxdccstartq $+ %botnick $+ %i 1%bt.rand /notice $gettok(%trigger, 2-, 32) }
          else { /outputxdccinfo 4ERROR: Unknown trigger type (7 $+ %botnick $+ ). }
          ;          if ($gettok(%trigger, 1, 32) == /msg) { .timerxdccstartq $+ %botnick $+ %i 1 %bt.rand /msg $gettok(%trigger, 2-, 32) }
          ;          elseif ($gettok(%trigger, 1, 32) == /ctcp) { .timerxdccstartq $+ %botnick $+ %i 1 %bt.rand /ctcp $gettok(%trigger, 2-, 32) }
          ;          elseif ($gettok(%trigger, 1, 32) == /notice) { .timerxdccstartq $+ %botnick $+ %i 1 %bt.rand /notice $gettok(%trigger, 2-, 32) }
          ;          else { /outputxdccinfo 4ERROR: Unknown trigger type (7 $+ %botnick $+ ). }
          if ($read($tempbotqueuefile,s,%botnick)) { /write -ds $+ %botnick $tempbotqueuefile }
          if ($read($xdccsinprogress, s, %botnick)) { /write -ds $+ %botnick $xdccsinprogress }  
          if ($read($networkfile(%botnetwork), wn, * %botnick *)) { /write -dw"* %botnick *" $networkfile(%botnetwork) } 
          if (!$read($xdccsinprogress, wnt, %botnick $read($getqfilenm(%botnetwork, %botnick), 0))) {
            //write -a $xdccsinprogress %botnick $read($getqfilenm(%botnetwork, %botnick), 0)
          }
          if ($exists($tempbotqueuefile) && $read($tempbotqueuefile,snt,%botnick)) {
            /write -ds $+ %botnick $tempbotqueuefile
          }
        }
        else { 
          if ($shouldstartmaxbotq != $null) {
            if (%botqueuehandling == on) {
              /removebotqueue $1
              if ($read($tempbotqueuefile,nt,1) != $null) {
                /outputxdccinfo No queue file for3 %botnetwork $+ ¦7 $+ %botnick $+ . Moving to next bot in Temporary Bot Queue file (7 $+ $read($tempbotqueuefile, 1) $+ ).
                /startbotqueues 1
              }
              elseif ($exists($botqueuefile)) {
                set %rand.bt $rand(%minautoqdelay, %maxautoqdelay);

                /outputxdccinfo No queue file for3 %botnetwork $+ ¦7 $+ %botnick $+ . Moving to next bot in Bot Queue file (7 $+ $read($botqueuefile, 1) $+ ).
                .timerxdccstartq $+ $read($botqueuefile, 1) $+ 2 1 3 /startqueue $read($botqueuefile, 1)
              }
              else { 
                /outputxdccinfo No queue file for3 %botnetwork $+ ¦7 $+ %botnick $+ . No Bot Queue file exists. 
              }
            }
            else { /outputxdccinfo No queue file for3 %botnetwork $+ ¦7 $+ %botnick $+ . 4Bot Queue Handling OFF. }
          }   
          else { /outputxdccinfo No queue file for3 %botnetwork $+ ¦7 $+ %botnick $+ . 4Maximum number of simultaneous transfers reached: Not moving to Bot Queue until next incoming transfer completion. }
        }
      }
      else { /outputxdccinfo Unknown bot or not a bot (7 $+ %botnick $+ ). }
      inc %i
    }
    ; unset %i %botnick %botnetwork %trigger %upperbound %bt.rand %rand.bt
  }

  /outputxdccinfo 
  /removebotqueue $1
  ; unset %xdccnickstring
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------


;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
; /stopxdccqueue $1:
; $1: botnick.
; Removes a bot from the currently active transfers files, resulting in a
; deactivated queue for that bot. The pack will not be removed from queue,
; however, and starting the queue for this bot will reactivate the auto 
; resume and auto queue options (if active).
;-------------------------------------------------------------------------
alias stopxdccqueue {
  if ($1 != $null) { %botnick = $1 }
  else { %botnick = $?="Enter bot nick for which to suspend queue processing." }
  set %botnetwork $triggerHash.network(%botnick)

  .timeoff %botnick %botnetwork

  if (%botnick != $null && $?!="Suspend auto re-request and auto queue processing for %botnick $+ ? (NOTE: The current send will not be removed from queue, and features will be reactivated when the queue is manually restarted.)") {
    if ($read($xdccsinprogress, wnt, %botnick *)) {
      /outputxdccinfo 14Found entry for bot7 $1 14in general active sends file, deleting.
      .write -ds $+ %botnick $xdccsinprogress
    }
    else { /outputxdccinfo 14No entry found for bot7 %botnick 14in general active sends file. }

    if (%botnetwork != $null) {
      if ($exists($networkfile(%botnetwork)) && $read($networkfile(%botnetwork),wnt,* %botnick *)) {
        /outputxdccinfo 14Found entry for bot7 %botnick 14on network3 %botnetwork 14active sends file, deleting.
        .write -dw $+ "* %botnick *" $networkfile(%botnetwork)
      }
      else { /outputxdccinfo 14No entry found for bot7 $1 14on network3 %botnetwork 14active sends file. }
    }
    if (!$read($autoresumedisablefile, wnt, %botnick $+ ¦ $+ %botnetwork)) {
      /write -a $autoresumedisablefile %botnick $+ ¦ $+ %botnetwork
    }
    if ($exists($tempbotqueuefile) && $read($tempbotqueuefile,snt,%botnick)) {
      /write -ds $+ %botnick $tempbotqueuefile
    }
    if ($exists($botqueuefile) && $read($botqueuefile,snt,%botnick)) {
      /write -ds $+ %botnick $botqueuefile
    }
    if ($botliston == TRUE) { //cline -lc2 @XDCC_Info $fline(@XDCC_Info,%botnick,1,1) }
    /outputxdccinfo 
  }
  ; unset %botnick %botnetwork
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------



;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
alias haltDownloads {
  /outputxdccinfo 4Halting downloads for7 $1 $+ .
  close -g $1
  if ($get($1).status != active && $botliston == TRUE) { //cline -lc7 @XDCC_Info $fline(@XDCC_Info,$1,1,1) }
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
alias haltUploads {
  /outputxdccinfo 4Halting uploads for7 $1 $+ .
  close -s $1
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------








;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
; /queuefullrerequest $1 $2:
; $1: $network.
; $2: $nick.
; This will react to a msg send by an XDCC bot that it's queue is full, by
; re-requesting the first pack in it's queue (if any).
;-------------------------------------------------------------------------
alias queuefullrerequest {
  if ($exists($getqfilenm($1, $2))) { 
    set %trigger $triggerHash.getTrigger($1, $2) $+ $read($getqfilenm($1, $2), tn, 1)
    set %bt.rand $rand(%minqfulldelay, %maxqfulldelay)

    /outputxdccinfo 13Queue full for bot3 $1 $+ ¦7 $+ $2 $+ , 3auto re-requesting in %bt.rand seconds. (Pack number had to be guessed from queue file and is set to $read($getqfilenm($1, $2), tn, 1) $+ ).
    if ($gettok(%trigger, 1, 32) == /msg) { /timerxdccautoresume $+ $2 $+ 3 1 %bt.rand /msg $gettok(%trigger, 2-, 32) }
    elseif ($gettok(%trigger, 1, 32) == /ctcp) { /timerxdccautoresume $+ $2 $+ 3 1 %bt.rand /ctcp $gettok(%trigger, 2-, 32) }
    elseif ($gettok(%trigger, 1, 32) == /notice) { /timerxdccautoresume $+ $2 $+ 3 1 %bt.rand /notice $gettok(%trigger, 2-, 32) }
    else { /outputxdccinfo 4ERROR: Unknown trigger type ( $+ %trigger $+ ). }

    if ($exists($tempbotqueuefile) && $read($tempbotqueuefile,snt,$2)) {
      /write -ds $+ $2 $tempbotqueuefile
    }
    ; unset %trigger %bt.rand
  }
  else {
    /outputxdccinfo 4ERROR: Can't auto re-request pack for3 $1 $+ ¦7 $+ $2 $+ . Pack number unknown. 
  }
  /outputxdccinfo   
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------







;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
; /addbotqueue $1:
; $1: botnick.
; Adds a bot to the back of the bot queue.
;-------------------------------------------------------------------------
alias addbotqueue {
  set %botnetwork $triggerHash.network($1)
  if (%botnetwork != $null) {
    if (!$read($botqueuefile, w, $1)) {
      /write -a $botqueuefile $1 
      /outputxdccinfo Added7 $1 to the bot queue for network3 %botnetwork in position $lines($botqueuefile) $+ .     
    }
    else {
      /outputxdccinfo Did not add7 $1 to the bot queue. Bot already in queue file. 
    }
  }
  else { /outputxdccinfo Bot7 $1 not listed in bot library. }  

  /outputxdccinfo 
  ; unset %botnetwork
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------


;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
; /removebotqueue $1:
; $1: botnick.
; Removes a specified bot from the bot queue if it is in there.
;-------------------------------------------------------------------------
alias removebotqueue {
  set %botnetwork $triggerHash.network($1)
  if (%botnetwork != $null) {
    if ($exists($botqueuefile) && $read($botqueuefile, w, $1)) {
      if ($lines($botqueuefile) <= 1) { .remove $botqueuefile }
      else { /write -dw $+ $1 $botqueuefile }

      /outputxdccinfo Removed7 $1 from the bot queue for network3 %botnetwork $+ .
      /outputxdccinfo 
    }
  }  
  else { 
    /outputxdccinfo Bot7 $1 not listed in bot library. 
    /outputxdccinfo 
  }  
  ; unset %botnetwork
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------


;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
; /clrbotq:
; Clears the Bot Queue file by deleting it. Uses one yes/no querybox.
;-------------------------------------------------------------------------
alias clrbotq {
  if ($?!="Clear entire Bot Queue file?") {
    if ($botqueuefile) { .remove $botqueuefile }
    /outputxdccinfo 14Cleared all queues for Bot Queue file.
  }
  else { /outputxdccinfo 14Cancelled clearing of Bot Queue file. }
  /outputxdccinfo 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------





;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
; /startbotqueues $1:
; $1: number of botqueues to start.
; This should start processing the queues of the first $1 queued bots.
;-------------------------------------------------------------------------
alias startbotqueues {
  if ($1 != $null && $1 > 0 && $1 isnum) {
    set %botnames $null

    set %j 0
    set %k 1
    while ($read($tempbotqueuefile, nt, 1) != $null && %j < $1 && %k <= $lines($tempbotqueuefile)) {
      if (!$read($autoresumedisablefile, wnt,$gettok($read($tempbotqueuefile, nt, 1),1,32) $+ ¦ $+ *)) {
        inc %j
        set %rand.bt $rand(%minautoqdelay, %maxautoqdelay)
        set %botnames %botnames $+ |7 $gettok($read($tempbotqueuefile, nt, 1),1,32) 14( $+ %rand.bt second delay) |        
        .timerxdccstartbotq $+ $gettok($read($tempbotqueuefile, nt, 1),1,32) $+ %j 1 %rand.bt /startqueue $gettok($read($tempbotqueuefile, 1),1,32)
        if (!$read($xdccsinprogress,snt,$gettok($read($tempbotqueuefile, nt, 1),1,32))) { /write -a $xdccsinprogress $read($tempbotqueuefile, nt, 1) }
        /write -dl1 $tempbotqueuefile
      }
      else {
        /outputxdccinfo 4Cannot start queue for $gettok($read($tempbotqueuefile, nt, 1),1,32) $+ : 5 Autoresume is temporarily disabled for this bot. To restart the bot now, choose Start XDCC Queue in the menu to resume the transfer.
        /outputxdccinfo 
        set %tempbotqstring $read($tempbotqueuefile, nt, 1)
        /write -dl1 $tempbotqueuefile        
        /write -a $tempbotqueuefile %tempbotqstring
        inc %k
      }
    }

    set %i 1
    while (%i <= $calc($1 - %j) && %i <= $lines($botqueuefile)) {
      set %rand.bt $rand(%minautoqdelay, %maxautoqdelay)
      .timerxdccstartbotq $+ $read($botqueuefile, %i) $+ %i 1 %rand.bt /startqueue $read($botqueuefile, %i)
      set %botnames %botnames $+ |7 $read($botqueuefile, %i) 14( $+ %rand.bt second delay) |
      inc %i
    }
    if (%j > 0 || %i > 1) { 
      /outputxdccinfo 14Starting queue processing for first $1 bots listed in Temp Bot Queue or Bot Queue file ( $+ %botnames $+ 14).
      /outputxdccinfo 
    }
    ; unset %i %botnames %rand.bt
  }
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------






;-------------------------------------------------------------------------
; /alternatesendcheck $1:
; $1: Network.
; $2: Nick.
; Checks the alternate DCC send method file for a dccserver command and
; executes it, and starts queue for $1, if a command is found. 
;-------------------------------------------------------------------------
alias alternatesendcheck {
  if ($exists($alternatedccserverfile) && $read($alternatedccserverfile,snt,$1 $2) && $get($1).status != active) {
    if (!$read($autoresumedisablefile,wnt,$2 $+ ¦ $+ $1)) {
      /outputxdccinfo 3Retrying XDCC download for7 $2 on3 $1 with alternate DCC send method ( $+ $read($alternatedccserverfile,snt,$1 $2) $+ ).
      $read($alternatedccserverfile,snt,$1 $2)
      /startqueue $2
    }
    else { 
      /outputxdccinfo 4Not retrying XDCC download for7 $2 on3 $1 with alternate DCC send method. 
      /outputxdccinfo 
    }
  }
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------







;-------------------------------------------------------------------------
; /timexdcctransferstest & /timexdcctransferstestoff:
; /timexdcctransferstest initiates one out of two unlimited timers if 
; botqueueing is on. 
; The first starts a cycle that checks the need for new bot queue starts
; on the basis of bandwidth statistics of a chosen time interval. 
; The second starts a cycle that checks the need for new bot queue starts
; on the basis of the number of active and presently requested transfers.
; /timexdcctransferstestoff switches both these timers off.
;-------------------------------------------------------------------------
alias timexdcctransferstest { 
  .timexdcctransferstestoff
  if (%botqueuehandling == on) {
    if (%botqueuemode == bandwidth) { .timerxdccstatistics -o 0 %statisticstime /calcxdccstats $timer(xdccstatistics).secs }
    elseif (%botqueuemode == number of transfers) { .timerxdcctransferstest -o 0 %statisticstime /checktransfernumber }
  }
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
alias timexdcctransferstestoff { 
  .timerxdccstatistics off 
  .timerxdcctransferstest off
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------


;-------------------------------------------------------------------------
; /checktransfernumber:
; This is triggered every %statisticstime seconds if botqueueing and 
; testing are switched on.
; It activates a new botqueue, if one exists, if it detects that the 
; number of bots + xdcctimers is less than the minimum number of transfers
; setting.
;-------------------------------------------------------------------------
alias checktransfernumber {
  if ($shouldstartminbotq && $botqueue.exists) { 
    /outputxdccinfo 3Number of transfers is lower than %mintransfers $+ . Starting $calc(%mintransfers - $calc($activeautoresumesends + $activesends)) new bot(s).
    /startbotqueues $calc(%mintransfers - $calc($activeautoresumesends + $activesends))
  }
  else { /debuglog CHECKTRANSFERNUMBER: Number of transfers lower than %mintransfers $+ . No bots to start. }
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
; /checktransfernumber:
; This is triggered every %statisticstime seconds if botqueueing and 
; testing are switched on.
; It activates a new botqueue, if one exists, if it detects that the 
; average bandwidth over the last %statisticstime seconds + (number of 
; active xdcctimers * square root of the system's maximum bandwidth) is 
; less than the minimum bandwidth setting. The timer for this one should 
; be reset whenever a new transfer starts, or a transfer finishes or 
; fails.
;-------------------------------------------------------------------------
alias calcxdccstats {
  set %averagebw 0
  set %z 1
  while (%z <= $get(0)) {
    if ($get(%z).status == active) { 
      write -a $statsfile(1) $get(%z) $get(%z).rcvd
    }
    inc %z      
  }

  set %oldtotalbytes 0
  if ($exists($statsfile(2))) {
    set %z 1
    while (%z <= $lines($statsfile(2))) {
      /debuglog CALC OLDSTATS: %z $gettok($read($statsfile(2),%z),2,32)
      if ($get($gettok($read($statsfile(2),%z),1,32)).status == active) { set %oldtotalbytes $calc(%oldtotalbytes + $gettok($read($statsfile(2),%z),2,32)) }
      inc %z
    }
  }
  set %newtotalbytes 0
  if ($exists($statsfile(1))) {
    set %z 1
    while (%z <= $lines($statsfile(1))) {
      /debuglog CALC NEWSTATS: %z $gettok($read($statsfile(1),%z),2,32)
      set %newtotalbytes $calc(%newtotalbytes + $gettok($read($statsfile(1),%z),2,32))
      inc %z
    }
  }
  set %totalbytes $calc(%newtotalbytes - %oldtotalbytes)
  set %averagebw $calc($calc(%totalbytes / $calc(%statisticstime - $1)) / 1024)

  set %totaltimers 0
  set %timeroverhead 0
  set %z 1
  while (%z <= $timer(0)) {
    if ($isXDCCTimer(%z) == TRUE) { 
      inc %totaltimers 
      set %timeroverhead $calc(%timeroverhead + $calc($calc(10 * $sqrt(%connectionbandwidth)) / $sqrt($timer(%z).secs)))
    }
    inc %z
  }

  /debuglog CALC TIMEROVERHEADSTATS: ( $+ %totaltimers $+ *(10* $+ $sqrt(%connectionbandwidth) $+ )/ $+ $sqrt($timer(%z).secs) $+ ) %timeroverhead $calc(%totaltimers * $calc(2 * $sqrt(%connectionbandwidth)))
  /debuglog CALC BANDWIDTH: %totalbytes $calc(2 * $sqrt(%connectionbandwidth)) %newtotalbytes %oldtotalbytes Average bandwidth use for last $calc(%statisticstime - $1) seconds: %averagebw + %timeroverhead $+ .
  if ($calc(%averagebw + %timeroverhead) <= %minbandwidth && $calc(%averagebw + %timeroverhead) >= 0 && $botqueue.exists == TRUE) {
    /outputxdccinfo Average bandwidth for last $calc(%statisticstime - $1) seconds ( $+ %averagebw KByte) plus estimated timer overhead ( $+ %timeroverhead KByte over %totaltimers request timers), $calc(%averagebw + %timeroverhead) KByte estimated total, is lower than minimum bandwidth setting ( $+ %minbandwidth KByte). Bot Queue exists. Starting new Bot Queue.
    /outputxdccinfo 
    /startbotqueues 1
  }
  elseif (%averagebw <= %minbandwidth) { /debuglog STATS: NO BOT QUEUES FOUND: Average bandwidth for last $calc(%statisticstime - $1) seconds ( $+ %averagebw KByte) plus estimated timer overhead ( $+ %timeroverhead KByte over %totaltimers request timers) is lower than minimum bandwidth setting ( $+ %minbandwidth KByte). No Bots In Bot Queues. }
  else { /debuglog STATS: AVERAGE EXCEEDS MAXIMUM: Average bandwidth for last $calc(%statisticstime - $1) seconds ( $+ %averagebw KByte) plus estimated timer overhead ( $+ %timeroverhead KByte over %totaltimers request timers) is higher than minimum bandwidth setting ( $+ %minbandwidth KByte). Not starting Bot Queues. }

  if ($exists($statsfile(2))) { .remove $statsfile(2) }
  if ($exists($statsfile(1))) { .rename $statsfile(1) $statsfile(2) }
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------








;-------------------------------------------------------------------------
; /addtoxdccwishlist $1-:
; $1-: Searchstring.
; This searches all packs for a string, then adds it to the wishlist if
; it wasn't in there already.
;-------------------------------------------------------------------------
alias addtoxdccwishlist {
  if ($1- != $null) {
    findpack $replaceallwishlist($1-)
    if (!$read($xdccwishlist,wnt,$1-)) { 
      /write -a $xdccwishlist $1-
      /outputxdccinfo 11Added $1- 14to your wishlist.
    }
    else { /outputxdccinfo 14You already have that item in your wishlist ( $+ $1- $+ ).  }
  }
  else { /outputxdccinfo 14No searchstring entered. }
  /outputxdccinfo 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------

;-------------------------------------------------------------------------
; /removefromxdccwishlist $1-:
; $1-: Searchstring.
; This removes an item from the wishlist.
;-------------------------------------------------------------------------
alias removefromxdccwishlist {
  if ($1- != $null) {
    if ($read($xdccwishlist,wnt,$1-)) { 
      /write -dw" $+ $1- $+ " $xdccwishlist
      /outputxdccinfo 10Removed item $1- 14from your wishlist.
    }
    else { /outputxdccinfo 14No such item in wishlist ( $+ $1- $+ ).  }
  }
  else { /outputxdccinfo 14No searchstring entered. }
  /outputxdccinfo 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------

;-------------------------------------------------------------------------
; /matchwishlistpack $1 $2 $3 $4-:
; $1: Nick.
; $2: Network.
; $3: Channel.
; $4-: Pack string.
; This matches a pack to any items in the wishlist and reports a match if
; one was found.
;-------------------------------------------------------------------------
alias matchwishlistpack {
  if ($exists($xdccwishlist)) {
    if ($read($xdccwishlist,wnt,$4-)) { 
      /outputxdccinfo 11Wishlist item found: Exact Match: Bot7 $1 on network3 $2 (12 $+ $3 $+ ) just listed 13" $+ $strip($4-,burc) $+ " for packlisting, which partially matches your wishlist entry 11" $+ $read($xdccwishlist, $readn) $+ ".
      /outputxdccinfo 
    }
    elseif ($read($xdccwishlist,wnt,* $+ $replaceallwishlist($4-) $+ *)) {
      /outputxdccinfo 11Possible wishlist item found: Partial Match: Bot7 $1 on network3 $2 (12 $+ $3 $+ ) just listed 13" $+ $strip($4-,burc) $+ " for packlisting, which partially matches your wishlist entry 11" $+ $read($xdccwishlist, $readn) $+ ". 
      /outputxdccinfo 
    }
    else {
      set %a 1
      while (%a <= $lines($xdccwishlist)) {
        if (* $+ $replaceallwishlist($read($xdccwishlist, nt, %a)) $+ * iswm $replaceallwishlist($4-)) { 
          /outputxdccinfo 11Possible wishlist item found: Normal Match: Bot7 $1 on network3 $2 (12 $+ $3 $+ ) just listed 13" $+ $strip($4-,burc) $+ " for packlisting, which partially matches your wishlist entry 11" $+ $read($xdccwishlist, $readn) $+ ". 
          /outputxdccinfo 
        }
        inc %a
      }
    }
  }
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------


;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
; /comparepackfiles $1 $2
; $1: New pack file filename.
; $2: Old pack file filename.
; This should compare pack files to detect changes in a bot's 
; packlistings. If the listing is changed it notifies the script user and
; warns if a queue exists for the changed bot. It only compares by 
; checking list length, because checking actual pack changes would be too 
; hard because of the fact that bots often add their number of packet gets
; to their ads.
;-------------------------------------------------------------------------
alias comparepackfiles {
  if (%comparepacks == on && $1 != $2 && $lines($2) > 0 && $lines($1) > 0) {
    set %changedpacks $null
    var %llen

    if ($lines($2) <= $lines($1)) {
      set %i 1
      set %llen $lines($2)
      while (%i <= %llen) {
        set %k $matchtok($read($2, %i),14, 0, 32)

        if ($remvall($read($2, %i)) != $remvall($read($1, %i)) && $gettok($read($2, %i),1,32) == $gettok($read($1, %i),1,32) && $gettok($read($1, %i),2-3,32) != Unknown Pack && $gettok($read($2, %i),2-3,32) != Unknown Pack) {
          /outputxdccinfo 4Old pack14 $strip($read($2, %i),burc) 15( $+ $remvall($read($2, %i)) $+ )4 is not the same as new pack 14 $+ $strip($read($1, %i),burc) 15( $+ $remvall($read($1, %i)) $+ ).
          set %changedpacks %changedpacks %i
        }
        inc %i
      }
      if ($lines($2) < $lines($1)) {
        if ($calc($lines($1) - $lines($2)) == 1) { set %changedpacks %changedpacks Packnumber added: $lines($1) }
        else { set %changedpacks %changedpacks Packnumbers added: $calc($lines($2) + 1) $+ - $+ $lines($1) }
      }
    }

    if ($lines($1) < $lines($2)) {
      set %i 1
      set %llen $lines($1)
      while (%i <= %llen) {
        set %k $matchtok($read($2, %i),14, 0, 32)

        if ($remvall($read($2, %i)) != $remvall($read($1, %i)) && $gettok($read($2, %i),1,32) == $gettok($read($1, %i),1,32) && $gettok($read($1, %i),2-3,32) != Unknown Pack && $gettok($read($2, %i),2-3,32) != Unknown Pack) {
          /outputxdccinfo 4Old pack14 $strip($read($2, %i),burc) 15( $+ $remvall($read($2, %i)) $+ )4 is not the same as new pack 14 $+ $strip($read($1, %i),burc) 15( $+ $remvall($read($1, %i)) $+ ).
          set %changedpacks %changedpacks %i
        }
        inc %i
      }
      if ($calc($lines($2) - $lines($1)) == 1) { set %changedpacks %changedpacks Packnumber removed: $lines($2) }
      else { set %changedpacks %changedpacks Packnumbers removed: $calc($lines($1) + 1) $+ - $+ $lines($2) }
    }
    unset %llen

    if (%changedpacks != $null) {
      if ($exists($replace($1,.pff,.q))) {
        /outputxdccinfo 14(NOTE: This message was delayed %packchangechecktime seconds.) Packfile most likely changed for2 $1 $+ 14, or bot went offline during listing, or interval between pack ad listing lines was longer than %packchangechecktime seconds. 4Warning: you have packs queued for this bot, make sure the right packs are queued (Old packfile: $lines($2) lines. New packfile: $lines($1) lines. Packnumber(s) changed:13 %changedpacks $+ 14). 
      }
      else { /outputxdccinfo 14(NOTE: This message was delayed %packchangechecktime seconds.) Packfile most likely changed for2 $1 $+ 14, or bot went offline during listing, or interval between pack ad listing lines was longer than %packchangechecktime seconds (Old packfile: $lines($2) lines. New packfile: $lines($1) lines. Packnumber(s) changed:13 %changedpacks $+ 14). }

      /outputxdccinfo 
    }
    ; unset %i %k %changedpacks
  }
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------









;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
; /timejoin1 & /timejoin2:
; $1: botnick.
; $2: botnetwork.
; Sets timers for the autojoin script. This was triggered by a timer in 
; the ON NOTICE trigger. The first alias triggers the second one after a 
; few seconds. The second sets timers to re-request a pack.
;-------------------------------------------------------------------------
alias timejoin1 {
  if ($read($chankeyfile,wnt,$network $triggerHash.getChan($2, $1) *)) {
    /join -n $gettok($read($chankeyfile,wnt,$network $triggerHash.getChan($2, $1) *),2-,32)
    /outputxdccinfo 12Channel requires key... 5Trying key found in channel key file.
    .timerxdccjoin $+ $1 $+ 3 1 10 /timejoin2 $1 $2
  }
  else { 
    /join -n $triggerHash.getChan($2, $1) 
    .timerxdccjoin $+ $1 $+ 3 1 5 /timejoin2 $1 $2
  }
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
alias timejoin2 {
  if ($me ison $triggerHash.getChan($2, $1)) {
    set %trigger $triggerHash.getTrigger($network, $1) $+ $read($getqfilenm($2, $1), tn, 1)
    set %bt.rand $rand(%minresumedelay, %maxresumedelay)

    if ($exists($dccallownetworkfile) && $read($dccallownetworkfile,wnt,$network)) { /DCCALLOW + $+ $gettok(%trigger, 2-, 32) }
    if ($exists($alternatedccserverfile) && $read($alternatedccserverfile,snt,$network $gettok(%trigger, 2-, 32))) { $read($alternatedccserverfile,snt,$network $gettok(%trigger, 2-, 32)) }

    if ($get($1).status != active && $botliston == TRUE) { //cline -lc12 @XDCC_Info $fline(@XDCC_Info,$1,1,1) }
    /outputxdccinfo 10Succesfully joined channel12 $triggerHash.getChan($2, $1) $+ . Retrying xdcc command for3 $2 $+ ¦7 $+ $1 in %bt.rand seconds ( $+ %trigger $+ ).
    if ($gettok(%trigger, 1, 32) == /msg) { /timerxdccjoin $+ $1 $+ 2 1 %bt.rand /msg $gettok(%trigger, 2-, 32) }
    elseif ($gettok(%trigger, 1, 32) == /ctcp) { /timerxdccjoin $+ $1 $+ 2 1 %bt.rand /ctcp $gettok(%trigger, 2-, 32) }
    elseif ($gettok(%trigger, 1, 32) == /notice) { /timerxdccjoin $+ $1 $+ 2 1 %bt.rand /notice $gettok(%trigger, 2-, 32) }
    else { /outputxdccinfo 4ERROR: Unknown trigger type ( $+ %trigger $+ ). }

    ; unset %trigger %bt.rand
  }
  else { /outputxdccinfo 4ERROR: Channel join command unsuccessful. }
  /outputxdccinfo 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------

;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
; /timeversionrequest & $timeversionrequest2:
; $1: nick. Usually %scriptauthor.
; Requests the latest script version. Uses one yes/no querybox.
;-------------------------------------------------------------------------
alias timeversionrequest {
  set %versionrequest $?!="Get new XDCC script version?"
  /timerxdccversionrequest 1 0 /timeversionrequest2 $1
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
alias timeversionrequest2 {
  if (%versionrequest == $true) {
    .notice $1 Requesting send of new XDCC script version.
    /outputxdccinfo 14 $+ New version available. Requesting download.
  }
  else { /outputxdccinfo 14 $+ New version available but not downloaded. }

  ; unset %versionrequest

  /outputxdccinfo 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------




;-------------------------------------------------------------------------
; /colorchannicks $1:
; $1: chan.
; Colours the nicknames for a channel in the @XDCC_Info nicklist.
;-------------------------------------------------------------------------
alias colorchannicks {
  if ($botliston == TRUE) {
    set %f 1
    while (%f <= $triggerHash.items) {
      if ($1 isin $triggerHash.item.chans(%f) && $triggerHash.item.network(%f) == $network && $triggerHash.item.nick(%f) ison $1 && $get($triggerHash.item.nick(%f)).status != active) { //cline -lc7 @XDCC_Info $fline(@XDCC_Info,$triggerHash.item.nick(%f),1,1) }
      inc %f
    }
  }
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------






;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
; /generalswitch, /resumeswitch, /autoqswitch, /autoremoveswitch, 
; /autojoinxdccswitch, /autostartswitch & /autoresendswitch:
; Toggles autoresume function, autoqueue function, autoremove function, 
; autojoin function, autoresume at start function or auto resend function 
; respectively. All can be triggered from the channel menu. Each uses 1 
; popup yes/no querybox.
;-------------------------------------------------------------------------
alias generalswitch {
  if ($group($1) == on) { /disable $1 }
  elseif ($group($1) == off) { /enable $1 }
}
;-------------------------------------------------------------------------
alias resumeswitch {
  /generalswitch #groupautoxdccresume
  /outputxdccinfo 14Auto Resume is now $group(#groupautoxdccresume) $+ .
  /outputxdccinfo 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
alias resumejoinswitch {
  /generalswitch #groupautoxdccresumejoin
  /outputxdccinfo 14Auto Resume On Bot Rejoin is now $group(#groupautoxdccresumejoin) $+ .
  /outputxdccinfo 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
alias autoqswitch {
  /generalswitch #groupautoxdccq
  /outputxdccinfo 14Auto Queueing is now $group(#groupautoxdccq) $+ .
  /outputxdccinfo 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
alias autostartswitch {
  if ($group(#groupautoresumeatstart) == on) { 
    /disable #groupautoresumeatstart 
    /disable #groupautoresumestart
  }
  elseif ($group(#groupautoresumeatstart) == off) { 
    /enable #groupautoresumeatstart 
    /enable #groupautoresumestart
  }
  /outputxdccinfo 14Auto Resume At Start is now $group(#groupautoresumeatstart) $+ .
  /outputxdccinfo 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
alias autoremoveswitch {
  /generalswitch #groupautoremove
  /outputxdccinfo 14Auto Remove is now $group(#groupautoremove) $+ .
  /outputxdccinfo 
} 
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
alias autojoinxdccswitch {
  /generalswitch #groupautojoinxdcc
  /outputxdccinfo 14Auto Join is now $group(#groupautojoinxdcc) $+ .
  /outputxdccinfo 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
alias autoresendswitch {
  /generalswitch #groupautosendresume
  /outputxdccinfo 14Auto Send Resume is now $group(#groupautosendresume) $+ .
  /outputxdccinfo 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
alias autononewconnectswitch {
  /generalswitch #groupnonewconnects
  /outputxdccinfo 14Auto retry on No New Connections notice is now $group(#groupnonewconnects) $+ .
  /outputxdccinfo 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
alias botqueuehandlingswitch {
  if (%botqueuehandling == off) { set %botqueuehandling on }
  else { 
    /timexdcctransferstestoff 
    set %botqueuehandling off 
  }
  /outputxdccinfo 14Bot Queue Handling is now %botqueuehandling $+ .
  /outputxdccinfo 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
alias timerbotqueuetestswitch {
  if (%testnumoftransferspeed == off) { 
    /timexdcctransferstest 
    set %testnumoftransferspeed on
  }
  else { 
    /timexdcctransferstestoff 
    set %testnumoftransferspeed off
  }
  /outputxdccinfo 14Bot Queue Handling Timed Test is now %testnumoftransferspeed $+ .
  /outputxdccinfo 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
alias comparepacksswitch {
  if (%comparepacks == off) { set %comparepacks on }
  else { set %comparepacks off }
  if ($group(#grouppackchangedetect) == on) { /disable #grouppackchangedetect }
  elseif ($group(#grouppackchangedetect) == off) { /enable #grouppackchangedetect }
  /outputxdccinfo 14Packfile Tracking is now %comparepacks $+ .
  /outputxdccinfo 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
alias trackqueueposswitch {
  /generalswitch #grouptrackqueuepos
  /outputxdccinfo 14Track Queue Position From Bot Notices is now $group(#grouptrackqueuepos) $+ .
  /outputxdccinfo 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
alias autocleanatstartswitch {
  if (%autocleanatstart == off) { set %autocleanatstart on }
  else { set %autocleanatstart off }
  /outputxdccinfo 14Auto Clean Bot Library At Start is now %autocleanatstart $+ .
  /outputxdccinfo 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
alias clearallqueuesoncompleteswitch {
  if (%clearallqueuesoncomplete == off) { set %clearallqueuesoncomplete on }
  else { set %clearallqueuesoncomplete off }
  /outputxdccinfo 14Auto Attempt to Clean All Bot Queues on Pack Complete is now %clearallqueuesoncomplete $+ .
  /outputxdccinfo 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
alias debugxdccswitch {
  if (%debugxdccinfo == off) { set %debugxdccinfo on }
  else { set %debugxdccinfo off }
  /outputxdccinfo 14Debugging log writing is now %debugxdccinfo $+ .
  /outputxdccinfo 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------



;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
; /reverttodefaults & /reverttodefaults2:
; This reverts all settings to their default values, including file and 
; directory names, timer settings, and group enabling settings. It also 
; creates the default XDCC folder. Uses 1 popup yes/no query box.
;-------------------------------------------------------------------------
alias reverttodefaults {
  if ($?!="Revert all settings to defaults (this includes directory/filename and group settings)?") {
    /reverttodefaults2
    /outputxdccinfo 14Timer variables set. File and directory names set. Directory $xdccdir created. Groups AutoQueue, AutoRemove, AutoSendResume, AutoChangeDetect, TrackQueuePos, AutoCleanAtStart and AutoResumeAtStart disabled. Window options set to " $+ %infochoise $+ ".
    /outputxdccinfo 
  }
}
alias reverttodefaults2 {
  set %XDCCdir XDCC\
  set %xdcctriggerfile xdcctriggerfile.apf
  set %triggerbackup triggerbackup.apf
  set %xdccsinprogress xdccsending.apf
  set %autoresumedisablefile autoresumedisabled.apf
  set %autoresumesenddisablefile autosenddisabled.apf
  set %botqueuefile botqueuefile.apf
  set %tempbotqueuefile tempbotqueuefile.apf
  set %xdccsessiongetfile sessiongets.apf
  set %xdccsessionsendfile sessionsends.apf
  set %networksendfile activenetworks.apf
  set %xdccqueueposfile queueposfile.apf
  set %chankeyfile chankeyfile.apf
  set %dccallownetworkfile dccallownetworkfile.apf
  set %alternatedccserverfile alternatedccserverfile.apf
  set %xdccwishlist xdccwishlist.apf
  set %alternatebotsfile alternatebotsfile.apf
  set %statsfile xdccstatsfile
  set %xdccdebugfile XDCCscriptLOG.log
  set %resumedelay 900
  set %sendresumedelay 200
  set %minresumedelay 1
  set %maxresumedelay 30
  set %minautoqdelay 1
  set %maxautoqdelay 120
  set %minqfulldelay 120
  set %maxqfulldelay 3600
  set %minnoconnect 60
  set %maxnoconnect 600
  set %startresumeoffset 90
  set %sendresumetime 15
  set %statisticstime 900
  set %packchangechecktime 60
  set %liblimitdate 40
  set %sendlimit Unlimited
  set %maxnumberresumes unlimited
  set %maxtransfers unlimited
  set %mintransfers 0
  set %connectionbandwidth 1
  set %maxbandwidth $floor($calc(%connectionbandwidth * 0.75))
  set %minbandwidth 0
  set %botqueuemode number of transfers
  set %infochoise special window
  set %xdccfont @XDCC_Info 12 Verdana
  set %showbotlist ON
  set %multisourcehandling off
  set %botqueuehandling off
  set %testnumoftransferspeed off
  set %comparepacks off
  set %autocleanatstart off
  set %clearallqueuesoncomplete off
  set %debugxdccinfo off
  .enable #groupautoxdccresume
  .enable #groupautoxdccresumejoin
  .enable #groupautoxdccq
  .disable #groupautoresumeatstart
  .disable #groupautoresumestart
  .enable #groupautojoinxdcc
  .enable #groupnonewconnects
  .disable #groupautoremove 
  .disable #groupautosendresume
  .disable #grouppackchangedetect
  .disable #grouptrackqueuepos
  .mkdir $xdccdir
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------

;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
; /savexdccscriptsettings $1:
; $1: settings file name.
; This should save the settings to file $1 using a key for each setting 
; and the value behind it separated by a space.
;-------------------------------------------------------------------------
alias savexdccscriptsettings {
  if (!$exists($1 $+ .set) || $?!="File exists, overwrite?") {
    if ($exists($1 $+ .set)) {
      .remove $1 $+ .set
    }
    /write -a $1 $+ .set XDCCdir $xdccdir
    /write -a $1 $+ .set xdcctriggerfile %xdcctriggerfile 
    /write -a $1 $+ .set triggerbackup %triggerbackup
    /write -a $1 $+ .set xdccsinprogress %xdccsinprogress 
    /write -a $1 $+ .set autoresumedisablefile %autoresumedisablefile 
    /write -a $1 $+ .set autoresumesenddisablefile %autoresumesenddisablefile 
    /write -a $1 $+ .set xdccsessiongetfile %xdccsessiongetfile 
    /write -a $1 $+ .set xdccsessionsendfile %xdccsessionsendfile 
    /write -a $1 $+ .set networksendfile %networksendfile
    /write -a $1 $+ .set botqueuefile %botqueuefile
    /write -a $1 $+ .set tempbotqueuefile %tempbotqueuefile
    /write -a $1 $+ .set alternatebotsfile %alternatebotsfile
    /write -a $1 $+ .set queueposfile %xdccqueueposfile
    /write -a $1 $+ .set alternatedccserverfile %alternatedccserverfile
    /write -a $1 $+ .set dccallownetworkfile %dccallownetworkfile
    /write -a $1 $+ .set chankeyfile %chankeyfile
    /write -a $1 $+ .set xdccdebugfile %xdccdebugfile
    /write -a $1 $+ .set xdccwishlist %xdccwishlist
    /write -a $1 $+ .set xdccstatsfile %statsfile
    /write -a $1 $+ .set resumedelay %resumedelay 
    /write -a $1 $+ .set sendresumedelay %sendresumedelay 
    /write -a $1 $+ .set minresumedelay %minresumedelay 
    /write -a $1 $+ .set maxresumedelay %maxresumedelay 
    /write -a $1 $+ .set minautoqdelay %minautoqdelay 
    /write -a $1 $+ .set maxautoqdelay %maxautoqdelay 
    /write -a $1 $+ .set minqfulldelay %minqfulldelay 
    /write -a $1 $+ .set maxqfulldelay %maxqfulldelay 
    /write -a $1 $+ .set minnoconnect %minnoconnect 
    /write -a $1 $+ .set maxnoconnect %maxnoconnect 
    /write -a $1 $+ .set startresumeoffset %startresumeoffset 
    /write -a $1 $+ .set sendresumetime %sendresumetime 
    /write -a $1 $+ .set packchangechecktime %packchangechecktime 
    /write -a $1 $+ .set liblimitdate %liblimitdate 
    /write -a $1 $+ .set sendlimit %sendlimit 
    /write -a $1 $+ .set maxtransfers %maxtransfers
    /write -a $1 $+ .set mintransfers %mintransfers
    /write -a $1 $+ .set connectionbandwidth %connectionbandwidth
    /write -a $1 $+ .set minbandwidth %minbandwidth
    /write -a $1 $+ .set maxbandwidth %maxbandwidth
    /write -a $1 $+ .set botqueuemode %botqueuemode
    /write -a $1 $+ .set testnumoftransferspeed %testnumoftransferspeed
    /write -a $1 $+ .set infochoise %infochoise 
    /write -a $1 $+ .set xdccfont %xdccfont 
    /write -a $1 $+ .set showbotlist %showbotlist 
    /write -a $1 $+ .set botqueuehandling %botqueuehandling
    /write -a $1 $+ .set multisourcehandling %multisourcehandling
    /write -a $1 $+ .set statisticstime %statisticstime 
    /write -a $1 $+ .set comparepacks %comparepacks 
    /write -a $1 $+ .set autocleanatstart %autocleanatstart 
    /write -a $1 $+ .set clearallqueuesoncomplete %clearallqueuesoncomplete
    /write -a $1 $+ .set debugxdccinfo %debugxdccinfo
    /write -a $1 $+ .set #groupautoxdccresume $group(#groupautoxdccresume)
    /write -a $1 $+ .set #groupautoxdccresumejoin $group(#groupautoxdccresumejoin)
    /write -a $1 $+ .set #groupautoxdccq $group(#groupautoxdccq)
    /write -a $1 $+ .set #groupautoresumeatstart $group(#groupautoresumeatstart)
    /write -a $1 $+ .set #groupautoresumestart $group(#groupautoresumestart)
    /write -a $1 $+ .set #groupautojoinxdcc $group(#groupautojoinxdcc)
    /write -a $1 $+ .set #groupnonewconnects $group(#groupnonewconnects)
    /write -a $1 $+ .set #groupautoremove $group(#groupautoremove)
    /write -a $1 $+ .set #groupautosendresume $group(#groupautosendresume)
    /write -a $1 $+ .set #grouppackchangedetect $group(#grouppackchangedetect)
    /write -a $1 $+ .set #grouptrackqueuepos $group(#grouptrackqueuepos)
    /outputxdccinfo 14Saved settings to profile $nopath($1) ( $+ $1 $+ .set).
  }
  else { /outputxdccinfo 4ERROR: Not overwriting existing profile. } 
  /outputxdccinfo 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------

;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
; /loadxdccscriptsettings $1:
; $1: settings file name.
; This should load the settings from file $1.set. If no value is found for 
; a certain setting, default value if used.
;-------------------------------------------------------------------------
alias loadxdccscriptsettings {
  if ($exists($1 $+ .set)) {
    if ($read($1 $+ .set, snt,XDCCdir) != $null) { set %XDCCdir $read($1 $+ .set, snt,XDCCdir) }
    else { 
      set %XDCCdir $scriptdir $+ XDCC\
      /outputxdccinfo 14Can't find setting for XDCC dir, using default setting.    
    }
    if ($read($1 $+ .set, snt,xdcctriggerfile) != $null) { set %xdcctriggerfile $read($1 $+ .set, snt,xdcctriggerfile) }
    else {
      set %xdcctriggerfile xdcctriggerfile.apf 
      /outputxdccinfo 14Can't find setting for xdcc trigger file, using default setting.
    }
    if ($read($1 $+ .set, snt,xdccsinprogress) != $null) { set %xdccsinprogress $read($1 $+ .set, snt,xdccsinprogress) }
    else { 
      set %xdccsinprogress xdccsending.apf 
      /outputxdccinfo 14Can't find setting for xdccs in progress file, using default setting.
    }
    if ($read($1 $+ .set, snt,triggerbackup) != $null) { set %triggerbackup $read($1 $+ .set, snt,triggerbackup) }
    else {
      set %triggerbackup triggerbackup.apf 
      /outputxdccinfo 14Can't find setting for backup trigger file, using default setting.
    }
    if ($read($1 $+ .set, snt,autoresumedisablefile) != $null) { set %autoresumedisablefile $read($1 $+ .set, snt,autoresumedisablefile) }
    else { 
      set %autoresumedisablefile autoresumedisabled.apf 
      /outputxdccinfo 14Can't find setting for auto resume disable file, using default setting.
    }
    if ($read($1 $+ .set, snt,autoresumesenddisablefile) != $null) { set %autoresumesenddisablefile $read($1 $+ .set, snt,autoresumesenddisablefile) }
    else {
      set %autoresumesenddisablefile autosenddisabled.apf 
      /outputxdccinfo 14Can't find setting for auto resume send disable file, using default setting.
    }
    if ($read($1 $+ .set, snt,xdccsessiongetfile) != $null) { set %xdccsessiongetfile $read($1 $+ .set, snt,xdccsessiongetfile) }
    else {
      set %xdccsessiongetfile sessiongets.apf 
      /outputxdccinfo 14Can't find setting for xdcc session get file, using default setting.
    }
    if ($read($1 $+ .set, snt,xdccsessionsendfile) != $null) { set %xdccsessionsendfile $read($1 $+ .set, snt,xdccsessionsendfile) }
    else { 
      set %xdccsessionsendfile sessionsends.apf 
      /outputxdccinfo 14Can't find setting for xdcc session send file, using default setting.
    }
    if ($read($1 $+ .set, snt,networksendfile) != $null) { set %networksendfile $read($1 $+ .set, snt,networksendfile) }
    else {
      set %networksendfile activenetworks.apf
      /outputxdccinfo 14Can't find setting for network sends file, using default setting.
    }
    if ($read($1 $+ .set, snt,botqueuefile) != $null) { set %botqueuefile $read($1 $+ .set, snt,botqueuefile) }
    else {
      set %botqueuefile botqueuefile.apf
      /outputxdccinfo 14Can't find setting for bot queue file, using default setting.
    }    
    if ($read($1 $+ .set, snt,tempbotqueuefile) != $null) { set %tempbotqueuefile $read($1 $+ .set, snt,tempbotqueuefile) }
    else {
      set %tempbotqueuefile tempbotqueuefile.apf
      /outputxdccinfo 14Can't find setting for temp bot queue file, using default setting.
    }
    if ($read($1 $+ .set, snt,alternatebotsfile) != $null) { set %alternatebotsfile $read($1 $+ .set, snt,alternatebotsfile) }
    else {
      set %alternatebotsfile alternatebotsfile.apf
      /outputxdccinfo 14Can't find setting for general alternate sources file, using default setting.
    }
    if ($read($1 $+ .set, snt,queueposfile) != $null) { set %xdccqueueposfile $read($1 $+ .set, snt,queueposfile) }
    else {
      set %xdccqueueposfile queueposfile.apf
      /outputxdccinfo 14Can't find setting for xdcc queue position file, using default setting.
    }
    if ($read($1 $+ .set, snt,chankeyfile) != $null) { set %chankeyfile $read($1 $+ .set, snt,chankeyfile) }
    else {
      set %chankeyfile chankeyfile.apf
      /outputxdccinfo 14Can't find setting for channel key file, using default setting.
    }
    if ($read($1 $+ .set, snt,dccallownetworkfile) != $null) { set %dccallownetworkfile $read($1 $+ .set, snt,dccallownetworkfile) }
    else {
      set %dccallownetworkfile dccallownetworkfile.apf
      /outputxdccinfo 14Can't find setting for dccallow network support file, using default setting.
    }
    if ($read($1 $+ .set, snt,alternatedccserverfile) != $null) { set %alternatedccserverfile $read($1 $+ .set, snt,alternatedccserverfile) }
    else {
      set %alternatedccserverfile alternatedccserverfile.apf
      /outputxdccinfo 14Can't find setting for alternate dcc server bot file, using default setting.
    }
    if ($read($1 $+ .set, snt,xdccstatsfile) != $null) { set %statsfile $read($1 $+ .set, snt,xdccstatsfile) }
    else {
      set %statsfile xdccstatsfile
      /outputxdccinfo 14Can't find setting for statistics files, using default setting.
    }
    if ($read($1 $+ .set, snt,xdccwishlist) != $null) { set %xdccwishlist $read($1 $+ .set, snt,xdccwishlist) }
    else {
      set %xdccwishlist xdccwishlist.apf
      /outputxdccinfo 14Can't find setting for wishlist file, using default setting.
    }
    if ($read($1 $+ .set, snt,xdccdebugfile) != $null) { set %xdccdebugfile $read($1 $+ .set, snt,xdccdebugfile) }
    else {
      set %xdccdebugfile XDCCscriptLOG.log
      /outputxdccinfo 14Can't find setting for xdcc queue position file, using default setting.
    }
    if ($read($1 $+ .set, snt,resumedelay) != $null) { set %resumedelay $read($1 $+ .set, snt,resumedelay) }
    else {
      set %resumedelay 900 
      /outputxdccinfo 14Can't find setting for autoresume reactivation time delay, using default setting.
    }
    if ($read($1 $+ .set, snt,sendresumedelay) != $null) { set %sendresumedelay $read($1 $+ .set, snt,sendresumedelay) }
    else {
      %sendresumedelay 200 
      /outputxdccinfo 14Can't find setting for send autoresume reactivation time delay, using default setting.
    }
    if ($read($1 $+ .set, snt,minresumedelay) != $null) { set %minresumedelay $read($1 $+ .set, snt,minresumedelay) }
    else {
      set %minresumedelay 1 
      /outputxdccinfo 14Can't find setting for min auto resume delay, using default setting.
    }
    if ($read($1 $+ .set, snt,maxresumedelay) != $null) { set %maxresumedelay $read($1 $+ .set, snt,maxresumedelay) }
    else { 
      set %maxresumedelay 30
      /outputxdccinfo 14Can't find setting for max auto resume delay, using default setting.
    }
    if ($read($1 $+ .set, snt,minautoqdelay) != $null) { set %minautoqdelay $read($1 $+ .set, snt,minautoqdelay) }
    else { 
      set %minautoqdelay 1
      /outputxdccinfo 14Can't find setting for min auto queue delay, using default setting.
    }
    if ($read($1 $+ .set, snt,maxautoqdelay) != $null) { set %maxautoqdelay $read($1 $+ .set, snt,maxautoqdelay) }
    else { 
      set %maxautoqdelay 120 
      /outputxdccinfo 14Can't find setting for max auto queue delay, using default setting.
    }
    if ($read($1 $+ .set, snt,minqfulldelay) != $null) { set %minqfulldelay $read($1 $+ .set, snt,minqfulldelay) }
    else { 
      set %minqfulldelay 120 
      /outputxdccinfo 14Can't find setting for min queue full request delay, using default setting.
    }
    if ($read($1 $+ .set, snt,maxqfulldelay) != $null) { set %maxqfulldelay $read($1 $+ .set, snt,maxqfulldelay) }
    else { 
      set %maxqfulldelay 3600 
      /outputxdccinfo 14Can't find setting for max queue full request delay, using default setting.
    }
    if ($read($1 $+ .set, snt,minnoconnect) != $null) { set %minnoconnect $read($1 $+ .set, snt,minnoconnect) }
    else {
      set %minnoconnect 60 
      /outputxdccinfo 14Can't find setting for min no connect request delay, using default setting.
    }
    if ($read($1 $+ .set, snt,maxnoconnect) != $null) { set %maxnoconnect $read($1 $+ .set, snt,maxnoconnect) }
    else {
      set %maxnoconnect 600 
      /outputxdccinfo 14Can't find setting for max no connect request delay, using default setting.
    }
    if ($read($1 $+ .set, snt,startresumeoffset) != $null) { set %startresumeoffset $read($1 $+ .set, snt,startresumeoffset) }
    else {
      set %startresumeoffset 90 
      /outputxdccinfo 14Can't find setting for resume at start offset, using default setting.
    }
    if ($read($1 $+ .set, snt,sendresumetime) != $null) { set %sendresumetime $read($1 $+ .set, snt,sendresumetime) }
    else {
      set %sendresumetime 15
      /outputxdccinfo 14Can't find setting for maximum send resume time, using default setting.
    }
    if ($read($1 $+ .set, snt,statisticstime) != $null) { set %statisticstime $read($1 $+ .set, snt,statisticstime) }
    else {
      set %statisticstime 900
      /outputxdccinfo 14Can't find setting for transfer number check time, using default setting.
    }
    if ($read($1 $+ .set, snt,packchangechecktime) != $null) { set %packchangechecktime $read($1 $+ .set, snt,packchangechecktime) }
    else {
      set %packchangechecktime 300
      /outputxdccinfo 14Can't find setting for pack change check time, using default setting.
    }
    if ($read($1 $+ .set, snt,liblimitdate) != $null) { set %liblimitdate $read($1 $+ .set, snt,liblimitdate) }
    else { 
      set %liblimitdate 40
      /outputxdccinfo 14Can't find setting for library expiration time, using default setting.
    }
    if ($read($1 $+ .set, snt,sendlimit) != $null) { set %sendlimit $read($1 $+ .set, snt,sendlimit) }
    else {
      set %sendlimit Unlimited 
      /outputxdccinfo 14Can't find setting for send limit, using default setting.
    }
    if ($read($1 $+ .set, snt,maxtransfers) != $null) { set %maxtransfers $read($1 $+ .set, snt,maxtransfers) }
    else {
      set %maxtransfers Unlimited 
      /outputxdccinfo 14Can't find setting for simultaneous transfers upper limit, using default setting.
    }
    if ($read($1 $+ .set, snt,mintransfers) != $null) { set %mintransfers $read($1 $+ .set, snt,mintransfers) }
    else {
      set %mintransfers 0
      /outputxdccinfo 14Can't find setting for simultaneous transfers lower limit, using default setting.
    }
    if ($read($1 $+ .set, snt,maxbandwidth) != $null) { set %maxbandwidth $read($1 $+ .set, snt,maxbandwidth) }
    else {
      set %maxbandwidth $floor($calc(%connectionbandwidth * 0.75))
      /outputxdccinfo 14Can't find setting for upper bandwidth limit, using default setting.
    }
    if ($read($1 $+ .set, snt,minbandwidth) != $null) { set %minbandwidth $read($1 $+ .set, snt,minbandwidth) }
    else {
      set %minbandwidth 0
      /outputxdccinfo 14Can't find setting for lower bandwidth limit, using default setting.
    }
    if ($read($1 $+ .set, snt,connectionbandwidth) != $null) { set %connectionbandwidth $read($1 $+ .set, snt,connectionbandwidth) }
    else {
      set %connectionbandwidth 1
      /outputxdccinfo 14Can't find setting for user connection speed, using default setting.
    }
    if ($read($1 $+ .set, snt,botqueuemode) != $null) { set %botqueuemode $read($1 $+ .set, snt,botqueuemode) }
    else {
      set %botqueuemode number of transfers
      /outputxdccinfo 14Can't find setting for bot queue mode setting, using default setting.
    }
    if ($read($1 $+ .set, snt,infochoise) != $null) { set %infochoise $read($1 $+ .set, snt,infochoise) }
    else { 
      set %infochoise special window 
      /outputxdccinfo 14Can't find setting for info output choise, using default setting.
    }
    if ($read($1 $+ .set, snt,xdccfont) != $null) { set %xdccfont $read($1 $+ .set, snt,xdccfont) }
    else { 
      set %xdccfont @XDCC_Info 12 Verdana 
      /outputxdccinfo 14Can't find setting for xdcc window font, using default setting.
    }
    if ($read($1 $+ .set, snt,showbotlist) != $null) { set %showbotlist $read($1 $+ .set, snt,showbotlist) }
    else {
      set %showbotlist ON 
      /outputxdccinfo 14Can't find setting for botlist showing, using default setting.
    }
    .mkdir $xdccdir
    if ($read($1 $+ .set, snt,botqueuehandling) != $null) { set %botqueuehandling $read($1 $+ .set, snt,botqueuehandling) }
    else { 
      set %botqueuehandling off 
      /outputxdccinfo 14Can't find setting for bot queue handling, using default setting.
    }
    if ($read($1 $+ .set, snt,multisourcehandling) != $null) { set %multisourcehandling $read($1 $+ .set, snt,multisourcehandling) }
    else { 
      set %multisourcehandling off 
      /outputxdccinfo 14Can't find setting for multi source download handling, using default setting.
    }
    if ($read($1 $+ .set, snt,testnumoftransferspeed) != $null) { set %testnumoftransferspeed $read($1 $+ .set, snt,testnumoftransferspeed) }
    else { 
      set %testnumoftransferspeed off 
      /outputxdccinfo 14Can't find setting for bot queue test on timer, using default setting.
    }
    if ($read($1 $+ .set, snt,comparepacks) != $null) { set %comparepacks $read($1 $+ .set, snt,comparepacks) }
    else {
      set %comparepacks off 
      /outputxdccinfo 14Can't find setting for compare packfiles, using default setting.
    }
    if ($read($1 $+ .set, snt,autocleanatstart) != $null) { set %autocleanatstart $read($1 $+ .set, snt,autocleanatstart) }
    else { 
      set %autocleanatstart off 
      /outputxdccinfo 14Can't find setting for auto clean at start, using default setting.
    }
    if ($read($1 $+ .set, snt,clearallqueuesoncomplete) != $null) { set %clearallqueuesoncomplete $read($1 $+ .set, snt,clearallqueuesoncomplete) }
    else { 
      set %clearallqueuesoncomplete off 
      /outputxdccinfo 14Can't find setting for clear all bots from complete pack, using default setting.
    }
    if ($read($1 $+ .set, snt,debugxdccinfo) != $null) { set %debugxdccinfo $read($1 $+ .set, snt,debugxdccinfo) }
    else { 
      set %debugxdccinfo off 
      /outputxdccinfo 14Can't find setting for debug log creation, using default setting.
    }
    if ($read($1 $+ .set, snt,#groupautoxdccresume) != $null) { 
      if ($read($1 $+ .set, snt,#groupautoxdccresume) == ON) { .enable #groupautoxdccresume }
      elseif ($read($1 $+ .set, snt,#groupautoxdccresume) == OFF) { .disable #groupautoxdccresume }
    }
    else { 
      .enable #groupautoxdccresume 
      /outputxdccinfo 14Can't find setting for auto xdcc resume, using default setting.
    }
    if ($read($1 $+ .set, snt,#groupautoxdccresumejoin) != $null) { 
      if ($read($1 $+ .set, snt,#groupautoxdccresumejoin) == ON) { .enable #groupautoxdccresumejoin }
      elseif ($read($1 $+ .set, snt,#groupautoxdccresumejoin) == OFF) { .disable #groupautoxdccresumejoin }
    }
    else {
      .enable #groupautoxdccresumejoin 
      /outputxdccinfo 14Can't find setting for auto xdcc resume on join, using default setting.
    }
    if ($read($1 $+ .set, snt,#groupnonewconnects) != $null) { 
      if ($read($1 $+ .set, snt,#groupnonewconnects) == ON) { .enable #groupnonewconnects }
      elseif ($read($1 $+ .set, snt,#groupnonewconnects) == OFF) { .disable #groupnonewconnects }
    }
    else {
      .enable #groupnonewconnects
      /outputxdccinfo 14Can't find setting for auto handle no new connects, using default setting.
    }
    if ($read($1 $+ .set, snt,#groupautoxdccq) != $null) { 
      if ($read($1 $+ .set, snt,#groupautoxdccq) == ON) { .enable #groupautoxdccq }
      elseif ($read($1 $+ .set, snt,#groupautoxdccq) == OFF) { .disable #groupautoxdccq }
    }
    else { 
      .enable #groupautoxdccq 
      /outputxdccinfo 14Can't find setting for auto xdcc queueing, using default setting.
    }
    if ($read($1 $+ .set, snt,#groupautoresumeatstart) != $null) { 
      if ($read($1 $+ .set, snt,#groupautoresumeatstart) == ON) { .enable #groupautoresumeatstart }
      elseif ($read($1 $+ .set, snt,#groupautoresumeatstart) == OFF) { .disable #groupautoresumeatstart }
    }
    else { 
      .disable #groupautoresumeatstart 
      /outputxdccinfo 14Can't find setting for auto resume at start (group 1), using default setting.
    }
    if ($read($1 $+ .set, snt,#groupautoresumestart) != $null) { 
      if ($read($1 $+ .set, snt,#groupautoresumestart) == ON) { .enable #groupautoresumestart }
      elseif ($read($1 $+ .set, snt,#groupautoresumestart) == OFF) { .disable #groupautoresumestart }
    }
    else { 
      .disable #groupautoresumestart 
      /outputxdccinfo 14Can't find setting for auto resume start (group 2), using default setting.
    }
    if ($read($1 $+ .set, snt,#groupautojoinxdcc) != $null) { 
      if ($read($1 $+ .set, snt,#groupautojoinxdcc) == ON) { .enable #groupautojoinxdcc }
      elseif ($read($1 $+ .set, snt,#groupautojoinxdcc) == OFF) { .disable #groupautojoinxdcc }
    }
    else { 
      .enable #groupautojoinxdcc 
      /outputxdccinfo 14Can't find setting for auto join on bot request, using default setting.
    }
    if ($read($1 $+ .set, snt,#groupautoremove) != $null) { 
      if ($read($1 $+ .set, snt,#groupautoremove) == ON) { .enable #groupautoremove }
      elseif ($read($1 $+ .set, snt,#groupautoremove) == OFF) { .disable #groupautoremove }
    }
    else { 
      /outputxdccinfo 14Can't find setting for auto remove at bot removal, using default setting.
      .disable #groupautoremove 
    }
    if ($read($1 $+ .set, snt,#groupautosendresume) != $null) { 
      if ($read($1 $+ .set, snt,#groupautosendresume) == ON) { .enable #groupautosendresume }
      elseif ($read($1 $+ .set, snt,#groupautosendresume) == OFF) { .disable #groupautosendresume }
    }
    else { 
      .disable #groupautosendresume 
      /outputxdccinfo 14Can't find setting for auto send resume, using default setting.
    }
    if ($read($1 $+ .set, snt,#grouppackchangedetect) != $null) { 
      if ($read($1 $+ .set, snt,#grouppackchangedetect) == ON) { .enable #grouppackchangedetect }
      elseif ($read($1 $+ .set, snt,#grouppackchangedetect) == OFF) { .disable #grouppackchangedetect }
    }
    else { 
      .disable #grouppackchangedetect 
      /outputxdccinfo 14Can't find setting for pack change detection, using default setting.
    }
    if ($read($1 $+ .set, snt,#grouptrackqueuepos) != $null) { 
      if ($read($1 $+ .set, snt,#grouptrackqueuepos) == ON) { .enable #grouptrackqueuepos }
      elseif ($read($1 $+ .set, snt,#grouptrackqueuepos) == OFF) { .disable #grouptrackqueuepos }
    }
    else {
      .disable #grouptrackqueuepos 
      /outputxdccinfo 14Can't find setting for track queue position, using default setting.
    }
    /outputxdccinfo 14Loaded profile $1 from file $1 $+ .set (Default values used where no setting was found). Directory $xdccdir created if not found.
  }
  else { /outputxdccinfo 4ERROR: No such XDCC Settings profile ( $+ $1 $+ ) in $xdccdir ( $+ $1 $+ .set). }
  /outputxdccinfo 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------







;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
; /XDCChelp:
; Small help file on how to use the script.
; Can be triggered from the channel, status, nick, or @XDCC_Info menu, or 
; menubar > commands. 
;-------------------------------------------------------------------------
alias XDCChelp {
  /outputxdccinfo 5*****************************************************************************
  /outputxdccinfo 
  /outputxdccinfo 4WARNING7: Many channels will ban you for using XDCC leech scripts. While this is a silly rule it is your responsibility. Use this wisely. Don't use it in such channels, or don't get caught. And play nice for the other people that want to use the XDCCs! If you leech em dry other people may be unable to get on.
  /outputxdccinfo  
  /outputxdccinfo 5*****************************************************************************
  /outputxdccinfo 
  /outputxdccinfo 6Before we get started:
  /outputxdccinfo 
  /outputxdccinfo 5The script must capture the triggers and packlistings for a bot before it can be used on that bot, so the first thing you must do is idle in an xdcc channel and let the in channel xdcc ads scroll by for a while. The capturing is fully automatic. Once a trigger has been captured, you can begin using the script. 
  /outputxdccinfo 5There is an XDCC menu item under your right mouse button. It will prompt you for more input if needed or perform the action on the selected nickname. Some functions can be used on multiple nicknames at the same time. 
  /outputxdccinfo 5If an option says it applies to "selected bot(s)", the function will be performed on all bots currently selected in the nicklist (the first bot selected is the only one mentioned in the menu item title). This means you can perform some functions on single, as well as multiple bots at the same time. 
  /outputxdccinfo 
  /outputxdccinfo 5The nicklist in the special @XDCC_Info window, if switched on, has color codes that tell you whether a bot is 9downloading5, successfully remotely queued5, 5waiting for a remote queue slot to open5, 6waiting for new connections to be allowed5, $& 
    4failed5, 2suspended5, 13trying to join a channel5, 12just joined a channel and trying to queue a pack5, 14unreachable because you're not on the same network5, 10unknown status because you're not in the same channel5, 7online and in the same channel as you5, or 1offline5.
  /outputxdccinfo 
  /outputxdccinfo 13Files used:
  /outputxdccinfo 
  /outputxdccinfo 5Note: The "XDCC Pack library" consists of the3 network5¦7bot5.pff files. These files store the info on the packs, while the *.apf files store non-bot-specific information such as the currently acquired triggers or the bots that are currently downloading. $&
    $triggerHash is the most important file in the apf section, as it stores the bot triggers and other information about the bots. It is not recommended to edit this file by hand, and if the script is running, it's actually rather useless because the information you edit will most likely be overwritten. 
  /outputxdccinfo 5The 3network5¦7bot5.q files hold the bot specific queues, whereas active queue information for a network (like the information used when using autoresume at start) is stored in a 3network5.apf file. $&
    The .old files store temporary information used to check for changing packs on an XDCC bot. You can change most of the filenames and the directory used if you go to 12Settings > 12Filename Settings5. The filename you choose when renaming a file should not exist. The new directory should exist, but the script can create directories on one level directory depth. If you don't specify a full path, the directory will be created in your IRC home dir.
  /outputxdccinfo 
  /outputxdccinfo 6Main menu commands:
  /outputxdccinfo 
  /outputxdccinfo 13Basic queue actions:
  /outputxdccinfo 
  /outputxdccinfo 12You can add bot specific queues by entering the packnumbers you wish to download, if you choose 12Add XDCC Queue For Bot <Bot Name>5. Use a format like "1 2 4-10 12" when entering the pack numbers. This example would queue up packnumbers 1, 2, 4, 5, 6, 7, 8, 9, 10 and 12. $&
    You can use this same format in 12Remove XDCC Queue For Bot <Bot Name>5, obviously with the opposite result.   12Clear XDCC Queue5 will remove all your queued up packs for the selected bot at once. The downloading will not start untill you choose 12Start Processing Queue File5. This will start downloading the requests in the queue for the specified bot one by one. 
  /outputxdccinfo 5You can halt a queue temporarily (and prevent a file from being automatically re-requested when the transfer fails) by choosing 12Suspend Autoqueue And Auto Re-Request 5for that particular bot. This will not remove the currently sending or queued pack from your queue, and it will not halt any current transfers. You can restart the queue where you left off by choosing 12Start Queue 5again later on.   
  /outputxdccinfo 12Remove a pack from ALL XDCC queues by Name5 will remove a pack based on it's pack description. When using this, be as precise as you can in the pack description. If you're not precise enough, you may accidentally dequeue packs you want to keep queued. Try entering the pack description exactly as it is in the bot library. $&
    For instance: 'blah' will remove all wildcard matches for *blah*, including 'blah.divx', 'blah.divx.cd1.tar', 'blah.cd2.divx' and 'blah.2.divx.tar', whereas 'blah.divx' will only remove the first two, and 'blah.divx.cd1' will only remove the second. 
  /outputxdccinfo 12Stop all current downloads for bot5 will halt any and all currently active incoming transfers for the selected bot(s), without triggering the auto resume function. 
  /outputxdccinfo 12Stop all current uploads for bot5 will halt any and all currently active outgoing transfers for the selected bot(s), without triggering the auto send resume function. 
  /outputxdccinfo 
  /outputxdccinfo 13Bot Queue actions:
  /outputxdccinfo 
  /outputxdccinfo 12Add Bot to Bot Queue5 will add a (number of) bot(s) to the Bot Queue. 12Remove Bot from Bot Queue5 will remove a (number of) bot(s) from that file. This secondary queue feature allows you to process the bots you have queues for automatically in a smooth row, rather than all at once, or manually. $&
    12Clear Bot Queue File5 will remove all bot queues at once. 12Start processing First N Bots in bot queue file5 will start queues for the first N number of bots (where N is a number you entered) that are in the queue file.
  /outputxdccinfo 12Remove <BOT/NETWORK> Entirely From Bot Library 5will remove all files and entries related to this3 network5¦7bot5 pair. It will only show up in the nicklist menu.
  /outputxdccinfo 
  /outputxdccinfo 13Searching XDCC packs:
  /outputxdccinfo 
  /outputxdccinfo 12Find XDCC Pack5 will search all bots in your library for any packs that match the string you entered. This is sensitive to word order, but it will respond to partial words or sentences as well as full descriptions.
  /outputxdccinfo 5If you want to look at the packs for a given (number of) bot(s), channel or network, you can choose the appropriate option. 12Browse All Known XDCC Packs For Bot/Channel/Network5 will list all packs for the selected target. Be aware that channel and especially network listings can be in the thousands of items. 
  /outputxdccinfo 
  /outputxdccinfo 13Queue Listings:
  /outputxdccinfo 
  /outputxdccinfo 12Show All Currently Active Bots5 will show all bots that you have started queues for, whether they are queued, active, or waiting for a bot to come online. 
  /outputxdccinfo 12Show all queues for all bots5 will briefly list all bots with their queued up pack numbers, whereas 12Show detailed Queues for all bots5 will list all queues for all bots, with the pack descriptions. Choose 12Show detailed Queue for specific selected bot(s)5 to view a (more selective number of) bot(s)'s detailed queue.
  /outputxdccinfo 5Finally, you can view the secondary queue by choosing 12Show Bot Queue5.
  /outputxdccinfo 
  /outputxdccinfo 13Remaining Listings:
  /outputxdccinfo 
  /outputxdccinfo 12Show all completed file receptions5 will show you all completed downloads from the current session.
  /outputxdccinfo 12Show all completed sends5 will show all completed uploads this session.
  /outputxdccinfo 12Get XDCC Library Statistics5 will show you a small number of statistics for the script.
  /outputxdccinfo 
  /outputxdccinfo 13Miscellaneous Commands:
  /outputxdccinfo 
  /outputxdccinfo 12Remove <BOT/NETWORK> Entirely From Bot Library 5will remove all files and entries related to this3 network5¦7bot5 pair, including queues, triggers, and pack listings, and remove that bot from the nick list for the separate output window (if the window and bot list are active).
  /outputxdccinfo 12Clean XDCC Library5 will remove all .pff files and their appropriate triggers if they are older than the number of days mentioned (unless you have a queue for the matching bot). It will also remove all .old files, unless a pack change test is pending.
  /outputxdccinfo 12Add/Change key for channel5 allows you to provide the script with a key needed to join a channel. This is useful if the script attempts to join that channel automatically if a bot that has an active queue requires you to be in the same channel with it.
  /outputxdccinfo 12Toggle DCCALLOW Support for Network5 makes the script do a /DCCALLOW +Nick every time it starts a queue. Only switch this on for networks that require this feature, otherwise it can be annoying and suspicious. 
  /outputxdccinfo 12XDCC Get Help5 will show this help file.
  /outputxdccinfo 12Check for new script version5 will check for a new version of this script and will prompt you to download it if it is available. You can only request a version check from the script's author (that's me, %scriptauthor $+ ) is online on the same network as you are.
  /outputxdccinfo 12About5 will tell you a few things about the script itself. 
  /outputxdccinfo 
  /outputxdccinfo 6Settings menu options:
  /outputxdccinfo 
  /outputxdccinfo 5In the 12Settings5 submenu one can switch ON or OFF a variety of this script's features. This next part of the helpfile will discuss these settings one at a time. $&
    The settings themselves are located in the 12Settings5 submenu, whereas the actual commands that make use of them are either automated, or located in the main XDCC menu, which we have already discussed in the above. Check the help file in the Settings submenu to find out about what these features do. Some features are disabled by default because they're more subtle, but you may want them enabled.
  /outputxdccinfo 
  /outputxdccinfo 6Happy hunting!
  /outputxdccinfo 
  /outputxdccinfo 5*****************************************************************************
  /outputxdccinfo 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------


;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
; /SettingsXDCChelp:
; Small help file on the script's main settings.
; Can be triggered from the channel, status, nick, or @XDCC_Info menu, 
; or menubar > commands. 
;-------------------------------------------------------------------------
alias SettingsXDCChelp {
  /outputxdccinfo 5*****************************************************************************
  /outputxdccinfo 
  /outputxdccinfo 6Settings menu options:
  /outputxdccinfo 
  /outputxdccinfo 13XDCC Get main features:
  /outputxdccinfo 
  /outputxdccinfo 12Autoresume 5automatically re-requests your failed downloads (if it knows the bot's trigger and the pack number of the failed download).
  /outputxdccinfo 
  /outputxdccinfo 12Activate/Deactivate Autoresume On Bot Rejoin5 will automatically resume a transfer when an activated (but offline) bot comes back online. These first two functions have been divided into separate items from version 1.22.16, and shutting one down (or switching it on) will not influence the other. 
  /outputxdccinfo 
  /outputxdccinfo 12Autoqueue 5automatically queues up the next download for a bot (only packnumbers specified by you) whenever one finishes (if there are any packs still in that bot's queue). 
  /outputxdccinfo 
  /outputxdccinfo 12Activate/Deactivate Bot Queue Handling5 will enable or disable the more advanced Bot Queue feature, which uses a secondary queue file that lists entire bots, rather than pack queue items. If switched on, once a bot completes it's entire queue, the script will move on to the next bot listed in the bot queue file. $&
    This continues until all bots in the bot queue file have completed their entire queues. Note that the bot queue feature will only work if the Auto-Queue feature is also switched to ON. 
  /outputxdccinfo 
  /outputxdccinfo 12Activate/Deactivate automated timed checking for available download slots/bandwidth5 is a feature that has two possible settings: bandwidth, and number of transfers. It will automatically check every so often whether all available bandwidth, or the maximum allowed download slots, is used. If there is room for more, it will start up a new download using the botqueue. You can switch modes using 12Swap mode for connection availability testing5. If you use this, don't forget to set your prefered maximum and minimum slots or bandwidth, and your system's total bandwidth (in Kilobytes).
  /outputxdccinfo 
  /outputxdccinfo 12Activate/Deactivate AutoResume At IRC Start 5will toggle the option to resume transfers that were active when IRC closed on startup (or whenever a connection is made to a server on an appropriate network). This is useful for, for instance, resuming downloads that were active during a system or program crash. $&
    Switching it off will not affect the normal autoresume function. By default it is turned OFF. This is because packlistings may change while you are offline, thus having the script request the wrong pack. However, this is very unlikely if you have only been gone for a short while, like the few minutes it takes to reboot after a system crash.
  /outputxdccinfo 
  /outputxdccinfo 12Activate/Deactivate Auto Retry at No New Connections notice 5will, if switched ON, attempt to re-request a pack after a (usually large) number of seconds, if a bot owner refuses to send a pack and notices you that he has requested that "No New Connections be made in the next N minutes".
  /outputxdccinfo 
  /outputxdccinfo 12Activate/Deactivate Auto Join at Bot Request 5will, if switched on, react to the requirement that some bots need you to be in a serving channel with them before they will send you any packs. It will auto-join a channel where the bot was known to have been and re-request the file on a timer. Be sure to add keys for your  channels where appropriate. 
  /outputxdccinfo 
  /outputxdccinfo 5Switching12 Activate/Deactivate AutoRemove at bot removal confirmation5 ON will make the script automatically remove items from your queue files if you dequeue them from a bot by sending that bot a /msg BOT xdcc remove message. It can only remove items that it can find a match for in the library. Any others will stay in the .q file.  
  /outputxdccinfo 
  /outputxdccinfo 12Activate/Deactivate Attempt to Clean Pack from ALL Bot Queues on Pack Complete5 does basically the same thing as 12Remove a pack from ALL XDCC queues by Name5 (only it does so automatically for each completed download to prevent double requests), and thus it has the same drawbacks. Be thorough when inputting a removal string. $&
    For instance: 'blah' will remove all wildcard matches for *blah*, including 'blah.divx', 'blah.divx.cd1.tar', 'blah.cd2.divx' and 'blah.2.divx.tar', whereas 'blah.divx' will only remove the first two, and 'blah.divx.cd1' will only remove the second.
  /outputxdccinfo 
  /outputxdccinfo 12Activate/Deactivate Packfile Change Tracking5 will, if switched ON, warn you when a pack listing for a bot seems to have changed. It is disabled by default because the warnings can be annoying when you are in a channel with a lot of xdccs that change their packlistings quite often. However, it is also useful to prevent you from queueing up the wrong packs, or informing you of new pack additions or removals.
  /outputxdccinfo 
  /outputxdccinfo 12Activate/Deactivate Queue Position Tracking5 will simply inform you every time a bot notices you that your queue position has changed. You can usually see these notices in the bot's channel or server window as well, but it may be handy for keeping the bot messages in somewhat clearer sight when visiting very busy channels. It will only inform you if your queue position actually changes. It is switched OFF by default.
  /outputxdccinfo 
  /outputxdccinfo 12Auto Clean XDCC Library At Startup5 will automatically clean the library on script start. This is disabled by default, because it takes a while to clean the library. 12Clean old files from Bot Library5 is the manual variety to this automated feature. It will remove files older than the number of days set by 12Set library file expiration date5. Doing this cleaning every once in a while prevents the library from becoming poluted with old bots that are no longer active. Default expiration time is set to 40 days. 
  /outputxdccinfo 
  /outputxdccinfo 13XDCC Send main features:
  /outputxdccinfo 
  /outputxdccinfo 5Switching12 Auto Resume Sends 5on will resume your sends if they fail to complete. This is switched OFF by default, since it can be annoying for the recipient if they try to cancel the u/l but fail to do so because it insists on resuming. For that reason the send autoresume function is temporarily disabled for that recipient after a send is resumed.
  /outputxdccinfo 
  /outputxdccinfo 12 Set AutoResume Send bandwidth Limit 5will set an upper bandwidth limit to your autoresumed sends. This is not a total bandwidth limit, but a limit PER SEND.
  /outputxdccinfo 
  /outputxdccinfo 13Miscellaneous Settings features:
  /outputxdccinfo 
  /outputxdccinfo 12Write debugging log file5 Writes a log file that can be used to filter bugs from the script. It is not necessary to turn this on unless your script locks up your IRC.
  /outputxdccinfo 
  /outputxdccinfo 5The 12window options 5allow you to choose where the information from the xdcc script goes. This information includes pack searches that you do, autoresume or queue notices, and error reporting. You can choose to report to the currently active window, to the server status window, to a window created specifically for this purpose, or to both the active window and the special window. 
  /outputxdccinfo 12Set Separate Output Window Font 5will set and store the font for the separate output window.
  /outputxdccinfo 12Toggle Bot List View 5will show a list of all bots in the triggerHash file. You can perform actions on this list like you can in a channel nick listbox.
  /outputxdccinfo 
  /outputxdccinfo 5The 12Timer options5 should only be changed if you know what you're changing, as they are the core of the script's stealth. There is a specific 12Help5 file on the timer settings in the timer options submenu.
  /outputxdccinfo   
  /outputxdccinfo 5You can save or load your settings in a .set file by choosing 12Save XDCC Script settings5 or 12Load previously stored XDCC Script settings5 respectively (Do not enter a filename, but only a profile name. The extension will be added automatically, and illegal characters should be filtered out). If a certain setting is not found when you load a profile, the default value will be used. 
  /outputxdccinfo 5Finally, If you changed something and the script stopped working properly, you can choose to 12revert ALL settings to their default values5. You won't lose queues or bot data, but all timer, window and filename modifications you made are reversed, and some features will be switched on or off. 
  /outputxdccinfo 
  /outputxdccinfo 5*****************************************************************************
  /outputxdccinfo 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------

;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
; /TimerXDCChelp:
; Small help file on how to set timer settings.
; Can be triggered from the channel menu under Timer Options. 
;-------------------------------------------------------------------------
alias TimerXDCChelp {
  /outputxdccinfo 5*****************************************************************************
  /outputxdccinfo 
  /outputxdccinfo 6Timer Menu Options:
  /outputxdccinfo 
  /outputxdccinfo 12Set delay for auto resume reactivation:5 When requesting a resume for a failed transfer the auto-resume script is temporarily disabled to prevent an unwilling server from being spammed with requests. Mostly, this would be caused by a server that continually times out, so this value should be set no lower (and preferably somewhat higher, just to be safe) than your DCC Get timeout value.
  /outputxdccinfo 
  /outputxdccinfo 12Set minimum delay for item resume request:5 To simulate a human being controlling the requests, the script uses a random timer before requesting a resume. This sets the lower boundary for this random time value. You should at least give it a second.
  /outputxdccinfo 12Set maximum delay for item resume request:5 To simulate a human being controlling the requests, the script uses a random timer before requesting a resume. This sets the upper boundary for this random time value. You should at least give it a few seconds.
  /outputxdccinfo 12Set minimum delay for next queue item request:5 To simulate a human being controlling the requests, the script uses a random timer before requesting a next item. This sets the lower boundary for this random time value. You should at least give it a second.
  /outputxdccinfo 12Set maximum delay for next queue item request:5 To simulate a human being controlling the requests, the script uses a random timer before requesting a next item. This sets the lower boundary for this random time value. You should at least give it half a minute.
  /outputxdccinfo 12Set minimum delay for re-request item on queue full:5 If a server sends you a notice that it has no queue spots available, the script will automatically re-request the pack on a random timer. This sets the lower value for that timer. It can be set no lower than 10 seconds. 
  /outputxdccinfo 12Set maximum delay for re-request item on queue full:5 If a server sends you a notice that it has no queue spots available, the script will automatically re-request the pack on a random timer. This sets the upper value for that timer. It can be set no lower than 10 seconds. It is recommended that you set this no lower than 300 seconds.
  /outputxdccinfo 12Set minimum delay for re-requesting file on no new connection demand:5 If a bot owner pauses a bot for a number of minutes, this part of the script will auto re-request the file after that number of minutes, plus a random offset. This is the minimum setting for that offset.
  /outputxdccinfo 12Set maximum delay for re-requesting file on no new connection demand:5 If a bot owner pauses a bot for a number of minutes, this part of the script will auto re-request the file after that number of minutes, plus a random offset. This is the maximum setting for that offset.
  /outputxdccinfo   
  /outputxdccinfo 12Set offset time for auto resume at start:5 This offset is primarily used to make sure the appropriate channels have been joined before sending the trigger for autoresume. A random delay is added to it that lies in the same range as that of the normal item resume request.
  /outputxdccinfo 
  /outputxdccinfo 10For all these values goes:5 the bigger the interval between min and max, the less likely that you'll be detected. Choose your own preference or use the default values.
  /outputxdccinfo 
  /outputxdccinfo 12Set delay offset for auto resume SEND reactivation:5 When resuming a failed DCC Send the auto-resume send script is temporarily disabled to prevent resends to an unwilling recipient (either because the connection is bad, or the recipient cancelled the file twice). Mostly, this would be caused by a recipient that continually times out, that has a full harddisc, has a corrupted upload part or who keeps cancelling the transfer, so this value should be set no lower (and preferably somewhat higher, just to be safe) than your DCC Send timeout value.
  /outputxdccinfo 
  /outputxdccinfo 12Set maximum delay for auto resume SEND:5 This time value will be used as the pause between a send fail and the next retry (the minimum for this is always 0, since send resume scripts will be less likely to be noticed or disliked by bot owners). A resend will be bandwidth-limited according to your settings.
  /outputxdccinfo 
  /outputxdccinfo 12Set delay for updated packfile comparison:5 This time value should be chosen with care: choosing it too low can cause the comparison to be made while listing is still in progress, causing false pack changed reports, whereas choosing it too high may render the function pointless because the wrongfull transfers may already have commenced, or the packfile may have scrolled by more than once, resulting in a pointless comparison. Note that the checker is not perfect, and it can sometimes overlook changes or report a change where none was made. It has been greatly improved since it's original implementation though.
  /outputxdccinfo 
  /outputxdccinfo 5*****************************************************************************
  /outputxdccinfo 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------








;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
;----------------------------Menu Add-Ons Section-------------------------
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------







;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
; Channel (and report window), status and nicklist addons.
;-------------------------------------------------------------------------
Menu channel,status,@XDCC_Info,nicklist,query {
  -
  XDCC Auto Resume/Auto Queue:
  .Add XDCC queue for bot $1:/addrequest $1
  .Remove specific XDCC queue for bot $1:/removerequest $1
  .Clear XDCC queue for selected bot(s) $1 (and on):{
    set %i 1
    while (%i <= $sline($active,0)) {
      /clrq $sline($active,%i)
      inc %i
    }
  }
  .Start Processing Queue File for Selected Bot(s) $1 (and on):{ 
    set %i 1
    set %nicklistselects $null
    while (%i <= $sline($active,0)) {
      set %nicklistselects %nicklistselects $sline($active,%i)
      inc %i
    }
    /startqueue %nicklistselects
  }
  .Suspend Autoqueue and Auto Re-Request for Selected Bot(s) $1 (and on):{
    set %i 1
    while (%i <= $sline($active,0)) {
      /stopxdccqueue $sline($active,%i)
      inc %i
    }
  }
  .-
  .VisualQ (XDCC Pack Browser):/xdccbrowsebots
  .-
  .Stop all current downloads for selected bot(s) $1 (and on):{
    if ($1 != $null && $?!="Halt ALL incoming transfers for ALL selected bots?") {
      /haltDownloads $1
      set %i 1    
      while (%i <= $sline($active,0)) {
        if ($get($sline($active,%i)).status != $null) { /haltDownloads $sline($active,%i) }
        else { /outputxdccinfo 14No current downloads active for $sline($active,%i) $+ . }
        inc %i
      }
    }
    else { /outputxdccinfo 14No bot selected or halting cancelled. }
    /outputxdccinfo 
  }
  .Stop all current uploads for selected bot(s) $1 (and on):{ 
    if ($1 != $null && $?!="Halt ALL outgoing transfers for ALL selected bots?") {
      /haltUploads $1
      set %i 1    
      while (%i <= $sline($active,0)) {
        if ($send($sline($active,%i)).status != $null) { /haltUploads $sline($active,%i) }
        else { /outputxdccinfo 14No current uploads active for $sline($active,%i) $+ . }
        inc %i
      }
    }
    else { /outputxdccinfo 14No bot selected or halting cancelled. }
    /outputxdccinfo 
  }
  .-
  .Remove yourself from REMOTE queue for bot $1:{
    if ($1 != $null) { set %botnick $1 }
    else { set %botnick $?="No bot selected, please enter bot name." }
    if (%botnick != $null) {
      if ($triggerHash.network(%botnick) != $null) {
        set %con $null
        set %j 1
        while (%con == $null && %j < 1000) {
          if ($scon(%j).network == $triggerHash.network(%botnick)) { set %con %j }
          inc %j
        }
        if (%con != $null) { /scon %con /msg %botnick xdcc remove }
        else { 
          /outputxdccinfo 14Bot not in bot library (7 $+ %botnick $+ 14). Asuming presence on current network by default (3 $+ $network $+ 14).
          /msg %botnick xdcc remove 
          /outputxdccinfo 
        }
      }
      else { 
        /outputxdccinfo 14Bot not in bot library (14 $+ %botnick $+ ). Asuming presence on current network by default (3 $+ $network $+ 14).
        /msg %botnick xdcc remove 
        /outputxdccinfo 
      }
    }
    else { 
      /outputxdccinfo 14No bot selected, no nickname entered or action cancelled.
      /outputxdccinfo 
    }
  }
  .Remove a Pack from ALL XDCC Queues by Name:{ 
    set %texttomatch $?="Enter the pack's EXACT description or filename (E.g.: 'File 1 cd 1-2004' OR 'file_1.CD1-2004.tar'. IMPORTANT TIP: Be thorough, for instance: 'blah' will remove all wildcard matches for *blah*, including 'blah.divx', 'blah.divx.cd1.tar', 'blah.cd2.divx' and 'blah.2.divx.tar', whereas 'blah.divx' will only remove the first two, and 'blah.divx.cd1' will only remove the second)."
    if (%texttomatch != $null) {
      /removepackfromallbots * * %texttomatch
    }
    else { 
      /outputxdccinfo 14Cancel pressed or no packname entered. No packs removed.
      /outputxdccinfo 
    } 
  }
  .-
  .Bot Queue:
  ..Add Selected Bot(s) $1 (and on) To Bot Queue File:{
    set %i 1
    while (%i <= $sline($active,0)) {
      /addbotqueue $sline($active,%i)
      inc %i
    }
  }
  ..Remove Selected Bot(s) $1 (and on) From Bot Queue File:{
    set %i 1
    while (%i <= $sline($active,0)) {
      /removebotqueue $sline($active,%i)
      inc %i
    }
  }
  ..Clear Bot Queue File:/clrbotq
  ..Start Processing First N Bots in Bot Queue File:{
    set %numbots $?="Give number of bots to start processing simultaneously."
    if (%numbots isnum && %numbots > 0) {
      /startbotqueues %numbots
    }
    else { 
      /outputxdccinfo 14Invalid amount entered or cancelled bot queue start. 
      /outputxdccinfo 
    }
  }
  ..Show Bot Queue:/viewbotqueues
  .-
  .Multi-Source Downloading:
  ..Check for More Sources for FIRST Pack in Queue(s) for Selected Bot(s) $1 (and on):{
    if ($?!="Alternate source searching can lock up your IRC for anywhere between several seconds up to several minutes depending on your system speed, number of selected bots and bot library size. Continue?") {
      /pleasewaitdialog
      set %y 1
      /outputxdccinfo 14Starting sources search for $sline($active,0) selected bot(s). 4Please wait, this can take anywhere from a few seconds up to a few minutes to complete depending on the size of your xdcc library and cause total nonresponsiveness in your IRC during that time...
      while (%y <= $sline($active,0)) {
        if ($exists($getqfilenm($triggerHash.network($sline($active,%y)),$sline($active,%y))) && $lines($getqfilenm($triggerHash.network($sline($active,%y)),$sline($active,%y))) > 0) {     
          /checkformorepacksources $triggerHash.network($sline($active,%y)) $sline($active,%y) $read($getqfilenm($triggerHash.network($sline($active,%y)),$sline($active,%y)), nt, 1)
        }
        else { 
          /outputxdccinfo 14No queue exists for bot7 $sline($active,%y) 14on network3 $triggerHash.network($sline($active,%y)) $+ . 
          /outputxdccinfo 
        }
        inc %y
      }
      /closewaitdialog
    }
  }
  ..Check for More Sources for ALL Packs in Queue(s) for Selected Bot(s) $1 (and on):{
    if ($?!="Alternate source searching can lock up your IRC for anywhere between several seconds up to several minutes depending on your system speed, number of selected bots, size of bots' queues and bot library size. Continue?") {
      /pleasewaitdialog
      set %y 1
      /outputxdccinfo 14Starting sources search for all queued packs for $sline($active,0) selected bot(s). 4Please wait, this can take anywhere from a few seconds up to a few minutes to complete depending on the size of your xdcc library and cause total nonresponsiveness in your IRC during that time...
      while (%y <= $sline($active,0)) {
        if ($exists($getqfilenm($triggerHash.network($sline($active,%y)),$sline($active,%y))) && $lines($getqfilenm($triggerHash.network($sline($active,%y)),$sline($active,%y))) > 0) {
          set %x 1
          while (%x <= $lines($getqfilenm($triggerHash.network($sline($active,%y)),$sline($active,%y)))) {
            /checkformorepacksources $triggerHash.network($sline($active,%y)) $sline($active,%y) $read($getqfilenm($triggerHash.network($sline($active,%y)),$sline($active,%y)), nt, %x)
            inc %x
          }
        }
        else { 
          /outputxdccinfo 14No queue exists for bot7 $sline($active,%y) 14on network3 $triggerHash.network($sline($active,%y)) $+ . 
          /outputxdccinfo 
        }
        inc %y
      }
      /closewaitdialog
    }
  }
  .-
  .Special Case Modifications:
  ..Add/Change Alternate DCC Server command for Bot $1 $iif($read($alternatedccserverfile, snt,$network $1), on $network (you have a command set),(no command currently set)):{
    if ($1 != $null && triggerHash.network($1) != $null) { set %altdcccommand $triggerHash.network($1) $1 $?="Enter alternate dcc command for $1 (E.g.: /dccserver +sc on 1337)." }
    elseif ($1 != $null) { set %altdcccommand $network $1 $?="Enter alternate dcc command for $1 (E.g.: /dccserver +sc on 1337)." }
    else { 
      set %temp $?="Enter bot nickname and alternate dcc command separated by a space (E.g.: guest1234 /dccserver +sc on 1337)." 
      set %altdcccommand $triggerHash.network($gettok(%temp,1,32)) %temp
    }
    if ($numtok(%altdcccommand, 32) > 5) { 
      if ($read($alternatedccserverfile, wnt, $gettok(%altdcccommand,1-2,32) *)) { write -dw" $+ $gettok(%altdcccommand,1-2,32) *" $alternatedccserverfile }
      /write -a $alternatedccserverfile %altdcccommand 
      /outputxdccinfo 14Added Alternate DCC command for bot 7 $gettok(%altdcccommand, 2, 32) 14on network3 $gettok(%altdcccommand, 1, 32) $+ .
      /outputxdccinfo 
    }
    else { 
      /outputxdccinfo 14No command entered, bot unknown, or action cancelled. 
      /outputxdccinfo 
    }    
  }
  ..-
  ..Toggle DCCALLOW support for Network $network ( $+ $iif($read($dccallownetworkfile, wnt, $network),on,off) $+ ):{
    if ($exists($dccallownetworkfile) && $read($dccallownetworkfile, wnt, $network)) { 
      /write -dw $+ $network $dccallownetworkfile $network 
      /outputxdccinfo 14Removed network 3 $network 14from DCCallow support file.
    }
    else { 
      /write -a $dccallownetworkfile $network 
      /outputxdccinfo 14Added network 3 $network 14to DCCallow support file.
    }
    /outputxdccinfo 
  }
  ..-
  ..Add/Change Key for Channel $chan $iif($read($chankeyfile, snt,$network $chan), on $network (you have a key set),(no key currently set)):{
    if ($chan != $null) { set %botchan $network $chan $?*="Enter key for $chan (E.g.: 1337Key)." }
    else { set %botchan $?*="Enter network, channel name and key separated by a space (E.g.: EFnet #Channel 1337Key)." }
    if ($numtok(%botchan, 32) > 2) { 
      if ($read($chankeyfile, wnt, $gettok(%botchan,1-2,32) *)) { write -dw" $+ $gettok(%botchan,1-2,32) *" $chankeyfile }
      /write -a $chankeyfile %botchan
      /outputxdccinfo 14Added channel key for channel12 $gettok(%botchan, 2, 32) 14on network3 $gettok(%botchan, 1, 32) $+ .
      /outputxdccinfo 
    }
    else { 
      /outputxdccinfo 14No key entered or action cancelled. 
      /outputxdccinfo 
    }    
  }
  .-
  .Pack Listings/Searches:
  ..VisualQ (XDCC Pack Browser):/xdccbrowsebots
  ..Find XDCC Pack:{ 
    set %searchstring $?="Enter XDCC pack search string (word-order specific!)."
    if (%searchstring != $null) {
      /pleasewaitdialog
      /findpack %searchstring 
      /closewaitdialog
    } 
  }
  ..Browse All Known XDCC Packs for Selected BOT(s) $1 (and on):{
    if ($1 != $null) {
      set %i 1
      while (%i <= $sline($active,0)) {
        if ($triggerHash.exists($network, $sline($active,%i)) != $null) {
          /botpacks $network $sline($active,%i) 
        }
        elseif ($triggerHash.findNetwork($sline($active,%i) *) != $null) {
          /botpacks $triggerHash.findNetwork($sline($active,%i) *) $sline($active,%i)
        }
        else { 
          /outputxdccinfo 5No matches found for3 $network 7 $+ $sline($active,%i) 5(Note: The script needs to catch the bot's ad before it can search the bot). 
          /outputxdccinfo 
        } 
        inc %i
      }
    }
    else {
      set %botnick $?="Enter bot and network name for pack listing separated by a space (E.g.: EFnet XDCC-Bot01)"
      if (%botnick != $null) { /botpacks %botnick } 
    }
  }
  ..Browse All Known XDCC Packs for CHANNEL $iif($chan != $null,$chan,$triggerHash.findChan($1 *)):{
    if ($chan != $null) { /chanpacks $network $chan }
    elseif ($triggerHash.findChan($1 *) != $null) {
      set %botchan $triggerHash.network($1) $triggerHash.findChan($1 *)
      /chanpacks %botchan
    }
    else {
      set %botchan $?="Enter network and channel name for pack listing separated by a space (E.g.: EFnet #Channel)."
      if (%botchan != $null) { /chanpacks %botchan } 
    }
  }
  ..Browse All Known XDCC Packs for NETWORK $iif($triggerHash.network($1) != $null,$triggerHash.network($1),$network):{
    if ($1 != $null && $triggerHash.network($1)) {
      set %botnetwork $triggerHash.network($1)
      /networkpacks %botnetwork
    }
    elseif ($network != $null) { /networkpacks $network }
    else {
      set %botnetwork $?="Enter network name for pack listing (E.g.: EFnet)."
      if (%botnetwork != $null) { /networkpacks %botnetwork } 
    }
  }
  .Queue/Active Bot Listings:
  ..VisualQ (XDCC Pack Browser):/xdccbrowsebots
  ..Show All Currently Active Bots:/getxdccsending
  ..Show All Queues for All Bots:/showqueues
  ..Show Detailed Queues for Specific Selected Bot(s) $1 (and on):{
    set %i 1
    while (%i <= $sline($active,0)) {
      /showdetailedqueue $sline($active,%i)
      inc %i
    }
  }  
  ..Show Detailed Queues For ALL Bots:/showdetailedqueues
  ..Show Bot Queue:/viewbotqueues
  .Wishlist:
  ..Add wishlist item:/addtoxdccwishlist $?="Input new wishlist item to search for."
  ..Remove wishlist item:/removefromxdccwishlist $?="Input wishlist item to remove."
  .Statistics/Completes:
  ..Show All Completed File Receptions this IRC Session:/getsessiongets
  ..Show All Completed File Sends this IRC Session:/getsessionsends
  ..Get XDCC library statistics:/xdccgetstats
  .-
  .XDCC Library Maintainance/Cleaning:
  ..Remove Selected Bot(s) $1 (and on) on $network Entirely from Bot Library:{
    set %i 1
    while (%i <= $sline($active,0)) {
      if ($triggerHash.exists($network, $sline($active,%i)) != $null) {
        /removebot $sline($active,%i) $network 
      }
      elseif ($triggerHash.findNetwork($sline($active,%i) *)) {
        /removebot $sline($active,%i) $triggerHash.findNetwork($sline($active,%i) *) 
      }
      else { 
        /outputxdccinfo Bot not listed (3 $+ $network $+ ¦7 $+ $sline($active,%i) $+ )
        /outputxdccinfo 
      } 
      inc %i
    }
  }
  ..-
  ..Clean Old Files from Bot Library ( $+ %liblimitdate days):{
    /pleasewaitdialog
    /cleanxdcclib
    /closewaitdialog
  }
  .-
  .Settings Menu:/xdccpreferencesdialog
  .Settings Old Style (direct menu access):
  ..Activate/Deactivate Autoresume ( $+ $group(#groupautoxdccresume) $+ ):{ 
    if ($group(#groupautoxdccresume) == ON) {
      if ($?!="Switch Autoresume Transfer OFF?") { /resumeswitch }
    }
    else {
      if ($?!="Switch Autoresume Transfer ON?") { /resumeswitch }
    }
  }
  ..Activate/Deactivate Autoresume On Bot Rejoin ( $+ $group(#groupautoxdccresumejoin) $+ ):{ 
    if ($group(#groupautoxdccresumejoin) == ON) {
      if ($?!="Switch Autoresume On Bot Rejoin OFF?") { /resumejoinswitch }
    }
    else {
      if ($?!="Switch Autoresume On Bot Rejoin ON?") { /resumejoinswitch }
    }
  }
  ..Activate/Deactivate AutoQueue ( $+ $group(#groupautoxdccq) $+ ):{ 
    if ($group(#groupautoxdccq) == ON) {
      if ($?!="Switch Autoqueue Function OFF?") { /autoqswitch }
    }
    else {
      if ($?!="Switch Autoqueue Function ON?") { /autoqswitch }
    }
  }
  ..Activate/Deactivate Bot Queue Handling ( $+ %botqueuehandling $+ ):{ 
    if (%botqueuehandling == on) {
      if ($?!="Switch Bot Queue Handling Function OFF?") { /botqueuehandlingswitch }
    }
    else {
      if ($?!="Switch Bot Queue Handling Function ON?") { /botqueuehandlingswitch }
    }
  }
  ..Activate/Deactivate Time Automated Testing For Available Download Slots Or Bandwidth ( $+ %testnumoftransferspeed $+ , %botqueuemode $+ ):{ 
    if (%testnumoftransferspeed == on) {
      if ($?!="Switch Time Automated Testing For Transfer Number Or Bandwidth Function OFF?") { /timerbotqueuetestswitch }
    }
    else {
      if ($?!="Switch Time Automated Testing For Transfer Number Or Bandwidth ON?") { /timerbotqueuetestswitch }
    }
  }
  ..Activate/Deactivate AutoResume at IRC Start ( $+ $group(#groupautoresumeatstart) $+ ):{ 
    if ($group(#groupautoresumeatstart) == ON) {
      if ($?!="Switch AutoResume at IRC start Function OFF?") { /autostartswitch }
    }
    else {
      if ($?!="Switch AutoResume at IRC start Function ON?") { /autostartswitch }
    }
  }
  ..Activate/Deactivate Auto Retry at No New Connections Notice ( $+ $group(#groupnonewconnects) $+ ):{
    if ($group(#groupnonewconnects) == ON) {
      if ($?!="Switch Auto Retry at No New Connections notice Function OFF?") { /autononewconnectswitch }
    }
    else {
      if ($?!="Switch Auto Retry at No New Connections notice Function ON?") { /autononewconnectswitch }
    }
  }
  ..Activate/Deactivate Auto Join at Bot Request ( $+ $group(#groupautojoinxdcc) $+ ):{
    if ($group(#groupautojoinxdcc) == ON) {
      if ($?!="Switch Auto join at XDCC bot request Function OFF?") { /autojoinxdccswitch }
    }
    else {
      if ($?!="Switch Auto join at XDCC bot request Function ON?") { /autojoinxdccswitch }
    }
  }
  ..Activate/Deactivate AutoRemove at Bot Removal Confirmation Message ( $+ $group(#groupautoremove) $+ ):{ 
    if ($group(#groupautoremove) == ON) {
      if ($?!="Switch AutoRemove at bot Removal confirmation Function OFF?") { /autoremoveswitch }
    }
    else {
      if ($?!="Switch AutoRemove at bot Removal confirmation ON?") { /autoremoveswitch }
    }
  }  
  ..Activate/Deactivate Attempt to Clean Pack from ALL Bot Queues on Pack Complete ( $+ %clearallqueuesoncomplete $+ ):{
    if (%clearallqueuesoncomplete == on) {
      if ($?!="Switch Attempt to Clean Pack from ALL Bot Queues on Pack Complete Function OFF?") { /clearallqueuesoncompleteswitch }
    }
    else {
      if ($?!="Switch Attempt to Clean Pack from ALL Bot Queues on Pack Complete Function ON? (WARNING: This feature MAY be unreliable, especially when queueing up multiple parts of a pack, like 'movie.avi' and 'movie 2.avi'. Also, full coverage can not be guaranteed. Use with caution.)") { /clearallqueuesoncompleteswitch }
    }
  }
  ..Activate/Deactivate Packfile Change Tracking ( $+ %comparepacks $+ ):{
    if (%comparepacks == on) {
      if ($?!="Switch Packfile Change Tracking Function OFF?") { /comparepacksswitch }
    }
    else {
      if ($?!="Switch Packfile Change Tracking Function ON?") { /comparepacksswitch }
    }
  }
  ..Activate/Deactivate Queue Position Tracking ( $+ $group(#grouptrackqueuepos) $+ ):{
    if ($group(#grouptrackqueuepos) == ON) {
      if ($?!="Switch Queue Position Tracking Function OFF?") { /trackqueueposswitch }
    }
    else {
      if ($?!="Switch Queue Position Tracking Function ON?") { /trackqueueposswitch }
    }
  }
  ..Activate/Deactivate Auto Clean XDCC Library At Startup ( $+ %autocleanatstart $+ ):{
    if (%autocleanatstart == on) {
      if ($?!="Switch Auto Clean XDCC Library At Startup Function OFF?") { /autocleanatstartswitch }
    }
    else {
      if ($?!="Switch Auto Clean XDCC Library At Startup Function ON?") { /autocleanatstartswitch }
    }
  }
  ..-
  ..Activate/Deactivate AutoResume Send ( $+ $group(#groupautosendresume) $+ ):{ 
    if ($group(#groupautosendresume) == ON) {
      if ($?!="Switch AutoResume Send Function OFF?") { /autoresendswitch }
    }
    else {
      if ($?!="Switch AutoResume Send Function ON?") { /autoresendswitch }
    }
  }
  ..Set AutoResume Send Bandwidth Limit ( $+ %sendlimit cps):{
    set %sendlimit $?="Enter auto resend upload cps bandwidth maximum (Type Unlimited for unlimited bandwidth)."
    if (%sendlimit isnum) {
      /outputxdccinfo 14Bandwidth limit for auto send resume set to %sendlimit cps.
    }
    else {
      set %sendlimit Unlimited
      /outputxdccinfo 14Bandwidth limit for auto send resume set to %sendlimit cps. 
    }
    /outputxdccinfo 
  }
  ..-
  ..Swap mode for connection availability testing ( $+ %botqueuemode $+ ):{
    if (%botqueuemode == number of transfers) { set %botqueuemode bandwidth }
    else { set %botqueuemode number of transfers }
    /timexdcctransferstest
    /outputxdccinfo 14Mode for connection availability testing set to %botqueuemode $+ .
    /outputxdccinfo 
  }
  ..Set your connection's maximum download bandwidth ( $+ %connectionbandwidth KByte):{
    set %temp $?="Enter connection maximum bandwidth (in KByte)"
    if (%temp isnum && %temp >= 1 && %connectionbandwidth >= %temp) { set %connectionbandwidth %temp }
    else { set %connectionbandwidth 1 }
    /outputxdccinfo 14Connection maximum bandwidth set to %connectionbandwidth $+ .
    /outputxdccinfo 
  }
  ..Set minimum bandwidth that should be used ( $+ %minbandwidth KByte):{
    set %temp $?="Enter minimum bandwidth usage (in KByte)"
    if (%temp isnum && %temp >= 0 && %maxbandwidth >= %temp) { set %minbandwidth %temp }
    else { set %minbandwidth 0 }
    /outputxdccinfo 14Minimum bandwidth usage set to %minbandwidth $+ .
    /outputxdccinfo 
  }
  ..Set maximum bandwidth that should be used ( $+ %maxbandwidth KByte):{
    set %temp $?="Enter maximum bandwidth usage (in KByte)"
    if (%temp isnum && %temp >= 0 && %temp >= %minbandwidth) { set %maxbandwidth %temp }
    else { set %maxbandwidth 0 }
    /outputxdccinfo 14Maximum bandwidth usage set to %maxbandwidth $+ .
    /outputxdccinfo 
  }
  ..Set maximum number of active download slots ( $+ %maxtransfers $+ ):{
    set %temp $?="Enter number of maximum simultaneous transfers"
    if (%temp isnum && %temp >= 0 && %temp >= %mintransfers) { set %maxtransfers %temp }
    else { set %maxtransfers unlimited }
    /outputxdccinfo 14Maximum number of simultaneous transfers set to %maxtransfers $+ .
    /outputxdccinfo 
  }
  ..Set minimum number of active download slots ( $+ %mintransfers $+ ):{
    set %temp $?="Enter number of minimum simultaneous transfers"
    if (%temp isnum && %temp >= 0 && %maxtransfers >= %temp) { set %mintransfers %temp }
    else { set %mintransfers 0 }
    /outputxdccinfo 14Minimum number of simultaneous transfers set to %mintransfers $+ .
    /outputxdccinfo 
  }
  ..-
  ..Write Debugging Log File ( $+ %debugxdccinfo $+ ):{
    if (%debugxdccinfo == on) {
      if ($?!="Switch Write Debugging Log Function OFF?") { /debugxdccswitch }
    }
    else {
      if ($?!="Switch Write Debugging Log Function ON?") { /debugxdccswitch }
    }
  }
  ..-
  ..Window Preferences ( $+ %infochoise $+ ):
  ...Print to Separate XDCC Info Window:{ 
    set %infochoise special window 
    /outputxdccinfo 14Output window options set to %infochoise $+ .
    /outputxdccinfo 
  }
  ...Print to Active Window:{ 
    set %infochoise active window
    /outputxdccinfo 14Output window options set to %infochoise $+ .
    /outputxdccinfo 
  }
  ...Print to Server Status Window:{
    set %infochoise server status window
    /outputxdccinfo 14Output window options set to %infochoise $+ .
    /outputxdccinfo 
  }
  ...Print to Both Active Window and Separate XDCC Info Window:{
    set %infochoise both active and special windows
    /outputxdccinfo 14Output window options set to %infochoise $+ .
    /outputxdccinfo 
  }
  ...-
  ...Set Separate Output Window Font ( $+ %xdccfont $+ ):/setxdccfont
  ...-
  ...Toggle Bot List View ( $+ %showbotlist $+ ):{
    if ($?!="This will close your separate XDCC window and then reopen it. Proceed?") {
      window -c @XDCC_Info
      if (%showbotlist == OFF) { set %showbotlist ON }
      else { set %showbotlist OFF }
      /outputxdccinfo 3Network14¦7Bot14 list view is now %showbotlist $+ .
      /outputxdccinfo 
    }
  }
  ..-
  ..Timer Options:
  ...Set delay offset for auto resume reactivation ( $+ %resumedelay secs):{ 
    set %delay $?="Set delay for item auto resume script reactivation after resume attempt (in seconds) (this should be at least as high as your DCC GET timeout value to be effective) ( $+ %resumedelay $+ )"
    if (%delay != $null && %delay isnum && %delay >= 0) { 
      set %resumedelay %delay 
      /outputxdccinfo 14Delay for item auto resume script reactivation after attempt set to %resumedelay $+ .
    } 
    else { /outputxdccinfo 4ERROR: No delay entered, timer setting cancelled, negative value, or non-numeric character used. }
    /outputxdccinfo 
  }
  ...Set minimum delay for item resume request ( $+ %minresumedelay secs):{ 
    set %delay $?="Set minimum delay for item auto resume request (in seconds) ( $+ %minresumedelay $+ )"
    if (%delay != $null && %delay isnum && %delay >= 0 && %delay <= %maxresumedelay) { 
      set %minresumedelay %delay 
      /outputxdccinfo 14Minimum delay for item auto resume request set to %minresumedelay $+ .
    }
    else { /outputxdccinfo 4ERROR: No delay entered, timer setting cancelled, negative value, or non-numeric character used, or minimum delay higher than maximum delay. }
    /outputxdccinfo 
  }
  ...Set maximum delay for item resume request ( $+ %maxresumedelay secs):{ 
    set %delay $?="Maximum delay for item auto resume request (in seconds) ( $+ %maxresumedelay $+ )"
    if (%delay != $null && %delay isnum && %delay >= 0 && %delay >= %minresumedelay) { 
      set %maxresumedelay %delay 
      /outputxdccinfo 14Maximum delay for item auto resume request set to %maxresumedelay $+ .
    } 
    else { /outputxdccinfo 4ERROR: No delay entered, timer setting cancelled, negative value, or non-numeric character used, or maximum delay lower than minimum delay. }
    /outputxdccinfo 
  }
  ...Set minimum delay for next queue item request ( $+ %minautoqdelay secs):{ 
    set %delay $?="Minimum delay for next queue item request (in seconds) ( $+ %minautoqdelay $+ )"
    if (%delay != $null && %delay isnum && %delay >= 0 && %delay <= %maxresumedelay) { 
      set %minautoqdelay %delay 
      /outputxdccinfo 14Minimum delay for next queue item request set to %minautoqdelay $+ .
    } 
    else { /outputxdccinfo 4ERROR: No delay entered, timer setting cancelled, negative value, or non-numeric character used, or minimum delay higher than maximum delay. }
    /outputxdccinfo 
  }
  ...Set maximum delay for next queue item request ( $+ %maxautoqdelay secs):{ 
    set %delay $?="Maximum delay for next queue item request (in seconds) ( $+ %maxautoqdelay $+ )"
    if (%delay != $null && %delay isnum && %delay >= 0 && %delay >= %minautoqdelay) { 
      set %maxautoqdelay %delay 
      /outputxdccinfo 14Maximum delay for next queue item request set to %maxautoqdelay $+ .
    }  
    else { /outputxdccinfo 4ERROR: No delay entered, timer setting cancelled, negative value, or non-numeric character used, or maximum delay lower than minimum delay. }
    /outputxdccinfo 
  }
  ...Set minimum delay for re-request item on queue full ( $+ %minqfulldelay secs):{ 
    set %delay $?="Minimum delay for re-request item when queue is full (in seconds) ( $+ %minqfulldelay $+ )"
    if (%delay != $null && %delay isnum && %delay >= 10 && %delay <= %maxqfulldelay) { 
      set %minqfulldelay %delay 
      /outputxdccinfo 14Minimum delay for re-request item on queue full set to %minqfulldelay $+ .
    }  
    else { /outputxdccinfo 4ERROR: No delay entered, timer setting cancelled, value lower than 10 seconds, or non-numeric character used, or maximum delay lower than minimum delay. }
    /outputxdccinfo 
  }
  ...Set maximum delay for re-request item on queue full ( $+ %maxqfulldelay secs):{ 
    set %delay $?="Maximum delay for re-request item when queue is full (in seconds) ( $+ %maxqfulldelay $+ )"
    if (%delay != $null && %delay isnum && %delay >= 10 && %delay >= %minqfulldelay) { 
      set %maxqfulldelay %delay 
      /outputxdccinfo 14Maximum delay for re-request item on queue full set to %maxqfulldelay $+ .
    }  
    else { /outputxdccinfo 4ERROR: No delay entered, timer setting cancelled, value lower than 10 seconds, or non-numeric character used, or maximum delay lower than minimum delay. }
    /outputxdccinfo 
  }
  ...Set minimum delay for re-requesting file on no new connection demand ( $+ %minnoconnect secs):{
    set %delay $?="Set minimum duration for auto re-request on Owner Demands That No New Connections Be Made notice (in seconds) ( $+ %minnoconnect $+ )"
    if (%delay != $null && %delay isnum && %delay >= 0) { 
      set %minnoconnect %delay 
      /outputxdccinfo 14Minimum duration for auto re-request on Owner Demands That No New Connections Be Made notice function set to %minnoconnect $+ .
    }  
    else { /outputxdccinfo 4ERROR: No delay entered, timer setting cancelled, negative value, or non-numeric character used. }
    /outputxdccinfo 
  }
  ...Set maximum delay for re-requesting file on no new connection demand ( $+ %maxnoconnect secs):{
    set %delay $?="Set maximum duration for auto re-request on Owner Demands That No New Connections Be Made notice (in seconds) ( $+ %maxnoconnect $+ )"    
    if (%delay != $null && %delay isnum && %delay >= 0) { 
      set %maxnoconnect %delay 
      /outputxdccinfo 14Maximum duration for auto re-request on Owner Demands That No New Connections Be Made notice function set to %maxnoconnect $+ .
    }  
    else { /outputxdccinfo 4ERROR: No delay entered, timer setting cancelled, negative value, or non-numeric character used. }
    /outputxdccinfo 
  }
  ...Set offset time for auto resume at start ( $+ %startresumeoffset secs):{
    set %delay $?="Set offset duration for auto resume at start function (in seconds) ( $+ %startresumeoffset $+ )"
    if (%delay != $null && %delay isnum && %delay >= 0) { 
      set %startresumeoffset %delay 
      /outputxdccinfo 14Offset duration for auto resume at start function set to %startresumeoffset $+ .
    }  
    else { /outputxdccinfo 4ERROR: No delay entered, timer setting cancelled, negative value, or non-numeric character used. }
    /outputxdccinfo 
  }
  ...-
  ...Set delay offset for auto resume SEND reactivation ( $+ %sendresumedelay secs):{ 
    set %delay $?="Set delay for item auto resume SEND script reactivation after resume attempt (in seconds) (this should be at least as high as your DCC SEND timeout value to be effective) ( $+ %sendresumedelay $+ )"
    if (%delay != $null && %delay isnum && %delay >= 0) { 
      set %sendresumedelay %delay 
      /outputxdccinfo 14Delay for item auto resume script reactivation after attempt set to %sendresumedelay $+ .
    } 
    else { /outputxdccinfo 4ERROR: No delay entered, timer setting cancelled, negative value, or non-numeric character used. }
    /outputxdccinfo 
  }
  ...Set maximum delay for auto resume SEND ( $+ %sendresumetime secs):{
    set %delay $?="Set offset duration for auto resume send function (in seconds) ( $+ %sendresumetime $+ )"
    if (%delay != $null && %delay isnum && %delay >= 0) { 
      set %sendresumetime %delay 
      /outputxdccinfo 14Offset duration for auto resume send function set to %sendresumetime $+ .
    }  
    else { /outputxdccinfo 4ERROR: No delay entered, timer setting cancelled, negative value, or non-numeric character used. }
    /outputxdccinfo 
  }
  ...-
  ...Set delay for updated packfile comparison ( $+ %packchangechecktime secs):{
    set %delay $?="Set delay for old/new packfile comparison (in seconds) ( $+ %packchangechecktime $+ )"
    if (%delay != $null && %delay isnum && %delay >= 0) { 
      set %packchangechecktime %delay 
      /outputxdccinfo 14Offset duration for old/new packfile comparison set to %packchangechecktime $+ .
    }  
    else { /outputxdccinfo 4ERROR: No delay entered, timer setting cancelled, negative value, or non-numeric character used. }
    /outputxdccinfo 
  }
  ...-
  ...Set delay for timed testing for available bandwidth or download slots ( $+ %statisticstime $+ ):{
    set %delay $?="Set delay for timed testing for available bandwidth or download slots (in seconds) ( $+ %statisticstime $+ )"
    if (%delay != $null && %delay isnum && %delay >= 0) { 
      set %statisticstime %delay 
      /timexdcctransferstest
      /outputxdccinfo 14Timed testing for available bandwidth or download slots interval set to %statisticstime $+ .
    }  
    else { /outputxdccinfo 4ERROR: No delay entered, timer setting cancelled, negative value, or non-numeric character used. }
    /outputxdccinfo      
  }
  ...-
  ...Set library file expiration date ( $+ %liblimitdate days):{
    set %delay $?="Enter the number of DAYS after which .pff and .old files should be removed upon Cleaning XDCC Library."
    if (%delay != $null && %delay isnum && %delay >= 0) {
      set %liblimitdate %delay
      /outputxdccinfo 14Expiration date for old .pff and .old files set to %liblimitdate days.
    }
    else { /outputxdccinfo 4ERROR: No delay entered, timer setting cancelled, negative value, or non-numeric character used. }
    /outputxdccinfo 
  }
  ...-
  ...Help on Timers:/TimerXDCChelp
  ..-
  ..Filename Settings:
  ...Set filename for XDCC Trigger Library File ( $+ %xdcctriggerfile $+ ):{
    set %newfilename $replxdccfile($?="Please input new filename for XDCC Trigger Library File")
    if (%newfilename != $null && !$exists($xdccdir $+ \ $+ %newfilename)) {
      .rename $triggerHash $xdccdir $+ \ $+ %newfilename
      set %xdcctriggerfile %newfilename
      /outputxdccinfo 14Set XDCC Trigger Library File name to2 $triggerHash $+ .
    }
    else { /outputxdccinfo 4ERROR:14 File already exists or no filename entered. }
    /outputxdccinfo 
  }
  ...Set filename for Backup Trigger File ( $+ %triggerbackup $+ ):{
    set %newfilename $replxdccfile($?="Please input new filename for Backup Trigger File")
    if (%newfilename != $null && !$exists($xdccdir $+ \ $+ %newfilename)) {
      .rename $triggerbackup $xdccdir $+ \ $+ %newfilename
      set %triggerbackup %newfilename
      /outputxdccinfo 14Set Backup Trigger File name to2 $triggerbackup $+ .
    }
    else { /outputxdccinfo 4ERROR:14 File already exists or no filename entered. }
    /outputxdccinfo 
  }
  ...Set filename for Bot Queue File ( $+ %botqueuefile $+ ):{
    set %newfilename $replxdccfile($?="Please input new filename for Bot Queue File")
    if (%newfilename != $null && !$exists($xdccdir $+ \ $+ %newfilename)) {
      .rename $botqueuefile $xdccdir $+ \ $+ %newfilename
      set %botqueuefile %newfilename
      /outputxdccinfo 14Set Bot Queue File name to2 $botqueuefile $+ .
    }
    else { /outputxdccinfo 4ERROR:14 File already exists or no filename entered. }
    /outputxdccinfo 
  }
  ...Set filename for Temporary Bot Queue File ( $+ %tempbotqueuefile $+ ):{
    set %newfilename $replxdccfile($?="Please input new filename for Temporary Bot Queue File")
    if (%newfilename != $null && !$exists($xdccdir $+ \ $+ %newfilename)) {
      .rename $tempbotqueuefile $xdccdir $+ \ $+ %newfilename
      set %tempbotqueuefile %newfilename
      /outputxdccinfo 14Set Temporary Bot Queue File name to2 $tempbotqueuefile $+ .
    }
    else { /outputxdccinfo 4ERROR:14 File already exists or no filename entered. }
    /outputxdccinfo 
  }
  ...Set filename for Auto Resume Get Disabled Bots File ( $+ %autoresumedisablefile $+ ):{
    set %newfilename $replxdccfile($?="Please input new filename for Auto Resume Get Disabled Bots File")
    if (%newfilename != $null && !$exists($xdccdir $+ \ $+ %newfilename)) {
      .rename $autoresumedisablefile $xdccdir $+ \ $+ %newfilename
      set %autoresumedisablefile %newfilename
      /outputxdccinfo 14Set Auto Resume Get Disabled Bots File name to2 $autoresumedisablefile $+ .
    }
    else { /outputxdccinfo 4ERROR:14 File already exists or no filename entered. }
    /outputxdccinfo 
  }
  ...Set filename for Auto Resume Send Disabled Bots File ( $+ %autoresumesenddisablefile $+ ):{
    set %newfilename $replxdccfile($?="Please input new filename for Auto Resume Send Disabled Bots File")
    if (%newfilename != $null && !$exists($xdccdir $+ \ $+ %newfilename)) {
      .rename $autoresumesenddisablefile $xdccdir $+ \ $+ %newfilename
      set %autoresumesenddisablefile %newfilename
      /outputxdccinfo 14Set Auto Resume Send Disabled Bots File name to2 $autoresumesenddisablefile $+ .
    }
    else { /outputxdccinfo 4ERROR:14 File already exists or no filename entered. }
    /outputxdccinfo 
  }
  ...Set filename for Active Networks File ( $+ %networksendfile $+ ):{
    set %newfilename $replxdccfile($?="Please input new filename for Active Networks File")
    if (%newfilename != $null && !$exists($xdccdir $+ \ $+ %newfilename)) {
      .rename $networksendfile $xdccdir $+ \ $+ %newfilename
      set %networksendfile %newfilename
      /outputxdccinfo 14Set Active Networks File name to2 $networksendfile $+ .
    }
    else { /outputxdccinfo 4ERROR:14 File already exists or no filename entered. }
    /outputxdccinfo 
  }
  ...Set filename for Current XDCC Transfers File ( $+ %xdccsinprogress $+ ):{
    set %newfilename $replxdccfile($?="Please input new filename for Current XDCC Transfers File")
    if (%newfilename != $null && !$exists($xdccdir $+ \ $+ %newfilename)) {
      .rename $xdccsinprogress $xdccdir $+ \ $+ %newfilename
      set %xdccsinprogress %newfilename
      /outputxdccinfo 14Set Current XDCC Transfers File name to2 $xdccsinprogress $+ .
    }
    else { /outputxdccinfo 4ERROR:14 File already exists or no filename entered. }
    /outputxdccinfo 
  }
  ...Set filename for Session Completed Incoming Transfers File ( $+ %xdccsessiongetfile $+ ):{
    set %newfilename $replxdccfile($?="Please input new filename for Session Completed Incoming Transfers File")
    if (%newfilename != $null && !$exists($xdccdir $+ \ $+ %newfilename)) {
      .rename $xdccsessiongetfile $xdccdir $+ \ $+ %newfilename
      set %xdccsessiongetfile %newfilename
      /outputxdccinfo 14Set Session Completed Incoming Transfers File name to2 $xdccsessiongetfile $+ .
    }
    else { /outputxdccinfo 4ERROR:14 File already exists or no filename entered. }
    /outputxdccinfo 
  }
  ...Set filename for Session Completed Outgoing Transfers File ( $+ %xdccsessionsendfile $+ ):{
    set %newfilename $replxdccfile($?="Please input new filename for Session Completed Outgoing Transfers File")
    if (%newfilename != $null && !$exists($xdccdir $+ \ $+ %newfilename)) {
      .rename $xdccsessionsendfile $xdccdir $+ \ $+ %newfilename
      set %xdccsessionsendfile %newfilename
      /outputxdccinfo 14Set Session Completed Outgoing Transfers File name to2 $xdccsessionsendfile $+ .
    }
    else { /outputxdccinfo 4ERROR:14 File already exists or no filename entered. }
    /outputxdccinfo 
  }
  ...Set filename for Last Known Queue Position File ( $+ %xdccqueueposfile $+ ):{
    set %newfilename $replxdccfile($?="Please input new filename for Last Known Queue Position File")
    if (%newfilename != $null && !$exists($xdccdir $+ \ $+ %newfilename)) {
      .rename $xdccqueueposfile $xdccdir $+ \ $+ %newfilename
      set %xdccqueueposfile %newfilename
      /outputxdccinfo 14Set Last Known Queue Position File name to2 $xdccqueueposfile $+ .
    }
    else { /outputxdccinfo 4ERROR:14 File already exists or no filename entered. }
    /outputxdccinfo 
  }
  ...Set filename for Channel Key File ( $+ %chankeyfile $+ ):{
    set %newfilename $replxdccfile($?="Please input new filename for Channel Key File")
    if (%newfilename != $null && !$exists($xdccdir $+ \ $+ %newfilename)) {
      .rename $chankeyfile $xdccdir $+ \ $+ %newfilename
      set %chankeyfile %newfilename
      /outputxdccinfo 14Set Channel Key File name to2 $chankeyfile $+ .
    }
    else { /outputxdccinfo 4ERROR:14 File already exists or no filename entered. }
    /outputxdccinfo 
  }
  ...Set filename for DCCALLOW Network Support File ( $+ %dccallownetworkfile $+ ):{
    set %newfilename $replxdccfile($?="Please input new filename for DCCALLOW Network Support File")
    if (%newfilename != $null && !$exists($xdccdir $+ \ $+ %newfilename)) {
      .rename $dccallownetworkfile $xdccdir $+ \ $+ %newfilename
      set %dccallownetworkfile %newfilename
      /outputxdccinfo 14Set DCCALLOW Network Support File name to2 $dccallownetworkfile $+ .
    }
    else { /outputxdccinfo 4ERROR:14 File already exists or no filename entered. }
    /outputxdccinfo 
  }
  ...Set filename for Alternate Server Method Bot File ( $+ %alternatedccserverfile $+ ):{
    set %newfilename $replxdccfile($?="Please input new filename for Alternate Server Method Bot File")
    if (%newfilename != $null && !$exists($xdccdir $+ \ $+ %newfilename)) {
      .rename $alternatedccserverfile $xdccdir $+ \ $+ %newfilename
      set %alternatedccserverfile %newfilename
      /outputxdccinfo 14Set Alternate Server Method Bot File name to2 $alternatedccserverfile $+ .
    }
    else { /outputxdccinfo 4ERROR:14 File already exists or no filename entered. }
    /outputxdccinfo 
  }
  ...Set filename for Wishlist File ( $+ %xdccwishlist $+ ):{
    set %newfilename $replxdccfile($?="Please input new filename for Wishlist File")
    if (%newfilename != $null && !$exists($xdccdir $+ \ $+ %newfilename)) {
      .rename $xdccwishlist $xdccdir $+ \ $+ %newfilename
      set %xdccwishlist %newfilename
      /outputxdccinfo 14Set Wishlist File name to2 $xdccwishlist $+ .
    }
    else { /outputxdccinfo 4ERROR:14 File already exists or no filename entered. }
    /outputxdccinfo 
  }
  ...Set filename for Debug Log File ( $+ %xdccdebugfile $+ ):{
    set %newfilename $replxdccfile($?="Please input new filename for Debug Log File")
    if (%newfilename != $null && !$exists($xdccdir $+ \ $+ %newfilename)) {
      .rename $xdccdebugfile $xdccdir $+ \ $+ %newfilename
      set %xdccdebugfile %newfilename
      /outputxdccinfo 14Set Debug Log File name to2 $xdccdebugfile $+ .
    }
    else { /outputxdccinfo 4ERROR:14 File already exists or no filename entered. }
    /outputxdccinfo 
  }
  ...-
  ...Set XDCC Script Main directory ( $+ $xdccdir $+ ):{ /movexdccdir }
  ..-
  ..Load Previously Stored XDCC Script Setting Profile:{
    set %xdccprofilename $sfile($xdccdir $+ \ $+ *.set, Enter file name to load profile from, Load)
    if (%xdccprofilename != $null) { /loadxdccscriptsettings $remove(%xdccprofilename,.set) }
  }
  ..Save XDCC Script Setting Profile:{
    set %xdccprofilename $sfile($xdccdir $+ \ $+ *.set, Enter file name to save profile to, Save)
    if (%xdccprofilename != $null) { /savexdccscriptsettings $remove(%xdccprofilename,.set) }
  }
  ..Revert ALL Settings to Default Values:/reverttodefaults
  ..-
  ..Help on These Settings:/SettingsXDCChelp
  .-
  .Help:
  ..Help On Script Workings:/XDCChelp
  ..Help On General Settings:/SettingsXDCChelp 
  ..Help On Timers:/TimerXDCChelp
  ..Show All Help Files:{
    /XDCChelp
    /SettingsXDCChelp
    /TimerXDCChelp
  }
  .Check for New Script Version:/checknewversion
  .About:/versioninfo 
  -
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------



;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
Menu menubar {
  -
  XDCC Get help:/XDCChelp
  -
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------









;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
;--------------------------Remote Triggers Section------------------------
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------









;-------------------------------------------------------------------------
; RAW 401: Processes RAW command for "no such nick/channel" and colors 
; nick black in @XDCC_Info window nicklist if applicable.
;-------------------------------------------------------------------------
raw 401:*No such nick/channel*:{ 
  .timeoff $2 $network
  .write -dw $+ $2 $+ ¦ $+ $network $autoresumedisablefile
  if (%multisourcehandling == on && $triggerHash.exists($network, $2) != $null) {
    if (!$exists($preventdoubleslash($xdccdir $+ \ $+ $replxdccfile($2) $+ .nsnc))) { /trynextsource $network $2 }
    /write -a $preventdoubleslash($xdccdir $+ \ $+ $replxdccfile($2) $+ .nsnc) disabled
    .timer 1 60 .remove $preventdoubleslash($xdccdir $+ \ $+ $replxdccfile($2) $+ .nsnc)
    if ($botliston == TRUE) { //cline -lc1 @XDCC_Info $fline(@XDCC_Info,$2,1,1) }
  }
  elseif ($triggerHash.exists($network, $2) != $null) {
    /outputxdccinfo 4Request failed: Bot7 $2 is currently not connected to3 $network $+ .
    /outputxdccinfo     
    if ($botliston == TRUE) { //cline -lc1 @XDCC_Info $fline(@XDCC_Info,$2,1,1) } 
  }
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------








#groupxdcc on
;-------------------------------------------------------------------------
; This TEXT trigger updates a channel for notice pack listing bots.
;-------------------------------------------------------------------------
on *:TEXT:*For a listing type*/msg * xdcc list*:#:{ /triggerHash.updateChannel $network $nick $chan }
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------


;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
; The first next few TEXT triggers catch a bot's filetrigger, whereas the
; ones after that block catch it's pack listings. 
; The last one catches a message from a bot that you have been removed 
; from queue. It will remove the relevant pack from your queued downloads 
; for that bot.
;-------------------------------------------------------------------------
; TRIGGER CAPTURE SCHEMES:
;-------------------------------------------------------------------------
; Trigger Capture Scheme 1: $network $nick $chan 1 %xdccfilegetcommand
;-------------------------------------------------------------------------
on *:TEXT:*To request a file*type*"*"*:#:{
  if ($nick == $strip($8,burc)) {
    set %xdccfilegetcommand $replxdccpack($7-)
    /triggercapture $network $nick $chan 1 %xdccfilegetcommand
    ; unset %xdccfilegetcommand
  }
}
on *:NOTICE:*To request a file type*"*"*:?:{
  if ($nick == $strip($8,burc)) {
    set %xdccfilegetcommand $replxdccpack($7-)
    if ($triggerHash.getChan($network, $nick) != $null) { /triggercapture $network $nick $triggerHash.getChan($network, $nick) 1N %xdccfilegetcommand }
    else { /triggercapture $network $nick |UNKNOWN| 1N %xdccfilegetcommand }
    ; unset %xdccfilegetcommand
  }
}
on *:TEXT:*To request a file type*"*"*:?:{
  if ($nick == $strip($8,burc)) {
    set %xdccfilegetcommand $replxdccpack($7-)
    if ($triggerHash.getChan($network, $nick) != $null) { /triggercapture $network $nick $triggerHash.getChan($network, $nick) 1PM %xdccfilegetcommand }
    else { /triggercapture $network $nick |UNKNOWN| 1PM %xdccfilegetcommand }
    ; unset %xdccfilegetcommand
  }
}

;-------------------------------------------------------------------------
; Trigger Capture Scheme 2: $network $nick $chan 2 %xdccfilegetcommand
;-------------------------------------------------------------------------
on *:TEXT:* request a file type*..*<number>*..*.•*«*»*•.*:#:{
  if ($nick == $strip($6, burc)) {
    set %xdccfilegetcommand $replxdccpack($5-)
    /triggercapture $network $nick $chan 2 %xdccfilegetcommand
    ; unset %xdccfilegetcommand
  }
}
;-------------------------------------------------------------------------
; Trigger Capture Scheme 3: $network $nick $chan 3 %xdccfilegetcommand
;-------------------------------------------------------------------------
on *:TEXT:*To get a file type*"*"*:#:{
  if ($nick == $strip($8,burc)) {
    set %xdccfilegetcommand $replxdccpack($7-)    
    /triggercapture $network $nick $chan 3 %xdccfilegetcommand
    ; unset %xdccfilegetcommand
  }
}
on *:NOTICE:*To get a file type*"*"*:?:{
  if ($nick == $strip($8,burc)) {
    set %xdccfilegetcommand $replxdccpack($7-)    
    /triggercapture $network $nick |UNKNOWN| 3N %xdccfilegetcommand
    ; unset %xdccfilegetcommand
  }
}
;-------------------------------------------------------------------------
; Trigger Capture Scheme 4: $network $nick $chan 4 %xdccfilegetcommand
;-------------------------------------------------------------------------
on *:TEXT:*Usage*pack number*:#:{
  if (*Send*Queue*Record*Description* !iswm $1-) {
    if ($nick == $strip($3,burc)) {
      if (/msg isin $1- || /ctcp isin $1- || /notice isin $1-) {
        set %xdccfilegetcommand $replace($strip($2-,burc)," **, ,**,,$chr(35) $+ x,$chr(35),$chr(35) $+ $chr(60) $+ pack number $+ $chr(62),$chr(35),",)
        set %xdccfilegetcommand $replace(%xdccfilegetcommand,$chr(60) $+ pack number $+ $chr(62),$chr(35))
        /triggercapture $network $nick $chan 4 %xdccfilegetcommand
        ; unset %xdccfilegetcommand
      }
    }
  }
}
;-------------------------------------------------------------------------
; Trigger Capture Scheme 5: $network $nick $chan 5 %xdccfilegetcommand
;-------------------------------------------------------------------------
on *:TEXT:*Type*XDCC Send*pack number*:#:{
  if ($nick isin $1-) {
    if (/msg $nick isin $1-) { set %xdccfilegetcommand /msg $nick XDCC Send $chr(35) }
    if (/ctcp $nick isin $1-) { set %xdccfilegetcommand /ctcp $nick XDCC Send $chr(35) }
    if (/notice $nick isin $1-) { set %xdccfilegetcommand /notice $nick XDCC Send $chr(35) }
    if (%xdccfilegetcommand != $null) {
      /triggercapture $network $nick $chan 5 %xdccfilegetcommand
      ; unset %xdccfilegetcommand
    }
  }
}
;-------------------------------------------------------------------------
; Trigger Capture Scheme 6: $network $nick $chan 6 %xdccfilegetcommand
;-------------------------------------------------------------------------
on *:TEXT:*«*«*Syntax*DCCALLOW*And*pack*number*:#:{
  if ($nick isin $strip($4,burc) && $nick == $strip($7,burc)) {
    set %xdccfilegetcommand $replxdccpack($6-)
    /triggercapture $network $nick $chan 6 %xdccfilegetcommand
    ; unset %xdccfilegetcommand
  }
}
;-------------------------------------------------------------------------
; Trigger Capture Scheme 7: $network $nick $chan 7 %xdccfilegetcommand
;-------------------------------------------------------------------------
on *:TEXT:*-*Syntax*pack*number*:#:{
  if ($nick == $strip($4,burc)) {
    set %xdccfilegetcommand $replxdccpack($3-)
    /triggercapture $network $nick $chan 7 %xdccfilegetcommand
    ; unset %xdccfilegetcommand
  }
}
;-------------------------------------------------------------------------
; Trigger Capture Scheme 8: $network $nick $chan 8 %xdccfilegetcommand
;-------------------------------------------------------------------------
on *:TEXT:*»*»*receive file*pack*number*:#:{
  if ($nick == $strip($5,burc)) {
    set %xdccfilegetcommand $replxdccpack($4-)
    /triggercapture $network $nick $chan 8 %xdccfilegetcommand
    ; unset %xdccfilegetcommand
  }
}
;-------------------------------------------------------------------------
; Trigger Capture Scheme 9: $network $nick $chan 8 %xdccfilegetcommand
; [To request a file type]: /ctcp Adrienne xdcc send Adrienne's #<number> ‹‹UPP››
;-------------------------------------------------------------------------
on *:TEXT:*request a file type*number*:#:{
  if ($nick == $strip($7,burc)) {
    set %xdccfilegetcommand $replxdccpack($6-)
    /triggercapture $network $nick $chan 9 %xdccfilegetcommand
    ; unset %xdccfilegetcommand
  }
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------







;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
; PACK CAPTURE SCHEMES:
;-------------------------------------------------------------------------
; Pack Capture Scheme 1: $network $nick $chan 1 1 $1-
;-------------------------------------------------------------------------
on *:TEXT:*(*)*[*]*-*-*:#:{ /packcapture $network $nick $chan 1 1 $1- }
on *:NOTICE:*(*)*[*]*-*-*:?:{ 
  if ($triggerHash.exists($network, $nick) != $null) { /packcapture $network $nick $triggerHash.getChan($network, $nick) 1N 1 $1- }
}
;-------------------------------------------------------------------------
; Pack Capture Scheme 2: $network $nick $chan 2 1 $1-
;-------------------------------------------------------------------------
on *:TEXT:*[*]* F*ile*..*..*S*ize*..*..*:#:{ /packcapture $network $nick $chan 2 1 $1- }
;-------------------------------------------------------------------------
; Pack Capture Scheme 3: $network $nick $chan 3 1 $1-
;-------------------------------------------------------------------------
on *:TEXT:*[*]*[*]*-*[*Get*]*:#:{ /packcapture $network $nick $chan 3 1 $1- }
;-------------------------------------------------------------------------
; Pack Capture Scheme 4: $network $nick $chan 4 2 $1-
;-------------------------------------------------------------------------
on *:TEXT:*(*)*-*(*get*)*:#:{ /packcapture $network $nick $chan 4 2 $1- }
;-------------------------------------------------------------------------
; Pack Capture Scheme 5: $network $nick $chan 5 1 $1-
;-------------------------------------------------------------------------
on *:TEXT:*«*»*[*]*(*get*)*:#:{ /packcapture $network $nick $chan 5 1 $1- }
;-------------------------------------------------------------------------
; Pack Capture Scheme 6: $network $nick $chan 6 2 $1-
;-------------------------------------------------------------------------
on *:TEXT:*««*[*]*(*)*-*:#:{ /packcapture $network $nick $chan 6 2 $1- }
;-------------------------------------------------------------------------
; Pack Capture Scheme 7: $network $nick $chan 7 1 $1-
;-------------------------------------------------------------------------
on *:TEXT:*#*x*[*]*:#:{ /packcapture $network $nick $chan 7 1 $1- }
on *:NOTICE:*#*x*[*]*:?:{ 
  if ($triggerHash.exists($network, $nick) != $null) { /packcapture $network $nick $triggerHash.getChan($network, $nick) 7N 1 $1- }
}
;-------------------------------------------------------------------------
; Pack Capture Scheme 8: $network $nick $chan 8 1 $1-
;-------------------------------------------------------------------------
on *:TEXT:*[*]*(*|*)*-*:#:{ /packcapture $network $nick $chan 8 1 $1- }
on *:NOTICE:*[*]*(*|*)*-*:?:{ 
  if ($triggerHash.exists($network, $nick) != $null) { /packcapture $network $nick $triggerHash.getChan($network, $nick) 8N 1 $1- }
}
;-------------------------------------------------------------------------
; Pack Capture Scheme 9: $network $nick $chan 9 1 $1-
;-------------------------------------------------------------------------
on *:TEXT:*(*)*[*]*»*»*-*(*x*)*:#:{ /packcapture $network $nick $chan 9 1 $1- }
;-------------------------------------------------------------------------
; Pack Capture Scheme 10: $network $nick $chan 10 1 $1-
;-------------------------------------------------------------------------
on *:TEXT:.* *x [*] *:#:{ 
  if ($triggerHash.getTrigger($network, $nick) == $null) { /triggercapture $network $nick $chan default /ctcp $nick xdcc get $chr(35) }
  /packcapture $network $nick $chan 10 1 $1- 
}
;-------------------------------------------------------------------------
; Pack Capture Scheme 11: $network $nick $chan 11 1 $1-
;-------------------------------------------------------------------------
on *:TEXT:*«*»*- (*gets)*:#:{ /packcapture $network $nick $chan 11 1 $1- }
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
; Pack Capture Scheme Default: $network $nick $chan default $findtok($1-,$matchtok($1-,$chr(35),1,32),1,32) $1-
;-------------------------------------------------------------------------
on *:TEXT:*#*:#:{ 
  /packcapture $network $nick $chan default $findtok($1-,$matchtok($1-,$chr(35),1,32),1,32) $1- 
  /debuglog $scriptline $+ : ON *:TEXT:*#*:#: TRIGGER: $network $chan $nick $+ : Unclassified $chr(35) text encountered (Attempting pack capture): $1-
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
#groupxdcc end




#groupautoremove on
;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
on *:TEXT:*Removed you from the queue for*"*"*waited*:?:{
  if ($get($nick).status != active && $botliston == TRUE) { //cline -lc7 @XDCC_Info $fline(@XDCC_Info,$nick,1,1) }

  if ($read($getpfffilenm($network, $nick), wnt, * $+ $remvqnotice($7) $+ *)) {
    set %packnum $gettok($read($getpfffilenm($network, $nick), $readn), 1, 32)

    if ($read($getqfilenm($network, $nick), wnt, %packnum)) {
      .removefromq $nick $network %packnum
      /outputxdccinfo You removed $remvqnotice($7) from queue for3 $network $+ ¦7 $+ $nick (Pack number %packnum $+ ), removing that pack from this bot's queue file.
    }
    else { /outputxdccinfo Pack %packnum not in queue for3 $network $+ ¦7 $+ $nick $+ . } 

    ; unset %packnum
  }
  else { /outputxdccinfo You removed a pack from queue for3 $network $+ ¦7 $+ $nick $+ , $remvqnotice($7) (Pack number unknown). }

  if ($exists($xdccqueueposfile) && $read($xdccqueueposfile, wnt, $nick $+ ¦ $+ * $+ ¦ $+ *)) {
    /write -dw $+ $nick $+ ¦* $xdccqueueposfile
  }

  /outputxdccinfo   
}
#groupautoremove end
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------





;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
on *:TEXT:*:#:{
  if ($triggerHash.exists($network, $nick) != $null) {
    /debuglog $scriptline $+ : ON *:TEXT:*:#: TRIGGER: $network $chan $nick $+ : Unknown public msg text by bot: $1-
  }
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
on *:TEXT:*:?:{
  if ($triggerHash.exists($network, $nick) != $null) {
    /debuglog $scriptline $+ : ON *:TEXT:*:?: TRIGGER: $network $nick $+ : Unknown private msg text by bot: $1- 
  }
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------







#groupxdcc on
;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
; The first few NOTICE triggers write information to a %xdccinprogress 
; file about what file transfers are currently active. This info is used 
; by the autoresume function. It notes the botname and packnumber. Note 
; that the second trigger must guess the pack number from the q file. 
; Unfortunatly that's the best i can do for now.
; The sixth-last auto re-requests a file after a few minutes if the bot
; queue is full. The fifth last one is to react to a demand that you be in a 
; channel with the bot to request a pack. It triggers an alias that joins 
; the appropriate channel and re-requests the pack.
; The ones after that will attempt to re-request a pack after a given 
; number of minutes if the owner of the bot has requested that no new 
; connections be made for that time period.
; The next one will process a notice that informs you that you've been 
; added to a bot's queue.
; The next two are meant for the version checker.
; The last ones keep track of (changing) queue positions.
;-------------------------------------------------------------------------
on *:notice:*Sending You Pack*which is*:?:{ 
  if ($botliston == TRUE && $triggerHash.exists($network, $nick)) { //cline -lc9 @XDCC_Info $fline(@XDCC_Info,$nick,1,1) }

  if ($read($xdccsinprogress, s, $nick)) { /write -ds $+ $nick $xdccsinprogress }  
  if ($read($networkfile($network), wn, * $nick *)) { /write -dw"* $nick *" $networkfile($network) } 

  if (!$read($xdccsinprogress, wnt,$nick $replace($5,$chr(35),))) {
    //write -a $xdccsinprogress $nick $replace($5,$chr(35),)
  }
  /outputxdccinfo 12Pack13 $replace($5,$chr(35),) 12sent by7 $nick on3 $network $+ .

  if ($exists($xdccqueueposfile) && $read($xdccqueueposfile, wnt, $nick $+ ¦ $+ * $+ ¦ $+ *)) {
    /write -dw $+ $nick $+ ¦* $xdccqueueposfile
  }
  if ($exists($tempbotqueuefile) && $read($tempbotqueuefile,snt,$nick)) {
    /write -ds $+ $nick $tempbotqueuefile
  }
  .timeoff $nick $network

  if (%botqueuehandling == on && %testnumoftransferspeed == on && %botqueuemode == bandwidth) { .timerxdccstatistics -o 0 %statisticstime /calcxdccstats $timer(xdccstatistics).secs }

  /outputxdccinfo 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
on *:notice:*Sending You Your Queued Pack Which Is*:?:{
  if ($botliston == TRUE && $triggerHash.exists($network, $nick)) { //cline -lc9 @XDCC_Info $fline(@XDCC_Info,$nick,1,1) }

  if ($exists($getqfilenm($network, $nick))) { 
    if (!$read($xdccsinprogress, wnt,$nick $read($getqfilenm($network, $nick), 0))) {
      //write -a $xdccsinprogress $nick $read($getqfilenm($network, $nick), 0)
    }
    /outputxdccinfo 12Pack13 $gettok($read($getqfilenm($network, $nick), 0),1,32) 12sent by7 $nick on3 $network (6Pack number had to be guessed from queue file and will be used by autoresume).
  }
  else { 
    /outputxdccinfo 12Pack sent by7 $nick on3 $network (4Pack number unknown $+ $chr(58) no autoresume possible). 
  }

  if ($exists($xdccqueueposfile) && $read($xdccqueueposfile, wnt, $nick $+ ¦ $+ * $+ ¦ $+ *)) {
    /write -dw $+ $nick $+ ¦* $xdccqueueposfile
  }
  if ($exists($tempbotqueuefile) && $read($tempbotqueuefile,snt,$nick)) {
    /write -ds $+ $nick $tempbotqueuefile
  }

  .timeoff $nick $network

  if (%botqueuehandling == on && %testnumoftransferspeed == on && %botqueuemode == bandwidth) { .timerxdccstatistics -o 0 %statisticstime /calcxdccstats $timer(xdccstatistics).secs }

  /outputxdccinfo 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
on *:notice:*DCC Send*(*)*:?:{
  if ($botliston == TRUE && $triggerHash.exists($network, $nick)) { //cline -lc9 @XDCC_Info $fline(@XDCC_Info,$nick,1,1) }

  if ($read($getpfffilenm($network, $nick), wnt, * $remvextent($3) *)) {
    set %readn $readn
    if (!$read($xdccsinprogress, wnt,$nick $gettok($read($getpfffilenm($network, $nick), %readn),1,32))) {
      //write -a $xdccsinprogress $nick $gettok($read($getpfffilenm($network, $nick), %readn),1,32)
    }
    /outputxdccinfo 12Pack13 $gettok($read($getpfffilenm($network, $nick), %readn),1,32) 12sent by7 $nick on3 $network (6Pack number had to be guessed from pack listing file and will be used by autoresume).
    ; unset %readn
  }
  elseif ($exists($getqfilenm($network, $nick))) {
    /outputxdccinfo 12Pack13 $gettok($read($getqfilenm($network, $nick), 0),1,32) 12sent by7 $nick on3 $network (6Pack number had to be guessed from queue file and will be used by autoresume).
  }
  else { 
    /outputxdccinfo 12Pack sent by7 $nick on3 $network (4Pack number unknown $+ $chr(58) no autoresume possible). 
  }

  if ($exists($xdccqueueposfile) && $read($xdccqueueposfile, wnt, $nick $+ ¦ $+ * $+ ¦ $+ *)) {
    /write -dw $+ $nick $+ ¦* $xdccqueueposfile
  }
  if ($exists($tempbotqueuefile) && $read($tempbotqueuefile,snt,$nick)) {
    /write -ds $+ $nick $tempbotqueuefile
  }

  .timeoff $nick $network

  if (%botqueuehandling == on && %testnumoftransferspeed == on && %botqueuemode == bandwidth) { .timerxdccstatistics -o 0 %statisticstime /calcxdccstats $timer(xdccstatistics).secs }

  /outputxdccinfo   
}
#groupxdcc end
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------



;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
#groupautoxdccresume on
on *:notice:*All Slots Full*queue*Full*Try Again Later*:?:{ 
  if ($get($nick).status != active && $botliston == TRUE) { //cline -lc5 @XDCC_Info $fline(@XDCC_Info,$nick,1,1) }
  /queuefullrerequest $network $nick 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
on *:notice:*XDCC*Sorry*all send and queue slots are full*:?:{ 
  if ($triggerHash.exists($network, $nick) && $get($nick).status != active && $botliston == TRUE) { //cline -lc5 @XDCC_Info $fline(@XDCC_Info,$nick,1,1) }
  /queuefullrerequest $network $nick 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
on *:notice:*Sorry*there are too many send in progress right now and all the queue slots are in use*:?:{ 
  if ($triggerHash.exists($network, $nick) && $get($nick).status != active && $botliston == TRUE) { //cline -lc5 @XDCC_Info $fline(@XDCC_Info,$nick,1,1) }
  /queuefullrerequest $network $nick 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
on *:notice:*sorry*all*queue slots are in use*:?:{
  if ($triggerHash.exists($network, $nick) && $get($nick).status != active && $botliston == TRUE) { //cline -lc5 @XDCC_Info $fline(@XDCC_Info,$nick,1,1) }
  /queuefullrerequest $network $nick 
}
#groupautoxdccresume end
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
on *:notice:*All Slots Full*queue*Full*Try Again Later*:?:{
  /outputxdccinfo 13Queue full for bot3 $network $+ ¦7 $+ $nick $+ , 4NOT auto re-requesting.
  /outputxdccinfo 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
on *:notice:*XDCC*Sorry*all send and queue slots are full*:?:{
  /outputxdccinfo 13Queue full for bot3 $network $+ ¦7 $+ $nick $+ , 4NOT auto re-requesting.
  /outputxdccinfo 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
on *:notice:*Sorry*there are too many send in progress right now and all the queue slots are in use*:?:{
  /outputxdccinfo 13Queue full for bot3 $network $+ ¦7 $+ $nick $+ , 4NOT auto re-requesting.
  /outputxdccinfo 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
on *:notice:*sorry*all*queue slots are in use*:?:{
  /outputxdccinfo 13Queue full for bot3 $network $+ ¦7 $+ $nick $+ , 4NOT auto re-requesting.
  /outputxdccinfo 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------

;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
#groupautojoinxdcc on
on *:notice:*SEND denied*must be on*known channel*request*:?:{
  if ($triggerHash.exists($network, $nick) && $get($nick).status != active && $botliston == TRUE) { //cline -lc13 @XDCC_Info $fline(@XDCC_Info,$nick,1,1) }

  if ($triggerHash.exists($network, $nick) && $triggerHash.getChan($network, $nick) != |UNKNOWN|) {
    set %rand.bt $rand(3, 30)
    /outputxdccinfo 7 $+ $nick 5refused to send you a pack because you are not in the same channel. 3Joining12 $triggerHash.getChan($network, $nick) in %rand.bt seconds.

    if ($me !ison $triggerHash.getChan($network, $nick)) {
      /timerxdccjoin $+ $nick $+ $triggerHash.getChan($network, $nick) 1 %rand.bt /timejoin1 $nick $network
    }
    else { /outputxdccinfo 4ERROR: Already in channel listed for $nick $+ . Bot most likely disabled or malfunctioning. }

    ; unset %rand.bt
  }
  else { 
    /outputxdccinfo 7 $+ $nick 5refused to send you a pack because you are not in the same channel. Make sure you have that channel on autojoin (No channels linked to7 $nick $+ ). 
  }
  /outputxdccinfo 
}

#groupautojoinxdcc end
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
on *:notice:*SEND denied*must be on*known channel*request*:?:{
  if ($triggerHash.getChan($network, $nick)) {
    /outputxdccinfo 7 $+ $nick 5refused to send you a pack because you are not in the same channel. Autojoin function OFF. Make sure you have that channel on autojoin on connect, or have the script autojoin function ON if you want to prevent this from happening in the future. Suggested channel:12 $triggerHash.getChan($network, $nick) $+ .
  }
  else { 
    /outputxdccinfo 7 $+ $nick 5refused to send you a pack because you are not in the same channel. Make sure you have that channel on autojoin (No channels linked to7 $nick $+ ). 
  }
  /outputxdccinfo 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------


#groupnonewconnects on
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
on *:notice:*The Owner Has Requested That No New Connections Are Made In The Next * Minutes:?:{
  if ($triggerHash.exists($network, $nick) && $get($nick).status != active && $botliston == TRUE) { //cline -lc6 @XDCC_Info $fline(@XDCC_Info,$nick,1,1) }

  set %timeoffset $calc($calc($15 * 60) + $rand(%minnoconnect,%maxnoconnect))

  if ($exists($getqfilenm($network, $nick))) {
    set %trigger $triggerHash.getTrigger($network, $nick) $+ $read($getqfilenm($network, $nick), tn, 1)
    /outputxdccinfo 4Pack send 13 $gettok($read($getqfilenm($network, $nick), 0),1,32) 4refused by7 $nick on3 $network (6Pack number had to be guessed from queue file and will be used by autoresume). 4Reason: The bot owner has requested that no new connections be made for the next $15 minutes. 3Re-requesting file in %timeoffset seconds (2 $+ %trigger $+ ).
  }
  else { 
    /outputxdccinfo 4Pack send refused by7 $nick on3 $network (4Pack number unknown $+ $chr(58) no autoresume possible). 4Reason: The bot owner has requested that no new connections be made for the next $15 minutes. 
  }
  if ($exists($tempbotqueuefile) && $read($tempbotqueuefile,snt,$nick)) {
    /write -ds $+ $nick $tempbotqueuefile
  }

  if ($gettok(%trigger, 1, 32) == /msg) { /timerxdccnonewconnect $+ $nick $+ 2 -o 1 %timeoffset /msg $gettok(%trigger, 2-, 32) }
  elseif ($gettok(%trigger, 1, 32) == /ctcp) { /timerxdccnonewconnect $+ $nick $+ 2 -o 1 %timeoffset /ctcp $gettok(%trigger, 2-, 32) }
  elseif ($gettok(%trigger, 1, 32) == /notice) { /timerxdccnonewconnect $+ $nick $+ 2 -o 1 %timeoffset /notice $gettok(%trigger, 2-, 32) }
  else { /outputxdccinfo 4ERROR: Unknown trigger type ( $+ %trigger $+ ). }
  .timer -o 1 %timeoffset /outputxdccinfo 4Re-requesting d/l after %timeoffset seconds:3 $network $+ ¦7 $+ $nick (owner requested that no connections be made prior to now).
  .timer -o 1 %timeoffset /outputxdccinfo 

  /outputxdccinfo 
  ; unset %timeoffset %trigger
}
#groupnonewconnects end
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
on *:notice:*The Owner Has Requested That No New Connections Are Made In The Next * Minutes:?:{
  /outputxdccinfo 4Pack send refused by7 $nick on3 $network $+ . 4Reason: The bot owner has requested that no new connections be made for the next $15 minutes. 4Not Retrying Request: Auto Retry on No New Connections Notice OFF.
  /outputxdccinfo 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------





;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
on *:notice:*All Slots Full, Added you to the main queue in position*:?:{
  if ($triggerHash.exists($network, $nick) && $get($nick).status != active && $botliston == TRUE) { //cline -lc3 @XDCC_Info $fline(@XDCC_Info,$nick,1,1) }

  if ($strip($remove($13,$chr(35),$chr(46),$chr(44)),burc) isnum) {
    /outputxdccinfo 12Pack succesfully queued for7 $nick on3 $network in XDCC bot's queue at position13 $strip($remove($13,$chr(35),$chr(46),$chr(44)),burc) $+ .
  }
  else {
    /outputxdccinfo 12Pack succesfully queued for7 $nick on3 $network $+ . 
  }
  if ($exists($tempbotqueuefile) && $read($tempbotqueuefile,snt,$nick)) {
    /write -ds $+ $nick $tempbotqueuefile
  }
  /outputxdccinfo 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
on *:notice:*XDCC*Adding your file to queue slot*The file will send when the next send slot is open*:?:{
  if ($triggerHash.exists($network, $nick) && $get($nick).status != active && $botliston == TRUE) { //cline -lc3 @XDCC_Info $fline(@XDCC_Info,$nick,1,1) }

  if ($strip($remove($8,$chr(35),$chr(46),$chr(44)),burc) isnum) {
    /outputxdccinfo 12Pack succesfully queued for7 $nick on3 $network in XDCC bot's queue at position13 $strip($remove($8,$chr(35),$chr(46),$chr(44)),burc) $+ .
  }
  else {
    /outputxdccinfo 12Pack succesfully queued for7 $nick on3 $network $+ . 
  }
  if ($exists($tempbotqueuefile) && $read($tempbotqueuefile,snt,$nick)) {
    /write -ds $+ $nick $tempbotqueuefile
  }
  /outputxdccinfo 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
on *:notice:*Queuing*(*)*.*It has been placed in queue slot *, it will send when sends are available.*:?:{
  if ($triggerHash.exists($network, $nick) && $get($nick).status != active && $botliston == TRUE) { //cline -lc3 @XDCC_Info $fline(@XDCC_Info,$nick,1,1) }

  if ($strip($remove($11,$chr(35),$chr(46),$chr(44)),burc) isnum) {
    /outputxdccinfo 12Pack succesfully queued for7 $nick on3 $network in XDCC bot's queue at position13 $strip($remove($11,$chr(35),$chr(46),$chr(44)),burc) $+ .
  }
  else {
    /outputxdccinfo 12Pack succesfully queued for7 $nick on3 $network $+ . 
  }
  if ($exists($tempbotqueuefile) && $read($tempbotqueuefile,snt,$nick)) {
    /write -ds $+ $nick $tempbotqueuefile
  }
  /outputxdccinfo 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------


#groupcheckversion on
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
on *:notice:Your version is up to date.:?:{
  /outputxdccinfo 14 $+ $nick replied to versioncheck. Your version is up to date.
  /outputxdccinfo 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
on *:notice:New XDCC script version available.:?:{
  /outputxdccinfo 14 $+ $nick replied to versioncheck. Your version is outdated. New version available.

  /timerxdccversionrequest1 1 0 /timeversionrequest $nick
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
#groupcheckversion end




;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
on *:notice:*Server Notice*This server is using an alternate send method, please make sure your DCC Server is active and set to port*/dccserver * on *:?:{
  if ($remove($strip($23,burc),$chr(46)) == $remove($strip($27,burc),$chr(46)) && $strip($24,burc) == /dccserver) {
    if ($exists($alternatedccserverfile) && $read($alternatedccserverfile, snt,$network $nick)) { /write -ds $+ $network $nick $alternatedccserverfile }
    /write -a alternatedccserverfile $network $nick $remove($strip($24-),$chr(46))
    set %rand.bt $calc(30 + $rand(%minresumedelay, %maxresumedelay))
    .timerxdccautoresume 1 %rand.bt /alternatesendcheck $network $nick
    /outputxdccinfo 7 $+ $nick 8 on 3 $+ $network 8requires an alternate DCC server setting. Setting dcc server in %rand.bt seconds ( $+ $remove($strip($24-),$chr(46)) $+ ).
    /outputxdccinfo 
  }
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------




#grouptrackqueuepos on
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
on *:notice:*You have been queued for*for*currently in main queue position*Estimated remaining time is*or*To remove yourself type*:?:{
  if ($triggerHash.exists($network, $nick) && $get($nick).status != active && $botliston == TRUE) { //cline -lc3 @XDCC_Info $fline(@XDCC_Info,$nick,1,1) }

  set %strippedtrigger $replace($strip($1-,burc),You have been queued for,, for ",¦, currently in main queue position,¦, Estimated remaining time is,¦,To remove yourself type ",¦,",,$chr(44),$chr(32),$chr(32) $+ $chr(32),$chr(32),$chr(32) $+ ¦,¦,¦ $+ $chr(32),¦)
  set %presentqueuepos $replace($gettok(%strippedtrigger,3,166),$chr(46),)
  set %queuedtime $replace($gettok(%strippedtrigger,1,166),$chr(46),)
  set %remainingtime $replace($gettok(%strippedtrigger,4,166),$chr(46),)
  set %removetrigger $replace($gettok(%strippedtrigger,5,166),$chr(46),)
  set %packdescript $gettok(%strippedtrigger,2,166)

  if (!$exists($xdccqueueposfile) || !$read($xdccqueueposfile, wnt, $nick $+ ¦ $+ $gettok(%presentqueuepos,1,32) * $+ ¦ $+ %removetrigger)) {
    .write -dw $+ $nick $+ ¦* $xdccqueueposfile
    .write -a $xdccqueueposfile $nick $+ ¦ $+ %presentqueuepos $+ ¦ $+ %removetrigger
    /outputxdccinfo 5Bot $nick queue position changed. Queued for %queuedtime $+ , present position %presentqueuepos $+ . Estimated remaining time %remainingtime $+ . Pack description: %packdescript $+ . To remove yourself type " $+ %removetrigger $+ " on the appropriate network.
    /outputxdccinfo 
  }

  .timeoff $nick $network

  ; unset %strippedtrigger %presentqueuepos %queuedtime %remainingtime %removetrigger %packdescript
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
on *:notice:*You have been queued for*currently in main queue position*Estimated remaining time is*or*To remove yourself type*:?:{
  if ($triggerHash.exists($network, $nick) && $get($nick).status != active && $botliston == TRUE) { //cline -lc3 @XDCC_Info $fline(@XDCC_Info,$nick,1,1) }

  set %strippedtrigger $replace($strip($1-,burc),You have been queued for,, for ",¦, currently in main queue position,¦, Estimated remaining time is,¦,To remove yourself type ",¦,",,$chr(46),$chr(32),$chr(44),$chr(32),$chr(32) $+ $chr(32),$chr(32),$chr(32) $+ ¦,¦,¦ $+ $chr(32),¦)
  set %presentqueuepos $replace($gettok(%strippedtrigger,2,166),$chr(46),)
  set %queuedtime $replace($gettok(%strippedtrigger,1,166),$chr(46),)
  set %remainingtime $replace($gettok(%strippedtrigger,3,166),$chr(46),)
  set %removetrigger $replace($gettok(%strippedtrigger,4,166),$chr(46),)

  if (!$exists($xdccqueueposfile) || !$read($xdccqueueposfile, wnt, $nick $+ ¦ $+ $gettok(%presentqueuepos,1,32) * $+ ¦ $+ %removetrigger)) {
    .write -dw $+ $nick $+ ¦* $xdccqueueposfile
    .write -a $xdccqueueposfile $nick $+ ¦ $+ %presentqueuepos $+ ¦ $+ %removetrigger
    /outputxdccinfo 5Bot $nick queue position changed. Queued for %queuedtime $+ , present position %presentqueuepos $+ . Estimated remaining time %remainingtime $+ . To remove yourself type " $+ %removetrigger $+ " on the appropriate network.
    /outputxdccinfo 
  }

  .timeoff $nick $network

  ; unset %strippedtrigger %presentqueuepos %queuedtime %remainingtime %removetrigger
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
#grouptrackqueuepos end




;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
;on *:notice:*:?:{
;  if ($triggerHash.exists($network, $nick) != $null) {
;    /debuglog $scriptline $+ : ON *:NOTICE:*:?: TRIGGER: $network $nick $+ : Unknown notice sent by bot: $1-
;  }
;}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------








#groupautoxdccq on
;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
; If autoqueue is on:
; If a file is succesfully received, this trigger checks if a queue file 
; exists for the given bot, and if so, queues up the next packnumber in 
; the .q file after running a timer with a random number of seconds 
; between 1 sec and 2 mins. It also removes the completed transfer from 
; the active transfers file and adds newly completed downloads to the 
; completed transfers file.
;-------------------------------------------------------------------------
; If Autoqueue is off: 
; When a file is succesfully received, this trigger removes that transfer 
; from the active transfers file and adds the newly completed download to 
; the completed transfers file.
;-------------------------------------------------------------------------
on *:FILERCVD:*:{
  if ($botliston == TRUE && $triggerHash.exists($network, $nick)) {
    if ($me ison $triggerHash.getChan($network, $nick) && $nick ison $triggerHash.getChan($network, $nick)) { //cline -lc7 @XDCC_Info $fline(@XDCC_Info,$nick,1,1) }
    elseif ($server == $null && $network == $triggerHash.network($nick)) { //cline -lc14 @XDCC_Info $fline(@XDCC_Info,$nick,1,1) }
    elseif ($network == $triggerHash.network($nick)) { //cline -lc10 @XDCC_Info $fline(@XDCC_Info,$nick,1,1) }
  }

  if ($read($xdccsinprogress, s, $nick)) { /write -ds $+ $nick $xdccsinprogress }  
  if ($read($networkfile($network), wnt, * $nick *)) { 
    if ($lines($networkfile($network)) <= 1) { .remove $networkfile($network) }
    else { /write -dw"* $nick *" $networkfile($network) }
  }  

  /outputxdccinfo 6Dequeueing all packs for3 $network $+ ¦7 $nick matching13 * $+ $remvextent($nopath($filename)) $+ *, or first pack in queue if no matching packs are found.
  if ($read($getpfffilenm($network, $nick),wtn, * $+ $remvextent($nopath($filename)) $+ *)) {
    %i = 0
    var %llen = $lines($getpfffilenm($network, $nick))
    while (%i <= %llen) {
      if (* $+ $remvextent($nopath($filename)) $+ * iswm $read($getpfffilenm($network, $nick),%i)) {
        .removefromq $nick $network $gettok($read($getpfffilenm($network, $nick), %i),1, 32)
      } 
      inc %i
    }
    unset %llen
    if ($lines($getqfilenm($network, $nick)) < 1) { .remove $getqfilenm($network, $nick) }
    ; unset %i
  }
  else {
    if ($lines($getqfilenm($network, $nick)) <= 1) { .remove $getqfilenm($network, $nick) }
    else { /write -dl1 $getqfilenm($network, $nick) }
  }

  if (%clearallqueuesoncomplete == on) { /removepackfromallbots $replxdccfile($nick $network) $filename }


  if (%botqueuehandling == on && $shouldstartmaxbotq == $null) {

    ;-------------------------------------------------------------------------------------------
    ;If the maximum number of sends is in progress, add the next queue for this bot to the temp
    ;bot queue. If no queue items exist, the script will start a normal bot queue on next file
    ;completion.
    ;-------------------------------------------------------------------------------------------

    if ($exists($getqfilenm($network, $nick))) { 
      /write -a $tempbotqueuefile $nick $read($getqfilenm($network, $nick), t, 0) 
      /outputxdccinfo 9Transfer Completed: Got2 $replace($filename,$nopath($filename),13 $+ $nopath($filename)) from7 $nick $+ . $activesends transfers active, $activeautoresumesends transfers waiting for auto resume: 4Maximum send slots in use ( $+ %maxtransfers $+ ): Adding7 $nick to temporary botqueue.
    }
    else {
      /outputxdccinfo 9Transfer Completed: Got2 $replace($filename,$nopath($filename),13 $+ $nopath($filename)) from7 $nick $+ , no more queues exist for this bot. $activesends transfers active, $%activeautoresumesends transfers waiting for auto resume: 4Maximum send slots in use ( $+ %maxtransfers $+ ): Waiting for next XDCC Get to complete, then moving on to next bot in Bot Queue file..
    }
  }
  else {
    if (%botqueuehandling == on && $read($tempbotqueuefile, nt, 1) != $null) {

      ;-------------------------------------------------------------------------------------------
      ;First we attempt the Temporary bot queue. if there is a temp bot queue file, take the next 
      ;bot in line and start it's queue, and remove it from the temp bot queue.
      ;-------------------------------------------------------------------------------------------

      set %rand.bt $rand(%minautoqdelay, %maxautoqdelay)
      /outputxdccinfo 9Transfer Completed: Got2 $replace($filename,$nopath($filename),13 $+ $nopath($filename)) from7 $nick $+ . Temporary Bot Queue exists. Moving to next bot in Temporary Bot Queue file in %rand.bt seconds (7 $+ $read($tempbotqueuefile, 1) $+ ).

      .timerxdccstartbotq $+ $gettok($read($tempbotqueuefile,1),1,32) $+ 3 1 %rand.bt /startqueue $gettok($read($tempbotqueuefile, nt, 1),1,32)
      if (!$read($xdccsinprogress,snt,$nick) && $exists($getqfilenm($network, $nick))) { /write -a $xdccsinprogress $nick $read($getqfilenm($network, $nick), t, 0) }
      /write -dl1 $tempbotqueuefile
    }
    elseif ($exists($getqfilenm($network, $nick))) {

      ;-------------------------------------------------------------------------------------------
      ;If there is no temp bot queue, move to the next queued item for this bot.
      ;-------------------------------------------------------------------------------------------

      set %trigger $triggerHash.getTrigger($network, $nick) $+ $read($getqfilenm($network, $nick), t, 0)
      set %rand.bt $rand(%minautoqdelay, %maxautoqdelay)

      /outputxdccinfo 9Transfer Completed: Got2 $replace($filename,$nopath($filename),13 $+ $nopath($filename)) from7 $nick $+ . 3Auto-requesting next pack in %rand.bt seconds ( $+ %trigger $+ ).

      if ($gettok(%trigger, 1, 32) == /msg) { /timerxdccstartq $+ $nick $+ 2 1 %rand.bt /msg $gettok(%trigger, 2-, 32) }
      elseif ($gettok(%trigger, 1, 32) == /ctcp) { /timerxdccstartq $+ $nick $+ 2 1 %rand.bt /ctcp $gettok(%trigger, 2-, 32) }
      elseif ($gettok(%trigger, 1, 32) == /notice) { /timerxdccstartq $+ $nick $+ 2 1 %rand.bt /notice $gettok(%trigger, 2-, 32) }
      else { /outputxdccinfo 4ERROR: Unknown trigger type ( $+ %trigger $+ ) }

      if (!$read($xdccsinprogress, wnt,$nick $read($getqfilenm($network, $nick), t, 0))) {
        //write -a $xdccsinprogress $nick $read($getqfilenm($network, $nick), t, 0)
      }
      ; unset %trigger %rand.bt
    }
    elseif (%botqueuehandling == on) {

      ;-------------------------------------------------------------------------------------------
      ;Here we must move to the bot queue. if there is a bot queue file, take the next bot in line 
      ;and start it's queue, and remove it from the bot queue.
      ;-------------------------------------------------------------------------------------------

      /removebotqueue $nick
      if ($exists($botqueuefile)) {
        set %rand.bt $rand(%minautoqdelay, %maxautoqdelay)

        /outputxdccinfo 9Transfer Completed: Got2 $replace($filename,$nopath($filename),13 $+ $nopath($filename)) from7 $nick $+ , no more queues exist for this bot. Moving to next bot in Bot Queue file in %rand.bt seconds (7 $+ $read($botqueuefile, 1) $+ ).
        .timerxdccstartbotq $+ $read($botqueuefile, 1) $+ 1 1 %rand.bt /startqueue $read($botqueuefile, 1)

        ; unset %rand.bt
      }
      else { 
        /outputxdccinfo 9Transfer Completed: Got2 $replace($filename,$nopath($filename),13 $+ $nopath($filename)) from7 $nick $+ , no more queues exist for this bot. No Bot Queue file exists. 
      }
    }
    else { /outputxdccinfo 9Transfer Completed: Got2 $replace($filename,$nopath($filename),13 $+ $nopath($filename)) from7 $nick $+ , no more queues exist for this bot. 4Bot Queue Handling OFF. }
  }

  if (!$exists($xdccsessiongetfile) || !$read($xdccsessiongetfile, wnt, 7 $+ $nick $+ 2 $replace($filename,$nopath($filename),13 $+ $nopath($filename)) $+ 15 [*])) {
    /write -a $xdccsessiongetfile 7 $+ $nick $+ 2 $replace($filename,$nopath($filename),13 $+ $nopath($filename)) $+ 15 $asctime([dd/mm/yyyy][HH:nn:ss])
  }

  if ($exists($xdccqueueposfile) && $read($xdccqueueposfile, wnt, $nick $+ ¦ $+ * $+ ¦ $+ *)) {
    /write -dw $+ $nick $+ ¦* $xdccqueueposfile
  }

  if (%botqueuehandling == on && testnumoftransferspeed == on && %botqueuemode == bandwidth) { .timerxdccstatistics -o 0 %statisticstime /calcxdccstats $timer(xdccstatistics).secs }

  inc %filesgettotal

  /outputxdccinfo 
}
#groupautoxdccq end
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
on *:FILERCVD:*:{
  if ($botliston == TRUE && $triggerHash.exists($network, $nick)) {
    if ($me ison $triggerHash.getChan($network, $nick) && $nick ison $triggerHash.getChan($network, $nick)) { //cline -lc7 @XDCC_Info $fline(@XDCC_Info,$nick,1,1) }
    elseif ($server == $null && $network == $triggerHash.network($nick)) { //cline -lc14 @XDCC_Info $fline(@XDCC_Info,$nick,1,1) }
    else { //cline -lc10 @XDCC_Info $fline(@XDCC_Info,$nick,1,1) }
  }
  if ($read($xdccsinprogress, s, $nick)) { /write -ds $+ $nick $xdccsinprogress }  
  if ($read($networkfile($network), wn, * $nick *)) { 
    if ($lines($networkfile($network)) <= 1) { .remove $networkfile($network) }
    else { /write -dw"* $nick *" $networkfile($network) }
  } 

  /outputxdccinfo 6Dequeueing all packs for3 $network $+ ¦7 $nick matching13 * $+ $remvextent($nopath($filename)) $+ *, or first pack in queue if no matching packs are found.
  if ($read($getpfffilenm($network, $nick),wtn, * $+ $remvextent($nopath($filename)) $+ *)) {
    set %i 0
    var %llen = $lines($getpfffilenm($network, $nick))
    while (%i <= %llen) {
      if (* $+ $remvextent($nopath($filename)) $+ * iswm $read($getpfffilenm($network, $nick),%i)) {
        .removefromq $nick $network $gettok($read($getpfffilenm($network, $nick), %i),1, 32)
      } 
      inc %i
    }
    unset %llen
    ; unset %i
  }
  else {
    if ($lines($getqfilenm($network, $nick)) <= 1) { .remove $getqfilenm($network, $nick) }
    else { /write -dl1 $getqfilenm($network, $nick) }
  }

  if (%clearallqueuesoncomplete == on) { /removepackfromallbots $replxdccfile($nick $network) $filename }

  if (!$exists($xdccsessiongetfile) || !$read($xdccsessiongetfile, wnt, 7 $+ $nick $+ 2 $replace($filename,$nopath($filename),13 $+ $nopath($filename)) $+ 15 [*])) {
    /write -a $xdccsessiongetfile 7 $+ $nick $+ 2 $replace($filename,$nopath($filename),13 $+ $nopath($filename)) $+ 15 $asctime([dd/mm/yyyy][HH:nn:ss])
  }

  if ($exists($xdccqueueposfile) && $read($xdccqueueposfile, wnt, $nick $+ ¦ $+ * $+ ¦ $+ *)) {
    /write -dw $+ $nick $+ ¦* $xdccqueueposfile
  }

  inc %filesgettotal

  /outputxdccinfo 9Transfer Completed: Got2 $replace($filename,$nopath($filename),13 $+ $nopath($filename)) from7 $nick $+ . Autoqueue OFF.
  /outputxdccinfo 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------








#groupautoxdccresume on
;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
; If autoresume is on:
; This trigger detects a failed transfer and sets a timer between 1 and 30
; seconds. After the timer finishes, the trigger and packnumber are sent 
; to the bot in question (if that bot is in the library) to get a resume. 
; It then deactivates the autoresume for that bot temporarily by writing 
; it to a "disabled bots" file. This is because a fileserver that keeps 
; timing out may cause the script to infinitly request the file, which
; will look VERY suspicious to any bot owner.
;-------------------------------------------------------------------------
; If autoresume is not on:
; Remove a failed download from the currently active transfers list.
;-------------------------------------------------------------------------
on *:GETFAIL:*:{
  if ($triggerHash.exists($network, $nick) && $botliston == TRUE) { //cline -lc4 @XDCC_Info $fline(@XDCC_Info,$nick,1,1) } 
  /outputxdccinfo 4GET fail from7 $nick on3 $network occured.

  if (!$exists($autoresumedisablefile) || !$read($autoresumedisablefile, wnt, $nick $+ ¦ $+ $network)) {
    if ($triggerHash($network, $nick)) {
      set %trigger $null
      if ($read($xdccsinprogress , s, $nick)) {
        set %trigger $triggerHash.getTrigger($network, $nick) $+ $read($xdccsinprogress , s, $nick)
      }
      elseif ($exists($getqfilenm($network, $nick))) {
        set %trigger $triggerHash.getTrigger($network, $nick) $+ $read($getqfilenm($network, $nick), nt, 1)
      }

      if (%trigger != $null) {
        set %rand.bt $rand(%minresumedelay ,%maxresumedelay)

        if ($exists($dccallownetworkfile) && $read($dccallownetworkfile,wnt,$network)) { /DCCALLOW + $+ $nick }
        if ($exists($alternatedccserverfile) && $read($alternatedccserverfile,snt,$network $nick)) { $read($alternatedccserverfile,snt,$network $nick) }

        /outputxdccinfo I 4failed to get the file2 $replace($filename,$nopath($filename),13 $+ $nopath($filename) $+ ) from7 $nick ( $+ %trigger $+ ), 3re-requesting in %rand.bt seconds
        if ($gettok(%trigger, 1, 32) == /msg) { /timerxdccautoresume $+ $nick $+ 1 1 %rand.bt /msg $gettok(%trigger, 2-, 32) }
        elseif ($gettok(%trigger, 1, 32) == /ctcp) { /timerxdccautoresume $+ $nick $+ 1 1 %rand.bt /ctcp $gettok(%trigger, 2-, 32) }
        elseif ($gettok(%trigger, 1, 32) == /notice) { /timerxdccautoresume $+ $nick $+ 1 1 %rand.bt /notice $gettok(%trigger, 2-, 32) }
        else { /outputxdccinfo 4ERROR: unknown trigger type ( $+ %trigger $+ ) }

        /outputxdccinfo 14Disabling group2 autoxdccresume for7 $nick for $calc(%resumedelay + %rand.bt) seconds to prevent repetitive request.
        .timer -o 1 $calc(%resumedelay + %rand.bt) /write -dw $+ $nick $+ ¦ $+ $network $autoresumedisablefile
        if (!$read($autoresumedisablefile, wnt, $nick $+ ¦ $+ $network)) {
          /write -a $autoresumedisablefile $nick $+ ¦ $+ $network
        }
        .timer -o 1 $calc(%resumedelay + %rand.bt + 1) /outputxdccinfo 2Autoresume14 reenabled for3 $network $+ 7 $nick $+ .
        .timer -o 1 $calc(%resumedelay + %rand.bt + 1) /outputxdccinfo 
        ; unset %rand.bt %trigger
      }
      else { /outputxdccinfo 4Cannot autoresume:3 $network $+ 7 $nick not in XDCC sends file, no queue file available, pack number unknown. }      
    }
    else { /outputxdccinfo 4Cannot autoresume:3 $network $+ 7 $nick not in XDCC bot library. }  
  }
  else { 
    /outputxdccinfo 4Not resuming pack for3 $network $+ 7 $nick $+ : Autoresume temporarily disabled for this bot to avoid bot flooding. This could be caused by a defective or unwilling bot or by setting a very long autoresume time interval. 

    if ($shouldstartmaxbotq != $null) {
      if (%botqueuehandling == on) {
        /startbotqueues 1
      }
      if ($read($xdccsinprogress , s, $nick)) { /write -i1 $tempbotqueuefile $nick $read($xdccsinprogress , s, $nick) }
      elseif ($exists($getqfilenm($network, $nick))) { /write -i1 $tempbotqueuefile $nick $read($getqfilenm($network, $nick), nt, 1) }
    }
  }

  if (%botqueuehandling == on && testnumoftransferspeed == on && %botqueuemode == bandwidth) { .timerxdccstatistics -o 0 %statisticstime /calcxdccstats $timer(xdccstatistics).secs }

  /outputxdccinfo 
}
#groupautoxdccresume end
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
on *:GETFAIL:*:{
  if ($triggerHash.exists($network, $nick) && $botliston == TRUE) { //cline -lc4 @XDCC_Info $fline(@XDCC_Info,$nick,1,1) } 
  /outputxdccinfo 4GET fail from7 $nick on3 $network occured. 4Not resuming pack for3 $network $+ 7 $nick $+ : Autoresume disabled.
  if ($read($xdccsinprogress, s, $nick)) { /write -ds $+ $nick $xdccsinprogress }  
  /outputxdccinfo 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------






#groupautosendresume on
;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
; This should resume a failed upload with the given bandwidth limit if the
; autoresume send group is ON, and disable further upload retries for that 
; recipient for a time period.
;-------------------------------------------------------------------------
on *:SENDFAIL:*:{
  if (!$read($autoresumesenddisablefile, wnt,$nick)) {
    set %rand.bt $rand(0,%sendresumetime)
    /outputxdccinfo I 4failed to send the file2 $replace($filename,$nopath($filename),13 $+ $nopath($filename) $+ ) to7 $nick $+ , 3re-sending in %rand.bt seconds

    /outputxdccinfo 14Disabling group2 Auto Send Resume for7 $nick for $calc(%resumedelay + %rand.bt) seconds to prevent unwanted resends.

    .timer -o 1 $calc(%sendresumedelay + %rand.bt) /write -dw $+ $nick $autoresumesenddisablefile
    if (!$read($autoresumesenddisablefile, wnt,$nick)) {
      /write -a $autoresumesenddisablefile $nick   
    }
    .timer -o 1 $calc(%sendresumedelay + %rand.bt) /outputxdccinfo 2Auto Send Resume14 reenabled for7 $nick $+ .
    .timer -o 1 $calc(%sendresumedelay + %rand.bt) /outputxdccinfo 

    if (%sendlimit isnum) {
      /timerxdccsendresume $+ $nick 1 %rand.bt /dcc send -cl $+ %sendlimit $nick $filename
    }
    else {
      /timerxdccsendresume $+ $nick 1 %rand.bt /dcc send -c $nick $filename
    }
    ; unset %rand.bt
  }
  else {
    /outputxdccinfo 4Not resuming SEND for7 $nick $+ : Auto Send Resume temporarily disabled for this recipient to avoid unwanted resends. This could be caused by a defective or unwilling recipient or by setting a very long auto send resume time interval. 
  }

  /outputxdccinfo 
}
#groupautosendresume end
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
on *:SENDFAIL:*:{
  /outputxdccinfo I 4failed to SEND the file2 $replace($filename,$nopath($filename),13 $+ $nopath($filename) $+ ) to7 $nick $+ . 4Not resuming send for7 $nick $+ : Autoresume Send disabled.
  /outputxdccinfo 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------







;-------------------------------------------------------------------------
; Outputs a comment to the xdcc script output window if a file was 
; succesfully sent, and adds that file and the recipient's nickname to the
; completed uploads file.
;-------------------------------------------------------------------------
on *:FILESENT:*:{
  if (!$exists($xdccsessionsendfile) || !$read($xdccsessionsendfile, wnt, 7 $+ $nick $+ 2 $replace($filename,$nopath($filename),13 $+ $nopath($filename)) $+ 15 [*])) {
    /write -a $xdccsessionsendfile 7 $+ $nick $+ 2 $replace($filename,$nopath($filename),13 $+ $nopath($filename)) $+ 15 $asctime([dd/mm/yyyy][HH:nn:ss])
  }
  inc %filessenttotal
  /outputxdccinfo 3Succesfully SENT2 $replace($filename,$nopath($filename),13 $+ $nopath($filename) $+ ) to7 $nick $+ 15 $address
  /outputxdccinfo 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------


#groupautoxdccresumejoin on
;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
; The on join should resume a file that was unfinished if the appropriate
; bot comes online.
;-------------------------------------------------------------------------
on *:JOIN:#:{ 
  if ($nick == $me) { .timer 1 3 /colorchannicks $chan }
  elseif ($triggerHash.exists($network, $nick) != $null) {
    set %requested 0
    if ($exists($autoresumedisablefile) && $read($autoresumedisablefile, wnt, $nick $+ ¦ $+ $network)) { 
      /outputxdccinfo 4Not resuming pack for3 $network $+ 7 $nick $+ :7 $nick just rejoined12 $chan $+ . Autoresume temporarily disabled for this bot to avoid bot flooding. This could be caused by a defective or unwilling bot or by setting a very long autoresume time interval, or because you suspended autoresume and queue features for this bot (14you can reenable these features by restarting the bot's queue manually). 
      /outputxdccinfo 
    }
    elseif ($exists($xdccsinprogress) && $get($nick).status == $null) { 
      if ($read($xdccsinprogress , s, $nick)) {
        if (%botqueuehandling == off || $shouldstartmaxbotq != $null) {      
          set %trigger $triggerHash.getTrigger($network, $nick) $+ $read($xdccsinprogress , s, $nick)
          set %rand.bt $rand(%minresumedelay ,%maxresumedelay)

          /outputxdccinfo 7 $+ $nick ( $+ %trigger $+ ) just joined12 $chan and has an unfinished transfer listed in the general transfers file, 3re-requesting in %rand.bt seconds.

          if ($exists($dccallownetworkfile) && $read($dccallownetworkfile,wnt,$network)) { /DCCALLOW + $+ $nick }
          if ($exists($alternatedccserverfile) && $read($alternatedccserverfile,snt,$network $nick)) { $read($alternatedccserverfile,snt,$network $nick) }

          if ($gettok(%trigger, 1, 32) == /msg) { /timerxdccautoresume $+ $nick $+ 1 1 %rand.bt /msg $gettok(%trigger, 2-, 32) }
          elseif ($gettok(%trigger, 1, 32) == /ctcp) { /timerxdccautoresume $+ $nick $+ 1 1 %rand.bt /ctcp $gettok(%trigger, 2-, 32) }
          elseif ($gettok(%trigger, 1, 32) == /notice) { /timerxdccautoresume $+ $nick $+ 1 1 %rand.bt /notice $gettok(%trigger, 2-, 32) }
          else { /outputxdccinfo 4ERROR: unknown trigger type ( $+ %trigger $+ ) }
          set %requested 1

          /outputxdccinfo 14Disabling group2 autoxdccresume for7 $nick for $calc(%resumedelay + %rand.bt) seconds to prevent repetitive request.
          /outputxdccinfo 

          .timer -o 1 $calc(%resumedelay + %rand.bt) /write -dw $+ $nick $+ ¦ $+ $network $autoresumedisablefile
          if (!$read($autoresumedisablefile, wnt, $nick $+ ¦ $+ $network)) {
            /write -a $autoresumedisablefile $nick $+ ¦ $+ $network
          }
          .timer -o 1 $calc(%resumedelay + %rand.bt + 1) /outputxdccinfo 2Autoresume14 reenabled for3 $network $+ 7 $nick $+ .
          .timer -o 1 $calc(%resumedelay + %rand.bt + 1) /outputxdccinfo 

          ; unset %trigger %rand.bt
        }
        elseif ($get($nick).status != active && $exists($xdccsinprogress) && $read($xdccsinprogress , s, $nick)) { 
          /outputxdccinfo 7 $+ $nick ( $+ %trigger $+ ) just joined12 $chan and has an unfinished transfer listed in the general transfers file, 4all send slots in use. Adding $nick to Temp Bot Queue file.
          set %trigger $null
          set %trigger $read($xdccsinprogress, w, $nick *)
          if (%trigger != $null && !$read($tempbotqueuefile, snt,$nick)) { /write -i1 $tempbotqueuefile %trigger }
        }
      }
      elseif ($exists($networkfile($network)) && %requested != 1 && $get($nick).status != active) {
        if ($read($networkfile($network), wn,* $nick *)) {  
          if (%botqueuehandling == off || $shouldstartmaxbotq != $null) {
            set %trigger $read($networkfile($network), $readn)
            set %rand.bt $rand(%minresumedelay , %maxresumedelay)

            /outputxdccinfo 7 $+ $nick ( $+ %trigger $+ ) just joined12 $chan and has an unfinished transfer listed in the3 $network network specific transfers file, 3re-requesting in %rand.bt seconds

            if ($exists($dccallownetworkfile) && $read($dccallownetworkfile,wnt,$network)) { /DCCALLOW + $+ $nick }
            if ($exists($alternatedccserverfile) && $read($alternatedccserverfile,snt,$network $nick)) { $read($alternatedccserverfile,snt,$network $nick) }

            if ($gettok(%trigger, 1, 32) == /msg) { /timerxdccautoresume $+ $nick $+ 1 1 %rand.bt /msg $gettok(%trigger, 2-, 32) }
            elseif ($gettok(%trigger, 1, 32) == /ctcp) { /timerxdccautoresume $+ $nick $+ 1 1 %rand.bt /ctcp $gettok(%trigger, 2-, 32) }
            elseif ($gettok(%trigger, 1, 32) == /notice) { /timerxdccautoresume $+ $nick $+ 1 1 %rand.bt /notice $gettok(%trigger, 2-, 32) }
            else { /outputxdccinfo 4ERROR: unknown trigger type ( $+ %trigger $+ ) }
            /outputxdccinfo 14Disabling group2 autoxdccresume for7 $nick for $calc(%resumedelay + %rand.bt) seconds to prevent repetitive request.
            /outputxdccinfo 

            .timer -o 1 $calc(%resumedelay + %rand.bt) /write -dw $+ $nick $+ ¦ $+ $network $autoresumedisablefile
            if (!$read($autoresumedisablefile, wnt, $nick $+ ¦ $+ $network)) {
              /write -a $autoresumedisablefile $nick $+ ¦ $+ $network
            }
            .timer -o 1 $calc(%resumedelay + %rand.bt + 1) /outputxdccinfo 2Autoresume14 reenabled for3 $network $+ 7 $nick $+ .
            .timer -o 1 $calc(%resumedelay + %rand.bt + 1) /outputxdccinfo 

            ; unset %trigger %rand.bt
          }
          elseif ($get($nick).status != active) {  
            /outputxdccinfo 7 $+ $nick ( $+ %trigger $+ ) just joined12 $chan and has an unfinished transfer listed in the general transfers file, 4all send slots in use. Adding $nick to Temp Bot Queue file.
            set %trigger $null
            set %trigger $nick $read($getqfilenm($network,$nick)) 
            if (%trigger != $null && !$read($tempbotqueuefile, snt,$nick)) { /write -i1 $tempbotqueuefile %trigger }
          }
        }      
      }
      ;else { /outputxdccinfo No unfinished packs listed for $network and no unspecified unfinished packs listed in "xdcc in progres file". }    
    }
    if ($get($nick).status != active && $botliston == TRUE) { //cline -lc7 @XDCC_Info $fline(@XDCC_Info,$nick,1,1) }  
  }

}
#groupautoxdccresumejoin end
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
ON *:JOIN:#:{ 
  if ($nick == $me) { .timer 1 3 /colorchannicks $chan }
  elseif ($triggerHash.exists($network, $nick) && $get($nick).status != active && $botliston == TRUE) { //cline -lc7 @XDCC_Info $fline(@XDCC_Info,$nick,1,1) } 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------






#grouppackchangedetect on
;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
; This deactivates a pack change detector timer when a bot goes offline,
; and resets the packfile. If $me is the one exiting the channel, it will
; stop all timers for that chan. If the bot quitting has an xdcc queue,
; it will notify the script owner.
;-------------------------------------------------------------------------
on *:QUIT:{
  if ($triggerHash.exists($network, $nick) != $null) {
    if ($triggerHash.exists($network, $nick) != $null && $get($nick).status != active && $botliston == TRUE) { //cline -lc1 @XDCC_Info $fline(@XDCC_Info,$nick,1,1) }
    if ($timer(packcapturetest $+ $nick) != $null) {
      .timer $+ packcapturetest $+ $nick off
      if ($exists($getoldfilenm($network, $nick))) {
        .copy -o $getoldfilenm($network, $nick) $getpfffilenm($network, $nick) 
      }
    }
    if ($exists($getqfilenm($network, $nick))) {
      /outputxdccinfo 14Bot with XDCC queue just went offline (3 $+ $network $+ 14¦7 $+ $nick $+ 14).
      /outputxdccinfo 
    }
    if ($exists($tempbotqueuefile) && $read($tempbotqueuefile,snt,$nick) && (!$exists($xdccsinprogress) || !$read($xdccsinprogress,snt,$gettok($read($tempbotqueuefile,wnt,$nick *),1,32)))) {
      /write -i1 $xdccsinprogress $read($tempbotqueuefile,wnt,$nick *)
      /write -ds $+ $nick $tempbotqueuefile
    }
  }
  elseif ($nick == $me) {
    /outputxdccinfo 14Quit: Stopping all pack capture tests for channel $chan $+ .
    set %i 1
    var %llen = $triggerHash.items
    while (%i <= %llen) {
      if ($get($triggerHash.item.nick(%i)).status != active && $botliston == TRUE) { //cline -lc14 @XDCC_Info $fline(@XDCC_Info,$triggerHash.item.nick(%i),1,1) }
      if ($network $chan iswm $triggerHash.item.network(%i) $triggerHash.item.chan(%i)) {
        set %botnick $triggerHash.item.nick(%i)
        if ($timer(packcapturetest $+ %botnick) != $null) {
          .timer $+ packcapturetest $+ %botnick off
          if ($exists($getoldfilenm($network, %botnick))) {
            .copy -o $getoldfilenm($network, %botnick) $getpfffilenm($network, %botnick) 
          }
        }
      }
      inc %i
    }
    unset %llen
    if ($exists($tempbotqueuefile) && $lines($tempbotqueuefile) > 0) {
      set %i 1
      while (%i <= $lines($tempbotqueuefile)) {
        if (!$exists($xdccsinprogress) || !$read($xdccsinprogress,snt,$gettok($read($tempbotqueuefile, %i),1,32))) { /write -i1 $xdccsinprogress $read($tempbotqueuefile, %i) }
        inc %i
      }
      .remove $tempbotqueuefile
    }
    ; unset %i %botnick
    /triggerHash.free
    /outputxdccinfo 
    /debuglog.sessionend
  }
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
on *:PART:#:{
  if ($triggerHash.exists($network, $nick) != $null) {
    if ($get($nick).status != active && $botliston == TRUE) { //cline -lc1 @XDCC_Info $fline(@XDCC_Info,$nick,1,1) }
    if ($timer(packcapturetest $+ $nick) != $null) {
      .timer $+ packcapturetest $+ $nick off
      if ($exists($getoldfilenm($network, $nick))) {
        .copy -o $getoldfilenm($network, $nick) $getpfffilenm($network, $nick) 
      }
    }
    if ($exists($tempbotqueuefile) && $read($tempbotqueuefile,snt,$nick) && (!$exists($xdccsinprogress) || !$read($xdccsinprogress,snt,$gettok($read($tempbotqueuefile,wnt,$nick *),1,32)))) {
      /write -i1 $xdccsinprogress $read($tempbotqueuefile,wnt,$nick *)
      /write -ds $+ $nick $tempbotqueuefile
    }
    if ($exists($getqfilenm($network, $nick))) {
      /outputxdccinfo 14Bot with XDCC queue just parted $chan (3 $+ $network $+ 14¦7 $+ $nick $+ 14).
      /outputxdccinfo 
    }
  }
  elseif ($nick == $me) {
    /outputxdccinfo 14Parted channel $chan $+ : Stopping all pack capture tests for channel $chan $+ .
    set %i 1
    var %llen = $triggerHash.items
    while (%i <= %llen) {
      if ($chan isin $triggerHash.item.chans(%i) && $triggerHash.item.network(%i) == $network) {
        if ($get($triggerHash.item.nick(%i)).status != active && $botliston == TRUE) { //cline -lc10 @XDCC_Info $fline(@XDCC_Info,$triggerHash.item.nick(%i),1,1) }
        if ($timer(packcapturetest $+ $triggerHash.item.nick(%i)) != $null) {
          .timer $+ packcapturetest $+ $triggerHash.item.nick(%i) off
          if ($exists($getoldfilenm($network, $triggerHash.item.nick(%i)))) {
            .copy -o $getoldfilenm($network, $triggerHash.item.nick(%i)) $getpfffilenm($network, $triggerHash.item.nick(%i)) 
          }
        }
      }
      inc %i
    }
    unset %llen
    if ($exists($tempbotqueuefile) && $lines($tempbotqueuefile) > 0) {
      set %i 1
      while (%i <= $lines($tempbotqueuefile)) {
        if ((!$exists($xdccsinprogress) || !$read($xdccsinprogress,snt,$gettok($read($tempbotqueuefile, %i),1,32))) && ($chan isin $triggerHash.getChans($network, $gettok($read($tempbotqueuefile, %i),1,32)))) { 
          /write -i1 $xdccsinprogress $read($tempbotqueuefile, %i) 
          /write -dl $+ %i $tempbotqueuefile
          dec %i
        }
        inc %i
      }
    }
    /outputxdccinfo 
    ; unset %i %botnick
  }
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
on *:DISCONNECT:{
  if ($nick == $me) {
    /outputxdccinfo 14Disconnected from server $server $+ : Stopping all pack capture tests for network $network $+ .
    set %i 1
    var %llen = $triggerHash.items
    while (%i <= %llen) {
      if ($triggerHash.item.network(%i) == $network) {
        if ($get($triggerHash.item.nick(%i)).status != active && $botliston == TRUE) { //cline -lc14 @XDCC_Info $fline(@XDCC_Info,$triggerHash.item.nick(%i),1,1) }
        if ($timer(packcapturetest $+ $triggerHash.item.nick(%i)) != $null) {
          .timer $+ packcapturetest $+ $triggerHash.item.nick(%i) off
          if ($exists($getoldfilenm($network, $triggerHash.item.nick(%i)))) {
            .copy -o $getoldfilenm($network, $triggerHash.item.nick(%i)) $getpfffilenm($network, $triggerHash.item.nick(%i)) 
          }
        }
      }
      inc %i
    }
    unset %llen
    if ($exists($tempbotqueuefile) && $lines($tempbotqueuefile) > 0) {
      set %i 1
      while (%i <= $lines($tempbotqueuefile)) {
        if ((!$exists($xdccsinprogress) || !$read($xdccsinprogress,snt,$gettok($read($tempbotqueuefile, %i),1,32))) && ($triggerHash.network($nick) == $network)) { 
          /write -i1 $xdccsinprogress $read($tempbotqueuefile, %i) 
          /write -dl $+ %i $tempbotqueuefile
          dec %i
        }
        inc %i
      }
    }
    ; unset %i %botnick
    /outputxdccinfo 
  }
  elseif ($triggerHash.exists($network, $nick) && $get($nick).status != active && $botliston == TRUE) { //cline -lc1 @XDCC_Info $fline(@XDCC_Info,$nick,1,1) }
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
#grouppackchangedetect end
on *:QUIT:{
  if ($triggerHash.exists($network, $nick) != $null && $get($nick).status != active && $botliston == TRUE) { //cline -lc1 @XDCC_Info $fline(@XDCC_Info,$nick,1,1) }
  elseif ($nick == $me) { 
    set %i 1
    var %llen = $triggerHash.items
    while (%i <= %llen) {
      if ($get($triggerHash.item.nick(%i)).status != active && $botliston == TRUE) { //cline -lc14 @XDCC_Info $fline(@XDCC_Info,$nick,1,1) }
      inc %i
    }
    unset %llen
    /debuglog.sessionend 
  }
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
on *:PART:{
  if ($triggerHash.exists($network, $nick) != $null && $get($nick).status != active && $botliston == TRUE) { //cline -lc1 @XDCC_Info $fline(@XDCC_Info,$nick,1,1) }
  elseif ($nick == $me) {
    set %i 1
    var %llen = $triggerHash.items
    while (%i <= %llen) {
      if ($chan isin $triggerHash.item.chans(%i) && $triggerHash.item.network(%i) == $network && $get($triggerHash.item.nick(%i)).status != active && $botliston == TRUE) { //cline -lc10 @XDCC_Info $fline(@XDCC_Info,$triggerHash.item.nick(%i),1,1) }
      inc %i
    }
    unset %llen
  }
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
on *:DISCONNECT:{
  if ($nick == $me) {
    set %i 1
    ver %llen = $triggerHash.items
    while (%i <= %llen) {
      if ($triggerHash.item.network(%i) == $network && $get($triggerHash.item.nick(%i)).status != active && $botliston == TRUE) { //cline -lc14 @XDCC_Info $fline(@XDCC_Info,$triggerHash.item.nick(%i),1,1) }
      inc %i
    }
    unset %llen
  }
  elseif ($triggerHash.exists($network, $nick) != $null && $get($nick).status != active && $botliston == TRUE) { //cline -lc1 @XDCC_Info $fline(@XDCC_Info,$nick,1,1) }
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------




#groupautoresumestart on
;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
; If auto resume at start is on:
; If the answer to the query box is yes, this checks whether a network 
; queue file exists for the currently connected network. If it does, it 
; sets all triggers in that file on different random timers and starts 
; them one by one. 
;-------------------------------------------------------------------------
; If auto resume at start is off:
; This removes the network queue file for the appropriate network.
;-------------------------------------------------------------------------
on *:CONNECT:{
  set %f 1
  var %llen = $triggerHash.items
  while (%f <= %llen) {
    if ($triggerHash.item.network(%f) == $network && $get($triggerHash.item.nick(%i)).status != active && $botliston == TRUE) { //cline -lc10 @XDCC_Info $fline(@XDCC_Info,$triggerHash.item.nick(%f),1,1) }
    inc %f
  }
  unset %llen

  if ($lines($networkfile($network)) > 0) {
    set %i 1
    while (%i <= $lines($networkfile($network))) {
      set %botnick $gettok($read($networkfile($network), %i), 2, 32)
      set %bt.rand $calc($rand(%minresumedelay, %maxresumedelay) + %startresumeoffset)

      if (%botqueuehandling == off || $shouldstartmaxbotq != $null) {
        if ($exists($dccallownetworkfile) && $read($dccallownetworkfile,wnt,$network)) { /DCCALLOW + $+ %botnick }
        if ($exists($alternatedccserverfile) && $read($alternatedccserverfile,snt,$network %botnick)) { $read($alternatedccserverfile,snt,$network %botnick) }

        /outputxdccinfo Auto resume at start ON, requesting transfers for network3 $network in %bt.rand seconds ( $+ $read($networkfile($network), %i) || 14//timerxdccautoresume $+ $network $+ %botnick $+ %i $+ )
        if ($gettok($read($networkfile($network), %i), 1, 32) == /msg) { //timerxdccautoresume $+ $network $+ %botnick $+ %i 1 %bt.rand /msg $gettok($read($networkfile($network), %i), 2-, 32) }
        elseif ($gettok($read($networkfile($network), %i), 1, 32) == /ctcp) { //timerxdccautoresume $+ $network $+ %botnick $+ %i 1 %bt.rand /ctcp $gettok($read($networkfile($network), %i), 2-, 32) }
        elseif ($gettok($read($networkfile($network), %i), 1, 32) == /notice) { //timerxdccautoresume $+ $network $+ %botnick $+ %i 1 %bt.rand /notice $gettok($read($networkfile($network), %i), 2-, 32) }
        else { /outputxdccinfo 4ERROR: Unknown trigger type ( $+ $read($networkfile($network), %i) $+ ). }
      }
      else {
        /outputxdccinfo Auto resume at start ON, too many sends or requests in progress. Temp queueing packs for3 $network ( $+ $read($networkfile($network), %i) || 14//timerxdccautoresume $+ $network $+ %botnick $+ %i $+ )
        set %trigger $read($getqfilenm($network, %botnick),nt,1)
        if (!$exists($tempbotqueuefile) || !$read($tempbotqueuefile,snt,%botnick)) { //write -a $tempbotqueuefile %botnick %trigger }
      }
      inc %i
    }
    ; unset %i %bt.rand
  }
  else { /outputxdccinfo No requests for autoresume known for this network (3 $+ $network $+ ). }
  /outputxdccinfo 
}
#groupautoresumestart end
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
on *:CONNECT:{
  var %llen = $triggerHash.items
  while (%i <= %llen) {
    if ($triggerHash.item.network(%i) == $network && $get($triggerHash.item.nick(%i)).status != active && $botliston == TRUE) { //cline -lc10 @XDCC_Info $fline(@XDCC_Info,$triggerHash.item.nick(%i),1,1) }
    inc %i
  }
  unset %llen
  /outputxdccinfo Not resuming aborted transfers (3 $+ $network $+ ). 
  if ($exists($networkfile($network))) {
    .remove $networkfile($network)
  }
  /outputxdccinfo 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------








#groupautoresumeatstart on
;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
; If auto resume at start is on:
; Enables the resume at start connect listener and creates separate 
; network queue files for each network found listed in the "currently 
; downloading" file. Afterwards, it removes the general file. It also 
; notifies the owner which networks have unfinished transfers. Finally, 
; it removes a couple of session specific files.
;-------------------------------------------------------------------------
; If auto resume at start is off:
; Just removes a couple of session specific files.
;-------------------------------------------------------------------------
on *:START:{
  /debuglog.sessionstart
  /triggerHash.init

  if ($exists($autoresumedisablefile)) {
    .remove $autoresumedisablefile
  }
  if ($exists($autoresumesenddisablefile)) {
    .remove $autoresumesenddisablefile
  }
  if ($exists($xdccsessiongetfile)) {
    .remove $xdccsessiongetfile
  }
  if ($exists($xdccsessionsendfile)) {
    .remove $xdccsessionsendfile
  }
  if ($exists($xdccqueueposfile)) {
    .remove $xdccqueueposfile
  }
  if ($exists($statsfile(1))) {
    .remove $xdccdir $+ \ $+ $statsfile(1)
  }
  if ($exists($statsfile(2))) {
    .remove $xdccdir $+ \ $+ $statsfile(2)
  }

  var %llen
  if ($exists($tempbotqueuefile) && $lines($tempbotqueuefile) > 0) {
    set %i 1
    set %llen $lines($tempbotqueuefile)
    while (%i = %llen) {
      if (!$exists($xdccsinprogress) || !$read($xdccsinprogress,snt,$gettok($read($tempbotqueuefile, %i),1,32))) { //write -i1 $xdccsinprogress $read($tempbotqueuefile, %i) }
      inc %i
    }
    .remove $tempbotqueuefile
  }


  set %allnetworks $null
  if ($exists($xdccsinprogress) && $lines($xdccsinprogress) > 0) {
    .enable #groupautoresumestart
    set %i 1
    set %llen $lines($xdccsinprogress)
    while (%i <= %llen) {
      set %botnick $gettok($read($xdccsinprogress, %i), 1, 32)
      set %botnetwork $triggerHash.network(%botnick)
      if (%botnetwork !isin %allnetworks) { set %allnetworks %allnetworks %botnetwork }
      set %trigger $triggerHash.getTrigger(%botnetwork, %botnick) $+ $read($xdccsinprogress , s, %botnick)

      if (!$read($networkfile(%botnetwork), wn, * $+ %trigger $+ *) && %botnetwork != $null) {
        ;/outputxdccinfo Writing autoresume queue file for network3 %botnetwork (7 $+ %botnick $+ ).
        /write -a $networkfile(%botnetwork) %trigger
      }
      if (!$read($networksendfile, wn, %botnetwork) && %botnetwork != $null) {
        /write -a $networksendfile %botnetwork
      }
      ;else { /outputxdccinfo Not writing %trigger to queue file for network3 %botnetwork $+ : Trigger already listed. }
      inc %i
    }
    .remove $xdccsinprogress
    ; unset %i %botnick %botnetwork %trigger %allnetworks
  }
  set %i 1
  unset %llen

  while ($findfile($xdccdir,*.apq,%i)) {
    if ($lines($findfile($xdccdir,*.apq,%i)) > 0 && $remove($nopath($findfile($xdccdir,*.apq,%i)),.apq) !isin %allnetworks) { set %allnetworks %allnetworks $remove($nopath($findfile($xdccdir,*.apq,%i)),.apq) }
    inc %i
  }

  if (%allnetworks != $null) { /outputxdccinfo You have potential transfers waiting on at least the following networks:3 %allnetworks $+ . }
  else { /outputxdccinfo No aborted transfers waiting. }

  if (%autocleanatstart == on) {
    /cleanxdcclib
  }

  if (%botqueuehandling == on && %testnumoftransferspeed == on) { /timexdcctransferstest }

  /outputxdccinfo 
}
#groupautoresumeatstart end 
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------
on *:START:{
  /debuglog.sessionstart

  /triggerHash.init
  if ($exists($autoresumedisablefile)) {
    .remove $autoresumedisablefile
  }
  if ($exists($autoresumesenddisablefile)) {
    .remove $autoresumesenddisablefile
  }
  if ($exists($xdccsessiongetfile)) {
    .remove $xdccsessiongetfile
  }
  if ($exists($xdccsessionsendfile)) {
    .remove $xdccsessionsendfile
  }
  if ($exists($xdccqueueposfile)) {
    .remove $xdccqueueposfile
  }
  if ($exists($statsfile(1))) {
    .remove $xdccdir $+ \ $+ $statsfile(1)
  }
  if ($exists($statsfile(2))) {
    .remove $xdccdir $+ \ $+ $statsfile(2)
  }

  if ($exists($tempbotqueuefile) && $lines($tempbotqueuefile) > 0) {
    set %i 1
    var %llen = $lines($tempbotqueuefile)
    while (%i = %llen) {
      if (!$exists($xdccsinprogress) || !$read($xdccsinprogress,snt,$gettok($read($tempbotqueuefile, %i),1,32))) { /write -i1 $xdccsinprogress $read($tempbotqueuefile, %i) }
      inc %i
    }
    unset %llen
    .remove $tempbotqueuefile
  }

  if (%autocleanatstart == on) {
    /cleanxdcclib
  }

  if (%botqueuehandling == on && %testnumoftransferspeed == on) { /timexdcctransferstest }

  /outputxdccinfo 14Not resuming failed transfers: Auto Resume At Start OFF.
  /outputxdccinfo 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------






;-------------------------------------------------------------------------
;**********************************DONE***********************************
;-------------------------------------------------------------------------
; This sets some variables and creates a directory when the script is 
; first loaded. 
;-------------------------------------------------------------------------
on *:LOAD:{
  /xdccinitwizard

  /debuglog.sessionstart
  /triggerHash.init

  set %xdccscriptversion 3.7
  set %scriptauthor werecow
  set %filessenttotal 0
  set %filesgettotal 0  
  set %installdate $asctime(dd/mm/yyyy [HH:nn:ss])

  /outputxdccinfo 15Succesfully set variables, timers, filenames and group settings. Created directory $xdccdir ( $+ %installdate $+ ).
  /outputxdccinfo 
}
;-------------------------------------------------------------------------
;-------------------------------------------------------------------------