mIRC Home    About    Download    Register    News    Help

Print Thread
Page 1 of 2 1 2
Help with $read #128617 27/08/05 11:02 PM
Joined: Aug 2005
Posts: 525
S
schaefer31 Offline OP
Fjord artisan
OP Offline
Fjord artisan
S
Joined: Aug 2005
Posts: 525
Hi, I have a text file that keeps a list of username and ips. In the list are some duplicate names but with a different ip. I have a command !search <name> that searches the text for the name and then messages the result to the channel. But the problem is that it only returns the first result found and not all of them. How can it be changed to return all results found?

Example

[Joe] !search Joe
[Me] 3 results found for 'Joe'
[Me] Joe - 127.0.0.1
[Me] Joe - 192.168.1.1
[Me] Joe - 192.168.254.254
[Me] Finished search database.

Here is my code

on 1:text:!search *:#mychannel:{
msg #mychannel $read(database.txt,w,$2)
}

I looked in mirc help but I did not find anything that helps, I am not very good at mirc scripting.


Also, how can I make an autoresponse in query if the first character of a message is not an exclamation point ( ! ).

I tried this but it doesn't work

on 1:text:*:?:{
if ($right($1,1) != $chr(33)) { msg $nick You are talking to a bot. }
}

Re: Help with $read #128618 27/08/05 11:54 PM
Joined: Aug 2003
Posts: 65
B
bynw Offline
Babel fish
Offline
Babel fish
B
Joined: Aug 2003
Posts: 65
I'm not sure if that can be done with $read. As it only finds the 1st instance of the search parameter. You COULD put all of the ips after one another in the text file.

Like joe - 127.0.0.1, 192.168.1.1, 192.168.254.254

Then it would return all of them.

Re: Help with $read #128619 28/08/05 12:05 AM
Joined: Aug 2005
Posts: 525
S
schaefer31 Offline OP
Fjord artisan
OP Offline
Fjord artisan
S
Joined: Aug 2005
Posts: 525
Well if not $read then is there something else that can do it? I would rather keep the format the same rather than put all IP in one line. The list is big and only gets bigger, I would have to manually change the format because it puts the IP in the list automatically on join.

Re: Help with $read #128620 28/08/05 03:23 AM
Joined: Aug 2005
Posts: 1,052
L
Lpfix5 Offline
Hoopy frood
Offline
Hoopy frood
L
Joined: Aug 2005
Posts: 1,052
Quote:
Well if not $read then is there something else that can do it? I would rather keep the format the same rather than put all IP in one line. The list is big and only gets bigger, I would have to manually change the format because it puts the IP in the list automatically on join.


Maybe not read but $readini yes for example you would write a new ini or too ini with this

/writeini -n <inifile> <section> <item> <value>

example

/writeini -n test.ini JOE 1 194.492.49.34
/writeini -n test.ini JOE 2 293.492.49.32

you can make that a script if you want smile so now you've create a ini with a Section called [JOE] and with 2 values in it which is the 2 ips you wrote.....

then to read the whole list back to channel you create a varible script with ini calc and $readini script as follows, note this is a cheap one just to show you the principal of it, im sure your a good script'er(sp?) you know the drill change channel names or make variables etc...
Code:
on *:TEXT:!search*:*: {
  %iplist.inc = 1
  %iplist.name = $2
  %iplist.inicalc = $ini(test.ini,%iplist.name,0)
  msg #mychan Scanning ( $+ %iplist.name $+ ) $+ ... please wait!
  .timernoresult 1 5 //msg #mychan No Results found for ( $+ %iplist.name $+ ) $+ .
  :NEXT
  msg #mychan $readini(test.ini,%iplist.name,%iplist.inc)
  if (%iplist.inc = %iplist.inicalc) { goto END }
  else {
    .timernoresult off
    inc %iplist.inc
    goto NEXT
  }
  :END
  msg #mychan ( $+ %iplist.inicalc $+ ) results were found on ( $+ %iplist.name $+ )
  unset %iplist*
}


