mIRC Home    About    Download    Register    News    Help

Print Thread
#133338 19/10/05 04:32 PM
Joined: Apr 2005
Posts: 72
B
Babel fish
OP Offline
Babel fish
B
Joined: Apr 2005
Posts: 72
hello
ich have a pic-channel
there are bots they post new pics in the channel
<@bot1> add house.one.jpg 34kb
<@bot4> add house.two.jpg 50kb
<@bot8> add house.three.jjpg 64kb
<@bot1> update house.one.jpg 60kb

i will update and add KB in a txt or hashtable and with trigger !kb msg in the channel <@bot> there are pics off 198kb
plz help me :-)

thx bodo

#133339 19/10/05 05:04 PM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
I'm not entirely sure what you're asking for... if all you want is a total size for the added pictures, you can do:

Code:
on *:text:add *:[color:red]#yourchan[/color]: {
  if ($3 == $null) {
    .notice $nick Invalid format.  Use:  10add filename size
    return
  }
  if ($hget(PicData,$2) != $null) {
    .notice $nick That picture is already added.  If you want to update the filesize, use:  10update filename size
    return
  }
  AddPicData $2 $3
}

on *:text:update *:[color:red]#yourchan[/color]: {
  if ($3 == $null) {
    .notice $nick Invalid format.  Use:  10update filename size
    return
  }
  if ($hget(PicData,$2) == $null) {
    .notice $nick No data for that picture.  If it's a new picture, use add instead of update.
    return
  }
  AddPicData $2 $3
}

on *:text:!kb:[color:red]#yourchan[/color]: {
  var %c = 1
  var %i = $hget(PicData,0).item
  while (%c &lt;= %i) {
    var %picbytes = %picbytes + $hget(PicData,%c)
    inc %c
  }
  msg $chan There are $bytes(%picbytes).suf of pictures.
}

alias AddPicData {
  if ($hget(PicData,0).item == $null) {
    hmake PicData 20
  }
  if (kb isin $2) { var %picbytes = $remove($2,kb) * 1024 }
  elseif (mb isin $2) { var %picbytes = $calc($remove($2,mb) * 1024 * 1024) }
  else {
    .notice $nick Please include the filesize (in kb or mb) when adding or updating -- Example:  10add pic1.jpg 10kb or 10update pic1.jpg 15kb
    return
  }
  hadd PicData $1 %picbytes
}


The 3 on texts could be placed into a single on text, but I usually like to avoid using * as the trigger followed by if's to determine if the correct trigger was used as it can cause trouble later if someone adds another on text to the same script and I think it's a bit slower that way (though I could be wrong about that part).

Also, note that you may be better off using !update and !add (with the !'s). If you want to do that, just change those triggers. Also, don't forget to change the channel name to yours.

As you can see, I added a lot of "error" messages to the script. If you know there won't be any errors, you can cut the script size down considerably by removing those errors and checks.

Last edited by Riamus2; 19/10/05 06:38 PM.

Invision Support
#Invision on irc.irchighway.net
#133340 19/10/05 06:02 PM
Joined: Apr 2005
Posts: 72
B
Babel fish
OP Offline
Babel fish
B
Joined: Apr 2005
Posts: 72
thx :-) im not good in mirc scripting, i think your script is to
complicated for me ...
i have tried this:
Code:
on *:TEXT:*add*:#: {
  hadd -m pics $nick $remove($3,kb)
}

now i have this in pics.hst:
bot1
147.6
bot2
61.7
bot3
1870.4
bot4
70.4
.
.
now i will add 147.6 + 61.7 + 1870.4 + 70.4 + and so on...=

#133341 19/10/05 06:35 PM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
Here, let me cut out all the "error" messages and explain it. It's actually not a hard-to-understand script. smile

Note that I would recommend using the code above as it will point out errors when someone using the commands incorrectly. I just removed them to make explaining easier. The parts removed are just to display errors if something is done incorrectly.

Code:
on *:text:add *:[color:red]#yourchan[/color]: {
  [color:green]; Halt (return) if there aren't 3 parts to the command (the trigger, the filename, and the size), or if the filename is already in the table.[/color]
  if ($3 == $null || $hget(PicData,$2) != $null) return
  [color:green]; Otherwise, run the alias and send the filename and filesize to the alias.[/color]
  AddPicData $2 $3
}

