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.

Wee bit o help needed

Old posts that have not been replied to for several years.
W
Weirdo
Master
Posts: 265
Joined: Sat Apr 27, 2002 8:00 pm
Location: Manchester, England

Wee bit o help needed

Post by Weirdo »

Hey again

Making a script for my channel, basically, you send the bot a file, it stores it, you do !set_pic <filename> it makes it the picture of the day. you do !pic, it send the file, and if you specify a specific filename, it sends you that.

so i wrote the script, getting a couple of errors, nothing major, just missing a close brace for the 2nd proc, and io have extra characters after close brace for pub 1
[23:06:51] <Natsuki-Chan> [23:06] Tcl error [pub:picoday]: missing close-bracket
[23:07:04] <Natsuki-Chan> [23:07] Tcl error [pub:pic]: extra characters after close-brace
so, read over this around 30 times. And cant for the life of me find the error. Can you lend me assistance in finding the irritaitng bug please?

Code: Select all

 
set dir(main) "filesys/incoming"

#This sets the bind for the !pic command
bind pub - !pic pub:pic

#This sets the bind for ops and halfops for picture of the day
bind pub ol|ol !set_pic pub:picoday

proc pub:pic { nick host hand chan text } {
	global dir
	if {$text == ""}{
		set $dir(file) $dir(main)/$dir(potd)
		dccsend $dir(file) $nick
		putcmdlog "$dir(file) sent to !$nick -- $hand! on $chan"
		} {
		set dir(filename) [lindex [split $text] 0]
		set dir(file) $dir(main)/$dir(filename)
		if {[fileexists $dir(main)/$dir(filename)]} {
			dccsend $dir(file) $nick
			putcmdlog "$dir(file) sent to !$nick -- $hand! on $chan"
			} {
			puthelp "notice $nick :File Cannot be Sent because it does not Exist on the File Space"
			putcmdlog "Failed Send due to Bad file error"
			}
		}
	}

proc pub:picoday {nick host hand chan text} {
	global dir
	set dir(filename) [lindex [split $text 0]
	if {[fileexists $dir(main/$dir(filename)]} {
		set dir(potd) $dir(filename)
		putcmdlog "New Picture of the Day uploaded by !$hand - $nick! - $dir(potd) 
	} {
		puthelp "notice $nick :File does not exist on the File System, please check your imput or upload that file"
		putcmdlog "New Picture of the Day - Failed"
	}
}

putlog "\Picture of the Day V0.1 by Weirdo loaded"
Thanks :)
Last edited by Weirdo on Tue Apr 08, 2003 7:36 am, edited 1 time in total.
W
Weirdo
Master
Posts: 265
Joined: Sat Apr 27, 2002 8:00 pm
Location: Manchester, England

Post by Weirdo »

pub:picoday has been fixed :)

Forwareded a few friends of mine here, it was a missing ] in the lindex. Works perfectly :)
W
Weirdo
Master
Posts: 265
Joined: Sat Apr 27, 2002 8:00 pm
Location: Manchester, England

Just one error left

Post by Weirdo »

made a few changes, same damn error though

Spent the last few hours doing some line by line testing and from what i can tell, its in the first if statement, somewhere :P

Code: Select all

proc pub:pic {nick host hand chan text} {
	global dir
	puthelp "Notice $nick :1"
	set dir(filename) [lrange [split $text] 0 end]
	if {$dir(filename) == "" }{
		set $dir(file) $dir(main)/$dir(potd)
		dccsend $dir(file) $nick
		puthelp "Notice $nick :2"
		putcmdlog "$dir(file) sent to !$nick -- $hand! on $chan"}{
		set dir(file) $dir(main)/$dir(filename)
		puthelp "Notice $nick :3"
		if {[file exists $dir(main)/$dir(filename)]}{
			dccsend $dir(file) $nick
			putcmdlog "$dir(file) sent to !$nick -- $hand! on $chan"
			puthelp "Notice $nick :4"
			}{
			puthelp "notice $nick :File Cannot be Sent because it does not Exist on the File Space"
			putcmdlog "Failed Send due to Bad file error"
			puthelp "Notice $nick :5"
		}
	}
}
Please can you help?
[12:30] Tcl error [pub:pic]: extra characters after close-brace
e
egghead
Master
Posts: 481
Joined: Mon Oct 29, 2001 8:00 pm
Contact:

