| View previous topic :: View next topic |
| Author |
Message |
Draknon Voice
Joined: 01 Apr 2018 Posts: 30
|
Posted: Thu Apr 12, 2018 5:50 am Post subject: I have gone brain fried trying to learn this |
|
|
| Code: | | 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: | | bind join - *!*@* join_random |
|
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Thu Apr 12, 2018 6:56 am Post subject: |
|
|
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. |
|
| Back to top |
|
 |
Draknon Voice
Joined: 01 Apr 2018 Posts: 30
|
Posted: Thu Apr 12, 2018 7:08 am Post subject: |
|
|
1st: thank you very much, that will help immensly..
2nd: | Quote: | | 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. |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Sat Apr 14, 2018 12:55 am Post subject: |
|
|
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. |
|
| Back to top |
|
 |
Draknon Voice
Joined: 01 Apr 2018 Posts: 30
|
Posted: Sat Apr 14, 2018 2:22 am Post subject: |
|
|
thanks a lot .. got it all done now  |
|
| Back to top |
|
 |
SpiKe^^ Owner

Joined: 12 May 2006 Posts: 792 Location: Tennessee, USA
|
Posted: Sat Apr 14, 2018 12:38 pm Post subject: Delayed Random Greet v.0.1 by SpiKe^^ |
|
|
Draknon: a little late, but please try this out and see if it will run:)
| Code: |
# 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."
|
_________________ SpiKe^^
Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
or visit the New Tcl Acrhive at www.tclarchive.org
.
Last edited by SpiKe^^ on Sun Apr 15, 2018 11:07 am; edited 1 time in total |
|
| Back to top |
|
 |
Draknon Voice
Joined: 01 Apr 2018 Posts: 30
|
Posted: Sun Apr 15, 2018 1:34 am Post subject: |
|
|
| Quote: | | Draknon: a little late, but please try this out and see if it will run:) |
I'll give it a shot.. |
|
| Back to top |
|
 |
Draknon Voice
Joined: 01 Apr 2018 Posts: 30
|
Posted: Mon Apr 16, 2018 1:18 am Post subject: |
|
|
| so far it seems to be working perfectly. |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Mon Apr 16, 2018 4:53 am Post subject: |
|
|
Is there a reason for complicating things and not using the example in Basic File Operations?
| Code: |
# 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: |
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: |
puthelp "PRIVMSG $ch :$randline"
|
line becomes:
| Code: |
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. _________________ Once the game is over, the king and the pawn go back in the same box.
Last edited by caesar on Tue Jul 24, 2018 2:29 am; edited 1 time in total |
|
| Back to top |
|
 |
SpiKe^^ Owner

Joined: 12 May 2006 Posts: 792 Location: Tennessee, USA
|
Posted: Mon Apr 16, 2018 6:00 pm Post subject: |
|
|
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
. |
|
| Back to top |
|
 |
|