Coders-IRC


IRC for Coders

Archive December 2021


Channel Top10


image
/*
Commands:
!stats [nick] => Overall stats for $nick|$2 in $network@#Channel
!top10 => Overall top 10 chatters in $network@channel
!tstats [nick] => Today's stats about $nick|$2
!ttop10 => Today's top 10 chatters in $network@#Channel
!delstats <nick> => Removing statistics about $2 in $network@#Channel
!clearstats => Removing all statistics collected for $network@#Channel
*/

; Binding all channel text to the parsing routine
; NB! No more "on text" events

/*
Version history:
21.02.2007 v1.2 bugfix release. (Fixed output bug resulting top9 instead of top10)
*/

ON *:TEXT:*:#: {
  if %stats_module == On {
    IF ($1 == %c $+ top10) {
      IF (%stats_floodpro >= 3) {
        halt
      }
      inc -u30 %stats_floodpro 1
      msg $chan $maketop10($network $+ @ $+ $chan)
      unset %stats_top10_*
      window -c @top10source
    }
    IF ($1 == %c $+ ttop10) {
      IF (%stats_floodpro >= 3) {
        halt
      }
      inc -u30 %stats_floodpro 1
      msg $chan $maketodaytop10($network $+ @ $+ $chan)
      unset %stats_top10_*
      window -c @top10source
    }
    IF ($1 == %c $+ stats) {
      IF (%stats_floodpro >= 3) {
        halt
      }
      inc -u30 %stats_floodpro 1
      IF ($2) {
        msg $chan $getstats($network $+ @ $+ $chan $+ @ $+ $2)
      }
      IF (!$2) {
        msg $chan $getstats($network $+ @ $+ $chan $+ @ $+ $nick)
      }
    }
    IF ($1 == %c $+ tstats) {
      IF (%stats_floodpro >= 3) {
        halt
      }
      inc -u30 %stats_floodpro 1
      IF ($2) {
        msg $chan $gettodaystats($network $+ @ $+ $chan $+ @ $+ $2)
      }
      IF (!$2) {
        msg $chan $gettodaystats($network $+ @ $+ $chan $+ @ $+ $nick)
      }
    }
    IF ($1 == %c $+ delstats) && ($2) &&  ($level($address($nick,2)) == 500) {
      remove-stats-nick $network $+ @ $+ $chan $+ @ $+ $2
      .msg $chan Erasing entries for nick $2
    }
    IF ($1 == %c $+ clearstats) &&  ($level($address($nick,2)) == 500) {
      remove-stats-channel $network $+ @ $+ $chan
      .msg $chan Channelstats erased.
    }
    IF ($left($1,1) == %c) {

      hinc -m totalcommands $network $+ @ $+ $chan $+ @ $+ $nick 1
      hinc -m todaytotalcommands $network $+ @ $+ $chan $+ @ $+ $nick 1
    }
    hinc -m totalwords $network $+ @ $+ $chan $+ @ $+ $nick $numtok($1-,32)
    hinc -m totalletters $network $+ @ $+ $chan $+ @ $+ $nick $len($1-)
    hinc -m totallines $network $+ @ $+ $chan $+ @ $+ $nick 1

    hinc -m todaytotalwords $network $+ @ $+ $chan $+ @ $+ $nick $numtok($1-,32)
    hinc -m todaytotalletters $network $+ @ $+ $chan $+ @ $+ $nick $len($1-)
    hinc -m todaytotallines $network $+ @ $+ $chan $+ @ $+ $nick 1
  }
}
; Action counting
; Will add all used words in action to the total spoken words as well

