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 

Read from .txt file...
Goto page 1, 2  Next
 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Requests
View previous topic :: View next topic  
Author Message
DjBeNNeTT
Voice


Joined: 18 Feb 2006
Posts: 27
Location: Telford, Shropshire, UK

PostPosted: Sat Apr 22, 2006 3:35 pm    Post subject: Read from .txt file... Reply with quote

I've done a search, not got far.. i did find this so i tried to sort it out, but because i cant code TCL alot yet, it obviously it isnt working.

Any ideas? Would help alot Smile

By The way, its to read from a file called sex.txt and to choose a random line on !sex to say into the #chan.

Code:

set sex "./sex.txt"
set sexmsg [string range [randomline $sex] 0 end]

bind pub - !sex randomline

proc randomline {nick uhost hand chan arg} {
 # !sex triggers this procedure.

proc randomline { sex } {

  set position [rand [expr [file size $filename] - 1024]]

  set fd [open $filename r]
  catch {
    seek $fd $position
    set text [read $fd 1024]
  }
  close $fd

  set lines [split $text \n]
  set lineno [randrange 1 [expr [llength $lines] - 1]]

  return [lindex $lines $lineno]
}
}

_________________
DjBeNNeTT

Kewlsounds Radio:
http://kewlsounds.com
irc://irc.quakenet.org/#kewlsounds


Last edited by DjBeNNeTT on Sat Apr 22, 2006 5:44 pm; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
De Kus
Revered One


Joined: 15 Dec 2002
Posts: 1361
Location: Germany

PostPosted: Sat Apr 22, 2006 4:18 pm    Post subject: Reply with quote

- you have pasted the code twice
- you define a proc within a proc
- you define two procs with the same name
- you unncessarily open the file twice (use gets twice, instead of read and second open)
- you define the random message globally... it will stay the same until rehash/restart

thats about all I can say about that code which will never work as itented like it is Very Happy.
_________________
De Kus
StarZ|De_Kus, De_Kus or DeKus on IRC
Copyright © 2005-2009 by De Kus - published under The MIT License
Love hurts, love strengthens...
Back to top
View user's profile Send private message MSN Messenger
DjBeNNeTT
Voice


Joined: 18 Feb 2006
Posts: 27
Location: Telford, Shropshire, UK

PostPosted: Sat Apr 22, 2006 5:45 pm    Post subject: Reply with quote

Well as i said, i know little. So i was wondering of some help.

Sorry for pasting twice, its now just once.

I had guessed that the 2 proc was wrong.. the first one was which causing the error.

Thanks for noticing tho's... Hope someone can point me in the right (coding) direction Wink
_________________
DjBeNNeTT

Kewlsounds Radio:
http://kewlsounds.com
irc://irc.quakenet.org/#kewlsounds
Back to top
View user's profile Send private message Visit poster's website
Alchera
Revered One


Joined: 11 Aug 2003
Posts: 3344
Location: Ballarat Victoria, Australia

PostPosted: Sat Apr 22, 2006 6:05 pm    Post subject: Reply with quote

Code:
set sex "./sex.txt"

bind pub - !sex sex:msg

proc sex:msg {nick uhost hand chan arg} {
  global sex
  set sexmsg [string range [randomline $sex] 0 end]
  puthelp "privmsg $chan :$sexmsg"
}

proc randomline { filename } {

  set position [rand [expr [file size $filename] - 1024]]

  set fd [open $filename r]
  catch {
    seek $fd $position
    set text [read $fd 1024]
  }
  close $fd

  set lines [split $text \n]
  set lineno [randrange 1 [expr [llength $lines] - 1]]

  return [lindex $lines $lineno]
}

proc randrange { lowerbound upperbound } {
 return [expr {int(($upperbound - $lowerbound + 1) * rand() + $lowerbound)}]
}

_________________
Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
Back to top
View user's profile Send private message Visit poster's website
DjBeNNeTT
Voice


Joined: 18 Feb 2006
Posts: 27
Location: Telford, Shropshire, UK

PostPosted: Sat Apr 22, 2006 6:33 pm    Post subject: Reply with quote

Your a god for loads of stuff i want if this works!!!
Just the one prob i find atm...

on !sex...
[23:30:51] [BooByBoT] [22:30] Tcl error [sex:msg]: random limit must be greater than zero

I've changed both "set sexmsg [string range [randomline $sex] 0 end] " and "* rand()" to (3) and still nothing...
I'm turning blind (must be tired) lol
_________________
DjBeNNeTT

Kewlsounds Radio:
http://kewlsounds.com
irc://irc.quakenet.org/#kewlsounds
Back to top
View user's profile Send private message Visit poster's website
Alchera
Revered One


Joined: 11 Aug 2003
Posts: 3344
Location: Ballarat Victoria, Australia