Re: Just one error left

Post by egghead »

Weirdo wrote:
Please can you help?

[12:30] Tcl error [pub:pic]: extra characters after close-brace
It's because of the weirdo way of placing the braces.

compare:

Code: Select all

set test 1

if { $test == 1 }{
   puts "test is 1" 
}{
   puts "test is 0"
}
to

Code: Select all

set test 1

if { $test == 1 } {
   puts "test is 1" 
} {
   puts "test is 0"
}
W
Weirdo
Master
Posts: 265
Joined: Sat Apr 27, 2002 8:00 pm
Location: Manchester, England

Post by Weirdo »

Yup, thats what it was alright :P

Now to fix the little errors i made :)

thanks
W
Weirdo
Master
Posts: 265
Joined: Sat Apr 27, 2002 8:00 pm
Location: Manchester, England

Post by Weirdo »

Slight question

I restarted my bot, cold during a TCL error (Damn wrong number of args :P) and i had a variable set before, picoday, which was a filename

After the reboot, she had forgotten it

Is there a way i can get the bot to remember what the image is, even if a reboot has taken place?
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

This would require that you save and restore the data amnualy to some form of database, be it a flatfile (simple write and read file) or full blown mysql DB.

The bot should survive a .rehash, so long as you don't overwrite the variable in the global context when reading the script.

EG

Code: Select all

set a test
proc blah {} {
  blah
}
When a rehash takles place, $a will be set to test, even if a change has taken place elsewhere in the script.

SOmthing like

Code: Select all

if {![info exists]} { set a test }
Will stop rehash from overwritting it.

A .restart wipes the memory, and is in effect, the same as doing a ".die" and starting the bot from the shell, except the bot doesn't die. No variables survive this.

".die" means memory is totaly freed, and it doesn't survive.

and a PC reboot is obvious.
W
Weirdo
Master
Posts: 265
Joined: Sat Apr 27, 2002 8:00 pm
Location: Manchester, England

Post by Weirdo »

Right, so definate writing to the first line of a variables file. perhaps could write something that could write new line for each time the script is set and a new pic set as $picoday, then add a line at end of file. Then, when !picoday is ran again, it checks last line of file, resets the variable, perhaps that can be done on reboot of the bot.

Got any links for file manipulation in this manner. Definately my weakpoint at the moment?
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

I have been nice, and produced a nice little script for you. It is a replacment for the "set" command, which you should only use of stored variables.

Code: Select all

set setfile "/path.to.file/containing/vars"

proc setsave {name value {type {}}} {
  if {$type != ""} {
    set mode $name
    set name $value
    set value $type
  }
  global $name
  switch -- [string tolower $mode] {
    {-init} {
      if {[info exists $name]} { return $[subst $name] }
      if {![catch {set int [set:read $name]}]} { set $name $int; return $int }
      set $name $value; return [set:save $name $value]
    }
    default {
      return [set:save $name $value]
    }
  }
}

proc set:read {name} {
  global setfile
  if {![file exists $setfile]} { return "" }
  set fp [open $setfile r]
  set list [read nonewline $fp]
  close $fp
  if {[set idx [lsearch -glob $list "$name *"]] == -1} { error "Not set here, do your thing" }
  return [lindex [lindex $list $idx] 1]
}

proc set:save {name value} {
  global setfile
  if {![file exists $setfile]} { return "" }
  set fp [open $setfile r]
  set list [read -nonewline $fp]
  close $fp
  if {[set idx [lsearch -glob $list "$name *"]] != -1} {
    set list [lreplace $list $idx $idx [list $name $value]]
  } else {
    lappend list [list $name $value]
  }
  set fp [open $setfile w]
  puts $fp $list
  close $fp
  return $value
}
Also download at http://www.ppslim.ukshells.co.uk/prov/e ... rapper.tcl

This has two uses, it will prevent set over-writting when you rehash the bot, so long as you use it correctly.

