diff --git a/frames/fEvents.pas b/frames/fEvents.pas index ce46e1e..1bf0380 100644 --- a/frames/fEvents.pas +++ b/frames/fEvents.pas @@ -8,7 +8,7 @@ uses FMX.Types, FMX.Graphics, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.StdCtrls, FMX.Edit, FMX.ListBox, FMX.Controls.Presentation, System.Rtti, FMX.Grid.Style, FMX.ScrollBox, FMX.Grid, uRecords, uDataBase, FMX.Menus, uKeyEvent, - fColorSettings, fFontSettings; + fColorSettings, fFontSettings, fobs; type TfrEvents = class(TFrame) @@ -44,14 +44,17 @@ type procedure cbActionsChange(Sender: TObject); private procedure toLog(aCode: integer; aMethod, aMess: string); - procedure ExecuteAction(const aAction: integer; const aParam, aUserInput, aUserName, aUserLogin: string); + public ListEvents: TArray; CustomRewardEvents: TList; + procedure ExecuteAction(const aAction: integer; + const aParam, aUserInput, aUserName, aUserLogin: string); procedure UpdateGrid; procedure ESOnGetCustomReward(CustomReward: TCustomRewardEvent); procedure OnDonate(aNick, aMessage, aSum: string); + procedure OnTTVEvent(aNick: string); end; implementation @@ -118,68 +121,62 @@ end; { --- Общая логика --- } -procedure TfrEvents.ExecuteAction(const aAction: integer; const aParam, aUserInput, aUserName, aUserLogin: string); +procedure TfrEvents.ExecuteAction(const aAction: integer; + const aParam, aUserInput, aUserName, aUserLogin: string); var sm: TSongMachine; f: TfrColorSettings; t: TfrFontSettings; - i, j: Integer; + i, j: integer; notify: TOBSNotify; se: TStyleEvent; + ws: TEventWebServers; begin sm := TSongMachine.Create; try case aAction of - 0: begin // Нажать кнопку - toLog(0, 'ExecuteAction', 'Симуляция нажатия: ' + aParam); - kePoints.SimulateKeyPress(aParam, 500); - end; - 1: begin // Воспроизведение звука - toLog(0, 'ExecuteAction', 'Воспроизведение звука: ' + aParam); - sm.PlayPublic(aParam, '100'); - end; - 2: begin // Kandinsky - toLog(0, 'ExecuteAction', 'Генерация Kandinsky для: ' + aUserInput); - Kandinsky.generate(aUserInput, aUserLogin); - end; - 3: begin // OBS Notify - f := TfrColorSettings.Create(Self); - t := TfrFontSettings.Create(Self); - try - for i := 0 to High(TTW_Bot.frOBS1.listNotify) do - if TTW_Bot.frOBS1.listNotify[i].TypeEvent = 5 then - begin - notify := TTW_Bot.frOBS1.listNotify[i]; - se.Title := StringReplace(notify.HeaderText, '[NICK]', aUserName, [rfReplaceAll]); - se.Context := notify.MessText; - se.Url := notify.Picture; - se.SoundURL := notify.Sound; - se.Timestamp := Now; - se.TimeMsg := notify.TimeMess; - se.BorderColor := notify.ColorBorder; - se.BorderSize := notify.SolidBorder; - se.BlockColor := notify.ColorBlock; - se.FontTitle.Font := notify.HeaderStyleFont; - se.FontTitle.Size := notify.HeaderSizeFont; - se.FontTitle.Color := notify.HeaderColorFont; - se.FontContext.Font := notify.MessStyleFont; - se.FontContext.Size := notify.MessSizeFont; - se.FontContext.Color := notify.MessColorFont; - se.RequireInteraction := True; + 0: + begin // Нажать кнопку + toLog(0, 'ExecuteAction', 'Симуляция нажатия: ' + aParam); + kePoints.SimulateKeyPress(aParam, 500); + end; + 1: + begin // Воспроизведение звука + toLog(0, 'ExecuteAction', 'Воспроизведение звука: ' + aParam); + sm.PlayPublic(aParam, '100'); + end; + 2: + begin // Kandinsky + toLog(0, 'ExecuteAction', 'Генерация Kandinsky для: ' + aUserInput); + Kandinsky.generate(aUserInput, aUserLogin); + end; + 3: + begin // OBS Notify - for j := 0 to TTW_Bot.frOBS1.EventWebServers.Count - 1 do - TTW_Bot.frOBS1.EventWebServers[j].WebServerChat.AddMessage(se); - end; - finally - f.Free; - t.Free; - end; - end; - 4: toLog(0, 'ExecuteAction', 'Написать в чат: ' + aUserInput); - 5: begin // Запуск файла - toLog(0, 'ExecuteAction', 'Запуск файла: ' + aParam); - ShellExecute(0, 'open', PWideChar(aParam), nil, nil, 0); - end; + for i := 0 to TTW_Bot.frOBS1.EventWebServers.Count - 1 do + begin + if TTW_Bot.frOBS1.EventWebServers[i].typeEvent <> 5 then + Continue; + ws := TTW_Bot.frOBS1.EventWebServers[i]; + var + un: string; + un := aUserName; + if un = '' then + un := aUserLogin; + ws.se.Title := StringReplace(ws.se.Title, '[NICK]', un, + [rfReplaceAll]); + ws.se.Timestamp := now; + ws.WebServerChat.AddMessage(ws.se); + end; + + end; + 4: + toLog(0, 'ExecuteAction', 'Написать в чат: ' + aUserInput); + 5: + begin // Запуск файла + toLog(0, 'ExecuteAction', 'Запуск файла: ' + aParam); + ShellExecute(0, 'open', PWideChar(aParam), nil, nil, 0); + end; end; finally sm.Free; @@ -190,17 +187,19 @@ procedure TfrEvents.ESOnGetCustomReward(CustomReward: TCustomRewardEvent); var ev: TEventGlobal; begin - toLog(3, 'ESOnGetCustomReward', 'Начало обработки награды: ' + CustomReward.Event.revard.Title); + toLog(3, 'ESOnGetCustomReward', 'Начало обработки награды: ' + + CustomReward.Event.revard.Title); for ev in ListEvents do if (ev.Event = 1) and (ev.Condition = CustomReward.Event.revard.Title) then - ExecuteAction(ev.Action, ev.Param, CustomReward.Event.user_input, CustomReward.Event.user_name, CustomReward.Event.user_login); + ExecuteAction(ev.Action, ev.Param, CustomReward.Event.user_input, + CustomReward.Event.user_name, CustomReward.Event.user_login); end; procedure TfrEvents.OnDonate(aNick, aMessage, aSum: string); var - i, aSumInt, BestRow, BestPriority, BestValue, - CurrentPriority, CurrentValue, MinVal, MaxVal: integer; + i, aSumInt, BestRow, BestPriority, BestValue, CurrentPriority, CurrentValue, + MinVal, MaxVal: integer; Condition: string; Parts: TStringList; begin @@ -257,11 +256,10 @@ begin CurrentPriority := 1; end; - if (CurrentPriority <> -1) and - ((CurrentPriority > BestPriority) or - ((CurrentPriority = BestPriority) and - (((CurrentPriority in [2,3]) and (CurrentValue > BestValue)) or - ((CurrentPriority = 1) and (CurrentValue < BestValue))))) then + if (CurrentPriority <> -1) and ((CurrentPriority > BestPriority) or + ((CurrentPriority = BestPriority) and (((CurrentPriority in [2, 3]) and + (CurrentValue > BestValue)) or ((CurrentPriority = 1) and + (CurrentValue < BestValue))))) then begin BestPriority := CurrentPriority; BestValue := CurrentValue; @@ -270,10 +268,18 @@ begin end; if BestRow <> -1 then - ExecuteAction(ListEvents[BestRow].Action, ListEvents[BestRow].Param, aMessage, aNick, aNick); + ExecuteAction(ListEvents[BestRow].Action, ListEvents[BestRow].Param, + aMessage, aNick, aNick); end; - +procedure TfrEvents.OnTTVEvent(aNick: string); +var + ev: TEventGlobal; +begin + for ev in ListEvents do + if ev.Event in ([2, 3, 4, 5]) then + ExecuteAction(ev.Action, ev.Param, '', aNick, ''); +end; procedure TfrEvents.UpdateGrid; var @@ -300,4 +306,3 @@ begin end; end. - diff --git a/frames/fOBS.pas b/frames/fOBS.pas index e027db4..f858d2c 100644 --- a/frames/fOBS.pas +++ b/frames/fOBS.pas @@ -806,6 +806,7 @@ begin EventWebServers[i].WebServerChat.AddMessage(ws.se); end; end; + TTW_Bot.frEvents1.OnTTVEvent(aEvent.event.user_name); end; procedure TfrOBS.toEventWebServer(aEvent: TSubEvent); @@ -823,6 +824,7 @@ begin EventWebServers[i] := ws; EventWebServers[i].WebServerChat.AddMessage(EventWebServers[i].se); end; + TTW_Bot.frEvents1.OnTTVEvent(aEvent.event.user_name); end; procedure TfrOBS.toEventWebServer(aEvent: TRaidEvent); @@ -842,6 +844,7 @@ begin EventWebServers[i] := ws; EventWebServers[i].WebServerChat.AddMessage(EventWebServers[i].se); end; + TTW_Bot.frEvents1.OnTTVEvent(aEvent.event.from_broadcaster_user_name); end; procedure TfrOBS.toEventWebServer(aEvent: TGiftEvent); @@ -859,6 +862,7 @@ begin EventWebServers[i] := ws; EventWebServers[i].WebServerChat.AddMessage(EventWebServers[i].se); end; + TTW_Bot.frEvents1.OnTTVEvent(aEvent.event.user_name); end; procedure TfrOBS.toEventWebServer(aNick, aSum, aText: string); diff --git a/utils/uRecords.pas b/utils/uRecords.pas index 80d79d5..eafddc3 100644 --- a/utils/uRecords.pas +++ b/utils/uRecords.pas @@ -2,6 +2,8 @@ unit uRecords; interface + + type TEventGlobal = record Event: integer;