| View previous topic :: View next topic |
| Author |
Message |
psybertech Voice
Joined: 28 May 2014 Posts: 3
|
Posted: Wed May 28, 2014 6:26 pm Post subject: Help scripting a commands reply to text file |
|
|
Hi there.
I am very new to eggdrop but I have my bot working well.
I am running a web based client on my forums for users to login to the IRC room so they don't need to know anything about IRC.
However, since it is not part of the forums it is not integrated.
I would like to see if there is a way for the eggdrop to perform a /who on a channel (or any command to accomplish this) that will then output the results to a file that I can then use PHP read the file and show people if anyone is in the room so they don't need to pop in just to see if anyone is there.
I tried a .who #channel in the partyline and it doesn't appear to work.
In my head, I would like to have a small script that every 2 minutes checks the channel and outputs who is in there and writes (overwrites) a static file. I think putlog would work if I can overwrite the same log file each time.
Is this possible with an eggdrop or will I need to find another way to do this on my server (a client that I can maybe cron a command piped to a file).
My goal is simply to let people know if anyone is online or not. Seems simple enough.
Any thoughts on this would be great.
cheers and thanks in advance!
 |
|
| Back to top |
|
 |
Madalin Master

Joined: 24 Jun 2005 Posts: 310 Location: Constanta, Romania
|
Posted: Thu May 29, 2014 6:06 am Post subject: |
|
|
It will create a filename who.#channel-name in the main director with all the names from the channel (it will refresh the list every 1 minute)
| Code: | bind time - * create:file
set what(chan) "#tcl"
set what(file) "who.$what(chan)"
proc create:file {min hour day month year} {
global what
set fo [open $what(file) w]
foreach nick [chanlist $what(chan)] { puts $fo $nick }
close $fo
} |
_________________ https://github.com/MadaliNTCL - To chat with me: https://tawk.to/MadaliNTCL |
|
| Back to top |
|
 |
psybertech Voice
Joined: 28 May 2014 Posts: 3
|
Posted: Thu May 29, 2014 9:30 am Post subject: |
|
|
Madalin,
Thank you very much! It worked like a champ! So simple and elegant.
I need to brush up on tcl, that's for sure.
I modified the file path to make it accessible to my webserver and then used fgets and a little logic to parse out how many people and to exclude my bot and spit out a friendly message with the user count and people in the room.
Looks and works fantastic!
Thanks again!
There is no thank or like system here, but if there was, points to you!
cheers!
 |
|
| Back to top |
|
 |
caesar Mint Rubber

Joined: 14 Oct 2001 Posts: 3741 Location: Mint Factory
|
Posted: Thu May 29, 2014 1:03 pm Post subject: |
|
|
| Code: |
bind cron - * chanlist:write
proc chanlist:write {minute hour day month weekday} {
set file "who.#channel"
if {[file readable $file]} {
set fh [open $file w]
puts $fh [lreplace [chanlist #channel] 0 0]
close $fh
}
}
|
Since there's the possibility to have PHP and the bot open the same file at the same time I think it's a good idea to check if the file is readable (meaning it's not used by some other process in the system). Also, you can trim the list of members directly from the TCL proc with lreplace.
PS: Replace #channel to match the actual channel name. _________________ Once the game is over, the king and the pawn go back in the same box. |
|
| Back to top |
|
 |
psybertech Voice
Joined: 28 May 2014 Posts: 3
|
Posted: Thu May 29, 2014 1:45 pm Post subject: |
|
|
Caesar,
Thanks, but I am actually doing that.
Using is_readable... if it is, PHP does its thing, otherwise it spits out a message that the list is currently being updated and to please refresh the page.
It is a tiny room with very little users so I don't expect it to happen often and by the time a user reads the message, the bot's work should be done and all is right with the world.
Good call and thanks!
Oh and additionally I am sorting the list of users (case insensitive) to make the view a little nicer. I don't care about ops or voice, I just wanted a simple csv'd list of users in the room with a little matching on known nicks to make some users stand out like the site admin, mods and me
cheers!
 |
|
| Back to top |
|
 |
|