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 

[No]greet

 
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help
View previous topic :: View next topic  
Author Message
hakim
Voice


Joined: 23 Apr 2006
Posts: 19

PostPosted: Sat May 20, 2006 10:53 am    Post subject: [No]greet Reply with quote

The script should send notice "greet" to the owner if his hostname is not in the host.db, send "no greet" if it's there, add the hostname to the db, when user msgs "!nogreet" to the bot and remove it from there if he msgs "!greet", but there is something wrong with the script Sad Any help appreciated.
So here is the script:
Code:
#setting channels which will be effected
set channel(one) "#channel"

#sends "greet/nogreet" to owner when he joins the channel
bind join n *!*@* greetuser

proc greetuser {nick uhost hand chan arg } {
   #only if in effected channel
   if {$chan==$channel(one)} {
   #creates host.db if it doesn't exist
   if {![file exists host.db]} {
    set fs [open host.db w]
    puts $fs ""
    close $fs
   }
 set dbfs [open host.db r]
 set tmpfs [open host.tmp w]
 set match 0
 #creates variable userhost, which will be the user host
 set userhost [getchanhost $nick $chan]
 global userhost
   #searches the file for userhost
   while {![eof $dbfs]} {
    if {![gets $dbfs line]} {
      puts $tmpfs "$line"
    } elseif {[lindex $line 0] == $userhost} {
      set match 1
    }
  }
   #if there is no entry, sends "greet"
   if {![match==1]} {
   puthelp "NOTICE Owner :greet"
   #otherwise nogreet
   } elseif {[match==1]} {
   puthelp "NOTICE Owner :nogreet"
   }
   }
      return 0
}

#adds userhost to host.db if user msgs "!nogreet" to bot
bind msg * !nogreet nogreet

proc nogreet { nick uhost hand text arg } {
  #looks if it's not there already
  while {![eof $dbfs]} {
    if {![gets $dbfs line]} {
      puts $tmpfs "$line"
    } elseif {[[lindex $line 0] == $userhost]} {
      }
      else {
      puts $tmpfs "$userhost"
    }
    }
  #writes to host.db
  close $dbfs
  close $tmpfs
  set fs [open host.db.tmp r]
  set hostsdb "[read $fs]"
  close $fs
  set fs [open host.db w]
  puts $fs "$hostsdb"
  close $fs
  return 0
  }
#removes hostname from db, if user msgs "!greet" to bot
bind msg * !greet greet

proc greet { nick uhost hand text arg } {
  set dbfs [open host.db r]
  set tmpfs [open host.db.tmp w]
  #finds and removes entry from db
  while {![eof $dbfs]} {
    if {![gets $dbfs line]} {
      puts $tmpfs "$line"
    } elseif {[lindex $line 0] == $userhost} {
      puts $tmpfs ""
      puthelp "NOTICE Owner :greeting again!"
    }
    }
  close $dbfs
  close $tmpfs
  set fs [open host.db.tmp r]
  set hostsdb "[read $fs]"
  close $fs
  set fs [open host.db w]
  puts $fs "$hostsdb"
  close $fs
  return 0
  }
Back to top
View user's profile Send private message
Alchera
Revered One


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

PostPosted: Sat May 20, 2006 7:12 pm    Post subject: Reply with quote

hakim wrote:
but there is something wrong with the script

Not very informative! Post the results of (via Command Console):
Code:
.set errorInfo

Also post any other relevant information (errors in logs &c).
_________________
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
hakim
Voice


Joined: 23 Apr 2006
Posts: 19

PostPosted: Sun May 21, 2006 10:10 am    Post subject: Reply with quote

The script is very buggy Embarassed
I think I corrected greetuser proc, but I still can't figure out what's wrong with nogreet proc Sad
Corrected greet user (also changed userhost with host. wich is acquired automatically):
Code:
set channel(one) "#channel"

bind join n|- *!*@* greetuser

proc greetuser { nick host hand chan } {
   global channel
   if {$chan==$channel(one)} {
   if {![file exists host.db]} {
    set fs [open host.db w]
    puts $fs ""
    close $fs
   }
 set dbfs [open host.db r]
 set tmpfs [open host.tmp w]
 global match
 set match 0
   while {![eof $dbfs]} {
    if {![gets $dbfs line]} {
      puts $tmpfs "$line"
    } elseif {[lindex $line 0] == $host} {
      set match 1
    }
  }
   if {!$match} {
   puthelp "NOTICE Owner :greet"
   } elseif {[match==1]} {
   puthelp "NOTICE Owner :nogreet"
   }
   }
  close $dbfs
  close $tmpfs
      return 0
}


