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.

Problems with my small script

Old posts that have not been replied to for several years.
Locked
B
Bomi

Problems with my small script

Post by Bomi »

Hi all,

I am very new in programming with Tcl and Eggdrop. I wanted to write a script, that writes the current number of users of a channel in a textfile.
Everytime a user joins the channel, the script opens the file "users.txt" and adds 1 to the existing number. And when a user leaves the channel, it substracts 1. But the script doesn't work, there's only a linefeed in the textfile. Where's my fault?

Here's my script:

Code: Select all

set channel "#channel"

bind join - * nc_join 
bind part - * nc_leave 
bind sign - * nc_leave 

if {![file exists users.txt]} {
 set none [open "users.txt" "w"]
 puts $none "0"
 close $none
}


proc nc_join { nick host hand chan } {
  if {$chan == $channel} {
	set in [open "users.txt" "r"]

	gets $in in_val
	close $in
	incr $in_val +1
	set out [open "users.txt" "w"]
	puts $out $in_val
	close $out
  }
}

proc nc_leave { nick host hand chan } {
  if {$chan == $channel} {
	set in2 [open "users.txt" "r"]
	gets $in2 in_val2
	close $in2
	incr $in_val2 -1
	set out2 [open "users.txt" "w"]
	puts $out2 $in_val2
	close $out2
  }
}
User avatar
awyeah
Revered One
Posts: 1580
Joined: Mon Apr 26, 2004 2:37 am
Location: Switzerland
Contact:

Post by awyeah »

Here try these scripts.
The main thing is to get the total channel users on the binds
of join, part, quit or when a netsplit occurs maybe.

Here are some scripts pre ready which do almost the same
thing, you can have an idea by maybe seeing their codes.

http://www.egghelp.org/tclhtml/3478-4-0 ... l-peak.htm

The first script I think will do the job for you in this result.
All scripts normally store channel peak users such as I have
a channel kick counter for my bot in .txt files myself.
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
B
Bomi

Post by Bomi »

hmm, I think my problem is writing something into a file,

Code: Select all

puts $none "0"
because the script doesn't write the 0 into the file although this has nothing to do with the binds. Is there an other possibility to put a number into a file?
B
Bomi

Post by Bomi »

I shrinked the script a little bit, but there's still the problem with the filecreation in line7, I always get a file with just a cryptic sign in it. If I replace line 15-17 with the comment-line, the script works fine but of course then it doesn't export the number into the file :-(

Code: Select all

bind join -|- * nc_join
bind part -|- * nc_join
bind sign -|- * nc_join

if {![file exists users.txt]} {
 set none [open "users.txt" "w"]
 puts $none ""
 close $none
}


proc nc_join { nick host hand chan } {
	set visitors [llength [chanlist $chan]]
#	puthelp "PRIVMSG $chan : $visitors"
	set saveme [open "users.txt" "a"]
	puts $saveme $visitors
 	close $saveme
}
User avatar
Alchera
Revered One
Posts: 3344
Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:

Post by Alchera »

This be of some help?

Code: Select all

# Create the storage file for users.
if {![file exists "users.txt"]} {
 set none [open "users.txt" w]
 close $none
 unset none
 if {![file exists "users.txt"]} {
  putlog "*** (notes) ERROR: Unable to write to \"users.txt\" ***"
  return 0
 }
}
:)
Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
B
Bomi

Post by Bomi »

yeah, thx, the filecreation is working now. But there's still the problem with the cryptic sign that is exported into the file instead of the visitor-number. :cry:

Code: Select all

proc nc_join { nick host hand chan } {
	set visitors [llength [chanlist $chan]]
#	puthelp "PRIVMSG $chan : $visitors"
	set saveme [open "users.txt" w] 
	puts $saveme $visitors << Mistake must be here, I think.
 	close $saveme
}
The Logfile doesn't report any error, so where's my mistake?
B
Bomi

Fix

Post by Bomi »

I solved the problem on my own:

I had to use this:

Code: Select all

puts -nonewline $saveme $visitors
instead of

Code: Select all

puts $saveme $visitors
Locked