!alarm

Moderator: bruhv

Post Reply
bruhv
Site Admin
Site Admin
Posts: 59
Joined: Thu Jun 08, 2006 11:55 am
Location: Afghanistan
Contact:

!alarm

Post by bruhv »

an irc alarm clock, oh yes, lol

use !alarm [time_in_minutes] message
after [time_in_minutes] channel or private message alarm happens
if channel is -c then colours get stripped
tracks nick changes

probably doesn't cope well if alarm setter leaves channel then comes back under a different nick, untested

Code: Select all

##########################
#   alarm.tcl by bruhv   #
# scripts@bruhv-ahh.org  #
##########################

##########################
# v1.1                   #
# added: +alarm chanflag #
# added: public alarm!!! #
# pub and msg alarms now #
# can now coexist        #
# added: swear filter :x #
# added: only person who #
# sets alarm may delete  #
# or overwrite current   #
##########################

##########################
#     set swearwords     #
##########################
set cursewords "fuck cunt wank cock shit"

setudef flag alarm

bind pub - !alarm pub:set:alarm
bind pub - !forget pub:del:alarm
bind pub - !newalarm pub:set:newalarm
bind pub - !alarm? pub:check:alarm

bind msg - alarm msg:set:alarm
bind msg - forget msg:del:alarm
bind msg - newalarm msg:set:newalarm
bind msg - alarm? msg:check:alarm

bind NICK - * nick:check

###############################
#      message alarm proc     #
###############################

proc msg:set:alarm {nick uhost hand text} {
	global msgwho msginfo msgwhen botnick
	if {[info exists msgwhen]} {
		putserv "notice $nick :$msgwhen minute alarm currently set ($msgwho) (\002/msg $botnick newalarm\002 to overwrite)" -next
		return 0
	}
	set alarm_mins [lindex [split $text] 0]
	if {![isnumber $alarm_mins]} {
		putserv "notice $nick :\002\[minutes\]\002 must be set (/msg $botnick alarm \002\[minutes\]\002 \[message\])" -next
		return 0
	}
	set alarm_msg [join [lrange [split $text] 1 end]]
	if {$alarm_msg == ""} {
		putserv "notice $nick :\002\[message\]\002 must be set (/msg $botnick alarm \[minutes\] \002\[message\]\002)" -next
		return 0
	}
	set msgwhen [lindex [split $text] 0]
	set msginfo [join [lrange [split $text] 1 end]]
	set msgwho $nick
	if {$msgwhen == 1} {
		puthelp "notice $nick :ok, I will call you in \002$msgwhen\002 minute" -next
		putlog "$nick set a reminder of $msginfo for $msgwhen minute"
	} else {
		puthelp "notice $nick :ok, I will call you in \002$msgwhen\002 minutes" -next
		putlog "$nick set a reminder of $msginfo for $msgwhen minutes"
	}
	if {$msgwhen > 10} {
		timer $msgwhen [list msg:alarm]
	return 0
	}
utimer [expr ($msgwhen * 60)] [list msg:alarm]
}

proc msg:set:newalarm {nick uhost hand text} {
	global msgwho msginfo msgwhen botnick
	if {![info exists msgwho]} {
		putserv "notice $nick :no alarms active" -next
		return 0
		}
	if {$msgwho != $nick} {
		putserv "notice $nick :you cannot overwrite $msgwho's alarm" -next
		return 0
	}
	if {$msgwho == $nick} {
		set alarm_mins [lindex [split $text] 0]
		if {![isnumber $alarm_mins]} {
			putserv "notice $nick :\002\[minutes\]\002 must be set (/msg $botnick newalarm \002\[minutes\]\002 \[message\])" -next
			return 0
		}
		set alarm_msg [join [lrange [split $text] 1 end]]
		if {$alarm_msg == ""} {
			putserv "notice $nick :\002\[message\]\002 must be set (/msg $botnick newalarm \[minutes\] \002\[message\]\002)" -next
			return 0
		}
		putserv "notice $nick :overwriting your current $msgwhen minute alarm" -next
		if {[set theutimer [utimerexists msg:alarm]]!=""} {killutimer $theutimer}
		if {[set thetimer [timerexists msg:alarm]]!=""} {killtimer $thetimer}
		set msgwhen [lindex [split $text] 0]
		set msginfo [join [lrange [split $text] 1 end]]
		set msgwho $nick
		if {$msgwhen == 1} {
			puthelp "notice $nick :ok, I will call you in \002$msgwhen\002 minute" -next
			putlog "$nick set a reminder of $msginfo for $msgwhen minute"
		} else {
			puthelp "notice $nick :ok, I will call you in \002$msgwhen\002 minutes" -next
			putlog "$nick set a reminder of $msginfo for $msgwhen minutes"
		}
		if {$msgwhen > 10} {
			timer $msgwhen [list msg:alarm]
			return 0
		}
	utimer [expr ($msgwhen * 60)] [list msg:alarm]
	}
}

