# First of all, before I start with this script :
# Credits go to mofo (mick@mindstorm.nl). He started this script.
# Origonally this script was called mICKp3, but I started to call MP3Script
# The source I got was version 0.4 beta, so I start from that version too.
#
# CHANGELOG
# 29/02/2002 V0.4b 
# - Cleaned the source a bit, added dcc command option, channel support 
#   and SPR ctcp support
# - Fancied the dcc output
#
# --= Settings, start edit below =--
# What do you want to be the command at the bot's partyline ?
# i.e. if you set this to "mp3" you can type .mp3 help for help. (d0h)
set mp3(dcctrigger) "mp3"

# Set the dirs in which the mp3's are located. Beware! The dirs are scanned
# recursively, so don't give overlapping dirs. Separate multiple dirs by a
# comma (,)
#
# The directory must be the full path, this will be displayed in the mp3-list,
# if you do not want that, make a symbolic link with ln (ln --help) in the
# directory of your eggdrops executable.
# set your mp3 directory
set mp3(dir) "/home/muziek"

# set maximum number of simultaneous downloads to allow for each user
set mp3(max) 1

# In which channels should this script bloat his mp3's?
# Seperate each chan with a space.
set mp3(chans) "#mp3"

# -- Options
# These are the default values the bot will have after a (re)start or rehash.

# set the time (in minutes) for randomly playing mp3's in the channel
# 0 minutes turns randomfile off
set mp3(rtime) 10

# set the time (in minutes) for advertising mp3-list and script in the channel
# 0 minutes turns commerce off
set mp3(ctime) 3 

# set this to use colors in channel/text output 
# 0 is no colors, 1 is with colors 
set mp3(color) 1

# set this to see what the users are getting when they use @find/@locator
# in the channel (you need console +c set)
# 0 spying turned off, 1 spying turned on
set mp3(spy) 1

# Enable SPR-like ctcp's to channel ?
# Some mp3 channels have a bot, wich collects from every share-bot
# how much files/kb's it has shared, enable this option if you want
# that yours is added to these 'stats'
set mp3(ctcp) 1

#
# --= Do not edit anything below this.=--
#

bind DCC n $mp3(dcctrigger) mp3
bind PUBM - "*" check_public
bind MSGM - "*" check_msg
bind CTCP - "*" ctcp_handling
bind SENT - "*" complete_send

set mp3(version) "V0.4b"
set mp3(versionreply) "MP3Script MP3 @locator script $mp3(version)."
set mp3(announce) "MP3Script"
set mp3(url) "http://djslash.selwerd.nl/mp3script"
set mp3(chans) [string trim $mp3(chans) ,]

foreach mod [modules] { lappend mods $mod }
if {[lsearch -exact $mods transfer] == -1} { loadmodule transfer }

proc mp3idx {idx arg} { global mp3; putidx $idx "\[-$mp3(announce)-\] $arg" }

