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 

I just want to understand these 5 lines

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


Joined: 25 Jun 2016
Posts: 19

PostPosted: Wed Mar 03, 2021 4:20 am    Post subject: I just want to understand these 5 lines Reply with quote

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 Very Happy

Code:
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
}

_________________
IRCwebNET
Back to top
View user's profile Send private message Visit poster's website AIM Address
Suratka
Voice


Joined: 25 Jun 2016
Posts: 19

PostPosted: Wed Mar 03, 2021 5:04 am    Post subject: Semplifying Reply with quote

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.
_________________
IRCwebNET
Back to top
View user's profile Send private message Visit poster's website AIM Address
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1032
Location: France

PostPosted: Wed Mar 03, 2021 6:19 am    Post subject: Reply with quote

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]]
_________________
https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community.
Back to top
View user's profile Send private message Visit poster's website
Suratka
Voice


Joined: 25 Jun 2016
Posts: 19

PostPosted: Wed Mar 03, 2021 6:37 am    Post subject: Reply with quote

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
_________________
IRCwebNET
Back to top
View user's profile Send private message Visit poster's website AIM Address
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1032
Location: France

PostPosted: Wed Mar 03, 2021 8:13 am    Post subject: Reply with quote

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:
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.
_________________
https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community.
Back to top
View user's profile Send private message Visit poster's website
Suratka
Voice


Joined: 25 Jun 2016
Posts: 19

PostPosted: Wed Mar 03, 2021 8:42 am    Post subject: Replay Reply with quote

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
_________________
IRCwebNET
Back to top
View user's profile Send private message Visit poster's website AIM Address
Suratka
Voice


Joined: 25 Jun 2016
Posts: 19

PostPosted: Wed Mar 03, 2021 8:48 am    Post subject: index.html Reply with quote

http://www.jpgdb.com
_________________
IRCwebNET
Back to top
View user's profile Send private message Visit poster's website AIM Address
caesar
Mint Rubber


Joined: 14 Oct 2001
Posts: 3741
Location: Mint Factory

PostPosted: Wed Mar 03, 2021 9:03 am    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Suratka
Voice


Joined: 25 Jun 2016
Posts: 19

PostPosted: Wed Mar 03, 2021 9:08 am    Post subject: caesar :D Reply with quote

caesar, for me it is already arbao tcl, eggdrop etc .. the json is even ancient aramaic.
Laughing Laughing Laughing Laughing
_________________
IRCwebNET
Back to top
View user's profile Send private message Visit poster's website AIM Address
willyw
Revered One


Joined: 15 Jan 2009
Posts: 1175

PostPosted: Wed Mar 03, 2021 9:43 am    Post subject: Re: I just want to understand these 5 lines Reply with quote

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. Smile

In other words, everybody starts knowing nothing.

The trick is: getting started. Wink

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. Smile

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. Very Happy Very Happy

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 !

Smile
_________________
For a fun (and popular) Trivia game, visit us at: irc.librairc.net #science-fiction . Over 300K Q & A to play in BogusTrivia !
Back to top
View user's profile Send private message
CrazyCat
Revered One


Joined: 13 Jan 2002
Posts: 1032
Location: France

PostPosted: Wed Mar 03, 2021 9:45 am    Post subject: Reply with quote

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:
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.
_________________
https://www.eggdrop.fr - French IRC network
Offer me a coffee - Do not ask me help in PM, we are a community.
Back to top
View user's profile Send private message Visit poster's website
Suratka
Voice


Joined: 25 Jun 2016
Posts: 19

PostPosted: Wed Mar 03, 2021 11:55 am    Post subject: Finished. and working. Reply with quote

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 Very Happy
_________________
IRCwebNET
Back to top
View user's profile Send private message Visit poster's website AIM Address
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