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.

friendcodes script from justdabomb2

Support & discussion of released scripts, and announcements of new releases.
Post Reply
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

friendcodes script from justdabomb2

Post by rosc2112 »

Uhm... What is wrong with this script that it causes my bot to LOOP and rehash 3 times when I load this script? I had to KILL my bot and restart it, as simply unloading the script and doing a restart did not solve the problem.

I suspect this bit of weirdness might have something to do with the problem:

Code: Select all

set mphtfile "scripts/codes/mphtcodes.txt" 
if {![file exists $mphtfile]} { 
  catch {close [open $mphtfile w]} 
} 
or maybe this weirdness:

Code: Select all

proc add:mpht {nick uhost hand chan arg} { 
  global noticecolor
  set gamer $nick 
  set code [lindex [split $arg] 0] 
  if {$gamer != "" && $code != ""} { 
    set fd [open $::mphtfile r+] 
    while {![eof $fd]} { 
      lappend list [gets $fd] 
    } 
    if {[lindex $list end] == ""} { 
      set list [lreplace $list end end] 
    } 
    lappend list "\[$nick\] <$gamer> <$code>" 
    seek $fd 0 
    puts -nonewline $fd [join $list \n] 
    close $fd 
    putquick "NOTICE $nick :^C$noticecolor Your code for ^BMPHT^B has been added." 
    } else { 
    putquick "NOTICE $nick :^C$noticecolor Type ^B!addmpht <code>^B" 
  } 
} 
or maybe using proc names that are actually tcl's commands??

Code: Select all

proc info:find {nick uhost hand rest txt} {
Gawd... <shakes her head sadly>

I have asked that this script be removed from the tcl archive until the author actually fixes this, as it is a serious problem.
User avatar
Alchera
Revered One
Posts: 3344
Joined: Mon Aug 11, 2003 12:42 pm
Location: Ballarat Victoria, Australia
Contact:

Post by Alchera »

The top piece is certainly different but the procedure name is unique i.e. info:find (regarded by eggdrop as one word) and should (in theory) not be a problem.
Add [SOLVED] to the thread title if your issue has been.
Search | FAQ | RTM
J
Justdabomb2
Voice
Posts: 37
Joined: Fri Sep 29, 2006 7:16 pm
Location: United States of America

/codes/

Post by Justdabomb2 »

Yeah, for the mpht file, I forgot to change it from looking in the code folder. Becuase that is what I use no my computer. I store the codes in "scripts/code/filename.txt". Just take out codes/ and it will work just fine. very sorry. I shouldn't have overlooked it :(
Yeah!
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

That was *not* the problem I posted about, the problem is this script making the bot LOOP and rehash three times when I issue ONE .rehash command, or restart, etc.

As far as the pathnames, why not just use a variable like
set filepath "/home/whatever/path/" and use that as a global var throughought the proc's

Actually, ALL of the redundant code and procs could be consolidated and use just ONE proc with variables to cover each game name.. etc.

I suggest before submitting another poorly written script to the tcl archive, you post it here and ask for testers and peer review.
J
Justdabomb2
Voice
Posts: 37
Joined: Fri Sep 29, 2006 7:16 pm
Location: United States of America

...

Post by Justdabomb2 »

Do you have proof it looped, my friend tested this script and it worked fine for him after he deleted the "codes/". Also I submitted an updated script, with one proc for adding and one for finding... Also it isn't case sensitive anymore. And no, I didn't have someone else write/help me with that. You don't need to be so mean, it was my frist script okay.. I do agree that I should have looked over my script more before submitting it to the archive. Sorry. :(
Yeah!
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

Basically when I put the script into the bot, and did a rehash or a restart, the result showing on the console was every command repeated 3x. I'll test the new version when it's up on the tcl archive and let you know if the problem is still present. I did not debug and test the script beyond loading it, and running the commands.

I'm running on a linux platform, dunno if that makes a diff.

And I apologize for being mean.
J
Justdabomb2
Voice
Posts: 37
Joined: Fri Sep 29, 2006 7:16 pm
Location: United States of America

Post by Justdabomb2 »

It should be on soon, and I made it so that the script user can easily change the name/initials for the games too if the script users don't like the ones I use. and it is not case sensitive at all now. I wish I could just figure out the stupiod delete thing though. I am still wokring on it. Sorry about putting a very poorly written script in the archive, my newer one should look much more neat.
Yeah!
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

What delete thing? Show us what you mean and your code.
J
Justdabomb2
Voice
Posts: 37
Joined: Fri Sep 29, 2006 7:16 pm
Location: United States of America

Post by Justdabomb2 »

remember my thread about trying to make a proc to delete a line with the specified nick from the file?
Yeah!
J
Justdabomb2
Voice
Posts: 37
Joined: Fri Sep 29, 2006 7:16 pm
Location: United States of America

It's on

Post by Justdabomb2 »

Hey, the new script is on the archive now, tell me what you think of this one okay. Thanks! :)
Yeah!
User avatar
rosc2112
Revered One
Posts: 1454
Joined: Sun Feb 19, 2006 8:36 pm
Location: Northeast Pennsylvania

Post by rosc2112 »

The loop problem is indeed fixed in this new version.

I have some suggestions for you, to reduce the number of duplicate functions.

