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 

How can we read txt file?

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


Joined: 19 Mar 2011
Posts: 19

PostPosted: Mon Feb 27, 2012 5:19 pm    Post subject: How can we read txt file? Reply with quote

Hi dear coders, how can we read txt file when user join the channel (if she/he has a message in txt file)?

I know, add/del a text to file. But i dont know check it. Smile


Like that;

*** Joins: s7e7v7e7n has joined the room.

After user has joined the room, my eggdrop'll open the file. if his/her nick in the text file, my bot'll send a message his/her greet to channel. In file.tx

file.txt (example)

(nick - greet)
s7e7v7e7n7 this is my message Razz
RoSe Hi everybody, this is my greet.

*** Joins: s7e7v7e7n has joined the room.
<Eggdrop> [s7e7v7e7n]: this is my message Razz
*** Joins: RoSe has joined the room.
<Eggdrop> [RoSe] Hi everybody, this is my greet.

If user has no message in the file, bot'll not send a message.

Thx for your concerns Smile
Back to top
View user's profile Send private message
Johannes13
Halfop


Joined: 10 Oct 2010
Posts: 46

PostPosted: Tue Feb 28, 2012 5:40 am    Post subject: Reply with quote

Code:
namespace eval ::welcome {
   set welcomefile "/foo/bar/baz.txt"

   bind join - * onjoin
   proc onjoin {n u h c} {
      variable welcomefile
      set fd [open $welcomefile r]
      set data [read $fd]
      close $fd
      set arraydata {}
      foreach line [split $data \r\n] {
         lappend arraydata [lindex [split $line] 0] [join [lrange [split $line] 1 end]]
      }
      array set welcomes $arraydata
      if {[info exists welcomes($n)]} {
         putnotc $n $welcomes($n)
      }
   }
}
Back to top
View user's profile Send private message
Regex
Voice


Joined: 19 Mar 2011
Posts: 19

PostPosted: Tue Feb 28, 2012 1:44 pm    Post subject: Reply with quote

Johannes13 thank you but, isn't workin'

Giving this message on the putty.

[19:43:02] Tcl error [onjoin]: invalid command name "onjoin"
Back to top
View user's profile Send private message
Johannes13
Halfop


Joined: 10 Oct 2010
Posts: 46

PostPosted: Tue Feb 28, 2012 2:36 pm    Post subject: Reply with quote

Code:
namespace eval ::welcome {
   set welcomefile "/foo/bar/baz.txt"

   bind join - * [namespace current]::onjoin
   proc onjoin {n u h c} {
      variable welcomefile
      set fd [open $welcomefile r]
      set data [read $fd]
      close $fd
      set arraydata {}
      foreach line [split $data \r\n] {
         lappend arraydata [lindex [split $line] 0] [join [lrange [split $line] 1 end]]
      }
      array set welcomes $arraydata
      if {[info exists welcomes($n)]} {
         putnotc $n $welcomes($n)
      }
   }
}


Forgot the namespace current
Back to top
View user's profile Send private message
Regex
Voice


Joined: 19 Mar 2011
Posts: 19

PostPosted: Tue Feb 28, 2012 5:48 pm    Post subject: Reply with quote

Johannes13 thank you so much!!!

You're the best! Thx for your concerns. My script is workin' with any problems Smile
Back to top
View user's profile Send private message
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