mIRC Home    About    Download    Register    News    Help

Print Thread
#164328 10/11/06 05:25 PM
Joined: Oct 2006
Posts: 23
F
Ameglian cow
OP Offline
Ameglian cow
F
Joined: Oct 2006
Posts: 23
Code:

on *:TEXT:*:#: { 

  if ($strip($$1) == !addictionary) { 
    write txt\dictionary.txt $2-
    msg $chan 3done }

    ;logs which user who enters what in the dictionary wont be displayd at "!dictionary ***"
    write txt\bgdictionary.txt $2- :: added by $nick <--> IP: $ip <--> HOST: $host <--> ADDRESS: $address <--> DATE AND TIME:  $date $time
  }

  if ($strip($$1) == !dictionary) { 
    msg $chan 3 $+ $2 $read(txt\dictionary.txt, s, $2 ) 
  }    

}




how can I make the seach string loop through the whole file and then post all lines that it can find, at the moment it stops at the first hit,
and i want to have "->" as a separator between the search string and the content of the dictionary, so I would like the script to reject any line that doesent contain "->"

and I would also want that when someone makes a search for something, that arent in the dictionary, it will return " $2 couldent be found in the dictionary" or something similar.

Im sorry for the shitty explanations, i hope you understand :P

thanks in advance

Joined: Aug 2005
Posts: 1,052
L
Hoopy frood
Offline
Hoopy frood
L
Joined: Aug 2005
Posts: 1,052
Well without having the mIRC help file to guide me not being at home all I can say real quick here is a small example of a loop

on *:TEXT:*:#:{
if ($1 == !Dictionary) {
var %x = 1
while (%x <= $read($mircdirtxt\dictionary.txt)) {
msg # $read($mircdirtxt\dictionary.txt,%x)
inc %x
}
}
}
this would loop through the whole txt file and read it ALL back to me but simple if statements can be added like

if (-> isin $read($mircdirtxt\dictionary.txt,%x)) { msg # $read($mircdirtxt\dictionary.txt,%x) | inc %x }

now as far as looping through a .txt file while searchign there has to be a method perhaps $read(txtfile,sw,$+(*,$2,*)) possibly an Nth can be added at the end like %x in my example if not then probably theres a different method but to be @ a 100% certainty I would need the help file to look over search strings.

Im just bored so I had to think on how to create such a script.


Code:
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
Joined: Aug 2004
Posts: 7,252
R
Hoopy frood
Offline
Hoopy frood
R
Joined: Aug 2004
Posts: 7,252
No need for two dictionaries.
Here's a re-write based on your original code.
Please note that $ip and $host return your information, not the ip/host of the person using the command.
Code:
 on *:TEXT:*:#: { 
  if ($strip($1) == !addictionary) { 
    write txt\bgdictionary.txt $2- :: added by $nick &lt;--&gt; IP: $ip &lt;--&gt; HOST: $host &lt;--&gt; ADDRESS: $address &lt;--&gt; DATE AND TIME:  $date $time
    msg $chan 3 done
  }
  ;logs which user who enters what in the dictionary wont be displayd at "!dictionary ***"
  elseif ($strip($1) == !dictionary) { 
    unset %found
    var %a = 1, %b = $lines(txt\bgdictionary.txt)
    while %a &lt;= %b {
      var %line = $read(txt\bgdictionary.txt,s,$2,%a)
      if (-&gt; isin %line) {
        msg $chan 3 $+ $2  $gettok(%line,1,58)
        set %found $true
      }
      inc %a
    }
    if !%found {      .msg $chan 3 $2 Not Found    }
  }    
}
 


I also did a re-write so that it uses a hash table, rather than a text file. Here's the code for that.
Code:
 on *:start:{
  if !$hget(Dictionary) { .hmake Dictionary 100 }
  if $exists(Dictionary.hsh) { .hload Dictionary Dictionary.hsh }
}
on *:exit:{
  .hsave -o Dictionary Dictionary.hsh
}
on *:disconnect:{
  .hsave -o Dictionary Dictionary.hsh
}
on *:TEXT:*:#: { 
  if ($strip($1) == !addictionary) { 
    .hadd -m Dictionary $qt($2-) added by $nick ADDRESS: $address DATE AND TIME:  $date $time
    msg $chan 3 done
  }
  ;logs which user who enters what in the dictionary wont be displayd at "!dictionary ***"
  elseif ($strip($1) == !dictionary) { 
    unset %found
    var %a = 1, %b = $hget(dictionary,0).items
    while %a &lt;= %b {
      msg $chan 3 $+ $2  $hget(Dictionary,$hfind(Dictionary,$2-,%a))
      set %found $true
      inc %a
    }
    if !%found {      .msg $chan 3 $2 Not Found    }
  }
}
 

I didn't include the IP/Host information, per my earlier statement that that information would be inaccurate in regards to what I think you were wanting to record.

Joined: Oct 2006
Posts: 23
F
Ameglian cow
OP Offline
Ameglian cow
F
Joined: Oct 2006
Posts: 23
going with the hash table.

I had no idea that $ip and $host worked that way, so no, I don't need those then. :tongue:

but theres some problem with the $hget, it cant find any lines in the dictionary smirk
doesent mather what the searchstring is, ti will only return "$2 Not Found" frown

Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Make sure you are not mistaking $hget for $hfind. $hget requires you to use the exact item name to get the data. If you don't want to use the exact name, then you should use $hfind.


Invision Support
#Invision on irc.irchighway.net
Joined: Oct 2003
Posts: 313
S
Fjord artisan
Offline
Fjord artisan
S
Joined: Oct 2003
Posts: 313
Not that this is the problem, but I'm guessing the error message is giving $2 because there is a colour code immediately in front of it.

It might help you work out why it's giving that error if you remove the colour from before the $2 (or alternatively use a well-placed $+ )


Sais
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Also, there is a problem with RusselB's hadd... It has no item name, which is probably the problem.

.hadd -m Dictionary $qt($2-) added by $nick ADDRESS: $address DATE AND TIME: $date $time

Let's say someone did !addictionary this is a quote

The item name would be "this (including the quote). The data for that item would be is a quote" added by $nick ADDRESS: $address DATE AND TIME: $date $time

You can't $hfind that because part of what you're searching for is in the item name instead of the data.

Instead, you need to include an item name. If you want to just use numbers, you can do something like:
Code:
.hadd -m Dictionary $calc($hget(Dictionary,0).item + 1) $qt($2-) added by $nick ADDRESS: $address DATE AND TIME:  $date $time


As long as you aren't deleting quotes, that will work fine. If you are deleting them, then you'll want to have it verify that you don't alreayd have a quote using the number chosen...

Code:
var %quotenum = $calc($hget(Dictionary,0).item + 1)
while ($hget(Dictionary,%quotenum)) {
  inc %quotenum
}
.hadd -m Dictionary %quotenum $qt($2-) added by $nick ADDRESS: $address DATE AND TIME:  $date $time


That will make certain that you are not accidentally overwriting a previous quote. This would probably be the best choice even if you don't plan to delete quotes.


EDIT: As a note, if you are using this as a dictionary rather than a quote script (where someone would look up an actual word and not a phrase), then I would suggest this:

Code:
.hadd -m Dictionary $2 $qt($3-) added by $nick ADDRESS: $address DATE AND TIME:  $date $time


This will let you use $hget(Dictionary,$2) to display the definition because $2 would be the item name and $3- would be the definition (in quotes). No need for $hfind. The issue was really the quotes, I think.

Last edited by Riamus2; 11/11/06 07:17 PM.

Invision Support
#Invision on irc.irchighway.net

Link Copied to Clipboard