This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

vhost.tcl

Help for those learning Tcl or writing their own scripts.
Post Reply
User avatar
aslpls
Halfop
Posts: 47
Joined: Mon May 02, 2016 9:41 am

vhost.tcl

Post by aslpls »

hello all, the script is working.. but there's a small issue. need help

here is the tcl error below

this is dcc from the bot after the user type in the channel !vhost day.to.day

Code: Select all

<Vhost> [02:01:40] Tcl error [join:ran]: random limit must be greater than 0
<Vhost> [02:01:47] -NOTICE- chgcmds.CHGHOST_COMMAND [info] CHGHOST: Vhost changed the virtual hostname of daytoday!daytoday@2607:f130:0:103:ff:ff:1d8b:621a to be day.to.day
this is the user requesting a vhost from the channel

Code: Select all

<daytoday> !vhost day.to.day
-Vhost- Your new VHost is: day.to.day
-Vhost- You may only have one vhost change per 30 minutes.
and right way the user vhost from this daytoday (daytoday@31B0C90E:845C875F:D93239FF:IP) to daytoday is daytoday@day.to.day * daytoday


here's the script

Code: Select all

#  VHost TCL By ctd1500 < vhost@coolchat-irc.org | ctd1500 on irc.p2pchat.net >              #
#  You can get this script at http://www.coolchat-irc.org                                    #
#                                                                                            #
#  If you are not a Server Administrator or higher on an IRC Network that runs Unreal IRCd   #
#  or Ultimate IRCd, then you can't use this script unless there are other IRCd's that use   #
#  the same commands.                                                                        #
#                                                                                            #
#  The bot *MUST* be an IRCOp with the ability to use the "/chghost" command.                #
#                                                                                            #
#                                                                                            #
#                             CopyRight 2003-2006 ctd1500                                    #
#                                                                                            #

# Set this to the Command Character of you're choice (default is !) #
set PUBCMD "!"

bind msg -|- vhost msg:vhost
bind msg n oper oper-up
bind pub -|- ${PUBCMD}vhost pub:vhost
bind pub -|- ${PUBCMD}randomvhost pub:ranvhost
bind join -|- *!*@* join:ran
bind msg -|- random msg:ran
bind msg -|- addvhost msg:addvhost
bind bot -|- auto-oper auto-oper

# Set this to the channel you want your bot to give out VHost's from #
set vhostchan "#vhost"

# Set this to your eggdrop's nickname. #
set botnickname "Vhost"

# Set this to your eggdrop's alt nick. #
set botaltnick "Vhost"

# Change this to your nickname #
set owner2 "aslpls"

# Set this to be how long (in minutes) you want to ban/ignore a user after they get a vhost. #
set bntime "30"

# Enable or disable public commands here. (on / off) #
  # !randomvhost #
set pub_randomvhost "on"
  # !vhost #
set pub_vhost "on"
  # /msg bot vhost vhost.here #
set msg_vhost "on"
  # /msg bot random #
set msg_random "on"


# Set this to the nicknames you want to allow to add new VHosts to the bot's list. (separate with a space) #
set vhostnicks "$owner2"

# Alternatively (and more securely) you can set a flag that users must have in order to add vhosts. #
set add_vhost_flag "V"

# Set the type of authentication you want to use for people to add VHosts. (flag / nicks) #
set av_type "flag"


# Set this to the bot's O-Line username #
set operid "oper-id"

# Set this to the bots O-Line password #
set operpass "passowrd-ircop"

# Set this to the nicknames you want exempt from getting vhosts when they join the VHost channel. (separate with a space) #
set exemptnicks "$owner2 $botnick $botaltnick"

