mIRC Homepage
Posted By: bodo0815 !afk user script - 04/01/07 09:07 PM
hello...
im searching an away-script that can use all members in a channel
its look like:

user1: !afk eat
bot: user1 is away @20:00:01
user2: user1?
bot: user1 is away (eat) since 20:00:01
.
.
user1: !back
bot: user1 is back from eat

any1 know a script or can help me?

bodo
Posted By: Riamus2 Re: !afk user script - 04/01/07 10:18 PM
Here is a very easy one. I didn't make it so it saves away messages if you (the bot) closes mIRC. I didn't think it made sense to have it do that because the people could return by the time the bot is started again. If you decide you want it saved, let me know.

Code:
on *:start: {
  hmake AwayTable 50
}

on *:text:!afk*:#yourchannel: {
  var %time = $ctime
  if (!$hget(AwayTable)) { hmake AwayTable 50 }
  hadd AwayTable $nick $iif($2,$2-,Unknown) %time
  msg $chan $nick is away @ $+ $time(%time)
}

on *:text:!back:#yourchannel: {
  if ($hget(AwayTable,$nick)) {
    msg $chan $nick is back from $gettok($v1,1- $calc($gettok($v1,0,32) - 1) $+ .  $nick was gone for $duration($calc($ctime - $gettok($v1,$gettok($v1,0,32),32))) $+ .
    hdel AwayTable $nick
  }
  else msg $chan You're not away.
}

on *:text:*:#yourchannel: {
  if ($right($1-,1) == ? && $hget(AwayTable,$left($1,-1)) && !$2) {
    var %data = $hget(AwayTable,$left($1,-1))
    msg $chan $left($1,-1) is away $chr(40) $+ $gettok(%data,1- $calc($gettok(%data,0,32) -1),32) $+ $chr(41) since $time($gettok(%data,$gettok(%data,0,32),32)) $+ .
  }
}

on *:part:#yourchannel: {
  if ($hget(AwayTable,$nick)) {
    hdel AwayTable $nick
  }
}

on *:quit: {
  if ($hget(AwayTable,$nick)) {
    hdel AwayTable $nick
  }
}


Use:

<nick> !afk reason
<bot> nick is away @time.

<user2> nick?
<bot> nick is away (reason) since time.

<nick> !back
<bot> nick is back from reason. nick was gone for 1min 5secs.

You need the ? after the nick and nothing else for the bot to respond with the away info for that user.

Change the #yourchannel to the channel name that you want to use this on. If you want it for more channels, you can, but it's really designed for one and going away in one will make you away in all and so on.
Posted By: bodo0815 Re: !afk user script - 05/01/07 02:57 PM
hello and thx :-)
!back dont work :-(
"* Invalid format: $gettok (line 14, afk.mrc)"

is it possible users use only the nick without "?" if they call an away-user? sry my fault.

ty bodo
Posted By: Riamus2 Re: !afk user script - 05/01/07 03:57 PM
Sorry, missed a ). I changed it to work without the ?. I did that because that's how your example was.

Code:
on *:start: {
  hmake AwayTable 50
}

on *:text:!afk*:#yourchannel: {
  var %time = $ctime
  if (!$hget(AwayTable)) { hmake AwayTable 50 }
  hadd AwayTable $nick $iif($2,$2-,Unknown) %time
  msg $chan $nick is away @ $+ $time(%time)
}

on *:text:!back:#yourchannel: {
  if ($hget(AwayTable,$nick)) {
    msg $chan $nick is back from $gettok($v1,1- $calc($gettok($v1,0,32) - 1)) $+ .  $nick was gone for $duration($calc($ctime - $gettok($v1,$gettok($v1,0,32),32))) $+ .
    hdel AwayTable $nick
  }
  else msg $chan You're not away.
}

on *:text:*:#yourchannel: {
  if ($hget(AwayTable,$remove($strip($1),?)) && !$2) {
    var %data = $hget(AwayTable,$remove($strip($1),?))
    msg $chan $left($1,-1) is away $chr(40) $+ $gettok(%data,1- $calc($gettok(%data,0,32) -1),32) $+ $chr(41) since $time($gettok(%data,$gettok(%data,0,32),32)) $+ .
  }
}