ON *:ACTION:*:#: {
  if %stats_module == on {
    hinc -m totalactions $network $+ @ $+ $chan $+ @ $+ $nick 1
    hinc -m totalwords $network $+ @ $+ $chan $+ @ $+ $nick $numtok($1-,32)
    hinc -m totalletters $network $+ @ $+ $chan $+ @ $+ $nick $len($1-)
    ;--
    hinc -m todaytotalactions $network $+ @ $+ $chan $+ @ $+ $nick 1
    hinc -m todaytotalwords $network $+ @ $+ $chan $+ @ $+ $nick $numtok($1-,32)
    hinc -m todaytotalletters $network $+ @ $+ $chan $+ @ $+ $nick $len($1-)
  }
}
ALIAS statsave {
  hsave -i totalwords chanstats.dat totalwords
  hsave -i totalletters chanstats.dat totalletters
  hsave -i totalcommands chanstats.dat totalcommands
  hsave -i totalactions chanstats.dat totalactions
  hsave -i totallines chanstats.dat totallines
}

ALIAS todaystatclear {
  hfree -w todaytotal*
  hmake todaytotalwords 10
  hmake todaytotalletters 10
  hmake todaytotalcommands 10
  hmake todaytotalactions 10
  hmake todaytotallines 10
}

ALIAS statload {
  hmake totalwords 10
  hmake totalletters 10
  hmake totalcommands 10
  hmake totalactions 10
  hmake totallines 10
  hload -i totalwords chanstats.dat totalwords
  hload -i totalletters chanstats.dat totalletters
  hload -i totalcommands chanstats.dat totalcommands
  hload -i totalactions chanstats.dat totalactions
  hload -i totallines chanstats.dat totallines
}

alias clearstats {
  var %stats_clearconfirm = $input(Are you sure you want to completely clear the statistics database?,yvqd,Channelstats :: Dreambot 5.6)
  IF (%stats_clearconfirm == $yes) {
    hfree -sw total*
    hmake totalwords 10
    hmake totalletters 10
    hmake totalcommands 10
    hmake totalactions 10
    hmake totallines 10
    todaystatclear
  }
}

ALIAS remove-stats-nick {
  var %stats-remnick = $1 $+ *
  hdel -w totalwords %stats-remnick
  hdel -w totalletters %stats-remnick
  hdel -w totalcommands %stats-remnick
  hdel -w totalactions %stats-remnick
  hdel -w totallines %stats-remnick
  hdel -w todaytotalwords %stats-remnick
  hdel -w todaytotalletters %stats-remnick
  hdel -w todaytotalcommands %stats-remnick
  hdel -w todaytotalactions %stats-remnick
  hdel -w todaytotallines %stats-remnick
  statsave
}

ALIAS remove-stats-channel {
  var %stats-remchan = $1 $+ *
  hdel -w totalwords %stats-remchan
  hdel -w totalletters %stats-remchan
  hdel -w totalcommands %stats-remchan
  hdel -w totalactions %stats-remchan
  hdel -w totallines %stats-remchan
  hdel -w todaytotalwords %stats-remchan
  hdel -w todaytotalletters %stats-remchan
  hdel -w todaytotalcommands %stats-remchan
  hdel -w todaytotalactions %stats-remchan
  hdel -w todaytotallines %stats-remchan
  statsave
}

ALIAS getstats {
  IF ($hget(totalwords, $1) != $null) {
    IF ($hget(totalwords, $1) != $null) {
      var %t.words = $hget(totalwords, $1)
    }
    ELSE {
      var %t.words = 0
    }
    IF ($hget(totalletters, $1) != $null) {
      var %t.letters = $hget(totalletters, $1)
    }
    ELSE {
      var %t.letters = 0
    }
    IF ($hget(totalcommands, $1) != $null) {
      var %t.commands = $hget(totalcommands, $1)
    }
    ELSE {
      var %t.commands = 0
    }
    IF ($hget(totallines, $1) != $null) {
      var %t.lines = $hget(totallines, $1)
    }
    ELSE {
      var %t.lines = 0
    }
    IF ($hget(totalactions, $1)) {
      var %t.actions = $hget(totalactions, $1)
    }
    ELSE {
      var %t.actions = 0
    }
    return [ $+ $gettok($1,3,64) $+ ] Spoken words: %t.words ( $+ %t.letters letters) Commands used %t.commands $+ . %t.lines lines and %t.actions actions.
    halt
  }
  return I have no stats about $gettok($1,3,64)
  halt
}