Instead of this for each filename:

Code: Select all

set mphtfile "/tmp/mphtcodes.txt" 
if {![file exists $mphtfile]} { 
  catch {close [open $mphtfile w]} 
} 
Try something like:

Code: Select all

set filepath "/home/mybot/datafiles/"
set codefiles [list mpht mkds lsmg stfx]

foreach name $codefiles {
     if {![file exists $filepath$name]} {
           catch {close [open $filepath$name\codes.txt w]}
      }
}
If you made $filepath a global variable, then people can change that one line and set the path to whatever they want more simply.

Actually, it's probably not even necessary to initialize the files in such a way, you can create them when needed in the procs that go to write them. But anyway..

You could also use lsearch to reduce the redundant sections in other proc's, for example:

Code: Select all


set command [lindex [split $arg] 0] 
global filepath codefiles

# This assumes that $command is the same as the name of the codefile
# so, if you had a command called !add mpht, it'll match the filenames
if {[set myarg [lsearch $codefiles $command]] != -1} { 
    set gamer [string tolower $nick] 
    set code [lindex [split $arg] 1] 
    # $nick would never be "" if this is run from a public command
    if {$code != ""} { 
           set fd [open $path$myarg\codes.txt r] 
           set list [split [read $fd] \n]
           catch {close $fd}
           # you should do an lsearch here for the nick, to prevent duplicates
            set linecount -1
            foreach line $list {
                 incr linecount
                 set nickf [lindex [split $line :] 0]
                 set codef [lindex [split $line :] 1]
                 if {$nickf == $gamer} {
                      # this is a matching line.. lreplace the data
                       set list [lreplace $list $linecount $linecount "$gamer:$code"]
                 } else {
                       set list [linsert $list end "$gamer:code"]
                 }
            }
            set fd [open $path$myarg\codes.txt w]
            foreach line $list {
                 if {$line != ""}
                      puts $fd $line
                  }
            }
            catch {close $fd}
            putquick "NOTICE $nick :^C$noticecolor Your code for ^B$acwwini^B has been added."
    } else { 
          putquick "NOTICE $nick :^C$noticecolor Type '^B!add $acwwini <code>^B'" 
    } 
} 

That will also format your lines in such a way as to make it easier to parse them in other procs. The find:code proc would be very similar to the above, except it's only reading and comparing the lines, not writing to the file.

As far as the info: proc's, they could all be combined into 1 generic help proc, then just parse the arg for the option:

Code: Select all

bind pub - !gamehelp gamehelp
proc gamehelp {$nick uhost hand chan text} {
        if {$text == "about"} {
              puthelp "PRIVMSG $nick :About the script.."
         } elseif {$text == "fcmenu"} {
              puthelp "PRIVMSG $nick :so forth and so on"
         } else {
               puthelp "PRIVMSG $nick :I didn't understand that command, here's a summary of options:"
               puthelp "PRIVMSG $nick :so forth and so on..."
         }
}
m
monie089
Halfop
Posts: 76
Joined: Sat Jul 29, 2006 11:13 pm

Post by monie089 »

Code: Select all

set nxg(char) @
set nxg(gamefile) "nxg/game.txt"

proc NintendoXG:find {nick uhost hand chan arg} {
global nxg
   set name [lindex [split $arg] 0]
   set game [lindex [split $arg] 1]
   if {![string length $name] || ![string length $game]} {
      putserv "PRIVMSG $nick :\002SYNTAX:\002 $::lastbind <nick> <game>"; return
   }
   set list [split [read [set fd [open $::nxg(gamefile) r]]] \n]; close $fd
  if {![llength [set matches [lsearch -all -inline -glob $list [md5 [string tolower $name]]*]]]} {
      putserv "PRIVMSG $nick :The user: $name couldn't be found in the NintendoXG Database."; return
   }
  foreach match $matches {
     foreach {x gm code} $match {
         if {[string equal -nocase $gm $game]} {
             putserv "PRIVMSG $nick :--- $name's Friendcodes ---"
             putserv "PRIVMSG $nick :Game: $gm -- Code: $code"
         }
     }
  }  
}

proc NintendoXG:code {nick uhost hand chan arg} {
global nxg
   foreach {game code} [split $arg] {break}
  if {![string length $game] || ![string length $code]} {
      putserv "PRIVMSG $nick :\002SYNTAX:\002 [string trim $nxg(char)]Code <game> <code>"; return
   }
 set list [split [read [set fd [open $::nxg(gamefile) r]]] \n]; close $fd
  if {![llength [lindex $list end]]} {
      set list [lreplace $list end end]
   }
   lappend list [list [md5 [string tolower $nick]] $game $code]
   puts -nonewline [set fd [open $::nxg(gamefile) w]] [join $list \n]; close $fd
   putserv "PRIVMSG $nick :Your code has been added to the NintendoXG Database."
}

bind pub - [string trim $nxg(char)]Find NintendoXG:find
bind pub - [string trim $nxg(char)]Code NintendoXG:code

Updated the friendcodes script so now you can do
@Find <nick> <game>
and to add your codes
use @Code <game> <code>

Just set the file location and rehash your bot and your done
New server irc.NintendoXG.com come and visit
Post Reply