|
Joined: Aug 2004
Posts: 26
Ameglian cow
|
OP
Ameglian cow
Joined: Aug 2004
Posts: 26 |
Hello,
I'm looking for a script where you can do something like !addquote <author> <quote>. E.g: !addquote Brian_K Too much is too much! This quote is then stored to some sort of db with timestamp.
And the !findquote trigger would work something like this; !findquote Too much is too much And the output would look something like this; Too much is too much was added by Brian_K on <time> (xxx minutes/seconds ago)
So..does there exists a script/addon like this ?
|
|
|
|
Joined: Aug 2004
Posts: 26
Ameglian cow
|
OP
Ameglian cow
Joined: Aug 2004
Posts: 26 |
Well, i've looked at that page but didnt really find what i was looking for..
|
|
|
|
Joined: Dec 2002
Posts: 1,922
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 1,922 |
OK, here's your script, hope you will like it. Quotes are stored in the file quotes.txt in the mIRC directory. On *:text:!AddQuote *:#:{
write quotes.txt $ctime $nick $2-
msg # Quote added: $2-
}
On *:text:!FindQuote *:#:{
var %wildcard = & & $2-
var %limit = 5
window -h @@
filter -fw quotes.txt @@ %wildcard
if !$filtered {
msg # No results.
close -@ @@
return
}
var %msg = Found $filtered result(s).
if $filtered > %limit {
%msg = %msg First %limit are shown below $+ .
dline @@ $calc(%limit + 1) $+ -
}
msg # %msg
var %i = 1
while $line(@@, %i) {
tokenize 32 $ifmatch
; $1 = ctime
; $2 = author
; $3- = text
msg # $3- [added by $2 on $asctime($1) $&
( $+ $duration($calc($ctime - $1)) ago)]
inc %i
}
close -@ @@
} Note to IE users: To preserve line-breaks in copied code, paste it first in Wordpad, and from there copy it to the script editor.
|
|
|
|
Joined: Aug 2004
Posts: 26
Ameglian cow
|
OP
Ameglian cow
Joined: Aug 2004
Posts: 26 |
Dude, that seems to be working great! :-)
|
|
|
|
Joined: Sep 2003
Posts: 4,230
Hoopy frood
|
Hoopy frood
Joined: Sep 2003
Posts: 4,230 |
Note to IE users[/u]: To preserve line-breaks in copied code, paste it first in Wordpad, and from there copy it to the script editor.[/color] Im off topic, but i thought id mention, its also easy to just click QUOTE, then just cut and paste from there. then click the back button.
|
|
|
|
Joined: Nov 2004
Posts: 332
Fjord artisan
|
Fjord artisan
Joined: Nov 2004
Posts: 332 |
or you could use a hash table on *:start: { hmake quote 10 } if ($isfile(quotes.hsh)) { hload quote quotes.hsh } else { hadd quote <data name> <value> .... .... .... .... hsave -o quote quotes.hsh } on *:exit:{ hsave -o quote quotes.hsh hfree quote } ; so on etc so it creates the table checks to see if the hashfile exists if it does it loads it otherwise set it to make it via adding all the starting entries you want then it saves the table then on exit it saves the table again in case youve made additions and frees the ram.
then on *:text:!addquote *:*:{ hadd quote $$2- }
on *:text:!findquote *:*:{ var %get = $hget(quote, $$2) ;use the assigned filename for $$2 } { //echo -a %get } ill just say that this is untested and i didnt bother putting in a way to display it to a channel
The Kodokan will move you, one way or another.
|
|
|
|
Joined: Nov 2004
Posts: 332
Fjord artisan
|
Fjord artisan
Joined: Nov 2004
Posts: 332 |
i should probably mention that you must set the size thats the 10 in the very beginning you want it to be the square root of the number of entries you expect the table to hold so 10 for 100 entries
The Kodokan will move you, one way or another.
|
|
|
|
Joined: Feb 2004
Posts: 2,019
Hoopy frood
|
Hoopy frood
Joined: Feb 2004
Posts: 2,019 |
No worries, if you don't specify an N slots, mIRC will make it by default at N = 10, so 100 "slots".
Btw you really ought to read that long dragging post that I replied to you with in that "help" thread, because you are completely misusing the braces.
Normally I wouldn't bother someone with this so much, but it's just aweful to see it, and gets other users the wrong idea of how braces are used.
on *:text:!findquote *:*:{ var %get = $hget(quote, $$2) ;use the assigned filename for $$2 } { //echo -a %get }
Should be
on *:text:!findquote *:*:{ var %get = $hget(quote, $$2) ;use the assigned filename for $$2 echo -a %get } or
on *:text:!findquote *:*: var %get = $hget(quote, $$2) | echo -a %get
or
on *:text:!findquote *:*:{ var %get = $hget(quote, $$2) | echo -a %get }
or
on *:text:!findquote *:*:{ var %get = $hget(quote, $$2) | echo -a %get }
All perfectly legit regarding the braces. Btw you should add a check to see if %get is actually filled with something, or the echo will result in /echo: insufficient parameters, as it will try to echo a $null.
Please read my post, it'll help you, I'm sure.
Greets
Gone.
|
|
|
|
Joined: Nov 2004
Posts: 332
Fjord artisan
|
Fjord artisan
Joined: Nov 2004
Posts: 332 |
excuse the hell out of me with my 2 extra brackets i said it was untested ive never written a hash table before so that was just a off the cuff thing that might help him i keep my edicate equal to my ability so i dont sweat my brackets real hard as long as the code functions which it always does and i dont use pipes edit ps your right that the brackets were wrong but i bet it would still work the reason i think i did them that way was the () which makes me thing comparison and im just tired but thank you for straightening out my mistake
Last edited by ricky_knuckles; 16/01/05 11:47 PM.
The Kodokan will move you, one way or another.
|
|
|
|
Joined: Nov 2004
Posts: 332
Fjord artisan
|
Fjord artisan
Joined: Nov 2004
Posts: 332 |
if i wanted a script to msg someone or a channel with the contents of a variable how would i do that im always worried ill wind up with it msging exactly what i type rather than the value
The Kodokan will move you, one way or another.
|
|
|
|
Joined: Sep 2003
Posts: 4,230
Hoopy frood
|
Hoopy frood
Joined: Sep 2003
Posts: 4,230 |
say you have variable %blah contaning the text "what who where?" set %balh what who where?
from inside a script its just... msg whoever %blah
if u doing that from the editbox in mirc then use //msg whoever %blah ^^ two /
|
|
|
|
Joined: Feb 2004
Posts: 2,019
Hoopy frood
|
Hoopy frood
Joined: Feb 2004
Posts: 2,019 |
mIRC evaluates any variables/identifiers when passes as parameters to a command, so never worry about that.
If you do //var %a = this is a test | echo -a %a
it will echo "this is a test", because the %a is evaluated before passed to the echo internal mechanism.
There are special cases about evaluating and reevaluating and such in timers, scon/scid, but I wouldn't worry about that.
One thing is always true: unless if some special flag is used, or if vars/identifiers are escaped, they will always be evaluated first before being passed to an alias.
Of course, from the editbox, if you specify a single / it doesn't, if you specify a double // then it is like it is triggered from a script.
I suppose the best advice I can give you is: try and find out, experiment, you'll learn a whole lot.
Good luck.
Gone.
|
|
|
|
Joined: Aug 2004
Posts: 26
Ameglian cow
|
OP
Ameglian cow
Joined: Aug 2004
Posts: 26 |
Hmm..whats all this about hash etc? Should these parts be in the script? :]
|
|
|
|
Joined: Feb 2004
Posts: 2,019
Hoopy frood
|
Hoopy frood
Joined: Feb 2004
Posts: 2,019 |
Nah, what Online gave you is fine, using filter and a hidden window is efficient enough. Don't worry, you got the good code Cya
Gone.
|
|
|
|
Joined: Aug 2003
Posts: 1,831
Hoopy frood
|
Hoopy frood
Joined: Aug 2003
Posts: 1,831 |
Not necessarily, unless you have a lot of !findquote'ing going on. Here's another way too, similar to Onlines, but using mIRCs File Handling tools. on *:text:!addquote *:#:{
if $read(quotes.txt,nw,& & $2-) {
msg # Quote $+(",$2-,") already added by $gettok($v1,2,32) on $asctime($gettok($v1,1,32)
}
else {
write Quotes.txt $ctime $nick $2-
msg # Quote added: $+(",$2-,") by $nick
}
}
on *:text:!findquote *:#:{
.fopen quotes quotes.txt
if $ferr { echo -atic Info * Missing Quotes.txt | .fclose quotes | return }
var %i = 1
while ![color:red]$[/color]feof {
.fseek -w quotes & & $+(*,$2-,*)
if $fread(quotes) {
tokenize 32 $v1
msg # Quote: $3- [Added by $2 on $asctime($1) ( $+ $duration($calc($ctime - $1)) ago)]
inc %i
if %i == 5 { break }
}
}
.fclose quotes
if %i == 1 { msg # Quote: $+(",$2-,") not found }
} Ta FO
Last edited by Iori; 17/01/05 12:57 AM.
|
|
|
|
Joined: Jan 2005
Posts: 75
Babel fish
|
Babel fish
Joined: Jan 2005
Posts: 75 |
I like that Iori, but what if a user specifies a number ? ie !findquote 1 and it shows say.. Quote [color:blue]#1 : <j4y> 1st quote :tongue: [Added by bob on Mon Jan 17 15:50:59 2005 (10secs ago)] [/color]
also for adding Quote [color:blue] #1 added: "<j4y> 1st quote :tongue:" by bob [/color]
|
|
|
|
Joined: Aug 2004
Posts: 26
Ameglian cow
|
OP
Ameglian cow
Joined: Aug 2004
Posts: 26 |
Online's little code works great, however i've ran into a few things.. Let's take an example. I add this quote: "Too much is overkill". 1) How can the code be modified so that i can do a "!findquote too much" instead of "!findquote too much*" ? Basicly i'd like to replace all spaces with a * and even add a * at the end of the !findquote trigger.. Tried to play around a little with $replace($1-,$chr(32),$chr(42)) etc, but didnt quite get it.. 2) Is it possible to e.g. type !last plur (plur is a nick), and the script will then paste the 5 last quotes by plur ($2) ?
|
|
|
|
Joined: Nov 2004
Posts: 332
Fjord artisan
|
Fjord artisan
Joined: Nov 2004
Posts: 332 |
bow down to the hash $hfind if you go to www.mirc.net there is a hash tutorial tat helped me immensly im sure you could also sit there and slade or optics or one of the many others will come give you what you need
The Kodokan will move you, one way or another.
|
|
|
|
Joined: Dec 2002
Posts: 1,922
Hoopy frood
|
Hoopy frood
Joined: Dec 2002
Posts: 1,922 |
Thanks everyone for the suggestions. Basicly i'd like to replace all spaces with a * and even add a * at the end of the !findquote trigger Change line 7 to var %wildcard = & & $+(*, $replace($2-, $chr(32), *), *) e.g. type !last plur (plur is a nick), and the script will then paste the 5 last quotes by plur Add this script: On *:text:!last &:#:{
var %wildcard = & $2 *
var %limit = 5
window -h @@
filter -fw quotes.txt @@ %wildcard
if !$filtered {
msg # No results.
close -@ @@
return
}
var %msg = Last quotes by $2:
if $filtered > %limit {
dline @@ 1- $+ $calc($filtered - %limit)
}
msg # %msg
var %i = 1
while $line(@@, %i) {
tokenize 32 $ifmatch
; $1 = ctime
; $2 = author
; $3- = text
msg # $3- [added on $asctime($1) $&
( $+ $duration($calc($ctime - $1)) ago)]
inc %i
}
close -@ @@
} To help keep track of changes, I uploaded a full version of the script here.
|
|
|
|
|