Skip to content

Commit

Permalink
/delete command for file manager
Browse files Browse the repository at this point in the history
and new deb version
  • Loading branch information
Al-Muhandis committed Dec 17, 2024
1 parent 4a0f1ab commit 83b62dd
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 9 deletions.
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,13 @@ DefaultDir=
3. Run as a console program or daemon/service.

### DEB package
You can easily install using a .deb file on Debian/Ubuntu/etc.
You can easily install/upgrade using a .deb file on Debian/Ubuntu/etc.

#### installation with deb
Download deb package from release section https://github.com/Al-Muhandis/ShellRemoteBot/releases
Then install for example:
``` BASH
sudo dpkg --install tgshd_1.2.4-1_amd64.deb
```SH
sudo dpkg --install tgshd_1.2.5-2_amd64.deb
# After package installation set up at least token and admin user id in the INI file located at /etc/tgshd/tgshd.ini
# for example with Nano editor
sudo nano /etc/tgshd/tgshd.ini
Expand All @@ -70,6 +72,14 @@ sudo nano /etc/tgshd/tgshd.ini
systemctl enable tgshd
systemctl start tgshd
```
#### Upgrade with deb

```SH
sudo systemctl stop tgshd
sudo dpkg --install tgshd_1.2.5-2_amd64.deb
sudo systemctl daemon-reload
systemctl start tgshd
```

## Users rights and telegram user ID
You can define user access in configuration file `tgshd.ini` by adding string like `user_id=a` where user_id is telegram user id of administrator.
Expand All @@ -91,6 +101,8 @@ Calls the menu for executing the prepared script from the list of files. Scripts
or you can set the folder in the settings in the the `[Scripts]` section / `Directory`
### /dir
Calls the file Manager. You can set the default value in the configuration file
### /delete
With the command (`/delete` `/fullpath/to/file`) You can delete file

## Possible problems

Expand Down
2 changes: 1 addition & 1 deletion deb.staging/DEBIAN/control
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: tgshd
Priority: optional
Version: 1.2.1.4-1
Version: 1.2.5.1-2
Maintainer: Renat Suleymanov <[email protected]>
Architecture: amd64
Section: utils
Expand Down
27 changes: 24 additions & 3 deletions src/shellthread.pas
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ TShellThread=class(TThread)
FProc: TProcess;
FTerminated: Boolean;
FLPTimeout: Integer;
procedure BotReceiveCallbackQuery({%H-}ASender: TObject; ACallback: TCallbackQueryObj);
procedure BotReceiveCallbackQuery({%H-}ASender: TObject; ACallback: TCallbackQueryObj);
procedure BotReceiveDeleteCommand({%H-}ASender: TObject; const {%H-}ACommand: String;
AMessage: TTelegramMessageObj);
procedure BotReceiveMessage({%H-}ASender: TObject; AMessage: TTelegramMessageObj);
function BotReceiveDocument(aDocument: TTelegramDocument; const aPath: String): Boolean;
{ Read output from shell terminal by command }
Expand Down Expand Up @@ -89,11 +91,13 @@ implementation
_ScriptFileExt='.script';

emj_FileFolder='📁';
emj_Wrnng='⚠️';

dt_script='script';
dt_dir='dir';
dt_file='file';
dt_input='input';
dt_input='input';
dt_dlt='delete';


{ TShellThread }
Expand Down Expand Up @@ -183,6 +187,22 @@ procedure TShellThread.BotReceiveCallbackQuery(ASender: TObject; ACallback: TCal
end;
end;

procedure TShellThread.BotReceiveDeleteCommand(ASender: TObject; const ACommand: String; AMessage: TTelegramMessageObj);
var
aPath: String;
begin
if not CommandStart then
Exit;
aPath:=ExtractDelimited(2, AMessage.Text, [' ']);
if aPath.IsEmpty then
FBot.sendMessage('Use command line format like /delete `/path-to-the-file/file-name.ext`', pmMarkdown)
else
if DeleteFileUTF8(aPath) then
FBot.sendMessage(Format('File (%s) succesfully deleted', [aPath]))
else
FBot.sendMessage(emj_Wrnng+' '+Format('File (%s) deletion error', [aPath]))
end;

procedure TShellThread.BotReceiveReadCommand(ASender: TObject;
const ACommand: String; AMessage: TTelegramMessageObj);
begin
Expand Down Expand Up @@ -481,7 +501,8 @@ constructor TShellThread.Create;
FBot.CommandHandlers['/sigkill']:=@BotReceiveSIGKILLCommand;
FBot.CommandHandlers['/sigquit']:=@BotReceiveSIGQUITCommand;
FBot.CommandHandlers['/sigterm']:=@BotReceiveSIGTERMCommand;{$ENDIF}
FBot.CommandHandlers['/'+dt_dir]:=@BotReceiveFileCommand;
FBot.CommandHandlers['/'+dt_dir]:=@BotReceiveFileCommand;
FBot.CommandHandlers['/'+dt_dlt]:=@BotReceiveDeleteCommand;
FBot.OnReceiveCallbackQuery:=@BotReceiveCallbackQuery;{$IFDEF MSWINDOWS}
SetConsoleOutputCP(CP_UTF8);{$ENDIF}
FBot.ServiceUser:=Cnfg.ServiceUser;
Expand Down
4 changes: 2 additions & 2 deletions src/tgshd.lpi
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
<AutoIncrementBuild Value="True"/>
<MajorVersionNr Value="1"/>
<MinorVersionNr Value="2"/>
<RevisionNr Value="2"/>
<BuildNr Value="1"/>
<RevisionNr Value="5"/>
<BuildNr Value="3"/>
</VersionInfo>
<BuildModes Count="4">
<Item1 Name="Default" Default="True"/>
Expand Down

0 comments on commit 83b62dd

Please sign in to comment.