оптимизон от нейронки, доделал автоматические действия, добавил глобальный лог, сделал реконекты к ДА

This commit is contained in:
PC1\PTyTb
2025-08-08 14:57:56 +03:00
parent 1936c9c9c0
commit 71cdcc9909
23 changed files with 721 additions and 249 deletions
+28 -15
View File
@@ -7,6 +7,9 @@ uses
IdMultipartFormData, DateUtils, uDataBase, System.Generics.Collections,
uRecords;
type
TOnLog = procedure(aModul: string; aMethod: string; aMessage:string; aLevel:integer) of object;
type
TTTW_API = class(TObject)
private
@@ -16,6 +19,7 @@ type
channel_name_api: string;
BotName_api: string;
FChatBadges:tlist<TChatBadge>;
FOnLog:TOnLog;
function GetFollowedAtFromJson(jsonString: string): string;
function getTTW(method: string; ClientID: string;
@@ -30,6 +34,8 @@ type
function patchTTW(method: string; ClientID: string; params: TStringStream;
isStreamer: boolean = false): string; overload;
procedure toLog(alevel:integer; amethod:string; amessage:string);
public
constructor Create(Sender: TObject);
destructor Destroy; override;
@@ -66,6 +72,7 @@ type
procedure GetChannelEmotes(var ce: Tlist<TEmotes>);
procedure GetGlobalEmotes(var ge: Tlist<TEmotes>);
function ValidateTwitchToken(const TokenName, TokenValue: string; var DayOfLive:integer): Boolean;
property OnLog: TOnLog read FOnLog write FOnLog;
end;
TChatBadges = TList<TChatBadge>;
TEmotesList = TList<TEmotes>;
@@ -849,6 +856,12 @@ begin
end;
end;
procedure TTTW_API.toLog(alevel: integer; amethod, amessage: string);
begin
if Assigned(FOnLog) then
FOnLog('uTTWAPI', aMethod, aMessage, aLevel);
end;
procedure TTTW_API.unBanUser(id: string);
begin
try
@@ -862,7 +875,7 @@ begin
except
on E: Exception do
//Form1.Log(2, 'TTTW_API.unBanUser', E.Message);
// flog.toLog(2,'TTW_API','unBanUser',E.Message);
toLog(2,'unBanUser',E.Message);
end;
end;
@@ -876,7 +889,7 @@ begin
except
on E: Exception do
//Form1.Log(2, 'TTTW_API.unRaid', E.Message);
// flog.toLog(2,'TTW_API','unRaid',E.Message);
toLog(2,'unRaid',E.Message);
end;
end;
@@ -900,7 +913,7 @@ begin
except
on E: Exception do
//Form1.Log(2, 'TTTW_API.UpdateCustomReward', E.Message);
// flog.toLog(2,'TTW_API','UpdateCustomReward',E.Message);
toLog(2,'UpdateCustomReward',E.Message);
end;
end;
@@ -920,8 +933,8 @@ begin
//Form1.Log(1, 'TTTW_API.UpdateRedemptionStatus', 'ChannelId: ' + qbid +
// '; Reward.id: ' + qrid + '; Redemption.id: ' + qid);
// flog.toLog(1,'TTW_API','UpdateRedemptionStatus','ChannelId: ' + qbid +
// '; Reward.id: ' + qrid + '; Redemption.id: ' + qid);
toLog(1,'UpdateRedemptionStatus','ChannelId: ' + qbid +
'; Reward.id: ' + qrid + '; Redemption.id: ' + qid);
RequestData := TStringStream.Create('{"status":"CANCELED"}', CP_UTF8);
try
patchTTW('channel_points/custom_rewards/redemptions?broadcaster_id=' +
@@ -933,7 +946,7 @@ begin
except
on E: Exception do
// Form1.Log(2, 'TTTW_API.UpdateRedemptionStatus', E.Message);
// flog.toLog(2,'TTW_API','UpdateRedemptionStatus',E.Message);
toLog(2,'UpdateRedemptionStatus',E.Message);
end;
end;
@@ -986,10 +999,10 @@ begin
try
if ResponseJSON.GetValue('expires_in') <> nil then
begin
//fLog.toLog(0, 'TokenCheck', TokenName,
// Format('Òîêåí äåéñòâèòåëåí. Îñòàëîñü: %d ñåê. Êëèåíò: %s',
// [ResponseJSON.GetValue('expires_in').Value.ToInteger,
// ResponseJSON.GetValue('client_id').Value]));
toLog(0, 'ValidateTwitchToken',
Format('Òîêåí äåéñòâèòåëåí. Îñòàëîñü: %d ñåê. Êëèåíò: %s',
[ResponseJSON.GetValue('expires_in').Value.ToInteger,
ResponseJSON.GetValue('client_id').Value]));
DayOfLive:=round(ResponseJSON.GetValue('expires_in').Value.ToInteger/60/60/24);
end;
Result := True;
@@ -998,19 +1011,19 @@ begin
end;
except
on E: Exception do
//fLog.toLog(2, 'TokenCheck', 'JSON Parse', E.Message);
toLog(2, 'ValidateTwitchToken', E.Message);
end;
end
else if StatusCode = 401 then
begin
//fLog.toLog(2, 'TokenCheck', TokenName, 'Invalid token');
toLog(2, 'ValidateTwitchToken', 'Invalid token');
DayOfLive:=0;
end
else
begin
DayOfLive:=0;
// fLog.toLog(2, 'TokenCheck', TokenName,
// Format('HTTP %d: %s', [StatusCode, ResponseText]));
toLog(2, 'ValidateTwitchToken',
Format('HTTP %d: %s', [StatusCode, ResponseText]));
end;
finally
@@ -1041,7 +1054,7 @@ begin
except
on E: Exception do
//Form1.Log(2, 'TTTW_API.warnUser', E.Message);
// flog.toLog(2,'TTW_API','warnUser',E.Message);
toLog(2,'warnUser',E.Message);
end;
end;