добавил часть модулей, нужно переделать БД на records
This commit is contained in:
+254
-2
@@ -3,9 +3,12 @@ unit fSettings;
|
||||
interface
|
||||
|
||||
uses
|
||||
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
|
||||
System.SysUtils, System.Types, System.UITypes, System.Classes,
|
||||
System.Variants, uQ,
|
||||
FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls,
|
||||
FMX.Controls.Presentation, FMX.Edit;
|
||||
ShellAPI, system.IOUtils, uDataBase,
|
||||
FMX.Controls.Presentation, FMX.Edit, uTWAuth, uRecords, uAPIDA, uShowText,
|
||||
json, uWSDA;
|
||||
|
||||
type
|
||||
TfrSettings = class(TFrame)
|
||||
@@ -42,14 +45,263 @@ type
|
||||
btnImportSettings: TButton;
|
||||
btnExportSettings: TButton;
|
||||
btnMaster: TButton;
|
||||
SaveDialog1: TSaveDialog;
|
||||
OpenDialog1: TOpenDialog;
|
||||
procedure btnGetTokenClick(Sender: TObject);
|
||||
procedure btnGetTokenStreamerClick(Sender: TObject);
|
||||
procedure btnOpenStreamClick(Sender: TObject);
|
||||
procedure btnDAGetCodeClick(Sender: TObject);
|
||||
procedure btnDAStartClick(Sender: TObject);
|
||||
procedure btnOpenRomaningClick(Sender: TObject);
|
||||
procedure btnImportSettingsClick(Sender: TObject);
|
||||
procedure btnExportSettingsClick(Sender: TObject);
|
||||
procedure btnMasterClick(Sender: TObject);
|
||||
private
|
||||
{ Private declarations }
|
||||
FAPIClient: TAPIClient;
|
||||
forbot: boolean;
|
||||
|
||||
procedure OnTTWToken(txt: string);
|
||||
procedure OnTokenDA(txt: string);
|
||||
procedure HandleWSStatus(AStatusText: string; AStatusCode: integer);
|
||||
procedure HandleWSDonate(aNick, aMessage, aSum: string);
|
||||
public
|
||||
{ Public declarations }
|
||||
FWSClient: TWSClient;
|
||||
procedure init();
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
{$R *.fmx}
|
||||
|
||||
uses uGeneral;
|
||||
|
||||
procedure TfrSettings.btnDAGetCodeClick(Sender: TObject);
|
||||
var
|
||||
twa: TTTWAuth;
|
||||
Url: string;
|
||||
begin
|
||||
if (edtDAClientSecret.text = '') or (edtDAClientID.text = '') or
|
||||
(edtDARedirectURL.text = '') then
|
||||
exit;
|
||||
|
||||
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);
|
||||
end;
|
||||
|
||||
procedure TfrSettings.OnTokenDA(txt: string);
|
||||
begin
|
||||
edtDACode.text := txt;
|
||||
if cbDAAutoLogin.IsChecked then
|
||||
begin
|
||||
btnDAStartClick(self);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TfrSettings.btnDAStartClick(Sender: TObject);
|
||||
var
|
||||
UserInfo: TJSONObject;
|
||||
Data: TJSONObject;
|
||||
begin
|
||||
if btnDAStart.text = 'Ïîäêëþ÷èòüñÿ' then
|
||||
begin
|
||||
try // Ïîëó÷åíèå òîêåíà
|
||||
if FAPIClient.Token = '' then
|
||||
begin
|
||||
FAPIClient.Token := FAPIClient.GetAccessToken(edtDAClientID.text,
|
||||
edtDAClientSecret.text, edtDARedirectURL.text, edtDACode.text);
|
||||
FWSClient.APIClient := FAPIClient;
|
||||
UserInfo := FAPIClient.GetUserInfo;
|
||||
Data := UserInfo.GetValue<TJSONObject>('data');
|
||||
FWSClient.Wsstoken := Data.GetValue<string>('socket_connection_token');
|
||||
FWSClient.WSID := Data.GetValue<string>('id');
|
||||
end;
|
||||
// Ïîëó÷åíèå èíôîðìàöèè î ïîëüçîâàòåëå
|
||||
|
||||
|
||||
FWSClient.Connect
|
||||
('wss://centrifugo.donationalerts.com/connection/websocket');
|
||||
FWSClient.Send(Format('{"params":{"token":"%s"},"id":1}',
|
||||
[FWSClient.Wsstoken]));
|
||||
finally
|
||||
UserInfo.Free;
|
||||
end;
|
||||
end
|
||||
else
|
||||
begin
|
||||
FWSClient.Disconnect;
|
||||
btnDAStart.ImageIndex := 18;
|
||||
btnDAStart.text := 'Ïîäêëþ÷èòüñÿ';
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TfrSettings.btnExportSettingsClick(Sender: TObject);
|
||||
var
|
||||
DestinationFile: string;
|
||||
begin
|
||||
SaveDialog1.FileName := TPath.GetFileName(myConst.DBPath);
|
||||
if SaveDialog1.Execute then
|
||||
begin
|
||||
DestinationFile := SaveDialog1.FileName;
|
||||
TFile.Copy(myConst.DBPath, DestinationFile, True);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TfrSettings.btnGetTokenClick(Sender: TObject);
|
||||
var
|
||||
s: string;
|
||||
sope: string;
|
||||
ttw_Auth: TTTWAuth;
|
||||
begin
|
||||
ttw_Auth := TTTWAuth.Create;
|
||||
ttw_Auth.OnToken := OnTTWToken;
|
||||
sope := 'moderator:manage:shoutouts' + '+moderator:manage:announcements' +
|
||||
'+moderator:manage:banned_users' + '+moderator:manage:warnings' +
|
||||
'+moderator:read:followers' + '+channel:manage:raids' +
|
||||
'+channel:manage:moderators' + '+channel:read:redemptions' + '+chat:read' +
|
||||
'+chat:edit+user:read:emotes';
|
||||
sope := StringReplace(sope, ':', '%3A', [rfReplaceAll]);
|
||||
|
||||
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;
|
||||
fShowText.Memo1.Lines.text := s;
|
||||
fShowText.Show;
|
||||
fShowText.Memo1.WordWrap := True;
|
||||
|
||||
end;
|
||||
|
||||
procedure TfrSettings.btnGetTokenStreamerClick(Sender: TObject);
|
||||
var
|
||||
sope: string;
|
||||
ttw_Auth: TTTWAuth;
|
||||
begin
|
||||
ttw_Auth := TTTWAuth.Create;
|
||||
ttw_Auth.OnToken := OnTTWToken;
|
||||
sope := 'channel:read:redemptions' + '+channel:manage:vips' +
|
||||
'+moderator:read:followers' + '+channel:read:subscriptions' +
|
||||
'+channel:manage:moderators' + '+channel:manage:redemptions';
|
||||
sope := StringReplace(sope, ':', '%3A', [rfReplaceAll]);
|
||||
ttw_Auth.StartServer('https://id.twitch.tv/oauth2/authorize?client_id=' +
|
||||
edtBotClientID.text + '&redirect_uri=http://localhost&response_type=token&'
|
||||
+ 'scope=' + sope);
|
||||
forbot := false;
|
||||
end;
|
||||
|
||||
procedure TfrSettings.btnImportSettingsClick(Sender: TObject);
|
||||
var
|
||||
SourceFile, DestinationDir, DestinationFile: string;
|
||||
begin
|
||||
if OpenDialog1.Execute then
|
||||
begin
|
||||
DB.Free;
|
||||
SourceFile := OpenDialog1.FileName;
|
||||
DestinationDir := myConst.DBPath;
|
||||
DestinationFile := myConst.DBPath;
|
||||
TFile.Copy(SourceFile, DestinationFile, True);
|
||||
DB := TSettingsDatabase.Create(myConst.DBPath);
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TfrSettings.btnMasterClick(Sender: TObject);
|
||||
var
|
||||
qf: tfrmq;
|
||||
|
||||
begin
|
||||
qf := tfrmq.Create(nil);
|
||||
try
|
||||
qf.SetLabelText('Ââåäèòå íèê àêêàóíòà îò êîòîðîãî áóäåò ïèñàòü áîò:');
|
||||
if qf.ShowModal = mrOk then
|
||||
edtBotName.text := qf.GetEditText;
|
||||
qf.SetLabelText('Ââåäèòå íèê ñòðèìåðà ãäå áóäåò ðàáîòàòü áîò:');
|
||||
if qf.ShowModal = mrOk then
|
||||
edtChannel.text := qf.GetEditText;
|
||||
if btnGetClientID.Visible then
|
||||
begin
|
||||
edtBotClientID.text := appconst.TTV_ClientID;
|
||||
showmessage('Ïîÿâèòñÿ îêíî, òàì áóäåò ññûëêà. ' + #13 +
|
||||
'Ñêîïèðóé åå è îòêðîé â áðàóçåðå ãäå àâòîðèçîâàí áîò. ' + #13 +
|
||||
'Åñëè ïîíÿë - æìè ÎÊ');
|
||||
btnGetTokenClick(self);
|
||||
showmessage
|
||||
('Êîãäà ññûëêà ïðîïàäåò æìè "Ïîëó÷èòü Token" îêîëî ïîëÿ "API Token Ñòðèìåðà". '
|
||||
+ #13 + 'Åñëè ïîíÿë - æìè ÎÊ');
|
||||
end
|
||||
else
|
||||
begin
|
||||
showmessage('Íåò ôàéëà êëþ÷åé! ' + #13 +
|
||||
'Ââåäèòå ClientID âðó÷íóþ è ïðîäîëæèòå íàñòðîéêó áåç ìàñòåðà!');
|
||||
end;
|
||||
|
||||
finally
|
||||
qf.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TfrSettings.btnOpenRomaningClick(Sender: TObject);
|
||||
begin
|
||||
ShellExecute(0, 'open', pwidechar(ExtractFilePath(myConst.DBPath)),
|
||||
nil, nil, 1);
|
||||
end;
|
||||
|
||||
procedure TfrSettings.btnOpenStreamClick(Sender: TObject);
|
||||
begin
|
||||
ShellExecute(0, 'open', pwidechar('https://www.twitch.tv/' + edtChannel.text),
|
||||
nil, nil, 1);
|
||||
end;
|
||||
|
||||
procedure TfrSettings.init;
|
||||
begin
|
||||
FAPIClient := TAPIClient.Create;
|
||||
FWSClient := TWSClient.Create;
|
||||
FWSClient.OnStatus := HandleWSStatus;
|
||||
FWSClient.OnDonate := HandleWSDonate;
|
||||
end;
|
||||
|
||||
procedure TfrSettings.OnTTWToken(txt: string);
|
||||
begin
|
||||
fShowText.Close;
|
||||
if forbot then
|
||||
begin
|
||||
edtBotToken.text := txt;
|
||||
DB.WriteSetting('edtBotToken', txt);
|
||||
end
|
||||
else
|
||||
begin
|
||||
edtBotTokenStreamer.text := txt;
|
||||
DB.WriteSetting('edtBotTokenStreamer', txt);
|
||||
end;
|
||||
|
||||
end;
|
||||
|
||||
procedure TfrSettings.HandleWSDonate(aNick, aMessage, aSum: string);
|
||||
begin
|
||||
// fDonats.OnDADonate(aNick, aMessage, aSum);
|
||||
end;
|
||||
|
||||
procedure TfrSettings.HandleWSStatus(AStatusText: string; AStatusCode: integer);
|
||||
begin
|
||||
// fLog.tolog(3,'uLogin','HandleWSStatus',AStatusText);
|
||||
TTW_Bot.Label8.text := AStatusText;
|
||||
case AStatusCode of
|
||||
0:
|
||||
begin
|
||||
btnDAStart.ImageIndex := 1;
|
||||
btnDAStart.text := 'Îòêëþ÷èòüñÿ';
|
||||
end;
|
||||
else
|
||||
begin
|
||||
btnDAStart.ImageIndex := 18;
|
||||
btnDAStart.text := 'Ïîäêëþ÷èòüñÿ';
|
||||
end;
|
||||
end;
|
||||
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
Reference in New Issue
Block a user