on *:part:#yourchannel: {
  if ($hget(AwayTable,$nick)) {
    hdel AwayTable $nick
  }
}

on *:quit: {
  if ($hget(AwayTable,$nick)) {
    hdel AwayTable $nick
  }
}


It now triggers the away message for:

nick
nick?

and also works if colors are used. It only displays if only the nick is on the line.
Posted By: bodo0815 Re: !afk user script - 05/01/07 04:35 PM
okay... ty all works fine but:
!back
"* Too few parameters: $gettok (line 14, afk.mrc)"

bodo
Posted By: Riamus2 Re: !afk user script - 05/01/07 07:25 PM
I wish I could test it... these are stupid mistakes.

Change line 14 to:
Code:
msg $chan $nick is back from $gettok($v1,1- $calc($gettok($v1,0,32) - 1),32) $+ .  $nick was gone for $duration($calc($ctime - $gettok($v1,$gettok($v1,0,32),32))) $+ .

Posted By: bodo0815 Re: !afk user script - 05/01/07 11:08 PM
now it works fine :-) thx

can u add a !away trigger thats show all away-user in a channel?
like:

user1: !away
bot: user2 is away (test) @02:04:00
bot: user3 is away (test) @02:05:00
bot: user4 is away (test) @02:06:00

bodo
Posted By: Riamus2 Re: !afk user script - 06/01/07 01:36 AM
Code:
on *:start: {
  hmake AwayTable 50
}

on *:text:!afk*:#yourchannel: {
  var %time = $ctime
  if (!$hget(AwayTable)) { hmake AwayTable 50 }
  hadd AwayTable $nick $iif($2,$2-,Unknown) %time
  msg $chan $nick is away @ $+ $time(%time)
}

on *:text:!back:#yourchannel: {
  if ($hget(AwayTable,$nick)) {
    msg $chan $nick is back from $gettok($v1,1- $calc($gettok($v1,0,32) - 1),32) $+ .  $nick was gone for $duration($calc($ctime - $gettok($v1,$gettok($v1,0,32),32))) $+ .
    hdel AwayTable $nick
  }
  else msg $chan You're not away.
}

on *:text:!away:#yourchannel: {
  var %cnt = 1
  var %total = $hget(AwayTable,0).item
  while (%cnt <= %total) {
    var %name = $hget(AwayTable,%cnt).item
    var %data = $hget(AwayTable,%cnt).data
    write afk.tmp %name is away $chr(40) $+ $gettok(%data,1- $calc($gettok(%data,0,32) -1),32) $+ $chr(41) since $time($gettok(%data,$gettok(%data,0,32),32)) $+ .
    inc %cnt
  }
  .play $chan afk.tmp 1500
  .remove afk.tmp
}

on *:text:*:#yourchannel: {
  if ($hget(AwayTable,$remove($strip($1),?)) && !$2) {
    var %data = $hget(AwayTable,$remove($strip($1),?))
    msg $chan $left($1,-1) is away $chr(40) $+ $gettok(%data,1- $calc($gettok(%data,0,32) -1),32) $+ $chr(41) since $time($gettok(%data,$gettok(%data,0,32),32)) $+ .
  }
}

on *:part:#yourchannel: {
  if ($hget(AwayTable,$nick)) {
    hdel AwayTable $nick
  }
}

on *:quit: {
  if ($hget(AwayTable,$nick)) {
    hdel AwayTable $nick
  }
}
Posted By: bodo0815 Re: !afk user script - 06/01/07 10:47 AM
great :-) thx

bodo
Posted By: BritishGent Re: !afk user script - 06/01/07 08:11 PM
Originally Posted By: Riamus2
Code:
on *:start: {
  hmake AwayTable 50
}

on *:text:!afk*:#yourchannel: {
  var %time = $ctime
  if (!$hget(AwayTable)) { hmake AwayTable 50 }
  hadd AwayTable $nick $iif($2,$2-,Unknown) %time
  msg $chan $nick is away @ $+ $time(%time)
}

