From a5d13afe53eaf45e381472a96e61dd6bb2c3244d Mon Sep 17 00:00:00 2001 From: Aleks-Daniel Jakimenko-Aleksejev Date: Fri, 27 Mar 2020 11:44:58 +0200 Subject: [PATCH] Make some bots respond to private messages Currently only for linkable6, notable6, releasable6 and one another upcoming bot. Addresses #374 (but without tests). #350 is related. --- lib/Whateverable.pm6 | 8 ++++++-- xbin/Linkable.p6 | 5 +++-- xbin/Notable.p6 | 6 +++++- xbin/Releasable.p6 | 1 + 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/Whateverable.pm6 b/lib/Whateverable.pm6 index ca7a0e7..d89d3e8 100644 --- a/lib/Whateverable.pm6 +++ b/lib/Whateverable.pm6 @@ -47,7 +47,8 @@ method TWEAK { # wrap around everything to catch exceptions once { # per class self.^lookup(‘irc-to-me’).wrap: sub ($self, $msg) { - return if $msg.channel ne $CONFIG and $msg.args[1].starts-with: ‘what:’; + return if $msg.?channel and $msg.channel ne $CONFIG + and $msg.args[1].starts-with: ‘what:’; # ↑ ideally this check shouldn't be here, but it's much harder otherwise LEAVE sleep 0.02; # https://github.com/Raku/whateverable/issues/163 @@ -130,7 +131,10 @@ multi method irc-privmsg-channel($msg where .text ~~ /:i [‘thank you’|‘tha #↓ Notices multi method irc-notice-me( $ --> Nil) {} # Issue #321 #↓ Private messages -multi method irc-privmsg-me($ --> ‘Sorry, it is too private here. You can join #whateverable channel instead’) {} # TODO issue #16 +method private-messages-allowed() { False } +multi method irc-privmsg-me($ where not $.private-messages-allowed) { # TODO issue #16 + ‘Sorry, it is too private here. You can join #whateverable channel instead’ +} #↓ Fallback multi method irc-to-me($) { ‘I cannot recognize this command. See wiki for some examples: ’ ~ self.get-wiki-link diff --git a/xbin/Linkable.p6 b/xbin/Linkable.p6 index 8ed84b6..a87844c 100755 --- a/xbin/Linkable.p6 +++ b/xbin/Linkable.p6 @@ -25,6 +25,7 @@ unit class Linkable does Whateverable; method help($msg) { ‘Like this: R#1946 D#1234 MOAR#768 NQP#509 SPEC#242 RT#126800 S09:320 524f98cdc’ } +method private-messages-allowed() { True } constant %TICKET-URLS = %( ‘R’ | ‘RAKUDO’ | ‘GH’ => ‘https://api.github.com/repos/rakudo/rakudo/issues/’, @@ -52,13 +53,13 @@ sub recent($what) { my Channel $channel-messages .= new; sub reply($msg, $answer) { - return if recent “$msg.channel()\0$answer”; + return if recent “{$msg.?channel // $msg.nick}\0$answer”; sleep 3 if $msg.nick eq ‘Geth’; $channel-messages.send: %(:$msg, :$answer) } start react whenever $channel-messages.Supply.throttle: 3, 3 -> $ (:$msg, :$answer) { - $msg.irc.send: :where($msg.channel), text => $answer; + $msg.irc.send: :where($msg.?channel // $msg.nick), text => $answer; } sub link-doc-page($msg, $match) { diff --git a/xbin/Notable.p6 b/xbin/Notable.p6 index 8e7803a..03ce03e 100755 --- a/xbin/Notable.p6 +++ b/xbin/Notable.p6 @@ -31,12 +31,16 @@ write %() unless $db.e; method help($msg) { “Like this: {$msg.server.current-nick}: weekly rakudo is now 10x as fast” } +method private-messages-allowed() { True } sub read() { from-json slurp $db } sub write(%data) { spurt $db, to-json %data } +# XXX The logic here is a bit convoluted. It is meant to be a +# zero-width match (only then things work), but I don't think this +# was what I meant when I originaly wrote it. my regex shortcut($msg) { } + make $shortcut if $msg.?channel and $shortcut eq @shortcuts.any }> } my regex topic { <[\w:_-]>+ } #| List topics diff --git a/xbin/Releasable.p6 b/xbin/Releasable.p6 index 768af95..fd7d605 100755 --- a/xbin/Releasable.p6 +++ b/xbin/Releasable.p6 @@ -37,6 +37,7 @@ my $DRAFT-USER-URL = ‘https://github.com/rakudo/rakudo/wiki/ChangeLog-Draft method help($msg) { “status | status link” } +method private-messages-allowed() { True } sub ignored-commits() { my $last-release = to-full-commit chomp slurp “$CONFIG/VERSION”;