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.

How can we read txt file?

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
R
Regex
Voice
Posts: 19
Joined: Sat Mar 19, 2011 1:23 pm

How can we read txt file?

Post by Regex »

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. :)


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 :P
RoSe Hi everybody, this is my greet.

*** Joins: s7e7v7e7n has joined the room.
<Eggdrop> [s7e7v7e7n]: this is my message :P
*** 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 :)
J
Johannes13
Halfop
Posts: 46
Joined: Sun Oct 10, 2010 11:38 am

Post by Johannes13 »

Code: Select all

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)
		}
	}
}
R
Regex
Voice
Posts: 19
Joined: Sat Mar 19, 2011 1:23 pm

Post by Regex »

Johannes13 thank you but, isn't workin'

Giving this message on the putty.

[19:43:02] Tcl error [onjoin]: invalid command name "onjoin"
J
Johannes13
Halfop
Posts: 46
Joined: Sun Oct 10, 2010 11:38 am

Post by Johannes13 »

Code: Select all

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
R
Regex
Voice
Posts: 19
Joined: Sat Mar 19, 2011 1:23 pm

Post by Regex »

Johannes13 thank you so much!!!

You're the best! Thx for your concerns. My script is workin' with any problems :)
Post Reply