proc msg:check:alarm {nick uhost hand text} {
	global msgwho msginfo msgwhen
	if {[info exists msgwhen]} {
		putserv "notice $nick :$msgwhen minute alarm currently set ($msgwho)" -next
	} else {
		putserv "notice $nick :no active alarm" -next
	}
}

proc msg:del:alarm {nick uhost hand text} {
	global msgwho msginfo msgwhen
	if {![info exists msgwho]} {
		putserv "notice $nick :no active alarm" -next
		return 0
	}
	if {$msgwho != $nick} {return}
	if {[set theutimer [utimerexists msg:alarm]]!=""} {killutimer $theutimer}
	if {[set thetimer [timerexists msg:alarm]]!=""} {killtimer $thetimer}
	putserv "notice $nick :your alarm has been forgotten"
	unset msgwho
	unset msginfo
	unset msgwhen
}

proc msg:alarm {} {
	global msgwho msginfo msgwhen
	set msginfo "\00302\002\[\]\002\00305\002\[\]\002\003\00302\002\[\]\002\003\00305\002\[\]\002\003\00302\002\[\]\002\003 \00305\002$msginfo\002\003 \00302\002\[\]\002\00305\002\[\]\002\003\00302\002\[\]\002\003\00305\002\[\]\002\003\00302\002\[\]\002\003"
	set msgwhomsg "\00302\002(\002\003\00305=\003\00302\002$msgwho\002\003\00305=\003\00302\002)\002\003"
	putserv "notice  $msgwho :$msgwhomsg $msginfo $msgwhomsg"
	utimer 4 [list putserv "notice  $msgwho :$msgwhomsg $msginfo $msgwhomsg"]
	utimer 8 [list putserv "notice  $msgwho :$msgwhomsg $msginfo $msgwhomsg"]
	utimer 12 [list putserv "notice  $msgwho :$msgwhomsg $msginfo $msgwhomsg"]
	unset msgwho
	unset msginfo
	unset msgwhen
}

###############################
#      public alarm proc      #
###############################

proc pub:set:alarm {nick uhost hand chan text} {
	global who info when alarmchannel cursewords
	if {![ischanflag $chan "+alarm"]} {return 0}
	set alarmchannel $chan
	if {[info exists who]} {
		putserv "privmsg $alarmchannel :$when minute alarm currently set ($who) ($alarmchannel) (\002.newalarm\002 to overwrite)" -next
		return 0
	}
	set alarm_mins [lindex [split $text] 0]
	if {![isnumber $alarm_mins]} {
		putserv "privmsg $alarmchannel :\002\[minutes\]\002 must be set (.alarm \002\[minutes\]\002 \[message\])" -next
		return 0
	}
	set alarm_msg [join [lrange [split $text] 1 end]]
	if {$alarm_msg == ""} {
		putserv "privmsg $alarmchannel :\002\[message\]\002 must be set (.alarm \[minutes\] \002\[message\]\002)" -next
		return 0
	}
	set when [lindex [split $text] 0]
	set info [join [lrange [split $text] 1 end]]
	set who $nick
	if {$when == "1"} {
		puthelp "privmsg $chan :ok, I will call you in \002$when\002 minute" -next
		putlog "$nick set a reminder of $info for $when minute ($alarmchannel)"
	} else {
		puthelp "privmsg $chan :ok, I will call you in \002$when\002 minutes" -next
		putlog "$nick set a reminder of $info for $when minutes ($alarmchannel)"
	}
	if {$when > 10} {
		timer $when pub:alarm
	return 0
	}
utimer [expr ($when * 60)] [list pub:alarm]
}

