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 

I have gone brain fried trying to learn this

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


Joined: 01 Apr 2018
Posts: 30

PostPosted: Thu Apr 12, 2018 5:50 am    Post subject: I have gone brain fried trying to learn this Reply with quote

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
View user's profile Send private message
caesar
Ass Kicker


Joined: 14 Oct 2001
Posts: 3450
Location: Area 51

PostPosted: Thu Apr 12, 2018 6:56 am    Post subject: Reply with quote

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?
_________________
You may say anything about me, but at least don't misspell my name. xD
Back to top
View user's profile Send private message
Draknon
Voice


Joined: 01 Apr 2018
Posts: 30

PostPosted: Thu Apr 12, 2018 7:08 am    Post subject: Reply with quote

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
View user's profile Send private message
caesar
Ass Kicker


Joined: 14 Oct 2001
Posts: 3450
Location: Area 51

PostPosted: Sat Apr 14, 2018 12:55 am    Post subject: Reply with quote

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.
_________________
You may say anything about me, but at least don't misspell my name. xD
Back to top
View user's profile Send private message
Draknon
Voice


Joined: 01 Apr 2018
Posts: 30

PostPosted: Sat Apr 14, 2018 2:22 am    Post subject: Reply with quote

thanks a lot .. got it all done now Smile
Back to top
View user's profile Send private message
SpiKe^^
Owner


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

PostPosted: Sat Apr 14, 2018 12:38 pm    Post subject: Delayed Random Greet v.0.1 by SpiKe^^ Reply with quote

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


Last edited by SpiKe^^ on Sun Apr 15, 2018 11:07 am; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
Draknon
Voice


Joined: 01 Apr 2018
Posts: 30

PostPosted: Sun Apr 15, 2018 1:34 am    Post subject: Reply with quote

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
View user's profile Send private message
Draknon
Voice


Joined: 01 Apr 2018
Posts: 30

PostPosted: Mon Apr 16, 2018 1:18 am    Post subject: Reply with quote

so far it seems to be working perfectly.
Back to top
View user's profile Send private message
caesar
Ass Kicker


Joined: 14 Oct 2001
Posts: 3450
Location: Area 51

PostPosted: Mon Apr 16, 2018 4:53 am    Post subject: Reply with quote

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.
_________________
You may say anything about me, but at least don't misspell my name. xD
Back to top
View user's profile Send private message
SpiKe^^
Owner


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

PostPosted: Mon Apr 16, 2018 6:00 pm    Post subject: Reply with quote

Thanks for testing that, Draknon:)
_________________
SpiKe^^

Get BogusTrivia 2.06.4.7 at www.mytclscripts.com
Back to top
View user's profile Send private message Visit poster's website
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