Skip to content

Commit efd7e91

Browse files
committed
Evalable: respond to discord even if camelia is present
Normally evalable6 leaves queries to camelia when she is around. But camelia does not support responding to discord, so in that case evalable6 should not restrain itself. This is made possible by mixing a FromDiscord role into the nick field of messages (not the message itself because that would break event dispatch in IRC::Client) and testing for that while deciding whether to leave the message to camelia or not.
1 parent bc827e0 commit efd7e91

File tree

3 files changed

+16
-5
lines changed

3 files changed

+16
-5
lines changed

lib/Whateverable/Discordable.pm6

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,17 @@
1414
# You should have received a copy of the GNU Affero General Public License
1515
# along with this program. If not, see <http://www.gnu.org/licenses/>.
1616

17+
use Whateverable::Bits;
1718
use IRC::Client::Message;
1819

1920
my constant ChannelMessage = IRC::Client::Message::Privmsg::Channel;
2021

2122
#| Transparently handle messages from the discord bridge.
2223
unit role Whateverable::Discordable;
2324

25+
#| Role mixed into .nick of messages processed by Discordable
26+
my role FromDiscord is export { }
27+
2428
#| Nick of the discord bridge bot.
2529
my constant DISCORD-BRIDGE = any(discord6, discord61);
2630

@@ -35,7 +39,7 @@ multi method irc-privmsg-channel(ChannelMessage $msg where .nick eq DISCORD-BRID
3539
# into $.nick. It is not used for routing the message on IRC, only to
3640
# address the user in the reply.
3741
my $bridged-msg = $msg.clone:
38-
nick => ~$<nick>,
42+
nick => ~$<nick> but FromDiscord,
3943
text => ~$<text>,
4044
args => [$msg.channel, ~$<text>],
4145
;

xbin/Evalable.p6

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ use Whateverable;
2121
use Whateverable::Bits;
2222
use Whateverable::Builds;
2323
use Whateverable::Config;
24+
use Whateverable::Discordable;
2425
use Whateverable::Processing;
2526
use Whateverable::Running;
2627
use Whateverable::Userlist;
@@ -35,8 +36,11 @@ method help($msg) {
3536
}
3637

3738
multi method irc-to-me($msg) {
38-
return self.process: $msg, $msg.text if $msg.args[1] !~~
39-
/^ \s*[master|rakudo|r|‘r-m’|m|p6|perl6]‘:’\s /;
39+
# Do not answer when camelia is around (she reacts to the same triggers).
40+
# But always do when the message is from discord because camelia doesn't
41+
# support that.
42+
return self.process: $msg, $msg.text if $msg.nick ~~ FromDiscord or
43+
$msg.args[1] !~~ /^ \s*[master|rakudo|r|‘r-m’|m|p6|perl6]‘:’\s /;
4044
self.make-believe: $msg, (camelia,), {
4145
self.process: $msg, $msg.text
4246
}

xt/evalable.t

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,11 @@ start $camelia.run;
185185
sleep 1;
186186

187187
for (, ) X~ (@alts X~ : ) {
188-
$t.test(camelia is back, be silent (‘$_’),
189-
$_ ~ say ‘$_)
188+
$t.test(:!both, camelia is back, be silent (‘$_’),
189+
$_ ~ say ‘$_);
190+
$t.test(:!both, :bridge, camelia is back, be NOT silent for discord (‘$_’),
191+
$_ ~ say ‘$_,
192+
/^ <me($t)>‘, rakudo-moar ’<sha>“: OUTPUT: «$_␤»” $/)
190193
}
191194

192195
for (, ) X~ (@alts X~ :) {

0 commit comments

Comments
 (0)