proc mp3 {handle idx args} {
 global mp3
 set args [string tolower [lindex $args 0]]
 if {[string tolower $args] == "list"} {
  putcmdlog "Making new mp3 list... this might take some time..."
  set result [make_list]
  putcmdlog "Finished mp3 list. Mp3's: [lindex $result 1] Size: [lindex $result 0] K"
  return
 }
 if {[string tolower [lindex $args 0]] == "commerce"} {
  if {[lindex $args 1] == ""} {
   mp3idx $idx "Auto-Commerce is set to $mp3(ctime) minutes"
   return
  } 
  if {[lindex $args 1] > 1 && [lindex $args 1] < 1440} {
   mp3idx $idx "Auto-commerce has been set to [lindex $args 1] minutes"
   set mp3(ctime) [lindex $args 1]
   initctime
   return
  } 
  if {[lindex $args 1] == 0} {
   mp3idx $idx "Auto-commerce has been turned off"
   set mp3(ctime) 0
   initctime
   return
  }
  mp3idx $idx "Usage: .$mp3(dcctrigger) commerce \[minutes\]"
  mp3idx $idx "Minutes can vary from 0 to 1440"
  return
 }
 if {[string tolower [lindex $args 0]] == "randomfile"} {
  if {[lindex $args 1] == ""} {
   mp3idx $idx "Random File is set to $mp3(rtime) minutes"
   return
  }
  if {[lindex $args 1] > 1 && [lindex $args 1] < 1440} {
   mp3idx $idx "Random File has been set to [lindex $args 1] minutes"
   set mp3(rtime) [lindex $args 1]
   initrtime
   return
  }
  if {[lindex $args 1] == 0} {
   mp3idx $idx "Random File has been turned off"
   set mp3(rtime) 0
   initrtime
   return
  }
  mp3idx $idx "Usage: .$mp3(dcctrigger) randomfile \[minutes\]"
  mp3idx $idx "Minutes can vary from 0 to 1440"
  return
 }
 if {[string tolower [lindex $args 0]] == "spy"} {
  if {[lindex $args 1] == ""} {
   if {$mp3(spy) == 0} { set spy "off" } else { set spy "on" }
   mp3idx $idx "Spy function is $spy"
   return
  }
  if {[lindex $args 1] == 0 || [lindex $args 1] == "off"} {
   set mp3(spy) 0
   mp3idx $idx "Spy function turned off"
   return
  }
  if {[lindex $args 1] == 1 || [lindex $args 1] == "on"} {
   set mp3(spy) 1
   mp3idx $idx "Spy function turned on"
   return
  }
  mp3idx $idx "Usage: .$mp3(ddctrigger) spy \[on\/off\]"
  return
 }
 if {[string tolower [lindex $args 0]] == "colors"} {
  if {[lindex $args 1] == ""} {
   if {$mp3(color) == 0} { set color "off" } else { set color "on" }
   mp3idx $idx "Colors are turned $color"
   return
  }
  if {[lindex $args 1] == 0 || [lindex $args 1] == "off"} {
   set mp3(color) 0
   mp3idx $idx "Colors turned off"
   return
  }
  if {[lindex $args 1] == 1 || [lindex $args 1] == "on"} {
   set mp3(color) 1
   mp3idx $idx "Colors turned on"
   return
  }
  mp3idx $idx "Usage: .$mp3(dcctrigger) Colors \[on\/off\]"
  return
 }
 if {[lindex $args 0] != "" && [lindex $args 0] != "help"} {
  mp3idx $idx "Invalid command"
 }
 mp3idx $idx "---= $mp3(announce) Commands Center =---"
 mp3idx $idx " "
 mp3idx $idx ".$mp3(dcctrigger) list             Make a new list of your mp3 files."    
 mp3idx $idx " "	
 mp3idx $idx "These Advertisements are Timers in Minutes, <n> is a number, 0=Off."    
 mp3idx $idx ".$mp3(dcctrigger) commerce <n>     Advertise in channel your mp3list and script."
 mp3idx $idx ".$mp3(dcctrigger) randomfile <n>   Advertise in channel randomly a song from your list."
 mp3idx $idx " "
 mp3idx $idx "These can be turned On or Off, <n> is a number, 1=On / 0=Off. "
 mp3idx $idx ".$mp3(dcctrigger) colors <n>       Colormode on/off for all text/msg output."
 mp3idx $idx ".$mp3(dcctrigger) spy <n>          Displays matches of channel searches on partyline."
 mp3idx $idx " "
 mp3idx $idx "All defaults must be set in the tcl script (settings after rehash/restart)."
}

set mp3(size) 0
set mp3(files) 0
set mp3(lines) 0