ALIAS gettodaystats {
  IF ($hget(todaytotalwords, $1) != $null) {
    IF ($hget(todaytotalwords, $1) != $null) {
      var %t.words = $hget(todaytotalwords, $1)
    }
    ELSE {
      var %t.words = 0
    }
    IF ($hget(todaytotalletters, $1) != $null) {
      var %t.letters = $hget(todaytotalletters, $1)
    }
    ELSE {
      var %t.letters = 0
    }
    IF ($hget(todaytotalcommands, $1) != $null) {
      var %t.commands = $hget(todaytotalcommands, $1)
    }
    ELSE {
      var %t.commands = 0
    }
    IF ($hget(todaytotallines, $1) != $null) {
      var %t.lines = $hget(todaytotallines, $1)
    }
    ELSE {
      var %t.lines = 0
    }
    IF ($hget(todaytotalactions, $1)) {
      var %t.actions = $hget(todaytotalactions, $1)
    }
    ELSE {
      var %t.actions = 0
    }
    return [ $+ $gettok($1,3,64) $+ ] Spoken words today: %t.words ( $+ %t.letters letters) Commands used today %t.commands $+ . %t.lines lines and %t.actions actions.
    halt
  }
  return I have no stats about $gettok($1,3,64)
  halt
}

ALIAS maketop10 {
  ; Save the hash table into .dat
  ; I know that this will make answer delayed especially in bigger channels... but well.... i dont care.
  ; This is about the best way to ensure that we will get the most recent result and also to ensure that we have backup of the hashtables.
  statsave
  ; Loading total spoken words into window
  window -hk0n @top10source
  clear @top10source
  var %stats_findbegin = $read(chanstats.dat, s, [totalwords])
  var %stats_looppoint = $calc($readn + 1 )
  WHILE (!%stats_loophalt) {
    var %stats_putline = $read(chanstats.dat, %stats_looppoint)
    IF ($left(%stats_putline,1) != $chr(91)) && ($left(%stats_putline,$len($1)) == $1) {
      var %statscleanline = $gettok($read(chanstats.dat, %stats_looppoint),3,64)
      aline @top10source %statscleanline
    }
    ELSEIF ($left(%stats_putline,1) == $chr(91)) {
      var %stats_loophalt = true
    }
    inc %stats_looppoint
  }
  ; Filtering the window
  filter -cetuww 2 61 @top10source @top10source *
  ; Now lets read the first 10 lines and store it to variables (%stats_top10_xx)
  ; Thats it if we have 10 lines of course
  ; If we have less then we will output only existing numbers of lines.
  var %stats_loop10 = 1
  WHILE (!%statssecondloophalt) {
    IF ($line(@top10source, %stats_loop10)) {
      set -e %stats_top10_ [ $+ [ %stats_loop10 ] ] $gettok($line(@top10source, %stats_loop10),1,61) ( $+ $gettok($line(@top10source, %stats_loop10),2,61) $+ )
      inc %stats_loop10
    }
    IF (!$line(@top10source, %stats_loop10)) || (%stats_loop10 >= 11) {
      var %statssecondloophalt = true
    }
  }
  IF (%stats_loop10 != 12) {
    var %stats_loop10 = $calc(%stats_loop10 - 1)
  }
  return Top %stats_loop10 chatters by total spoken words: %stats_top10_1 %stats_top10_2 %stats_top10_3 %stats_top10_4 %stats_top10_5 %stats_top10_6 %stats_top10_7 %stats_top10_8 %stats_top10_9 %stats_top10_10
}