on *:text:update *:[color:red]#yourchan[/color]: {
  [color:green]; Almost the same as above... halt if there aren't 3 parts, or, in this case, if the filename isn't added yet (you can't update something that isn't there)[/color]
  if ($3 == $null || $hget(PicData,$2) == $null) return
  [color:green]; Otherwise, run the alias (as above)[/color]
  AddPicData $2 $3
}

on *:text:!kb:[color:red]#yourchan[/color]: {
  [color:green]; Set up a loop to add up all the values in the table[/color]
  var %c = 1
  [color:green]; This is the total number of items in the table (we're looping from 1 to that)[/color]
  var %i = $hget(PicData,0).item
  while (%c &lt;= %i) {
    [color:green]; Add each value together into the one variable[/color]
    var %picbytes = %picbytes + $hget(PicData,%c)
    inc %c
  }
  [color:green]; When done, output the size.  Using $bytes lets us see the total size in bytes,kb,mb,etc.[/color]
  msg $chan There are $bytes(%picbytes).suf of pictures.
}

[color:green]; The alias to add the data[/color]
alias AddPicData {
  [color:green]; Check to see if the table is made.  If not, make it.[/color]
  if ($hget(PicData,0).item == $null) {
    hmake PicData 20
  }
  [color:green]; If the size is in kb, multiply the size by 1024 (this is the number of actual bytes rather than kb... it makes it easier to output a valid amount)[/color]
  if (kb isin $2) { var %picbytes = $remove($2,kb) * 1024 }
  [color:green]; This is the same thing, but for any that are in MB instead of kB.  Multiple it by 1024 and again by 1024 to give the total bytes.[/color]
  elseif (mb isin $2) { var %picbytes = $calc($remove($2,mb) * 1024 * 1024) }
  [color:green]; Add the filename and bytes to the table.[/color]
  hadd PicData $1 %picbytes
}


What makes it seem more complicated is that it inputs bytes into the table. The reason for this is because if someone adds a picture that is 1.5mb, you will want to differentiate between that and 1.5kb. Also, putting it into bytes will allow a nice, clean output using $bytes. Of course, if you don't ever use files that are over 1mb, then you can simply remove the mb section. I'd still leave the rest like it is. Note that I did make one small change to the kb/mb code... I wasn't thinking when I did it up.

This will be faster than trying to save it and examine the data from a file.

As a final note, you may want to consider adding a /hsave (on a timer) and /hload to the script if you want to avoid losing the data since hash tables are in memory and aren't saved automatically if you exit mIRC.


Oh, and if you wanted to, you could just use a single command to add and update ... it wouldn't matter since it would automatically update it if it was already there or add it if it wasn't... However, I did it like this (with the error messages in the script previously) so that you don't accidentally overwrite something or end up adding a new entry when you thought you were updating one (maybe because of a typo).

If you wanted to make it one command, remove the first two on texts, and replace them with:

Code:
on *:text:add *:[color:red]#yourchan[/color]: {
  [color:green]; Halt (return) if there aren't 3 parts to the command (the trigger, the filename, and the size)[/color]
  if ($3 == $null) return
  [color:green]; Otherwise, run the alias and send the filename and filesize to the alias.[/color]
  AddPicData $2 $3
}


Not really much different, except how it handles if the data is there or not.


Invision Support
#Invision on irc.irchighway.net
#133342 19/10/05 06:44 PM
Joined: Oct 2004
Posts: 8,330
Hoopy frood
Offline
Hoopy frood
Joined: Oct 2004
Posts: 8,330
One last thing... I strongly recommend not to do:

on *:text:*add*:#:{

Why? Because that would trigger whenever add is anywhere any line of text...

my address is...
you can add 1 + 2
the horse is in a paddock

You should use either of these instead:
!add * (the space makes it work only on !add and not !address or something else)
add * (same thing with space... without a * at the beginning and with the space before the end *, it will only trigger when the first word is add)


Invision Support
#Invision on irc.irchighway.net

Link Copied to Clipboard