feat: add Redis identify ratelimiter

This commit is contained in:
spiral
2022-01-13 12:26:25 -05:00
parent 8aa2b0b7aa
commit 2aead40449
15 changed files with 449 additions and 40 deletions

View File

@@ -19,6 +19,7 @@ public class BotConfig
public ClusterSettings? Cluster { get; set; }
public string? GatewayQueueUrl { get; set; }
public bool UseRedisRatelimiter { get; set; } = false;
public string? DiscordBaseUrl { get; set; }

View File

@@ -42,6 +42,11 @@ public class Init
opts.DisableTaskUnobservedTaskExceptionCapture();
});
// initialize Redis
var coreConfig = services.Resolve<CoreConfig>();
var redis = services.Resolve<RedisService>();
await redis.InitAsync(coreConfig);
var config = services.Resolve<BotConfig>();
if (config.Cluster == null)
{
@@ -141,6 +146,8 @@ public class Init
{
var info = await services.Resolve<DiscordApiClient>().GetGatewayBot();
var redis = services.Resolve<RedisService>();
var cluster = services.Resolve<Cluster>();
var config = services.Resolve<BotConfig>();
@@ -155,11 +162,11 @@ public class Init
var shardMin = (int)Math.Round(totalShards * (float)nodeIndex / totalNodes);
var shardMax = (int)Math.Round(totalShards * (float)(nodeIndex + 1) / totalNodes) - 1;
await cluster.Start(info.Url, shardMin, shardMax, totalShards, info.SessionStartLimit.MaxConcurrency);
await cluster.Start(info.Url, shardMin, shardMax, totalShards, info.SessionStartLimit.MaxConcurrency, redis.Connection);
}
else
{
await cluster.Start(info);
await cluster.Start(info, redis.Connection);
}
}
}

View File

@@ -31,6 +31,7 @@ public class BotModule: Module
Token = botConfig.Token,
MaxShardConcurrency = botConfig.MaxShardConcurrency,
GatewayQueueUrl = botConfig.GatewayQueueUrl,
UseRedisRatelimiter = botConfig.UseRedisRatelimiter,
Intents = GatewayIntent.Guilds |
GatewayIntent.DirectMessages |
GatewayIntent.DirectMessageReactions |

View File

