bind pub o|o $botnick single_use

proc single_use {nick2 host hand chan text} {
global nick
set my_say [lindex $text 0]
set to_say [lrange $text 1 end]
set to_sayc [lrange $text 2 end]
set new_chan [lindex $text 1]
set new_nick [lindex $text 1]
set old_chan [lindex $text 1]
set new_user [lindex $text 1]
set new_mask [lindex $text 2]
set handles [lindex $text 1]
set modes [lindex $text 2]
set cchan [lindex $text 3]
set hostnick [lindex $text 1]
set ahost [lindex $text 2]
set hostmasks [getuser $hostnick hosts]
set dhostnick [lindex $text 1]
set dhost [lindex $text 2]
set hostmasks [getuser $dhostnick hosts]
set rnick [lindex $text 1]


   if {$my_say == "say"} { putquick "PRIVMSG $chan :$to_say" }
   if {$my_say == "tell"} { putquick "PRIVMSG $new_chan :$to_sayc" }
    if {$my_say == "join"} {
if {$new_chan == ""} { putlog  "###CORE### Trebuie setat un canal." ; return 0
}  else {

channel add $new_chan {
chanmode "+nt"
flood-chan 60:60
flood-ctcp 60:60
flood-deop 3:10
flood-kick 3:10
flood-join 5:60
-clearbans +cycle +enforcebans -dynamicbans +userbans -bitch +greet -protectops -statuslog +shared
+seen -revenge -stopnethack -autoop +dontkickops -autovoice -secret
  }
putlog  "###CORE### Am intrat pe $new_chan la cererea lui $nick care are hand = $hand"
     }
}

    if {$my_say == "nick"} { set nick $new_nick ; save }
    if {$my_say == "part"} {
if {$old_chan == ""} { channel remove $chan
} else { channel remove $old_chan }
 }
    if {$my_say == "adduser"} {

if {[matchattr $hand n] != 0} {
        if {[validuser $new_user] == 1} {
        putserv "PRIVMSG $chan :$new_user is already in my userlist"
        putlog "$nick attempted to add $new_user to my userlist, $new_user is already in my userlist"
        return 0
 }

        putlog "adding $new_user to the userlist, mask: \[$new_mask\] by $nick"
        putserv "PRIVMSG $chan :\00304$new_user \00302added to userlist"
        adduser $new_user $new_mask
return 0
 }
}

     if {$my_say == "chattr"} {
 if {[matchattr $hand n] != 0} {
        if {[validuser $handles] == 1} {
        if {$cchan == "" } {
        putlog "changing modes $modes for $handles by $nick"
        putserv "PRIVMSG $chan :\00302Changed modes \00304$modes \00302for $handles on \00304all channels"
        chattr $handles $modes
}
        if {$cchan != ""} {
        putlog "changing modes $modes for $handles on $cchan by $nick"
        putserv "PRIVMSG $chan :\00302Changed modes \00304$modes \00302for $handles on \00304$cchan"
        chattr $handles |$modes $cchan
 }
 }
return 0
 }
putserv "PRIVMSG $chan :$handles is not in my userlist"
return 0
}
 }

      if {$my_say == "addhost"} {

   if {[matchattr $hand n] != 0} {
        if {[validuser $hostnick] != 1} {
        putserv "PRIVMSG $chan :$hostnick is not in my userlist"
        putlog "$nick attempted to add $ahost to $hostnick in my userlist, $hostnick is not in my userlist"
return 0
}
        set hostmasks [getuser $hostnick hosts]
        if { [lsearch -exact $hostmasks $ahost]>-1 } {
        putserv "PRIVMSG $chan :Hostmask $ahost for user $hostnick already exists"
        putlog "$nick attempted to add $ahost to $hostnick in my userlist, $ahost already exists for $hostnick"
return 0
}
        setuser $hostnick HOSTS $ahost
        putserv "PRIVMSG $chan :\00302Added $ahost to \00304$hostnick \00302in my userlist"
        putlog "$nick added $ahost to $hostnick"
return 0
 }
}

      if {$my_say == "delhost"} {

 if {[matchattr $hand n] != 0} {
        if {[validuser $dhostnick] != 1} {
        putserv "PRIVMSG $chan :$dhostnick is not in my userlist"
        putlog "$nick attempted to delete $dhost from $dhostnick in my userlist, $dhostnick is not in my userlist"
return 0
}
        set hostmasks [getuser $dhostnick hosts]
        if { [lsearch -exact $hostmasks $dhost] == -1 } {
        putserv "PRIVMSG $chan :Hostmask $dhost for user $dhostnick does not exist"
putlog "$nick attempted to delete $dhost from $dhostnick in my userlist, $dhost does not exist for $dhostnick"
return 0
}
        delhost $dhostnick $dhost
        putserv "PRIVMSG $chan :\00302Deleted $dhost from  \00304$dhostnick  \00302in my userlist"
        putlog "$nick deleted $dhost from $dhostnick"
return 0
 }
}


       if {$my_say == "remuser"} {

if {[matchattr $hand n] != 0} {
        if {[validuser $rnick] == 1} {
        putlog "removing $rnick from the userlist at $nick's request"
        putserv "PRIVMSG $chan :\00304$rnick \00302removed from userlist"
        deluser $rnick
return 0
 }
putserv "PRIVMSG $chan :$rnick is not in my userlist"
return 0
}
  }
}
