egghelp.org community Forum Index
[ egghelp.org home | forum home ]
egghelp.org community
Discussion of eggdrop bots, shell accounts and tcl scripts.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

friendcodes script from justdabomb2

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Support & Releases
View previous topic :: View next topic  
Author Message
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Thu Oct 05, 2006 7:07 pm    Post subject: friendcodes script from justdabomb2 Reply with quote

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:

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

or maybe this weirdness:
Code:

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:

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.
Back to top
View user's profile Send private message
Alchera
Revered One


Joined: 11 Aug 2003
Posts: 3344
Location: Ballarat Victoria, Australia

PostPosted: Thu Oct 05, 2006 8:14 pm    Post subject: Reply with quote

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
Back to top
View user's profile Send private message Visit poster's website
Justdabomb2
Voice


Joined: 29 Sep 2006
Posts: 37
Location: United States of America

PostPosted: Fri Oct 06, 2006 5:59 pm    Post subject: /codes/ Reply with quote

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 Sad
_________________
Yeah!
Back to top
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Fri Oct 06, 2006 11:08 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Justdabomb2
Voice


Joined: 29 Sep 2006
Posts: 37
Location: United States of America

PostPosted: Sun Oct 08, 2006 3:30 am    Post subject: ... Reply with quote

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. Sad
_________________
Yeah!
Back to top
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Sun Oct 08, 2006 6:23 pm    Post subject: Reply with quote

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.
Back to top
View user's profile Send private message
Justdabomb2
Voice


Joined: 29 Sep 2006
Posts: 37
Location: United States of America

PostPosted: Sun Oct 08, 2006 6:28 pm    Post subject: Reply with quote

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!
Back to top
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Sun Oct 08, 2006 7:10 pm    Post subject: Reply with quote

What delete thing? Show us what you mean and your code.
Back to top
View user's profile Send private message
Justdabomb2
Voice


Joined: 29 Sep 2006
Posts: 37
Location: United States of America

PostPosted: Sun Oct 08, 2006 7:14 pm    Post subject: Reply with quote

remember my thread about trying to make a proc to delete a line with the specified nick from the file?
_________________
Yeah!
Back to top
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger
Justdabomb2
Voice


Joined: 29 Sep 2006
Posts: 37
Location: United States of America

PostPosted: Tue Oct 10, 2006 9:57 pm    Post subject: It's on Reply with quote

Hey, the new script is on the archive now, tell me what you think of this one okay. Thanks! Smile
_________________
Yeah!
Back to top
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger
rosc2112
Revered One


Joined: 19 Feb 2006
Posts: 1454
Location: Northeast Pennsylvania

PostPosted: Wed Oct 11, 2006 5:09 pm    Post subject: Reply with quote

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:

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

Try something like:
Code:

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:


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:

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..."
         }
}
Back to top
View user's profile Send private message
monie089
Halfop


Joined: 29 Jul 2006
Posts: 76

PostPosted: Fri Oct 13, 2006 6:29 am    Post subject: Reply with quote

Code:

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
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Script Support & Releases All times are GMT - 4 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Forum hosting provided by Reverse.net

Powered by phpBB © 2001, 2005 phpBB Group
subGreen style by ktauber