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.

Help scripting a commands reply to text file

Help for those learning Tcl or writing their own scripts.
Post Reply
p
psybertech
Voice
Posts: 3
Joined: Wed May 28, 2014 6:15 pm

Help scripting a commands reply to text file

Post by psybertech »

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!
:D
User avatar
Madalin
Master
Posts: 310
Joined: Fri Jun 24, 2005 11:36 am
Location: Constanta, Romania
Contact:

Post by Madalin »

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: Select all

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
}
p
psybertech
Voice
Posts: 3
Joined: Wed May 28, 2014 6:15 pm

Post by psybertech »

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!
:D
User avatar
caesar
Mint Rubber
Posts: 3778
Joined: Sun Oct 14, 2001 8:00 pm
Location: Mint Factory

Post by caesar »

Code: Select all

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.
p
psybertech
Voice
Posts: 3
Joined: Wed May 28, 2014 6:15 pm

Post by psybertech »

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. :lol:

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!
:D
Post Reply