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 the five newest inputs from a file
Goto page 1, 2  Next
 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    egghelp.org community Forum Index -> Archive
View previous topic :: View next topic  
Author Message
froost
Voice


Joined: 09 Sep 2005
Posts: 4

PostPosted: Fri Sep 09, 2005 4:36 pm    Post subject: Reply with quote

Ty stdragon for the great info Smile

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 Smile
/regards Froost
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Fri Sep 09, 2005 5:49 pm    Post subject: Reply with quote

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

Code:
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
}

_________________
Follow me on GitHub

- Opposing

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


Joined: 09 Sep 2005
Posts: 4

PostPosted: Fri Sep 09, 2005 6:04 pm    Post subject: Reply with quote

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

Code:
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 Sad

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:

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
}
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Fri Sep 09, 2005 8:56 pm    Post subject: Reply with quote

Make sure that the last 5 lines in define.db are not empty.
_________________
Follow me on GitHub

- Opposing

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


Joined: 09 Sep 2005
Posts: 4

PostPosted: Sat Sep 10, 2005 4:07 am    Post subject: Reply with quote

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 Smile
Back to top
View user's profile Send private message
JoshuaUK
Voice


Joined: 07 Aug 2005
Posts: 24

PostPosted: Sun Sep 11, 2005 6:51 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
demond
Revered One


Joined: 12 Jun 2004
Posts: 3073
Location: San Francisco, CA

PostPosted: Sun Sep 11, 2005 9:25 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Visit poster's website
JoshuaUK
Voice


Joined: 07 Aug 2005
Posts: 24

PostPosted: Mon Sep 12, 2005 10:17 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Alchera
Revered One


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

PostPosted: Mon Sep 12, 2005 10:38 am    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Visit poster's website
demond
Revered One


Joined: 12 Jun 2004
Posts: 3073
Location: San Francisco, CA

PostPosted: Mon Sep 12, 2005 1:30 pm    Post subject: Reply with quote

also, a simple forum search for "faq" or "rules" should give you zillions of hits
Back to top
View user's profile Send private message Visit poster's website
JoshuaUK
Voice


Joined: 07 Aug 2005
Posts: 24

PostPosted: Mon Sep 12, 2005 1:40 pm    Post subject: Reply with quote

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 Smile
Back to top
View user's profile Send private message
JoshuaUK
Voice


Joined: 07 Aug 2005
Posts: 24

PostPosted: Mon Sep 12, 2005 1:53 pm    Post subject: Reply with quote

Can't see any that read from txt files Sad or that I can have multiple triggers for.
Back to top
View user's profile Send private message
demond
Revered One


Joined: 12 Jun 2004
Posts: 3073
Location: San Francisco, CA

PostPosted: Mon Sep 12, 2005 3:51 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Visit poster's website
JoshuaUK
Voice


Joined: 07 Aug 2005
Posts: 24

PostPosted: Mon Sep 12, 2005 4:00 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message
demond
Revered One


Joined: 12 Jun 2004
Posts: 3073
Location: San Francisco, CA

PostPosted: Mon Sep 12, 2005 4:39 pm    Post subject: Reply with quote

Code:

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:

!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
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    egghelp.org community Forum Index -> Archive 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