SHARE
TWEET

pisg tools

Seb Feb 26th, 2012 (edited) 177 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Author: paultwang
  2. # Date: 2010-03-17
  3. # Requested by: xplo@Undernet
  4.  
  5. # This is where pisg.cfg is stored
  6. set pp_confname "/home/jedi/pisg/pisg-0.73/pisg.cfg"
  7.  
  8. # This is where your IRC logs are stored
  9. set pp_baselogdir "/home/jedi/eggdrop/logs"
  10.  
  11. # This is the file extension of your logs
  12. set pp_logfilesuffix ".%Y%m%d"
  13.  
  14. # This is where your output should be
  15. set pp_baseoutputdir "/var/www/html/chanstats"
  16.  
  17. # This is the file extension of your output
  18. set pp_outputsuffix ".html"
  19.  
  20. # Set IRC network name
  21. set pp_networkname "Undernet"
  22.  
  23. # Set log file format
  24. set pp_format "eggdrop"
  25.  
  26. # NOTE: When you add channel, it will make eggdrop start logging that channel
  27.  
  28.  
  29. bind pub m|m !pisgadd pub_pisgadd
  30. bind pub m|m !pisgdel pub_pisgdel
  31. bind pub m|m !pisgreaddall pub_pisgreaddall
  32. bind join - * join_autoaddbotselfjoin
  33. proc pub_pisgadd {n u h c a} {
  34.  if {[string length $a] == 0} {
  35.   set chan $c
  36.  } else {
  37.   set chan [lindex [split $a] 0]
  38.  }
  39.  pp_addchan $chan
  40.  puthelp "privmsg $c :Added $chan"
  41. }
  42.  
  43. proc pub_pisgdel {n u h c a} {
  44.  if {[string length $a] == 0} {
  45.   set chan $c
  46.  } else {
  47.   set chan [lindex [split $a] 0]
  48.  }
  49.  pp_delchan $chan
  50.  puthelp "privmsg $c :Deleted $chan"
  51. }
  52.  
  53. proc pub_pisgreaddall {n u h c a} {
  54.  pp_readdallchans
  55.  puthelp "privmsg $c :Re-added all channels"
  56.  
  57. }
  58.  
  59.  
  60. proc pp_toASCII {char} {
  61.  return [scan $char %c]
  62. }
  63.  
  64. proc pp_toASCIIHEX {string} {
  65.  set hexvalue [list]
  66.  foreach char [split $string ""] {
  67.   lappend hexvalue [format %x [scan $char %c]]
  68.  }
  69.  return $hexvalue
  70. }
  71.  
  72. proc pp_sanitizechanname {chan} {
  73.  # This makes it suitable for filename
  74.  set chan [string tolower [string range $chan 1 end]]
  75.  set newchan [list]
  76.  foreach char [split $chan ""] {
  77.   set ascii [pp_toASCII $char]
  78.   if {$ascii >= 48 && $ascii <= 57} {lappend newchan $char; continue}
  79.   if {$ascii >= 65 && $ascii <= 90} {lappend newchan $char; continue}
  80.   if {$ascii >= 97 && $ascii <= 122} {lappend newchan $char; continue}
  81.   lappend newchan "%[join [pp_toASCIIHEX $char]]"  
  82.  }
  83.  set newchan [join $newchan ""]
  84.  return $newchan
  85. }
  86.  
  87.  
  88. proc pp_addlog {chan} {
  89.  global pp_baselogdir pp_logfilesuffix
  90.  set logname [pp_sanitizechanname $chan]
  91.  logfile "pjk" "$chan" "${pp_baselogdir}/${logname}${pp_logfilesuffix}"
  92. }
  93.  
  94. proc pp_addlogfiles {} {
  95.  foreach chan [channels] {
  96.   pp_addlog $chan
  97.  }
  98. }
  99.  
  100. proc join_autoaddbotselfjoin {n u h chan} {
  101.  if {[isbotnick $n]} {
  102.   pp_addlog $chan
  103.  }
  104. }
  105.  
  106. proc pp_loadconf {} {
  107.  global pp_confname
  108.  set conflines [list]
  109.  set fh [open $pp_confname "r"]
  110.  for {set i 0} {![eof $fh]} {incr i} {
  111.   lappend conflines [gets $fh]
  112.  }
  113.  close $fh
  114.  return $conflines
  115. }
  116.  
  117. proc pp_overwriteconf {conflines} {
  118.  global pp_confname {temp-path}
  119.  set fh [open "${pp_confname}.new" "w"]
  120.  set lmax [llength $conflines]
  121.  for {set i 0} {$i < $lmax} {incr i} {
  122.   puts $fh [lindex $conflines $i]
  123.  }
  124.  close $fh
  125.  file copy -force -- "${pp_confname}.new" $pp_confname
  126.  file delete -- "${pp_confname}.new"
  127.  return
  128. }
  129.  
  130.  
  131. proc pp_appendconf {addnewlines} {
  132.  global pp_confname
  133.  set fh [open $pp_confname "a"]
  134.  set lmax [llength $addnewlines]
  135.  for {set i 0} {$i < $lmax} {incr i} {
  136.   puts $fh [lindex $addnewlines $i]
  137.  }
  138.  close $fh
  139.  return
  140. }
  141.  
  142. proc pp_findchaninconf {conflines} {
  143.  set lmax [llength $conflines]
  144.  set chanlines [list]
  145.  set single [list]
  146.  set begun 0
  147.  for {set i 0} {$i < $lmax} {incr i} {
  148.   set line [string trim [lindex $conflines $i]]
  149.   if {!$begun && [string match "<channel=*>" $line]} {
  150.    set channame [string tolower [join [lrange [split $line "\""] 1 end-1] "\""]]
  151.    if {[string length $channame] == 0} {
  152.     set channame "malform"
  153.    }
  154.    set single [list $channame]
  155.    lappend single $i
  156.    set begun 1
  157.   } elseif {$begun && [string match "</channel>" $line]} {
  158.    lappend single $i
  159.    set begun 0
  160.    lappend chanlines $single
  161.   }
  162.  }
  163.  return $chanlines
  164. }
  165.  
  166.  
  167. proc pp_addchan {chan} {
  168.  global pp_baselogdir pp_logfilesuffix pp_baseoutputdir pp_outputsuffix pp_networkname pp_format
  169.  if {![string equal [string index $chan 0] "#"]} {
  170.   putlog "autoadd err: Chan must begin with # sign"
  171.   return
  172.  }
  173.  pp_addlog $chan
  174.  
  175.  set conflines [pp_loadconf]
  176.  set chanlines [pp_findchaninconf $conflines]
  177.  set lmax [llength $chanlines]
  178.  for {set i 0} {$i < $lmax} {incr i} {
  179.   if {[string equal -nocase $chan [lindex [lindex $chanlines $i] 0]]} {
  180.    # Channel already exists. Ignore command.
  181.    return
  182.   }
  183.  }
  184.  set addnewlines [list]
  185.  #puthelp "privmsg #ChanStats :debug 1"
  186.  lappend addnewlines "<channel=\"${chan}\">"
  187.  #lappend addnewlines "  Logfile=\"${pp_baselogdir}/${chan}${pp_logfilesuffix}\""
  188.  lappend addnewlines "  LogDir=\"${pp_baselogdir}/\""
  189.  lappend addnewlines "  LogPrefix=\"[pp_sanitizechanname ${chan}].\""
  190.  lappend addnewlines "  Format=\"${pp_format}\""
  191.  lappend addnewlines "  Network=\"${pp_networkname}\""
  192.  lappend addnewlines "  OutputFile=\"${pp_baseoutputdir}/[pp_sanitizechanname ${chan}]${pp_outputsuffix}\""
  193.  lappend addnewlines "</channel>"
  194.  #puthelp "privmsg #ChanStats :debug 1.5"
  195.  pp_appendconf $addnewlines
  196.  #puthelp "privmsg #ChanStats :debug 2"
  197. }
  198.  
  199. proc pp_delchan {chan} {
  200.  global pp_logfilesuffix
  201.  set conflines [pp_loadconf]
  202.  set chanlines [pp_findchaninconf $conflines]
  203.  set linestodelete [list]
  204.  set lmax [llength $chanlines]
  205.  
  206.  
  207.  for {set i 0} {$i < $lmax} {incr i} {
  208.   if {[string equal -nocase $chan [lindex [lindex $chanlines $i] 0]]} {
  209.    set linepair [lrange [lindex $chanlines $i] 1 2]
  210.    lappend linestodelete $linepair
  211.   }
  212.  }
  213.  set linestodelete [lsort -integer -index 0 -decreasing $linestodelete]
  214.  set lmax [llength $linestodelete]
  215.  for {set i 0} {$i < $lmax} {incr i} {
  216.   set d [lindex $linestodelete $i]
  217.   set conflines [lreplace $conflines [lindex $d 0] [lindex $d 1]]
  218.  }
  219.  pp_overwriteconf $conflines
  220. }
  221.  
  222. proc pp_readdallchans {} {
  223.  global pp_logfilesuffix
  224.  set conflines [pp_loadconf]
  225.  set chanlines [pp_findchaninconf $conflines]
  226.  set linestodelete [list]
  227.  set lmax [llength $chanlines]
  228.  
  229.  
  230.  for {set i 0} {$i < $lmax} {incr i} {
  231.   set linepair [lrange [lindex $chanlines $i] 1 2]
  232.   lappend linestodelete $linepair
  233.  }
  234.  set linestodelete [lsort -integer -index 0 -decreasing $linestodelete]
  235.  set lmax [llength $linestodelete]
  236.  for {set i 0} {$i < $lmax} {incr i} {
  237.   set d [lindex $linestodelete $i]
  238.   set conflines [lreplace $conflines [lindex $d 0] [lindex $d 1]]
  239.  }
  240.  pp_overwriteconf $conflines
  241.  foreach chan [channels] {
  242.   pp_addchan $chan
  243.  }
  244. }
  245.  
  246. pp_addlogfiles
RAW Paste Data
Top