1
0
Fork 1
mirror of https://github.com/TeamOctolings/Octobot.git synced 2025-05-06 22:16:29 +03:00

Use TryGetValue instead of ContainsKey and retrieving afterwards

This commit is contained in:
Octol1ttle 2022-10-21 11:09:56 +05:00
parent 59d9423b5f
commit 7afd00bf30
Signed by: Octol1ttle
GPG key ID: B77C34313AEE1FFF
4 changed files with 9 additions and 9 deletions

View file

@ -83,7 +83,7 @@ public static class Boyfriend {
if (!RemovedRolesDictionary.ContainsKey(id))
RemovedRolesDictionary.Add(id, new Dictionary<ulong, ReadOnlyCollection<ulong>>());
if (GuildConfigDictionary.ContainsKey(id)) return GuildConfigDictionary[id];
if (GuildConfigDictionary.TryGetValue(id, out var cfg)) return cfg;
var path = $"config_{id}.json";
@ -110,7 +110,7 @@ public static class Boyfriend {
}
public static Dictionary<ulong, ReadOnlyCollection<ulong>> GetRemovedRoles(ulong id) {
if (RemovedRolesDictionary.ContainsKey(id)) return RemovedRolesDictionary[id];
if (RemovedRolesDictionary.TryGetValue(id, out var dict)) return dict;
var path = $"removedroles_{id}.json";
@ -126,7 +126,7 @@ public static class Boyfriend {
}
public static SocketGuild FindGuild(ulong channel) {
if (GuildCache.ContainsKey(channel)) return GuildCache[channel];
if (GuildCache.TryGetValue(channel, out var gld)) return gld;
foreach (var guild in Client.Guilds) {
// ReSharper disable once LoopCanBeConvertedToQuery
foreach (var x in guild.Channels)