| View previous topic :: View next topic |
| Author |
Message |
Regex Voice
Joined: 19 Mar 2011 Posts: 19
|
Posted: Mon Feb 27, 2012 5:19 pm Post subject: How can we read txt file? |
|
|
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
RoSe Hi everybody, this is my greet.
*** Joins: s7e7v7e7n has joined the room.
<Eggdrop> [s7e7v7e7n]: this is my message
*** 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  |
|
| Back to top |
|
 |
Johannes13 Halfop
Joined: 10 Oct 2010 Posts: 46
|
Posted: Tue Feb 28, 2012 5:40 am Post subject: |
|
|
| 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 |
|
 |
Regex Voice
Joined: 19 Mar 2011 Posts: 19
|
Posted: Tue Feb 28, 2012 1:44 pm Post subject: |
|
|
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 |
|
 |
Johannes13 Halfop
Joined: 10 Oct 2010 Posts: 46
|
Posted: Tue Feb 28, 2012 2:36 pm Post subject: |
|
|
| 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 |
|
 |
Regex Voice
Joined: 19 Mar 2011 Posts: 19
|
Posted: Tue Feb 28, 2012 5:48 pm Post subject: |
|
|
Johannes13 thank you so much!!!
You're the best! Thx for your concerns. My script is workin' with any problems  |
|
| Back to top |
|
 |
|