All pastes #736450 Raw Edit

Stuff

public text v1 · immutable
·published 2007-10-14 15:32 UTC
rendered paste body
; WhatPulse Information Script for mIRC 6.X
; Written by Scott Wilcox <sc0tt@sc0tt.ca>
; Thanks go to Splodgey, wasted.
;
; http://sc0tt.ca http://unlagged.org
;
; Recoded by RooZ
;
; irc.irchighway.net #tmnt-files
;
; CONFIGURING:
; There isn't much to configure, other then setting your
; user ID. To get this click on the WhatPulse tray icon,
; (the W), and go to Account -> Your Account Info, and
; copy the user ID (the NUMBER!), and simply type /wp update
; and enter your ID, and it's all set!
; You can also set what colours you want and design a layout below
; but only do it if you know how to script in mIRC ;)
;
; PLEASE NOTE:
; For this script to work, you need to enable your
; stats to be generated on the WhatPulse server. To
; do this, login to the WhatPulse site, go to your 
; options and check "Generate XML statistics (WebAPI)"
; these stats update every hour, so they won't be
; fully up-to-date with you last Pulse.
;
; USAGE:
; /wp update - Updates your stats for use on IRC (do this regually!)
; /wp long - Shows a detailed version of your stats in 3 lines
; /wp short - Shows a summarised version of your stats in 1 line
; /wp team - Shows your team stats in 2 lines
; /wp changeid - Change your WhatPulse user ID
;
; You can also add a number on the end of "/wp long"
; and "/wp team" to limit the amount of lines outputted.
; eg. "/wp long 2" would only say 2 lines, not all 3

; Colours (TWO digits! eg. 04, or 14):
alias c {
  if ($1 = 1) { return 04 }
  if ($1 = 2) { return 14 }
}

; Layouts:
alias bracket {
  return $c(1) $+ [ $+ $c(2) $+ $1 $+ $iif((($1 !== $null) && ($2- !== $null)),$chr(32)) $+ $2- $+ $c(1) $+ ]
}
alias border { 
  return $c(1) $+ « $+ $c(2) $+ $1 $+ $c(1) $+ »
}

on *:start: {
  %old = %wp_userid
  unset %wp_*
  %wp_userid = %old
  unset %old
  wp update
}