***************UNTESTED***************
im almost next to certain its what your aiming for :P
*******************************************


Code:
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
Re: Help with $read #128621 28/08/05 04:39 AM
Joined: Aug 2005
Posts: 525
S
schaefer31 Offline OP
Fjord artisan
OP Offline
Fjord artisan
S
Joined: Aug 2005
Posts: 525
Your script works how I described, but not entirely.

It works only if you first do the /writeini which is a problem for me, because there are already many many lines of names and ip in a text file, and I would have to convert them all to the format you're using. It also does not auto-increment the line # and I'd have to remember what the next line # is. This would be a tedious process. I'd rather keep the format I already have.

I know there must be some way to do this, as I've seen similar things in other channels but the people were not very willing to help.

Sorry, I do not know much about mirc scripting so I am a bit clueless as to what to do.

Last edited by schaefer31; 28/08/05 04:41 AM.
Re: Help with $read #128622 28/08/05 05:08 AM
Joined: Aug 2005
Posts: 1,052
L
Lpfix5 Offline
Hoopy frood
Offline
Hoopy frood
L
Joined: Aug 2005
Posts: 1,052
Quote:
Your script works how I described, but not entirely.

It works only if you first do the /writeini which is a problem for me, because there are already many many lines of names and ip in a text file, and I would have to convert them all to the format you're using. It also does not auto-increment the line # and I'd have to remember what the next line # is. This would be a tedious process. I'd rather keep the format I already have.

I know there must be some way to do this, as I've seen similar things in other channels but the people were not very willing to help.

Sorry, I do not know much about mirc scripting so I am a bit clueless as to what to do.


thats why i said you can make an alias for add example... to have an alias incremiment the line and all you do is type

/ipadd nickname iphere

Code:
alias ipadd {
  %ipadd.nick = $1
  %ipadd.inicalc = $ini(test.ini,%ipadd.nick,0)
  if (%ipadd.inicalc = 0) { writeini test.ini %ipadd.nick 1 $2- }
  elseif (%ipadd.inicalc &gt; 0) { %ipadd.inicalc = $calc( 1 + $ini(test.ini,%ipadd.nick,0)) 
    writeini test.ini %ipadd.nick %ipadd.inicalc $2-
  }


again this can be put in a longer script another example

this is for a bot just an example again

on 100:text:*:?: {
if ($1 == ADD) { $ipadd $2 $3 }
}

theres various ways to do it...

a text file is bulky plus if.. you do writeini it writes new sections in brackets making it easier to read

Last edited by Lpfix5; 28/08/05 05:22 AM.

Code:
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
Re: Help with $read #128623 28/08/05 02:18 PM
Joined: Apr 2003
Posts: 701
K
Kelder Offline
Hoopy frood
Offline
Hoopy frood
K
Joined: Apr 2003
Posts: 701
Code:
on 1:text:!search *:#mychannel:{
  var %rn = 1
  while ($read(database.txt,w,$2, %rn)) {
    msg $chan $v1
    var %rn = $readn + 1
  }
  msg $chan Finished database search.
}


Doesn't give you the number of results though.

Re: Help with $read #128624 28/08/05 03:46 PM
Joined: Aug 2005
Posts: 525
S
schaefer31 Offline OP
Fjord artisan
OP Offline
Fjord artisan
S
Joined: Aug 2005
Posts: 525
Lpfix5, I think I've found a way to adapt the database to the script you've made, but have a couple questions.

When I do /ipadd for a Name that does not already exist in the list, it adds the [Name] section but then adds the IP twice, so it does

[Name]
0=123.123.123.123
1=123.123.123.123

I don't really understand your script fully so I don't know how to fix this.


Also Is it possible to check for duplicates when doing the /ipadd ? If there's a duplicate then it sends a notice to self and does not add the ip.