Use it like follows

When defining the default settings for a script, you normaly use the set command near the top of the file, but not in a procedure (proc). Replace

Code: Select all

set defaultscriptsetting "value"
to

Code: Select all

setsave -init defaultscriptsetting "value"
This does one of three things.

1: On a rehash, it will check to see if the setting exists, if it does, leave it as it is, and do not replace its current value with "value".

2: It will try and read the setting from a file (on start or .restart). If the setting is in the file, it uses this setting, instead of "value"

3: If not in memory, or in the file, it saves "value" to the file, and uses "value" as the setting.

When you create a command in a script, that is designed to changes a setting (EG, you make a public kick script, and you are using a command to change the DEFAULT kick message), instead of making the setting global and chanign the value, use the "setsave" command

EG, from

Code: Select all

setsave -init defaultkick "Goodbye"
proc kickchange {nick uh hand chan arg} {
  #do some checking
  global defaultkick
  set defaultkick $arg
}
This will only change it while the setting is in memory

CHange it too

Code: Select all

setsave -init defaultkick "Goodbye"
proc kickchange {nick uh hand chan arg} {
  #do some checking
  setsave defaultkick $arg
}
Note there is no -init in this.

When there is no -init, it simply saves the new setting to the file.

This setsave only works on global variables. You then use the variables the way you normaly do.

These command just take care of the save and read functions.

Warning: I havn't tested the code in any way. If you have any problems, just ask.
W
Weirdo
Master
Posts: 265
Joined: Sat Apr 27, 2002 8:00 pm
Location: Manchester, England

Post by Weirdo »

W...o....w

Ill give it a go.

Slight Question on when it adds to the file. Does it add a new line for each file that is set?

http://sucess.faereal.net/sebstuff/picoday.tcl

thats the file as it is at the moment. Currently getting a variable error on the !set_pic command.
[12:16:36] <Natsuki-Chan> [12:16] Tcl error [pub:picoday]: can't read "mode": no such variable
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

Re-download the file form the link. I remember thinking about that when making it, but thought it wasn't need (WRONG) :P

It will only create one line for each variable.

This prevents the file from becoming bloated.

It should never cause a error, but when file doesn't exist, all data is lost. So you will also need to create the file first. Quickest way, is to use "touch file.name" on the shell.
W
Weirdo
Master
Posts: 265
Joined: Sat Apr 27, 2002 8:00 pm
Location: Manchester, England

Post by Weirdo »

Was missing a close brace, added it :)

Giving me a Picoday - no such variable error now. Thats the variable i am using for set save. I have uploaded the changed tcl file to the link above :)
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

First off, I have changed the script again. It fixes the missing bracket, and also prevents the error you have shown.

However, you should also have a "setsave -init" line.

Without this line, your script will not re-load the previously set value when the bot died.

It will need to be below the "proc setsave" definition.

Use

Code: Select all

setsave -init picoday default
This will make it reload the value each time.
W
Weirdo
Master
Posts: 265
Joined: Sat Apr 27, 2002 8:00 pm
Location: Manchester, England

Post by Weirdo »

if picoday is set using

setsave -init picoday default

I do still have to use the

setsave picoday [file join $dir(main) $dir(filename)]

in the proc pub:picoday?

[edit]

Re-Read the instructions above, understand where to put it now. Think i need both, but setsave -init outside of a proc :)

Changed the download to show the script

[edit2]

{picoday filesys/incoming/1044150826579.jpg} is what it records :) And DOES change when a new image is set.

only one problem

At restart, this occurs

[13:28:24] <Natsuki-Chan> [13:28] Tcl error [pub:pic]: can't read "picoday": no such variable

Which means the variable has been wiped, and i done it wrong :P
p
ppslim
Revered One
Posts: 3914
Joined: Sun Sep 23, 2001 8:00 pm
Location: Liverpool, England

Post by ppslim »

First off, you should move the "setsave -init" line further down. Below the "set:save" proc.

I noticed why there was a missing bracket now. It was when I hadn't cleared up funny and tidying the code. At this time, using "-init" causes this problem.

Redownload

Aditionaly, did you create the file as noted?
Locked