This is the new home of the egghelp.org community forum.
All data has been migrated (including user logins/passwords) to a new phpBB version.


For more information, see this announcement post. Click the X in the top right-corner of this box to dismiss this message.

Basic script, writing info to file

Help for those learning Tcl or writing their own scripts.
Post Reply
N
Nara
Halfop
Posts: 40
Joined: Sun Jul 23, 2006 11:12 pm

Basic script, writing info to file

Post by Nara »

Code: Select all

proc battle:flagsong { nick host hand chan text } {
	global head tail delim dj
	set chan [string tolower $chan]
	if !{ [channel get $chan advertonly] } {
		if !{ [string equal $text ""] } {
		putlog "\002Radio:\002 $nick \($hand\) flagged a song."
		set song [battle:getxml]
		if !{ [string equal $song ""] } {
			regexp {<SONGTITLE>(.*?)<\/SONGTITLE>} $song match song
			regsub -all {'} $song "'" song
			regsub -all {<} $song "<" song
			regsub -all {>} $song ">" song
			regsub -all {&} $song "&" song
			regsub -all {ÿ} $song "ñ" song
                	regsub -all {°} $song "º" song
			regsub -all {&} $song "&" song
			}
			if { [string equal $dj ""] } {
			set $currentdj "AutoDJ"
			} else {
				set $currentdj $dj
			}
			set r [open flaggedsongs.txt a+]
			puts $r "[strftime "%d %b %Y, %H:%M %z"]: $song was played on air and flagged by $nick \($hand\). DJ onair was $currentdj. Reason: $text"
			close $r
			putserv "PRIVMSG $nick :$head I have flagged the current song, which was \($song\). It will be reviewed by management. Reason provided: $text $tail"
		} else {
		putserv "PRIVMSG $nick :$head You must provide a reason. $tail"
		}
	}
}
It errors after

Code: Select all

	if !{ [channel get $chan advertonly] } {
with a 'Tcl error [battle:flagsong]: missing close-brace'

~Nara
r
r0t3n
Owner
Posts: 507
Joined: Tue May 31, 2005 6:56 pm
Location: UK

Post by r0t3n »

Try:

Code: Select all

proc battle:flagsong {nick host hand chan text} {
    global head tail delim dj
    if {[channel get $chan advertonly]} { return }
    if {$text != ""} {
        putlog "\002Radio:\002 $nick \($hand\) flagged a song."
        set song [battle:getxml]
        if {$song != ""} {
            regexp {<SONGTITLE>(.*?)<\/SONGTITLE>} $song match song
            regsub -all {'} $song "'" song
            regsub -all {<} $song "<" song
            regsub -all {>} $song ">" song
            regsub -all {&} $song "&" song
            regsub -all {ÿ} $song "ñ" song
            regsub -all {°} $song "º" song
            regsub -all {&} $song "&" song
        }
        if {$dj == ""} {
            set currentdj "AutoDj"
        } else {
            set currentdj $dj
        }
        set r [open flaggedsongs.txt a+]
        puts $r "[strftime "%d %b %Y, %H:%M %z"]: $song was played on air and flagged by $nick \($hand\). DJ onair was $currentdj. Reason: $text"
        close $r
        putserv "PRIVMSG $nick :$head I have flagged the current song, which was \($song\). It will be reviewed by management. Reason provided: $text $tail"
    } else {
        putserv "PRIVMSG $nick :$head You must provide a reason. $tail"
    }
}
r0t3n @ #r0t3n @ Quakenet
N
Nara
Halfop
Posts: 40
Joined: Sun Jul 23, 2006 11:12 pm

Post by Nara »

That worked. Thanks.

~Nara
Post Reply