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