proc oper-up {nick host chan text} {
  global operid operpass owner2
  putserv "OPER $operid $operpass"
  putserv "NOTICE $owner2 :I Opered up"
}
set vhost_masktype 2
proc msg:vhost {nick uhost hand vhost} {
  global bntime msg_vhost
  if {$msg_vhost == "on"} {
  set vhost [lindex $vhost 0]
  set fullvhost "*!*[string range $uhost [string first ! $uhost] 4]*@[string range $vhost [string first @ $vhost] end]"
  set ihost [vhost:masktype $uhost]
  putserv "CHGHOST $nick $vhost"
  putserv "NOTICE $nick : Your Vhost has been changed to: $vhost"
  putserv "NOTICE $nick : You may only have one vhost change per $bntime minutes."
  newignore $ihost VHost $nick $bntime
  newignore $fullvhost VHost $nick $bntime
  } else {
  putserv "PRIVMSG $nick :The msg vhost command has been turned off."
  }
}

proc auto-oper {} {
  global operid operpass botnick vhostchan
  putquick "OPER $operid $operpass"
  putserv "SAMODE $vhostchan +o $botnick"
}

proc join:ran {nick host hand chan} {
  global ison operid operpass botnick vhostchan exemptnicks bntime
  set joinvhost "[get_vhost]"
  set realbhost [vhost:masktype $host]
  if {$chan == "[lindex $vhostchan 0]" && ([lsearch -exact [string tolower $exemptnicks] [string tolower $nick]] == -1)} {
  putquick "CHGHOST $nick $joinvhost"
  putserv "MODE $vhostchan +b $realbhost"
  putserv "MODE $vhostchan +b *!*@$joinvhost"
  putserv "MODE $vhostchan +b $realbhost"
  puthelp "KICK $vhostchan $nick one vhost change per $bntime minutes."
  puthelp "NOTICE $nick :Your new VHost is: $joinvhost"
  puthelp "NOTICE $nick :You may only have one vhost change per $bntime minutes."
  timer $bntime "pushmode $vhostchan -b *!*@$joinvhost"
  timer $bntime "pushmode $vhostchan -b $realbhost"
  }
  if {$chan == "[lindex $vhostchan 0]" && ($nick == $botnick)} {
  timer 1 "auto-oper"
  }
}

proc vhost:masktype {uhost} {
  global vhost_masktype
  switch -exact -- $vhost_masktype {
    0 {return *!*[string range $uhost [string first @ $uhost] end]}
    1 {return *!*$uhost}
    2 {return *!*[lindex [split [maskhost $uhost] "!"] 1]}
  }
  return
}

proc msg:ran {nick uhost hand read} {
  global bntime msg_random 
  if {$msg_random == "on"} {
  set ranvhost "[get_vhost]"
  set fullvhost "*!*[string range $uhost [string first ! $uhost] 4]*@[string range $ranvhost [string first @ $ranvhost] end]"
  set ihost [vhost:masktype $uhost]
  putserv "CHGHOST $nick $ranvhost"
  putserv "NOTICE $nick :Your new VHost is: $ranvhost"
  putserv "NOTICE $nick :You may only have one vhost change per $bntime minutes."
  newignore $ihost VHost $nick $bntime
  newignore $fullvhost VHost $nick $bntime
  } else {
  putserv "PRIVMSG $nick :The msg random command has been turned off."
  }
}

proc pub:vhost {nick uhost hand chan text} {
  global bntime pub_vhost PUBCMD
  if {$pub_vhost == "on"} {
  set vhost [lindex $text 0]
  set fullvhost "*!*[string range $uhost [string first ! $uhost] 4]*@[string range $vhost [string first @ $vhost] end]"
  set ihost [vhost:masktype $uhost]
  putserv "CHGHOST $nick $vhost"
  putserv "NOTICE $nick :Your new VHost is: $vhost"
  putserv "NOTICE $nick :You may only have one vhost change per $bntime minutes."
  newignore $ihost VHost $nick $bntime
  newignore $fullvhost VHost $nick $bntime
  } else {
  putserv "NOTICE $nick :The ${PUBCMD}vhost command has been turned off."
  }
}
proc pub:ranvhost {nick uhost hand chan text} {
  global bntime pub_randomvhost PUBCMD
  if {$pub_randomvhost == "on"} {
  set ranvhost "[get_vhost]"
  set fullvhost "*!*[string range $uhost [string first ! $uhost] 4]*@[string range $ranvhost [string first @ $ranvhost] end]"
  set ihost [vhost:masktype $uhost]
  putserv "CHGHOST $nick $ranvhost"
  putserv "NOTICE $nick :Your new VHost is: $ranvhost"
  putserv "NOTICE $nick :You may only have one vhost change per $bntime minutes."
  newignore $ihost VHost $nick $bntime
  newignore $fullvhost VHost $nick $bntime
  } else {
  putserv "NOTICE $nick :The ${PUBCMD}random command has been turned off."
  }
}

