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.

Problems with the script Dictionary 4.68 by MORA@EFNet

Old posts that have not been replied to for several years.
Locked
C
Calamaro
Voice
Posts: 5
Joined: Tue Sep 28, 2004 7:07 pm
Contact:

Problems with the script Dictionary 4.68 by MORA@EFNet

Post by Calamaro »

Here is the script http://www.egghelp.org/cgi-bin/tcl_arch ... oad&id=839

The problem i'm having is that if i add a word and use special characters in the definition like:

Code: Select all

!learn Calamaro says "hell ya" alot
It works correctly when i show the definition right away. But saves it like this to the db:

Code: Select all

Calamaro says {"hell ya"} alot
So if/when i restart the bot it loads from the db and shows the definition with those {} around "hell ya" in the channel.

I've tried looking around in the script but this is a bit more then i can get through my head. Can anyone take a quick look or clue me in what to look for. I really like the script otherwise but this is kinda a showstopper since people do use special characters when adding definitions.
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

I can't be bothered to d/l the script, but using [join] on the output will solve your problem:

Code: Select all

putserv "PRIVMSG $channel :[join $string_read_from_db]"
C
Calamaro
Voice
Posts: 5
Joined: Tue Sep 28, 2004 7:07 pm
Contact:

Post by Calamaro »

Thanks for the reply but if i understand you correctly that seems more like a fix then a solution to the problem. This is the part of the script that adds the definitions to the in memory db:

Code: Select all

bind pub $dictionary(addflag) $dictionary(addtrigger) dic:pub:add

proc dic:pub:add {nick uhost handle chan text} {
 global dictionary 
 if {$dictionary(dicmchanonly)==1 && [lsearch -exact [channel info $chan] +dicm]==-1} { return 0 }
 if {[dic:check:flood $handle]} { return 0 }
 set str [dic:intr:add $text]
 set word [lindex $str 0]
 set def [lindex $str 1]
 if {$def==""} { putserv "PRIVMSG $chan :Error, no definition given." ; return 0 }
 dic:add $nick $word $def
 putlog "$nick@$chan $dictionary(addtrigger) $text"
 if {$dictionary(quiret) == 0 && [dic:ishub $chan]} {
  if {$dictionary(where)==1} { putserv "PRIVMSG $chan :Added $word=$def" }
  if {$dictionary(where)==2} { putserv "NOTICE $nick :Added $word=$def" }
 }
}

proc dic:intr:add {line} {
 #input a string, as the user typed it.
 #output a list with 2 parts, word, def
  if {[string range $line 0 0]=="\""} {
   set found [join [lindex [split $line "\""] 1]]
   set meaning [join [lrange [split $line "\""] 2 end]]
  } else {
   set found [lindex [split $line] 0]
   set meaning [join [lrange [split $line] 1 end]]
  }
  lappend res $found
  lappend res $meaning
  return $res
}

proc dic:add {author word def} {
 #Both word and def are lists when we get em.
 global dictionary
 set dictionary(changed) 1
 set word [split $word]
 if {[llength $word]>1} { set word "\"[join $word]\"" } else { set word [join $word] }
 set def $def
 set time [strftime %m-%d-%Y@%H:%M]
 lappend dictionary(db) "$author $time $word $def"
}
And this writes it to the db file:

Code: Select all

bind time - "* * * * *" dic:save:list
proc dic:save:list {m h d mm y} {
 global dictionary
 if {$dictionary(imtemphub) > 0} { set dictionary(imtemphub) [expr $dictionary(imtemphub) - 1] }

 if {$dictionary(flood)<$dictionary(floodlimit)} { set dictionary(flood) 0 }

 if {$dictionary(changed)==1} {
  dicm:save:db:to:file $dictionary(file)
  set dictionary(changed) 0

 if {$dictionary(xml) == 1} {
  set fp [open $dictionary(xmlname) w+]
  puts $fp "<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>"
  puts $fp "<Dictionary>"

  foreach line $dictionary(db) {
   puts $fp "<entry>"
   puts $fp "<author>[join [lindex $line 0]]</author>"
   puts $fp "<word>[join [lindex $line 2]]</word>"
   puts $fp "<time>[join [lindex $line 1]]</time>"
   puts $fp "<def>[join [lrange $line 3 end]]</def>"
   puts $fp "</entry>"
  }
  puts $fp "</Dictionary>"
  close $fp
 }
 }
}

proc dicm:save:db:to:file {file} {
global dictionary
  set fp [open $file w+]
  foreach line $dictionary(db) { puts $fp [join [lrange [split $line] 0 end]] }
  close $fp
}
Somewhere in these parts it's not handling special characters correctly. I will continue trying to find where. As always any help is appreciated.
C
Calamaro
Voice
Posts: 5
Joined: Tue Sep 28, 2004 7:07 pm
Contact:

Post by Calamaro »

Disregard my previous post. It would seem that the {} around words with special characters only comes when you remove a definition from the dictionary.

These are the relevant parts (i think):

Code: Select all

bind pub $dictionary(delflag) $dictionary(deltrigger) dic:pub:del

proc dic:pub:del {nick uhost handle chan line} {
 global dictionary
 if {$dictionary(dicmchanonly)==1 && [lsearch -exact [channel info $chan] +dicm]==-1} { return 0 }
 if {[dic:check:flood $handle]} { return 0 }
 if {[string range $line 0 0]=="\""} {
  set found [join [lindex [split $line "\""] 1]]
  set id [join [lindex [split $line "\""] 2]]
 } else {
  set found [join [lindex $line 0]]
  set id [join [lindex $line 1]]
 }
 #check if id is a integer.
 dic:del $found $id
 putlog "$nick@$chan $dictionary(deltrigger) $line"
 if {$dictionary(quiret) == 0 && [dic:ishub $chan]} {
  if {$dictionary(where)==1} { putserv "PRIVMSG $chan :Deleted $found \[$id\]" }
  if {$dictionary(where)==2} { putserv "NOTICE $nick :Deleted $found \[$id\]" }
 }
}

proc dic:del {word id} {
 #Input : word and id, if id=0 delete all def for that word.
 #returns nothing
 global dictionary
 set dictionary(changed) 1
 set word [join $word]
 set bgdb $dictionary(db)
 if {![info exists dictionary(db)]} { rehash ; return 0 }
 unset dictionary(db)
 set oid 0
 foreach line $bgdb {
  set line [split $line]
  set found [lindex $line 2]
  if {[string equal -nocase $found $word]} {
   incr oid
   if {$oid==$id || $id==0} { continue }
  }
 #We should only get here if the word is not matched or it is not the number we want.
 lappend dictionary(db) $line
 }
}
Every time someone removes a definition from the db it adds another pair of {} around words with special characters.
User avatar
demond
Revered One
Posts: 3073
Joined: Sat Jun 12, 2004 9:58 am
Location: San Francisco, CA
Contact:

Post by demond »

well, if the script's correctness is what bothers you, contacting the author is probably your best option; if you just need to get rid of that glitch, applying what I suggested is more than enough
Locked