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.

botscript doesn't save some variables

Old posts that have not been replied to for several years.
C
CosmicD
Op
Posts: 102
Joined: Sat Dec 11, 2004 3:46 pm

botscript doesn't save some variables

Post by CosmicD »

there's some script that I am having wich is cool on its own but it seems to forget lots of the settings when the bot is shut down.

for example theres a "autovoice on" fuction wich I would want to be remembered even when the bot is down..

I've tried to extract the code that I think is responsible for the procedure:

Code: Select all

autovoice { if {[matchattr $handle &m $channel] || [matchattr $handle o]} {
          if {![checksec $nick $uhost $handle]} { return 0 }
             if {![matchattr $handle +Q]} {
          putserv "NOTICE $nick :Je bent niet ingelogd."
            putserv "NOTICE $nick :Log in met: /msg $botnick login <paswoord>."
            return 0}
            if {$who == ""} {
             putserv "NOTICE $nick :Gebruik: autovoice <on|off>"
            return 0 }
             switch $who {
             off { set topicinfo(vchan$channel) "0"
                   putserv "NOTICE $nick :AutoVoice uit."
                   return 0 }
              on { set topicinfo(vchan$channel) "1"
                   putserv "NOTICE $nick :AutoVoice aan."
                   return 0 }}}}
I see something that has to do with "set topicinfo" but i don't really have a clue. I would like the bot to remember these variables that have been set but there doesnt seem to be a write structure to a file. Can anyone try to help ?

the save feature of the bot just saves the things that are being saved when you type .save in dcc chat, i think

Code: Select all

      save { if {[matchattr $handle m]} {
          if {![checksec $nick $uhost $handle]} { return 0 }
            if {![matchattr $handle +Q]} {
          putserv "NOTICE $nick :Je bent niet ingelogd."
            putserv "NOTICE $nick :Log in met: /msg $botnick login <paswoord>."
            return 0}
            save
            putserv "NOTICE $nick :Opgeslagen."
            putserv "PRIVMSG $home :$botnick@$servicename: \002\0035\[\002\00314[lindex [ctime [unixtime]] 0] [lindex [ctime [unixtime]] 2] [lindex [ctime [unixtime]] 1] [lindex [ctime [unixtime]] 4] \0031@\00310 [lindex [ctime [unixtime]] 3]\0035\002\]\002\003 $nick (\00314$nick!$uhost\003) heeft me alle data laten \002\0032OPSLAAN\002\003." }}
Last edited by CosmicD on Fri Jan 07, 2005 2:45 pm, edited 1 time in total.
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Re: botscript doesn't save some scripts

Post by user »