proc get_vhost { } {
  set f [open "VHostlist.txt" r]
  set vhostcount 0
  while {[gets $f line] != -1} {
    incr vhostcount
  }
  close $f
  set vhostcount [expr $vhostcount -1]

  set vhostnum [rand $vhostcount]

  set f [open "VHostlist.txt" r]
  set vnum 0
  while {$vnum <= $vhostcount} {
    gets $f line
    incr vnum
    set vhnum [expr $vnum -1]
    if {$vhnum == $vhostnum} {
      set vhost "[lrange $line 0 end]"
      if {$vhost == ""} {
        set vhostnum [rand $vhostcount]
        set vnum 0
      }
    }
  }
  return $vhost
}

proc msg:addvhost { nick host hand arg } {
global av_type add_vhost_flag vhostnicks

set allowed "0"
if {$av_type == "flag"} {
  if {[matchattr $hand $add_vhost_flag]} {
    set allowed "1"
  }
} elseif {$av_type == "nicks"} {
  if {([lsearch -exact [string tolower $vhostnicks] [string tolower $nick]] != -1)} {
    set allowed "1"
  }
} else {
  set allowed "0"
}

if {$allowed == "1"} {

    set newvhost "$arg"
    set f [open "VHostlist.txt" r]
    set tmpf [open "VHostlist.txt.tmp" w]

    while {[gets $f line] != -1} {
      puts $tmpf "$line"
    }

    puts $tmpf "$newvhost"
    putserv "PRIVMSG $nick :The new VHost: \"$newvhost\" has been added to the list."

    close $f
    close $tmpf

    set f [open "VHostlist.txt.tmp" r]
    set vhostdb "[read $f]"
    close $f
    set f [open "VHostlist.txt" w]
    puts $f "$vhostdb"
    close $f
    return 0
  } else {
    putserv "PRIVMSG $nick :You do not appear to be allowed to add vhosts to this bot.."
  }
}

putlog "\002(1: \0039VHOST\003)\002 Loaded: \002VHOST v1.0.5\002 by ctd1500 <vhost@coolchat-irc.org>"
putlog "\002(1: \0039VHOST\003)\002 From The CoolChat-IRC Network -- \002http://www.coolchat-irc.org\002"

It was FUNNY!
User avatar
CrazyCat
Revered One
Posts: 1299
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Re: vhost.tcl

Post by CrazyCat »

I think the trouble is in the get_vhost procedure, probably you have only one line in VHostlist.txt so you try to make a rand on 0 (value of $vhostcount if there is only one line).

Here is a modification (and probably optimisation) of this proc:
proc get_vhost { } {
   set fi [open "VHostlist.txt" r]
   set vhosts [split [read -nonewline $fi] "\n"]
   close $fi
   set vhostcount [llength $vhosts]
   if {$vhostcount < 1} {
      putlog "Error : no vhost in VHostlist.txt"
      return 
   }
   return [lindex $vhosts [rand $vhostcount]]
}
Note that your VHostlist.txt must not contain empty lines
User avatar
aslpls
Halfop
Posts: 47
Joined: Mon May 02, 2016 9:41 am

Re: vhost.tcl

Post by aslpls »

Thanks Crazycat now working as it is.
It was FUNNY!
Post Reply