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.

Write out userlist on a specific channel every x minutes

Old posts that have not been replied to for several years.
Locked
F
Fahr

Write out userlist on a specific channel every x minutes

Post by Fahr »

Hello all,

first of all, I am a complete newbie when it comes to TCL scripting, so please endure my idiocy. I should pick up quickly, though, seeing how I am a programmer by profession.

Second, I searched the forums and found some things remotely connected to what I want, but I wasn't able to pour them into one working solution. If I missed something, I'm sorry to needlessly bother you all.

That being said, here's the actual question;

I am looking for a way to write a list of users in a specific IRC channel to a file, say, every 5 minutes. I should not be a command or trigger, just every 5 minutes it should check all the users in the channel and write their names to a flatfile, one username per line.
I can deal with any overhead data, filter it out in the after processing.
Ideally, the list would not contain the nick of the bot itself. The most utopic situation would be if it were to export the list of nicks to XML format, but I guess that's going to by quite impossibe.

Anyways, any help is appreciated, I can work with a list containing all users (and botnick) + overhead data just as well.

Thanks a lot,
- Fahr
User avatar
stdragon
Owner
Posts: 959
Joined: Sun Sep 23, 2001 8:00 pm
Contact:

Post by stdragon »

Not tested, but probably works...

Code: Select all

# Channel to export to xml
set chanxml(channel) "#sheep"

# Export file name
set chanxml(filename) "sheep.xml"

if {![info exists chanxml(timer)]} {
  set chanxml(timer) [timer 5 chanxml_timer]
}

proc chanxml_timer {args} {
  global chanxml
  set chanxml(timer) [timer 5 chanxml_timer]
  set fp [open $chanxml(filename) w]
  puts $fp "<?xml version=\"1.0\"?>"
  # Add dtd and all that here if you want
  puts $fp "<!-- Generated by stdragon's cool script -->"
  puts $fp "<channel_list>"
  puts $fp "  <channel>"
  puts $fp "    <name>$chanxml(channel)</name>"
  puts $fp "    <topic>[topic $chanxml(channel)]</topic>"
  puts $fp "    <chanmode>[getchanmode $chanxml(channel)]</chanmode"
  foreach nick [chanlist $chanxml(channel)] {
    # Skip bot's nick
    if {[isbotnick $nick]} { continue }

    puts $fp "    <user>"
    puts $fp "      <nick>$nick</nick>"
    puts $fp "      <uhost>[getchanhost $nick]</uhost>"
    puts $fp "      <jointime>[getchanjoin $nick $chanxml(channel)]</jointime>"
    puts $fp "      <idletime>[getchanidle $nick $chanxml(channel)]</idletime>"

    # Get channel mode for user
    set mode ""
    if {[isvoice $nick $chanxml(channel)]} { append mode "v" }
    if {[isop $nick $chanxml(channel)]} { append mode "o" }
    puts $fp "      <mode>$mode</mode>"

    # Done with this user
    puts $fp "    </user>"
  }
  puts $fp "  </channel>"
  puts $fp "</channel_list>"
  close $fp
}
F
Fahr

Post by Fahr »

That's excellent, thanks a lot :)

I'll give it a try and let you know if it works! :)

One more thing; is there any way to get the current time in UNIX timestamp format?

Thanks,
- Fahr
User avatar
CrazyCat
Revered One
Posts: 1280
Joined: Sun Jan 13, 2002 8:00 pm
Location: France
Contact:

Post by CrazyCat »

Code: Select all

set now unixtime
User avatar
strikelight
Owner
Posts: 708
Joined: Mon Oct 07, 2002 10:39 am
Contact:

Post by strikelight »

CrazyCat wrote:

Code: Select all

set now unixtime
Uh... yea... if he wanted the word "unixtime" ....

Should be:

Code: Select all

set now [unixtime]
Or more Tcl-friendly would be to use the clock command:

Code: Select all

set now [clock seconds]
F
Fahr

Post by Fahr »

I figured it out already, using [unixtime] :P

I still decided to run the script every minute and I added some comments and the unixtime. Plus, stdragon forgot a > after </chanmode.

Here is my altered script, maybe someone else can use it as well :)

Code: Select all

proc chanxml_timer {args} {
  global chanxml

  # Reset timer
  set chanxml(timer) [timer 1 chanxml_timer]

  # Write file
  set fp [open $chanxml(filename) w]
  puts $fp "<?xml version=\"1.0\"?>"
  puts $fp "<!-- $chanxml(channel) channel user statistics -->"
  puts $fp "<channel_list time=\"[unixtime]\">"
  puts $fp "  <channel>"
  puts $fp "    <name>$chanxml(channel)</name>"
  puts $fp "    <topic>[topic $chanxml(channel)]</topic>"
  puts $fp "    <chanmode>[getchanmode $chanxml(channel)]</chanmode>"

  # Loop users
  foreach nick [chanlist $chanxml(channel)] {
    # Skip bot's nick
    if {[isbotnick $nick]} { continue }

    puts $fp "    <user>"
    puts $fp "      <nick>$nick</nick>"
    puts $fp "      <uhost>[getchanhost $nick]</uhost>"
    puts $fp "      <jointime>[getchanjoin $nick $chanxml(channel)]</jointime>"
    puts $fp "      <idletime>[getchanidle $nick $chanxml(channel)]</idletime>"

    # Get channel mode for user
    set mode ""
    if {[isvoice $nick $chanxml(channel)]} { append mode "v" }
    if {[isop $nick $chanxml(channel)]} { append mode "o" }

    puts $fp "      <mode>$mode</mode>"

    # Done with this user
    puts $fp "    </user>"
  }

  # Finish file
  puts $fp "  </channel>"
  puts $fp "</channel_list>"
  close $fp
}
Thanks for all the help, especially to stdragon. All that remains now is building a PHP parser for this particular XML file. I'll share it here as soon as it's finished :)

