fix(tasks): 放宽持续任务识别并改为秒级间隔
This commit is contained in:
1 parent
ca0d3cdc73
commit
e022c6e887
2 files changed
+34
-12
No files matched your search
@@ -1,4 +1,4 @@
|
||||
@namespace TelegramPanel.Web.Components.Dialogs
|
||||
@namespace TelegramPanel.Web.Components.Dialogs
|
||||
@inject AccountCategoryManagementService CategoryManagement
|
||||
@using System.Text.Json
|
||||
@using TelegramPanel.Data.Entities
|
||||
@@ -43,11 +43,11 @@
|
||||
<MudGrid>
|
||||
<MudItem xs="12" md="4">
|
||||
<MudNumericField T="int" @bind-Value="delayMinMs" @bind-Value:after="OnInputsChanged"
|
||||
Label="最小间隔(ms)" Variant="Variant.Outlined" Min="0" Max="600000" />
|
||||
Label="最小间隔(秒)" Variant="Variant.Outlined" Min="0" Max="600" />
|
||||
</MudItem>
|
||||
<MudItem xs="12" md="4">
|
||||
<MudNumericField T="int" @bind-Value="delayMaxMs" @bind-Value:after="OnInputsChanged"
|
||||
Label="最大间隔(ms)" Variant="Variant.Outlined" Min="0" Max="600000" />
|
||||
Label="最大间隔(秒)" Variant="Variant.Outlined" Min="0" Max="600" />
|
||||
</MudItem>
|
||||
<MudItem xs="12" md="4">
|
||||
<MudNumericField T="int" @bind-Value="maxMessages" @bind-Value:after="OnInputsChanged"
|
||||
@@ -94,8 +94,8 @@
|
||||
private int selectedCategoryId;
|
||||
private string targetsText = "";
|
||||
private string dictionaryText = "";
|
||||
private int delayMinMs = 15000;
|
||||
private int delayMaxMs = 45000;
|
||||
private int delayMinMs = 15;
|
||||
private int delayMaxMs = 45;
|
||||
private int maxMessages = 0;
|
||||
|
||||
private string accountMode = UserChatActiveTaskModes.Random;
|
||||
@@ -145,8 +145,8 @@
|
||||
|
||||
targetsText = string.Join(Environment.NewLine, cfg.Targets ?? new List<string>());
|
||||
dictionaryText = string.Join(Environment.NewLine, cfg.Dictionary ?? new List<string>());
|
||||
delayMinMs = cfg.DelayMinMs;
|
||||
delayMaxMs = cfg.DelayMaxMs;
|
||||
delayMinMs = ConvertMillisecondsToSeconds(cfg.DelayMinMs);
|
||||
delayMaxMs = ConvertMillisecondsToSeconds(cfg.DelayMaxMs);
|
||||
maxMessages = cfg.MaxMessages;
|
||||
accountMode = NormalizeMode(cfg.AccountMode);
|
||||
targetMode = NormalizeMode(cfg.TargetMode);
|
||||
@@ -229,8 +229,8 @@
|
||||
CategoryName = category.Name,
|
||||
Targets = targets,
|
||||
Dictionary = dictionary,
|
||||
DelayMinMs = delayMinMs,
|
||||
DelayMaxMs = delayMaxMs,
|
||||
DelayMinMs = delayMinMs * 1000,
|
||||
DelayMaxMs = delayMaxMs * 1000,
|
||||
MaxMessages = maxMessages,
|
||||
AccountMode = accountMode,
|
||||
TargetMode = targetMode,
|
||||
@@ -242,6 +242,14 @@
|
||||
await DraftChanged.InvokeAsync(new ModuleTaskDraft(total, json, true, null));
|
||||
}
|
||||
|
||||
private static int ConvertMillisecondsToSeconds(int value)
|
||||
{
|
||||
if (value <= 0)
|
||||
return 0;
|
||||
|
||||
return Math.Max(1, (int)Math.Ceiling(value / 1000d));
|
||||
}
|
||||
|
||||
private static bool IsValidMode(string? value)
|
||||
{
|
||||
return string.Equals(value, UserChatActiveTaskModes.Random, StringComparison.OrdinalIgnoreCase)
|
||||
@@ -280,3 +288,5 @@
|
||||
.ToList();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -378,7 +378,7 @@
|
||||
private static string GetDisplayStatus(BatchTask task)
|
||||
{
|
||||
if (task.Status == "pending"
|
||||
&& task.TaskType == BatchTaskTypes.UserChatActive
|
||||
&& IsUserChatActiveTask(task.TaskType)
|
||||
&& task.Total == 0)
|
||||
{
|
||||
return "running";
|
||||
@@ -431,7 +431,7 @@
|
||||
taskType is BatchTaskTypes.BotChannelSetAdminsByAccount or BatchTaskTypes.BotSetAdmins;
|
||||
|
||||
private static bool IsUserChatActiveTask(string taskType) =>
|
||||
taskType is BatchTaskTypes.UserChatActive;
|
||||
string.Equals((taskType ?? string.Empty).Trim(), BatchTaskTypes.UserChatActive, StringComparison.OrdinalIgnoreCase);
|
||||
|
||||
private static bool CanPauseUserChatActiveTask(BatchTask task)
|
||||
{
|
||||
@@ -578,7 +578,7 @@
|
||||
details += $"账号模式: {NormalizeTaskModeDisplay(accountMode)}\n";
|
||||
details += $"目标模式: {NormalizeTaskModeDisplay(targetMode)}\n";
|
||||
details += $"词典模式: {NormalizeTaskModeDisplay(messageMode)}\n";
|
||||
details += $"间隔: {delayMin} ~ {delayMax} ms\n";
|
||||
details += $"间隔: {FormatDelaySeconds(delayMin)} ~ {FormatDelaySeconds(delayMax)} 秒\n";
|
||||
details += $"最多发送: {(maxMessages <= 0 ? "持续运行(直到取消)" : maxMessages.ToString())}\n";
|
||||
|
||||
if (lines.Count > 0)
|
||||
@@ -595,6 +595,15 @@
|
||||
}
|
||||
}
|
||||
|
||||
private static string FormatDelaySeconds(int milliseconds)
|
||||
{
|
||||
if (milliseconds <= 0)
|
||||
return "0";
|
||||
|
||||
var seconds = milliseconds / 1000d;
|
||||
return seconds.ToString("0.###");
|
||||
}
|
||||
|
||||
private static string NormalizeTaskModeDisplay(string? mode)
|
||||
{
|
||||
var text = (mode ?? "").Trim();
|
||||
@@ -905,3 +914,6 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in new issue
Block a user