on *:text:!back:#yourchannel: {
  if ($hget(AwayTable,$nick)) {
    msg $chan $nick is back from $gettok($v1,1- $calc($gettok($v1,0,32) - 1),32) $+ .  $nick was gone for $duration($calc($ctime - $gettok($v1,$gettok($v1,0,32),32))) $+ .
    hdel AwayTable $nick
  }
  else msg $chan You're not away.
}

on *:text:!away:#yourchannel: {
  var %cnt = 1
  var %total = $hget(AwayTable,0).item
  while (%cnt <= %total) {
    var %name = $hget(AwayTable,%cnt).item
    var %data = $hget(AwayTable,%cnt).data
    write afk.tmp %name is away $chr(40) $+ $gettok(%data,1- $calc($gettok(%data,0,32) -1),32) $+ $chr(41) since $time($gettok(%data,$gettok(%data,0,32),32)) $+ .
    inc %cnt
  }
  .play $chan afk.tmp 1500
  .remove afk.tmp
}

on *:text:*:#yourchannel: {
  if ($hget(AwayTable,$remove($strip($1),?)) && !$2) {
    var %data = $hget(AwayTable,$remove($strip($1),?))
    msg $chan $left($1,-1) is away $chr(40) $+ $gettok(%data,1- $calc($gettok(%data,0,32) -1),32) $+ $chr(41) since $time($gettok(%data,$gettok(%data,0,32),32)) $+ .
  }
}

on *:part:#yourchannel: {
  if ($hget(AwayTable,$nick)) {
    hdel AwayTable $nick
  }
}

on *:quit: {
  if ($hget(AwayTable,$nick)) {
    hdel AwayTable $nick
  }
}


Is it at all possible to add the date after the time ?
Posted By: Riamus2 Re: !afk user script - 07/01/07 05:28 AM
Just change the $time( ) part to include the formatting options that you want to use.

/help $time

For example, at the end, you could put:

,hh:nntt mmm dd yyyy)

... instead of just the )

Just look at the help file and choose how you want it to look. You can add colors and control codes inside there and if you want to include a comma, use $chr(44).
Posted By: BritishGent Re: !afk user script - 08/01/07 03:49 AM
i have noticed that the !away command has a slight glitch with it.

my friend marked themselves away in my channel as you can see below at the specified time:

[00:52] <CHIEFY> !afk making coffee
[00:52] <^Merlin> CHIEFY is away @12:52am Jan 08 2007

Yet some hours later i did the !away command to see how it was working and i got this responce:

[03:31] <Tallulah> cool!
[03:34] <^Silent_Runner^> !away
[03:34] <^Merlin> CHIEFY is away (making coffee) since 03:34:35 on 08/01/07.
[03:35] <Tallulah> cool, I knew you had done that, but couldn't remember what the command was

and as you can see the time being reported as my friend being away is completely wrong from the time of the command being issued.

If anyone could help me with this i would be grateful smile

Many Thanks
Posted By: Riamus2 Re: !afk user script - 08/01/07 05:10 AM
Are you sure he didn't do !afk again? Try having someone do !afk, then check !away after a minute or two.
Posted By: BritishGent Re: !afk user script - 08/01/07 05:17 AM
yes i am sure he didn't go !afk again. checked and double checked and tried it myself, it returns the time when !away is used everytime frown
Posted By: billythekid Re: !afk user script - 08/01/07 10:05 AM
i there some $time error perhaps, a MM instead of an NN or something? I know that wouldn't give the results you show with the data but just another idea in the ring...

[edit] in fact i'm pretty sure it's a $time problem as the returned time is the same as the timestamp in your example...

[03:34] <^Merlin> CHIEFY is away (making coffee) since 03:34:35 on 08/01/07.

[/edit]


btk
Posted By: Riamus2 Re: !afk user script - 08/01/07 02:08 PM
Well, I just tried the script I posted above and it works as expected. Perhaps when you added the date information, you entered it incorrectly. Paste the msg line in the !away section.