PostPosted: Sat Apr 22, 2006 7:27 pm    Post subject: Reply with quote

change:
Code:
set sex "./sex.txt"

to
Code:
set sex "scripts/sex.txt"

.. making certain the file (sex.txt) actually exists and you have added the lines of text you want (using pico).

I tested on a Windrop and it worked 100%. Smile
_________________
Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
Back to top
View user's profile Send private message Visit poster's website
DjBeNNeTT
Voice


Joined: 18 Feb 2006
Posts: 27
Location: Telford, Shropshire, UK

PostPosted: Sat Apr 22, 2006 7:39 pm    Post subject: Reply with quote

Mines windrop and Still getting same message...

my sex.txt file has:
Quote:
Ohhh babeh!
Hmmmm!
YES YES YEEESSHHHH!!!!
With You? [censored] off!
Send Me Your Pic First Wink
Get Away From Me With That Filthy Anaconda!
All as it looks there..
What you mean "using pico"?
_________________
DjBeNNeTT

Kewlsounds Radio:
http://kewlsounds.com
irc://irc.quakenet.org/#kewlsounds
Back to top
View user's profile Send private message Visit poster's website
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Sat Apr 22, 2006 7:43 pm    Post subject: Reply with quote

Code:
set sex "./sex.txt"

bind pub - !sex sex:msg

proc sex:msg {nick uhost hand chan arg} {
  global sex
  set sexmsg [string range [randomline $sex] 0 end]
  puthelp "privmsg $chan :$sexmsg"
}

proc randomline f {
 set data [split [read [set file [open $f]]][close $file] \n]
 set position [rand [llength $data]]
 lindex $data $position
}


But the best solution would be to read the file into a list and use the list instead of the file everytime the command is called. Try to search the forum about how that can be implemented, it has been implemented 100 times here.
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts


Last edited by Sir_Fz on Sat Apr 22, 2006 7:48 pm; edited 1 time in total
Back to top
View user's profile Send private message Visit poster's website
Alchera
Revered One


Joined: 11 Aug 2003
Posts: 3344
Location: Ballarat Victoria, Australia

PostPosted: Sat Apr 22, 2006 7:48 pm    Post subject: Reply with quote

Excellent Sir_Fz. Smile

I concur. I should have thought of that in the first place. Laughing

DjBeNNeTT wrote:
What you mean "using pico"?

pico is a *nix text editor. I was unaware you were using a Windrop in which case you'd be using notepad/EditPlus to edit scripts.
_________________
Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
Back to top
View user's profile Send private message Visit poster's website
DjBeNNeTT
Voice


Joined: 18 Feb 2006
Posts: 27
Location: Telford, Shropshire, UK

PostPosted: Sat Apr 22, 2006 8:11 pm    Post subject: Reply with quote

Thank you both for your time. Sir_Fz worked perfectly! Thanks Very Happy

And i actually use WordPad for scripts... as Notepad likes to bugger up most the time and not set out the next lines properly making it unreadable... Bugger thing.

Ah well

Thanks both again Very Happy
_________________
DjBeNNeTT

Kewlsounds Radio:
http://kewlsounds.com
irc://irc.quakenet.org/#kewlsounds
Back to top
View user's profile Send private message Visit poster's website
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Sat Apr 22, 2006 8:32 pm    Post subject: Reply with quote

Try Notepad++.
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
DjBeNNeTT
Voice


Joined: 18 Feb 2006
Posts: 27
Location: Telford, Shropshire, UK

PostPosted: Sun Apr 23, 2006 3:21 am    Post subject: Reply with quote

Thanks, i'll give it a try.

Is there a way that if it has $nick in the .txt file it will say the nickname who did the command? Or can that only be done in the code itself to say for each message?.
_________________
DjBeNNeTT

Kewlsounds Radio:
http://kewlsounds.com
irc://irc.quakenet.org/#kewlsounds
Back to top
View user's profile Send private message Visit poster's website
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Sun Apr 23, 2006 4:40 am    Post subject: Reply with quote

use
Code:
[subst -nocommands $sexmsg]

instead of just $sexmsg.
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
DjBeNNeTT
Voice


Joined: 18 Feb 2006
Posts: 27
Location: Telford, Shropshire, UK

PostPosted: Sun Apr 23, 2006 5:29 am    Post subject: Reply with quote

Embarassed where Embarassed

LoL sorry :p
_________________
DjBeNNeTT

Kewlsounds Radio:
http://kewlsounds.com
irc://irc.quakenet.org/#kewlsounds
Back to top
View user's profile Send private message Visit poster's website
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Sun Apr 23, 2006 1:01 pm    Post subject: Reply with quote

How many $sexmsgs are there in that code?
_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
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 -> Script Requests All times are GMT - 4 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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