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.

Read the five newest inputs from a file

Old posts that have not been replied to for several years.
f
froost
Voice
Posts: 4
Joined: Fri Sep 09, 2005 4:20 pm

Post by froost »

Ty stdragon for the great info :)

What should i do in my scenario?

I have a file with info in it that is added by users with !commands..

Would it be possible to make a small script that would read the five newest inputs in that file? (The newest are always at the bottom of the file)
For example !new , and it displays it in the channel u want it to.

The file im talking about is with lines and looks like this:

blablabla
hey
hello, hows things

I hope u understand what i mean :)
/regards Froost
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Always post such requests in the proper forum (dont ask in the TCL faq)

Code: Select all

set yourfile "scripts/file.txt"

bind pub - !new show:new

proc show:new {nick uhost hand chan arg} {
 global yourfile
 foreach n [lrange [split [read [set f [open $yourfile]]] \n] end-4 end] {
  puthelp "privmsg $chan :$n"
 }
 close $f
}
f
froost
Voice
Posts: 4
Joined: Fri Sep 09, 2005 4:20 pm

Post by froost »

Sir_Fz wrote:Always post such requests in the proper forum (dont ask in the TCL faq)

Code: Select all

set yourfile "scripts/file.txt"

bind pub - !new show:new

proc show:new {nick uhost hand chan arg} {
 global yourfile
 foreach n [lrange [split [read [set f [open $yourfile]]] \n] end-4 end] {
  puthelp "privmsg $chan :$n"
 }
 close $f
}
Ops, sorry that i posted in the wrong place :(

Sir_Fz , ty for your answer! but it didnt show anything in the channel.
I saved this into a empty .tcl file and loaded it in the eggdrop source/scripts.

Code: Select all

set yourfile "scripts/define.db" 

bind pub - !new show:new 

proc show:new {nick uhost hand chan arg} { 
 global yourfile 
 foreach n [lrange [split [read [set f [open $yourfile]]] \n] end-4 end] { 
  puthelp "privmsg $chan :$n" 
 } 
 close $f 
}
User avatar
Sir_Fz
Revered One
Posts: 3794
Joined: Sun Apr 27, 2003 3:10 pm
Location: Lebanon
Contact:

Post by Sir_Fz »

Make sure that the last 5 lines in define.db are not empty.
f
froost
Voice
Posts: 4
Joined: Fri Sep 09, 2005 4:20 pm

Post by froost »

Sir_Fz wrote:Make sure that the last 5 lines in define.db are not empty.
Yes, it had some spaces in it.

I cant thank you enough for this, thank you :)
J
JoshuaUK
Voice
Posts: 24
Joined: Sun Aug 07, 2005 11:35 am

Post by JoshuaUK »

HI I am trying to find a script which will allow me to add custom triggers and read lines from a text file, so for example !released0509 for example and it would announce so information not announcing it for everyone to see but only the person who requested it as a 'notice' in the channel they are in and it is set to... there may be something like this already just going to continue but this seems the closest I have seen so far.
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

normally, the trigger keywords would be constants and you specify what you want not by introducing a new trigger command but by supplying parameters to your command line which are interpreted by that command's handler proc in a certain way
J
JoshuaUK
Voice
Posts: 24
Joined: Sun Aug 07, 2005 11:35 am

Post by JoshuaUK »

Hmm not sure if there is such a script I found one called mc.readfile1.5.tcl.tcl not sure if it works or what, but not sure if anyone here would know how I could set up a script to say when someone types !rules it takes rules from a text file for example, so the info can be altered easily though a text file on the server.. one which I can have more than one trigger would be great.
User avatar
Alchera
Revered One
Posts: 3344
Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:

Post by Alchera »

JoshuaUK wrote:Hmm not sure if there is such a script I found one called mc.readfile1.5.tcl.tcl not sure if it works or what, ...
Ever thought of reading the instructions at the top of the script? Had thoughts of actually testing it?
Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

also, a simple forum search for "faq" or "rules" should give you zillions of hits
J
JoshuaUK
Voice
Posts: 24
Joined: Sun Aug 07, 2005 11:35 am

Post by JoshuaUK »

Yeah I have looked into it, but I can't seem to get it to work, going to try again with it, but not sure if it will work, and not sure what I should search for! I looked for Trigger scripts, reading from text file etc.. and not really sure what it would come under.. I will try FAQ and rules etc.. and see :)
J
JoshuaUK
Voice
Posts: 24
Joined: Sun Aug 07, 2005 11:35 am

Post by JoshuaUK »

Can't see any that read from txt files :( or that I can have multiple triggers for.
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

what do you need multiple triggers for? If you cannot clearly and unambiguously describe what you need, nobody could help you even if they wanted to
J
JoshuaUK
Voice
Posts: 24
Joined: Sun Aug 07, 2005 11:35 am

Post by JoshuaUK »

Right wel what I would like is to have a !Chart option !Rules and !srealses0509 !areleases0509 etc.. for music releases and I can just alter the trigger when I update and remove them and add new ones, and can modify new additions to the lists for each one everytime like the chart etc.. each week through a text file and just .rehash the bot
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

Code: Select all

set data {}
if {![catch {set f [open file.txt]}]} {
   foreach t [split [read $f] \n] {
      if {[string match !* $t]} {
         set k [string range $t 1 e]
         set data($k) {}
      } {
         lappend data($k) $t
      }
   }
   close $f
}
bind pub - !get foo
proc foo {n u h c t} {
   if {[info exists ::data($t)]} {
      foreach e $::data($t) {puthelp "notice $n :$e"}
   } {
      puthelp "notice $n :no data found for $t"
   }
}
your file.txt looks like this:

Code: Select all

!key1
line1 for key1
line2 for key1
...
lineN for key1
!key2
line1 for key2
line2 for key2
...
lineM for key2
!key3
...
and you retrieve data for keyK by typing !get keyK
Locked