CosmicD wrote:the save feature of the bot just saves the things that are being saved when you type .save in dcc chat, i think
Variables are not meant to last forever. (at least not in the eggdrop world - you might think so because you've been living in the mIRC world :P) If you want variables saved, you have to do it yourself. Here's some code to get you started:

Code: Select all

proc saveArray {array file {mode w}} {
	if {![file writable $file]} return
	upvar 1 $array Array
	set data [array get Array]
	set f [open $file $mode]
	puts $f $data
	close $f
}
proc loadArray {array file} {
	if {![file readable $file]} return
	upvar 1 $array Array
	array set Array {}
	set f [open $file]
	set data [read -nonewline $f]
	close $f
	array set Array $data
}

# saving your "topicinfo" array to "your.file"
bind evnt - save yourSave
bind evnt - prerehash yourSave
proc yourSave args {
	global topicinfo
	saveArray topicinfo your.file
}
loadArray topicinfo your.file
Have you ever read "The Manual"?
C
CosmicD
Op
Posts: 102
Joined: Sat Dec 11, 2004 3:46 pm

Post by CosmicD »

ah,

well i'm a script newbie really : i mean, i can add and modif some small things but this I dont really understand..

do I have to have this prodecure for each variable that I want to make savable ?
Last edited by CosmicD on Fri Jan 07, 2005 2:37 pm, edited 1 time in total.
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

That's up to you...just keep in mind that the loaded values overwrite any existing values.
Have you ever read "The Manual"?
C
CosmicD
Op
Posts: 102
Joined: Sat Dec 11, 2004 3:46 pm

Post by CosmicD »

oops , just changed that message while you were replying :( ..

I don't really know how to use it really,

i've changed your.file to something that s named after my bot, and when I save , nothing comes in it :(..

so as i rephrased my last message, do I have to use this piece of code for each variable ? for example I have the vchan$channel thingy for autovoice on or of, but could you give an example for one instance that would be saved into a file ?
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

you mean "topicinfo(vchan$channel)"? that's an element in the array, so it should be saved...if topicinfo is a global array. Is your script using a different namespace maybe?
Have you ever read "The Manual"?
C
CosmicD
Op
Posts: 102
Joined: Sat Dec 11, 2004 3:46 pm

Post by CosmicD »

lol.. namespace ? dont know enough to know what it is,

if its not too much could i send that script over or is it allowed to post an entire script here so it can be inspected in its whole...

EDIT:

i think i might understand, the settings are configurable for each channel sepparately, does that have something to do with it ?
Last edited by CosmicD on Fri Jan 07, 2005 3:04 pm, edited 1 time in total.
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

is the word "namespace" mentioned anywhere in the script? what happened when you did .save? did it create an empty file? (posting entire scripts is fine as long as they're not too big...how big is too big? I don't know :P)
Have you ever read "The Manual"?
C
CosmicD
Op
Posts: 102
Joined: Sat Dec 11, 2004 3:46 pm

Post by CosmicD »

theres no namespace mentioned,

when i did save it didn't create anything, not even an empty file...
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

Are you sure the script is loaded? Replace the yourSave proc with this one and see what happens...

Code: Select all

proc yourSave args { 
	global topicinfo
	if {[info exists topicinfo]} {
		saveArray topicinfo your.file
		putlog "topicinfo saved?"
	} else {
		putlog "no array? :/"
	}
}
Have you ever read "The Manual"?
C
CosmicD
Op
Posts: 102
Joined: Sat Dec 11, 2004 3:46 pm

Post by CosmicD »

well,

i see the entry when i enter the "save" command, but no file is being written on the disk

I have write access for the linux user to all disks, so i can't see what is going wrong realy.

and the fact that it doesnt show the other message to indicate that theres no userinfo vars, must mean that it actually should work ?

i know that this script also saves some extra info to the user file..., wonder why this doesn't work though
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

CosmicD wrote:i see the entry when i enter the "save" command, but no file is being written on the disk
The "topicinfo saved?" message? Did you remember to change the file name in the proc? Replace the proc once more...

Code: Select all

proc yourSave args { 
	global topicinfo

	set file "your.file"

	if {[info exists topicinfo]} {
		if {[file writable $file]} {
			saveArray topicinfo $file
			putlog "topicinfo saved to $file"
		} else {
			putlog "can't write $file"
		}
	} else {
		putlog "no array? :/"
	}
}
Have you ever read "The Manual"?
C
CosmicD
Op
Posts: 102
Joined: Sat Dec 11, 2004 3:46 pm

Post by CosmicD »

yep,

now it says "can't write file"..

i changed that your.file into botname.public so i knew what i had to look for ,

but now with this new proc it seems taht thers a problem writing the file, weird that all other files are writable...

i even set the scripts dir to 777 and that doesnt work :(
Last edited by CosmicD on Fri Jan 07, 2005 4:15 pm, edited 1 time in total.
User avatar
user
&nbsp;
Posts: 1452
Joined: Tue Mar 18, 2003 9:58 pm
Location: Norway

Post by user »

Does the file exist? Is your working directory changed to something weird? (putlog [pwd]) Try creating the file if it doesn't exist and see if that helps.

EDIT: doh...it seems like file writable expects the file to exist...that's stupid :P

Code: Select all

proc saveArray {array file {mode w}} {
	if {([file exists $file]&&![file writable $file])||![file writable [file dir $file]]} return
	upvar 1 $array Array
	set data [array get Array]
	set f [open $file $mode]
	puts $f $data
	close $f
}
proc loadArray {array file} {
	if {![file readable $file]} return
	upvar 1 $array Array
	array set Array {}
	set f [open $file]
	set data [read -nonewline $f]
	close $f
	array set Array $data
}

# saving your "topicinfo" array to "your.file"
bind evnt - save yourSave
bind evnt - prerehash yourSave
proc yourSave args {
	global topicinfo
	saveArray topicinfo your.file
}
loadArray topicinfo your.file
Have you ever read "The Manual"?
C
CosmicD
Op
Posts: 102
Joined: Sat Dec 11, 2004 3:46 pm

Post by CosmicD »

wow,

when i created the file in the eggdrop root it started saving data :).. thats cool

now I actually hope it'll also load this data on startup,

i created a sepparate tcl for this procedure you gave me...

UPDATE:
ok now it saves and loads all, thanks for your patience and help, i just need to do something and that is, to unify the way you set the file and you load the userfile on that last line

so i have the script you provided in a sepparate tcl:

Code: Select all

# saving your "topicinfo" array to "your.file"
bind evnt - save yourSave
bind evnt - prerehash yourSave

proc yourSave args {
   global topicinfo

   set file "mybot.public"

   if {[info exists topicinfo]} {
      if {[file writable $file]} {
         saveArray topicinfo $file
         putlog "Saving extra variables..."
      } else {
         putlog "can't write $file"
      }
   } else {
      putlog "no array? :/"
   }
}

proc saveArray {array file {mode w}} {
   if {![file writable $file]} return
   upvar 1 $array Array
   set data [array get Array]
   set f [open $file $mode]
   puts $f $data
   close $f
}

proc loadArray {array file} {
   if {![file readable $file]} return
   upvar 1 $array Array
   array set Array {}
   set f [open $file]
   set data [read -nonewline $f]
   close $f
   array set Array $data
}

loadArray topicinfo mybot.public
Well, shouldnt that last file now be:

Code: Select all

loadArray topicinfo $file
Locked