Голоса перенесены в AppData
This commit is contained in:
+37
-35
@@ -4,11 +4,12 @@ interface
|
||||
|
||||
uses
|
||||
System.SysUtils, System.Types, System.UITypes, System.Classes,
|
||||
System.Variants, uQ,
|
||||
System.Variants, uQ, IdHTTP, IdComponent, System.Zip,
|
||||
FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls,
|
||||
winapi.ShellAPI, System.IOUtils, uDataBase,
|
||||
FMX.Controls.Presentation, FMX.Edit, uTWAuth, uRecords, uAPIDA, uShowText,
|
||||
System.json, uWSDA, fLog;
|
||||
System.json, uWSDA, fLog, IdBaseComponent, IdIOHandler, IdIOHandlerSocket,
|
||||
IdIOHandlerStack, IdSSL, IdSSLOpenSSL;
|
||||
|
||||
type
|
||||
TfrSettings = class(TFrame)
|
||||
@@ -83,18 +84,18 @@ uses uGeneral;
|
||||
procedure TfrSettings.btnDAGetCodeClick(Sender: TObject);
|
||||
var
|
||||
twa: TTTWAuth;
|
||||
Url: string;
|
||||
URL: string;
|
||||
begin
|
||||
if (edtDAClientSecret.text = '') or (edtDAClientID.text = '') or
|
||||
(edtDARedirectURL.text = '') then
|
||||
exit;
|
||||
|
||||
Url := 'https://www.donationalerts.com/oauth/authorize?client_id=' +
|
||||
URL := 'https://www.donationalerts.com/oauth/authorize?client_id=' +
|
||||
edtDAClientID.text +
|
||||
'&redirect_uri=http://localhost/da&response_type=code&scope=oauth-user-show+oauth-donation-subscribe';
|
||||
twa := TTTWAuth.Create;
|
||||
twa.OnToken := OnTokenDA;
|
||||
twa.StartServer(Url);
|
||||
twa.StartServer(URL);
|
||||
// ttw_Auth áóäåò îñâîáîæäåí àâòîìàòè÷åñêè ïîñëå ïîëó÷åíèÿ òîêåíà (ñì. uTWAuth)
|
||||
end;
|
||||
|
||||
@@ -107,7 +108,6 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
|
||||
procedure TfrSettings.btnDAStartClick(Sender: TObject);
|
||||
var
|
||||
UserInfo: TJSONObject;
|
||||
@@ -124,17 +124,14 @@ begin
|
||||
if FAPIClient.Token = '' then
|
||||
begin
|
||||
try
|
||||
FAPIClient.Token := FAPIClient.GetAccessToken(
|
||||
edtDAClientID.text,
|
||||
edtDAClientSecret.text,
|
||||
edtDARedirectURL.text,
|
||||
edtDACode.text
|
||||
);
|
||||
FAPIClient.Token := FAPIClient.GetAccessToken(edtDAClientID.text,
|
||||
edtDAClientSecret.text, edtDARedirectURL.text, edtDACode.text);
|
||||
except
|
||||
on E: Exception do
|
||||
begin
|
||||
TTW_Bot.toLog('fSettings', 'btnDAStartClick', 'Îøèáêà ïîëó÷åíèÿ òîêåíà: ' + E.Message,2);
|
||||
Exit;
|
||||
TTW_Bot.toLog('fSettings', 'btnDAStartClick',
|
||||
'Îøèáêà ïîëó÷åíèÿ òîêåíà: ' + E.Message, 2);
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
|
||||
@@ -143,31 +140,34 @@ begin
|
||||
try
|
||||
UserInfo := FAPIClient.GetUserInfo;
|
||||
Data := UserInfo.GetValue<TJSONObject>('data');
|
||||
FWSClient.Wsstoken := Data.GetValue<string>('socket_connection_token');
|
||||
FWSClient.Wsstoken := Data.GetValue<string>
|
||||
('socket_connection_token');
|
||||
FWSClient.WSID := Data.GetValue<string>('id');
|
||||
except
|
||||
on E: Exception do
|
||||
begin
|
||||
TTW_Bot.toLog( 'fSettings','btnDAStartClick', 'Îøèáêà ïîëó÷åíèÿ UserInfo: ' + E.Message,2);
|
||||
Exit;
|
||||
TTW_Bot.toLog('fSettings', 'btnDAStartClick',
|
||||
'Îøèáêà ïîëó÷åíèÿ UserInfo: ' + E.Message, 2);
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
try
|
||||
FWSClient.Connect('wss://centrifugo.donationalerts.com/connection/websocket');
|
||||
FWSClient.Send(Format(
|
||||
'{"params":{"token":"%s"},"id":1}',
|
||||
[FWSClient.Wsstoken]
|
||||
));
|
||||
FWSClient.Connect
|
||||
('wss://centrifugo.donationalerts.com/connection/websocket');
|
||||
FWSClient.Send(Format('{"params":{"token":"%s"},"id":1}',
|
||||
[FWSClient.Wsstoken]));
|
||||
except
|
||||
on E: Exception do
|
||||
TTW_Bot.toLog( 'fSettings','btnDAStartClick', 'Îøèáêà ïîäêëþ÷åíèÿ ê WebSocket: ' + E.Message,2);
|
||||
TTW_Bot.toLog('fSettings', 'btnDAStartClick',
|
||||
'Îøèáêà ïîäêëþ÷åíèÿ ê WebSocket: ' + E.Message, 2);
|
||||
end;
|
||||
|
||||
except
|
||||
on E: Exception do
|
||||
TTW_Bot.toLog('fSettings', 'btnDAStartClick', 'Íåèçâåñòíàÿ îøèáêà: ' + E.Message,2);
|
||||
TTW_Bot.toLog('fSettings', 'btnDAStartClick', 'Íåèçâåñòíàÿ îøèáêà: ' +
|
||||
E.Message, 2);
|
||||
end;
|
||||
finally
|
||||
UserInfo.Free;
|
||||
@@ -176,14 +176,15 @@ begin
|
||||
else
|
||||
begin
|
||||
try
|
||||
edtDACode.Text:='';
|
||||
edtDACode.text := '';
|
||||
if Assigned(FWSClient) then
|
||||
begin
|
||||
try
|
||||
FWSClient.Disconnect;
|
||||
except
|
||||
on E: Exception do
|
||||
TTW_Bot.toLog( 'fSettings', 'btnDAStartClick', 'Îøèáêà ïðè îòêëþ÷åíèè WS: ' + E.Message,2);
|
||||
TTW_Bot.toLog('fSettings', 'btnDAStartClick',
|
||||
'Îøèáêà ïðè îòêëþ÷åíèè WS: ' + E.Message, 2);
|
||||
end;
|
||||
FreeAndNil(FWSClient);
|
||||
end;
|
||||
@@ -204,7 +205,7 @@ begin
|
||||
if SaveDialog1.Execute then
|
||||
begin
|
||||
DestinationFile := SaveDialog1.FileName;
|
||||
TFile.Copy(myConst.DBPath, DestinationFile, True);
|
||||
TFile.Copy(myConst.DBPath, DestinationFile, true);
|
||||
end;
|
||||
end;
|
||||
|
||||
@@ -227,10 +228,10 @@ begin
|
||||
s := 'https://id.twitch.tv/oauth2/authorize?client_id=' + edtBotClientID.text
|
||||
+ '&redirect_uri=http://localhost&response_type=token&' + 'scope=' + sope;
|
||||
ttw_Auth.StartServer('');
|
||||
forbot := True;
|
||||
forbot := true;
|
||||
fShowText.Memo1.Lines.text := s;
|
||||
fShowText.Show;
|
||||
fShowText.Memo1.WordWrap := True;
|
||||
fShowText.Memo1.WordWrap := true;
|
||||
|
||||
end;
|
||||
|
||||
@@ -261,7 +262,7 @@ begin
|
||||
SourceFile := OpenDialog1.FileName;
|
||||
DestinationDir := myConst.DBPath;
|
||||
DestinationFile := myConst.DBPath;
|
||||
TFile.Copy(SourceFile, DestinationFile, True);
|
||||
TFile.Copy(SourceFile, DestinationFile, true);
|
||||
DB := TSettingsDatabase.Create(myConst.DBPath);
|
||||
end;
|
||||
end;
|
||||
@@ -315,11 +316,12 @@ end;
|
||||
|
||||
destructor TfrSettings.Destroy;
|
||||
begin
|
||||
if Assigned(FWSClient) then
|
||||
if Assigned(FWSClient) then
|
||||
begin
|
||||
try
|
||||
FWSClient.Disconnect; // åñëè åñòü ìåòîä îòêëþ÷åíèÿ
|
||||
except end;
|
||||
except
|
||||
end;
|
||||
FreeAndNil(FWSClient);
|
||||
end;
|
||||
FreeAndNil(FAPIClient);
|
||||
@@ -339,7 +341,7 @@ end;
|
||||
|
||||
procedure TfrSettings.init;
|
||||
begin
|
||||
if not Assigned(FAPIClient) then
|
||||
if not Assigned(FAPIClient) then
|
||||
FAPIClient := TAPIClient.Create;
|
||||
if not Assigned(FWSClient) then
|
||||
begin
|
||||
@@ -369,14 +371,14 @@ end;
|
||||
procedure TfrSettings.HandleWSDonate(aNick, aMessage, aSum: string);
|
||||
begin
|
||||
// fDonats.OnDADonate(aNick, aMessage, aSum);
|
||||
TTW_Bot.frOBS1.toEventWebServer(aNick,aSum,aMessage);
|
||||
TTW_Bot.frOBS1.toEventWebServer(aNick, aSum, aMessage);
|
||||
TTW_Bot.frEvents1.OnDonate(aNick, aMessage, aSum);
|
||||
|
||||
end;
|
||||
|
||||
procedure TfrSettings.HandleWSStatus(AStatusText: string; AStatusCode: integer);
|
||||
begin
|
||||
TTW_Bot.tolog('fSettings','HandleWSStatus',AStatusText,3);
|
||||
TTW_Bot.toLog('fSettings', 'HandleWSStatus', AStatusText, 3);
|
||||
TTW_Bot.Label8.text := AStatusText;
|
||||
case AStatusCode of
|
||||
0:
|
||||
|
||||
Reference in New Issue
Block a user