proc make_list {} {
 global mp3 botnick nick
 set mp3(files) 0
 set mp3(size) 0
 set mp3(lines) 0
 set curdir ""
 set oldcurdir ""
 exec mkdir -p text
 exec rm -f text/rawlist.txt
 foreach dir [split $mp3(dir) ","] {
  set cnt [string length $dir]
  incr cnt -1
  if {[string index $dir $cnt] != "\/"} { append dir "\/" }
   exec echo $dir: >> text/rawlist.txt
   exec ls -ClR $dir >> text/rawlist.txt
  }
  exec rm -f text/$nick-mp3list.doc
  exec rm -f text/mp3list.txt
  exec rm -f text/tryout.txt
  exec echo "---------------------------------------------------------------------\-----------" >> text/$nick-mp3list.doc
  exec echo "List of $botnick's MPEG 3 files" >> text/$nick-mp3list.doc
  exec echo "- Last Updated on [exec date] by MP3Script $mp3(version) " >> text/$nick-mp3list.doc
  exec echo "($mp3(url))" >> text/$nick-mp3list.doc
  exec echo "The TCL @locator/@find Mp3 script for UNIX (Linux, \*BSD\*) Eggdrop1.x (IRC)" >> text/$nick-mp3list.doc
  exec echo "---------------------------------------------------------------------\-----------" >> text/$nick-mp3list.doc
  exec echo " " >> text/$nick-mp3list.doc
  exec echo "To grab a file from me, type !Mynick Exact_Filename or copy/paste a" >> text/$nick-mp3list.doc
  exec echo "corresponding line in Channel" >> text/$nick-mp3list.doc
  exec echo " " >> text/$nick-mp3list.doc
  exec echo "e.g., !$nick Korn - Freak on a leach.mp3" >> text/$nick-mp3list.doc
  exec echo " " >> text/$nick-mp3list.doc
  exec echo "--------------------------------------------------------------------------------" >> text/$nick-mp3list.doc
  incr mp3(lines) 13
  set fileID [open text/rawlist.txt]
  while {1} {
   set line [gets $fileID]
   set splitline [just_one_space $line]
   if {[eof $fileID] == 1} {
    close $fileID
    break
   }
   set i [string length $line]
   set j $i
   incr i -1
   incr j -2
   if {[string index $line $i] == ":"} {
    if {[string index $line $j] == "\/"} {
     incr j -1
    }
    set curdir [string range $line 0 $j]
    if {[string trim $curdir] != [string trim $oldcurdir]} {
     exec echo " " >> text/$nick-mp3list.doc
     exec echo "--- \[ $curdir \] ---" >> text/$nick-mp3list.doc
     exec echo " " >> text/$nick-mp3list.doc
     incr mp3(lines) 3
    }
    set oldcurdir $curdir
   }
   incr i -3
   if {[string tolower [string range $line $i end]] == ".mp3"} {
    set size 0
    incr mp3(files) 1
    if {[string index $line 37] != " "} {
     set tempsize [lindex $splitline 4]
     set sizelength [string length $tempsize]
     incr sizelength -4
     set tempsize [string range $tempsize 0 $sizelength]
     incr size $tempsize
     incr mp3(size) $size
    }
    set outname [lindex [split [just_one_space $line] ";"] 1]
    set outstring "!$botnick $outname"
   if {[string length $outstring] >= 70} {
    append outstring " \|\| $tempsize\K"
   } else {
    set pos -69
    incr pos [string length $outstring]
    for {set x -1} {$x>=$pos} {incr x -1} { append outstring " " }
    append outstring " \|\| $tempsize\K"
   }
   exec echo $outstring >> text/$nick-mp3list.doc
   incr mp3(lines) 1
   exec echo $outname \;$curdir/$outname >> text/mp3list.txt
  }
 }
 exec echo " " >> text/$nick-mp3list.doc
 exec echo "--- \[ Total mp3 files: $mp3(files) with a total size of $mp3(size) K \] ---" >> text/$nick-mp3list.doc
 exec echo " " >> text/$nick-mp3list.doc
 exec echo " " >> text/$nick-mp3list.doc
 exec echo " " >> text/$nick-mp3list.doc
 exec echo " " >> text/$nick-mp3list.doc
 exec echo "\*\*\*\* Disclaimer \*\*\*\*\*" >> text/$nick-mp3list.doc
 exec echo "" >> text/$nick-mp3list.doc
 exec echo "Everything you do with the files and information (all data) given/presented to" >> text/$nick-mp3list.doc
 exec echo "you on IRC (and on Internet in general), is for your own risk and" >> text/$nick-mp3list.doc
 exec echo "responsability. We do not take any responsability, mainly because this" >> text/$nick-mp3list.doc
 exec echo "service is free." >> text/$nick-mp3list.doc
 exec echo " " >> text/$nick-mp3list.doc
 exec echo "Legal Notice" >> text/$nick-mp3list.doc
 exec echo " " >> text/$nick-mp3list.doc
 exec echo "1/ You can only legally keep your mp3 downloads for 24 hours. After that you" >> text/$nick-mp3list.doc
 exec echo "   must delete them from your hard-disk." >> text/$nick-mp3list.doc
 exec echo "2/ If you have the CD, then you can have copies of the music from that CD on" >> text/$nick-mp3list.doc
 exec echo "   your hard-disk for your personal use." >> text/$nick-mp3list.doc
 exec echo " " >> text/$nick-mp3list.doc
 exec echo "So if you download music and you really(!) like it, support the artists who" >> text/$nick-mp3list.doc
 exec echo "created it and buy the CD. Then you will be legal and supporting the musicians" >> text/$nick-mp3list.doc
 exec echo "who created this excellent music." >> text/$nick-mp3list.doc
 incr mp3(lines) 23
 exec echo $mp3(files) $mp3(size) $mp3(lines) > text/mp3Script.set
 return "$mp3(size) $mp3(files)"
}

