daily pastebin goal
13%
SHARE
TWEET

pisg tools

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