Last edited by schaefer31; 28/08/05 03:56 PM.
Re: Help with $read #128625 28/08/05 04:02 PM
Joined: Aug 2005
Posts: 1,052
L
Lpfix5 Offline
Hoopy frood
Offline
Hoopy frood
L
Joined: Aug 2005
Posts: 1,052
Quote:
Lpfix5, I think I've found a way to adapt the database to the script you've made, but have a couple questions.

When I do /ipadd for a Name that does not already exist in the list, it adds the [Name] section but then adds the IP twice, so it does

[Name]
0=123.123.123.123
1=123.123.123.123

I don't really understand your script fully so I don't know how to fix this.


Also Is it possible to check for duplicates when doing the /ipadd ? If there's a duplicate then it sends a notice to self and does not add the ip.


Yeah there is btw i like people like atleast you profile says newbie but you try smile!

here you go mate

Code:
alias ipadd {
  %ipadd.nick = $1
  %ipadd.inicalc = $ini(test.ini,%ipadd.nick,0)
  %ipadd.ip = $2
  if (%ipadd.ip iswm $readini(test.ini,%ipadd.nick,%ipadd.inicalc)) { echo -a --**IP is already found in list**-- }
  if (%ipadd.inicalc = 0) { writeini test.ini %ipadd.nick 1 $2- }
  elseif (%ipadd.inicalc &gt; 0) { %ipadd.inicalc = $calc( 1 + $ini(test.ini,%ipadd.nick,0)) 
    writeini test.ini %ipadd.nick %ipadd.inicalc $2-
  }
unset %ipadd*
}


O i c you just edited your post, anyhoo it shouldnt duplicate if you have my recent code and not the first one i posted which you may have because i edited my post i forgot something important..

see this is what happens when i

/ipadd JOE 304.24.4.4
/ipadd david 203.233.532.55
/ipadd doug 320.320.244.9
/ipadd andre 034.42.42.42

it returns ini ini file

[JOE]
1=304.24.4.4
[david]
1=203.233.532.55
[doug]
1=320.320.244.9
[andre]
1=034.42.42.42

however if i do those commands again i get a notice because of same ip

but... if i add a new ip to nickname then it becomes second line not duplicate

Last edited by Lpfix5; 28/08/05 04:09 PM.

Code:
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
Re: Help with $read #128626 28/08/05 04:20 PM
Joined: Aug 2005
Posts: 525
S
schaefer31 Offline OP
Fjord artisan
OP Offline
Fjord artisan
S
Joined: Aug 2005
Posts: 525
Hey, it still has small problem. When adding a duplicate IP it does give a notice, but it still writes the duplicate IP to the ini file. Everything else works nice!

I do try to fix if I know how, but I am only just starting to learn mirc scripting, so I don't know much yet.

Thanks for helping.

Re: Help with $read #128627 28/08/05 04:27 PM
Joined: Aug 2005
Posts: 1,052
L
Lpfix5 Offline
Hoopy frood
Offline
Hoopy frood
L
Joined: Aug 2005
Posts: 1,052
oops i didnt click on edit button it created a second file sorry

Last edited by Lpfix5; 28/08/05 04:28 PM.