proc check_public {inick uh handle chan args} {
 global mp3 botnick nick
 if {[lsearch -exact $mp3(chans) $chan] == -1} { return }
 if {[string first "\"" $args ] != -1} { return }
 set locator 0
 set args [lindex $args 0]
 set args [string trim $args]
 set tmpargs [string tolower $args]
 set givelist [string tolower @$botnick]
 set givefile [string tolower !$nick]
 set findfile [string tolower @locator]
 if {[string tolower [lindex $args 0]] == $findfile } { set locator 1 }
 set findfile [string tolower @find]
 if {[string tolower [lindex $args 0]] == $findfile } { set locator 1 }
 if {$tmpargs == $givelist} {
  dccsend text/$nick-mp3list.doc $inick
 } elseif {$locator} {
  set a [string first " " $args]
  incr a 1
  set match_list [find_file [string range $args $a end]]
  if {$match_list != ""} {
   if {$mp3(color) == 0} {
    putserv "privmsg $inick :Matches for *[string range $args $a end]*  Copy and Paste in Channel to Request a File"
   }
   if {$mp3(color) == 1} {
    putserv "privmsg $inick :0,1 Matches for *[string range $args $a end]* 15,2 Copy and Paste in 8,2Channel15,2 to Request a File 0,1 \[-4,1m0,1ICK4,1p30,1-\] "
   }
   if {$mp3(spy)} {
    putcmdlog "\!Spy\! $inick requested -> [string range $args $a end]"
   }
   foreach entry $match_list {
    if {$entry == "over4"} {
     if {$mp3(color) == 0} {
      set entry "Too Many Results to Display  (Recommend to get my list by typing @$botnick in the channel) \[-$mp3(announce)-\]"
     }
     if {$mp3(color) == 1} {
      set entry "0,1 Too Many Results to Display 15,2 (Recommend to get my list by typing 8,2@$botnick 15,2in the channel) 0,1 \[-4,1MP30,1Script4,10,1-\] "
     }
    }
    if {$mp3(spy)} { putcmdlog "\!Spy\! $inick -> [string trim $entry]" }
    putserv "privmsg $inick :$entry"
   }
   set amnt [llength $match_list]
   if {$amnt != 5} {
    if {$mp3(color) == 0} { putserv "privmsg $inick : ..... Total $amnt files Found" }
    if {$mp3(color) == 1} { putserv "privmsg $inick :0,1 ..... Total8,1 $amnt0,1 files Found " }
   }
  }
 } elseif {[string tolower [lindex $args 0]] == $givefile } {
  set i [string length $nick]
  incr i 2
  set tmpname [string range $args $i end]
  set tmpname [string trim [lindex [split $tmpname "\|"] 0]]
  set j [string length $tmpname]
  set k $j
  incr j 1
  incr k -1
  set filematched [give_file_name $tmpname]
  if {$filematched != ""} {
   exec ln -fs "$filematched" text/[join $tmpname "_"]
   dccsend text/[join $tmpname "_"] $inick
   exec rm text/[join $tmpname _]
  }
 }
}

proc give_file_name {name} {
 set fileID [open text/mp3list.txt]
 while {1} {
  set line [gets $fileID]
  if {[eof $fileID] == 1} {
   close $fileID
   break
  }
  set i [string first "\;" $line]
  incr i 1
  set j $i
  incr j -3
  if {[string trim [string tolower $name]] == [string trim [string tolower [string range $line 0 $j]]]} {
   set retstring [string range $line $i end]
   if {[string index $retstring 0] != "\/"} { set retstring "[exec pwd]\/$retstring" }
   return $retstring
  }
 }
}

proc find_file {args} {
 set args [lindex $args 0]
 set args [lindex [split $args "\|"] 0]
 global botnick nick
 set fileID [open text/$nick-mp3list.doc]
 set count 0
 set matches ""
 while {1} {
  set line_full [gets $fileID]
  if {[eof $fileID] == 1} {
   close $fileID
   break
  }
  set line_full [lindex [split $line_full "\|"] 0]
  set i [string first " " $line_full]
  incr i 1
  set line [string range $line_full $i end]
  set ok 1
  set args [strip_string $args]
  if {$args != ""} {
   foreach arg $args {
    set arg [string trim $arg]
    if {[string index $line_full 0] != "!"} {
     set ok 0
    }
    if {$arg != ""} {
     if {$ok == 1} {
      if {[string first [string tolower $arg] [string tolower $line]] == -1} {
       set ok 0
      }
     }
    }
   }
   if {$ok == 1} {
    lappend matches $line_full
    incr count 1
    if {$count == 4} {
     lappend matches "over4"
     close $fileID
     break
    }
   }
  }
 }
 return $matches
}