Error message executing nogreet:
Code:
 Tcl error [nogreet]: invalid command name ""
 invalid command name ""
     while executing
 "[lindex $line 0] == $host"
     (procedure "nogreet" line 9)
     invoked from within
 "nogreet $_msg1 $_msg2 $_msg3 $_msg4"


nogreet proc:
Code:
bind msg * !nogreet nogreet

proc nogreet { nick host hand text } {
 set dbfs [open host.db r]
 set tmpfs [open host.tmp w]
  while {![eof $dbfs]} {
    if {![gets $dbfs line]} {
      puts $tmpfs "$line"
    } elseif {[[lindex $line 0] == $host]} {
      putserv "NOTICE Owner :Nogreet is on. Type !greet to greet again."
      } else {
      puts $tmpfs "$host"
     putserv "NOTICE Owner :turned on nogreet."
    }
    }
  close $dbfs
  close $tmpfs
  set fs [open host.db.tmp r]
  set hostsdb "[read $fs]"
  close $fs
  set fs [open host.db w]
  puts $fs "$hostsdb"
  close $fs
  return 0
  }
Back to top
View user's profile Send private message
Sir_Fz
Revered One


Joined: 27 Apr 2003
Posts: 3793
Location: Lebanon

PostPosted: Sun May 21, 2006 5:07 pm    Post subject: Reply with quote

Code:
elseif {[[lindex $line 0] == $host]}

Look closely into the comparison, is it correct in your opinion? Are the extra brackets needed? It's usually done like this:
Code:
if {$bla == $blo} {

_________________
Follow me on GitHub

- Opposing

Public Tcl scripts
Back to top
View user's profile Send private message Visit poster's website
hakim
Voice


Joined: 23 Apr 2006
Posts: 19

PostPosted: Mon May 22, 2006 10:26 am    Post subject: Reply with quote

Tahnks, Sir_Fz. Well, we live and learn Smile
So, here is the completely working script:
Code:
set channel(one) "#channel_name"

if {![file exists host.db]} {
    set fs [open host.db w]
    puts $fs ""
    close $fs
   }

bind join n|- *!*@* greetuser

proc greetuser { nick host hand chan } {
   global channel
   if {$chan==$channel(one)} {
 set dbfs [open host.db r]
 global match
 set match 0
   while {![eof $dbfs]} {
    gets $dbfs line
    if {[lindex $line 0] == $host} {
      set match 1
    }
  }
   if {!$match} {
   puthelp "NOTICE owners_nick :greet"
   } elseif {$match} {
   puthelp "NOTICE owners_nick :nogreet"
   }
   }
  close $dbfs
      return 0
}

bind msg * !nogreet nogreet

proc nogreet { nick host hand text } {
 set dbfs [open host.db r]
 set tmpfs [open host.db.tmp w]
  while {![eof $dbfs]} {
    if {![gets $dbfs line]} {
      puts $tmpfs "$line"
    } elseif {[lindex $line 0] == $host} {
      puthelp "NOTICE owners_nick :Nogreet is on. Type !greet to greet again."
      } else {
      puts $tmpfs "$host"
    }
    }
  close $dbfs
  close $tmpfs
  set fs [open host.db.tmp r]
  set hostsdb "[read $fs]"
  close $fs
  set fs [open host.db w]
  puts $fs "$hostsdb"
  close $fs
  return 0
  }

bind msg * !greet greet

proc greet { nick host hand text } {
  set dbfs [open host.db r]
  set tmpfs [open host.db.tmp w]

  while {![eof $dbfs]} {
    if {![gets $dbfs line]} {
      puts $tmpfs "$line"
    } elseif {[lindex $line 0] == $host} {
      puts $tmpfs ""
      puthelp "NOTICE Owners_nick :greeting again!"
    }
    }
  close $dbfs
  close $tmpfs
  set fs [open host.db.tmp r]
  set hostsdb "[read $fs]"
  close $fs
  set fs [open host.db w]
  puts $fs "$hostsdb"
  close $fs
  return 0
  }


Bind for greet_user proc can be changed to "bind join - *!*@* greetuser", "Owners_nick" to "$nick", "channel_name" to prefered channel and should work just fine for everyone Wink
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    egghelp.org community Forum Index -> Scripting Help 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