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.

Simple Script Request... I think...

Old posts that have not been replied to for several years.
Locked
K
Kingster

Simple Script Request... I think...

Post by Kingster »

Shouldn't be too much... I looked to see if I could find examples or scripts that will do what I want... But I don't see anything...

I need a script that will create 2 text files...

one will be a comma delimited user list, i.e.:
user1,user2,user3,user4,etc...
the second is similar, only it is in this format:
userstatus (voice, op, etc),username,idletime in min,hostmask

so:
@,user1,5,blah!blah@some.cheesy.net
+v,user2,3,user2!user2@some.cheesy.net
can anyone help me out with this? The first one is the most important to me...

Thanks in advance!
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

So you wish to create a file, with a list of users. Is this of eggdrop overall, or just a channel.

I am guessing just a channel

Code: Select all

proc fileusers {chan file} {
  if {![validchan $chan]} { return -1 }
  set l1 [chanlist $chan]
  set l2 {}
  set l3 {}
  foreach u $l1 {
    if {[isop $u $chan]} {
      lappend l3 "@"
    } elseif {[isvoice $u $chan]} {
      lappend l3 "+v"
    } else {
      lappend l3 ""
    }
    #lappend l3 [lindex [split [getchanhost $nick $chan] @] 0]
    lappend l3 [nick2hand $u $chan]
    lappend l3 [getchanidle $u $chan]
    #lappend l3 [maskhost "${u}[getchanhost $u $chan]"]
    lappend l3 "${u}[getchanhost $u $chan]"
    lappend l2 [join $l3 {,}]
    set l3 {}
  }
  set fp [open "${file}.users" w]
  puts $fp [join l1 {,}]
  catch {close $fp}
  set fp [open "${file}.status" w]
  puts $fp [join $l2 \n]
  catch {close $fp}
}
It was not clear what you wanted for username or hostmask.

As such, it currently uses the username from the "nick!username@host". You can comment out that line, and uncomment the toher, to use the handle they have on the bot.

Also, the hostmask was not clear. Do you want a mask (*!*user@*.host) or the IRC userhost (nick!user@host). It currently uses the userhost.
K
Kingster

Question...

Post by Kingster »

Thanks ppslim - code looks great, and I will test it this evening. Question though...

Code: Select all

  set fp [open "${location}${chan}.users.txt" w] 
  puts $fp [join l1 {,}] 
  catch {close $fp} 
  set fp [open "${location}${chan}.status.txt" w] 
  puts $fp [join $l2 \n] 
  catch {close $fp} 
I tweaked the code a bit... Notice the additon of the var $location. Will it work that way? Also... Why did you use catch? I would assume (maybe incorrectly) that just closing a file wouldn't cause an error... I mean, I am glad to take your word for it - you haven't steered me wrong yet... I'm just curious, and this is how I learn.

Thanks again for the script - I really do appreciate it.
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

yes and no.

the script is used, by calling the procudure fileusers, and passing a file, and channel name.

You can simply pass the location, using the $file var.

IE.

instead of using:
fileusers mychan #channel

Which would create 2 files, named mychan.users and mychan.status, inside the bots directory.

You could use
fileusers /home/ppslim/filestore/mychan #channel

This would create 2 files
/home/ppslim/filestore/mychan.status
/home/ppslim/filestore/mychan.users

As for the catch statment. This is used mainly as a error prevention.

It would not hurt to remove this, as it is more of a standard practice for me.
K
Kingster

Coolness...

Post by Kingster »

I just thought you might like to see the final code that is currently in production...

Code: Select all

# Location to save files
set location "/home/ircadmin/MonkBOT/userlists/"

# Channel to watch
set chan "#unrealplayground"

# How often to update file in minutes
set updatetime 2

# Check to see if the timer is running - only needed really during a .rehash

putlog "users2list.tcl v1.0 has started"

if {![info exists fileusers_running]} {
  timer $updatetime fileusers
  set fileusers_running 1
}

proc fileusers {} {
  global updatetime chan file location
  if {![validchan $chan]} {
    putlog "ERROR - users2file.tcl - I am not on $chan, so I cannot output lists"
    return 1
  }
  set l1 [chanlist $chan]
  set l2 {}
  set l3 {}
  foreach u $l1 {
    if {[isop $u $chan]} {
      lappend l3 "@"
    } elseif {[isvoice $u $chan]} {
      lappend l3 "+v"
    } else {
      lappend l3 ""
    }
    lappend l3 $u
    lappend l3 [getchanidle $u $chan]
    lappend l3 "[getchanhost $u $chan]"
    lappend l2 [join $l3 {,}]
    set l3 {}
  }

  #write the files
  set fp [open "${location}${chan}.users.txt" w]
  puts $fp [join $l1 {,}]
  close $fp
  set fp [open "${location}${chan}.status.txt" w]
  puts $fp [join $l2 \n]
  close $fp

  #restart the timer
  timer $updatetime fileusers
}
Works like a champ... Thanks a ton, ppslim!
Locked