aIRC — File Browser
aIRCv0.8.69 / aIRCv0.8.69 / script / notes.mrc
notes.mrc — 11.13 KB — Download this file
;/**********************************************************************
; *
; * aIRC
; * Notes
; *
; **********************************************************************/
ON *:JOIN:#:{
if (%++handle != $null) && ($_getsetup(script,notify-onjoin)) && ($_not($_partyline.isonline(%++handle))) && ($comchan($chan,$nick) == 0) && ($_not($_notes.noticeonjoinprot(%++handle))) {
if ($_notes.number(%++handle)) { _notes.sendnotice %++handle $nick $ifmatch _j_ }
}
}
; notes
; notes index
; notes read <# or ALL>
; notes erase <# or ALL>
alias _cmd.notes {
var %result = $__cmd.notes($1,$2,$3-),%handle = $iif($1,$1,$me)
if ($left(%result,1) >= 4) { return %result }
.timer -o 1 0 _cmdlog %handle notes $2-
return %result
}
alias __cmd.notes {
var %handle = $1,%r,%lwin = @__loadnotes,%win = @__notes,%file = $_noteinifile
if ($2 == $null) { return 574 }
if ($istok(index read erase,$2,32) == $false) { return 575 }
if ($2 == index) || ($3 == $null) || ($3 == all) { %r = 1- }
else { %r = $3 }
if ($_notes.number($1) == 0) { return 576 }
_openwins %win
__cmd.notes.loadnotes $1 %r
if ($2 == index) {
aline %win ### You have the following notes waiting:
var %i = 1,%n = $line(%lwin,0)
while (%i <= %n) {
__cmd.notes.index $line(%lwin,%i)
inc %i
}
aline %win ### Use '.notes read' to read them.
return 222 @__notes @__loadnotes,@__notes
}
if ($line(%lwin,0) == 0) {
close -@ %win %lwin
return 577
}
var %i = 1,%n = $line(%lwin,0)
while (%i <= %n) {
if ($2 == read) { __cmd.notes.read $line(%lwin,%i) }
else { write -ds" $+ $gettok($line(%lwin,%i),2-,32) $+ " $"(%file) }
inc %i
}
if ($2 == erase) {
close -@ %win
close -@ %lwin
if ($_notes.number($1)) { return 260 $calc(%i - 1) $ifmatch }
return 261
}
return 222 @__notes @__loadnotes,@__notes
}
alias __cmd.notes.index { aline @__notes $_filleft(4, ,$round($1,0)) $+ . $3 ( $+ $__cmd.notes.expires($4) $+ ) }
alias __cmd.notes.read { aline @__notes $_filleft(2, ,$round($1,0)) $+ . $3 ( $+ $__cmd.notes.expires($4) $+ ): $5- }
alias __cmd.notes.expires {
var %t = $asctime($1,mmm dd HH:nn),%exp = $calc(($1 + ($_getsetup(script,note-life) * 86400) - $ctime) / 86400)
if (%exp >= 0) {
if (%exp <= 1) { return %t -- EXPIRES TODAY }
if ($round(%exp,0) <= 7) { return %t -- EXPIRES IN $_nsingoplur($ifmatch,DAY,DAYS) }
}
return %t
}
alias __cmd.notes.loadnotes {
var %file = $_noteinifile,%lwin = @__loadnotespre,%win = @__loadnotes
tokenize 32 $1 $replace($2,;,$chr(44))
close -@ %lwin
window -h %lwin
close -@ %win
window -hs %win
_notes.chexpire
filter -fw $"(%file) %lwin $1 *
var %i = 1,%n = $numtok($2,44),%l = $line(%lwin,0),%t,%r
while (%i <= %n) {
%t = $gettok($2,%i,44)
if ($_isint(%t)) {
if (%t <= %l) {
if ($istok(%r,%t,44) == $false) { aline %win $_filleft(6,0,%t) $line(%lwin,%t) }
%r = $addtok(%r,%t,44)
}
}
elseif ($count(%t,-) == 1) && ($_isint($gettok(%t,1,45))) && ($_isint($remove(%t,-))) {
var %< = $gettok(%t,1,45),%> = $calc(%< + 1000)
if ($_isint($gettok(%t,2,45))) { %> = $ifmatch }
if (%< < %>) {
while (%< <= %>) && (%< <= %l) {
if ($istok(%r,%<,44) == $false) { aline %win $_filleft(6,0,%<) $line(%lwin,%<) }
%r = $addtok(%r,%<,44)
inc %<
}
}
}
inc %i
}
close -@ %lwin
}
;_
; fwd +m
; fwd <handle> [desto]
; +noteign
; +noteign <ignoremask>
; +noteign +m
; +noteign [user] <ignoremask>
alias +noteign { _useredit.echocode +noteign $1- }
alias _cmd.+noteign {
var %file = $_noteignoreinifile,%user,%ignore,%line,%readn
if ($2 == $null) || (($1 == $null) && ($3 == $null)) { return 607 }
_cmdlog $iif($1,$1,$me) +noteign $2-
if ($3 != $null) {
if ($_validateuser(4,$2,$null)) { return $ifmatch $2 }
if ($1 != $null) && ($1 != $2) && ( ($_not($_ismaster($1,0,mn))) || ($_partyline.chlevels($1,$2)) ) { return 608 $2 }
var %user = $2,%ignore = $3
}
elseif ($1 != $null) { var %user = $1,%ignore = $2 }
else { return 607 }
%line = $_noteignores(%user)
if ($istok(%line,%ignore,32)) { return 609 %user %ignore }
write -s $+ %user $"(%file) %user $addtok(%line,%ignore,32)
return 290 %user %ignore
}
; -noteign
; -noteign <ignoremask>
; -noteign +m
; -noteign [user] <ignoremask>
alias -noteign { _useredit.echocode -noteign $1- }
alias _cmd.-noteign {
var %file = $_noteignoreinifile,%user,%ignore,%line,%readn
if ($2 == $null) || (($1 == $null) && ($3 == $null)) { return 610 }
_cmdlog $iif($1,$1,$me) -noteign $2-
if ($3 != $null) {
if ($_validateuser(4,$2,$null)) { return $ifmatch $2 }
if ($1 != $null) && ($1 != $2) && ( ($_not($_ismaster($1,0,mn))) || ($_partyline.chlevels($1,$2)) ) { return 608 $2 }
var %user = $2,%ignore = $3
}
elseif ($1 != $null) { var %user = $1,%ignore = $2 }
else { return 610 }
%line = $_noteignores(%user)
if ($istok(%line,%ignore,32) == $false) { return 611 %user %ignore }
if ($remtok(%line,%ignore,32) != $null) { write -s $+ %user $"(%file) %user $ifmatch }
else { write -ds $+ %user $"(%file) %user }
return 290 %user %ignore
}
; noteigns
; noteigns +m
; noteigns [user]
alias noteigns { _useredit.echocode noteigns $1- }
alias _cmd.noteigns {
var %file = $_noteignoreinifile,%user,%ignore,%line,%readn
if ($1 == $null) && ($2 == $null) { return 612 }
if ($2 != $null) {
if ($_validateuser(4,$2,$null)) { return $ifmatch $2 }
if ($1 != $null) && ($1 != $2) && ( ($_not($_ismaster($1,0,mn))) || ($_partyline.chlevels($1,$2)) ) { return 608 $2 }
var %user = $2
}
elseif ($1 != $null) { var %user = $1 }
else { return 612 }
%line = $_noteignores(%user)
if (%line == $null) { return 613 %user }
_cmdlog $iif($1,$1,$me) noteigns $2-
return 292 %user %line
}
;;
; $_noteignores(handle)
alias _noteignores { return $read -ns $+ $1 $_noteignoreinifile }
; note
; note <nickname[@bot]> <message>
alias note {
if ($_isuser($1)) { _useredit.echocode note $1- }
else {
if ($1- != $null) {
write $"($_pnoteinifile) $ctime $1-
if ($show) { info.a Note saved }
}
else { notes }
}
}
alias notes {
if ($1 == flush) {
write -c $"($_pnoteinifile)
if ($show) { info.a Notes flushed! }
}
else {
var %win @__pnotes,%i = 1,%line,%ctime,%note,%len
_openwins %win
loadbuf %win $"($_pnoteinifile)
if ($line(%win,0)) {
%len = $len($ifmatch)
lecho.a $colour(info) $^*** You have the following notes:
while (%i <= $line(%win,0)) {
if ($line(%win,%i) != $null) {
var %line = $ifmatch,%ctime = $gettok(%line,1,32),%note = $gettok(%line,2-,32)
echo.a $colour(info) $^*** $_filleft(%len, ,$round(%i,0)) $+ . ( $+ $asctime(%ctime,mmm dd HH:nn) $+ ): %note
}
inc %i
}
}
elseif ($show) { info.a You have no stored notes }
close -@ %win
}
}
alias _cmd.note {
var %file,%index,%i,%n,%sock,%notaway,%socka,%sockh,%sockt,%sockmsg,%nodisp = %c.note.nodisplay,%ignorefrom
unset %c.note.nodisplay
if ($2 == $null) { return 555 }
if ($_validateuser(4,$2,$null)) { return $ifmatch $2 }
if (b isincs $_nickflags($2)) { return 607 $2 }
var %ignorefrom = $_noteignores($2),%i = $numtok(%ignorefrom,32)
if ($1 != $null) && (%ignorefrom != $null) {
while (%i) {
if ($gettok(%ignorefrom,%i,32) iswm $1) { return 614 $2 }
dec %i
}
}
%index = partyline*. $+ $2 $+ ._l*
if ($sock(%index,0)) {
var %i = 1,%n = $ifmatch
while (%i <= %n) {
%sock = $sock(%index,%i)
if ($_sockmark(%sock,5) != $null) { %socka = $addtok(%socka,%sock,44) }
else {
%sockh = $addtok(%sockh,%sock,44)
inc %notaway
}
inc %i
}
if (%notaway) {
if (%nodisp) { %sockmsg = $+ $1 [Outside note]: $3- }
else { %sockmsg = Note [ $+ $iif($1,$1,$me) $+ ]: $3- }
}
elseif ($_not(%nodisp)) { %sockmsg = *** Note arrived for you. }
if (%sockmsg != $null) {
%sockt = $iif(%notaway,%sockh,%socka)
%i = 1
%n = $numtok(%sockt,44)
while (%i <= %n) {
sockwrite $gettok(%sockt,%i,44) %sockmsg $+ $crlf
inc %i
}
}
}
if (%notaway) { return 244 $2 $3- }
if ($_notes.number($2) >= $_getsetup(script,max-notes)) { return 262 $2 }
write " $+ $_noteinifile $+ " $2 $iif($1,$1,$me) $ctime $3-
return 245 $2 $3-
}
alias _notes.chexpire {
var %file = $_noteinifile,%win = @__noteschexpire,%i,%deleted = 0,%notelife = $calc($_getsetup(script,note-life) * 86400),%time,%left
if ($_not($lines(%file))) { return 0 0 }
_openwins %win
loadbuf %win %file
%i = $line(%win,0)
while (%i) {
%time = $gettok($line(%win,%i),3,32) + %notelife
if (%time < $ctime) {
dline %win %i
inc %deleted
}
dec %i
}
%left = $line(%win,0)
if (%deleted) {
savebuf %win %file
_putlog Expired $_nsingoplur(%deleted,note,notes)
}
close -@ %win
return %deleted %left
}
alias _start.notes {
if ($gettok($_notes.chexpire,1,32)) { info.s Expired $_nsingoplur(%deleted,note,notes) }
}
alias _notes.number {
var %win = @__partylineusernotes,%file = $_noteinifile,%index = $1 *,%n
if ($1 == $null) || ($1 == *) { %index = * }
_openwins %win
filter -fw $"(%file) %win %index
%n = $line(%win,0)
close -@ %win
return %n
}
alias _notes.hourly {
var %win = @__notes.hourly,%i,%n,%file = $_noteinifile,%hnotes = 0,%handle,%oldhandle
if ($gettok($_notes.chexpire,2,32)) && ($_getsetup(script,notify-users)) {
_openwins %win
filter -fwt 1 32 $"(%file) %win *
%i = 1
%n = $line(%win,0)
while (%i <= %n) {
tokenize 32 $line(%win,%i)
if (%i == 1) { %oldhandle = $1 }
%handle = $1
if (%handle != %oldhandle) {
__notes.hourly.notify %oldhandle %hnotes
%hnotes = 0
}
inc %hnotes
%oldhandle = %handle
inc %i
}
__notes.hourly.notify %handle %hnotes
}
close -@ %win
}
; /__notes.hourly.notify handle #notes
alias __notes.hourly.notify {
var %handle = $1,%notes = $2,%nicks,%i,%n
if ($_partyline.isonline(%handle)) {
_partyline.msgtohandle %handle ### You have $_nsingoplur(%notes,note,notes) waiting.
_partyline.msgtohandle %handle ### Use '.notes read' to read them.
}
elseif ($_connected) {
%nicks = $gettok($_hand2nick(%handle,*,*),1-3,32)
%i = 1
%n = $numtok(%nicks,44)
while (%i <= %n) {
_notes.sendnotice %handle $gettok(%nicks,%i,44) %notes _h_
inc %i
}
}
}
; /_notes.sendnotice handle nick #notes j|h
alias _notes.sendnotice {
_puthelp $2 & _qnotice $2 You have $_nsingoplur($3,note,notes) waiting on $me $+ .
if ($_group(#_rctext)) { _puthelp $2 & _qnotice $2 For a list $+ $iif(j isin $4,$chr(44),:) /MSG $me NOTES [pass] INDEX }
elseif ($_group(#_rcctcp)) { _puthelp $2 & _qnotice $2 For a list $+ $iif(j isin $4,$chr(44),:) /CTCP $me NOTES [pass] INDEX }
}
alias _notes.noticeonjoinprot {
var %var = __NOTE. $+ $1
return $_flood2(15,%var)
}