All pastes #185260 Raw Edit

talim

public text v1 · immutable
#185260 ·published 2006-09-28 20:05 UTC
rendered paste body
on *:start: { load_hash }

alias -l load_hash {
  var %i = 1, %a, %b
  while ($findfile($scriptdir, *.hash, %i)) {
    %a = $ifmatch
    %b = $nopath(%a)
    hmake %b
    hload %b $+(", %a, ")
    inc %i
  }
}

on *:text:*:#: {
  if (%disable) { halt }
  tokenize 32 $remove($strip($1-), $chr(36))

  if ($regex($remove($1-, $me $+ $chr(32)), /^(who|what)('s|\sis)\s(\w+)/i)) {
    var %n = $regml(3)
    if ($definition(%n)) {
      .timer 1 $rand(1, 3) msg $chan %n $ifmatch $iif($rand(0, 1), $emote)
      return
    }
  }

  elseif ($me isin $1) {
    inconv $nick
    if (!$2) {
      bot_say $chan $nick yeash, $nick $+ ? $emote
    }
    elseif ($regex($remove($1-, $me), /(\w+)('s|\s(is|are))\s(.*)$/i)) {
      hadd -m bot3.hash $2-
      $iif($rand(0, 1), .timer 1 $rand(1, 3) msg $chan $+(Gotcha', $chr(44) $nick, .))
      return
    }
    elseif ($2 == forget) { 
      if ($definition($3)) { 
        hdel bot3.hash $3
        msg $chan $nick $+ : I forgot $3 $+ .
      }
      else {
        msg $chan $nick $+ : I don't know who/what $3 is.
      }
    }
    elseif ($2 == delete) {
      if ($3) {
        var %i = 1, %s
        while ($hmatch(bot1.hash, $+(*, $3-, *), 1).data) {
          %s = $ifmatch
          hdel bot1.hash %s
          hadd -m bot4.hash %s
          inc %i
        }
        msg $chan %i quotes have been deleted from my database.
      }
      else {
        msg $chan Delete what?
      }
      return
    }
    elseif ($2 == match) {
      if ($3 isnum) {
        msg $chan Match $3 $+ : $hget(bot1.hash, $hmatch(bot1.hash, $+(*, $4-, *), $3).data)
      }
      else {

        msg $chan I have $hmatch(bot1.hash, $+(*, $3-, *), 0).data matches for $+(", $3-, ".)
      }
      return
    }
    elseif ($2 == stfu) { 
      set -u5 %disable 1
    }
    elseif ($2 == troll) { 
      .timer 0 1 send_bla $3 
      msg $chan Now Trolling $3 $+ .
    }
    elseif ($3 ison $chan) || ($4 ison $chan) {
      bot_act $chan $1 $+ $iif($right($2, 1) != s, s) $replace($2-, me, $nick) 
    }
    elseif ($2 == pm) {
      set %base $chan
      .msg $3 $4-
      return
    }
  }
  if ($0 < 20) {
    tokenize 32 $strip($1-)
    reply $chan $nick $1-
    learn $chan $1-
  }
}

alias send_bla {
  $iif($rand(0,1), msg, $iif($rand(0,1), notice, ctcp)) $1 $flood_chars
}

alias -l flood_chars { dll $+(", $scriptdir, whilefix.dll, ") WhileFix | var %a = $rand(1, 2), %b
  if (%a == 1) { %b = $str($+($asc_junk, $rand(A, Z), $asc_junk, $rand(a, z)), 40) }
  elseif (%a == 2) { %b = $str($+($asc_junk, $chr($rand(1, 300)), $asc_junk, $chr($rand(1, 300)),$asc_junk, $chr($rand(1, 300))), 10) }
  return %b
}
alias -l asc_junk { return $+($chr(2), $chr(3), $rand(1, 15)) }


alias definition {
  return $hget(bot3.hash, $1)
}

alias -l reply {
  if ($me isin $1-) || ($inconv($2)) || ($rand(1, 3) == 3) {
    var %c = $1, %n = $2, %s, %p
    tokenize 32 $3-
    if ($hget(reply)) { hfree reply }
    while ($gettok($1-, %i, 32)) {
      %s = $ifmatch
      if ($len(%s) > 3) && (%s !ison $chan) {
        if ($hmatch(bot1.hash, $+(*, %s, *), 0).data) {
          hadd -m reply $ticks $hget(bot1.hash, $hmatch(bot1.hash, $+(*, %s, *), $rand(1, $ifmatch)).data)
        }
      }
      %p = $iif(%p, %p $+ \s) $+ $iif($rand(0, 1), %s, \w+)
      inc %i
    }
    %i = $hget(reply, 0).item
    if (%i) {
      %p = $+(/, %p, /i)
      if ($hregex(reply, %p, 0).data) {
        %s = $hget($hregex(reply, %p, $rand(1, $ifmatch)).data)
        if (%s != $1-) {
          bot_say %c %n %s
          return
        }
      }
      else {
        :retry
        if (%i) {
          %s = $hget(reply, $rand(1, %i)).data
          if (%s != $1-) {
            bot_say %c %n %s
            if ($rand(1, 5) == 5) { .timer 1 $rand(1, 60) msg %c $word($rand(5, 10)) }
            return
          }
          else {
            dec %i
            goto retry
          }
        }
      }
    }
  }
}

alias -l inconv {
  if ($isid) {
    return $hget(inconv, $1)
  }
  else {
    hadd -mu15 inconv $1 1
  }
}

alias -l learn {
  var %i = 1, %c = $1, %s
  tokenize 32 $2-
  while ($gettok($1-, %i, 32)) {
    %s = $ifmatch
    if ($isnick(%s, %c)) {
      tokenize 32 $reptok($1-, %s, <NICK>, 1, 32)
    }
    elseif ($regex(%s, /((s)?he(')?s)/i)) { %s = $iif($rand(0, 1), i, me) }
    inc %i
  }
  if (!$hmatch(bot1.hash, $1-).data) {
    if ($hget(bot4.hash, 1).item) {
      %i = $ifmatch
      hdel bot4.hash %i
    }
    else {
      %i = ITEM $+ $calc($hget(bot1.hash, 0).item + 1)
    }
    hadd -m bot1.hash %i  $1-
  }
}

alias -l bot_say {
  var %c = $1, %n = $2, %i = 1, %x = 0
  tokenize 32 $3-
  while ($gettok($1-, %i, 32)) {
    %s = $ifmatch
    if (*<NICK>* iswm %s) {
      tokenize 32 $reptok($1-, %s, $replace(%s, <NICK>, $iif(!%x, %n, $nick(%c, $rand(1, $nick(%c, 0))))), 1, 32)
      inc %x
    }
    inc %i
  }
  .timer 1 $rand(1, 3) msg %c $iif(%n !isin $1- && $rand(1, 5) == 5 && $1, %n $+ :) $1-
  if ($rand(1, 5) == 5) {
    .timer 1 $rand(1, 3) msg %c $emote
  }
}

alias emote {
  var %p = /^((:|;|=|x)('|-|o)?(\)|\||\(|\[|\]|o|x|d)|(o|\^|\.)(\.|_)(o|\^|\.))$/i
  if ($hregex(bot1.hash, %p, 0).data) {
    return $hget(bot1.hash, $hregex(bot1.hash, %p, $rand(1, $ifmatch)).data)
  }
}

alias word {
  var %a = $str(., $calc($1 - 1)), %b = $str(., $calc($1 + 1)), %p = $+(/\s(a(n)?|the)\s, $chr(40), [^, $chr(40), \W|, %a, |, %b, $chr(41), ]+, $chr(41)/)
  if ($hregex(bot1.hash, %p, 0).data) {
    if ($hget(bot1.hash, $hregex(bot1.hash, %p, $rand(1, $ifmatch)).data)) {
      if ($regex($ifmatch, %p)) {
        return $regml(1) $regml(2)
      }
    }
  }
}

on *:action:*:#: {
  if (%disable) { halt }
  tokenize 32 $remove($strip($1-), $chr(36))
  if ($0 <= 10) {
    if ($me isin $1-) {
      reply_a $chan $nick $1-
    }
    learn_a $chan $1-
  }
}

alias reply_a {
  if ($rand(0, 1)) {
    var %s = $gettok($word($rand(4, 10)), 2, 32)
    if ($right(%s, 1) != s) { %s = %s $+ s }
    %s = %s $2 
  }
  else {
    %s = $replace($3-, $me, $2)
  }
  bot_act $1-2 %s $iif($rand(0, 1), in return, $iif($rand(0, 1), back)) $iif($rand(0, 1) && with !isin $3-, with $word($rand(1, 10))) $iif($rand(0, 1), $emote)
}

alias -l learn_a {
  var %i = 1, %c = $1, %s
  tokenize 32 $2-
  while ($gettok($1-, %i, 32)) {
    %s = $ifmatch
    if ($isnick(%s, %c)) {
      tokenize 32 $reptok($1-, %s, <NICK>, 1, 32)
    }
    inc %i
  }
  if (!$hmatch(bot2.hash, $1-).data) {
    hadd -m bot2.hash ITEM $+ $calc($hget(bot2.hash, 0).item + 1) $1-
  }
}

alias -l bot_act {
  var %c = $1, %n = $2, %x = 0, %i = 1
  tokenize 32 $3-
  while ($gettok($1-, %i, 32)) {
    %s = $ifmatch
    if (*<NICK>* iswm %s) {
      tokenize 32 $reptok($1-, %s, $replace(%s, <NICK>, $iif(!%x, %n, $nick(%c, $rand(1, $nick(%c, 0))))), 1, 32)
      inc %x
    }
    inc %i
  }
  .timer 1 $rand(1, 3) describe %c $1-
}

alias isnick {
  var %c = $2, %i, %s
  if ($hget(nlist, active) != %c) { 
    hadd -m nlist active %c
    %i = 1
    while ($nick(%c, %i)) {
      hadd nlist $ifmatch
      inc %i
    }
  }
  %i = 1
  while ($hget(nlist, %i).item) {
    %s = $ifmatch
    if (%s isin $1) { return 1 }
    inc %i
  } 
  return 0
}

on !*:voice:#: {
  if ($vnick == $me) {
    var %p = /^(thanks|thank\syou)/i
    if ($hregex(bot1.hash, %p, 0).data) {
      bot_say $chan $nick $hget(bot1.hash, $hregex(bot1.hash, %p, $rand(1, $ifmatch)).data) $emote
    }
  }
}

on *:exit: {
  save_hash
}

alias save_hash {
  var %i = 1, %s
  while ($hget($+(bot, %i, .hash))) {
    %s = $ifmatch
    hsave -o %s $+(", $scriptdir, %s, ")
    hfree %s
    inc %i
  }
}

on *:text:*:?: { msg %base message from $nick $+ : $1- | window -c $nick }