From 9fd5da692c91ce1faceef70344fc900689098d68 Mon Sep 17 00:00:00 2001 From: Zoffix Znet Date: Sun, 3 Jan 2016 14:43:40 -0500 Subject: Add $when argument to .respond --- README.md | 13 ++++++++++++- lib/IRC/Client.pm6 | 10 +++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 694c285..616246d 100644 --- a/README.md +++ b/README.md @@ -283,9 +283,10 @@ to the user/channel specified as the first argument. ```perl6 $irc.respond: :where<#zofbot> - :what('Hallo how are you?!') + :what("Hallo how are you?! It's been 1 hour!") :how :who + :when( now + 3600 ) ; ``` Generates a response based on the provided arguments, which are as follows: @@ -326,6 +327,16 @@ valid in any way). If the `where` argument is set to a name of a channel, then the method will modify the `what` argument, by prepending `$who, ` to it. +### `when` + +```perl6 + $irc.respond: :when(now+5) ... # respond in 5 seconds + $irc.respond: :when(DateTime.new: :2016year :1month :2day) ... +``` +**Optional**. Takes a `Dateish` or `Instant` value that specifies when the +response should be generated. If omited, the response will be generated +as soon as possible. **By default** is not specified. + ## `.ssay` ```perl6 diff --git a/lib/IRC/Client.pm6 b/lib/IRC/Client.pm6 index 41bb45d..63a7e98 100644 --- a/lib/IRC/Client.pm6 +++ b/lib/IRC/Client.pm6 @@ -91,13 +91,21 @@ method respond ( Str:D :$where is required, Str:D :$what is required is copy, Str:D :$who, + :$when where Dateish|Instant; ) { $what = "$who, $what" if $who and $where ~~ /^<[#&]>/; my $method = $how.fc eq 'PRIVMSG'.fc ?? 'privmsg' !! $how.fc eq 'NOTICE'.fc ?? 'notice' !! fail 'Unknown :$how specified. Use PRIVMSG or NOTICE'; - self."$method"($where, $what); + if $when { + Promise.at($when).then: { self."$method"($where, $what) }; + CATCH { warn .backtrace } + } + else { + self."$method"($where, $what); + } + self; } method run { -- cgit v1.1