@@ -294,8 +294,8 @@
},
"Microsoft.NETCore.Platforms": {
"type": "Transitive",
"resolved": "1.1.0",
"contentHash": "kz0PEW2lhqygehI/d6XsPCQzD7ff7gUJaVGPVETX611eadGsA3A877GdSlU0LRVMCTH/+P3o2iDTak+S08V2+A=="
"resolved": "5.0.0",
"contentHash": "VyPlqzH2wavqquTcYpkIIAQ6WdenuKoFN0BdYBbCWsclXacSOHNQn66Gt4z5NBqEYW0FAPm5rlvki9ZiCij5xQ=="
},
"Microsoft.NETCore.Targets": {
"type": "Transitive",
@@ -312,6 +312,23 @@
"System.Runtime": "4.3.0"
}
},
"Microsoft.Win32.Registry": {
"type": "Transitive",
"resolved": "5.0.0",
"contentHash": "dDoKi0PnDz31yAyETfRntsLArTlVAVzUzCIvvEDsDsucrl33Dl8pIJG06ePTJTI3tGpeyHS9Cq7Foc/s4EeKcg==",
"dependencies": {
"System.Security.AccessControl": "5.0.0",
"System.Security.Principal.Windows": "5.0.0"
}
},
"Microsoft.Win32.SystemEvents": {
"type": "Transitive",
"resolved": "5.0.0",
"contentHash": "Bh6blKG8VAKvXiLe2L+sEsn62nc1Ij34MrNxepD2OCrS5cpCwQa9MeLyhVQPQ/R4Wlzwuy6wMK8hLb11QPDRsQ==",
"dependencies": {
"Microsoft.NETCore.Platforms": "5.0.0"
}
},
"NETStandard.Library": {
"type": "Transitive",
"resolved": "1.6.1",
@@ -402,6 +419,14 @@
"Npgsql": "4.1.5"
}
},
"Pipelines.Sockets.Unofficial": {
"type": "Transitive",
"resolved": "2.2.0",
"contentHash": "7hzHplEIVOGBl5zOQZGX/DiJDHjq+RVRVrYgDiqXb6RriqWAdacXxp+XO9WSrATCEXyNOUOQg9aqQArsjase/A==",
"dependencies": {
"System.IO.Pipelines": "5.0.0"
}
},
"Polly": {
"type": "Transitive",
"resolved": "7.2.1",
@@ -631,6 +656,15 @@
"dapper": "1.50.5"
}
},
"StackExchange.Redis": {
"type": "Transitive",
"resolved": "2.2.88",
"contentHash": "JJi1jcO3/ZiamBhlsC/TR8aZmYf+nqpGzMi0HRRCy5wJkUPmMnRp0kBA6V84uhU8b531FHSdTDaFCAyCUJomjA==",
"dependencies": {
"Pipelines.Sockets.Unofficial": "2.2.0",
"System.Diagnostics.PerformanceCounter": "5.0.0"
}
},
"System.AppContext": {
"type": "Transitive",
"resolved": "4.3.0",
@@ -671,6 +705,15 @@
"System.Threading.Tasks": "4.3.0"
}
},
"System.Configuration.ConfigurationManager": {
"type": "Transitive",
"resolved": "5.0.0",
"contentHash": "aM7cbfEfVNlEEOj3DsZP+2g9NRwbkyiAv2isQEzw7pnkDg9ekCU2m1cdJLM02Uq691OaCS91tooaxcEn8d0q5w==",
"dependencies": {
"System.Security.Cryptography.ProtectedData": "5.0.0",
"System.Security.Permissions": "5.0.0"
}
},
"System.Console": {
"type": "Transitive",
"resolved": "4.3.0",
@@ -698,6 +741,17 @@
"resolved": "4.7.1",
"contentHash": "j81Lovt90PDAq8kLpaJfJKV/rWdWuEk6jfV+MBkee33vzYLEUsy4gXK8laa9V2nZlLM9VM9yA/OOQxxPEJKAMw=="
},
"System.Diagnostics.PerformanceCounter": {
"type": "Transitive",
"resolved": "5.0.0",
"contentHash": "kcQWWtGVC3MWMNXdMDWfrmIlFZZ2OdoeT6pSNVRtk9+Sa7jwdPiMlNwb0ZQcS7NRlT92pCfmjRtkSWUW3RAKwg==",
"dependencies": {
"Microsoft.NETCore.Platforms": "5.0.0",
"Microsoft.Win32.Registry": "5.0.0",
"System.Configuration.ConfigurationManager": "5.0.0",
"System.Security.Principal.Windows": "5.0.0"
}
},
"System.Diagnostics.Tools": {
"type": "Transitive",
"resolved": "4.3.0",
@@ -718,6 +772,14 @@
"System.Runtime": "4.3.0"
}
},
"System.Drawing.Common": {
"type": "Transitive",
"resolved": "5.0.0",
"contentHash": "SztFwAnpfKC8+sEKXAFxCBWhKQaEd97EiOL7oZJZP56zbqnLpmxACWA8aGseaUExciuEAUuR9dY8f7HkTRAdnw==",
"dependencies": {
"Microsoft.Win32.SystemEvents": "5.0.0"
}
},
"System.Globalization": {
"type": "Transitive",
"resolved": "4.3.0",
@@ -833,6 +895,11 @@
"System.Runtime": "4.3.0"
}
},
"System.IO.Pipelines": {
"type": "Transitive",
"resolved": "5.0.0",
"contentHash": "irMYm3vhVgRsYvHTU5b2gsT2CwT/SMM6LZFzuJjpIvT5Z4CshxNsaoBC1X/LltwuR3Opp8d6jOS/60WwOb7Q2Q=="
},
"System.Linq": {
"type": "Transitive",
"resolved": "4.3.0",
@@ -1089,6 +1156,15 @@
"System.Runtime.Extensions": "4.3.0"
}
},
"System.Security.AccessControl": {
"type": "Transitive",
"resolved": "5.0.0",
"contentHash": "dagJ1mHZO3Ani8GH0PHpPEe/oYO+rVdbQjvjJkBRNQkX4t0r1iaeGn8+/ybkSLEan3/slM0t59SVdHzuHf2jmw==",
"dependencies": {
"Microsoft.NETCore.Platforms": "5.0.0",
"System.Security.Principal.Windows": "5.0.0"
}
},
"System.Security.Cryptography.Algorithms": {
"type": "Transitive",
"resolved": "4.3.0",
@@ -1201,6 +1277,11 @@
"System.Threading.Tasks": "4.3.0"
}
},
"System.Security.Cryptography.ProtectedData": {
"type": "Transitive",
"resolved": "5.0.0",
"contentHash": "HGxMSAFAPLNoxBvSfW08vHde0F9uh7BjASwu6JF9JnXuEPhCY3YUqURn0+bQV/4UWeaqymmrHWV+Aw9riQCtCA=="
},
"System.Security.Cryptography.X509Certificates": {
"type": "Transitive",
"resolved": "4.3.0",
@@ -1233,6 +1314,20 @@
"runtime.native.System.Security.Cryptography.OpenSsl": "4.3.0"
}
},
"System.Security.Permissions": {
"type": "Transitive",
"resolved": "5.0.0",
"contentHash": "uE8juAhEkp7KDBCdjDIE3H9R1HJuEHqeqX8nLX9gmYKWwsqk3T5qZlPx8qle5DPKimC/Fy3AFTdV7HamgCh9qQ==",
"dependencies": {
"System.Security.AccessControl": "5.0.0",
"System.Windows.Extensions": "5.0.0"
}
},
"System.Security.Principal.Windows": {
"type": "Transitive",
"resolved": "5.0.0",
"contentHash": "t0MGLukB5WAVU9bO3MGzvlGnyJPgUlcwerXn1kzBRjwLKixT96XV0Uza41W49gVd8zEMFu9vQEFlv0IOrytICA=="
},
"System.Text.Encoding": {
"type": "Transitive",
"resolved": "4.3.0",
@@ -1306,6 +1401,14 @@
"System.Runtime": "4.3.0"
}
},
"System.Windows.Extensions": {
"type": "Transitive",
"resolved": "5.0.0",
"contentHash": "c1ho9WU9ZxMZawML+ssPKZfdnrg/OjR3pe0m9v8230z3acqphwvPJqzAkH54xRYm5ntZHGG1EPP3sux9H3qSPg==",
"dependencies": {
"System.Drawing.Common": "5.0.0"
}
},
"System.Xml.ReaderWriter": {
"type": "Transitive",
"resolved": "4.3.0",
@@ -1353,6 +1456,7 @@
"Polly": "7.2.1",
"Polly.Contrib.WaitAndRetry": "1.1.1",
"Serilog": "2.10.0",
"StackExchange.Redis": "2.2.88",
"System.Linq.Async": "5.0.0"
}
},
@@ -1388,6 +1492,7 @@
"Serilog.Sinks.File": "4.1.0",
"SqlKata": "2.3.7",
"SqlKata.Execution": "2.3.7",
"StackExchange.Redis": "2.2.88",
"System.Interactive.Async": "5.0.0",
"ipnetwork2": "2.5.381"
}