egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

help with this script

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
Zohaib
Voice


Joined: 18 May 2011
Posts: 22

PostPosted: Fri Feb 06, 2015 3:38 am    Post subject: help with this script Reply with quote

hello,
I need help wit his script, it will read a vhost from list and say it on channel and then remove it from list too so it dont give the same reply again. I am able to made this to read random vhosts from list but how do I make it to delete that vhost from list so it is not repeated again. thanks in advance

Code:
set vhostlist {

"vhost1.balabla.balabala"
"vhost2.balabla.balabala"
"vhost3.balabla.balabala"
"vhost4.balabla.balabala"
"vhost5.balabla.balabala"
"vhost6.balabla.balabala"
}

bind pub _ !vhost pub_vhost

proc pub_vhost {nick host hand channel args} {
putserv "PRIVMSG $channel : [randvhost $args]"
}




proc randvhost {nick} {
       global vhostlist
       return [lindex $vhostlist [expr int(rand()*[llength $vhostlist])]]
}

_________________
<Zohaib>
Back to top
View user's profile Send private message
SpiKe^^
Owner


Joined: 12 May 2006
Posts: 792
Location: Tennessee, USA

PostPosted: Fri Feb 06, 2015 12:31 pm    Post subject: Reply with quote

Try this...
Code:
set vhostlist {
"vhost1.balabla.balabala"
"vhost2.balabla.balabala"
"vhost3.balabla.balabala"
"vhost4.balabla.balabala"
"vhost5.balabla.balabala"
"vhost6.balabla.balabala"
}

bind pub _ !vhost pub_vhost

proc pub_vhost {nick host hand channel text} {
  putserv "PRIVMSG $channel : [randvhost $text]"
}

proc randvhost {nick} {
  global vhostlist

  # save the index number of the chosen list item #
  set ret [lindex $vhostlist [set idx [rand [llength $vhostlist]]]]

  # remove the chosen item from the list #
  set vhostlist [lreplace $vhostlist $idx $idx]

  return $ret
}
Note: rehashing/restarting the bot will start again with all items in the provided list.
_________________
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
Back to top
View user's profile Send private message Visit poster's website
Zohaib
Voice


Joined: 18 May 2011
Posts: 22

PostPosted: Sat Feb 07, 2015 12:59 pm    Post subject: Reply with quote

thanks SpiK^^ ok I try to modify it by Saving it in a vhost.txt file, then it will not start again after rehash/restart right?
_________________
<Zohaib>
Back to top
View user's profile Send private message
SpiKe^^
Owner


Joined: 12 May 2006
Posts: 792
Location: Tennessee, USA

PostPosted: Sat Feb 07, 2015 2:11 pm    Post subject: Reply with quote

Yes, you could put the vhosts in a text file, read them and pick one, then rewrite the file without the chosen vhost....
That would make the script remember where it was with the provided list.

When you have some of that wrote, post it back here for review:)

Goodluck,
_________________
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
Back to top
View user's profile Send private message Visit poster's website
Zohaib
Voice


Joined: 18 May 2011
Posts: 22

PostPosted: Mon Feb 09, 2015 1:27 pm    Post subject: Reply with quote

Code:


bind pub _ !vhost pub_vhost

proc pub_vhost {nick host hand channel text} {
  putserv "PRIVMSG $channel : [randvhost $text]"
}

proc randvhost {nick} {
  set vhostlist "/home/fun/eggdrop/scripts/vhosts.cfg"
  set f [open $vhostlist r ]
  set data [read -nonewline $f]
  set lines [split $data "\n"]
  set randline [lindex $lines [set idx [rand [llength $lines]]]]
  set lines [lreplace $lines $idx $idx]
  set f [open $f "w"]
  puts $f [join $lines "\n"]
  close $f
  return $randline
}


it reads from the line but it is not removing it. please tell me where i am doing it wrong
_________________
<Zohaib>
Back to top
View user's profile Send private message
SpiKe^^
Owner


Joined: 12 May 2006
Posts: 792
Location: Tennessee, USA

PostPosted: Mon Feb 09, 2015 10:57 pm    Post subject: Reply with quote

Very close, but no cigar:)

1) You opened the file for reading only, which is fine, read the contents to a variable and close the file.

2) You can't do [open $f "w"], $f is just the channel reference to the file we opened earlier, not a route/file.name

You should try something more like this...
Code:

bind pub _ !vhost pub_vhost

proc pub_vhost {nick host hand channel text} {
  putserv "PRIVMSG $channel : [randvhost $text]"
}

proc randvhost {nick} {
  set vhostlist "/home/fun/eggdrop/scripts/vhosts.cfg"

  # open the vhost file, read it to a var, and close the file #
  set f [open $vhostlist r]
  set data [read -nonewline $f]
  close $f

  # split $data to a list, choose one to show, and remove it from list #
  set lines [split $data "\n"]
  set randline [lindex $lines [set idx [rand [llength $lines]]]]
  set lines [lreplace $lines $idx $idx]

  # open vhost file for writing, write the file, and close the file #
  set f [open $vhostlist w]
  puts $f [join $lines "\n"]
  close $f

  return $randline
}


_________________
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
Back to top
View user's profile Send private message Visit poster's website
Zohaib
Voice


Joined: 18 May 2011
Posts: 22

PostPosted: Tue Feb 10, 2015 1:13 am    Post subject: Reply with quote

I see. Thanks SpiKe^^ wasn't possible for me without your help. Thanks again Smile
_________________
<Zohaib>
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber