daily pastebin goal
50%
SHARE
TWEET

pisg tools

Seb Feb 26th, 2012 (edited) 192 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.  
  32. #STOP EDITING HERE
  33. #STOP EDITING HERE
  34.  
  35. bind join - * join_autoaddbotselfjoin
  36. proc pub_pisgadd {n u h c a} {
  37.  if {[string length $a] == 0} {
  38.   set chan $c
  39.  } else {
  40.   set chan [lindex [split $a] 0]
  41.  }
  42.  pp_addchan $chan
  43.  puthelp "privmsg $c :Added $chan"
  44. }
  45.  
  46. proc pub_pisgdel {n u h c a} {
  47.  if {[string length $a] == 0} {
  48.   set chan $c
  49.  } else {
  50.   set chan [lindex [split $a] 0]
  51.  }
  52.  pp_delchan $chan
  53.  puthelp "privmsg $c :Deleted $chan"
  54. }
  55.  
  56. proc pub_pisgreaddall {n u h c a} {
  57.  pp_readdallchans
  58.  puthelp "privmsg $c :Re-added all channels"
  59.  
  60. }
  61.  
  62.  
  63. proc pp_toASCII {char} {
  64.  return [scan $char %c]
  65. }
  66.  
  67. proc pp_toASCIIHEX {string} {
  68.  set hexvalue [list]
  69.  foreach char [split $string ""] {
  70.   lappend hexvalue [format %x [scan $char %c]]
  71.  }
  72.  return $hexvalue
  73. }
  74.  
  75. proc pp_sanitizechanname {chan} {
  76.  # This makes it suitable for filename
  77.  set chan [string tolower [string range $chan 1 end]]
  78.  set newchan [list]
  79.  foreach char [split $chan ""] {
  80.   set ascii [pp_toASCII $char]
  81.   if {$ascii >= 48 && $ascii <= 57} {lappend newchan $char; continue}
  82.   if {$ascii >= 65 && $ascii <= 90} {lappend newchan $char; continue}
  83.   if {$ascii >= 97 && $ascii <= 122} {lappend newchan $char; continue}
  84.   lappend newchan "%[join [pp_toASCIIHEX $char]]"  
  85.  }
  86.  set newchan [join $newchan ""]
  87.  return $newchan
  88. }
  89.  
  90.  
  91. proc pp_addlog {chan} {
  92.  global pp_baselogdir pp_logfilesuffix
  93.  set logname [pp_sanitizechanname $chan]
  94.  logfile "pjk" "$chan" "${pp_baselogdir}/${logname}${pp_logfilesuffix}"
  95. }
  96.  
  97. proc pp_addlogfiles {} {
  98.  foreach chan [channels] {
  99.   pp_addlog $chan
  100.  }
  101. }
  102.  
  103. proc join_autoaddbotselfjoin {n u h chan} {
  104.  if {[isbotnick $n]} {
  105.   pp_addlog $chan
  106.  }
  107. }
  108.  
  109. proc pp_loadconf {} {
  110.  global pp_confname
  111.  set conflines [list]
  112.  set fh [open $pp_confname "r"]
  113.  for {set i 0} {![eof $fh]} {incr i} {
  114.   lappend conflines [gets $fh]
  115.  }
  116.  close $fh
  117.  return $conflines
  118. }
  119.  
  120. proc pp_overwriteconf {conflines} {
  121.  global pp_confname {temp-path}
  122.  set fh [open "${pp_confname}.new" "w"]
  123.  set lmax [llength $conflines]
  124.  for {set i 0} {$i < $lmax} {incr i} {
  125.   puts $fh [lindex $conflines $i]
  126.  }
  127.  close $fh
  128.  file copy -force -- "${pp_confname}.new" $pp_confname
  129.  file delete -- "${pp_confname}.new"
  130.  return
  131. }
  132.  
  133.  
  134. proc pp_appendconf {addnewlines} {
  135.  global pp_confname
  136.  set fh [open $pp_confname "a"]
  137.  set lmax [llength $addnewlines]
  138.  for {set i 0} {$i < $lmax} {incr i} {
  139.   puts $fh [lindex $addnewlines $i]
  140.  }
  141.  close $fh
  142.  return
  143. }
  144.  
  145. proc pp_findchaninconf {conflines} {
  146.  set lmax [llength $conflines]
  147.  set chanlines [list]
  148.  set single [list]
  149.  set begun 0
  150.  for {set i 0} {$i < $lmax} {incr i} {
  151.   set line [string trim [lindex $conflines $i]]
  152.   if {!$begun && [string match "<channel=*>" $line]} {
  153.    set channame [string tolower [join [lrange [split $line "\""] 1 end-1] "\""]]
  154.    if {[string length $channame] == 0} {
  155.     set channame "malform"
  156.    }
  157.    set single [list $channame]
  158.    lappend single $i
  159.    set begun 1
  160.   } elseif {$begun && [string match "</channel>" $line]} {
  161.    lappend single $i
  162.    set begun 0
  163.    lappend chanlines $single
  164.   }
  165.  }
  166.  return $chanlines
  167. }
  168.  
  169.  
  170. proc pp_addchan {chan} {
  171.  global pp_baselogdir pp_logfilesuffix pp_baseoutputdir pp_outputsuffix pp_networkname pp_format
  172.  if {![string equal [string index $chan 0] "#"]} {
  173.   putlog "autoadd err: Chan must begin with # sign"
  174.   return
  175.  }
  176.  pp_addlog $chan
  177.  
  178.  set conflines [pp_loadconf]
  179.  set chanlines [pp_findchaninconf $conflines]
  180.  set lmax [llength $chanlines]
  181.  for {set i 0} {$i < $lmax} {incr i} {
  182.   if {[string equal -nocase $chan [lindex [lindex $chanlines $i] 0]]} {
  183.    # Channel already exists. Ignore command.
  184.    return
  185.   }
  186.  }
  187.  set addnewlines [list]
  188.  #puthelp "privmsg #ChanStats :debug 1"
  189.  lappend addnewlines "<channel=\"${chan}\">"
  190.  #lappend addnewlines "  Logfile=\"${pp_baselogdir}/${chan}${pp_logfilesuffix}\""
  191.  lappend addnewlines "  LogDir=\"${pp_baselogdir}/\""
  192.  lappend addnewlines "  LogPrefix=\"[pp_sanitizechanname ${chan}].\""
  193.  lappend addnewlines "  Format=\"${pp_format}\""
  194.  lappend addnewlines "  Network=\"${pp_networkname}\""
  195.  lappend addnewlines "  OutputFile=\"${pp_baseoutputdir}/[pp_sanitizechanname ${chan}]${pp_outputsuffix}\""
  196.  lappend addnewlines "</channel>"
  197.  #puthelp "privmsg #ChanStats :debug 1.5"
  198.  pp_appendconf $addnewlines
  199.  #puthelp "privmsg #ChanStats :debug 2"
  200. }
  201.  
  202. proc pp_delchan {chan} {
  203.  global pp_logfilesuffix
  204.  set conflines [pp_loadconf]
  205.  set chanlines [pp_findchaninconf $conflines]
  206.  set linestodelete [list]
  207.  set lmax [llength $chanlines]
  208.  
  209.  
  210.  for {set i 0} {$i < $lmax} {incr i} {
  211.   if {[string equal -nocase $chan [lindex [lindex $chanlines $i] 0]]} {
  212.    set linepair [lrange [lindex $chanlines $i] 1 2]
  213.    lappend linestodelete $linepair
  214.   }
  215.  }
  216.  set linestodelete [lsort -integer -index 0 -decreasing $linestodelete]
  217.  set lmax [llength $linestodelete]
  218.  for {set i 0} {$i < $lmax} {incr i} {
  219.   set d [lindex $linestodelete $i]
  220.   set conflines [lreplace $conflines [lindex $d 0] [lindex $d 1]]
  221.  }
  222.  pp_overwriteconf $conflines
  223. }
  224.  
  225. proc pp_readdallchans {} {
  226.  global pp_logfilesuffix
  227.  set conflines [pp_loadconf]
  228.  set chanlines [pp_findchaninconf $conflines]
  229.  set linestodelete [list]
  230.  set lmax [llength $chanlines]
  231.  
  232.  
  233.  for {set i 0} {$i < $lmax} {incr i} {
  234.   set linepair [lrange [lindex $chanlines $i] 1 2]
  235.   lappend linestodelete $linepair
  236.  }
  237.  set linestodelete [lsort -integer -index 0 -decreasing $linestodelete]
  238.  set lmax [llength $linestodelete]
  239.  for {set i 0} {$i < $lmax} {incr i} {
  240.   set d [lindex $linestodelete $i]
  241.   set conflines [lreplace $conflines [lindex $d 0] [lindex $d 1]]
  242.  }
  243.  pp_overwriteconf $conflines
  244.  foreach chan [channels] {
  245.   pp_addchan $chan
  246.  }
  247. }
  248.  
  249. pp_addlogfiles
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top