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 

Search and write file.

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


Joined: 20 Mar 2006
Posts: 13

PostPosted: Wed Jul 18, 2007 11:21 am    Post subject: Search and write file. Reply with quote

Hey, I've just done a simple little code and It's working as planned. Although I would like to be able to have X host in the nicks.txt file so that if that same X joins the channel the new nickname of that X will be put in the same line. (associated with the old nicknames) BUT! here's the catch, if X joins with a nickname that is already in the list, I don't want it to be logged as a new nick in nicks.txt

Code:

set nicklista "nicks.txt"

bind join - * join_onjoin

proc join_onjoin {nick uhost hand chan} {
 global nicklista
  set filename $nicklista
  set txt [open $filename "a"]
  puts $txt "$nick $uhost"
  close $txt
}


Has anyone got an idea?
Back to top
View user's profile Send private message
awyeah
Revered One


Joined: 26 Apr 2004
Posts: 1580
Location: Switzerland

PostPosted: Thu Jul 19, 2007 7:31 am    Post subject: Reply with quote

Let me get this straight, if you have an entries in your database, and someone with a different nick and uhost join the channel (corresponding to an old entry in the database with a different nick but same uhost), then if that is what you want you can do this:

Code:

#read data from file
set fp [open $nicklista r]
set data [read -nonewline $fp]
close $fp
set datalist [split $data "\n"]

#if nick is already present in list, halt
foreach user $datalist {
 if {[string equal -nocase "[lindex [split $user] 0]" $nick]} {
  return 0
  }
}

#check if uhost is present in list
foreach host $datalist {
 if {[string equal -nocase "[lindex [split $host] 1]" $uhost]} {
  set host:found 1; break
  }
}

#if uhost present in list delete that line write the new nick and uhost to file
if {[info exists host:found]} {
 set user "$nick $host"
 set i [lsearch -exact [split [string tolower $datalist]] [split $user]]
 set datalist [lsort -unique [lreplace $datalist $i $i]]
 set fp [open $nicklista w]
 puts $fp [join $nicklista "\n"]
 close $fp
}

_________________
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
ipone
Voice


Joined: 20 Mar 2006
Posts: 13

PostPosted: Thu Jul 19, 2007 2:43 pm    Post subject: Reply with quote

Was almost that i where looking for. I was wondering something about this code..
Code:

#if uhost present in list delete that line write the new nick and uhost to file
if {[info exists host:found]} {
 set user "$nick $host"
 set i [lsearch -exact [split [string tolower $datalist]] [split $user]]
 set datalist [lsort -unique [lreplace $datalist $i $i]]
 set fp [open $nicklista w]
 puts $fp [join $nicklista "\n"]
 close $fp
}


That means that the newest nick are going to be in the database?

I want it to store the nicks associated whit the users uhost. for exampel

Iamwithstupid (test@some.host.eu.se) has joined #Testing
then parts and joins with a diffrent nick.
Buzz (test@some.host.eu.se) has joined #Testing

so it would look something like this i the database:
Buzz Iamwithstupid test@some.host.eu.se

Is it even possible? And thank you awyeah for your help so far, iam going to try the code you just wrote and see if i can change it somehow to store all the nicks and uhost on one line.
Back to top
View user's profile Send private message
awyeah
Revered One


Joined: 26 Apr 2004
Posts: 1580
Location: Switzerland

PostPosted: Fri Jul 20, 2007 12:26 am    Post subject: Reply with quote

Well then these won't work if you store 2 nicks and then one host, and then follow up, more nicks and so on for the same host.

Code:

#if nick is already present in list, halt
foreach user $datalist {
 if {[string equal -nocase "[lindex [split $user] 0]" $nick]} {
  return 0
  }
}

#check if uhost is present in list
foreach host $datalist {
 if {[string equal -nocase "[lindex [split $host] 1]" $uhost]} {
  set host:found 1; break
  }
}


Since the database will check the first element for a nick and the second element for a uhost.

You should have a proper format for all database entries, so that they can be differentiated from nicks and uhosts. But then again maybe you can check for the entry with an @, which will be a uhost and then lsearch the entry number in the list and then lindex the list with that entry and get the uhost and then compare it.

However a proper differentiated format would be better. Something like:

Quote:

nick:$uhost
nick1,nick2:$uhost
nick1,nick2,nick3:$uhost


Code:

#If suppose $data is the total data in the file then read the data as a list
#and you can get the nicks and uhosts by:

set nicklist [list]
foreach entry $data {
 lappend nicklist [lindex [split $entry :] 0]
}

set uhostlist [list]
foreach entry $data {
 lappend uhostlist [lindex [split $entry :] 1]
}

#Then you check if the nick is not already in the list
#if nick is already present in list, halt

foreach user $nicklist {
 if {[string match -nocase "*$user*" $nick]} {
  set nickfound 1; break
  }
}
if {![info exists nickfound]} {
 return 0

#find the entry in the nicklist and uhostlist
} else {
 set findnick [lsearch -glob [split [string tolower $nicklist]] *$nick*]
 set finduhost [lsearch -glob [split [string tolower $uhostlist]] *uhost*]
}

#if everything is ok, then proceed
if {$findnick == $finduhost} {

#
#then you can use lreplace to replace the entry however you want
#

_________________
·­awyeah·

==================================
Facebook: jawad@idsia.ch (Jay Dee)
PS: Guys, I don't accept script helps or requests personally anymore.
==================================
Back to top
View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger MSN Messenger
ipone
Voice


Joined: 20 Mar 2006
Posts: 13

PostPosted: Tue Aug 14, 2007 10:00 pm    Post subject: Reply with quote

thats look pretty sweet, but i dont really understand how the tcl file should look like for it to work? im new at this so can u help me with that? i want i to logg the nicks an uhost like nick1,nick2,nick3@$uhost everytime somone joins the channel.. or if someone else have an ide.
Back to top
View user's profile Send private message
ipone
Voice


Joined: 20 Mar 2006
Posts: 13

PostPosted: Wed Aug 22, 2007 9:49 am    Post subject: Reply with quote

Now i have tested many things to make this work, and it just will not work :/
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