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.

I just want to understand these 5 lines

Requests for complete scripts or modifications/fixes for scripts you didn't write. Response not guaranteed, and no thread bumping!
Post Reply
S
Suratka
Voice
Posts: 19
Joined: Sat Jun 25, 2016 4:56 pm
Contact:

I just want to understand these 5 lines

Post by Suratka »

I hope it is the right section.

I found a little code for tcl which I find very interesting. I state that I am a perfect ignorant on the subject of tcl, eggdrop, etc ..

I don't pretend to learn everything immediately, also because after the age of 30 you lose your mental elasticity: D
Since I've seen this little code and tried it, and it works, I'd like to understand how it works? I would like to understand that short code. I just want someone to explain to me in simple words what that tiny code does, what does it order to do at eggdrop? And after that, I would like to ask:

How was it possible to tell the eggdrop to create that html file that would report the number of users in the channels, it is also possible to publish logs in html? or txt files? chosen by me?
I realize that if this were the case, there would be no complex modules to do these jobs and everything would be solved with 5 lines of code, but I'm just curious to understand why?
As reported in html the number of users with those 5 lines, why can't I write in those 5 lines that file x has to publish, in folder x ???
which can be log, stats etc ...

I repeat, just to understand.
The last thing;

it is possible to enhance these 5 lines of code to make him do something more interesting, such as: publish not only the number but also the nicknames ??? or any other upgrade?
I find this little tcl very interesting indeed. I find it a great starting point for learning tcl logic. Thank you all.

This is the little TCL :D

Code: Select all

bind time - "* * * * *" web_users

# Path to save html page.
set webusers_file "/var/www/html/index.html"

proc web_users {min hour day month year} {
global webusers_file
    if {[file exists "$webusers_file"]} {
        set fh [open "$webusers_file" "a+"]
    }
    set fh [open "$webusers_file" "w+"]
    puts $fh "<HTML><HEAD><TITLE>Total users</TITLE></HEAD>"
    puts $fh "<BODY>"
    foreach chan [channels] {
        set users [chanlist $chan]
        puts $fh "$chan: [llength $users] users<BR />"
    }

puts $fh "</BODY></HTML>"
close $fh
}
S
Suratka
Voice
Posts: 19
Joined: Sat Jun 25, 2016 4:56 pm
Contact:

Semplifying

Post by Suratka »

simplifying, can I set in the tcl to take a log file from the log folder and post it?

or, can I tell the tcl to also put the list of connected nicknames?

or: can I tell the tcl to put the channels in ascending order automatically? since so it puts them according to the order in which the eggdrop entered the channels.
or any other modification to enhance this little code and make it really functional.
User avatar
CrazyCat
Revered One
Posts: 1234
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

The script is quite simple:
Each minute, it lists the channels in its channel list (even if they are inactive), and foreach, it counts the number of users.
And it writes everything in index.html file.

Taking a logfile is the most difficult thing to do, because you have to find it and it depends on multiple factors:
- is loging enable for the chan ?
- is there a rotation of log ?
- if yes, which is the format of filename ? and wich file do you want to read ?

For the other questions:
list of connected users: can be donne with [join $users ", "] to have a comma separated list
sort channels: can be done with [lsort [channels]]
S
Suratka
Voice
Posts: 19
Joined: Sat Jun 25, 2016 4:56 pm
Contact:

Post by Suratka »

then....

For example the log files in question are located in eggdrop / logs / and I have no idea what format they are. they are created by the system and are named by channel name and date. # siamosolonoi.log._2Mar2021

Can I tell the tcl to fetch the latest log file by date and post it in that html?

another thing:

Excuse me Crazycat, and I thank you for your availability and patience, but I am ignorant and those strings of code you have given me I really don't know where to insert them. since the tcl is small could you insert them yourself and post it complete and maybe make me understand the meaning? Grz
User avatar
CrazyCat
Revered One
Posts: 1234
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

For the logfiles, I clearly advise against trying to display them on the html page:
- getting the last file could be heavy, depending of the number of files you have,
- displaying their content could generate an enormous page,
- what about the privacy of users ?

For the two other points:

Code: Select all

bind time - "* * * * *" web_users

# Path to save html page.
set webusers_file "/var/www/html/index.html"

proc web_users {min hour day month year} {
    global webusers_file
    set fh [open "$webusers_file" "w+"]
    puts $fh "<HTML><HEAD><TITLE>Total users</TITLE></HEAD>"
    puts $fh "<BODY>"
    foreach chan [lsort [channels]] {
        set users [chanlist $chan]
        puts $fh "$chan: [llength $users] users : [join $users {, }]<BR />"
    }
    puts $fh "</BODY></HTML>"
    close $fh
}
I remove the short verification about the existence of the file because opening it in w+ mode will create it if needed and erase it contents before writing.
S
Suratka
Voice
Posts: 19
Joined: Sat Jun 25, 2016 4:56 pm
Contact:

Replay

Post by Suratka »

Answering your privacy question:
This is a server between friends.

As for the change to the tcl ...

Now the nicknames come out.
The problem is that there is no space between the end of one channel and the beginning of another and everything becomes confusing and difficult to read.
and I also noticed that the order of the channels is not from largest to smallest, but is random.
If you could list the channels in an increasing way, that is, from the most populated to the least populated, and insert at least one or two spaces between the end of one channel and the beginning of another I would say that it would be perfect. Then I play with the html and I will try to make it more presentable aesthetically. : D
S
Suratka
Voice
Posts: 19
Joined: Sat Jun 25, 2016 4:56 pm
Contact:

index.html

Post by Suratka »

User avatar
caesar
Mint Rubber
Posts: 3776
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Should make that in JSON format for easier parsing.
Once the game is over, the king and the pawn go back in the same box.
S
Suratka
Voice
Posts: 19
Joined: Sat Jun 25, 2016 4:56 pm
Contact:

caesar :D

Post by Suratka »

caesar, for me it is already arbao tcl, eggdrop etc .. the json is even ancient aramaic.
:lol: :lol: :lol: :lol:
w
willyw
Revered One
Posts: 1197
Joined: Thu Jan 15, 2009 12:55 am

Re: I just want to understand these 5 lines

Post by willyw »

Suratka wrote:I hope it is the right section.

I found a little code for tcl which I find very interesting. I state that I am a perfect ignorant on the subject of tcl, eggdrop, etc ..
...
Great... now you know where you are starting from. :)

In other words, everybody starts knowing nothing.

The trick is: getting started. ;)

I used some sites. Still use them for reference! I just keep them open in tabs, when playing with tcl for Eggdrop.

Oh... that's another thing ... play. A lot. Write silly little scripts and test them in some channel away from everybody else, so you won't bother them, and they won't bother (laugh at) you. :)

Heck... if you can... make another bot, just for testing and learning. This way, if you crash the bot, it won't matter. You'll crash it .... don't ask me how I know. heheheeh I mean... *I* have never crashed a bot due to a typo or something. Nope. Never. Not even once. :D :D

Here's some links for you to bookmark:

http://suninet.the-demon.de/
This is old. But still very good. It is designed to start with somebody that knows nothing of TCL. If you start at the beginning and go through it - just do what you can at one sitting and then come back and start from there - it will help you. A LOT.

Next, know that TCL is a stand alone scripting language. It doesn't "belong" to Eggdrop.... Eggdrop just borrows it.
This causes there to be two parts to TCL. The original TCL, and then the commands that the Eggdrop people created.

https://docs.eggheads.org/mainDocs/tcl-commands.html
That's the eggdrop specific commands.

http://www.tcl.tk/man/tcl8.6/TclCmd/contents.htm
That's the rest of TCL.

As with anything, it takes a little getting used to, to be able to grasp their style and understand it. No big deal. Just stick with it, and it'll come.

You can look up every command from your little logging/posting script, on those pages.
But doing so, is a bit like jumping into the middle. If you do, I hope it doesn't frustrate you. That's where starting small, like the Suninet course takes you, and then working up, comes in. Again, write lots of silly little scripts. Practice. Especially when learning a command that is new to you.

Mostly though - have fun !

:)
For a fun (and popular) Trivia game, visit us at: irc.librairc.net #science-fiction . Over 300K Q & A to play in BogusTrivia !
User avatar
CrazyCat
Revered One
Posts: 1234
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

The sort of channel list is not random, it's alphabetical. Sorting by number of users is possible but more complex, need to create a list containing channel and users and then sort it using the good index.

Short example (not totaly working):

Code: Select all

bind dcc - co sortchan

proc sortchan {handle idx text} {
	foreach chan [channels] {
		lappend c [lindex $chan 0] [llength [chanlist $chan]]
	}
	putlog $c
	lsort -integer -index 1 $c
	foreach {ch us} $c {
		putlog "$ch as $us user"
	}
}
If you want to separate channels, add another <br /> or a <hr /> tag, that's html, not tcl.
S
Suratka
Voice
Posts: 19
Joined: Sat Jun 25, 2016 4:56 pm
Contact:

Finished. and working.

Post by Suratka »

It is nothing special, but I am satisfied. Thanks again for the help given.
if you want to see the final result I passed the link in the previous answer. THANKS: D

Crazycat buon caffe :D
Post Reply