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 

Help scripting a commands reply to text file

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
psybertech
Voice


Joined: 28 May 2014
Posts: 3

PostPosted: Wed May 28, 2014 6:26 pm    Post subject: Help scripting a commands reply to text file Reply with quote

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

Any thoughts on this would be great.

cheers and thanks in advance!
Very Happy
Back to top
View user's profile Send private message
Madalin
Master


Joined: 24 Jun 2005
Posts: 310
Location: Constanta, Romania

PostPosted: Thu May 29, 2014 6:06 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger
psybertech
Voice


Joined: 28 May 2014
Posts: 3

PostPosted: Thu May 29, 2014 9:30 am    Post subject: Reply with quote

Madalin,

Thank you very much! It worked like a champ! So simple and elegant. Smile
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!
Very Happy
Back to top
View user's profile Send private message
caesar
Mint Rubber


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

PostPosted: Thu May 29, 2014 1:03 pm    Post subject: Reply with quote

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
View user's profile Send private message
psybertech
Voice


Joined: 28 May 2014
Posts: 3

PostPosted: Thu May 29, 2014 1:45 pm    Post subject: Reply with quote

Caesar,

Thanks, but I am actually doing that. Smile

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

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 Wink

cheers!
Very Happy
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help 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