proc pub:set:newalarm {nick uhost hand chan text} {
	global who info when alarmchannel cursewords
	if {![ischanflag $chan "+alarm"]} {return 0}
	set alarmchannel $chan
	if {![info exists who] == 1} {
		putserv "privmsg $chan :no active alarm" -next
		return 0
	}
	if {$who != $nick} {
		putserv "privmsg $chan :$nick, you cannot overwrite $who's alarm" -next
		return 0
	}
	if {$who == $nick} {
		set alarm_mins [lindex [split $text] 0]
		if {![isnumber $alarm_mins]} {
			putserv "privmsg $chan :\002\[minutes\]\002 must be set (.newalarm \002\[minutes\]\002 \[message\])" -next
			return 0
		}
		set alarm_msg [join [lrange [split $text] 1 end]]
		if {$alarm_msg == ""} {
			putserv "privmsg $chan :\002\[message\]\002 must be set (.newalarm \[minutes\] \002\[message\]\002)" -next
			return 0
		}
		putserv "privmsg $chan :overwriting your current $when minute alarm" -next
		if {[set theutimer [utimerexists pub:alarm]]!=""} {killutimer $theutimer}
		if {[set thetimer [timerexists pub:alarm]]!=""} {killtimer $thetimer}
		set when [lindex [split $text] 0]
		set info [join [lrange [split $text] 1 end]]
		set who $nick
		if {$when == "1"} {
			puthelp "privmsg $chan :ok, I will call you in \002$when\002 minute" -next
			putlog "$nick set a reminder of $info for $when minute ($alarmchannel)"
		} else {
			puthelp "privmsg $chan :ok, I will call you in \002$when\002 minutes" -next
			putlog "$nick set a reminder of $info for $when minutes ($alarmchannel)"
		}	
		if {$when > 10} {
			timer $when pub:alarm
		return 0
		}
	utimer [expr ($when * 60)] [list pub:alarm]
	}
}

proc pub:check:alarm {nick uhost hand chan text} {
	global who info when alarmchannel
	if {[ischanflag $chan "+alarm"]} {
		if {[info exists when]} {
			putserv "privmsg $chan :$when minute alarm currently set ($who) ($alarmchannel)" -next
		} else {
			putserv "privmsg $chan :no active alarms" -next
		}
	}
}

proc pub:del:alarm {nick uhost hand chan text} {
	global who info when alarmchannel
	if {[ischanflag $chan "+alarm"]} {
		if {![info exists who]} {
		putserv "notice $nick :no active alarm"
		return 0
	}
		if {$who == $nick} {
			if {[set theutimer [utimerexists pub:alarm]]!=""} {killutimer $theutimer}
			if {[set thetimer [timerexists pub:alarm]]!=""} {killtimer $thetimer}
			putserv "privmsg $chan :your alarm has been forgotten" -next
			unset who
			unset info
			unset when
		}
	}
}

proc pub:alarm {} {
	global who info when alarmchannel cursewords
	set info "\00302\002\[\]\002\00305\002\[\]\002\003\00302\002\[\]\002\003\00305\002\[\]\002\003\00302\002\[\]\002\003 \00305\002$info\002\003 \00302\002\[\]\002\00305\002\[\]\002\003\00302\002\[\]\002\003\00305\002\[\]\002\003\00302\002\[\]\002\003"
	set who "\00302\002(\002\003\00305=\003\00302\002$who\002\003\00305=\003\00302\002)\002\003"
	if {[regexp -- {c} [getchanmode $alarmchannel]]} {
		set info [stripcodes c $info]
	}
	if {[regexp -- {c} [getchanmode $alarmchannel]]} {
		set who [stripcodes c $who]
	}
	foreach fword $cursewords {
		regsub -nocase -all  $fword $info "~@#$#/$-" info
	}
	putserv "privmsg  $alarmchannel :$who $info $who" -next
	utimer 4 [list putserv "privmsg  $alarmchannel :$who $info $who" -next]
	utimer 8 [list putserv "privmsg  $alarmchannel :$who $info $who" -next]
	utimer 12 [list putserv "privmsg  $alarmchannel :$who $info $who" -next]
	unset who
	unset info
	unset when
}

###############################
#     nick tracking proc      #
###############################
proc nick:check {nick uhost hand chan text} {
	global who
	if {[info exists who]} {	
		if {[string compare $who $nick] == 0} {
			putlog "tracking nick: $who --> $text"
			set who $text
		}
	}
}

proc ischanflag {chan flag} {
	foreach f [channel info $chan] {
		if {$f == $flag} {
			return 1
		}
	}
	return 0
}

putlog "* alarm.tcl loaded."

########
# 2006 #
########
:bruhv:
Image
drug free since 11:28pm 26/3/06 :D

www.robnicklin.com

You're so fucking special, I wish I was special
Post Reply