From d9a6d133fb4a89799ee49d1fd2cf819fdd75c88d Mon Sep 17 00:00:00 2001 From: dakkar Date: Fri, 4 Jun 2021 18:19:53 +0100 Subject: move stuff into modules --- boha.raku | 6 +++-- lib/Boha/TrackOps.rakumod | 56 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 lib/Boha/TrackOps.rakumod diff --git a/boha.raku b/boha.raku index 28b7263..20172c0 100644 --- a/boha.raku +++ b/boha.raku @@ -1,6 +1,8 @@ #!/usr/bin/env rakudo use v6.d; use Config::TOML; +use lib $?FILE.IO.sibling('lib').Str; +use Boha::TrackOps; use IRC::Client; my $config = from-toml( @@ -61,7 +63,7 @@ class TrackOps does IRC::Client::Plugin { } class Boha1 does IRC::Client::Plugin { - has TrackOps $.ops handles ; + has Boha::TrackOps $.ops handles ; # irc-addressed for in-channel messages # irc-privmsg-me for direct messages @@ -84,7 +86,7 @@ class Boha1 does IRC::Client::Plugin { } } -my TrackOps $ops .= new; +my Boha::TrackOps $ops .= new; my Boha1 $boha .= new(:$ops); .run with IRC::Client.new( 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 ~~ / ^ $ = [ '@' | '+' ]? $ = [ .+ ] $ /; + + self!set-user-mode( + $server, $channel, + $user, + $user 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; + } +} -- cgit v1.2.3