исправил оповещения, теперь работают четко
This commit is contained in:
+153
-240
@@ -7,7 +7,8 @@ uses
|
||||
System.Variants, System.Generics.Collections, ShellAPI, uSoundManager,
|
||||
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;
|
||||
FMX.ScrollBox, FMX.Grid, uRecords, uDataBase, FMX.Menus, uKeyEvent,
|
||||
fColorSettings, fFontSettings;
|
||||
|
||||
type
|
||||
TfrEvents = class(TFrame)
|
||||
@@ -42,16 +43,13 @@ type
|
||||
procedure MenuItem1Click(Sender: TObject);
|
||||
procedure cbActionsChange(Sender: TObject);
|
||||
private
|
||||
{ Private declarations }
|
||||
procedure toLog(aCode: integer; aMethod: string; aMess: string);
|
||||
procedure toLog(aCode: integer; aMethod, aMess: string);
|
||||
procedure ExecuteAction(const aAction: integer; const aParam, aUserInput, aUserName, aUserLogin: string);
|
||||
public
|
||||
{ Public declarations }
|
||||
ListEvents: TArray<TEventGlobal>;
|
||||
CustomRewards: Tlist<TCustomRevards>;
|
||||
CustomRewardEvents: Tlist<TCustomRewardEvent>;
|
||||
CustomRewardEvents: TList<TCustomRewardEvent>;
|
||||
|
||||
procedure UpdateGrid;
|
||||
procedure LoadCustomRevards();
|
||||
procedure ESOnGetCustomReward(CustomReward: TCustomRewardEvent);
|
||||
procedure OnDonate(aNick, aMessage, aSum: string);
|
||||
end;
|
||||
@@ -62,36 +60,40 @@ implementation
|
||||
|
||||
uses uGeneral;
|
||||
|
||||
{ --- UI --- }
|
||||
|
||||
procedure TfrEvents.btnAddClick(Sender: TObject);
|
||||
var
|
||||
NewRec: TEventGlobal;
|
||||
begin
|
||||
if (cbEventList.Text = '') or (cbActions.Text = '') then
|
||||
exit;
|
||||
if (cbEventList.ItemIndex < 0) or (cbActions.ItemIndex < 0) then
|
||||
Exit;
|
||||
|
||||
NewRec.Event := cbEventList.ItemIndex;
|
||||
NewRec.Action := cbActions.ItemIndex;
|
||||
NewRec.Param := edtParams.Text;
|
||||
|
||||
if edtIF.Visible then
|
||||
NewRec.Condition := edtIF.Text;
|
||||
if cbRevards.Visible then
|
||||
NewRec.Condition := edtIF.Text
|
||||
else if cbRevards.Visible then
|
||||
NewRec.Condition := cbRevards.Text;
|
||||
|
||||
SetLength(ListEvents, Length(ListEvents) + 1);
|
||||
ListEvents[High(ListEvents)] := NewRec;
|
||||
ListEvents := ListEvents + [NewRec];
|
||||
|
||||
DB.SaveRecordArray<TEventGlobal>('ListEvents', ListEvents);
|
||||
UpdateGrid;
|
||||
end;
|
||||
|
||||
procedure TfrEvents.btnDeleteClick(Sender: TObject);
|
||||
var
|
||||
i, RowIndex: integer;
|
||||
RowIndex: integer;
|
||||
begin
|
||||
RowIndex := sgEvents.Row;
|
||||
if (RowIndex < 0) or (RowIndex > High(ListEvents)) then
|
||||
exit;
|
||||
for i := RowIndex to High(ListEvents) - 1 do
|
||||
ListEvents[i] := ListEvents[i + 1];
|
||||
SetLength(ListEvents, Length(ListEvents) - 1);
|
||||
Exit;
|
||||
|
||||
Delete(ListEvents, RowIndex, 1);
|
||||
|
||||
DB.SaveRecordArray<TEventGlobal>('ListEvents', ListEvents);
|
||||
UpdateGrid;
|
||||
end;
|
||||
@@ -106,265 +108,172 @@ begin
|
||||
edtIF.Visible := cbEventList.ItemIndex = 0;
|
||||
cbRevards.Visible := cbEventList.ItemIndex = 1;
|
||||
Label2.Visible := cbEventList.ItemIndex <= 1;
|
||||
|
||||
end;
|
||||
|
||||
procedure TfrEvents.ESOnGetCustomReward(CustomReward: TCustomRewardEvent);
|
||||
procedure TfrEvents.MenuItem1Click(Sender: TObject);
|
||||
begin
|
||||
if OpenDialog1.Execute and (PopupMenu1.PopupComponent is TEdit) then
|
||||
TEdit(PopupMenu1.PopupComponent).Text := OpenDialog1.FileName;
|
||||
end;
|
||||
|
||||
{ --- Îáùàÿ ëîãèêà --- }
|
||||
|
||||
procedure TfrEvents.ExecuteAction(const aAction: integer; const aParam, aUserInput, aUserName, aUserLogin: string);
|
||||
var
|
||||
i, i2: integer;
|
||||
req, s: string;
|
||||
hr: TCustomRewardEvent;
|
||||
sm: TSongMachine;
|
||||
myAction: integer;
|
||||
f: TfrColorSettings;
|
||||
t: TfrFontSettings;
|
||||
i, j: Integer;
|
||||
notify: TOBSNotify;
|
||||
se: TStyleEvent;
|
||||
begin
|
||||
sm := TSongMachine.Create;
|
||||
try
|
||||
toLog(3, 'ESOnGetCustomReward', 'Íà÷àëî îáðàáîòêè íàãðàäû: ' +
|
||||
CustomReward.Event.revard.Title);
|
||||
s := '[' + CustomReward.Event.user_name +
|
||||
'] êóïèë çà áàëëû êàíàëà íàãðàäó "' +
|
||||
CustomReward.Event.revard.Title + '" ';
|
||||
if CustomReward.Event.user_input <> '' then
|
||||
begin
|
||||
toLog(0, 'ESOnGetCustomReward', 'Ïîëüçîâàòåëüñêèé ââîä: ' +
|
||||
CustomReward.Event.user_input);
|
||||
s := s + ' è ïåðåäàë ñòðîêó ' + CustomReward.Event.user_input
|
||||
end;
|
||||
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;
|
||||
|
||||
for i := 0 to high(ListEvents) do
|
||||
begin
|
||||
if ListEvents[i].Event <> 1 then
|
||||
continue;
|
||||
if ListEvents[i].Condition = CustomReward.Event.revard.Title then
|
||||
begin
|
||||
myAction := ListEvents[i].Action;
|
||||
|
||||
{
|
||||
0 Íàæàòü íêîïêó íà êëàâèàòóðå
|
||||
1 Ïðîèãðàòü çâóê
|
||||
2 Kandinsky
|
||||
3 Çàïóñòèòü Web Event
|
||||
4 Íàïèñàòü â ÷àò
|
||||
5 Çàïóñòèòü ïðîãðàììó
|
||||
|
||||
}
|
||||
case myAction of
|
||||
0:
|
||||
begin // íàæàòü êíîïêó
|
||||
toLog(0, 'ESOnGetCustomReward', 'Ñèìóëÿöèÿ íàæàòèÿ: ' +
|
||||
ListEvents[i].Param);
|
||||
kePoints.SimulateKeyPress(ListEvents[i].Param, 500);
|
||||
end;
|
||||
1:
|
||||
begin // âîñïðîèçâåäåíèå çâóêà
|
||||
toLog(0, 'ESOnGetCustomReward', 'Âîñïðîèçâåäåíèå çâóêà: ' +
|
||||
ListEvents[i].Param);
|
||||
sm.PlayPublic(ListEvents[i].Param, '100');
|
||||
end;
|
||||
2:
|
||||
begin // Kandinsky
|
||||
toLog(0, 'ESOnGetCustomReward', 'Ãåíåðàöèÿ Kandinsky äëÿ: ' +
|
||||
CustomReward.Event.user_input);
|
||||
Kandinsky.generate(CustomReward.Event.user_input,
|
||||
CustomReward.Event.user_login);
|
||||
end;
|
||||
4:
|
||||
begin // Íàïèñàòü â ÷àò
|
||||
|
||||
toLog(0, 'ESOnGetCustomReward', 'Íàïèñàòü â ÷àò: ' +
|
||||
CustomReward.Event.user_input);
|
||||
end;
|
||||
5:
|
||||
begin // çàïóñê ôàéëà
|
||||
toLog(0, 'ESOnGetCustomReward', 'Çàïóñê ôàéëà: ' + ListEvents
|
||||
[i].Param);
|
||||
ShellExecute(0, 'open', pwidechar(ListEvents[i].Param),
|
||||
nil, nil, 0);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
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;
|
||||
end;
|
||||
finally
|
||||
sm.Free;
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TfrEvents.LoadCustomRevards();
|
||||
procedure TfrEvents.ESOnGetCustomReward(CustomReward: TCustomRewardEvent);
|
||||
var
|
||||
cr: TCustomRevards;
|
||||
ev: TEventGlobal;
|
||||
begin
|
||||
CustomRewards.Clear;
|
||||
cbRevards.Items.Clear;
|
||||
TTW_Bot.toLog('fEvents', 'LoadCustomRevards', 'Çàïðîñ íàãðàä ñ ñåðâåðà', 3);
|
||||
ttw_API.getCustomReward(CustomRewards);
|
||||
for cr in CustomRewards do
|
||||
begin
|
||||
cbRevards.Items.Add(cr.Title);
|
||||
end;
|
||||
end;
|
||||
toLog(3, 'ESOnGetCustomReward', 'Íà÷àëî îáðàáîòêè íàãðàäû: ' + CustomReward.Event.revard.Title);
|
||||
|
||||
procedure TfrEvents.MenuItem1Click(Sender: TObject);
|
||||
begin
|
||||
if OpenDialog1.Execute then
|
||||
TEdit(PopupMenu1.PopupComponent).Text := OpenDialog1.FileName;
|
||||
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);
|
||||
end;
|
||||
|
||||
procedure TfrEvents.OnDonate(aNick, aMessage, aSum: string);
|
||||
var
|
||||
i, i2: integer;
|
||||
req, s: string;
|
||||
hr: TCustomRewardEvent;
|
||||
sm: TSongMachine;
|
||||
myAction: integer;
|
||||
|
||||
j: integer;
|
||||
aSumInt: integer;
|
||||
BestRow: integer;
|
||||
BestPriority: integer;
|
||||
BestValue: integer;
|
||||
i, aSumInt, BestRow, BestPriority, BestValue,
|
||||
CurrentPriority, CurrentValue, MinVal, MaxVal: integer;
|
||||
Condition: string;
|
||||
CurrentPriority: integer;
|
||||
CurrentValue: integer;
|
||||
MinVal, MaxVal: integer;
|
||||
Parts: tstringlist;
|
||||
se: TStyleEvent;
|
||||
notify: TEventGlobal;
|
||||
|
||||
Parts: TStringList;
|
||||
begin
|
||||
|
||||
aSumInt := StrToIntDef(aSum, 0);
|
||||
BestRow := -1;
|
||||
BestPriority := -1;
|
||||
BestValue := 0;
|
||||
|
||||
for i := 0 to high(ListEvents) do
|
||||
for i := 0 to High(ListEvents) do
|
||||
begin
|
||||
if ListEvents[i].Event = 0 then
|
||||
if ListEvents[i].Event <> 0 then
|
||||
Continue;
|
||||
|
||||
Condition := ListEvents[i].Condition;
|
||||
CurrentPriority := -1;
|
||||
CurrentValue := 0;
|
||||
|
||||
if TryStrToInt(Condition, CurrentValue) then
|
||||
begin
|
||||
Condition := ListEvents[i].Condition;
|
||||
CurrentPriority := -1;
|
||||
CurrentValue := 0;
|
||||
|
||||
// Ïðîâåðêà íà òî÷íîå çíà÷åíèå
|
||||
if Pos('-', Condition) = 0 then
|
||||
begin
|
||||
if Pos('>', Condition) = 0 then
|
||||
if aSumInt = CurrentValue then
|
||||
CurrentPriority := 4;
|
||||
end
|
||||
else if Pos('-', Condition) > 0 then
|
||||
begin
|
||||
Parts := TStringList.Create;
|
||||
try
|
||||
Parts.Delimiter := '-';
|
||||
Parts.StrictDelimiter := True;
|
||||
Parts.DelimitedText := Condition;
|
||||
if Parts.Count = 2 then
|
||||
begin
|
||||
if Pos('<', Condition) = 0 then
|
||||
MinVal := StrToIntDef(Trim(Parts[0]), 0);
|
||||
MaxVal := StrToIntDef(Trim(Parts[1]), 0);
|
||||
if (aSumInt >= MinVal) and (aSumInt <= MaxVal) then
|
||||
begin
|
||||
// Òî÷íîå çíà÷åíèå
|
||||
CurrentValue := StrToIntDef(Condition, -1);
|
||||
if aSumInt = CurrentValue then
|
||||
CurrentPriority := 4;
|
||||
CurrentPriority := 3;
|
||||
CurrentValue := MinVal;
|
||||
end;
|
||||
end;
|
||||
finally
|
||||
Parts.Free;
|
||||
end;
|
||||
|
||||
if CurrentPriority = -1 then
|
||||
begin
|
||||
if Pos('-', Condition) > 0 then
|
||||
begin
|
||||
// Äèàïàçîí
|
||||
Parts := tstringlist.Create;
|
||||
try
|
||||
Parts.Delimiter := '-';
|
||||
Parts.StrictDelimiter := True;
|
||||
Parts.DelimitedText := Condition;
|
||||
if Parts.Count = 2 then
|
||||
begin
|
||||
MinVal := StrToIntDef(Trim(Parts[0]), 0);
|
||||
MaxVal := StrToIntDef(Trim(Parts[1]), 0);
|
||||
if (aSumInt >= MinVal) and (aSumInt <= MaxVal) then
|
||||
begin
|
||||
CurrentPriority := 3;
|
||||
CurrentValue := MinVal; // Ïðèîðèòåò ïî MinVal
|
||||
end;
|
||||
end;
|
||||
finally
|
||||
Parts.Free;
|
||||
end;
|
||||
end
|
||||
else if Pos('>', Condition) > 0 then
|
||||
begin
|
||||
// Óñëîâèå ">X"
|
||||
CurrentValue :=
|
||||
StrToIntDef(Trim(StringReplace(Condition, '>', '',
|
||||
[rfReplaceAll])), 0);
|
||||
if aSumInt >= CurrentValue then
|
||||
CurrentPriority := 2;
|
||||
end
|
||||
else if Pos('<', Condition) > 0 then
|
||||
begin
|
||||
// Óñëîâèå "<X"
|
||||
CurrentValue :=
|
||||
StrToIntDef(Trim(StringReplace(Condition, '<', '',
|
||||
[rfReplaceAll])), 0);
|
||||
if aSumInt <= CurrentValue then
|
||||
CurrentPriority := 1;
|
||||
end;
|
||||
end;
|
||||
|
||||
if CurrentPriority <> -1 then
|
||||
begin
|
||||
// Îïðåäåëåíèå íàèëó÷øåãî óñëîâèÿ
|
||||
if (CurrentPriority > BestPriority) or (CurrentPriority = BestPriority)
|
||||
and ((CurrentPriority = 3) and (CurrentValue > BestValue) or
|
||||
(CurrentPriority = 2) and (CurrentValue > BestValue) or
|
||||
(CurrentPriority = 1) and (CurrentValue < BestValue)) then
|
||||
begin
|
||||
BestPriority := CurrentPriority;
|
||||
BestValue := CurrentValue;
|
||||
BestRow := i;
|
||||
notify := ListEvents[i];
|
||||
end;
|
||||
end;
|
||||
if BestRow = -1 then
|
||||
Break;
|
||||
|
||||
end;
|
||||
end;
|
||||
if BestRow = -1 then
|
||||
exit;
|
||||
sm := TSongMachine.Create;
|
||||
try
|
||||
myAction := ListEvents[i].Action;
|
||||
case myAction of
|
||||
0:
|
||||
begin // íàæàòü êíîïêó
|
||||
toLog(0, 'OnDonate', 'Ñèìóëÿöèÿ íàæàòèÿ: ' + ListEvents[i].Param);
|
||||
kePoints.SimulateKeyPress(ListEvents[i].Param, 500);
|
||||
end;
|
||||
1:
|
||||
begin // âîñïðîèçâåäåíèå çâóêà
|
||||
toLog(0, 'OnDonate', 'Âîñïðîèçâåäåíèå çâóêà: ' + ListEvents[i].Param);
|
||||
sm.PlayPublic(ListEvents[i].Param, '100');
|
||||
end;
|
||||
2:
|
||||
begin // Kandinsky
|
||||
toLog(0, 'OnDonate', 'Ãåíåðàöèÿ Kandinsky äëÿ: ' + aNick);
|
||||
Kandinsky.generate(aMessage, aNick);
|
||||
end;
|
||||
4:
|
||||
begin // Íàïèñàòü â ÷àò
|
||||
|
||||
toLog(0, 'OnDonate', 'Íàïèñàòü â ÷àò: ' + aNick);
|
||||
end;
|
||||
5:
|
||||
begin // çàïóñê ôàéëà
|
||||
toLog(0, 'OnDonate', 'Çàïóñê ôàéëà: ' + ListEvents[i].Param);
|
||||
ShellExecute(0, 'open', pwidechar(ListEvents[i].Param), nil, nil, 0);
|
||||
end;
|
||||
end
|
||||
else if (Condition.StartsWith('>')) then
|
||||
begin
|
||||
CurrentValue := StrToIntDef(Copy(Condition, 2), 0);
|
||||
if aSumInt >= CurrentValue then
|
||||
CurrentPriority := 2;
|
||||
end
|
||||
else if (Condition.StartsWith('<')) then
|
||||
begin
|
||||
CurrentValue := StrToIntDef(Copy(Condition, 2), 0);
|
||||
if aSumInt <= CurrentValue then
|
||||
CurrentPriority := 1;
|
||||
end;
|
||||
|
||||
finally
|
||||
sm.Free;
|
||||
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;
|
||||
BestRow := i;
|
||||
end;
|
||||
end;
|
||||
|
||||
if BestRow <> -1 then
|
||||
ExecuteAction(ListEvents[BestRow].Action, ListEvents[BestRow].Param, aMessage, aNick, aNick);
|
||||
end;
|
||||
|
||||
procedure TfrEvents.toLog(aCode: integer; aMethod, aMess: string);
|
||||
begin
|
||||
TTW_Bot.toLog('fEvents', aMethod, aMess, aCode);
|
||||
end;
|
||||
|
||||
|
||||
procedure TfrEvents.UpdateGrid;
|
||||
var
|
||||
@@ -372,11 +281,9 @@ var
|
||||
begin
|
||||
sgEvents.BeginUpdate;
|
||||
try
|
||||
sgEvents.RowCount := 0; // Ñáðàñûâàåì ñòðîêè (îñòàâëÿåì òîëüêî çàãîëîâêè)
|
||||
|
||||
sgEvents.RowCount := Length(ListEvents);
|
||||
for i := 0 to High(ListEvents) do
|
||||
begin
|
||||
sgEvents.RowCount := i + 1;
|
||||
sgEvents.Cells[0, i] := cbEventList.Items[ListEvents[i].Event];
|
||||
sgEvents.Cells[1, i] := ListEvents[i].Condition;
|
||||
sgEvents.Cells[2, i] := cbActions.Items[ListEvents[i].Action];
|
||||
@@ -387,4 +294,10 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
procedure TfrEvents.toLog(aCode: integer; aMethod, aMess: string);
|
||||
begin
|
||||
TTW_Bot.toLog('fEvents', aMethod, aMess, aCode);
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user