Skip to content

Commit

Permalink
Make some bots respond to private messages
Browse files Browse the repository at this point in the history
Currently only for linkable6, notable6, releasable6 and one another
upcoming bot.

Addresses #374 (but without tests). #350 is related.
  • Loading branch information
AlexDaniel committed Mar 27, 2020
1 parent 75e84f7 commit a5d13af
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 5 deletions.
8 changes: 6 additions & 2 deletions lib/Whateverable.pm6
Original file line number Diff line number Diff line change
Expand Up @@ -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<cave> and $msg.args[1].starts-with: what:;
return if $msg.?channel and $msg.channel ne $CONFIG<cave>
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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions xbin/Linkable.p6
Original file line number Diff line number Diff line change
Expand Up @@ -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/,
Expand Down Expand Up @@ -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) {
Expand Down
6 changes: 5 additions & 1 deletion xbin/Notable.p6
Original file line number Diff line number Diff line change
Expand Up @@ -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) { <?{ my $shortcut = $msg.args[1].split(:)[0];
make $shortcut if $shortcut eq @shortcuts.any }> }
make $shortcut if $msg.?channel and $shortcut eq @shortcuts.any }> }
my regex topic { <[\w:_-]>+ }

#| List topics
Expand Down
1 change: 1 addition & 0 deletions xbin/Releasable.p6
Original file line number Diff line number Diff line change
Expand Up @@ -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<rakudo>/VERSION;
Expand Down

0 comments on commit a5d13af

Please sign in to comment.