ALIAS maketodaytop10 {
  window -hk0n @top10source
  clear @top10source
  hsave -i todaytotalwords tempstats.dat totalwords
  var %stats_loopline = 1
  WHILE (%stats_loopline <= $lines(tempstats.dat)) {
    IF ($gettok($read(tempstats.dat,%stats_loopline),1,64) == $gettok($1,1,64)) && ($gettok($read(tempstats.dat,%stats_loopline),2,64) == $gettok($1,2,64)) {
      aline -p @top10source $gettok($read(tempstats.dat,%stats_loopline),3,64)
    }
    inc %stats_loopline
  }
  filter -cetuww 2 61 @top10source @top10source *
  var  %stats_loop10 = 1
  WHILE (!%statssecondloophalt) {
    IF ($line(@top10source, %stats_loop10)) {
      set -e %stats_top10_ [ $+ [ %stats_loop10 ] ] $gettok($line(@top10source, %stats_loop10),1,61) ( $+ $gettok($line(@top10source, %stats_loop10),2,61) $+ )
      inc  %stats_loop10
    }
    IF (!$line(@top10source, %stats_loop10)) || (%stats_loop10 >= 11) {
      var  %statssecondloophalt = true
    }
  }
  IF (%stats_loop10 != 12) {
    var %stats_loop10 = $calc(%stats_loop10 - 1)
  }
  .remove tempstats.dat
  return Todays top %stats_loop10 chatters by total spoken words: %stats_top10_1 %stats_top10_2 %stats_top10_3 %stats_top10_4 %stats_top10_5 %stats_top10_6 %stats_top10_7 %stats_top10_8 %stats_top10_9 %stats_top10_10
}

ON *:CONNECT: timerresettodaystats -o {
  statload
  if %stats_module == $null { set %stats_module on }
  timerresettodaystats 23:59 1 60 dailystatsflush}

  ON *:EXIT: {
    echo -a ::: Stats ::: Storing stats.
    statsave
  }

  ALIAS dailystatsflush: disconnect server {
    timerresettodaystats 23:59 0 60 /todaystatclear
    todaystatclear
    /MSG $chan todaystats cleared when the bot resets}

Read More

Idlekicker


