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 

Write and Read

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


Joined: 07 Aug 2007
Posts: 67

PostPosted: Fri Aug 31, 2007 2:27 pm    Post subject: Write and Read Reply with quote

Good evening Smile

I've the following Code done by myself, which i'm proud of ^^

Code:

bind pubm - "*" pub_write

proc pub_write {nick uhost hand chan text} {
set text [stripcodes bcruag $text]
if {$nick == "Blub" & $chan == "#testchan"} {
set text [split $text "\n"]
foreach line $text {
set fileId [open test.txt "a"]
puts $fileId $text
close $fileId
  }
 }
}


Each line of Nick=Blub is written into the test.txt

This looks like:

Quote:

{[Spain2007] Family.and.Friends.2007}


1st Question: Is it "normal" that those Brackets {} have been added automaticly ?

2nd: In near future the list will be getting longer and longer

Is it possible to search in this .txt File. although there are those Brackets and how could a searche engine look like eg:

!search spain or !search family so that every line will be printed that contains a Word of the .txt File in a Channel

Please help Smile

Kind Regards
Back to top
View user's profile Send private message
nml375
Revered One


Joined: 04 Aug 2006
Posts: 2857

PostPosted: Fri Aug 31, 2007 2:45 pm    Post subject: Reply with quote

1: Those are added since you are converting the text-line into a list (splitting by newline). Since the text-parameter will always contain a single line, I'm not sure this is what you intended. {} would be added to encapsulate the list item (the text string) whenever it contains any "special" characters or whitespaces that would otherwize interfere with list structures.

2: Searching would be quite possible using various commands such as "string match". Concern must however be taken to whatever format is used when lines were added. I would however suggest adding lines of text, rather than lines of lists.

Also, your foreach-list is flawed, as you use the variable "text" within the loop rather than the iterated variable "line". Furthermore, you'd be better off opening and closing the file outside the loop.

Even further, & is "bit-wize and-operator", and is not recommended for logical comparisons, use && instead. Also considder using "string equal" to allow non case-sensitive comparisons.

Finally, as stated in answer to q; "text" will always contain one single line, so using that foreach-loop along with splitting is completely pointless.

I'd suggest something like this instead:
Code:
bind pubm - "*" pub_write

proc pub_write {nick uhost hand chan text} {
 set text [stripcodes bcruag $text]
 if {[string equal -nocase $nick "Blub"] && [string equal -nocase $chan "#testchan"]} {
  set fileId [open test.txt "a"]
  puts $fileId $text
  close $fileId
 }
}


Searching in this case would be a matter of opening the file, read one line at a time using gets, and check it against your credentials..
Another option might be to open it and read all data using the "read" command, then split the data on newlines, and use lsearch..
_________________
NML_375, idling at #eggdrop@IrcNET
Back to top
View user's profile Send private message
Elfriede
Halfop


Joined: 07 Aug 2007
Posts: 67

PostPosted: Fri Aug 31, 2007 4:50 pm    Post subject: Reply with quote

Thank you very much ! Especially for detailed answer!
I've now changed the Code Smile

Can someone please give me an example, how the search can work ? Smile

Quote:

[Spain2007] Family.and.Friends.2007
[GB2004] Tim.Tom.Sabine.2004
[Italy1998] Grandmother.Uncle.and.ugly.wife1998 ^^


eg: posted above:

!search Family or !search Grandmother.Uncle - including two or more Words in the search.

I'm sorry for asking, but i have absolutely no idea Sad
[/quote]
Back to top
View user's profile Send private message
awyeah
Revered One


Joined: 26 Apr 2004
Posts: 1580
Location: Switzerland

PostPosted: Sat Sep 01, 2007 4:19 pm    Post subject: Reply with quote

To match these strings, you can use something like this:

Code:

if {[regexp {^[A-Z]$} [string index $text 0]] && [regexp -nocase {^[a-z.]{1,}$} [string range $text 1 end-4]] && [regexp {^[0-9]{4}$} [string range $text end-3 end]]} {


Might not be the best of solutions, (not a regexp pro).. but should do the job for you.
_________________
·­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
Elfriede
Halfop


Joined: 07 Aug 2007
Posts: 67

PostPosted: Tue Sep 04, 2007 6:37 am    Post subject: Reply with quote

Thank you very much, but i am sorry to say that i've no idea for the rest of the Code Sad

Can someone please help me ? Smile
Back to top
View user's profile Send private message
awyeah
Revered One


Joined: 26 Apr 2004
Posts: 1580
Location: Switzerland

PostPosted: Tue Sep 04, 2007 8:20 am    Post subject: Reply with quote

Err sorry, my last post was to tell you, how to match those three lines, for that I gave you a regexp code.

Now what is it, that you want your script to do? I don't clearly understand your purpose.
_________________
·­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
Elfriede
Halfop


Joined: 07 Aug 2007
Posts: 67

PostPosted: Tue Sep 04, 2007 9:19 am    Post subject: Reply with quote

Those three lines are examples of the content. I would like to have .. i don't how its correctly called.. a search engine.

A search Engine, that reads the complete text file and print those lines, that includes the Matchword(s).

edit: Maybe someone can help me another way. I have exactly found, what i was looking for, BUT the Code is written in Mirc Sad Maybe somone please can change the following lines to tcl

Code:

;# Command: !search <Search String>
on *:TEXT:!search*:#:{
  if ($2-) Mod.Search.aTXT Test.txt $chan $ifmatch
  else .notice $nick Enter Search String!
}

;# Befehl: /Mod.Search.aTXT <TXT File> <#Channel> <Search String>
alias Mod.Search.aTXT {
  var %a = 1, %b = $lines($1), %text = $strip($3-)
  while (%a <= %b) {
    if (%text $iif($chr(42) isin %text, iswm, isin) $read($1, %a)) msg $2 $v2
    inc %a
  }
}
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