Code:
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
Re: Help with $read #128628 28/08/05 04:28 PM
Joined: Aug 2005
Posts: 1,052
L
Lpfix5 Offline
Hoopy frood
Offline
Hoopy frood
L
Joined: Aug 2005
Posts: 1,052
Here's a breakdown of my script for you smile note all my commands that are written below the values are meant for on top of the note like alias ipadd {
; sflkfsajfsalkfasfas will be meant for alias ipadd {

alias ipadd {
; create a new alias named ipadd to be used with /ipadd
%ipadd.nick = $1
; Creates a variable with the first word said after /ipadd in this case its /ipadd nickname
%ipadd.inicalc = $ini(test.ini,%ipadd.nick,0)
; Calculates the lines that are in the test.ini at section %ipadd.nick which is the variable on top which means again its the nick you type by adding a ,0 after it it caculates the lines total only in that section
%ipadd.ip = $2
; This is the new section you wanted , variable created so it captures ip ex:. /ipadd nickname 127.0.0.1
if (%ipadd.ip iswm $readini(test.ini,%ipadd.nick,%ipadd.inicalc)) { echo -a --**IP is already found in list**-- }
; this means if ip is wildcard match in the test.ini in section [nickname] it echo's in active window --**IP is already found in list**-- <<<fully customizable btw.
if (%ipadd.inicalc = 0) { writeini test.ini %ipadd.nick 1 $2- }
; if the calculation of test.ini has NO nickname registered when you do /ipadd completenewnickname iphere. it then at this times write's the test.ini with nickname and automatically assigns it position 1 in a new section
elseif (%ipadd.inicalc > 0) { %ipadd.inicalc = $calc( 1 + $ini(test.ini,%ipadd.nick,0))
writeini test.ini %ipadd.nick %ipadd.inicalc $2-
}
; else... if my ini calculation has a value 1 2 3 4 .... like
[nick]
1=blah
2=blah
and is set has if larger then 0 << by looking at the other if command on top you will understand where 0 comes from, then perform this command... so it takes the calculation of lines in the section of the ini example 3 and does a simple 1st grade calculation 3 + 1 which 3 would be the lines that already exist, then by having it automatically calculate one it will write the new 4th value...

unset %ipadd*
; unsets all variables that begin with %ipadd
}

enjoy and have fun scripting

um it shouldnt overwrite... the only reason why i assume it overwrites if your mIRC is sending 2 text at same time do to maybe something like a ON input script or... you have 2 identical scripts make sure alias ipadd is only one... just to try a test rename alias ipadd to ipaddtest and try /ipaddtest ............

Last edited by Lpfix5; 28/08/05 04:30 PM.

Code:
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
Re: Help with $read #128629 28/08/05 04:44 PM
Joined: Aug 2005
Posts: 525
S
schaefer31 Offline OP
Fjord artisan
OP Offline
Fjord artisan
S
Joined: Aug 2005
Posts: 525
Thanks much for explaining!

But I think maybe you misunderstood me.

Your script works great except for when I try to do /ipadd Name IP.

If the IP is a duplicate IP, it echos the message that it is a duplicate however it will still write the duplicate IP to the ini file.

Re: Help with $read #128630 28/08/05 04:49 PM
Joined: Aug 2005
Posts: 1,052
L
Lpfix5 Offline
Hoopy frood
Offline
Hoopy frood
L
Joined: Aug 2005
Posts: 1,052
Quote:
Thanks much for explaining!

But I think maybe you misunderstood me.

Your script works great except for when I try to do /ipadd Name IP.

If the IP is a duplicate IP, it echos the message that it is a duplicate however it will still write the duplicate IP to the ini file.



oh i c i just noticed why just looking at real quickly this is the original line
Code:
if (%ipadd.ip iswm $readini(test.ini,%ipadd.nick,%ipadd.inicalc)) { echo -a --**IP is already found in list**-- }


it should be halted within the same command sorry about that

new code
[code]
if (%ipadd.ip iswm $readini(test.ini,%ipadd.nick,%ipadd.inicalc)) { echo -a --**IP is already found in list**-- | halt }

Last edited by Lpfix5; 28/08/05 04:53 PM.

Code:
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
Re: Help with $read #128631 28/08/05 04:58 PM
Joined: Aug 2005
Posts: 525
S
schaefer31 Offline OP
Fjord artisan
OP Offline
Fjord artisan
S
Joined: Aug 2005
Posts: 525
Thank you very much! It works exactly how I need it to now smile

Your help is very much appreciated.

Re: Help with $read #128632 28/08/05 04:59 PM
Joined: Aug 2005
Posts: 1,052
L
Lpfix5 Offline
Hoopy frood
Offline
Hoopy frood
L
Joined: Aug 2005
Posts: 1,052
Quote:
Thank you very much! It works exactly how I need it to now smile

Your help is very much appreciated.


Your very much welcomed smile happy scripting


Code:
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
Re: Help with $read #128633 28/08/05 09:13 PM
Joined: Aug 2005
Posts: 525
S
schaefer31 Offline OP
Fjord artisan
OP Offline
Fjord artisan
S
Joined: Aug 2005
Posts: 525
Hmm, I've just encountered another problem with it adding duplicates.

When the /ipadd is performed, it appears to check only the newest entry and if it matches the newest entry then it does not add the IP. But if the newest entry is not the same, but entries before the new are match the one being added, it will still add it as a duplicate.

Lol, I don't know if you can understand this or not as I just read it to myself and it's quite confusing. So just in case I'll try a better explanation:

In the database.ini file is the following (example)

[Joe]
1=123.123.123.123
2=1.1.1.1
3=1.2.3.4

When I do the /ipadd it only checks if the 3= is a duplicate of the one being added, and does not check any of the entries before it. So for example if I were to do /ipadd Joe 1.1.1.1 it would add it (even though it already exists as the 2nd entry) because the 3rd entry is not 1.1.1.1 and it completely ignores the first 2 entries.

I've not made any changes to the code other than the ini file name and the channel.

Last edited by schaefer31; 28/08/05 09:16 PM.
Re: Help with $read #128634 28/08/05 09:48 PM
Joined: Aug 2005
Posts: 1,052
L
Lpfix5 Offline
Hoopy frood
Offline
Hoopy frood
L
Joined: Aug 2005
Posts: 1,052
Sorry about that this should work better we will use the $read only this time and do a if ip is in text file which is the ini in theory then return echo blah blah

here is the full alias script

Code:
alias ipadd {
  %ipadd.nick = $1
  %ipadd.inicalc = $ini(test.ini,%ipadd.nick,0)
  %ipadd.ip = $2
  if (%ipadd.ip isin $read(test.ini,w, * $+ %ipadd.ip $+ *)) { echo -a --**IP is already found in list**-- | halt }
  if (%ipadd.inicalc = 0) { writeini test.ini %ipadd.nick 1 $2- }
  elseif (%ipadd.inicalc &gt; 0) { %ipadd.inicalc = $calc( 1 + $ini(test.ini,%ipadd.nick,0)) 
    writeini test.ini %ipadd.nick %ipadd.inicalc $2-
  }
  unset %ipadd*
}


and thanks for pointing that out i was using something similar i just built awhile ago


Code:
if $reality > $fiction { set %sanity Sane }
Else { echo -a *voices* }
Re: Help with $read #128635 29/08/05 01:55 PM
Joined: Oct 2004
Posts: 8,327
Riamus2 Offline
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,327
Just as a note, from your original script for your original text file of data, you can just do this:

Code:
on 1:text:!search *:#mychannel:{
  var %lines = $lines(database.txt)
  var %currentline = 1
  var %total = 0
  while (%currentline &lt;= %lines) {
    var %data = $read(database.txt,w,$2 $+ *,%currentline)
    if (%data != $null) {
      msg #mychannel %data
      inc %total
    }
    var %currentline = $calc($readn + 1)
  }
  msg $mychannel %total found.
}


Using the 4th parameter (a line number) in $read, lets you continue your search starting from a specific line. $readn tells you the most recent line you $read. So, adding 1 to that in your loop will let you continue on.


Invision Support
#Invision on irc.irchighway.net
Re: Help with $read #128636 29/08/05 04:11 PM
Joined: Aug 2005
Posts: 525
S
schaefer31 Offline OP
Fjord artisan
OP Offline
Fjord artisan
S
Joined: Aug 2005
Posts: 525
Thanks for suggestion, I saved it in case I might have use for it later.

Though, I did a brief test and it caused an excess flood after returning the first line.

Page 1 of 2 1 2