image
#idlekicker on
on *@!:JOIN:#help: if !$timer($nick) { $+(.timer,$nick) 1 120 KickIdler $chan $nick }
on *:TEXT:*:#help: $+(.timer,$nick) 1 120 KickIdler $chan $nick
on 1:NICK: {
if ($nick isop $chan) { return }
var %nick = $newnick, %cn = $comchan(%nick,0)
while (%cn) {
if (*#help* iswm $comchan(%nick,%cn)) { $+(.timer,%nick) 1 120 KickIdler #help %nick }
dec %cn
}
}
alias KickIdler { if ($me isop $1) && ($2 isreg $1) { ban -ku120 $1-2 2 Don't hang your nick here. Come back after 2 minutes if you really need help! Thank you }
}

#idlekicker end

Read More

AntiFlood v1.0


image
#####################################################################
#   AntiFlood v1.0
#   Description: Catching different types of flood on channels
#   Author: Epic
#####################################################################

alias af_data {
  .hadd -m af check-mess true
  .hadd -m af check-rep true
  .hadd -m af check-words true
  .hadd -m af check-mode true
  .hadd -m af check-kick true
  ;---------------------------
  .hadd -m af max-mess 5
  .hadd -m af max-mess-sec 3
  .hadd -m af max-rep 3
  .hadd -m af max-rep-sec 10
  .hadd -m af max-words 200
  .hadd -m af max-words-sec 10
  .hadd -m af mode +m
  .hadd -m af demode -m
  .hadd -m af mode-sec 300
  .hadd -m af reason flood/spam
}
====================================================
alias afcheck {
  var %af_check count- $+ $1 $+ $2
  if ($prop == rep) return $hget(af_rep,%af_check)
  if ($prop == rsec) return $hget(af_rsec,%af_check)
  if ($prop == mes) return $hget(af_mess,%af_check)
  if ($prop == msec) return $hget(af_msec,%af_check)
  if ($prop == words) return $hget(af_words,%af_check)
  if ($prop == wsec) return $hget(af_wsec,%af_check)
}
alias af_count_mes {
  var %af_count count- $+ $1 $+ $2
  if (!$hget(af_msec,%af_count)) .hadd -mz af_msec %af_count $hget(af,max-mess-sec)
  if (!$hget(af_mess,%af_count)) .hadd -mu $+ $hget(af,max-mess-sec) af_mess %af_count 0
  if ($hget(af_msec,%af_count) > 0) .hinc -m af_mess %af_count 1
}
alias af_count_rep {
  var %af_count count- $+ $1 $+ $2
  if (!$hget(af_rsec,%af_count)) || ($3- !isin $hget(af_rep_text,%af_count)) {
    .hadd -mz af_rsec %af_count $hget(af,max-rep-sec)
    .hadd -mu $+ $hget(af,max-rep-sec) af_rep %af_count 0
    .hadd -m af_rep_text %af_count $3-
  }
  else { .hinc -mu $+ $hget(af,max-rep-sec) af_rep %af_count 1 }
}
alias af_count_words {
  var %af_count count- $+ $1 $+ $2
  if (!$hget(af_wsec,%af_count)) .hadd -mz af_wsec %af_count $hget(af,max-words-sec)
  if (!$hget(af_words,%af_count)) .hadd -mu $+ $hget(af,max-words-sec) af_words %af_count 0
  if ($hget(af_wsec,%af_count) > 0) .hinc -m af_words %af_count $numtok($3-,32)
}
====================================================
on *:TEXT:*:#:{
  af_data | var %af_count count- $+ $nick $+ $chan
  if ($hget(af,check-mess) == true) af_count_mes $nick $chan
  if ($hget(af,check-rep) == true) af_count_rep $nick $chan $1-
  if ($hget(af,check-words) == true) af_count_words $nick $chan $strip($1-)

  ;# Debug check script echo
  ;/echo -s 28debug:18 $nick $chan 28 message:53 $hget(af_mess,%af_count) $hget(af_msec,%af_count) 28 repeat:41 $hget(af_rep,%af_count) $hget(af_rsec,%af_count) 28 words:29 $hget(af_words,%af_count) $hget(af_wsec,%af_count)

  if ($afcheck($nick,$chan).mes >= $hget(af,max-mess) && $afcheck($nick,$chan).msec > 0) {
    /echo -a FLOOD $chan $nick :40 $afcheck($nick,$chan).mes messages in40 $hget(af,max-mess-sec) seconds.
    if ($hget(af,check-mode) == true) af_mode_chan $nick $chan
    if ($hget(af_mess,%af_count)) .hdel -sw af_mess count-* | if ($hget(af_msec,%af_count)) .hdel -sw af_msec count-*
  }
  if ($afcheck($nick,$chan).rep >= $hget(af,max-rep) && $afcheck($nick,$chan).rsec > 0) {
    /echo -a FLOOD $chan $nick :40 $afcheck($nick,$chan).rep reps in40 $hget(af,max-rep-sec) seconds.
    if ($hget(af,check-mode) == true) af_mode_chan $nick $chan
    if ($hget(af_rep,%af_count)) .hdel -sw af_rep count-* | if ($hget(af_rsec,%af_count)) .hdel -sw af_rsec count-*
  }
  if ($afcheck($nick,$chan).words >= $hget(af,max-words) && $afcheck($nick,$chan).wsec > 0) {
    /echo -a FLOOD $chan $nick :40 $afcheck($nick,$chan).words words in40 $hget(af,max-words-sec) seconds.
    if ($hget(af,check-mode) == true) af_mode_chan $nick $chan
    if ($hget(af_words,%af_count)) .hdel -sw af_words count-* | if ($hget(af_wsec,%af_count)) .hdel -sw af_wsec count-*
  }
}
====================================================
alias af_mode_chan {
  if ($hget(af,check-kick) == true) /kick $2 $1 $hget(af,reason)
  if (!$timer(AF $+ $2)) {
    /mode $2 $hget(af,mode)
    .timerAF $+ $2 1 $hget(af,mode-sec) /mode $2 $hget(af,demode)
  }
}
====================================================

Read More