Code: Select all
namespace eval cronPlay {
set play(info) ""
bind pub * !play [namespace current]::create
proc create {nick uhost hand chan text} {
variable play
if {[scan $text {%[^:]:%s%s%s} hour minute file channel] != 4} {
puthelp "NOTICE $nick :Usage: !play <hour:minute> <file> <#channel>"
return
}
if {![regexp {^[0-9]+$} $hour] || ![regexp {^[0-9]+$} $minute]} {
puthelp "NOTICE $nick :Error, the hour or minute aren't valid."
return
}
if {![file exists $file]} {
puthelp "NOTICE $nick :Error, $file file doesn't exist."
return
}
if {![validchan $channel]} {
puthelp "NOTICE $nick :Error, $channel channel is not valid."
return
}
set play(info) "$file $channel"
bind cron - "$minute $hour * * *" [namespace current]::play
puthelp "PRIVMSG $chan :I will play $file to $channel at $hour:$minute"
}
proc play {minute hour day month weekday} {
variable play
if {[catch {unbind cron - "$minute $hour * * *" [namespace current]::play} err]} {
putlog "Error in cronPlay: $err"
}
if {[scan $play(info) {%s%s} file channel] != 2} return
if {![file exists $file]} return
set fo [open $file]
set lines [split [read -nonewline $fo] \n]
close $fo
if {![llength $lines]} return
if {[botisop $channel]} {
puthelp "MODE $channel +m"
foreach line $lines {
puthelp "PRIVMSG $channel :$line"
}
puthelp "MODE $channel -m"
}
}
}
putlog "cronPlay.tcl loaded.."
Code: Select all
if {[validchan $channel]} {
Code: Select all
if {![validchan $channel]} {
Code: Select all
pushmode $channel +m
foreach line $lines {
puthelp "PRIVMSG $channel :$line"
}
pushmode $channel -m
Code: Select all
pushmode $channel +m
flushmode $channel
foreach line $lines {
puthelp "PRIVMSG $channel :$line"
}
pushmode $channel -m
flushmode $channel
The code as it is right now, the bot will play the file (only if it file exists and isn't empty) at the time you wanted if the bot has op on the channel.[08:13] <caesar> !play 08:14 preview.txt #channel
[08:13] <@bot> I will play preview.txt to #channel at 08:14
[08:14] * bot sets mode: +m
[08:14] <@bot> line 1
[08:14] <@bot> line 2
[08:14] <@bot> line 3
[08:14] * bot sets mode: -m
Code: Select all
if {![regexp {^[0-9]+$} $hour] || ![regexp {^[0-9]+$} $minute]} {
puthelp "NOTICE $nick :Error, the hour or minute aren't valid."
return
}
Code: Select all
if {![regexp {^[0-9]+$} $hour] || ![regexp {^[0-9]+$} $minute]} {
puthelp "NOTICE $nick :Error, the hour or minute aren't valid."
return
} else {
scan $hour %d hour
scan $minute %d minute
}
Code: Select all
if {[catch {unbind cron - "$minute $hour * * *" [namespace current]::play} err]} {
Code: Select all
scan $minute %d minute
scan $hour %d hour
Code: Select all
namespace eval cronPlay {
bind pub * !play [namespace current]::create
proc create {nick uhost hand chan text} {
variable play
if {[scan $text {%[^:]:%s%s%s} hour minute file channel] != 4} {
puthelp "NOTICE $nick :Usage: !play <hour:minute> <file> <#channel>"
return
}
if {![regexp {^[0-9]+$} $hour] || ![regexp {^[0-9]+$} $minute]} {
puthelp "NOTICE $nick :Error, the hour or minute aren't valid."
return
}
if {![file exists $file]} {
puthelp "NOTICE $nick :Error, $file file doesn't exist."
return
}
switch -- [catch {botisop $channel} err] {
"0" {
if {!$err} {
puthelp "NOTICE $nick :I won't be able to play the $file file in $channel channel if I'm not oped."
return
}
}
"1" {
puthelp "NOTICE $nick :Error, $channel channel is not valid."
return
}
}
set play(info) "$file $channel"
scan $hour %d hour
scan $minute %d minute
bind cron - "$minute $hour * * *" [namespace current]::play
puthelp "PRIVMSG $chan :I will play $file to $channel at $hour:$minute"
}
proc play {minute hour day month weekday} {
variable play
scan $minute %d minute
scan $hour %d hour
if {[catch {unbind cron - "$minute $hour * * *" [namespace current]::play} err]} {
putlog "Error in cronPlay: $err"
}
if {[scan $play(info) {%s%s} file channel] != 2} return
if {![file exists $file]} return
set fo [open $file]
set lines [split [read -nonewline $fo] \n]
close $fo
if {![llength $lines]} return
if {![catch {botisop $channel} err] && $err eq 1} {
puthelp "MODE $channel +m"
foreach line $lines {
puthelp "PRIVMSG $channel :$line"
}
puthelp "MODE $channel -m"
}
}
}
putlog "cronPlay.tcl loaded.."