Coders-IRC
IRC for Coders
KeepMyNick.mrc
****************************************************************
;
; KeepMyNick ver 1.5 by Czuz (https://github.com/Czuz)
; To install just type: /load -rs KeepMyNick.mrc
;
;****************************************************************
;
; Help:
; KEEPNICK
; Syntax: /keepnick [<nick>] [<network>|default]
; Assigns <nick> to <network> (Or current network.) W/o argument
; disables grabbing until reconnection.
;
; LISTNICK
; Syntax: /listnick [-all]
; Displays list of nicks.
;
; DELNICK
; Syntax: /delnick [<network>|default]
; Remove nick associated with <network> (Or current network) from
; list
;
;****************************************************************
; ChangeLog:
; ver 1.5 (08.05.2021)
; - published on GitHub
; ver 1.4 (23.03.2005)
; - better handling of nick collisions on IRCnet
; ver 1.3 (15.03.2005)
; - new download link
; - better handling of ERR_RESTRICTED on IRCnet
; ver 1.2 (28.08.2004)
; - new download link
; ver 1.1 (04.06.2004)
; - spelling checked
; - fixed handling of raw events
; - default nick
; - /keepnick <nick> default, /delnick default
; - some GUI changes
; ver 1.0 (30.05.2004)
; - setup dialog (Commands->KeepMyNick v1.0)
; - minor changes in functions
; - extended syntax of commands
; - configurable timer delay
; ver 1.0-pre3 (13.05.2004)
; - added support for raw events:
; ERR_ERRONEUSNICKNAME, ERR_NICKNAMEINUSE, ERR_UNAVAILRESOURCE and ERR_RESTRICTED
; ver 1.0-pre2 (25.12.2003)
; - fixed disappearing timer bug
; - $comchan() instead of $ial()
; - minor bugs fixed
; ver 1.0-pre1 (22.12.2003)
; - keeping different nicks in multi-server mode
; - /keepnick, /listnick and /delnick commands
; - saving settings to file on exit and reading them on first connect
; - three states of nick grabbing:
; 0 - disabled
; 1 - passive (on events only, when we are on the same channel as nickstealer)
; 2 - active (periodically nick checking with timer)
;
; ver 0.9 (a long time ago)
; - simple on-event nick keeping for a single network
;
;****************************************************************
;--------------------------[ E V E N T S ]--------------------------
on *:LOAD: {
%KMN.Version = KeepMyNick v1.5
echo -st [KeepMyNick] Loading %KMN.Version ...
if ($version < 6.03) {
echo -st [KeepMyNick] Script NOT installed. Upgrade your mIRC version to 6.03+.
timer 1 2 unload -rs " $+ $script $+ "
halt
}
if (%KeepMyNickDelay) {
%KMN.Delay = %KeepMyNickDelay
unset %KeepMyNickDelay
}
else { %KMN.Delay = 10 }
if ($hget(MyNicks) == $null) {
hmake MyNicks 10
if ($scon(0) > 0 && $isfile(KeepMyNick.dat)) {
hload -b MyNicks KeepMyNick.dat
}
}
echo -st [KeepMyNick] - DONE! -
echo -st [KeepMyNick]
echo -st [KeepMyNick] Available commands:
echo -st [KeepMyNick] /keepnick [<nick>] [<network>|default]
echo -st [KeepMyNick] /listnick [-all]
echo -st [KeepMyNick] /delnick [<network>|default]
echo -st [KeepMyNick]
echo -st [KeepMyNick] For graphic setup, go to Menu->Commands-> $+ %KMN.Version
}
on *:UNLOAD: {
.timerKeepMyNick off
if ($hget(MyNicks)) {
hsave -ob MyNicks KeepMyNick.dat
hfree MyNicks
}
unset %KMN.Delay
unset %KMN.Version
unset %KMN.Default
unset %KMN.Options
echo -st [KeepMyNick] Bye...
}
on *:CONNECT: {
if ($scon(0) == 1) {
if ($isfile(KeepMyNick.dat)) {
if ($hget(MyNicks) == $null) { hmake MyNicks 10 }
hload -b MyNicks KeepMyNick.dat
}
}
if ($KMN.MyNick) { KMN.ChangeNickState 2 }
elseif (%KMN.Options == KMN.AddDef) { hadd -m MyNicks $KMN.FindNetwork 2 %KMN.Default }
elseif (%KMN.Options == KMN.KeepDef) { hadd -m MyNicks $KMN.FindNetwork 2 %KMN.Default 1 }
KMN.GetMyNick
}
on *:DISCONNECT: {
if ($nick == $me && $KMN.NickIsHidden) { hdel MyNicks $KMN.FindNetwork }
}
on *:EXIT: {
if ($hget(MyNicks)) {
hsave -ob MyNicks KeepMyNick.dat
hfree MyNicks
}
}
on *:KICK:#: {
if ($nick == $me || $nick == $KMN.MyNick) {
if ( $KMN.NickState > 0 ) {
KMN.ChangeNickState 2
}
}
}
on *:PART:#: {
if ($nick == $me || $nick == $KMN.MyNick) {
if ( $KMN.NickState > 0 ) {
KMN.ChangeNickState 2
}
}
}
on *:NICK: {
if ($nick != $me && $nick == $KMN.MyNick) {
if ( $KMN.NickState > 0 ) {
tnick $KMN.MyNick
}
}
elseif ($nick == $me && $nick == $KMN.MyNick && $KMN.NickState > 0) {
echo -at [KeepMyNick] Disabled for network $KMN.FindNetwork
KMN.ChangeNickState 0
}
}
on *:QUIT: {
if ($nick != $me && $nick == $KMN.MyNick) {
if ( $KMN.NickState > 0 ) {
tnick $KMN.MyNick
}
}
}
;----------------------[ R A W E V E N T S ]----------------------
; ERR_ERRONEUSNICKNAME
raw 432:*: {
if ($KMN.MyNick && $2 == $KMN.MyNick) {
echo -st [KeepMyNick] $2 - Erroneous Nickname
echo -st [KeepMyNick] Disabling for network $KMN.FindNetwork
KMN.ChangeNickState 0
halt
}
}
; ERR_NICKNAMEINUSE
raw 433:*: {
if ($KMN.MyNick && $2 == $KMN.MyNick) {
halt
}
}
; ERR_UNAVAILRESOURCE
raw 437:*: {
if ($KMN.MyNick && $2 == $KMN.MyNick) {
halt
}
}
; ERR_RESTRICTED
raw 484:*: {
if ($KMN.FindNetwork != IRCnet || $left($me, 1) !isin 0123456789) {
if ($KMN.NickState && $KMN.NickState != 0) {
echo -st [KeepMyNick] Your connection is restricted!
echo -st [KeepMyNick] Disabling for network $KMN.FindNetwork
KMN.ChangeNickState 0
halt
}
}
}
;---------------------[From OmenServe 1.42-b08]---------------------
; This should compensate for NewNet's lack of $network issues
alias KMN.FindNetwork {
if ( $network != $null ) { return $network }
if ( $server == irc.aohell.org ) { return NewNet }
if ( $server == irc.d0t.net ) { return NewNet }
if ( $server == irc.dividedspace.com ) { return NewNet }
if ( $server == irc.dragonskeep.com ) { return NewNet }
if ( $server == irc.eskimo.com ) { return NewNet }
if ( $server == irc.feartomorrow.com ) { return NewNet }
if ( $server == irc.firex.org ) { return NewNet }
if ( $server == irc.josephbarnhart.net ) { return NewNet }
if ( $server == irc.linux-friendly-56k.com ) { return NewNet }
if ( $server == irc.phantomshitter.net ) { return NewNet }
if ( $server == irc.sweatnet.net ) { return NewNet }
if ( $server == irc.moo.me.uk ) { return NewNet }
if ( $server == olympic.olympos-net.gr ) { return NewNet }
if ( $server != $null ) { return $server }
return Offline
}
;------------------------------[END]--------------------------------
;-----------------------[ F U N C T I O N S ]-----------------------
alias KMN.MyNick {
if ($1) {
return $gettok($hget(MyNicks, $1), 2, 32)
}
else {
return $gettok($hget(MyNicks, $KMN.FindNetwork), 2, 32)
}
}
alias KMN.NickState {
if ($1) {
return $gettok($hget(MyNicks, $1), 1, 32)
}
else {
return $gettok($hget(MyNicks, $KMN.FindNetwork), 1, 32)
}
}
alias KMN.NickIsHidden {
if ($1) {
return $gettok($hget(MyNicks, $1), 3, 32)
}
else {
return $gettok($hget(MyNicks, $KMN.FindNetwork), 3, 32)
}
}
alias KMN.ChangeNickState {
hadd -m MyNicks $KMN.FindNetwork $1 $mid($hget(MyNicks, $KMN.FindNetwork), 3)
}
alias KMN.GetMyNick {
var %currentserver = $cid
var %i = 1
while ($scon(%i)) {
scid $scon(%i)
if ( $server != $null && $me != $KMN.MyNick && $KMN.NickState > 1 ) {
if ($comchan($KMN.MyNick,0) != 0) {
KMN.ChangeNickState 1
}
else {
tnick $KMN.MyNick
}
}
inc %i
}
scid %currentserver
.timerKeepMyNick -i 1 %KMN.Delay KMN.GetMyNick
}
alias KMN.GetNetworkFromLine {
return $gettok($did(KMN.Setup, 11).seltext, 2, $asc(@))
}
alias KMN.CheckDelay {
if ($1 !isnum) { return 10 }
elseif ($1 < 5 ) { return 5 }
elseif ($1 > 600) { return 600 }
else { return $1 }
}
alias KMN.UpdateNicks {
var %currentserver = $cid
var %i = 1
while ($scon(%i)) {
scid $scon(%i)
if ((!$KMN.MyNick || $KMN.NickIsHidden) && %KMN.Options == KMN.AddDef) {
hadd -m MyNicks $KMN.FindNetwork 2 %KMN.Default
}
elseif ((!$KMN.MyNick || $KMN.NickIsHidden) && %KMN.Options == KMN.KeepDef) {
hadd -m MyNicks $KMN.FindNetwork 2 %KMN.Default 1
}
elseif ($KMN.NickIsHidden && %KMN.Options != KMN.KeepDef) {
hdel MyNicks $KMN.FindNetwork
}
inc %i
}
scid %currentserver
KMN.GetMyNick
}
alias KMN.DialogDelNick {
if ($1) {
hdel MyNicks $1
did -d KMN.Setup 11 $did(KMN.Setup, 11, 1).sel
}
}
alias KMN.DialogAddNick {
if ($1) { hdel MyNicks $1 }
hadd -m MyNicks $did(KMN.AddEdit,101) 2 $did(KMN.AddEdit,102)
if ($1) { did -o KMN.Setup 11 $did(KMN.Setup, 11, 1).sel $did(KMN.AddEdit,102) $+ @ $+ $did(KMN.AddEdit,101) }
else { did -a KMN.Setup 11 $did(KMN.AddEdit,102) $+ @ $+ $did(KMN.AddEdit,101) }
KMN.GetMyNick
}
alias KMN.DialogCheckBox {
if ($1 == 23) { var %i = 24 }
else { var %i = 23 }
if ($did(KMN.setup, $1).state == 0) {
if ($1 == 23) { var %i = 24 }
else { var %i = 23 }
%KMN.Options = $null
did -e KMN.setup %i
}
else {
if ($1 == 23) {
var %i = 24
%KMN.Options = KMN.AddDef
}
else {
var %i = 23
%KMN.Options = KMN.KeepDef
}
did -b KMN.setup %i
}
}
;------------------------[ C O M M A N D S ]------------------------
alias keepnick {
if ($2 == $null && $server == $null) {
echo -st [KeepMyNick] Connect to a server first.
halt
}
if ($1) {
if ($2 && $2 != default) { hadd -m MyNicks $2 2 $1 }
elseif ($2 && $2 == default) { %KMN.Default = $1 | %KMN.Options = KMN.KeepDef }
else { hadd -m MyNicks $KMN.FindNetwork 2 $1 }
KMN.GetMyNick
}
else {
echo -st [KeepMyNick] Disabled for network $KMN.FindNetwork
KMN.ChangeNickState 0
}
}
alias listnick {
echo -at [KeepMyNick] List of nicks:
var %i = 1
if ($1 == -all) {
var %max.servers = $hget(MyNicks,0).item
while (%i <= %max.servers) {
var %tmpserver = $hget(MyNicks,%i).item
if (!$KMN.NickIsHidden(%tmpserver)) {
echo -at [KeepMyNick] $KMN.MyNick(%tmpserver) $+ @ $+ %tmpserver
}
inc %i
}
}
else {
var %currentserver = $cid
while ($scon(%i)) {
scid $scon(%i)
if ($server && $KMN.MyNick && !$KMN.NickIsHidden) {
echo -at [KeepMyNick] $KMN.MyNick $+ @ $+ $KMN.FindNetwork $iif(($KMN.NickState == 0),(disabled),(enabled))
}
inc %i
}
scid %currentserver
}
}
alias delnick {
if ($1 && $1 == default && %KMN.Options = KMN.KeepDef) {
echo -st [KeepMyNick] Default nick disabled.
%KMN.Options = $null
KMN.UpdateNicks
}
elseif ($1 && $KMN.MyNick($1)) {
echo -st [KeepMyNick] Nick for $1 deleted.
hdel MyNicks $1
}
elseif ($1 == $null && $KMN.MyNick) {
echo -st [KeepMyNick] Nick for $KMN.FindNetwork deleted.
hdel MyNicks $KMN.FindNetwork
}
else { echo -st [KeepMyNick] No nick for that network. }
}
;----------------------------[ M E N U ]----------------------------
menu menubar {
%KMN.Version { dialog -m KMN.setup KMN.SetupDialog }
}
;-------------------------[ D I A L O G S ]-------------------------
dialog -l KMN.SetupDialog {
title %KMN.Version
size -1 -1 210 155
option dbu
box "Setup", 10, 2 2 206 130
list 11, 30 19 165 65, size, sort, vsbar
button "Add", 12, 6 19 20 15
button "Edit", 13, 6 36 20 15
button "Del", 14, 6 53 20 15
text "Nicks:", 15, 31 10 25 8
text %KMN.Version by Czuz, 16, 125 90 80 8
link "Latest version", 17, 125 98 80 8
text "Timer delay:", 18, 30 87 30 8
edit %KMN.Delay, 19, 63 86 35 10, right, limit 4
text "sec.", 20, 100 87 10 8
text "Default nick:", 21, 30 99 30 8
edit %KMN.Default, 22, 63 98 35 10, right
check "Add default nick to undefined networks", 23, 30 111 200 8
check "Keep default nick on undefined networks", 24, 30 121 200 8
button "Done", 99, 85 135 40 15, ok
}
dialog -l KMN.AddEditDialog {
title "KeepMyNick - Add/Edit"
size -1 -1 145 60
option dbu
combo 101, 15 15 60 10, edit, vsbar, drop
edit "", 102, 90 15 40 10
text "Network:", 103, 17 5 58 8
text "Nick:", 104, 92 5 38 8
button "Ok", 109, 30 35 30 15, ok
button "Cancel", 110, 85 35 30 15, cancel
}
on *:dialog:KMN.setup:init:0 {
var %max.servers = $hget(MyNicks,0).item
var %i = 1
while (%i <= %max.servers) {
var %tmpserver = $hget(MyNicks,%i).item
if (!$KMN.NickIsHidden(%tmpserver)) {
did -a KMN.setup 11 $KMN.MyNick(%tmpserver) $+ @ $+ %tmpserver
}
inc %i
}
if (%KMN.Options == KMN.AddDef) { did -c KMN.setup 23 | did -b KMN.setup 24 }
elseif (%KMN.Options == KMN.KeepDef) { did -c KMN.setup 24 | did -b KMN.setup 23 }
}
on *:dialog:KMN.setup:sclick:12 {
did -u KMN.Setup 11 $did(KMN.Setup, 11, 1).sel
$dialog(KMN.AddEdit, KMN.AddEditDialog, -4)
}
on *:dialog:KMN.setup:sclick:13 { $dialog(KMN.AddEdit, KMN.AddEditDialog, -4) }
on *:dialog:KMN.setup:sclick:14 { $KMN.DialogDelNick($KMN.GetNetworkFromLine) }
on *:dialog:KMN.setup:sclick:17 { run https://github.com/Czuz/KeepMyNick }
on *:dialog:KMN.setup:edit:19 { %KMN.Delay = $KMN.CheckDelay($did(KMN.setup,19)) }
on *:dialog:KMN.setup:edit:22 { %KMN.Default = $did(KMN.setup, 22)) }
on *:dialog:KMN.setup:sclick:23,24 { $KMN.DialogCheckBox($did) }
on *:dialog:KMN.setup:sclick:99 { $KMN.UpdateNicks }
on *:dialog:KMN.AddEdit:init:0 {
var %sel.network = $KMN.GetNetworkFromLine
if (%sel.network) { did -a KMN.AddEdit 101 %sel.network }
var %currentserver = $cid
var %i = 1
while ($scon(%i)) {
scid $scon(%i)
if ($server != $null && $network != $did(KMN.AddEdit,101,1)) {
did -a KMN.AddEdit 101 $KMN.FindNetwork
}
inc %i
}
scid %currentserver
did -c KMN.AddEdit 101 1
did -i KMN.AddEdit 102 1 $KMN.MyNick($did(KMN.AddEdit,101,1))
}
on *:dialog:KMN.AddEdit:sclick:109 { $KMN.DialogAddNick($KMN.GetNetworkFromLine) }
;----------------------------[ E N D ]------------------------------
Happy Birthday chain!!
Happy 60th Birthday to our very own chain. May your day be filled with love and family OLDMAN!!!
Channel Top10
/*
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}