proc complete_send {handle inick path} {
#    dccputchan 0 "handle: $handle inick: $inick path: $path"
}

proc check_msg {inick uh handle args} {
 global botnick nick
 set args [lindex $args 0]
 if {[string tolower [lindex $args 0]] == [string tolower "!$botnick"]} {
  putserv "privmsg $inick :Private message not supported, go to file -> options -> sounds -> requests and uncheck 'send !nick file as a private message' and try again in the channel"
 }
}

proc just_one_space {line} {
 set tempstring ""
 set savefilename [split $line ":"]
 set splitstring [split [lindex $savefilename 0] " "]
 set j [llength $splitstring]
 for {set i 0} {$i<$j} {incr i 1} {
  if {[lindex $splitstring $i] != ""} {
   append tempstring "[lindex $splitstring $i] "
  }
 }
 append tempstring ";"
 append tempstring [string range [lindex $savefilename 1] 3 end]
 set retstring [string trim $tempstring]
 return $retstring
}

proc strip_string {line} {
 set ret_string ""
 set cnt 0
 while {1} {
  set tmp_char [string index $line $cnt]
  if {$tmp_char == ""} {
   set ret_string [string trim $ret_string]
   set cnta 0
   set cntb 1
   set cntc 2
   while {1} {
    if {[string index $ret_string $cntc] == ""} { return $ret_string }
    if {[string index $ret_string $cntb] == " "} {
     if {[string index $ret_string $cntc] == " "} {
      set tmp_ret_string [string range $ret_string 0 $cnta]
      append tmp_ret_string [string range $ret_string $cntc end]
      set ret_string $tmp_ret_string
     } else { 
      incr cnta 1; incr cntb 1; incr cntc 1
     }
    } else {
     incr cnta 1; incr cntb 1; incr cntc 1
    }
   }
  }
  if {$tmp_char == "\*"} {
   append ret_string " "
  } elseif {$tmp_char == "\?"} {
   append ret_string " "
  } elseif {$tmp_char == "\-"} {
   append ret_string " "
  } else {
   append ret_string $tmp_char
  }
  incr cnt
 }
}

proc globalvars {} {
 global mp3
 exec echo "" >> text/mp3Script.set
 set fileID [open text/mp3Script.set]
 set line [gets $fileID]
 if {$line != ""} {
  set $mp3(files) [string trim [lindex [split $line " "] 0]]
  set $mp3(size) [string trim [lindex [split $line " "] 1]]
  set $mp3(lines) [string trim [lindex [split $line " "] 2]]
  exec echo $mp3(files) $mp3(size) $mp3(lines) > text/mp3Script.set
 }
}
globalvars

proc ctcp_handling {nick uhost handle dest keyword args} {
 global mp3
 set keyword [string tolower $keyword]
 if {$keyword == "version"} {
  putserv "NOTICE $nick :VERSION $mp3(versionreply)"
  return 1
 } elseif {$keyword == "userinfo" || $keyword == "clientinfo" || $keyword == "finger" || $keyword == "errmsg"} {
  return 1
 }
 return 0
}

