Code: Select all
bind msg mno .formatfile format:file
proc format:file {nick uhost hand arg} {
set oldfilename "scripts/old.file"
set newfilename "scripts/new.file"
set openold [open $oldfilename r]
set opennew [open $newfilename w]
while {![eof $openold]} {
lassign [split [gets $openold] "*"] ques answ
if {$ques eq "" || $answ eq ""} { continue }
puts $opennew "${answ}|$ques"
}
close $openold
close $opennew
}
Code: Select all
### Trivia Question File Format Converter ***
# formatfile.tcl v0.1 by SpiKe^^ (1Dec2021) *
# This script will convert trivia files from Q*A to A|Q #
# Also convert Q*A1*A2*A3 to A1|Q (uses first answer) #
# Also adds a ? to the end of questions, if has none #
# Also removes any kaos and scramble questions #
# load this script to the eggdrop bot.
# rename the source file to old.file & put in scripts/ dir.
# private message the bot with .formatfile
bind msg mno .formatfile format:file
proc format:file {nick uhost hand arg} {
set oldfilename "scripts/old.file"
set newfilename "scripts/new.file"
if {![file exists $oldfilename]} {
putserv "PRIVMSG $nick :Error: File not found: $oldfilename"
return 0
}
set openold [open $oldfilename r]
set opennew [open $newfilename w]
set cnt 0
while {![eof $openold]} {
lassign [split [gets $openold] "*"] ques answ
set ques [string trim $ques]
set answ [string trim $answ]
if {$ques eq "" || $answ eq ""} { continue }
if {[string match -nocase "kaos:*" $ques]} { continue }
if {[regexp -nocase {^(scramble|uword)$} $ques]} { continue }
if {![string match {*[.?]} $ques]} { append ques "?" }
incr cnt
puts $opennew "${answ}|$ques"
}
close $openold
close $opennew
if {$cnt == 0} { file delete $newfilename
putserv "PRIVMSG $nick :Error: No valid questions found in $oldfilename"
} else {
putserv "PRIVMSG $nick :Saved $cnt reformatted questions to $newfilename"
}
return 0
}
putlog "formatfile.tcl ver 0.1 by SpiKe^^ Loaded."
Code: Select all
### Trivia Question File Format Converter 2 ###
# formatfile2.tcl v0.3 by SpiKe^^ (7Dec2021) #
### Public command: .format2 :will convert trivia files from...
#
# 1. Question: What year did Disneyland open?
# Answer: 1955.
#
# ...to something more like:
# 1955|What year did Disneyland open?
### You can also specify a Question Category for the current file.
# Public command: .format2 Disney Trivia :will convert to...
#
# 1955|Disney Trivia: What year did Disneyland open?
# Script will also add a ? to the end of questions, if has none #
### load this script to the eggdrop bot.
### rename the source file to old.file & put in scripts/ dir.
### private message the bot with .format2 |or| .format2 Category-Name
bind msg mno .format2 format:file2
proc format:file2 {nick uhost hand arg} {
set oldfilename "scripts/old.file"
set newfilename "scripts/new.file"
if {![file exists $oldfilename]} {
putserv "PRIVMSG $nick :Error: File not found: $oldfilename"
return 0
}
set arg [string trim $arg]
if {$arg ne ""} {
if {![string match "*:" $arg]} { append arg ":" }
append arg " "
}
set openold [open $oldfilename r]
set opennew [open $newfilename w]
set cnt 0
set ques "" ; set answ ""
while {![eof $openold]} {
set line [string trim [gets $openold]]
if {$line eq ""} { continue }
if {$ques eq ""} {
if {![string match -nocase "answer: *" $line]} { set ques $line }
continue
}
if {[lsearch -nocase [lrange [split $line] 0 1] "question:"] > -1} {
set ques $line ; continue
}
set answ $line
set x [lsearch -nocase [lrange [split $ques] 0 1] "question:"]
if {$x > -1} {
regexp -nocase {question:(.*?)$} $ques - ques
set ques [string trim $ques]
}
if {[string tolower [lindex [split $answ] 0]] eq "answer:"} {
regexp -nocase {answer:(.*?)$} $answ - answ
set answ [string trim $answ ". "]
}
if {$ques ne "" && $answ ne ""} { incr cnt
if {![string match {*[.?]} $ques]} { append ques "?" }
puts $opennew "${answ}|${arg}$ques"
}
set ques "" ; set answ ""
}
close $openold
close $opennew
if {$cnt == 0} { file delete $newfilename
putserv "PRIVMSG $nick :Error: No valid questions found in $oldfilename"
} else {
putserv "PRIVMSG $nick :Saved $cnt reformatted questions to $newfilename"
}
return 0
}
putlog "formatfile2.tcl ver 0.3 by SpiKe^^ Loaded."