mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2026-01-05 08:30:18 +00:00
Add MessagingLimiterDelay
This commit is contained in:
@@ -93,6 +93,7 @@ namespace ArchiSteamFarm {
|
||||
private readonly SemaphoreSlim GamesRedeemerInBackgroundSemaphore = new SemaphoreSlim(1, 1);
|
||||
private readonly Timer HeartBeatTimer;
|
||||
private readonly SemaphoreSlim InitializationSemaphore = new SemaphoreSlim(1, 1);
|
||||
private readonly SemaphoreSlim MessagingSemaphore = new SemaphoreSlim(1, 1);
|
||||
private readonly SemaphoreSlim PICSSemaphore = new SemaphoreSlim(1, 1);
|
||||
private readonly Statistics Statistics;
|
||||
private readonly SteamClient SteamClient;
|
||||
@@ -243,6 +244,7 @@ namespace ArchiSteamFarm {
|
||||
CallbackSemaphore.Dispose();
|
||||
GamesRedeemerInBackgroundSemaphore.Dispose();
|
||||
InitializationSemaphore.Dispose();
|
||||
MessagingSemaphore.Dispose();
|
||||
PICSSemaphore.Dispose();
|
||||
|
||||
// Those are objects that might be null and the check should be in-place
|
||||
@@ -922,6 +924,8 @@ namespace ArchiSteamFarm {
|
||||
|
||||
messagePart = Program.GlobalConfig.SteamMessagePrefix + (i > 0 ? "…" : "") + messagePart + (maxMessageLength < message.Length - i ? "…" : "");
|
||||
|
||||
await LimitMessagingRequestsAsync().ConfigureAwait(false);
|
||||
|
||||
if (!await ArchiHandler.SendMessage(steamID, messagePart).ConfigureAwait(false)) {
|
||||
return false;
|
||||
}
|
||||
@@ -959,6 +963,8 @@ namespace ArchiSteamFarm {
|
||||
|
||||
messagePart = Program.GlobalConfig.SteamMessagePrefix + (i > 0 ? "…" : "") + messagePart + (maxMessageLength < message.Length - i ? "…" : "");
|
||||
|
||||
await LimitMessagingRequestsAsync().ConfigureAwait(false);
|
||||
|
||||
if (!await ArchiHandler.SendMessage(chatGroupID, chatID, messagePart).ConfigureAwait(false)) {
|
||||
return false;
|
||||
}
|
||||
@@ -1475,6 +1481,20 @@ namespace ArchiSteamFarm {
|
||||
);
|
||||
}
|
||||
|
||||
private async Task LimitMessagingRequestsAsync() {
|
||||
if (Program.GlobalConfig.MessagingLimiterDelay == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
await MessagingSemaphore.WaitAsync().ConfigureAwait(false);
|
||||
Utilities.InBackground(
|
||||
async () => {
|
||||
await Task.Delay(Program.GlobalConfig.MessagingLimiterDelay).ConfigureAwait(false);
|
||||
MessagingSemaphore.Release();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private async void OnConnected(SteamClient.ConnectedCallback callback) {
|
||||
if (callback == null) {
|
||||
ArchiLogger.LogNullError(nameof(callback));
|
||||
|
||||
@@ -49,6 +49,7 @@ namespace ArchiSteamFarm {
|
||||
private const byte DefaultLoginLimiterDelay = 10;
|
||||
private const byte DefaultMaxFarmingTime = 10;
|
||||
private const byte DefaultMaxTradeHoldDuration = 15;
|
||||
private const ushort DefaultMessagingLimiterDelay = 1000;
|
||||
private const EOptimizationMode DefaultOptimizationMode = EOptimizationMode.MaxPerformance;
|
||||
private const bool DefaultStatistics = true;
|
||||
private const string DefaultSteamMessagePrefix = "/me ";
|
||||
@@ -117,6 +118,9 @@ namespace ArchiSteamFarm {
|
||||
[JsonProperty(Required = Required.DisallowNull)]
|
||||
internal readonly byte MaxTradeHoldDuration = DefaultMaxTradeHoldDuration;
|
||||
|
||||
[JsonProperty(Required = Required.DisallowNull)]
|
||||
internal readonly ushort MessagingLimiterDelay = DefaultMessagingLimiterDelay;
|
||||
|
||||
[JsonProperty(Required = Required.DisallowNull)]
|
||||
internal readonly EOptimizationMode OptimizationMode = DefaultOptimizationMode;
|
||||
|
||||
@@ -341,6 +345,7 @@ namespace ArchiSteamFarm {
|
||||
public bool ShouldSerializeLoginLimiterDelay() => ShouldSerializeEverything || (LoginLimiterDelay != DefaultLoginLimiterDelay);
|
||||
public bool ShouldSerializeMaxFarmingTime() => ShouldSerializeEverything || (MaxFarmingTime != DefaultMaxFarmingTime);
|
||||
public bool ShouldSerializeMaxTradeHoldDuration() => ShouldSerializeEverything || (MaxTradeHoldDuration != DefaultMaxTradeHoldDuration);
|
||||
public bool ShouldSerializeMessagingLimiterDelay() => ShouldSerializeEverything || (MessagingLimiterDelay != DefaultMessagingLimiterDelay);
|
||||
public bool ShouldSerializeOptimizationMode() => ShouldSerializeEverything || (OptimizationMode != DefaultOptimizationMode);
|
||||
public bool ShouldSerializeSSteamOwnerID() => ShouldSerializeEverything; // We never serialize helper properties
|
||||
public bool ShouldSerializeStatistics() => ShouldSerializeEverything || (Statistics != DefaultStatistics);
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
"LoginLimiterDelay": 10,
|
||||
"MaxFarmingTime": 10,
|
||||
"MaxTradeHoldDuration": 15,
|
||||
"MessagingLimiterDelay": 1000,
|
||||
"OptimizationMode": 0,
|
||||
"Statistics": true,
|
||||
"SteamMessagePrefix": "/me ",
|
||||
|
||||
Reference in New Issue
Block a user