Skip to content

Commit b19cbe6

Browse files
author
MAXIM-SYSOEV\WorkPC
committed
Merge branch 'release/3.5.5'
2 parents c226296 + 1d3bb88 commit b19cbe6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+4912
-2650
lines changed

Delphinus.Info.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"dependencies": [],
1313
"author": "Maxim Sysoev",
1414
"description": "Telegram Bot API for Delphi",
15-
"version": "3.5.4",
15+
"version": "3.5.5",
1616
"first_version": "2.3.1",
1717
"project_url": "https://github.com/ms301/TelegAPI",
1818
"homepage_url": "https://t.me/telegaPiBotTest",

Demo/Console/ConsoleBot.dpr

Lines changed: 25 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,9 @@
55

66
{/$DEFINE USE_INDY_CORE}
77
uses
8-
{$IFDEF USE_INDY_CORE}
9-
//Indy Http Core
8+
{$IFDEF USE_INDY_CORE} //Indy Http Core
109
CrossUrl.Indy.HttpClient,
11-
{$ELSE}
12-
// System.Net HTTP Core
10+
{$ELSE} // System.Net HTTP Core
1311
CrossUrl.SystemNet.HttpClient,
1412
{$ENDIF}
1513

@@ -19,16 +17,11 @@ uses
1917
TelegAPI.Bot,
2018
TelegAPI.Types,
2119
TelegAPI.Bot.Impl,
22-
TelegAPI.Exceptions;
20+
TelegAPI.Logger,
21+
TelegAPI.Logger.Old;
2322

24-
procedure SMG(ABot: ITelegramBot; AMessage: ITgMessage);
25-
var
26-
Test: TtgInputMediaPhoto;
27-
begin
28-
Test := TtgInputMediaPhoto.Create(TtgFileToSend.FromFile('D:\Repositories\Мои проекты\ms301-TelegAPI\Install\pJNqeRflXYU.png'),
29-
'Test');
30-
ABot.sendMediaGroup(AMessage.Chat.ID, [Test, Test])
31-
end;
23+
const
24+
TOKEN = 'YOUR_TOKEN';
3225

3326
procedure Main;
3427
var
@@ -37,24 +30,25 @@ var
3730
LExcp: TtgExceptionManagerConsole;
3831
LStop: string;
3932
begin
40-
LBot := TTelegramBot.Create('YOUR_TOKEN',
41-
{$IFDEF USE_INDY_CORE}
42-
TcuHttpClientIndy.Create(nil)
43-
{$ELSE}
44-
TcuHttpClientSysNet.Create(nil)
45-
{$ENDIF});
33+
{$IFDEF USE_INDY_CORE}
34+
LBot := TTelegramBot.Create(TOKEN, TcuHttpClientIndy.Create(nil));
35+
{$ELSE}
36+
LBot := TTelegramBot.Create(TOKEN, TcuHttpClientSysNet.Create(nil));
37+
{$ENDIF}
4638
LReceiver := TtgReceiverConsole.Create(LBot);
39+
LBot.Logger := TtgExceptionManagerConsole.Create(nil);
4740
try
48-
LExcp := LBot.ExceptionManager as TtgExceptionManagerConsole;
49-
LExcp.OnApiException :=
50-
procedure(AMethod: string; AExp: EApiRequestException)
51-
begin
52-
Writeln(AExp.ToString);
53-
end;
54-
LExcp.OnGlobalException :=
55-
procedure(AMethod: string; AExp: Exception)
41+
LExcp := LBot.Logger as TtgExceptionManagerConsole;
42+
LExcp.OnLog :=
43+
procedure(level: TLogLevel; msg: string; e: Exception)
5644
begin
57-
Writeln(AExp.ToString);
45+
if level >= TLogLevel.Error then
46+
begin
47+
if Assigned(e) then
48+
Writeln('[' + e.ToString + '] ' + msg)
49+
else
50+
Writeln(msg);
51+
end;
5852
end;
5953
LReceiver.OnStart :=
6054
procedure
@@ -70,8 +64,7 @@ begin
7064
procedure(AMessage: ITgMessage)
7165
begin
7266
Writeln(AMessage.From.ID, ': ', AMessage.Text);
73-
// LBot.SendMessage(AMessage.From.ID, AMessage.Text);
74-
SMG(LBot, AMessage);
67+
LBot.SendMessage(AMessage.From.ID, AMessage.Text);
7568
end;
7669
Writeln('Bot nick: ', LBot.GetMe.Username);
7770
LReceiver.IsActive := True;
@@ -93,8 +86,8 @@ begin
9386
{ TODO -oUser -cConsole Main : Insert code here }
9487
Main;
9588
except
96-
on E: Exception do
97-
Writeln(E.ClassName, ': ', E.message);
89+
on e: Exception do
90+
Writeln(e.ClassName, ': ', e.message);
9891
end;
9992

10093
end.

0 commit comments

Comments
 (0)