Split out areafix command processing, implemented start of filefix
This commit is contained in:
93
app/Classes/FTN/Process/Netmail/Robot/Areafix.php
Normal file
93
app/Classes/FTN/Process/Netmail/Robot/Areafix.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\FTN\Process\Netmail\Robot;
|
||||
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
use App\Classes\FTN\Process\Netmail\Robot;
|
||||
use App\Models\{Echomail,Netmail};
|
||||
use App\Notifications\Netmails\Areafix\CommandsProcessed;
|
||||
|
||||
/**
|
||||
* Process messages to Ping
|
||||
*
|
||||
* @package App\Classes\FTN\Process
|
||||
*/
|
||||
final class Areafix extends Robot
|
||||
{
|
||||
private const LOGKEY = 'RPA';
|
||||
|
||||
public const commands = 'App\\Classes\\FTN\\Process\\Netmail\\Robot\\Areafix\\';
|
||||
|
||||
public static function handle(Echomail|Netmail $mo): bool
|
||||
{
|
||||
if ((strtolower($mo->to) !== 'areafix') || (! ($mo instanceof Netmail)))
|
||||
return FALSE;
|
||||
|
||||
Log::info(sprintf('%s:- Processing AREAFIX [%s] message from (%s) [%s]', self::LOGKEY, $mo->to, $mo->from, $mo->fftn->ftn));
|
||||
|
||||
return parent::handle($mo);
|
||||
}
|
||||
|
||||
public static function areafix(Netmail $mo): bool
|
||||
{
|
||||
$result = collect();
|
||||
$result->push('--> BEGIN <--');
|
||||
|
||||
foreach ($mo->body_lines as $command) {
|
||||
// Skip empty lines
|
||||
if (! $command)
|
||||
continue;
|
||||
|
||||
$command = explode(' ',strtoupper(trim($command)));
|
||||
|
||||
// If command starts with '...' or '---', its a tear/tag line, and we have reached the end
|
||||
if (str_starts_with($command[0],'...') || str_starts_with($command[0],'---')) {
|
||||
Log::debug(sprintf('%s:= We got a tearline/tagline, end of processing',self::LOGKEY));
|
||||
|
||||
$result->push('--> END OF PROCESSING <--');
|
||||
|
||||
break;
|
||||
|
||||
// If command doesnt start with %, its an area
|
||||
} elseif (! str_starts_with($command[0],'%')) {
|
||||
Log::info(sprintf('%s:= Assuming command [%s] is an AREA command',self::LOGKEY,$command[0]));
|
||||
|
||||
array_unshift($command,'%AREA');
|
||||
}
|
||||
|
||||
// Some commands are reserved words
|
||||
switch ($x=strtolower(substr($command[0],1))) {
|
||||
case 'list':
|
||||
$class = self::commands.'AreaList';
|
||||
break;
|
||||
|
||||
default:
|
||||
// Parse the message body and pluck out the commands on each line
|
||||
$class = self::commands.ucfirst($x);
|
||||
}
|
||||
|
||||
if (! class_exists($class)) {
|
||||
$result->push(sprintf('%-25s <-- **COMMAND UNKNOWN**',join(' ',$command)));
|
||||
Log::info(sprintf('%s:! Command UNKNOWN [%s] ',self::LOGKEY,join('|',$command)),['class'=>$class]);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// Drop the command from the array, the rest are arguments
|
||||
array_shift($command);
|
||||
|
||||
// Refresh our echoareas
|
||||
$mo->fftn->load('echoareas');
|
||||
|
||||
$o = new $class($mo,$command);
|
||||
$result->push($o->process());
|
||||
}
|
||||
|
||||
// Reply with a confirmation of what commands were processed
|
||||
Notification::route('netmail',$mo->fftn)->notify(new CommandsProcessed($mo,$result));
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
}
|
@@ -5,7 +5,7 @@ namespace App\Classes\FTN\Process\Netmail\Robot\Areafix;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
|
||||
use App\Classes\FTN\Process\Netmail\Areafix;
|
||||
use App\Classes\FTN\Process\Netmail\Robot\Areafix;
|
||||
use App\Notifications\Netmails\Areafix\Help as HelpNotification;
|
||||
|
||||
// A Help Index Command
|
||||
@@ -33,7 +33,7 @@ class Help extends Base
|
||||
if (($file === 'Base.php') || (! str_ends_with(strtolower($file),'.php')))
|
||||
continue;
|
||||
|
||||
$class = Areafix::areafix_commands.preg_replace('/\.php$/','',$file);
|
||||
$class = Areafix::commands.preg_replace('/\.php$/','',$file);
|
||||
if ($result->count())
|
||||
$result->push('');
|
||||
|
||||
|
93
app/Classes/FTN/Process/Netmail/Robot/Filefix.php
Normal file
93
app/Classes/FTN/Process/Netmail/Robot/Filefix.php
Normal file
@@ -0,0 +1,93 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\FTN\Process\Netmail\Robot;
|
||||
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
use App\Classes\FTN\Process\Netmail\Robot;
|
||||
use App\Models\{Echomail,Netmail};
|
||||
use App\Notifications\Netmails\Areafix\CommandsProcessed;
|
||||
|
||||
/**
|
||||
* Process messages to Ping
|
||||
*
|
||||
* @package App\Classes\FTN\Process
|
||||
*/
|
||||
final class Filefix extends Robot
|
||||
{
|
||||
private const LOGKEY = 'RPF';
|
||||
|
||||
public const commands = 'App\\Classes\\FTN\\Process\\Netmail\\Robot\\Filefix\\';
|
||||
|
||||
public static function handle(Echomail|Netmail $mo): bool
|
||||
{
|
||||
if ((strtolower($mo->to) !== 'filefix') || (! ($mo instanceof Netmail)))
|
||||
return FALSE;
|
||||
|
||||
Log::info(sprintf('%s:- Processing FILEFIX [%s] message from (%s) [%s]', self::LOGKEY, $mo->to, $mo->from, $mo->fftn->ftn));
|
||||
|
||||
return parent::handle($mo);
|
||||
}
|
||||
|
||||
public static function filefix(Netmail $mo): bool
|
||||
{
|
||||
$result = collect();
|
||||
$result->push('--> BEGIN <--');
|
||||
|
||||
foreach ($mo->body_lines as $command) {
|
||||
// Skip empty lines
|
||||
if (! $command)
|
||||
continue;
|
||||
|
||||
$command = explode(' ',strtoupper(trim($command)));
|
||||
|
||||
// If command starts with '...' or '---', its a tear/tag line, and we have reached the end
|
||||
if (str_starts_with($command[0],'...') || str_starts_with($command[0],'---')) {
|
||||
Log::debug(sprintf('%s:= We got a tearline/tagline, end of processing',self::LOGKEY));
|
||||
|
||||
$result->push('--> END OF PROCESSING <--');
|
||||
|
||||
break;
|
||||
|
||||
// If command doesnt start with %, its an area
|
||||
} elseif (! str_starts_with($command[0],'%')) {
|
||||
Log::info(sprintf('%s:= Assuming command [%s] is an AREA command',self::LOGKEY,$command[0]));
|
||||
|
||||
array_unshift($command,'%AREA');
|
||||
}
|
||||
|
||||
// Some commands are reserved words
|
||||
switch ($x=strtolower(substr($command[0],1))) {
|
||||
case 'list':
|
||||
$class = self::commands.'FileList';
|
||||
break;
|
||||
|
||||
default:
|
||||
// Parse the message body and pluck out the commands on each line
|
||||
$class = self::commands.ucfirst($x);
|
||||
}
|
||||
|
||||
if (! class_exists($class)) {
|
||||
$result->push(sprintf('%-25s <-- **COMMAND UNKNOWN**',join(' ',$command)));
|
||||
Log::info(sprintf('%s:! Command UNKNOWN [%s] ',self::LOGKEY,join('|',$command)),['class'=>$class]);
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
// Drop the command from the array, the rest are arguments
|
||||
array_shift($command);
|
||||
|
||||
// Refresh our echoareas
|
||||
$mo->fftn->load('fileareas');
|
||||
|
||||
$o = new $class($mo,$command);
|
||||
$result->push($o->process());
|
||||
}
|
||||
|
||||
// Reply with a confirmation of what commands were processed
|
||||
Notification::route('netmail',$mo->fftn)->notify(new CommandsProcessed($mo,$result));
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
}
|
50
app/Classes/FTN/Process/Netmail/Robot/Filefix/Help.php
Normal file
50
app/Classes/FTN/Process/Netmail/Robot/Filefix/Help.php
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace App\Classes\FTN\Process\Netmail\Robot\Filefix;
|
||||
|
||||
use App\Classes\FTN\Process\Netmail\Robot\Areafix\Base;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Notification;
|
||||
|
||||
use App\Classes\FTN\Process\Netmail\Robot\Filefix;
|
||||
use App\Notifications\Netmails\Filefix\Help as HelpNotification;
|
||||
|
||||
// A Help Index Command
|
||||
class Help extends Base
|
||||
{
|
||||
private const LOGKEY = 'FFH';
|
||||
|
||||
private const filefix_classes = 'app/Classes/FTN/Process/Netmail/Robot/Filefix';
|
||||
private const command = '%HELP';
|
||||
|
||||
public static function help(): array
|
||||
{
|
||||
return [
|
||||
self::command,
|
||||
' This message!',
|
||||
];
|
||||
}
|
||||
|
||||
public function process(): string
|
||||
{
|
||||
Log::debug(sprintf('%s:- Processing [%s] for [%s]',self::LOGKEY,self::command,$this->mo->fftn->ftn));
|
||||
|
||||
$result = collect();
|
||||
|
||||
foreach (preg_grep('/^([^.])/',scandir(self::filefix_classes)) as $file) {
|
||||
if (($file === 'Base.php') || (! str_ends_with(strtolower($file),'.php')))
|
||||
continue;
|
||||
|
||||
$class = Filefix::commands.preg_replace('/\.php$/','',$file);
|
||||
if ($result->count())
|
||||
$result->push('');
|
||||
|
||||
$result = $result
|
||||
->merge($class::help());
|
||||
}
|
||||
|
||||
Notification::route('netmail',$this->mo->fftn)->notify(new HelpNotification($this->mo,$result));
|
||||
|
||||
return sprintf('%-25s <-- COMMAND PROCESSED',self::command);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user