diff options
-rw-r--r-- | META6.json | 4 | ||||
-rw-r--r--[-rwxr-xr-x] | bin/musashi | 0 | ||||
-rw-r--r-- | lib/Local/Musashi.pm6 | 115 |
3 files changed, 85 insertions, 34 deletions
@@ -4,8 +4,8 @@ "Patrick Spek <p.spek@tyil.work>" ], "depends": [ - "Config", - "Config::Parser::toml", + "Config:ver<3.0.3>", + "Config::Parser::toml:ver<1.0.3>", "IO::Path::XDG", "IRC::Client", "IRC::Client::Plugin::NickServ:ver<0.3.0+>:api<0>", diff --git a/bin/musashi b/bin/musashi index 67f8ae5..67f8ae5 100755..100644 --- a/bin/musashi +++ b/bin/musashi diff --git a/lib/Local/Musashi.pm6 b/lib/Local/Musashi.pm6 index 84ea1f7..8732844 100644 --- a/lib/Local/Musashi.pm6 +++ b/lib/Local/Musashi.pm6 @@ -7,6 +7,7 @@ use IO::Glob; use IO::Path::XDG; use IRC::Client; use IRC::Client::Plugin::DiceRolls; +use IRC::Client::Plugin::Memos; use IRC::Client::Plugin::NickServ; use IRC::Client::Plugin::Reminders; use IRC::TextColor; @@ -35,24 +36,51 @@ unit sub MAIN ( signal(SIGTERM).tap({ .quit with $bot }); # Load config - my IO::Path $config-file = xdg-config-dirs() - .map(*.add('musashi.toml')) - .grep(*.f) - .first - ; - - die "Missing configuration file: $config-file.absolute()." unless $config-file; - - my $*CONFIG = Config.new.read($config-file.absolute); + my $config = Config.new({ + debug => False, + database => { + driver => 'postgresql', + host => Str, + database => 'musashi', + user => ~$*USER, + password => Str, + }, + irc => { + nickname => 'musashi', + username => 'musashi', + realname => 'musashi', + + host => Str, + port => 6697, + ssl => True, + + channels => [ ], + + command-prefix => '.', + + plugins => { + dicerolls => { + command-word => 'roll', + }, + nickserv => { + account => Str, + password => Str, + }, + reminders => { + interval => Int, + }, + }, + }, + }, :name<musashi>); - if (!$*CONFIG.get('irc.opers')) { + if (!$config.get('irc.opers')) { .warning('No opers defined in irc.opers') with $Log::instance; } # Set up database connection my $*DB; - my $db-driver = $*CONFIG.get('database.driver', '').fc; + my $db-driver = $config.get('database.driver', '').fc; given ($db-driver) { when 'postgresql' { @@ -64,11 +92,11 @@ unit sub MAIN ( } my $conninfo = %( - host => $*CONFIG.get('database.host', 'localhost'), - dbname => $*CONFIG.get('database.database', 'musashi'), - user => $*CONFIG.get('database.user', ~$*USER), - password => $*CONFIG.get('database.password'), - port => $*CONFIG.get('database.port', 5432), + host => $config.get('database.host', 'localhost'), + dbname => $config.get('database.database', 'musashi'), + user => $config.get('database.user', ~$*USER), + password => $config.get('database.password'), + port => $config.get('database.port', 5432), ).pairs.grep(*.value).map({ "{$_.key}={$_.value}" }).join(' '); .info("Using Postgres database ($conninfo)") with $Log::instance; @@ -89,7 +117,7 @@ unit sub MAIN ( method bulli ( Str() $usermask, ) { - for $*CONFIG.get('irc.ignore', []).List -> $bully { + for $config.get('irc.ignore', []).List -> $bully { next unless $usermask ~~ glob($bully); .notice("$bully is ignored") with $Log::instance; @@ -112,9 +140,10 @@ unit sub MAIN ( multi method irc-notice ($event) { self.bulli($event.usermask) } }, - IRC::Client::Plugin::NickServ.new(config => $*CONFIG), - IRC::Client::Plugin::DiceRolls.new(config => $*CONFIG), - IRC::Client::Plugin::Reminders.new(config => $*CONFIG), + IRC::Client::Plugin::NickServ.new(config => $config), + IRC::Client::Plugin::DiceRolls.new(config => $config), + IRC::Client::Plugin::Reminders.new(config => $config), + IRC::Client::Plugin::Memos.new(config => $config), # Musashi-specific behaviour class { @@ -133,9 +162,31 @@ unit sub MAIN ( "And a good morning to you too, {$e.nick}" } + #| Rewrite Twitter links multi method irc-privmsg-channel($e where *.text.contains('twitter.com')) { - $e.text.subst('twitter.com', ircstyle('nitter.net', :bold), :g) + my $alternative = < + nitter.42l.fr + nitter.eu + nitter.fdn.fr + nitter.namazso.eu + nitter.nixnet.services + nitter.pussthecat.org + nitter.tedomum.net + nitter.unixfox.eu + prvy.top + >.pick(); + + for $e.text.words.grep(*.contains('twitter.com')) -> $link { + .debug("Rewriting $link to $alternative") with $Log::instance; + + $e.irc.send( + text => '> ' ~ $link.subst('twitter.com', $alternative), + where => $e.channel, + ); + } + + Nil; } #| Allow reloading configuration while the bot is @@ -148,13 +199,13 @@ unit sub MAIN ( } .info('Reloading configuration') with $Log::instance; - $*CONFIG.=read($config-file.absolute); + .error('Not Properly Implemented!') with $Log::instance; for @plugins -> $plugin { next unless $plugin.^can('reload-config'); .info("Reloading plugin $plugin") with $Log::instance; - $plugin.reload-config($*CONFIG); + $plugin.reload-config($config); } 'Reloaded configuration!'; @@ -165,7 +216,7 @@ unit sub MAIN ( Str() $usermask, --> Bool:D ) { - for $*CONFIG.get('irc.opers', []).List -> $oper { + for $config.get('irc.opers', []).List -> $oper { return True if $usermask ~~ glob($oper); } @@ -176,14 +227,14 @@ unit sub MAIN ( # Set up the bot $bot .= new( - :nick($*CONFIG.get("irc.nickname", "musashi")) - :username($*CONFIG.get("irc.username", "musashi")) - :realuser($*CONFIG.get("irc.realname", "Yet another tachikoma AI")) - :host($*CONFIG.get("irc.host", "irc.darenet.org")) - :port($*CONFIG.get("irc.port", 6667)) - :ssl($*CONFIG.get("irc.ssl", False)) - :channels($*CONFIG.get("irc.channels", "#scriptkitties")) - :debug($*CONFIG.get("debug", True)) + :nick($config.get("irc.nickname", "musashi")) + :username($config.get("irc.username", "musashi")) + :realuser($config.get("irc.realname", "Yet another tachikoma AI")) + :host($config.get("irc.host", "irc.darenet.org")) + :port($config.get("irc.port", 6667)) + :ssl($config.get("irc.ssl", False)) + :channels($config.get("irc.channels", "#scriptkitties")) + :debug($config.get("debug", True)) :!autoprefix :@plugins ); |