on *:sockopen:wp_socket: {
  if ($sockerr) {
    echo -a $bracket(***) Error $sockerr when downloading
    return
  }
  unset %downloadlength %downloadready
  sockwrite -n $sockname GET /api/user.php?UserID= $+ %wp_userid HTTP/1.0
  sockwrite -n $sockname Accept: */*
  sockwrite -n $sockname Host: whatpulse.org
  sockwrite -n $sockname User-Agent: http://sc0tt.ca v1.0
  sockwrite -n $sockname
}

on *:sockread:wp_socket:{
  if (%wp_downloadready != 1) {
    var %wp_header
    sockread %wp_header
    while ($sockbr) {
      if (Content-length: * iswm %wp_header) {
        %wp_downloadlength = $gettok(%wp_header,2,32)
      }
      elseif (* !iswm %wp_header) {
        %wp_downloadready = 1
        %wp_downloadoffset = $sock($sockname).rcvd
        break
      }
      sockread %wp_header
    }
  }
  sockread %wp_c
  while ($sockbr) {
    set $+(% $+ wp_,$gettok($gettok(%wp_c,2,60),1,62)) $gettok($gettok(%wp_c,2,62),1,60)
    sockread 4096 %wp_c
  }

  set %wp_lastupdated $ctime
}

on *:sockclose:wp_socket:{
  ; Socket has been closed, the stats were updated.
  echo -a $bracket(***) WhatPulse stats finished updating ( $+ %wp_downloadlength bytes downloaded).
}

alias wp {
  ; The list below shows the variables that are set when you
  ; update the script. They are set globally, and you can use
  ; them in any way that you want to.
  ; For this example, I just used a /say
  ;
  ; %wp_UserID 199872
  ; %wp_downloadlength 921
  ; %wp_downloadready 1
  ; %wp_downloadoffset 225
  ; %wp_GeneratedTime 2007-03-14 04:01:03
  ; %wp_AccountName Amatively
  ; %wp_Country Australia
  ; %wp_DateJoined 2006-11-23
  ; %wp_Homepage http://www.myspace.com/roozbenjrox
  ; %wp_LastPulse 2007-03-14 00:20:15
  ; %wp_Pulses 268
  ; %wp_TotalKeyCount 2665339
  ; %wp_TotalMouseClicks 1749908
  ; %wp_TotalMiles 83.658
  ; %wp_AvKeysPerPulse 9945
  ; %wp_AvClicksPerPulse 6530
  ; %wp_AvKPS 0.28
  ; %wp_AvCPS 0
  ; %wp_Rank 21721
  ; %wp_TeamID 3226
  ; %wp_TeamName Cunts United
  ; %wp_TeamMembers 19
  ; %wp_TeamKeys 49069315
  ; %wp_TeamClicks 22807322
  ; %wp_TeamMiles 105.578
  ; %wp_TeamDescription N/A
  ; %wp_TeamDateFormed N/A
  ; %wp_TeamRank N/A
  ; %wp_RankInTeam N/A
  ; %wp_lastupdated 1173841722

  ; Most of your stats in 3 lines (/wp long)
  if ($1 == long) {
    say $bracket(WhatPulse.org user %wp_AccountName) I have pressed a total of $border($bytes(%wp_TotalKeyCount,b)) keys, clicked $border($bytes(%wp_TotalMouseClicks,b)) times and have moved my mouse $border(%wp_TotalMiles) miles since $border(%wp_DateJoined) my global rank is $border(%wp_Rank)
    if ($2 != 1) {
      say $c(1) $+ Pulses: $border(%wp_Pulses) Last Pulse: $border(%wp_LastPulse) Stats Last Updated: $border($time(%wp_lastupdated, dd/mm/yy @ hh:nn:sstt))
      if ($2 != 2) {
        say $c(1) $+ Average Keys Per Second: $border(%wp_AvKPS) Average Clicks Per Second: $border(%wp_AvCPS)
      }
    }
  }

  ; Shorted summary of your stats in 1 line (/wp short)
  if ($1 == short) {
    say $bracket(WhatPulse.org user %wp_AccountName) Keys Pressed: $border($bytes(%wp_TotalKeyCount,b)) Mouse Clicks: $border($bytes(%wp_TotalMouseClicks,b)) Miles Moved: $border(%wp_TotalMiles) Since: $border(%wp_DateJoined) Rank: $border(%wp_Rank)
  }

  ; Your teams stats in 2 lines (/wp team)
  if ($1 == team) {
    ; NOTE: The latest XML file is incomplete, and gives "broken" values for:
    ;       TeamDescription, TeamDateFormed, TeamRank, and RankInTeam
    ;
    ;       This sets them to "N/A". You can delete these 4 lines if they are fixed
    ;       To wasted: Fix them please!

    if (%wp_TeamDescription == /TeamDescription) { set %wp_TeamDescription n/a }
    if (%wp_TeamDateFormed == /TeamDateFormed) { set %wp_TeamDateFormed n/a }
    if (%wp_TeamRank == /TeamRank) { set %wp_TeamRank n/a }
    if (%wp_RankInTeam == /RankInTeam) { set %wp_RankInTeam n/a }

    say $bracket(WhatPulse.org team %wp_TeamName) My team has $border(%wp_TeamMembers) members and has pressed a total of $border($bytes(%wp_TeamKeys,b)) keys, clicked $border($bytes(%wp_TeamClicks,b)) times and moved their mouse $border(%wp_TeamMiles) miles since $border(%wp_TeamDateFormed)
    if ($2 != 1) {
      say $c(1) $+ My teams overall ranking is: $border(%wp_TeamRank) and my rank in the team is: $border(%wp_RankInTeam $+ / $+ %wp_TeamMembers) 
    }
  }

  ; Updates your stats, do this regually! (/wp update)
  if ($1 == update) {
    if (%wp_userid !isnum) {
      set %wp_userid $$?="Enter Your WhatPulse User ID (this is a number! eg. 199872):"
      if (%wp_userid !isnum) {
        echo -a $bracket(***) WhatPulse User ID is not a number! Please re-run /wp update and enter your user ID
      }
      else {
        echo -a $bracket(***) WhatPulse User ID Set!
      }
    }
    if (%wp_userid isnum) {
      ; Check to see if socket is already in use.
      if ($sock(wp_socket)) {
        ; Return error message if so
        echo -a $bracket(***) WhatPulse is already updating stats, please wait.
        return
      }

      ; Socket not in use, echo out updating message
      echo -a $bracket(***) WhatPulse updating stats

      ; If the WhatPulse server ever changes, this will 
      ; need to be updated too.
      sockopen wp_socket whatpulse.org 80
    }
  }

  if ($1 == changeid) {
    unset %wp_userid
    if (%wp_userid !isnum) {
      set %wp_userid $$?="Enter Your WhatPulse User ID (this is a number! eg. 199872):"
      if (%wp_userid !isnum) {
        echo -a $bracket(***) WhatPulse User ID is not a number! Please re-run /wp changeid and enter your user ID
      }
      else {
        echo -a $bracket(***) WhatPulse User ID Set!
      }
    }
    if (%wp_userid isnum) {
      ; Check to see if socket is already in use.
      if ($sock(wp_socket)) {
        ; Return error message if so
        echo -a $bracket(***) WhatPulse is already updating stats, please wait.
        return
      }

      ; Socket not in use, echo out updating message
      echo -a $bracket(***) WhatPulse updating stats

      ; If the WhatPulse server ever changes, this will 
      ; need to be updated too.
      sockopen wp_socket whatpulse.org 80
    }
  }
}

; Simple menus
menu channel,nicklist,nicklist {
  WhatPulse Stats
  .Update: wp update
  .Change User ID: wp changeid
  .Show in # $+
  ..Short: wp short
  ..Long: wp long
  ..Team: wp team
}