|
DuXxXieJ
|
DuXxXieJ
|
Hello, I've tried to rewrite my quotes script (just using a .txt) to let it use .ini now, but I've got one problem using $readini, which is the following: Let's say I want to read 2=second test line. from ALL sections ( [ThisThingy]). So, I've got: $readini(%ini.quotes, <what am I supposed to put here?>, $2) Let's say I'm testing it, so I've changed the part of <what am i...> to '#Channel1' which is a real section: [#Channel1]
1=first test line
2=second test line
3=third test line.
[#Channel2]
4=fourth test line.
5=fifth test line . This way it works fine, my bot now says 'QUOTE 2: second test line.'. Ofcourse it doesn't work when I change #Channel1 to #Channel2, because there's no '2'. I'd like the $readini to read from ALL sections. I've read the mIRC help file, but I only saw the $readini(mIRC.ini, mIRC, nick) which I am using and something about the n and p switch, which shouldnt help my problem. I'd like this because I'm also using a channel-only function. Let's say: .quote #testchannel 2 - Now it reads '2' from #testchannel, but when no channel is specified, I'd like it to read from ALL sections. %ini.quotes is an variable which returns the specified .ini file. Possible?
Last edited by DuXxXieJ; 13/01/11 08:19 PM.
|
|
|
|
Joined: Jul 2007
Posts: 1,124
Hoopy frood
|
Hoopy frood
Joined: Jul 2007
Posts: 1,124 |
alias read {
if ($1) {
var %r = 1
while ($ini(file.ini,$1,%r)) {
echo -s $+($v1,=,$readini(file.ini,$1,$v1))
inc %r
}
}
else {
.play -s file.ini 1500
}
} will read all the topics under the section. If no $1 is specified, it'll play all the sections via your status window. Change file.ini to your actual ini file name.
|
|
|
|
Joined: Nov 2006
Posts: 1,552
Hoopy frood
|
Hoopy frood
Joined: Nov 2006
Posts: 1,552 |
There's no native command to read a specific/random line from all sections of an ini. Anyway, here's a quick scribble: ; $readallini(<file>,[line])
; [line] can be:
; - a positive integer to return data of that line counting top-bottom
; - a negative integer to return data of that line counting bottom-top
; - 0 to return the total number of lines
; - nothing to return data of a random line
alias readallini {
; any lines in <file>
if ($lines($1)) {
; filter to a tempfile, exclude lines starting with "[" and blank lines
filter -ffcxg $qt($1) readallini.tmp ^\[|^$
; any lines remaining
if ($filtered) {
; second parameter is 0: return total
if ($2 == 0) { return $filtered }
; no or invalid second parameter: return random
elseif ($2 !isnum) { return $gettok($read(readallini.tmp,n),2-,61) }
; second parameter is a positive number: return that line
elseif ($2 > 0) { return $gettok($read(readallini.tmp,n,$v1),2-,61) }
; second parameter is a negativenumber: return that-last line
elseif ($calc($filtered + $2 +1) > 0) { return $gettok($read(readallini.tmp,n,$v1),2-,61) }
}
}
}
|
|
|
|
DuXxXieJ
|
DuXxXieJ
|
Thanks Horstl!
Last edited by DuXxXieJ; 14/01/11 11:43 AM.
|
|
|
|
Joined: Jul 2007
Posts: 1,124
Hoopy frood
|
Hoopy frood
Joined: Jul 2007
Posts: 1,124 |
You only give thanks to the one whose code works for you and undermine the other. Thanks for being biased.
|
|
|
|
DuXxXieJ
|
DuXxXieJ
|
Oh, I'm sorry. I didn't see your post. Well, thanks anyway :P.
Got one question again; I'd like to search for quotes. Like, !search speaker. It has to return the top 5 results. Tried it with $read, but that only returns the first result and I'm not that good with $read etc. Any help?
|
|
|
|
Joined: Jan 2007
Posts: 1,155
Hoopy frood
|
Hoopy frood
Joined: Jan 2007
Posts: 1,155 |
What defines them as the top5? Would they be #1 in each channel? $read doesn't work right with ini files. That is what $readini and $ini is for. File.ini [Topic] item=data $readini(file.ini,section,item) = data Use $ini to find information in your ini file if you dont have a direct path to "data", or want information other than "data". $ini(file,topic/N,item/N)
Returns the name/Nth position of the specified topic/item in an ini/text file.
$ini(mirc.ini,0) returns total number of topics in mirc.ini
$ini(mirc.ini,1) returns name of 1st topic in mirc.ini
$ini(mirc.ini,help) returns Nth position of topic help if it exists, or returns 0 if it doesn't exist
The item/N parameter is optional. If you specify N = 0, it returns the total number of topics/items.
With $readini you have to have the actual values, you cannot use $readini to tell you what the 1st item is or how many items there are in a topic. You use $ini for that. So if you want the 1st data in each topic, you have to use $ini to return the 1st item name, then $readini to return the data for that item. I think your overall problem is how you want to organize your ini file. I'd suggest numbering them consistently within each topic (Channel). Which means [#Channel1] 1=first test line chan1 2=second test line chan1 3=third test line. chan1 [#Channel2] 1=first test line. chan2 2=second test line chan2 3=third test line chan2 If you want, you can make a seperate topic named Top5 which has the 5 favorite quotes, or you can use a while loop to find the top results for each channel. This code will scan your file.ini and return the 1st items data for each topic. ;find how many topics
var %ini = $ini(file.ini,0), %x = 1, %topic, %item
while (%x <= %ini) {
;Loop through topics to gather data from each one.
;Topic %x
%topic = $ini(file.ini,%x)
echo -a Topic %x is %topic
%item = $ini(file.ini,%topic,1)
;%item = 1st item under %topic
echo -a Result %x : $readini(file.ini,%topic,%item)
;return the first item under %topic
inc %x
}
|
|
|
|
|