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 

Play text file

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
Madalin
Master


Joined: 24 Jun 2005
Posts: 301
Location: Constanta, Romania

PostPosted: Mon Feb 27, 2017 7:50 am    Post subject: Play text file Reply with quote

Im trying to make a text file to play on a channel with commands like !start !stop !resume and !pause

!start and !stop no problem ... but !pause and !resume i cant really figure it out Smile i messed the code so far that i didnt know what ive done good or wrong..

This is the code i managed to save upon now..

Code:
bind PUB - !start pub:prestart
bind PUB - !pause pub:pause
bind PUB - !resume pub:resume
bind PUB - !stop pub:stop

proc pub:prestart {nick uhost hand chan arg} {
   global class

   set class(end) 0
   set class(numara) -1
   set class(linie) -1

   class:start $chan $nick
}

proc class:start {chan nick} {
   global class

   set of [open class]

   incr class(numara)
   
   while {[gets $of line] ne -1} {
      incr class(linie)
      if {$class(end)} { close $of; putlog "Ne oprim"; return }
      
      if {$class(numara) eq $class(linie)} {

         putserv "PRIVMSG $chan :$line"
         close $of
      }
   }
   class:start $chan $nick
}

proc pub:stop {nick uhost hand chan arg} {
   global class

   if {![info exists class(start)]} { putquick "PRIVMSG $chan :\002::\002 Nu ruleaza nimic nu am ce opri"; return }

   set class(end) 1

   putquick "PRIVMSG $chan :\002::\002 Am oprit cu succes"
}


If someone can give me some HINTS ill apreaciate
_________________
https://github.com/MadaliNTCL - To chat with me: https://tawk.to/MadaliNTCL
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger
caesar
Ass Kicker


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

PostPosted: Mon Feb 27, 2017 10:39 am    Post subject: Reply with quote

What you are looking for is called offset and as far as I know this can be accomplished only with seek, but since this is binary you basically need to make an index of where the each line starts and ends.

Long story told short, have a look at a good example from here and you will easily figure out based on that example how to read any given line.

If stuck drop a reply. Smile
_________________
You may say anything about me, but don't misspell my name.
Back to top
View user's profile Send private message
Madalin
Master


Joined: 24 Jun 2005
Posts: 301
Location: Constanta, Romania

PostPosted: Mon Feb 27, 2017 12:30 pm    Post subject: Reply with quote

Yeah that would be nice .. i tryed to test the code ... yet i have for three lines

Code:

proc lineindex filename {
    set res 0
    set fp [open $filename]
    while {[gets $fp line]>=0} {lappend res [tell $fp]}
    close $fp
    set res
 }



[14:26:55] 0 10 20 28

And why set rest at the end of this proc ?

But i dont know how to use the second proc from the example

Code:
proc lineread {fp index line} {
    seek $fp [lindex $index $line]
    gets $fp
 }


I mean .tcl lineread class 0 1, where class is the file it doesnt work.


PS: Starting from this example i can create my own array index and get the numbers from there var(1) "text" and get everything from there.. yet it would increase the memory of the eggdrop for a while
_________________
https://github.com/MadaliNTCL - To chat with me: https://tawk.to/MadaliNTCL
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger
caesar
Ass Kicker


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

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

Like i said this is binary, so from 0 to 10 is the first line, from 10 to 20 the second and from 20 to 28 the third, or that's how I imagine things are. I had a line with 6 lines and the output of lineindex was 0 8 16 24 32 40 41 and thus my silly explanation makes some sense after all. Smile

You need to alter the second piece of code to "point" it to the opened file:
Code:

proc lineRead {filename index line} {
   set fp [open $filename]
   seek $fp [lindex $index $line]
   set data [gets $fp]
   close $fp
   set data
}

And then build the index and call the above code to grab whatever line you want.
Code:

set filename "class"

# build lines index
set index [lineindex $filename]

# read 3rd line from file
set result [lineRead $filename $index 3]

The set res will just return the output, just like a return $res.

How many lines and how long are them in text file you want to read anyway? If this is running on linux I'm sure there are better ways to use the system tools to get the same results at a lower CPU/RAM usage if that's your concern.
_________________
You may say anything about me, but don't misspell my name.
Back to top
View user's profile Send private message
Madalin
Master


Joined: 24 Jun 2005
Posts: 301
Location: Constanta, Romania

PostPosted: Mon Feb 27, 2017 1:31 pm    Post subject: Reply with quote

Its a script im making for a friend .. he wants to play maximum 100 lines. He just wants stop/start/pause/resume commands, so nothing major.
_________________
https://github.com/MadaliNTCL - To chat with me: https://tawk.to/MadaliNTCL
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger
caesar
Ass Kicker


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

PostPosted: Mon Feb 27, 2017 1:41 pm    Post subject: Reply with quote

When you pause you can save the offset into a channel string, for instance in your code you got:
Code:

setudef str playOffset

and when pausing:
Code:

channel set $chan playOffset $x

where $x is the last index you just pulled. As for when resuming just grab the number from there.
Code:

set last [channel get $chan playOffset]
# and play from this
set result [lineRead $filename $index [expr $last + 1] ]

I imagine you use some sort of timed messaging to prevent the bot to flood the server or itself, so this should be easy to implement.
_________________
You may say anything about me, but don't misspell my name.
Back to top
View user's profile Send private message
Madalin
Master


Joined: 24 Jun 2005
Posts: 301
Location: Constanta, Romania

PostPosted: Mon Feb 27, 2017 1:48 pm    Post subject: Reply with quote

Thats what i tryed to do. I mean i saved everything in array and started from there Smile but i dont know where im getting it wrong.

If you take a closer look at the code i posted is something similar Smile yet not working as it should.
_________________
https://github.com/MadaliNTCL - To chat with me: https://tawk.to/MadaliNTCL
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger
Madalin
Master


Joined: 24 Jun 2005
Posts: 301
Location: Constanta, Romania

PostPosted: Tue Feb 28, 2017 4:43 am    Post subject: Reply with quote

Its done .. Thanks
_________________
https://github.com/MadaliNTCL - To chat with me: https://tawk.to/MadaliNTCL
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger
caesar
Ass Kicker


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

PostPosted: Mon Mar 06, 2017 4:36 am    Post subject: Reply with quote

Hey, sorry for the late reply.. Been busy with work and stuff and didn't get the chance to have a look on the code to adapt it to fit the requirements.

If it's done then why not share it? Smile
_________________
You may say anything about me, but don't misspell my name.
Back to top
View user's profile Send private message
Madalin
Master


Joined: 24 Jun 2005
Posts: 301
Location: Constanta, Romania

PostPosted: Mon Mar 06, 2017 8:41 am    Post subject: Reply with quote

If someone will want to use it in the future i will make it public. He/She just needs to ask it. Don`t want to post it because maybe im gonna improve it so no need for older version posted here.
_________________
https://github.com/MadaliNTCL - To chat with me: https://tawk.to/MadaliNTCL
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests 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