From 1128bddcee5091678627ecb8d4bfa8882999ea01 Mon Sep 17 00:00:00 2001 From: Deon George Date: Thu, 31 Oct 2024 23:53:43 +1100 Subject: [PATCH] Added areafix %HELP --- app/Classes/FTN/Process/Netmail/Areafix.php | 4 +- .../Process/Netmail/Robot/Areafix/Area.php | 58 ++++++++-------- .../Process/Netmail/Robot/Areafix/Base.php | 12 ++-- .../Process/Netmail/Robot/Areafix/Help.php | 44 ++++++++++++ .../Netmails/Areafix/CommandsProcessed.php | 67 +++++++++++++++++++ app/Notifications/Netmails/Areafix/Help.php | 65 ++++++++++++++++++ 6 files changed, 214 insertions(+), 36 deletions(-) create mode 100644 app/Classes/FTN/Process/Netmail/Robot/Areafix/Help.php create mode 100644 app/Notifications/Netmails/Areafix/CommandsProcessed.php create mode 100644 app/Notifications/Netmails/Areafix/Help.php diff --git a/app/Classes/FTN/Process/Netmail/Areafix.php b/app/Classes/FTN/Process/Netmail/Areafix.php index a97f4ef..0dcfdfa 100644 --- a/app/Classes/FTN/Process/Netmail/Areafix.php +++ b/app/Classes/FTN/Process/Netmail/Areafix.php @@ -19,7 +19,7 @@ final class Areafix extends Process { private const LOGKEY = 'RP-'; - private const areafix_commands = 'App\\Classes\\FTN\\Process\\Netmail\\Robot\\Areafix\\'; + public const areafix_commands = 'App\\Classes\\FTN\\Process\\Netmail\\Robot\\Areafix\\'; public static function handle(Echomail|Netmail $mo): bool { @@ -82,7 +82,7 @@ final class Areafix extends Process // Refresh our echoareas $mo->fftn->load('echoareas'); - $o = new $class($mo->fftn,$command); + $o = new $class($mo,$command); $result->push($o->process()); } diff --git a/app/Classes/FTN/Process/Netmail/Robot/Areafix/Area.php b/app/Classes/FTN/Process/Netmail/Robot/Areafix/Area.php index b4ece79..d9cde0c 100644 --- a/app/Classes/FTN/Process/Netmail/Robot/Areafix/Area.php +++ b/app/Classes/FTN/Process/Netmail/Robot/Areafix/Area.php @@ -13,21 +13,23 @@ class Area extends Base { private const LOGKEY = 'AFA'; - public function help(): array + private const command = '%AREA'; + + public static function help(): array { return [ - '%AREA [-|+] [R|D=]', - ' Use the area command to subscribe (+) or unsubscribe (-) to an ECHOAREA', - ' Arguments:', - ' - ECHOAREA (required) name of area to subscribe or unsubscribe', - ' - D=DAYS (optional) number of days to resend mail from this area that you', - ' havent already received (useful if you are resubscribing to an area and', - ' have received mail in the past)', - ' - R=DAYS (optional) number of days to resend mail from this area (even if', - ' it was sent to you previously)', - ' Notes:', - ' * "+" is optional, and is implied if "-" is not used', - ' * "R" and "D" options only apply to subscribing', + self::command.' [-|+] [R|D=]', + ' Use the area command to subscribe (+) or unsubscribe (-) to an ECHOAREA', + ' Arguments:', + ' - ECHOAREA (required) name of area to subscribe or unsubscribe', + ' - D=DAYS (optional) number of days to resend mail from this area that you', + ' havent already received (useful if you are resubscribing to an area and', + ' have received mail in the past)', + ' - R=DAYS (optional) number of days to resend mail from this area (even if', + ' it was sent to you previously)', + ' Notes:', + ' * "+" is optional, and is implied if "-" is not used', + ' * "R" and "D" options only apply to subscribing', ]; } @@ -52,40 +54,40 @@ class Area extends Base // Drop the area from the arguments, the rest are options array_shift($this->arguments); - if ($ea=$this->ao->domain->echoareas->where('name',$area)->pop()) { + if ($ea=$this->mo->fftn->domain->echoareas->where('name',$area)->pop()) { // If already subscribed - if ($nea=$this->ao->echoareas->where('name',$area)->pop()) { + if ($nea=$this->mo->fftn->echoareas->where('name',$area)->pop()) { // requesting to subscribe "You already are since..., arguments ignored if ($sub) { - Log::debug(sprintf('%s:- FTN [%s] ALREADY subscribed to [%s] since [%s]',self::LOGKEY,$this->ao->ftn,$area,$nea->pivot->subscribed->format('Y-m-d H:i'))); + Log::debug(sprintf('%s:- FTN [%s] ALREADY subscribed to [%s] since [%s]',self::LOGKEY,$this->mo->fftn->ftn,$area,$nea->pivot->subscribed->format('Y-m-d H:i'))); return sprintf('%-25s <-- ALREADY subscribed since %s',$area,$nea->pivot->subscribed->format('Y-m-d H:i')); // requesting to unsubscribe } else { - $this->ao->echoareas()->detach($ea->id); + $this->mo->fftn->echoareas()->detach($ea->id); // Remove sub, clear queue $x = DB::table('echomail_seenby') - ->where('address_id',$this->ao->id) + ->where('address_id',$this->mo->fftn->id) ->join('echomails',['echomails.id'=>'echomail_seenby.echomail_id']) ->where('echoarea_id',$nea->id) ->whereNotNull('export_at') ->whereNull('sent_at') ->orderBy('echomails.datetime') - ->skip($this->ao->system->pkt_msgs) + ->skip($this->mo->fftn->system->pkt_msgs) ->delete(); - Log::debug(sprintf('%s:- FTN [%s] UNSUBSCRIBED from [%s] clearing [%s]',self::LOGKEY,$this->ao->ftn,$area,$x)); + Log::debug(sprintf('%s:- FTN [%s] UNSUBSCRIBED from [%s] clearing [%s]',self::LOGKEY,$this->mo->fftn->ftn,$area,$x)); - return sprintf('%-25s <-- UNSUBSCRIBED, cleared [%d] items from queue',$area,$x); + return sprintf('%-25s <-- UNSUBSCRIBED, CLEARED [%d] MSGS from queue',$area,$x); } // If not subscribed } else { // requesting to subscribe, subsubsribe and rescan if arguments if ($sub) { - $this->ao->echoareas()->attach([$ea->id=>['subscribed'=>Carbon::now()]]); + $this->mo->fftn->echoareas()->attach([$ea->id=>['subscribed'=>Carbon::now()]]); // If we have arguments, they are to rescan if (count($this->arguments) === 1) { @@ -94,14 +96,14 @@ class Area extends Base switch ($m[1]) { // Scan case 'D': - AreafixRescan::dispatch($this->ao,$ea,$m[2]) + AreafixRescan::dispatch($this->mo->fftn,$ea,$m[2]) ->onQueue('mail'); return sprintf('%-25s <-- AREA SUBSCRIBED, RESCAN [%d] DAYS queued',$area,$m[2]); // Scan case 'R': - AreafixRescan::dispatch($this->ao,$ea,$m[2],TRUE) + AreafixRescan::dispatch($this->mo->fftn,$ea,$m[2],TRUE) ->onQueue('mail'); return sprintf('%-25s <-- AREA SUBSCRIBED, FORCE RESCAN [%d] DAYS queued',$area,$m[2]); @@ -111,26 +113,26 @@ class Area extends Base return sprintf('%-25s <-- AREA SUBSCRIBED, INVALID OPTIONS',$area); } elseif (count($this->arguments) > 1) { - Log::debug(sprintf('%s:- FTN [%s] subscribed to [%s], extra commands [%s] ignored',self::LOGKEY,$this->ao->ftn,$area,implode('|',$this->arguments))); + Log::debug(sprintf('%s:- FTN [%s] subscribed to [%s], extra commands [%s] ignored',self::LOGKEY,$this->mo->fftn->ftn,$area,implode('|',$this->arguments))); return sprintf('%-25s <-- AREA SUBSCRIBED, OPTIONS IGNORED',$area); } else { - Log::debug(sprintf('%s:- FTN [%s] subscribed to [%s]',self::LOGKEY,$this->ao->ftn,$area)); + Log::debug(sprintf('%s:- FTN [%s] subscribed to [%s]',self::LOGKEY,$this->mo->fftn->ftn,$area)); return sprintf('%-25s <-- AREA SUBSCRIBED',$area); } // If not subscribed, "you arent subscribed, arguments ignored" } else { - Log::debug(sprintf('%s:- FTN [%s] is NOT subscribed to [%s], NO ACTION taken',self::LOGKEY,$this->ao->ftn,$area)); + Log::debug(sprintf('%s:- FTN [%s] is NOT subscribed to [%s], NO ACTION taken',self::LOGKEY,$this->mo->fftn->ftn,$area)); return sprintf('%-25s <-- NOT subscribed, NO ACTION taken',$area); } } } else { - Log::debug(sprintf('%s:- FTN [%s] area UNKNOWN [%s], NO ACTION taken',self::LOGKEY,$this->ao->ftn,$area)); + Log::debug(sprintf('%s:- FTN [%s] area UNKNOWN [%s], NO ACTION taken',self::LOGKEY,$this->mo->fftn->ftn,$area)); return sprintf('%-25s <-- AREA UNKNOWN, NO ACTION TAKEN',$area); } diff --git a/app/Classes/FTN/Process/Netmail/Robot/Areafix/Base.php b/app/Classes/FTN/Process/Netmail/Robot/Areafix/Base.php index a68cafb..1b6480b 100644 --- a/app/Classes/FTN/Process/Netmail/Robot/Areafix/Base.php +++ b/app/Classes/FTN/Process/Netmail/Robot/Areafix/Base.php @@ -4,23 +4,23 @@ namespace App\Classes\FTN\Process\Netmail\Robot\Areafix; use Illuminate\Support\Facades\Log; -use App\Models\Address; +use App\Models\Netmail; // Our base areafix commands class abstract class Base { private const LOGKEY = 'AB-'; - protected Address $ao; + protected Netmail $mo; protected array $arguments; - public function __construct(Address $ao,array $arguments) { - Log::debug(sprintf('%s:- Areafix [%s] command with arguments [%s] for [%s]',self::LOGKEY,get_class($this),implode('|',$arguments),$ao->ftn)); + public function __construct(Netmail $mo,array $arguments) { + Log::debug(sprintf('%s:- Areafix [%s] command with arguments [%s] for [%s]',self::LOGKEY,get_class($this),implode('|',$arguments),$mo->fftn->ftn)); - $this->ao = $ao; + $this->mo = $mo; $this->arguments = $arguments; } - abstract public function help(): array; + abstract public static function help(): array; abstract public function process(): string; } \ No newline at end of file diff --git a/app/Classes/FTN/Process/Netmail/Robot/Areafix/Help.php b/app/Classes/FTN/Process/Netmail/Robot/Areafix/Help.php new file mode 100644 index 0000000..daac1db --- /dev/null +++ b/app/Classes/FTN/Process/Netmail/Robot/Areafix/Help.php @@ -0,0 +1,44 @@ +mo->fftn->ftn)); + + $result = collect(); + + foreach (preg_grep('/^([^.])/',scandir(self::areafix_classes)) as $file) { + if ($file === 'Base.php') + continue; + + $class = Areafix::areafix_commands.preg_replace('/\.php$/','',$file); + $result = $result->merge($class::help()); + } + + Notification::route('netmail',$this->mo->fftn)->notify(new HelpNotification($this->mo,$result)); + + return sprintf('%-25s <-- COMMAND PROCESSED',self::command); + } +} \ No newline at end of file diff --git a/app/Notifications/Netmails/Areafix/CommandsProcessed.php b/app/Notifications/Netmails/Areafix/CommandsProcessed.php new file mode 100644 index 0000000..192f891 --- /dev/null +++ b/app/Notifications/Netmails/Areafix/CommandsProcessed.php @@ -0,0 +1,67 @@ +setupNetmail($notifiable); + $ao = $notifiable->routeNotificationFor(static::via); + + Log::info(sprintf('%s:+ Responding to areafix for a node [%s] commands processed',self::LOGKEY,$ao->ftn)); + + $o->to = $this->mo->from; + $o->replyid = $this->mo->msgid; + $o->subject = 'Areafix - Result'; + + // Message + $msg = $this->page(FALSE,'Areafix'); + + $msg->addText("Your areafix request has been received, here is the result:\r\r"); + + foreach ($this->commands as $command) { + $msg->addText("$command\r"); + } + + $msg->addText("\r"); + + $msg->addText($this->message_path($this->mo)); + + $o->msg = $msg->render(); + $o->set_tagline = 'Why did the robot cross the road? The chicken programmed it.'; + + $o->save(); + + return $o; + } +} \ No newline at end of file diff --git a/app/Notifications/Netmails/Areafix/Help.php b/app/Notifications/Netmails/Areafix/Help.php new file mode 100644 index 0000000..08b648c --- /dev/null +++ b/app/Notifications/Netmails/Areafix/Help.php @@ -0,0 +1,65 @@ +setupNetmail($notifiable); + $ao = $notifiable->routeNotificationFor(static::via); + + Log::info(sprintf('%s:+ Responding to areafix for a node [%s] commands processed',self::LOGKEY,$ao->ftn)); + + $o->to = $this->mo->from; + $o->replyid = $this->mo->msgid; + $o->subject = 'Areafix - Help'; + + // Message + $msg = $this->page(FALSE,'Areafix'); + + $msg->addText("Here are the list of commands available to you:\r\r\r\r"); + + foreach ($this->commands as $command) { + $msg->addText("$command\r"); + } + + $msg->addText("\r"); + + $o->msg = $msg->render(); + $o->set_tagline = 'Why did the robot cross the road? The chicken programmed it.'; + + $o->save(); + + return $o; + } +} \ No newline at end of file