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.

Script Insert Help

Help for those learning Tcl or writing their own scripts.
Post Reply
A
Ace2008
Voice
Posts: 1
Joined: Sat Jun 28, 2008 4:44 pm

Script Insert Help

Post by Ace2008 »

i want to insert some text to a db but i know this is half correct anyway lol
but i have a prob. this bit is wrong if {$info=="NEWS && position == 1"} and not sure how to fix it.

the bot announces like so,
#2: NEWS :: World News :: Today 1hr 4mins 22secs ago - BBCNews: UK the empty world ::

but my code will fail if where "the empty world" would change and become say 5 words

Code: Select all

bind pubm - * news_insert

proc pre_insert {nick host handle channel text} {
    global db_handle

proc filter_mirc_codes {} { 
  upvar text text 
  regsub -all -- "(\002|\017|\026|\037|\003(\[0-9\]\[0-9\]?(,\[0-9\]\[0-9\]?)?)?)"  $text "" text 
}

filter_mirc_codes


set position [lindex [string map {# {} : {}} $text] 0]
set info [lindex $text 1]

if {$info=="NEWS && position == 1"} { <--- [b] I KNOW THIS BIT IS WRONG [/b]

set 1 [lindex [split $text] 6] [lindex [split $text] 7]
set 2 [lindex $text 3]
set 3 [lindex $text 12]
set 4 [lindex [split $text] 13] [lindex [split $text] 14]

set sql "blah"
}
  mysqlendquery $db_handle
}
User avatar
speechles
Revered One
Posts: 1398
Joined: Sat Aug 26, 2006 10:19 pm
Location: emerald triangle, california (coastal redwoods)

Post by speechles »

Code: Select all

bind pubm - * news_insert

proc pre_insert {nick host handle channel text} {
   set text [split [stripcodes bcruag $text]]
   set position [string map {"#" "" ":" ""} [lindex $text 0]]
   set info [lindex $text 1]
   if {($info == "NEWS") && ($position == "1")} {
      set a [join [lrange $text 6 7]]
      set b [lindex $text 3]
      set c [lindex $text 12]
      set d [join [lrange $text 13 end]]
      set sql "blah"
   }
   mysqlendquery $::db_handle
} 
You cannot set 1,2,3,4 to any other values.. because they are already numeric, variables begin with an alphabetic character a-z, also fixed your flawed evaluation the "I KNOW THIS BIT IS WRONG" part, also added the necessary split and the stripcodes, lrange sensibly substituted for multiple lindex as well. There are quite a few things that go wrong when you kludge together code you have no idea how works. Don'tcha think?

And now I've got to wonder, why you have the procedure titled pre_insert and the bind labeled news_insert?.. oops, was I not supposed to find this out.. but i bet.... this has something to do with piracy, not to mention databases, warez releases, pre times (all of which you failed to mention knowing it would get you zero support, your post junked, and similar consequences). This is something not really suited to discussion on this forum. It lends itself to discussion on piracy and hundreds of other things not related at all to eggdrop (where can i find 'xyz' warez release? similar to this). I would not be surprised at all to find this junked, not surprised at all... :roll:
Post Reply