Also, you might want to change this:
Code:
on *:text:*:#yourchannel: {
  if ($hget(AwayTable,$remove($strip($1),?)) && !$2) {
    var %data = $hget(AwayTable,$remove($strip($1),?))
    msg $chan $left($1,-1) is away $chr(40) $+ $gettok(%data,1- $calc($gettok(%data,0,32) -1),32) $+ $chr(41) since $time($gettok(%data,$gettok(%data,0,32),32)) $+ .
  }
}


to this:
Code:
on *:text:*:#yourchannel: {
  if ($hget(AwayTable,$remove($strip($1),?)) && !$2) {
    var %data = $hget(AwayTable,$remove($strip($1),?))
    msg $chan $remove($strip($1),?) is away $chr(40) $+ $gettok(%data,1- $calc($gettok(%data,0,32) -1),32) $+ $chr(41) since $time($gettok(%data,$gettok(%data,0,32),32)) $+ .
  }
}


I forgot to change that msg line when I made it work without the ? at the end.
Posted By: BritishGent Re: !afk user script - 09/01/07 01:25 AM
This is how i have the script at present and all works superb with the exception of the !away function.

Code:
on *:start: {
  hmake AwayTable 50
}

on *:text:!afk*:#Simons-Forums: {
  var %time = $ctime
  if (!$hget(AwayTable)) { hmake AwayTable 50 }
  hadd AwayTable $nick $iif($2,$2-,Unknown) %time 
  msg $chan $nick is away @ $+ $time(%time,hh:nn mmm dd yyyy)
}

on *:text:!back:#Simons-Forums: {
  if ($hget(AwayTable,$nick)) {
    msg $chan $nick is back from $gettok($v1,1- $calc($gettok($v1,0,32) - 1),32) $+ .  $nick was gone for $duration($calc($ctime - $gettok($v1,$gettok($v1,0,32),32))) $+ .
    hdel AwayTable $nick
  }
  else msg $chan You're not away.
}

on *:text:!away:#Simons-Forums: {
  var %cnt = 1
  var %total = $hget(AwayTable,0).item
  while (%cnt <= %total) {
    var %name = $hget(AwayTable,%cnt).item
    var %data = $hget(AwayTable,%cnt).data
    write afk.tmp %name is away $chr(40) $+ $gettok(%data,1- $calc($gettok(%data,0,32) -1),32) $+ $chr(41) since $time on $date($gettok(%data,$gettok(%data,0,32),32)) $+ .
    inc %cnt
  }
  .play $chan afk.tmp 1500
  .remove afk.tmp
}

on *:text:*:#Simons-Forums: {
  if ($hget(AwayTable,$remove($strip($1),?)) && !$2) {
    var %data = $hget(AwayTable,$remove($strip($1),?))
    msg $chan $remove($strip($1),?) is away $chr(40) $+ $gettok(%data,1- $calc($gettok(%data,0,32) -1),32) $+ $chr(41) since $time($gettok(%data,$gettok(%data,0,32),32)) $+ .
  }
}

on *:action:*:#Simons-Forums: {
  if ($hget(AwayTable,$remove($strip($1),?)) && !$2) {
    var %data = $hget(AwayTable,$remove($strip($1),?))
    msg $chan $left($1,-1) is away $chr(40) $+ $gettok(%data,1- $calc($gettok(%data,0,32) -1),32) $+ $chr(41) since $time on $date($gettok(%data,$gettok(%data,0,32),32)) $+ .
  }
}

on *:part:#Simons-Forums: {
  if ($hget(AwayTable,$nick)) {
    hdel AwayTable $nick
  }
}

on *:quit: {
  if ($hget(AwayTable,$nick)) {
    hdel AwayTable $nick
  }
}


I took onbaord comments earlier about time commands and edited and comments about changing lin structures.

I have just tested it and this is the result.

