Skip to content

Instantly share code, notes, and snippets.

@zoffixznet
Created September 24, 2016 20:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zoffixznet/c47f02fc7772147eafdb72e0be1f6dcd to your computer and use it in GitHub Desktop.
Save zoffixznet/c47f02fc7772147eafdb72e0be1f6dcd to your computer and use it in GitHub Desktop.
use IRC::Client;
.run with IRC::Client.new:
:host<localhost>,
:channels<#zofbot>,
:debug,
plugins =>
class :: does IRC::Client::Plugin {
method irc-addressed ($e) {
$e does role { method is-addressed { True } }
$.NEXT;
}
subset BotCommand of IRC::Client::Message::Privmsg where {
$^e.?is-addressed
?? $e.text ~~ /^ $<command>=\S+ \s+ $<command-args>=.+/
!! $^e.args[1] ~~ /^ '.' $<command>=\S+ \s+ $<command-args>=.+/;
my $m = $/;
$e does role {
method com { ~($m<command>//'') }
method com-args { ~($m<command-args>//'') }
}
True;
}
multi method irc-privmsg-channel (BotCommand $e where .com eq 'google' ) {
"Googling: $e.com-args()";
}
multi method irc-privmsg-channel (BotCommand $e where .com eq 'run' ) {
"Running: $e.com-args()";
}
multi method irc-privmsg ($e where .?is-addressed) {
"Don't know how to do `$e.text()`";
}
}
@zoffixznet
Copy link
Author

zoffixznet commented Sep 24, 2016

<zoffix> P6Bot, google foo
<P6Bot> zoffix, Googling: foo
<zoffix> P6Bot, meow
<P6Bot> zoffix, Don't know how to do `meow`
<zoffix> P6Bot, run foo
<P6Bot> zoffix, Running: foo
<zoffix> .run foo
<P6Bot> zoffix, Running: foo
<zoffix> .meow
<zoffix> .foobar

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment