summaryrefslogtreecommitdiff
path: root/lib/Boha/TrackOps.rakumod
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Boha/TrackOps.rakumod')
-rw-r--r--lib/Boha/TrackOps.rakumod56
1 files changed, 56 insertions, 0 deletions
diff --git a/lib/Boha/TrackOps.rakumod b/lib/Boha/TrackOps.rakumod
new file mode 100644
index 0000000..3218cc3
--- /dev/null
+++ b/lib/Boha/TrackOps.rakumod
@@ -0,0 +1,56 @@
+#!/usr/bin/env rakudo
+use v6.d;
+use IRC::Client;
+
+class Boha::TrackOps does IRC::Client::Plugin {
+ has %!is-op;
+
+ multi method is-op(
+ Str() $server, Str() $channel, Str() $nick --> Bool
+ ) {
+ return %!is-op{$server}{$channel}{$nick}.so;
+ }
+ multi method is-op(IRC::Client::Message $e --> Bool) {
+ fail 'not a channel message' unless $e.?channel;
+ return self.is-op($e.server,$e.channel,$e.nick);
+ }
+
+ method !set-user-mode(
+ Str() $server, Str() $channel, Str() $nick, Bool $mode
+ ) {
+ %!is-op{$server}{$channel}{$nick} = $mode;
+ }
+
+ # response to /NAMES
+ method irc-n353(IRC::Client::Message $e) {
+ my $server = $e.server;
+ my ($my-nick,$equal,$channel,$names) = $e.args();
+
+ for $names.split(/\s+/) -> $name-str {
+ my $user = $name-str ~~ / ^ $<sigil> = [ '@' | '+' ]? $<nick> = [ .+ ] $ /;
+
+ self!set-user-mode(
+ $server, $channel,
+ $user<nick>,
+ $user<sigil> eq '@'
+ );
+ }
+
+ return $.NEXT;
+ }
+
+ method irc-mode-channel($e) {
+ my ($server, $channel) = $e.server, $e.channel;
+ my $new-mode = (
+ $e.mode eq '+o' ?? True !!
+ $e.mode eq '-o' ?? False !!
+ return $.NEXT
+ );
+
+ for $e.nicks() -> $nick {
+ self!set-user-mode($server,$channel,$nick,$new-mode);
+ }
+
+ return $.NEXT;
+ }
+}