proc rand_file {} {
 global mp3 botnick nick
 if {$mp3(lines) > 0 && $mp3(lines) < 99999999} {
  set lines $mp3(lines)
  incr lines -39
  set line [rand $lines]
  incr line 17
  set fileID [open text/$nick-mp3list.doc]
  set count 0
  for {set i 1} {$i < $line} {incr i 1} { set templine [gets $fileID] }
  while {1} {
   set templine [gets $fileID]
   if {[eof $fileID] == 1} {
    close $fileID
    break
   }
   if {[string first \| $templine] != -1} {
    set tempfile [string trim [lindex [split $templine "\|"] 0]]
    set tempsize [string trim [lindex [split $templine "\|"] 2]]
    foreach chan $mp3(chans) {
     if {$mp3(color) == 1} {
      set randline [rand 7]
      if {$randline == 0} {
       putserv "privmsg $chan :15,2 \[-$mp3(announce)-\] 2,15 Type: \[ 2,15$tempfile 1,15\] To get this song! (Size:2,15 $tempsize1,15) 15,2 \[-$mp3(announce)-\] "
      } elseif {$randline == 1} {
       putserv "privmsg $chan :2,15 \[-$mp3(announce)-\] 15,2 Type: \[ 8,2$tempfile 15,2\] To get this song! (Size:8,2 $tempsize15,2) 2,15 \[-$mp3(announce)-\] "
      } elseif {$randline == 2} {
       putserv "privmsg $chan :5,7 \[-$mp3(announce)-\] 7,5 Type: \[ 0,5$tempfile 7,5\] To get this song! (Size:0,5 $tempsize7,5) 5,7 \[-$mp3(announce)-\] "
      } elseif {$randline == 3} {
       putserv "privmsg $chan :7,5 \[-$mp3(announce)-\] 5,7 Type: \[ 1,7$tempfile 5,7\] To get this song! (Size:1,7 $tempsize5,7) 7,5 \[-$mp3(announce)-\] "
      } elseif {$randline == 4} {
       putserv "privmsg $chan :11,2 \[-$mp3(announce)-\] 2,11 Type: \[ 1,11$tempfile 2,11\] To get this song! (Size:1,11 $tempsize2,11) 11,2 \[-$mp3(announce)-\] "
      } elseif {$randline == 5} {
       putserv "privmsg $chan :2,11 \[-$mp3(announce)-\] 11,2 Type: \[ 0,2$tempfile 11,2\] To get this song! (Size:0,2 $tempsize11,2) 2,11 \[-$mp3(announce)-\] "
      } else {
       putserv "privmsg $chan :0,1 \[-$mp3(announce)-\] 0,3 Type: \[ 1,3$tempfile 0,3\] To get this song! (Size:1,3 $tempsize0,3) 0,1 \[-$mp3(announce)-\] "
      }
     }
     if {$mp3(color) == 0} {
      putserv "privmsg $chan :\[-$mp3(announce)-\]  Type: \[ $tempfile \] To get this file! (Size: $tempsize)  \[-$mp3(announce)-\]"
     }
    }
    close $fileID
    break
   }
  }
 }		
}

proc commerce {} {
 global mp3 botnick nick
 foreach chan $mp3(chans) {
  if {$mp3(color) == 1} {
   putserv "privmsg $chan :0,1 \[-$mp3(announce)-\]15,1 For my list type: \[ 8,1@$botnick15,1 \] in the channel \[-->8,1 $mp3(files)15,1 Mp3's with a total size of8,1 $mp3(size)15,1 KB\].0,1 \[-$mp3(announce)-\]15,1 The TCL Mp3 script for Eggdrop 1.x re-written by DjSlash, version8,1 $mp3(version)15,1. For search-help and script: \[8,1 $mp3(url)15,1 \] 0,1\[-$mp3(announce)-\] "
  }
  if {$mp3(color) == 0} {
   putserv "privmsg $chan :\[-$mp3(announce)-\] For my list type: \[ @$botnick \] in the channel \[--> $mp3(files) Mp3's with a total size of $mp3(size) KB\]. \[-$mp3(announce)-\] The TCL Mp3 script for Eggdrop 1.x re-written by DjSlash, version $mp3(version). For search-help and script: \[ $mp3(url) \] \[-$mp3(announce)-\] "
  }
 }
}

proc CommerceMinExist {} {
 foreach timer [timers] {
  if {[lindex $timer 1] == "CommerceMin"} { return 1 }
 }
 return 0
}

proc RandFileMinExist {} {
 foreach timer [timers] {
  if {[lindex $timer 1] == "RandFileMin"} { return 1 }
 }
 return 0
}

proc CommerceMin {} {
 global mp3
 if {$mp3(ctime) == 0} { return }
 commerce
 if {[CommerceMinExist] == 0} {	timer $mp3(ctime) CommerceMin }
}
CommerceMin

proc initctime {} {
 foreach timer [timers] {
  if {[lindex $timer 1] == "CommerceMin"} {
   killtimer [lindex $timer 2]
  }
 }
 CommerceMin
}

proc initrtime {} {
 foreach timer [timers] {
  if {[lindex $timer 1] == "RandFileMin"} {
   killtimer [lindex $timer 2]
  }
 }
 RandFileMin
}

proc RandFileMin {} {
 global mp3
 if {$mp3(rtime) == 0} { return }
 rand_file
 if {[RandFileMinExist] == 0} {	timer $mp3(rtime) RandFileMin }
}
RandFileMin

putlog "MP3Script Mp3 @locator script $mp3(version) By: DjSlash Loaded..."
