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.

I have gone brain fried trying to learn this

Help for those learning Tcl or writing their own scripts.
Post Reply
D
Draknon
Voice
Posts: 30
Joined: Sun Apr 01, 2018 8:24 am

I have gone brain fried trying to learn this

Post by Draknon »

Code: Select all

on 1:JOIN:#:/play -r #The-Dungeon C:\random\random.txt 120000
what that line does is "plays"(similar to PRIVMSG $chan) a random line from file random.txt at a 3 min delay

so my question is either where do I get the info for getting a random line from a file to send to the chan or.. what is the command to do it?

and would the bind look like ..

Code: Select all

bind join - *!*@* join_random
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Have a look at Basic File Operations where you will find a few examples on how to read a line, multiple or even a random line.

As for the mIRC code you mentioned it spits out a line from that file every 3 minutes? Dose it ever stops? When?
Once the game is over, the king and the pawn go back in the same box.
D
Draknon
Voice
Posts: 30
Joined: Sun Apr 01, 2018 8:24 am

Post by Draknon »

1st: thank you very much, that will help immensly..

2nd:
As for the mIRC code you mentioned it spits out a line from that file every 3 minutes? Dose it ever stops? When?
it is only triggered when a person joins the chan then 3 min later plays 1 random line and stops there.
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

1. You can turn the "*!*@*" turned into "*" without a problem.

2. In this case an utimer will do the trick. Have a look at tcl-commands.doc that comes with the bot in it's doc folder (or grab it from here in pdf format) where everything is nicely explained.
Once the game is over, the king and the pawn go back in the same box.
D
Draknon
Voice
Posts: 30
Joined: Sun Apr 01, 2018 8:24 am

Post by Draknon »

thanks a lot .. got it all done now :)
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Delayed Random Greet v.0.1 by SpiKe^^

Post by SpiKe^^ »

Draknon: a little late, but please try this out and see if it will run:)

Code: Select all

# Delayed Random Greet v.0.1 by SpiKe^^ (14Apr2018) #

# set file name to read #
set filename "yourfile.txt"

# set send message delay (in seconds) #
set msgdelay "180"

# set channel(s) this script monitors (space sep list) #
#  ex.  set msgchan "#channel"
#  ex.  set msgchan "#chan #chan2 #another"
#  or use "*" for all channels the bot is on.
set msgchan "*"

####### End of Settings #######

bind join - * checkjoin

set msgchan [split $msgchan]

proc checkjoin {nk uh hn ch} {  global msgdelay msgchan
  if {[lsearch -nocase $msgchan $ch]=="-1" || [isbotnick $nk]} {
    return 0
  }
  utimer $msgdelay [list sendrandom $nk $ch]
  return 0
}

proc sendrandom {nk ch} {  global filename msglist
  if {![file exists $filename]} {  return 0  }

  # read the entire file into a list #
  set openfile [open $filename "r"]
  set data [split [read -nonewline $openfile] "\n"]
  close $openfile

  # does some short term msg tracking #
  # tries to read all lines once, before reading any lines a second time #
  # .restart or killing the bot will clear this tracking data #
  if {![info exists msglist]} {  set cnt 0
    set x [llength $data]
    while {$cnt < $x} {
      lappend msglist $cnt
      incr cnt
    }
  }

  # choose a random line from the file #
  if {[llength $msglist]==1} {
    set nxidx [join $msglist]
    unset msglist
  } else {  set x [rand [llength $msglist]]
    set nxidx [lindex $msglist $x]
    set msglist [lreplace $msglist $x $x]
  }

  set next [lindex $data $nxidx]
  puthelp "PRIVMSG $ch :$next"
  return 0
}

putlog "Delayed Random Greet v.0.1 loaded."

Last edited by SpiKe^^ on Sun Apr 15, 2018 11:07 am, edited 1 time in total.
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
D
Draknon
Voice
Posts: 30
Joined: Sun Apr 01, 2018 8:24 am

Post by Draknon »

Draknon: a little late, but please try this out and see if it will run:)
I'll give it a shot..
D
Draknon
Voice
Posts: 30
Joined: Sun Apr 01, 2018 8:24 am

Post by Draknon »

so far it seems to be working perfectly.
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Is there a reason for complicating things and not using the example in Basic File Operations?

Code: Select all

# open file for read access
set fp [open $filename "r"]

# read in all of the data
set data [read -nonewline $fp] 

# split the data into lines
set lines [split $data "\n"]

# close the file, since we're done reading
close $fp

# count the number of lines
set numlines [llength $lines]

# grab a random line
set num [expr {int(rand()*$numlines) + 1}]

# grab the random picked line from the list
set randline [lindex $lines $num]

puthelp "PRIVMSG $ch :$randline" 
I added the random part cos [rand 10] for instance starts from 0 instead of 1 and will go up to 9 instead of 10. But if you insist into using rand then make it [expr [rand $numlines] +1] to fix the randomness. In Spike's example would be [expr [rand $msglist] +1]

If you want to spice things up a bit by adding the name of the person that joined or the channel inside the line you are reading you can adjust your lines to have them in a format for example:

Code: Select all

hello %nick, welcome to %chan channel..
shhh! %nick joined, let's stop talking about him in %chan channel xD
... and so on
then that:

Code: Select all

puthelp "PRIVMSG $ch :$randline" 
line becomes:

Code: Select all

puthelp "PRIVMSG $ch :[string map [list %nick $nk %chan $ch] $randline]"
and the bot will substitute %nick with the actual nick and %chan with the actual channel name.
Last edited by caesar on Tue Jul 24, 2018 2:29 am, edited 1 time in total.
Once the game is over, the king and the pawn go back in the same box.
User avatar
SpiKe^^
Owner
Posts: 831
Joined: Fri May 12, 2006 10:20 pm
Location: Tennessee, USA
Contact:

Post by SpiKe^^ »

Thanks for testing that, Draknon:)
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
Post Reply