Script has not been tested, try it out and see what we have.
Some notes on this script:
This script only keeps a data file so it can retain all its current data through an Eggdrop start/restart.
Do Not edit this file except through the public !reportbot and private message !reportdel commands!
All script data is always stored and kept current in the global array variable reBot(-data). That variable is a tcl list, and each element of that list is a tcl list with 6 elements like this...
{unixtime nick uhost handle channel reporttext}
The script currently has just 3 commands:
1) Public command: !reportbot <something to report> :available to all channel users.
2) Private message command: !reportlist :available to all global owners, masters, and operators.
Use this command to see all current reports.
Use the report numbers from this list for the !reportdel command.
3) Private message command: !reportdel <report number(s) to delete> :available to all global owners, masters, and operators.
Use this command to delete reports that are closed out.
Use the report numbers from the current !reportlist command reply.
IMPORTANT: After a successful !reportdel command, all/some reports may be renumbered to reflect their now current numbering!!!
Make sure to get the current report numbering with the !reportlist command before doing another !reportdel command!!!
Code: Select all
########################### ReportBot Version 0.1 ###########################
# author: SpiKe^^ #
# e-mail: spike<at>mytclscripts<dot>com #
# webpage: http://mytclscripts.com/ #
# This file is Copyrighted under the GNU Public License. #
# http://www.gnu.org/copyleft/gpl.html #
# Note: this script requires tcl 8.5 or higher! #
# Note: this script requires alltools.tcl! #
########################### General Script Settings ###########################
# Set the channel(s) for this script to run in.
# Ex. set reBot(chan) {#yourchannel}
# Ex. set reBot(chan) {#yourchannel #anotherchannel #someotherchan}
set reBot(chan) {#yourchannel}
# Set the file name or /fullRoute/fileName of the script data file.
# Ex. set reBot(file) {reBot_data.txt}
# Ex. set reBot(file) {/usr/home/spike/eggdrop/scripts/reBot_data.txt}
set reBot(file) {reBot_data.txt}
# Should this script message the perm owner(s) when a new report is received?
# 0 = no, do not message the owner(s)
# 1 = yes, message the owner(s) if they are online
set reBot(msgOwner) 1
############################ END OF SCRIPT SETINGS ############################
## edit command access flags and triggers here ##
bind pub -|- !reportbot reportBot:add
bind msg mno !reportlist reportBot:list
bind msg mno !reportdel reportBot:del
# END edit command access flags & triggers here #
set reBot(chan) [split $reBot(chan)]
proc reportBot:add {nick uhost hand chan text} {
global reBot owner
if {[lsearch -exact -nocase $reBot(chan) $chan] == -1} { return 0 }
set text [string trim $text]
if {$text eq ""} {
putnotc $nick "Correct syntax is: !reportbot <something to report>"
putnotc $nick "Example: !reportbot The bot is no longer opping me."
return 0
}
if {![string match {[.!?]} [stridx $text end]]} { append text "." }
lappend reBot(-data) [list [unixtime] $nick $uhost $hand $chan $text]
reportBot:writeFile
putnotc $nick "Your report has been received. Thanks for participating."
if {$reBot(msgOwner) == 1} {
set msg "\[ReportBot\] New report received from $nick $uhost"
if {[llength $reBot(chan)] > 1} { append msg " on $chan" }
foreach hnd [split $owner ", "] {
if {$hnd eq ""} { continue }
if {[handonchan $hnd] && [matchattr $hnd n]} {
putmsg [hand2nick $hnd] "$msg \"$text\""
}
}
}
return 0
}
proc reportBot:list {nick uhost hand text} {
global reBot
if {![llength $reBot(-data)]} {
putmsg $nick "Report list is currently empty."
} else {
set cnt 0
foreach item $reBot(-data) {
incr cnt
foreach {ut nk uh hn ch tx} $item { break }
set date [strftime %m/%d/%Y $ut]
if {[llength $reBot(chan)] == 1} { set ch ""
} else { set ch " on $ch" }
putmsg $nick "\[$cnt\] $nk $uh$ch Report: $tx Date: $date"
}
}
return 0
}
proc reportBot:del {nick uhost hand text} {
global reBot
set text [split [string trim $text]]
if {![string is digit -strict [lindex $text 0]]} {
putmsg $nick "Correct syntax is: !reportdel <report number(s) to delete>"
putmsg $nick "Example: !reportdel 3"
putmsg $nick "Example: !reportdel 1 3 4"
if {[llength $reBot(-data)]} { return 0 }
}
if {![llength $reBot(-data)]} {
putmsg $nick "Report list is currently empty."
} else {
set del "" ; set err ""
foreach item $text {
if {$item eq ""} { continue }
if {[string is digit $item] && $item <= [llength $reBot(-data)]} {
lappend del $item
} else { set err $item ; break }
}
if {[llength $del]} {
set cnt 0
set newdata ""
foreach item $reBot(-data) {
incr cnt
if {[lsearch $del $cnt] == -1} { lappend newdata $item ; continue }
foreach {ut nk uh hn ch tx} $item { break }
putmsg $nick "Deleted report #$cnt: $nk $uh \"$tx\""
}
set reBot(-data) $newdata
reportBot:writeFile
}
if {$err ne ""} {
if {[string is digit $err]} {
putmsg $nick "ReportBot Error: Report #$err does not exist!"
putmsg $nick "Use: !reportlist :for a list of all current reports."
} else {
putmsg $nick "ReportBot Error: Invalid !reportdel command option: $err"
putmsg $nick "Use: !reportdel :for correct syntax to delete reports."
}
}
}
return 0
}
# set global reBot(-data) variable to match script data file #
proc reportBot:readFile {} {
global reBot
if {![file exists $reBot(file)]} {
set reBot(-data) ""
} else {
set id [open $reBot(file)]
set data [read -nonewline $id]
close $id
set reBot(-data) [split $data \n]
}
}
# set global reBot(-data) variable at script load #
reportBot:readFile
# write script data file to match global reBot(-data) variable #
proc reportBot:writeFile {} {
global reBot
if {![llength $reBot(-data)]} {
file delete $reBot(file)
} else {
set id [open $reBot(file) w]
foreach item $reBot(-data) {
puts $id $item
}
close $id
}
}
putlog "ReportBot Ver 0.1 by SpiKe^^ loaded."