I don't know if there is a limit or not. ... It is interesting.Football wrote:Both lines exist, they are pretty long though, maybe thats the problem?
Code: Select all
set phile [open $message_file "r"]
Code: Select all
if {$chan eq "#chan1"} {
set phile [open $message_file1 "r"]
} else {
set phile [open $message_file2 "r"]
}
Wouldn't that require that you know, before you write the script, the names of every channel that you might ever use it in?Football wrote:Like this?
if {$chan eq "#Football"} {
set phile [open $message_file1 "r"]
}
if {$chan eq "#Football2"} {
set phile [open $messages_file2 "r"]
else {
set phile [open $message_file3"r"]
}
Code: Select all
if {$chan eq "#Football"} {
set phile [open $message_file1]
} elseif {$chan eq "#Football2"} {
set phile [open $message_file2]
} else {
set phile [open $message_file3]
}
I may have found it. Thanks for pointing it out.Football wrote:Think I found an error...
From message #1 it jumped to #3, same from #3 to #5
...
Code: Select all
# August 4, 2010
# fixed : if {[botonchan $chan]} { putserv "privmsg $chan : [join [lindex [split $data \n] $line_counter]] "}
# ^^^^^^^^^^^^^^^^^^^^^ was not there and it is possible for bot to NOT be in a channel, that has +announcer set
#
# moved the section that increments the line counter in proc run_announce, as it looked like it was incrementing for each chan
# not just for each run of run_announce
# changed the determination of number of lines in file, in case NO channels have +announcer set
#
# added more binds and proc, so that commands may be sent via /msg
# Is now multi-chan, with seperate message files on a per-channel basis
###################
# August 3, 2010
# http://forum.egghelp.org/viewtopic.php?p=93728#93728
########################################################
#The public commands would be:
#!enable
#!disable
#!settimer
#!addmsg
#!delmsg
#!listmsg
#!timeron
#!timeroff
#!status
#!setline
#!enable - will enable the script in the current channel
#!disable - will disable the script in the current channel
#!status - will notify you whether the script is enabled or disabled
#!addmsg <message-here> and the bot will add it to his list
#!listmsg <number> - will list one message, from line #<number>
#!listmsg - will list all the messages that were added to the bot
#!delmsg <message-number> - will erase that specific message
#!settimer <number of minutes> - Every X minutes the bot will display the messages by order; #1 and then X minutes later #2 and so on
#!settimer will display the current setting.
#!timeroff Stops the timer for message display (timer is ON, when bot starts )
#!timeron Starts the timer for message display (without having to restart the bot)
#!setline <number> Manually set the line number of the next displayed line
#!setline will display current setting
### Same commands work, via /msg, but many must include #channel as first word of msg
#
# Example: /msg botnick !enable #channel
#
# ( !timeron , !timeroff, and !settimer via /msg do not require a #channel )
#
####################################
##### Config
# Set the path and directory name for the directory that will hold message files. Be sure to include the trailing forward slash.
set message_file_dir "scripts/"
# Set the default starting timer minutes.
# This is the time that will be used after a restart, until a !settimer command is used to change it.
set timer_minutes 2
##### End Config
########### script begins here
bind pub - "!addmsg" addmsg
bind pub - "!listmsg" listmsg
bind pub - "!delmsg" delmsg
bind pub - "!settimer" settimer
bind pub - "!enable" enable
bind pub - "!disable" disable
bind pub - "!status" status
bind pub - "!timeroff" timer_off
bind pub - "!timeron" timer_on
bind pub - "!setline" setline
bind msg o "!addmsg" msg_addmsg
bind msg o "!listmsg" msg_listmsg
bind msg o "!delmsg" msg_delmsg
bind msg o "!settimer" msg_settimer
bind msg o "!enable" msg_enable
bind msg o "!disable" msg_disable
bind msg o "!status" msg_status
bind msg o "!timeroff" msg_timer_off
bind msg o "!timeron" msg_timer_on
bind msg o "!setline" msg_setline
setudef flag announcer
## Check to see if script is loaded already, and if not, then start timer.
## The idea is to NOT start additional timers, after a rehash
if {![info exists timer_announcer_loaded]} {
set timer_announcer_loaded 1
timer $timer_minutes run_announce
}
## Sends one message to channel, every XX minutes, incrementing through stored messages.
proc run_announce {} {
global message_file_dir timer_minutes line_counter
foreach chan [channels] {
if {([lsearch -exact [channel info $chan] {+announcer}] != -1)} {
if {![info exists line_counter($chan)]} {
set line_counter($chan) 0
}
if {$line_counter($chan) < 0} {
set line_counter($chan) 0
}
if {![file exist $message_file_dir${chan}]} {
close [open $message_file_dir${chan} w]
}
set phile [open $message_file_dir${chan} "r"]
set data [read -nonewline $phile]
close $phile
#Check to see if the line number we are looking for, is greater than the actual number of lines in the message file
#and if so, instead have it go to the last line
if {[llength [split $data \n]]<=$line_counter($chan)} {
set line_counter($chan) [expr [llength [split $data \n]] - 1]
}
#Display the line
if {"[lindex [split $data \n] $line_counter($chan)]"!=""} {
if {[botonchan $chan]} { putserv "privmsg $chan : [join [lindex [split $data \n] $line_counter($chan)]] "}
incr line_counter($chan)
if {[llength [split $data \n]] <= $line_counter($chan)} {
set line_counter($chan) 0
}
}
}
}
# re-starts the timer, to run this proc again
timer $timer_minutes run_announce
}
## Allows line counter to be manually set
proc setline {nick uhost handle chan text} {
global line_counter
if {[string is integer -strict [join [lindex [split $text] 0]]]} {
set line_counter($chan) [expr [lindex [split $text] 0] -1]
putserv "notice $nick :Next line displayed in $chan will be line [expr $line_counter($chan) +1]"
} else {
putserv "notice $nick :Next line displayed in $chan will be line [expr $line_counter($chan) +1]"
}
}
#Via MSG - setline
proc msg_setline {nick uhost handle text} {
global botnick line_counter
if {"$text"==""} {
putserv "notice $nick :Syntax: /msg $botnick !setline #<channel> \[number\]"
putserv "notice $nick :\[number\] is optional. Without it, !setline will report only"
return 0
}
set chan [lindex [split $text] 0]
if {[validchan $chan]} {
if {[string is integer -strict [join [lindex [split $text] 1]]]} {
set line_counter($chan) [expr [lindex [split $text] 1] -1]
putserv "notice $nick :Next line displayed in $chan will be line [expr $line_counter($chan) +1]"
} else {
putserv "notice $nick :Next line displayed in $chan will be line [expr $line_counter($chan) +1]"
}
} else {
putserv "notice $nick :$chan is not a valid channel on $botnick"
}
}
##Allows timer delay to be changed via a pub command
proc settimer {nick uhost handle chan text} {
global timer_minutes
if {([lsearch -exact [channel info $chan] {+announcer}] != -1)} {
if {"[lindex [split $text] 0]"==""} {
putserv "notice $nick :Timer is set to $timer_minutes minutes"
} elseif {"[lindex [split $text] 0]"<="0"} {
putserv "notice $nick :No change. Timer must be set to a positive integer"
} else {
set timer_minutes "[lindex [split $text] 0]"
putserv "notice $nick :Timer will be set to $timer_minutes minutes"
}
}
}
# Via MSG - change timer delay
proc msg_settimer {nick uhost handle text} {
global timer_minutes
if {"[lindex [split $text] 0]"==""} {
putserv "notice $nick :Timer is set to $timer_minutes minutes"
} elseif {"[lindex [split $text] 0]"<="0"} {
putserv "notice $nick :No change. Timer must be set to a positive integer"
} else {
set timer_minutes "[lindex [split $text] 0]"
putserv "notice $nick :Timer will be set to $timer_minutes minutes"
}
}
##Allows timer to be turned off via a pub command
proc timer_off {nick uhost handle chan text} {
if {([lsearch -exact [channel info $chan] {+announcer}] != -1)} {
foreach thetimer [timers] {
if {[string match -nocase "run_announce*" [lindex $thetimer 1]]} {
# got a match
killtimer [lindex $thetimer 2]
putserv "notice $nick :Timed Announcer is off"
# killed the timerID which is the 3rd element of $thetimer.
break
# stopped since no need for further checks.
}
}
# credit: http://forum.egghelp.org/viewtopic.php?p=53896#53896
}
}
# Via MSG - timer off
proc msg_timer_off {nick uhost handle text} {
foreach thetimer [timers] {
if {[string match -nocase "run_announce*" [lindex $thetimer 1]]} {
# got a match
killtimer [lindex $thetimer 2]
putserv "notice $nick :Timed Announcer is off"
# killed the timerID which is the 3rd element of $thetimer.
break
# stopped since no need for further checks.
}
}
}
## Allows timer to be turned on via a pub command
proc timer_on {nick uhost handle chan text} {
if {([lsearch -exact [channel info $chan] {+announcer}] != -1)} {
if {"[timerexists run_announce]"==""} {
run_announce
putserv "notice $nick :Timed Announcer is on"
}
}
}
#Via MSG - timeron
proc msg_timer_on {nick uhost handle text} {
if {"[timerexists run_announce]"==""} {
run_announce
putserv "notice $nick :Timed Announcer is on"
}
}
## Used by other procedure, to find out if a timer already exists
proc timerexists {command} {
foreach i [timers] {
if {![string compare $command [lindex $i 1]]} then {
return [lindex $i 2]
}
}
return
#credit: from alltools.tcl
}
## Allows messages to be added via a pub command
proc addmsg {nick uhost handle chan text} {
global message_file_dir
if {([lsearch -exact [channel info $chan] {+announcer}] != -1)} {
if {"$text"==""} {
putserv "notice $nick :Syntax: !addmsg <message here..... >"
return 0
}
set phile [open $message_file_dir${chan} "r"]
set first_line [gets $phile]
close $phile
if {"$first_line"==""} {
set phile [open $message_file_dir${chan} "w"]
puts $phile "[lrange [split $text] 0 end]"
close $phile
} else {
set phile [open $message_file_dir${chan} "a"]
puts $phile "[lrange [split $text] 0 end]"
close $phile
}
putserv "notice $nick :Added: \"[join [lrange [split $text] 0 end]]\" "
}
}
# Via MSG - addmsg
proc msg_addmsg {nick uhost handle text} {
global botnick message_file_dir
set chan [lindex [split $text] 0]
if {"$text"==""} {
putserv "notice $nick :Syntax: /msg $botnick !addmsg #<channel> <message here..... >"
return 0
}
if {[validchan $chan]} {
set phile [open $message_file_dir${chan} "r"]
set first_line [gets $phile]
close $phile
if {"$first_line"==""} {
set phile [open $message_file_dir${chan} "w"]
puts $phile "[lrange [split $text] 1 end]"
close $phile
} else {
set phile [open $message_file_dir${chan} "a"]
puts $phile "[lrange [split $text] 1 end]"
close $phile
}
putserv "notice $nick :Added: \"[join [lrange [split $text] 1 end]]\" "
} else {
putserv "notice $nick :$chan is not a valid channel on $botnick"
}
}
## Will display all messages, in response to a pub command
proc listmsg {nick uhost handle chan text} {
global message_file_dir line_counter
if {([lsearch -exact [channel info $chan] {+announcer}] != -1)} {
#Display one message via notice, only if a number is given with !listmsg - if no number given, then list all messages
if {[string is integer -strict [join [lindex [split $text] 0]]]} {
set phile [open $message_file_dir${chan} "r"]
set data [read -nonewline $phile]
close $phile
if {[llength [split $data \n]]>=[lindex [split $text] 0]} {
putserv "notice $nick :[join [lindex [split $data \n] [expr [lindex [split $text] 0]-1]]]"
} else {
putserv "notice $nick :No such line"
}
return 0
}
set phile [open $message_file_dir${chan} "r"]
set first_line [gets $phile]
close $phile
if {"$first_line"==""} {
putserv "notice $nick : I got nothing"
return 0
}
set lnum 0
set phile [open $message_file_dir${chan} "r"]
while {[gets $phile line] >= 0} {
putserv "notice $nick :[incr lnum]: [join $line]"
}
close $phile
#credit: Luminous
}
}
# Via MSG - !listmsg
proc msg_listmsg {nick uhost handle text} {
global botnick message_file_dir line_counter
set chan [lindex [split $text] 0]
if {"$text"==""} {
putserv "notice $nick :Syntax: /msg $botnick !listmsg #<channel> \[#\]"
putserv "notice $nick :The number is optional. Without it, all messages are listed. Include it, and only that message is displayed"
return 0
}
if {[validchan $chan]} {
if {![file exists $message_file_dir${chan}]} {
putserv "notice $nick :No message file exists yet, for $chan"
putserv "notice $nick :The first time you use !enable to enable $chan, an empty message file will be created for $chan"
return 0
}
#Display one message via notice, only if a number is given with !listmsg - if no number given, then list all messages
if {[string is integer -strict [join [lindex [split $text] 1]]]} {
set phile [open $message_file_dir${chan} "r"]
set data [read -nonewline $phile]
close $phile
if {[llength [split $data \n]]>=[lindex [split $text] 1]} {
putserv "notice $nick :[join [lindex [split $data \n] [expr [lindex [split $text] 1]-1]]]"
} else {
putserv "notice $nick :No such line"
}
return 0
}
set phile [open $message_file_dir${chan} "r"]
set first_line [gets $phile]
close $phile
if {"$first_line"==""} {
putserv "notice $nick : I got nothing"
return 0
}
set lnum 0
set phile [open $message_file_dir${chan} "r"]
while {[gets $phile line] >= 0} {
putserv "notice $nick :[incr lnum]: [join $line]"
}
close $phile
#credit: Luminous
} else {
putserv "notice $nick :[lindex [split $text] 0] is not a valid channel on $botnick"
}
}
## Allows a message to be deleted (by message number, see !listmsg) via a pub command
proc delmsg {nick uhost handle chan text} {
global message_file_dir
if {([lsearch -exact [channel info $chan] {+announcer}] != -1)} {
if {"$text"==""} {
putserv "notice $nick :Syntax: !delmsg <number>"
putserv "notice $nick :Use !listmsg to get line numbers"
return 0
}
set del_line_num [expr [lindex [split $text] 0] - 1 ]
if {$del_line_num < 0} {
putserv "notice $nick :No can do. Must be 1 or greater."
return 0
}
set phile [open $message_file_dir${chan} r]
set data [read -nonewline $phile]
close $phile
set lines [split $data "\n"]
if {[llength $lines] <= $del_line_num} {
putserv "notice $nick :No such line number"
return 0
}
putserv "notice $nick :Deleting: [join [lindex $lines $del_line_num]]"
putserv "notice $nick : (use !listmsg again now, as you may have changed the line numbers!)"
set lines [lreplace $lines $del_line_num $del_line_num]
set phile [open $message_file_dir${chan} "w"]
puts $phile [join $lines "\n"]
close $phile
}
}
# Via MSG - delmsg
proc msg_delmsg {nick uhost handle text} {
global botnick message_file_dir
set chan [lindex [split $text] 0]
if {"$text"==""} {
putserv "notice $nick :Syntax: !delmsg #<channel> <number>"
putserv "notice $nick :Use !listmsg #<channel> to get line numbers"
return 0
}
if {[validchan $chan]} {
if {![file exists $message_file_dir${chan}]} {
putserv "notice $nick :No message file exists yet, for $chan"
putserv "notice $nick :The first time you use !enable to enable $chan, an empty message file will be created for $chan"
return 0
}
set del_line_num [expr [lindex [split $text] 1] - 1 ]
if {$del_line_num < 0} {
putserv "notice $nick :No can do. Must be 1 or greater."
return 0
}
set phile [open $message_file_dir${chan} r]
set data [read -nonewline $phile]
close $phile
set lines [split $data "\n"]
if {[llength $lines] <= $del_line_num} {
putserv "notice $nick :No such line number"
return 0
}
putserv "notice $nick :Deleting: [join [lindex $lines $del_line_num]]"
putserv "notice $nick : (use !listmsg again now, as you may have changed the line numbers!)"
set lines [lreplace $lines $del_line_num $del_line_num]
set phile [open $message_file_dir${chan} "w"]
puts $phile [join $lines "\n"]
close $phile
} else {
putserv "notice $nick :$chan is not a valid channel on $botnick"
}
}
## Will enable timed messages announcements in the channel where the pub command is sent
proc enable {nick uhost handle chan text} {
global message_file_dir
channel set $chan +announcer
if {([lsearch -exact [channel info $chan] {+announcer}] != -1)} {
putserv "notice $nick :Timed Announcer enabled on $chan"
if {![file exist $message_file_dir${chan}]} {
close [open $message_file_dir${chan} w]
}
}
}
# Via MSG - will enable timed message announcements in a channel
proc msg_enable {nick uhost handle text} {
global botnick
if {"[lindex [split $text] 0]"==""} {
putserv "notice $nick :Syntax: /msg $botnick !enable #<channel>"
return 0
}
if {[validchan [lindex [split $text] 0]]} {
enable $nick $uhost $handle [lindex [split $text] 0] -fillerFortext-
} else {
putserv "notice $nick :[lindex [split $text] 0] is not a valid channel on $botnick"
}
}
## Will disable timed message announcements in the channel where the pub command is sent
proc disable {nick uhost handle chan text} {
if {([lsearch -exact [channel info $chan] {+announcer}] != -1)} {
channel set $chan -announcer
}
if {([lsearch -exact [channel info $chan] {-announcer}] != -1)} {
putserv "notice $nick :Timed Announcer disabled on $chan"
}
}
# Via MSG - will disable timed message announcements in a channel
proc msg_disable {nick uhost handle text} {
global botnick
if {"[lindex [split $text] 0]"==""} {
putserv "notice $nick :Syntax: /msg $botnick !disnable #<channel>"
return 0
}
if {[validchan [lindex [split $text] 0]]} {
disable $nick $uhost $handle [lindex [split $text] 0] -fillerFortext-
} else {
putserv "notice $nick :[lindex [split $text] 0] is not a valid channel on $botnick"
}
}
## Send the status (enabled or disabled) to the channel where the pub command is given
proc status {nick uhost handle chan text} {
set time_left 0
foreach thetimer [timers] {
if {[string match -nocase "run_announce*" [lindex $thetimer 1]]} {
set time_left [lindex $thetimer 0]
}
}
if {([lsearch -exact [channel info $chan] {+announcer}] != -1)} {
putserv "notice $nick :Announcer is enabled in $chan."
if {$time_left} {putserv "notice $nick :Timer is running with $time_left minutes or less to go"}
if !{$time_left} {putserv "notice $nick :Timer is not running"}
} else {
putserv "notice $nick :Timed Announcer is disabled in $chan"
if {$time_left} {putserv "notice $nick :Timer is running with $time_left or less to go"}
if !{$time_left} {putserv "notice $nick :Timer is not running"}
}
}
# Via MSG - status
proc msg_status {nick uhost handle text} {
global botnick
if {"[lindex [split $text] 0]"==""} {
putserv "notice $nick :Syntax: /msg $botnick !status #<channel>"
return 0
}
if {[validchan [lindex [split $text] 0]]} {
set time_left 0
foreach thetimer [timers] {
if {[string match -nocase "run_announce*" [lindex $thetimer 1]]} {
set time_left [lindex $thetimer 0]
}
}
if {([lsearch -exact [channel info [lindex [split $text] 0]] {+announcer}] != -1)} {
putserv "notice $nick :Announcer is enabled in [lindex [split $text] 0]."
if {$time_left} {putserv "notice $nick :Timer is running with $time_left minutes or less to go"}
if !{$time_left} {putserv "notice $nick :Timer is not running"}
} else {
putserv "notice $nick :Timed Announcer is disabled in [lindex [split $text] 0]"
if {$time_left} {putserv "notice $nick :Timer is running with $time_left or less to go"}
if !{$time_left} {putserv "notice $nick :Timer is not running"}
}
} else {putserv "notice $nick :[lindex [split $text] 0] is not a valid chan on $botnick"
}
}
putlog "Loaded Timed Announcer :) See: http://forum.egghelp.org/viewtopic.php?p=93728#93728 "
## Much credit goes to posters on the forum at http://forum.egghelp.org/
## Bits and pieces, and ideas used above - were borrowed from there.
## To anyone not specifically mentioned, I apologize.
## Any errors, broken code, poor code, or other strange things, are not theirs. They are mine.
It appears that something is calling "proc:laina", whatever that is.Football wrote:Hey willyw, thanks for the hard work and reply again!
[11:31:01] <EPL> [08:31] Tcl error [proc:laina]: invalid command name "PRIVMSG #EPL-Staff :<Xabriel!Boca@MeSCh.users.quakenet.org>:
Neither am I.
!addmsg #EPL NEW #EPL Addon Uploaded! Date Release: July 20th. http://tinyurl.com/2wzoukk"
Not sure what the error is about...
I could have put in a check, in every command - yes.
[11:29:34] <EPL> [08:29] Tcl error [listmsg]: couldn't open "scripts/messages/#EPL": no such file or directory
Shouldn't it create the file when you try one of the commands?
[11:29:34] <EPL> [08:29] Tcl error [listmsg]: couldn't open "scripts/messages/#EPL": no such file or directory
Because that is what I named it.Why is it #EPL and not #EPL.txt ?
Do us a favor, please:Football wrote: ...
[11:29:34] <EPL> [08:29] Tcl error [listmsg]: couldn't open "scripts/messages/#EPL": no such file or directory
Shouldn't it create the file when you try one of the commands?
[11:29:34] <EPL> [08:29] Tcl error [listmsg]: couldn't open "scripts/messages/#EPL": no such file or directory
...