@@ -21,7 +21,9 @@ TShellThread=class(TThread)
2121 FProc: TProcess;
2222 FTerminated: Boolean;
2323 FLPTimeout: Integer;
24- procedure BotReceiveCallbackQuery ({ %H-} ASender: TObject; ACallback: TCallbackQueryObj);
24+ procedure BotReceiveCallbackQuery ({ %H-} ASender: TObject; ACallback: TCallbackQueryObj);
25+ procedure BotReceiveDeleteCommand ({ %H-} ASender: TObject; const { %H-} ACommand: String;
26+ AMessage: TTelegramMessageObj);
2527 procedure BotReceiveMessage ({ %H-} ASender: TObject; AMessage: TTelegramMessageObj);
2628 function BotReceiveDocument (aDocument: TTelegramDocument; const aPath: String): Boolean;
2729 { Read output from shell terminal by command }
@@ -89,11 +91,13 @@ implementation
8991 _ScriptFileExt=' .script' ;
9092
9193 emj_FileFolder=' 📁' ;
94+ emj_Wrnng=' ⚠️' ;
9295
9396 dt_script=' script' ;
9497 dt_dir=' dir' ;
9598 dt_file=' file' ;
96- dt_input=' input' ;
99+ dt_input=' input' ;
100+ dt_dlt=' delete' ;
97101
98102
99103{ TShellThread }
@@ -183,6 +187,22 @@ procedure TShellThread.BotReceiveCallbackQuery(ASender: TObject; ACallback: TCal
183187 end ;
184188end ;
185189
190+ procedure TShellThread.BotReceiveDeleteCommand (ASender: TObject; const ACommand: String; AMessage: TTelegramMessageObj);
191+ var
192+ aPath: String;
193+ begin
194+ if not CommandStart then
195+ Exit;
196+ aPath:=ExtractDelimited(2 , AMessage.Text, [' ' ]);
197+ if aPath.IsEmpty then
198+ FBot.sendMessage(' Use command line format like /delete `/path-to-the-file/file-name.ext`' , pmMarkdown)
199+ else
200+ if DeleteFileUTF8(aPath) then
201+ FBot.sendMessage(Format(' File (%s) succesfully deleted' , [aPath]))
202+ else
203+ FBot.sendMessage(emj_Wrnng+' ' +Format(' File (%s) deletion error' , [aPath]))
204+ end ;
205+
186206procedure TShellThread.BotReceiveReadCommand (ASender: TObject;
187207 const ACommand: String; AMessage: TTelegramMessageObj);
188208begin
@@ -481,7 +501,8 @@ constructor TShellThread.Create;
481501 FBot.CommandHandlers[' /sigkill' ]:=@BotReceiveSIGKILLCommand;
482502 FBot.CommandHandlers[' /sigquit' ]:=@BotReceiveSIGQUITCommand;
483503 FBot.CommandHandlers[' /sigterm' ]:=@BotReceiveSIGTERMCommand;{ $ENDIF}
484- FBot.CommandHandlers[' /' +dt_dir]:=@BotReceiveFileCommand;
504+ FBot.CommandHandlers[' /' +dt_dir]:=@BotReceiveFileCommand;
505+ FBot.CommandHandlers[' /' +dt_dlt]:=@BotReceiveDeleteCommand;
485506 FBot.OnReceiveCallbackQuery:=@BotReceiveCallbackQuery;{ $IFDEF MSWINDOWS}
486507 SetConsoleOutputCP(CP_UTF8);{ $ENDIF}
487508 FBot.ServiceUser:=Cnfg.ServiceUser;
0 commit comments