- Fahr[/code]
F
Fahr

Post by Fahr »

For those interested, the PHP source is available here:

http://dump.lycantrope.com/IRCChannelInfo.phps

Feel free to modify it into whatever, but please send me back a copy (to Fahr at -[IDONTLIKESPAM]- lycantrope -[IMEANIT]- dot com).

I'll post the final version of the TCL script here (I made some minor adjustments).

Once more, thanks to everyone! :)

Code: Select all

# Channel to export to xml
set chanxml(channel) "#EQrus"

# Export file name
set chanxml(filename) "../WWW/eqrus.xml"

# Set initial timer
if {![info exists chanxml(timer)]} {
  set chanxml(timer) [timer 1 chanxml_timer]
}

proc chanxml_timer {args} {
  global chanxml

  # Reset timer
  set chanxml(timer) [timer 1 chanxml_timer]

  # Write file
  set fp [open $chanxml(filename) w]
  puts $fp "<?xml version=\"1.0\"?>"
  puts $fp "<!-- $chanxml(channel) channel user statistics -->"
  puts $fp "<channel_list>"
  puts $fp "  <time>[unixtime]</time>"
  puts $fp "  <channel>"
  puts $fp "    <name>$chanxml(channel)</name>"
  puts $fp "    <topic>[topic $chanxml(channel)]</topic>"
  puts $fp "    <chanmode>[getchanmode $chanxml(channel)]</chanmode>"

  # Loop users
  foreach nick [chanlist $chanxml(channel)] {
    # Skip bot's nick
    if {[isbotnick $nick]} { continue }

    puts $fp "    <user>"
    puts $fp "      <nick>$nick</nick>"
    puts $fp "      <uhost>[getchanhost $nick]</uhost>"
    puts $fp "      <jointime>[getchanjoin $nick $chanxml(channel)]</jointime>"
    puts $fp "      <idletime>[getchanidle $nick $chanxml(channel)]</idletime>"

    # Get channel mode for user
    set mode ""
    if {[isvoice $nick $chanxml(channel)]} { append mode "v" }
    if {[isop $nick $chanxml(channel)]} { append mode "o" }

    puts $fp "      <mode>$mode</mode>"

    # Done with this user
    puts $fp "    </user>"
  }

  # Finish file
  puts $fp "  </channel>"
  puts $fp "</channel_list>"
  close $fp
}
- Fahr
User avatar
blood_x
Halfop
Posts: 77
Joined: Tue Nov 20, 2001 8:00 pm
Location: KL, Malaysia
Contact:

Post by blood_x »

Dear fahr,

Can I see online example of this script?
Thank you for your support and commitments.

Sincerely,
fzAy®
http://www.iNTRACyber.com
(We Chat, We Share & We Learn)
F
Fahr

Post by Fahr »

blood_x wrote:Dear fahr,

Can I see online example of this script?
Sure you can.

Here is the direct output: http://www.lycantrope.com/~ircbots/
The xml file therein is the file generated by the TCL script, it changes every minute. This channel is VERY low traffic, so don't expect to see any user there anytime soon.
The IRCChannelInfo.inc.php is the file I linked the source of.
The users.php contains only the following:

Code: Select all

<?

// Error handling
error_reporting(E_ALL);

// Handler
require('IRCChannelInfo.inc.php');

// Get XML
$fXML = file_get_contents('http://www.lycantrope.com/~ircbots/eqrus.xml');

// Create object
$IRC = new IRCChannelInfo($fXML);

var_dump($IRC);

?>
Basically, this will give you a var_dump of the object generated from XML.

To see it working in practise, you'll have the visit the actual site hosting the chat, but it's in Russian.
Anyways, here's the link to the chat login: http://www.imagesofher.com/EQrus/chat.php
There, after the italic text (Пользователи онлайн) it will list the online users (with @ or + if they're opped or voiced), or njet (нет) if there's none.

On the forum (http://www.imagesofher.com/EQrus/forum) it somewhere lists chat (Чат), below it, it lists the usercount.

That's all the practise examples I can give :P

- Fahr
c
cvanmeer
Halfop
Posts: 40
Joined: Tue Dec 02, 2003 1:00 pm
Location: The Netherlands
Contact:

Post by cvanmeer »

this part:

Code: Select all

$fXML = file_get_contents(
gives an error:

Code: Select all

Fatal error: Call to undefined function: file_get_contents() in /var/www/html/xml/users.php on line 10
Just to mention it. Not TCL related at all

gr.

Chrizz
F
Fahr

Post by Fahr »

cvanmeer wrote:this part:

Code: Select all

$fXML = file_get_contents(
gives an error:

Code: Select all

Fatal error: Call to undefined function: file_get_contents() in /var/www/html/xml/users.php on line 10
Just to mention it. Not TCL related at all

gr.

Chrizz
Then you're running on a seriously outdated version of PHP.
See http://www.php.net/file_get_contents - it's implemented since PHP 4.3.0

An alternative (if you do not want to or cannot update) would be;

Code: Select all

<? 

// Error handling 
error_reporting(E_ALL); 

// Handler 
require('IRCChannelInfo.inc.php'); 

// Get XML 
$fXML = fopen('myfile.xml', 'r');
$sXML = fread($fXML, filesize('myfile.xml'));
fclose($fXML);

// Create object 
$IRC = new IRCChannelInfo($sXML); 

var_dump($IRC); 

?>
- Fahr
Locked