# Fusi0n Services Bot (FSB) v1.0 beta

# Configuration

# Auto Adduser on join with these flags
set FSBData ""
set FSB(autoadd) 1
set FSB(autoflag) v

# Public Commands trigger (usualy 1 char)
set FSB(trigger) "."

# Private Meggage Commands Trigger (leave blank if no trigger ex: op #uber-nuber Fusi0n)
set FSB(ptrigger) ""

# Allow Quotes
set FSB(quotes) 1

# BINDS

bind pubm - * FSB_trigger

# CORE
set FSB(file) "chan.local"
proc FSB_trigger {nick mask hand chan arg} {
  global FSB
  if {[string first "$FSB(trigger)" "$arg"] == 0} { set arg "[string trimleft "$arg" "$FSB(trigger)"]"
    putserv "privmsg $chan :Command: [lindex $arg 0] Arg: [lrange $arg 1 end]"
    if {[FSB_cmd $nick $mask $hand $chan "[lindex $arg 0]" "[lrange $arg 1 end]"] == "Invalid"} { putserv "privmsg $chan ::Invalid Cmd:" }
  }
}
proc FSB_cmd {nick mask hand chan cmd arg} {
  global FSB
  switch [string tolower $cmd] {
    rehash {
      rehash
      putserv "privmsg $chan ::Rehash: Scripts Reloaded."
    }
    set {
      set file [open $FSB(file) w]
      puts $file "$chan [lindex $arg 0] [lrange $arg 1 end]"
      close $file
      putserv "privmsg $chan ::Set: Commands set."
    }
    default {
        "privmsg $chan : $FSBData($cmd)" 
    }
  }
}
putlog ":Fusi0n Services Bot v1.0b: Loaded"

# Ripped Proc's
# load from BotToolbox (great script that he will never finish :P) by: Tetryon
proc FSB_load {{save ""}} {
  global FSBData FSB
  if {![file exists $FSB(file)]} { return 0 }
  set file [open $FSB(file) r]
  while {![eof $file]} {
    set text [gets $file]
    set FSBData([lindex $text 1]) "[lrange putlog $text 2 end]"
  }
  set FSBData(_MTIME) "[file mtime $FSB(file)]"
  close $file
  return 1
}