[01:14] <^Silent_Runner^> testing 3I Am Away From Keyboard script
[01:14] <^Silent_Runner^> !afk testing script
[01:14] <^Merlin> ^Silent_Runner^ is away @01:14 Jan 09 2007
[01:15] <^Silent_Runner^> right 01:14
[01:15] <^Silent_Runner^> give it a few mins and i'll check if it has recorded correct time
[01:15] <Tallulah> ok
[01:17] * ChanServ sets mode: +o ^Silent_Runner^
[01:17] -ChanServ:#Simons-Forums- OP command used for ^Silent_Runner^ by ^Silent_Runner^
[01:17] -ChanServ- Opped ^Silent_Runner^ on channel #Simons-Forums.
[01:17] * ^Silent_Runner^ sets mode: -o ^Silent_Runner^
[01:18] * ChanServ sets mode: +o ^Silent_Runner^
[01:18] -ChanServ:#Simons-Forums- OP command used for ^Silent_Runner^ by ^Silent_Runner^
[01:18] -ChanServ- Opped ^Silent_Runner^ on channel #Simons-Forums.
[01:18] * ^Silent_Runner^ sets mode: -o ^Silent_Runner^
[01:18] * ChanServ sets mode: +o ^Silent_Runner^
[01:18] -ChanServ:#Simons-Forums- OP command used for ^Silent_Runner^ by ^Silent_Runner^
[01:18] -ChanServ- Opped ^Silent_Runner^ on channel #Simons-Forums.
[01:18] * ^Silent_Runner^ sets mode: -o ^Silent_Runner^
[01:20] <^Silent_Runner^> nagh i give up with that one, i can not get it too work
[01:20] <^Silent_Runner^> !away
[01:20] <^Merlin> ^Silent_Runner^ is away (testing script) since 01:20:27 on 09/01/07.

As you can see it is still posting on the !away command the time that command is issued and not the time the !afk command was issued.

So i am none the wiser about what to do, any help would be greatly appreciated as this is a cool script thus far, i love it smile

Many Thanks
Posted By: Riamus2 Re: !afk user script - 09/01/07 05:15 AM
Heh. Look at this line (from your !away part):

Code:
write afk.tmp %name is away $chr(40) $+ $gettok(%data,1- $calc($gettok(%data,0,32) -1),32) $+ $chr(41) since $time on $date($gettok(%data,$gettok(%data,0,32),32)) $+ .



And compare it to mine. Your $date part is fine, unless you want the month/day reversed, but you just have $time there... that will definitely just show the current time. The $time part should look identical to the $date part on that line, except that it says $time.
Posted By: BritishGent Re: !afk user script - 09/01/07 09:16 AM
Originally Posted By: Riamus2
Heh. Look at this line (from your !away part):

Code:
write afk.tmp %name is away $chr(40) $+ $gettok(%data,1- $calc($gettok(%data,0,32) -1),32) $+ $chr(41) since $time on $date($gettok(%data,$gettok(%data,0,32),32)) $+ .



And compare it to mine. Your $date part is fine, unless you want the month/day reversed, but you just have $time there... that will definitely just show the current time. The $time part should look identical to the $date part on that line, except that it says $time.


For give my stupidity here but i just do not get what you are saying.....
Posted By: Riamus2 Re: !afk user script - 09/01/07 02:12 PM
Change that line to:

Code:
write afk.tmp %name is away $chr(40) $+ $gettok(%data,1- $calc($gettok(%data,0,32) -1),32) $+ $chr(41) since $time($gettok(%data,$gettok(%data,0,32),32)) on $date($gettok(%data,$gettok(%data,0,32),32)) $+ .



Notice that $time now matches what I originally gave you before you edited it for date.
Posted By: BritishGent Re: !afk user script - 11/01/07 12:37 AM
Thank you. i think i understand now, thank you for your patience. smile
Posted By: Lucan Re: !afk user script - 12/01/07 01:48 AM
So I'm using this and loving it. But I had another idea (not sure how hard it would be to implement): changing the syntax to "!afk <time expected back> <reason>" then at the time entered the bot would message the chan "Nick expected back soon." then the rest would be like normal. Or maybe it could just be an option. Just hit me and i figured id post.
Posted By: Riamus2 Re: !afk user script - 12/01/07 01:47 PM
What do you do with people in different time zones?
Posted By: Lucan Re: !afk user script - 12/01/07 08:35 PM
Well i guess they could input it as hours they expect to be away (idk about minutes), but it was just an idea
Posted By: Riamus2 Re: !afk user script - 12/01/07 09:21 PM
Try this. To include the estimated time away, a user would type:

For 2 hours:
!afk -t2 reason for being away

For 30 minutes (0.5 hours):
!afk -t.5 reason for being away
!afk -t0.5 reason for being away

Etc. This is only in hours, so decimals are needed for minutes... or, you could enter it as:

For 30 minutes (30 minutes * 60 minutes in an hour):
!afk -t30*60 reason for being away

Code:
on *:start: {
  hmake AwayTable 50
}

on *:text:!afk*:#Simons-Forums: {
  var %time = $ctime
  if (!$hget(AwayTable)) { hmake AwayTable 50 }
  if ($left($2,2) == -t) {
    if ($len($2) == 2) {
      var %reason = $iif($4,$4-,Unknown)
      .timerAway. $+ $nick 1 $calc($3 * 3600) msg $chan $nick should be back soon.
    }
    else {
      var %reason = $iif($3,$3-,Unknown)
      .timerAway. $+ $nick 1 $calc($right($2,-2) * 3600) msg $chan $nick should be back soon.
    }
  }
  else var %reason = $iif($2,$2-,Unknown)
  hadd AwayTable $nick %reason %time 
  msg $chan $nick is away @ $+ $time(%time,hh:nn mmm dd yyyy)
}

on *:text:!back:#Simons-Forums: {
  if ($hget(AwayTable,$nick)) {
    msg $chan $nick is back from $gettok($v1,1- $calc($gettok($v1,0,32) - 1),32) $+ .  $nick was gone for $duration($calc($ctime - $gettok($v1,$gettok($v1,0,32),32))) $+ .
    hdel AwayTable $nick
    .timerAway. [ $+ [ $nick ] ] off
  }
  else msg $chan You're not away.
}

on *:text:!away:#Simons-Forums: {
  var %cnt = 1
  var %total = $hget(AwayTable,0).item
  while (%cnt <= %total) {
    var %name = $hget(AwayTable,%cnt).item
    var %data = $hget(AwayTable,%cnt).data
    write afk.tmp %name is away $chr(40) $+ $gettok(%data,1- $calc($gettok(%data,0,32) -1),32) $+ $chr(41) since $time on $date($gettok(%data,$gettok(%data,0,32),32)) $+ .
    inc %cnt
  }
  .play $chan afk.tmp 1500
  .remove afk.tmp
}

on *:text:*:#Simons-Forums: {
  if ($hget(AwayTable,$remove($strip($1),?)) && !$2) {
    var %data = $hget(AwayTable,$remove($strip($1),?))
    msg $chan $remove($strip($1),?) is away $chr(40) $+ $gettok(%data,1- $calc($gettok(%data,0,32) -1),32) $+ $chr(41) since $time($gettok(%data,$gettok(%data,0,32),32)) $+ .
  }
}

on *:action:*:#Simons-Forums: {
  if ($hget(AwayTable,$remove($strip($1),?)) && !$2) {
    var %data = $hget(AwayTable,$remove($strip($1),?))
    msg $chan $left($1,-1) is away $chr(40) $+ $gettok(%data,1- $calc($gettok(%data,0,32) -1),32) $+ $chr(41) since $time($gettok(%data,$gettok(%data,0,32),32)) on $date($gettok(%data,$gettok(%data,0,32),32)) $+ .
  }
}

on *:part:#Simons-Forums: {
  if ($hget(AwayTable,$nick)) {
    hdel AwayTable $nick
    .timerAway. [ $+ [ $nick ] ] off
  }
}

on *:quit: {
  if ($hget(AwayTable,$nick)) {
    hdel AwayTable $nick
    .timerAway. [ $+ [ $nick ] ] off
  }
}


As a note, you can enter it using a space after the -t if you want to:

For 3.5 hours:
!afk -t 3.5 Reason for being away.
© mIRC Discussion Forums